Migrate more preferences
This commit is contained in:
@@ -15,6 +15,9 @@ 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 kotlinx.coroutines.Job
|
||||
import rx.Observable
|
||||
import rx.Subscription
|
||||
import rx.subscriptions.CompositeSubscription
|
||||
@@ -24,6 +27,7 @@ import uy.kohesive.injekt.api.get
|
||||
abstract class SettingsController : PreferenceController() {
|
||||
|
||||
val preferences: PreferencesHelper = Injekt.get()
|
||||
val scope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
|
||||
var untilDestroySubscriptions = CompositeSubscription()
|
||||
private set
|
||||
@@ -78,10 +82,6 @@ abstract class SettingsController : PreferenceController() {
|
||||
super.onChangeStarted(handler, type)
|
||||
}
|
||||
|
||||
fun <T> Observable<T>.subscribeUntilDestroy(): Subscription {
|
||||
return subscribe().also { untilDestroySubscriptions.add(it) }
|
||||
}
|
||||
|
||||
fun <T> Observable<T>.subscribeUntilDestroy(onNext: (T) -> Unit): Subscription {
|
||||
return subscribe(onNext).also { untilDestroySubscriptions.add(it) }
|
||||
}
|
||||
|
||||
@@ -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.util.lang.launchInUI
|
||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||
import eu.kanade.tachiyomi.util.preference.entriesRes
|
||||
import eu.kanade.tachiyomi.util.preference.intListPreference
|
||||
@@ -19,6 +18,7 @@ import eu.kanade.tachiyomi.util.preference.preferenceCategory
|
||||
import eu.kanade.tachiyomi.util.preference.switchPreference
|
||||
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() {
|
||||
@@ -147,7 +147,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
isVisible = preferences.themeMode().get() != Values.THEME_MODE_DARK
|
||||
preferences.themeMode().asFlow()
|
||||
.onEach { isVisible = it != Values.THEME_MODE_DARK }
|
||||
.launchInUI()
|
||||
.launchIn(scope)
|
||||
|
||||
onChange {
|
||||
if (preferences.themeMode().get() != Values.THEME_MODE_DARK) {
|
||||
@@ -173,7 +173,7 @@ class SettingsGeneralController : SettingsController() {
|
||||
isVisible = preferences.themeMode().get() != Values.THEME_MODE_LIGHT
|
||||
preferences.themeMode().asFlow()
|
||||
.onEach { isVisible = it != Values.THEME_MODE_LIGHT }
|
||||
.launchInUI()
|
||||
.launchIn(scope)
|
||||
|
||||
onChange {
|
||||
if (preferences.themeMode().get() != Values.THEME_MODE_LIGHT) {
|
||||
|
||||
@@ -4,12 +4,12 @@ import androidx.biometric.BiometricManager
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
import eu.kanade.tachiyomi.util.lang.launchInUI
|
||||
import eu.kanade.tachiyomi.util.preference.defaultValue
|
||||
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.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
|
||||
class SettingsSecurityController : SettingsController() {
|
||||
@@ -41,7 +41,7 @@ class SettingsSecurityController : SettingsController() {
|
||||
isVisible = preferences.useBiometricLock().get()
|
||||
preferences.useBiometricLock().asFlow()
|
||||
.onEach { isVisible = it }
|
||||
.launchInUI()
|
||||
.launchIn(scope)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import androidx.preference.CheckBoxPreference
|
||||
import androidx.preference.PreferenceGroup
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.source.icon
|
||||
import eu.kanade.tachiyomi.source.online.HttpSource
|
||||
@@ -25,7 +24,7 @@ class SettingsSourcesController : SettingsController() {
|
||||
titleRes = R.string.action_filter
|
||||
|
||||
// Get the list of active language codes.
|
||||
val activeLangsCodes = preferences.enabledLanguages().getOrDefault()
|
||||
val activeLangsCodes = preferences.enabledLanguages().get()
|
||||
|
||||
// Get a map of sources grouped by language.
|
||||
val sourcesByLang = onlineSources.groupByTo(TreeMap(), { it.lang })
|
||||
@@ -49,7 +48,7 @@ class SettingsSourcesController : SettingsController() {
|
||||
|
||||
onChange { newValue ->
|
||||
val checked = newValue as Boolean
|
||||
val current = preferences.enabledLanguages().getOrDefault()
|
||||
val current = preferences.enabledLanguages().get()
|
||||
if (!checked) {
|
||||
preferences.enabledLanguages().set(current - lang)
|
||||
removeAll()
|
||||
@@ -73,7 +72,7 @@ class SettingsSourcesController : SettingsController() {
|
||||
* @param group the language category.
|
||||
*/
|
||||
private fun addLanguageSources(group: PreferenceGroup, sources: List<HttpSource>) {
|
||||
val hiddenCatalogues = preferences.hiddenCatalogues().getOrDefault()
|
||||
val hiddenCatalogues = preferences.hiddenCatalogues().get()
|
||||
|
||||
sources.forEach { source ->
|
||||
val sourcePreference = CheckBoxPreference(group.context).apply {
|
||||
@@ -90,7 +89,7 @@ class SettingsSourcesController : SettingsController() {
|
||||
|
||||
onChange { newValue ->
|
||||
val checked = newValue as Boolean
|
||||
val current = preferences.hiddenCatalogues().getOrDefault()
|
||||
val current = preferences.hiddenCatalogues().get()
|
||||
|
||||
preferences.hiddenCatalogues().set(if (checked)
|
||||
current - id
|
||||
|
||||
Reference in New Issue
Block a user