diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml index 77ad2de94..4165ba7d1 100644 --- a/.idea/codeStyles/Project.xml +++ b/.idea/codeStyles/Project.xml @@ -224,4 +224,4 @@ - + \ No newline at end of file diff --git a/build.gradle b/build.gradle index fceef9b6a..f2feea587 100644 --- a/build.gradle +++ b/build.gradle @@ -41,6 +41,7 @@ buildscript { classpath Dep.GradlePlugin.licensesPlugin classpath Dep.GradlePlugin.crashlytics classpath Dep.GradlePlugin.iconRibbonPlugin + classpath 'com.android.tools.build:gradle:3.4.0-beta05' } } diff --git a/corecomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt b/corecomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt index 85c6912da..bd55307dc 100644 --- a/corecomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt +++ b/corecomponent/androidcomponent/src/main/java/io/github/droidkaigi/confsched2019/action/Action.kt @@ -92,4 +92,7 @@ sealed class Action { data class SessionSurveyLoaded(val sessionFeedback: SessionFeedback) : Action() class FloorMapLoadingStateChanged(val loadingState: LoadingState) : Action() + + data class SettingContentsChanged(val contents : MutableMap) : Action() + } diff --git a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionContentsStore.kt b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionContentsStore.kt index e30d52bf2..e215524d6 100644 --- a/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionContentsStore.kt +++ b/feature/session/src/main/java/io/github/droidkaigi/confsched2019/session/ui/store/SessionContentsStore.kt @@ -18,7 +18,7 @@ import javax.inject.Inject import javax.inject.Singleton @Singleton -class SessionContentsStore @Inject constructor( +class SessionContentsStore @Inject constructor( dispatcher: Dispatcher ) { val loadingState = dispatcher diff --git a/feature/settings/build.gradle b/feature/settings/build.gradle index c9227c5c1..55ddb28aa 100644 --- a/feature/settings/build.gradle +++ b/feature/settings/build.gradle @@ -44,4 +44,5 @@ dependencies { testImplementation Dep.Test.junit androidTestImplementation Dep.Test.testRunner androidTestImplementation Dep.Test.espressoCore + compile project(path: ':feature:system') } diff --git a/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/DaggerFragment.kt b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/DaggerFragment.kt new file mode 100644 index 000000000..1a1336b1c --- /dev/null +++ b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/DaggerFragment.kt @@ -0,0 +1,28 @@ +package io.github.droidkaigi.confsched2019.settings.ui + +import android.os.Bundle +import androidx.fragment.app.Fragment +import androidx.preference.PreferenceFragmentCompat +import dagger.android.AndroidInjector +import dagger.android.DispatchingAndroidInjector +import dagger.android.support.AndroidSupportInjection +import dagger.android.support.HasSupportFragmentInjector +import javax.inject.Inject + +/** + * By [dagger.android.support.DaggerFragment] + * Inject in [onActivityCreated]. + * Because you can not get [Fragment.getViewLifecycleOwner] when [onAttach] timing + */ +open class DaggerFragment : Fragment(), HasSupportFragmentInjector { + + @Inject lateinit var childFragmentInjector: DispatchingAndroidInjector + override fun onActivityCreated(savedInstanceState: Bundle?) { + AndroidSupportInjection.inject(this) + super.onActivityCreated(savedInstanceState) + } + + override fun supportFragmentInjector(): AndroidInjector? { + return childFragmentInjector + } +} diff --git a/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/PreferenceActionCreator.kt b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/PreferenceActionCreator.kt new file mode 100644 index 000000000..0e090279c --- /dev/null +++ b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/PreferenceActionCreator.kt @@ -0,0 +1,20 @@ +package io.github.droidkaigi.confsched2019.settings.ui + +import io.github.droidkaigi.confsched2019.action.Action +import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher +import io.github.droidkaigi.confsched2019.model.SettingContents +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.GlobalScope +import kotlinx.coroutines.SupervisorJob +import kotlinx.coroutines.launch +import kotlinx.coroutines.plus +import javax.inject.Inject + +class PreferenceActionCreator @Inject constructor( + val dispatcher: Dispatcher) + : CoroutineScope by GlobalScope + SupervisorJob() { + fun submit(action: Action)=launch { + dispatcher.dispatch(action) + + } +} diff --git a/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsFragment.kt b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsFragment.kt index 5485a6fd0..8f6d76822 100644 --- a/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsFragment.kt +++ b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsFragment.kt @@ -1,11 +1,160 @@ package io.github.droidkaigi.confsched2019.settings.ui +import android.content.Context +import android.content.SharedPreferences import android.os.Bundle -import androidx.preference.PreferenceFragmentCompat +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.CheckBox +import androidx.fragment.app.Fragment +import androidx.lifecycle.Lifecycle +import dagger.Module +import dagger.Provides +import io.github.droidkaigi.confsched2019.di.PageScope +import io.github.droidkaigi.confsched2019.model.SettingContents import io.github.droidkaigi.confsched2019.settings.R +import java.lang.RuntimeException +import javax.inject.Inject -class SettingsFragment : PreferenceFragmentCompat() { - override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { - setPreferencesFromResource(R.xml.preferences, rootKey) +class SettingsFragment : DaggerFragment() { + + + override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { + return inflater.inflate(R.layout.settings_fragment, container, false) } + + override fun onViewCreated(view: View, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + + val sessionTitleValue = android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SESSION_TITLE, false) + val sessionUrlValue = android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(SESSION_URL, false) + val eventHashtagValue = android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(EVENT_HUSHTAG, false) + val roomHashtagValue = android.preference.PreferenceManager.getDefaultSharedPreferences(context).getBoolean(ROOM_HUSHTAG, false) + + val settingContents = SettingContents() + settingContents.preferences[SESSION_TITLE] = sessionTitleValue + settingContents.preferences[SESSION_URL] = sessionUrlValue + settingContents.preferences[EVENT_HUSHTAG] = eventHashtagValue + settingContents.preferences[ROOM_HUSHTAG] = roomHashtagValue + + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.session_title_key).isChecked = settingContents.preferences[SESSION_TITLE]!! + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.session_title_key).setOnCheckedChangeListener { buttonView, isChecked -> + android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit() + .putBoolean(SESSION_TITLE,isChecked) + .apply() + } + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.session_url_key).isChecked = settingContents.preferences [SESSION_URL]!! + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.session_url_key).setOnCheckedChangeListener { buttonView, isChecked -> + android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit() + .putBoolean(SESSION_URL, isChecked) + .apply() + } + + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.event_hashtag_key).isChecked = settingContents.preferences [EVENT_HUSHTAG]!! + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.event_hashtag_key).setOnCheckedChangeListener { buttonView, isChecked -> + android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit() + .putBoolean(EVENT_HUSHTAG, isChecked) + .apply() + } + + + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.room_hashtag_key).isChecked = settingContents.preferences [ROOM_HUSHTAG]!! + view.findViewById(io.github.droidkaigi.confsched2019.settings.R.id.room_hashtag_key).setOnCheckedChangeListener { buttonView, isChecked -> + android.preference.PreferenceManager.getDefaultSharedPreferences(context).edit() + .putBoolean(ROOM_HUSHTAG, isChecked) + .apply() + } + + } + + companion object { + private const val SESSION_TITLE = "session_title_key" + private const val SESSION_URL = "session_url_key" + private const val EVENT_HUSHTAG = "event_hashtag_key" + private const val ROOM_HUSHTAG = "room_hashtag_key" + + fun newInstance() = SettingsFragment() + } + + @Inject lateinit var preferenceActionCreator: PreferenceActionCreator + @Inject lateinit var settingsStore: SettingsStore + + override fun onActivityCreated(savedInstanceState: Bundle?) { + super.onActivityCreated(savedInstanceState) + } + + override fun onDestroy() { + super.onDestroy() + } + +} + +@Module +abstract class SettingsFragmentModule { + @Module + companion object { + @PageScope + @JvmStatic + @Provides + fun providesLifecycle( + settingsFragment: SettingsFragment + ): Lifecycle { + return settingsFragment.viewLifecycleOwner.lifecycle + } + } +} + + +// override fun onViewCreated(view: View, savedInstanceState: Bundle?) { +// super.onViewCreated(view, savedInstanceState) +// settingsStore.settingsResult.changed(viewLifecycleOwner) { settingContents -> +// for (content in settingContents.preferences) { +// val editor = PreferenceManager.getDefaultSharedPreferences(context).edit() +// editor.putBoolean(content.key, content.value ?: false) +// editor.apply() +// } +// } +// } +// override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences?, key: String?) { +// val contents = mutableMapOf() +// val changed_title = sharedPreferences?.getBoolean( +// "session_title", false +// ) +// val changed_url = sharedPreferences?.getBoolean( +// "session_url", false +// ) +// val changed_event = sharedPreferences?.getBoolean( +// "event_hashtag", false +// ) +// val changed_room = sharedPreferences?.getBoolean( +// "room_hashtag", false +// ) +// +// contents["session_title"] = changed_title +// contents["session_url"] = changed_url +// contents["event_hashtag"] = changed_event +// contents["room_hashtag"] = changed_room + +// preferenceActionCreator.submit(Action.SettingContentsChanged(contents)) +// } +/* + private fun settingContent( + changed_title: Boolean?, + changed_url: Boolean?, + changed_event: Boolean?, + changed_room: Boolean? + ): MutableMap = + mutableMapOf(changed_title, changed_url, changed_event, changed_room) +} + + preferenceActionCreator.submit(Action.SettingContentsChanged( + - settingContent( + - changed_title, + - changed_url, + - changed_event, + - changed_room + - ) + - )) +*/ diff --git a/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsStore.kt b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsStore.kt new file mode 100644 index 000000000..639347fcd --- /dev/null +++ b/feature/settings/src/main/java/io/github/droidkaigi/confsched2019/settings/ui/SettingsStore.kt @@ -0,0 +1,23 @@ +package io.github.droidkaigi.confsched2019.settings.ui + +import androidx.lifecycle.LiveData +import io.github.droidkaigi.confsched2019.action.Action +import io.github.droidkaigi.confsched2019.dispatcher.Dispatcher +import io.github.droidkaigi.confsched2019.ext.toLiveData +import io.github.droidkaigi.confsched2019.model.SettingContents +import io.github.droidkaigi.confsched2019.store.Store +import kotlinx.coroutines.channels.map +import javax.inject.Inject +import javax.inject.Singleton + +class SettingsStore @Inject constructor( + dispatcher: Dispatcher +) : Store() { + + val settingsResult : LiveData = dispatcher + + .subscribe() + .map { SettingContents(it.contents) } + .toLiveData(this, null) +} + diff --git a/feature/settings/src/main/res/layout/settings_fragment.xml b/feature/settings/src/main/res/layout/settings_fragment.xml new file mode 100644 index 000000000..9cd1ac712 --- /dev/null +++ b/feature/settings/src/main/res/layout/settings_fragment.xml @@ -0,0 +1,123 @@ + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/feature/settings/src/main/res/values/bools.xml b/feature/settings/src/main/res/values/bools.xml new file mode 100644 index 000000000..5b91c5ed0 --- /dev/null +++ b/feature/settings/src/main/res/values/bools.xml @@ -0,0 +1,7 @@ + + + true + true + true + true + diff --git a/feature/settings/src/main/res/values/strings.xml b/feature/settings/src/main/res/values/strings.xml index 045e125f3..eaeed1f47 100644 --- a/feature/settings/src/main/res/values/strings.xml +++ b/feature/settings/src/main/res/values/strings.xml @@ -1,3 +1,22 @@ + Sharing Settings for Tweet + share_setting + + Session Title + session_title + ex.What will be changed on tests in multi-module projects + + Session URL + session_url + ex.https://droidkaigi.jp/2019/.. + + Event Hashtag + event_hashtag + ex.#droidkaigi + + Room Hashtag + room_hashtag + ex.#hallA, #room1 + diff --git a/feature/settings/src/main/res/xml/preferences.xml b/feature/settings/src/main/res/xml/preferences.xml deleted file mode 100644 index 532b9f74b..000000000 --- a/feature/settings/src/main/res/xml/preferences.xml +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/App.kt b/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/App.kt index 2d03a4cb0..52eb8ddab 100644 --- a/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/App.kt +++ b/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/App.kt @@ -18,6 +18,7 @@ import io.github.droidkaigi.confsched2019.announcement.ui.subscribeAnnouncementT import io.github.droidkaigi.confsched2019.di.createAppComponent import io.github.droidkaigi.confsched2019.ext.changedForever import io.github.droidkaigi.confsched2019.model.SystemProperty +import io.github.droidkaigi.confsched2019.settings.ui.SettingsStore import io.github.droidkaigi.confsched2019.system.actioncreator.SystemActionCreator import io.github.droidkaigi.confsched2019.system.store.SystemStore import timber.log.LogcatTree diff --git a/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/ui/MainActivity.kt b/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/ui/MainActivity.kt index 89e7850ae..20017bf12 100644 --- a/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/ui/MainActivity.kt +++ b/frontend/android/src/main/java/io/github/droidkaigi/confsched2019/ui/MainActivity.kt @@ -54,6 +54,8 @@ import io.github.droidkaigi.confsched2019.session.ui.SpeakerFragment import io.github.droidkaigi.confsched2019.session.ui.SpeakerFragmentModule import io.github.droidkaigi.confsched2019.session.ui.TabularFormSessionPagesFragment import io.github.droidkaigi.confsched2019.session.ui.TabularFromSessionPagesFragmentModule +import io.github.droidkaigi.confsched2019.settings.ui.SettingsFragment +import io.github.droidkaigi.confsched2019.settings.ui.SettingsFragmentModule import io.github.droidkaigi.confsched2019.sponsor.ui.SponsorFragment import io.github.droidkaigi.confsched2019.sponsor.ui.SponsorFragmentModule import io.github.droidkaigi.confsched2019.staff.ui.StaffSearchFragment @@ -126,8 +128,10 @@ class MainActivity : DaggerAppCompatActivity() { } private fun setupNavigation() { - val topLevelDestinationIds = setOf(R.id.main, R.id.about, R.id.announce, R.id.setting, - R.id.floormap, R.id.sponsor, R.id.contributor) + val topLevelDestinationIds = setOf( + R.id.main, R.id.about, R.id.announce, R.id.setting, + R.id.floormap, R.id.sponsor, R.id.contributor + ) val appBarConfiguration = AppBarConfiguration( topLevelDestinationIds, binding.drawerLayout @@ -333,6 +337,10 @@ abstract class MainActivityModule { ) abstract fun contrbutorContributorFragment(): ContributorFragment + @PageScope + @ContributesAndroidInjector(modules = [SettingsFragmentModule::class]) + abstract fun contributeSettingsFragment(): SettingsFragment + @Module companion object { @JvmStatic @Provides fun provideNavController(mainActivity: MainActivity): NavController { diff --git a/frontend/android/src/main/res/menu/menu_nav_drawer.xml b/frontend/android/src/main/res/menu/menu_nav_drawer.xml index ec1390085..e7a9be219 100644 --- a/frontend/android/src/main/res/menu/menu_nav_drawer.xml +++ b/frontend/android/src/main/res/menu/menu_nav_drawer.xml @@ -47,11 +47,11 @@ android:title="@string/contributor"/> - - - - - + @style/Widget.App.Toolbar.Button.Navigation + + diff --git a/model/src/commonMain/kotlin/SettingContents.kt b/model/src/commonMain/kotlin/SettingContents.kt new file mode 100644 index 000000000..a4f6ba987 --- /dev/null +++ b/model/src/commonMain/kotlin/SettingContents.kt @@ -0,0 +1,13 @@ +package io.github.droidkaigi.confsched2019.model + + +data class SettingContents( + val preferences: MutableMap = mutableMapOf(sessionTit to false, sessionUrl to false, eventHashtag to false, roomHashtag to false) +) { + companion object { + private const val sessionTit = "session_title_key" + private const val sessionUrl = "session_url_key" + private const val eventHashtag = "event_hashtag_key" + private const val roomHashtag = "room_hashtag_key" + } +}