-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Neonankitifix #1
base: master
Are you sure you want to change the base?
Changes from all commits
e887b65
9375609
bb50321
d7bdebf
6756ef3
c0b7f38
0ab9ae5
b737932
4c4da24
0022e1a
ff11f9f
d49cf2b
a700082
6554941
4e5a91e
a87363f
6d52700
31ce418
00b7908
2c6e4ee
703f95d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,7 +18,7 @@ import javax.inject.Inject | |
import javax.inject.Singleton | ||
|
||
@Singleton | ||
class SessionContentsStore @Inject constructor( | ||
class SessionContentsStore @Inject constructor( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. へんな空白が入っている。formatする |
||
dispatcher: Dispatcher | ||
) { | ||
val loadingState = dispatcher | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. このクラスも削除 |
||
|
||
@Inject lateinit var childFragmentInjector: DispatchingAndroidInjector<Fragment> | ||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
AndroidSupportInjection.inject(this) | ||
super.onActivityCreated(savedInstanceState) | ||
} | ||
|
||
override fun supportFragmentInjector(): AndroidInjector<Fragment>? { | ||
return childFragmentInjector | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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) | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fragmentにする |
||
|
||
|
||
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<CheckBox>(io.github.droidkaigi.confsched2019.settings.R.id.session_title_key).isChecked = settingContents.preferences[SESSION_TITLE]!! | ||
view.findViewById<CheckBox>(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<CheckBox>(io.github.droidkaigi.confsched2019.settings.R.id.session_url_key).isChecked = settingContents.preferences [SESSION_URL]!! | ||
view.findViewById<CheckBox>(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<CheckBox>(io.github.droidkaigi.confsched2019.settings.R.id.event_hashtag_key).isChecked = settingContents.preferences [EVENT_HUSHTAG]!! | ||
view.findViewById<CheckBox>(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<CheckBox>(io.github.droidkaigi.confsched2019.settings.R.id.room_hashtag_key).isChecked = settingContents.preferences [ROOM_HUSHTAG]!! | ||
view.findViewById<CheckBox>(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() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要なので削除 |
||
|
||
} | ||
|
||
@Inject lateinit var preferenceActionCreator: PreferenceActionCreator | ||
@Inject lateinit var settingsStore: SettingsStore | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要なので、削除 |
||
|
||
override fun onActivityCreated(savedInstanceState: Bundle?) { | ||
super.onActivityCreated(savedInstanceState) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要なので削除 |
||
|
||
override fun onDestroy() { | ||
super.onDestroy() | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 不要なので削除 |
||
|
||
} | ||
|
||
@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<String, Boolean?>() | ||
// 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<Any, Any> = | ||
mutableMapOf(changed_title, changed_url, changed_event, changed_room) | ||
} | ||
|
||
preferenceActionCreator.submit(Action.SettingContentsChanged( | ||
- settingContent( | ||
- changed_title, | ||
- changed_url, | ||
- changed_event, | ||
- changed_room | ||
- ) | ||
- )) | ||
*/ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 全部消す |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<SettingContents> = dispatcher | ||
|
||
.subscribe<Action.SettingContentsChanged>() | ||
.map { SettingContents(it.contents) } | ||
.toLiveData(this, null) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
これは不要なはず