More FlowPreferences migrations
This commit is contained in:
@@ -15,6 +15,8 @@ import com.bluelinelabs.conductor.ControllerChangeType
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.ui.base.controller.BaseController
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.subscriptions.CompositeSubscription
|
||||
@@ -25,6 +27,8 @@ abstract class SettingsController : PreferenceController() {
|
||||
|
||||
val preferences: PreferencesHelper = Injekt.get()
|
||||
|
||||
val uiScope = CoroutineScope(Dispatchers.Main)
|
||||
|
||||
var untilDestroySubscriptions = CompositeSubscription()
|
||||
private set
|
||||
|
||||
|
||||
@@ -7,7 +7,6 @@ import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||
import eu.kanade.tachiyomi.util.preference.entriesRes
|
||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||
@@ -18,6 +17,8 @@ import eu.kanade.tachiyomi.util.preference.preference
|
||||
import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
class SettingsGeneralController : SettingsController() {
|
||||
|
||||
@@ -138,11 +139,13 @@ class SettingsGeneralController : SettingsController() {
|
||||
defaultValue = Values.THEME_LIGHT_DEFAULT
|
||||
summary = "%s"
|
||||
|
||||
preferences.themeMode().asObservable()
|
||||
.subscribeUntilDestroy { isVisible = it != Values.THEME_MODE_DARK }
|
||||
isVisible = preferences.themeMode().get() != Values.THEME_MODE_DARK
|
||||
preferences.themeMode().asFlow()
|
||||
.onEach { isVisible = it != Values.THEME_MODE_DARK }
|
||||
.launchIn(uiScope)
|
||||
|
||||
onChange {
|
||||
if (preferences.themeMode().getOrDefault() != Values.THEME_MODE_DARK) {
|
||||
if (preferences.themeMode().get() != Values.THEME_MODE_DARK) {
|
||||
activity?.recreate()
|
||||
}
|
||||
true
|
||||
@@ -162,11 +165,13 @@ class SettingsGeneralController : SettingsController() {
|
||||
defaultValue = Values.THEME_DARK_DEFAULT
|
||||
summary = "%s"
|
||||
|
||||
preferences.themeMode().asObservable()
|
||||
.subscribeUntilDestroy { isVisible = it != Values.THEME_MODE_LIGHT }
|
||||
isVisible = preferences.themeMode().get() != Values.THEME_MODE_LIGHT
|
||||
preferences.themeMode().asFlow()
|
||||
.onEach { isVisible = it != Values.THEME_MODE_LIGHT }
|
||||
.launchIn(uiScope)
|
||||
|
||||
onChange {
|
||||
if (preferences.themeMode().getOrDefault() != Values.THEME_MODE_LIGHT) {
|
||||
if (preferences.themeMode().get() != Values.THEME_MODE_LIGHT) {
|
||||
activity?.recreate()
|
||||
}
|
||||
true
|
||||
|
||||
@@ -9,15 +9,11 @@ import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||
import eu.kanade.tachiyomi.util.preference.summaryRes
|
||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||
import eu.kanade.tachiyomi.util.preference.titleRes
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
class SettingsSecurityController : SettingsController() {
|
||||
|
||||
private val uiScope = CoroutineScope(Dispatchers.Main)
|
||||
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = with(screen) {
|
||||
titleRes = R.string.pref_category_security
|
||||
|
||||
|
||||
Reference in New Issue
Block a user