Skip to content
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

Open
wants to merge 21 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これは不要なはず

}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<String, Boolean>) : Action()

}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import javax.inject.Inject
import javax.inject.Singleton

@Singleton
class SessionContentsStore @Inject constructor(
class SessionContentsStore @Inject constructor(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

へんな空白が入っている。formatする

dispatcher: Dispatcher
) {
val loadingState = dispatcher
Expand Down
1 change: 1 addition & 0 deletions feature/settings/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ dependencies {
testImplementation Dep.Test.junit
androidTestImplementation Dep.Test.testRunner
androidTestImplementation Dep.Test.espressoCore
compile project(path: ':feature:system')
}
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 {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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() {
Copy link
Collaborator

Choose a reason for hiding this comment

The 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()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なので削除


}

@Inject lateinit var preferenceActionCreator: PreferenceActionCreator
@Inject lateinit var settingsStore: SettingsStore
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なので、削除


override fun onActivityCreated(savedInstanceState: Bundle?) {
super.onActivityCreated(savedInstanceState)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不要なので削除


override fun onDestroy() {
super.onDestroy()
}
Copy link
Collaborator

Choose a reason for hiding this comment

The 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
- )
- ))
*/
Copy link
Collaborator

Choose a reason for hiding this comment

The 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)
}

Loading