From 401210da44abbb254586674e7cc9be938ee92fc5 Mon Sep 17 00:00:00 2001 From: arkon Date: Fri, 17 Apr 2020 18:30:05 -0400 Subject: [PATCH] More FlowPreferences migrations --- .../java/eu/kanade/tachiyomi/Migrations.kt | 2 +- .../data/preference/PreferencesHelper.kt | 16 +++++++--------- .../tachiyomi/extension/ExtensionManager.kt | 3 +-- .../tachiyomi/extension/ExtensionUpdateJob.kt | 3 +-- .../extension/util/ExtensionLoader.kt | 3 +-- .../ui/base/activity/BaseActivity.kt | 7 +++---- .../ui/base/controller/BaseController.kt | 4 ++++ .../ui/base/controller/DialogController.kt | 4 ++++ .../ui/category/CategoryController.kt | 4 ---- .../ui/extension/ExtensionController.kt | 7 +------ .../extension/ExtensionDetailsController.kt | 4 ---- .../tachiyomi/ui/library/LibraryController.kt | 4 ---- .../kanade/tachiyomi/ui/main/MainActivity.kt | 2 +- .../ui/manga/chapter/ChaptersController.kt | 4 ---- .../ui/manga/info/MangaInfoController.kt | 4 ---- .../ui/manga/track/TrackController.kt | 4 ---- .../ui/manga/track/TrackSearchDialog.kt | 4 ---- .../ui/migration/SearchController.kt | 3 +-- .../tachiyomi/ui/migration/SearchPresenter.kt | 3 +-- .../ui/recent/updates/UpdatesController.kt | 4 ---- .../ui/setting/SettingsController.kt | 4 ++++ .../ui/setting/SettingsGeneralController.kt | 19 ++++++++++++------- .../ui/setting/SettingsSecurityController.kt | 4 ---- .../tachiyomi/ui/source/SourceController.kt | 4 ---- .../source/browse/BrowseSourceController.kt | 4 ---- .../global_search/GlobalSearchController.kt | 4 ---- 26 files changed, 42 insertions(+), 86 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt index d0e9b823c3..7367de7342 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/Migrations.kt @@ -28,7 +28,7 @@ object Migrations { if (BuildConfig.INCLUDE_UPDATER && preferences.automaticUpdates()) { UpdaterJob.setupTask(context) } - if (preferences.automaticExtUpdates().getOrDefault()) { + if (preferences.automaticExtUpdates().get()) { ExtensionUpdateJob.setupTask(context) } return false diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 0e2a974ac4..2de9ed1a9c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -20,8 +20,6 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi fun Preference.getOrDefault(): T = get() ?: defaultValue()!! -fun Preference.invert(): Boolean = getOrDefault().let { set(!it); !it } - private class DateFormatConverter : Preference.Adapter { override fun get(key: String, preferences: SharedPreferences): DateFormat { val dateFormat = preferences.getString(Keys.dateFormat, "")!! @@ -67,11 +65,11 @@ class PreferencesHelper(val context: Context) { fun clear() = prefs.edit().clear().apply() - fun themeMode() = rxPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM) + fun themeMode() = flowPrefs.getString(Keys.themeMode, Values.THEME_MODE_SYSTEM) - fun themeLight() = prefs.getString(Keys.themeLight, Values.THEME_DARK_DEFAULT) + fun themeLight() = flowPrefs.getString(Keys.themeLight, Values.THEME_DARK_DEFAULT) - fun themeDark() = prefs.getString(Keys.themeDark, Values.THEME_LIGHT_DEFAULT) + fun themeDark() = flowPrefs.getString(Keys.themeDark, Values.THEME_LIGHT_DEFAULT) fun rotation() = rxPrefs.getInteger(Keys.rotation, 1) @@ -194,11 +192,11 @@ class PreferencesHelper(val context: Context) { fun automaticUpdates() = prefs.getBoolean(Keys.automaticUpdates, true) - fun automaticExtUpdates() = rxPrefs.getBoolean(Keys.automaticExtUpdates, true) + fun automaticExtUpdates() = flowPrefs.getBoolean(Keys.automaticExtUpdates, true) fun extensionUpdatesCount() = rxPrefs.getInteger("ext_updates_count", 0) - fun lastExtCheck() = rxPrefs.getLong("last_ext_check", 0) + fun lastExtCheck() = flowPrefs.getLong("last_ext_check", 0) fun hiddenCatalogues() = rxPrefs.getStringSet("hidden_catalogues", emptySet()) @@ -216,9 +214,9 @@ class PreferencesHelper(val context: Context) { fun skipFiltered() = prefs.getBoolean(Keys.skipFiltered, false) - fun migrateFlags() = rxPrefs.getInteger("migrate_flags", Int.MAX_VALUE) + fun migrateFlags() = flowPrefs.getInt("migrate_flags", Int.MAX_VALUE) - fun trustedSignatures() = rxPrefs.getStringSet("trusted_signatures", emptySet()) + fun trustedSignatures() = flowPrefs.getStringSet("trusted_signatures", emptySet()) fun alwaysShowChapterTransition() = rxPrefs.getBoolean(Keys.alwaysShowChapterTransition, true) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index c85919ad6a..d7dcfcb439 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -4,7 +4,6 @@ import android.content.Context import android.graphics.drawable.Drawable import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep @@ -259,7 +258,7 @@ class ExtensionManager( ExtensionLoader.trustedSignatures += signature val preference = preferences.trustedSignatures() - preference.set(preference.getOrDefault() + signature) + preference.set(preference.get() + signature) val nowTrustedExtensions = untrustedExtensions.filter { it.signatureHash == signature } untrustedExtensions -= nowTrustedExtensions diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 4c21ccf3eb..29c2b36644 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi import eu.kanade.tachiyomi.util.system.notification import java.util.concurrent.TimeUnit @@ -65,7 +64,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam fun setupTask(context: Context, forceAutoUpdateJob: Boolean? = null) { val preferences = Injekt.get() - val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().getOrDefault() + val autoUpdateJob = forceAutoUpdateJob ?: preferences.automaticExtUpdates().get() if (autoUpdateJob) { val constraints = Constraints.Builder() .setRequiredNetworkType(NetworkType.CONNECTED) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt index 1e6dcade28..1b22e3292c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/util/ExtensionLoader.kt @@ -6,7 +6,6 @@ import android.content.pm.PackageInfo import android.content.pm.PackageManager import dalvik.system.PathClassLoader import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.LoadResult import eu.kanade.tachiyomi.source.CatalogueSource @@ -36,7 +35,7 @@ internal object ExtensionLoader { * List of the trusted signatures. */ var trustedSignatures = mutableSetOf() + - Injekt.get().trustedSignatures().getOrDefault() + + Injekt.get().trustedSignatures().get() + // inorichi's key "7ce04da7773d41b489f4693a366c36bcd0a11fc39b547168553c285bd7348e23" diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt index bc5e3584d9..e3d89e5547 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseActivity.kt @@ -7,7 +7,6 @@ import androidx.appcompat.app.AppCompatActivity import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.LocaleHelper import uy.kohesive.injekt.injectLazy @@ -20,7 +19,7 @@ abstract class BaseActivity : AppCompatActivity() { private val secureActivityDelegate = SecureActivityDelegate(this) private val lightTheme: Int by lazy { - when (preferences.themeLight()) { + when (preferences.themeLight().get()) { Values.THEME_LIGHT_BLUE -> R.style.Theme_Tachiyomi_LightBlue else -> { when { @@ -42,7 +41,7 @@ abstract class BaseActivity : AppCompatActivity() { } private val darkTheme: Int by lazy { - when (preferences.themeDark()) { + when (preferences.themeDark().get()) { Values.THEME_DARK_BLUE -> R.style.Theme_Tachiyomi_DarkBlue Values.THEME_DARK_AMOLED -> R.style.Theme_Tachiyomi_Amoled else -> R.style.Theme_Tachiyomi_Dark @@ -55,7 +54,7 @@ abstract class BaseActivity : AppCompatActivity() { } override fun onCreate(savedInstanceState: Bundle?) { - setTheme(when (preferences.themeMode().getOrDefault()) { + setTheme(when (preferences.themeMode().get()) { Values.THEME_MODE_SYSTEM -> { if (resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK == Configuration.UI_MODE_NIGHT_YES) { darkTheme diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt index 90d0664c28..b00153fa9a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/BaseController.kt @@ -12,6 +12,8 @@ import com.bluelinelabs.conductor.ControllerChangeType import com.bluelinelabs.conductor.RestoreViewOnCreateController import kotlinx.android.extensions.LayoutContainer import kotlinx.android.synthetic.clearFindViewByIdCache +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers import timber.log.Timber abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateController(bundle), @@ -41,6 +43,8 @@ abstract class BaseController(bundle: Bundle? = null) : RestoreViewOnCreateContr }) } + val uiScope = CoroutineScope(Dispatchers.Main) + override val containerView: View? get() = view diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt index 4388fa8d1d..55d746f48d 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/controller/DialogController.kt @@ -9,6 +9,8 @@ import com.bluelinelabs.conductor.RestoreViewOnCreateController import com.bluelinelabs.conductor.Router import com.bluelinelabs.conductor.RouterTransaction import com.bluelinelabs.conductor.changehandler.SimpleSwapChangeHandler +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.Dispatchers /** * A controller that displays a dialog window, floating on top of its activity's window. @@ -24,6 +26,8 @@ abstract class DialogController : RestoreViewOnCreateController { private var dismissed = false + val uiScope = CoroutineScope(Dispatchers.Main) + /** * Convenience constructor for use when no arguments are needed. */ diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt index 6f63956739..7abd5287e2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/category/CategoryController.kt @@ -18,8 +18,6 @@ import eu.kanade.tachiyomi.data.database.models.Category import eu.kanade.tachiyomi.databinding.CategoriesControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.util.system.toast -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -51,8 +49,6 @@ class CategoryController : NucleusController(), */ private var undoHelper: UndoHelper? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: CategoriesControllerBinding /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt index 79fb114bfd..a69e0102c6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionController.kt @@ -16,14 +16,11 @@ import eu.davidea.flexibleadapter.FlexibleAdapter import eu.davidea.flexibleadapter.items.IFlexible import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.databinding.ExtensionControllerBinding import eu.kanade.tachiyomi.extension.ExtensionUpdateJob import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -52,8 +49,6 @@ open class ExtensionController : NucleusController(), private var query = "" - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: ExtensionControllerBinding init { @@ -163,7 +158,7 @@ open class ExtensionController : NucleusController(), // Fixes problem with the overflow icon showing up in lieu of search searchItem.fixExpand(onExpand = { invalidateMenuOnExpand() }) - menu.findItem(R.id.action_auto_check).isChecked = preferences.automaticExtUpdates().getOrDefault() + menu.findItem(R.id.action_auto_check).isChecked = preferences.automaticExtUpdates().get() } override fun onItemClick(view: View, position: Int): Boolean { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt index 748149cd37..2b1a076866 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/extension/ExtensionDetailsController.kt @@ -32,8 +32,6 @@ import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.util.preference.preferenceCategory import eu.kanade.tachiyomi.util.system.LocaleHelper import eu.kanade.tachiyomi.util.view.visible -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -48,8 +46,6 @@ class ExtensionDetailsController(bundle: Bundle? = null) : private var preferenceScreen: PreferenceScreen? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: ExtensionDetailControllerBinding constructor(pkgName: String) : this(Bundle().apply { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index e6c3ac9613..7795ca5bc1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -39,8 +39,6 @@ import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.toast import java.io.IOException import kotlinx.android.synthetic.main.main_activity.tabs -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -128,8 +126,6 @@ class LibraryController( private var tabsVisibilitySubscription: Subscription? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: LibraryControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 35cb9153a3..4f5938f359 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -170,7 +170,7 @@ class MainActivity : BaseActivity() { private fun getExtensionUpdates() { // Limit checks to once a day at most val now = Date().time - if (now < preferences.lastExtCheck().getOrDefault() + TimeUnit.DAYS.toMillis(1)) { + if (now < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) { return } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt index 8a37afebbb..ecc9dfb093 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/chapter/ChaptersController.kt @@ -34,8 +34,6 @@ import eu.kanade.tachiyomi.util.view.gone import eu.kanade.tachiyomi.util.view.shrinkOnScroll import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -66,8 +64,6 @@ class ChaptersController : NucleusController(), private var lastClickPosition = -1 - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: ChaptersControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt index ad9bdc38eb..ae2f3380a4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/info/MangaInfoController.kt @@ -53,8 +53,6 @@ import eu.kanade.tachiyomi.util.system.toast import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible import jp.wasabeef.glide.transformations.CropSquareTransformation -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.android.view.clicks @@ -74,8 +72,6 @@ class MangaInfoController : NucleusController(), private val preferences: PreferencesHelper by injectLazy() - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: MangaInfoControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt index c0cfa5b448..c36c887742 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackController.kt @@ -12,8 +12,6 @@ import eu.kanade.tachiyomi.databinding.TrackControllerBinding import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.system.toast -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.swiperefreshlayout.refreshes @@ -27,8 +25,6 @@ class TrackController : NucleusController(), private var adapter: TrackAdapter? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: TrackControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt index dbd99e95e0..f7a0d3cdba 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/track/TrackSearchDialog.kt @@ -16,8 +16,6 @@ import java.util.concurrent.TimeUnit import kotlinx.android.synthetic.main.track_search_dialog.view.progress import kotlinx.android.synthetic.main.track_search_dialog.view.track_search import kotlinx.android.synthetic.main.track_search_dialog.view.track_search_list -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn @@ -41,8 +39,6 @@ class TrackSearchDialog : DialogController { private val trackController get() = targetController as TrackController - private val uiScope = CoroutineScope(Dispatchers.Main) - constructor(target: TrackController, service: TrackService) : super(Bundle().apply { putInt(KEY_SERVICE, service.id) }) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt index f80be95103..c78cdce964 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchController.kt @@ -6,7 +6,6 @@ import com.afollestad.materialdialogs.MaterialDialog import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.popControllerWithTag import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController @@ -77,7 +76,7 @@ class SearchController( private val preferences: PreferencesHelper by injectLazy() override fun onCreateDialog(savedViewState: Bundle?): Dialog { - val prefValue = preferences.migrateFlags().getOrDefault() + val prefValue = preferences.migrateFlags().get() val preselected = MigrationFlags.getEnabledFlagsPositions(prefValue) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt index 3c9e7e579c..354b519ff9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/migration/SearchPresenter.kt @@ -4,7 +4,6 @@ import android.os.Bundle import com.jakewharton.rxrelay.BehaviorRelay import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.MangaCategory -import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.source.Source import eu.kanade.tachiyomi.source.model.SChapter @@ -70,7 +69,7 @@ class SearchPresenter( manga: Manga, replace: Boolean ) { - val flags = preferences.migrateFlags().getOrDefault() + val flags = preferences.migrateFlags().get() val migrateChapters = MigrationFlags.hasChapters(flags) val migrateCategories = MigrationFlags.hasCategories(flags) val migrateTracks = MigrationFlags.hasTracks(flags) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt index 3aec40797e..6f54d9ca1a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/recent/updates/UpdatesController.kt @@ -27,8 +27,6 @@ import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.util.system.notificationManager import eu.kanade.tachiyomi.util.system.toast -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach import reactivecircus.flowbinding.recyclerview.scrollStateChanges @@ -61,8 +59,6 @@ class UpdatesController : NucleusController(), var adapter: UpdatesAdapter? = null private set - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: UpdatesControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index d0697eb6db..f9e26e584b 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt index b8c543a6b4..40ac063d2e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsGeneralController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt index 055a7df02f..7af0f32599 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsSecurityController.kt @@ -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 diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt index f4ea1b6cfe..aa0d5a2759 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/SourceController.kt @@ -30,8 +30,6 @@ import eu.kanade.tachiyomi.ui.setting.SettingsSourcesController import eu.kanade.tachiyomi.ui.source.browse.BrowseSourceController import eu.kanade.tachiyomi.ui.source.global_search.GlobalSearchController import eu.kanade.tachiyomi.ui.source.latest.LatestUpdatesController -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -60,8 +58,6 @@ class SourceController : NucleusController(), */ private var adapter: SourceAdapter? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: SourceMainControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index f2e791c414..967887a48f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -40,8 +40,6 @@ import eu.kanade.tachiyomi.util.view.snack import eu.kanade.tachiyomi.util.view.visible import eu.kanade.tachiyomi.widget.AutofitRecyclerView import eu.kanade.tachiyomi.widget.EmptyView -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -97,8 +95,6 @@ open class BrowseSourceController(bundle: Bundle) : */ private var progressItem: ProgressItem? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: SourceControllerBinding init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt index cfd85dc2a5..922e4f9ea8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/global_search/GlobalSearchController.kt @@ -16,8 +16,6 @@ import eu.kanade.tachiyomi.source.CatalogueSource import eu.kanade.tachiyomi.ui.base.controller.NucleusController import eu.kanade.tachiyomi.ui.base.controller.withFadeTransaction import eu.kanade.tachiyomi.ui.manga.MangaController -import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.flow.filter import kotlinx.coroutines.flow.launchIn import kotlinx.coroutines.flow.onEach @@ -40,8 +38,6 @@ open class GlobalSearchController( */ protected var adapter: GlobalSearchAdapter? = null - private val uiScope = CoroutineScope(Dispatchers.Main) - private lateinit var binding: GlobalSearchControllerBinding /**