From 284c019b32d9f755442d0c17ebcc272e2660934e Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 28 Apr 2021 17:38:41 -0400 Subject: [PATCH] Cancel scope in SettingsControllers properly --- .../eu/kanade/tachiyomi/ui/setting/SettingsController.kt | 6 +++++- .../kanade/tachiyomi/ui/setting/SettingsReaderController.kt | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) 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 025457652..fed170be1 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 @@ -23,7 +23,9 @@ import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.RootController import eu.kanade.tachiyomi.util.system.getResourceColor +import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope +import kotlinx.coroutines.cancel import uy.kohesive.injekt.Injekt import uy.kohesive.injekt.api.get @@ -31,10 +33,11 @@ abstract class SettingsController : PreferenceController() { var preferenceKey: String? = null val preferences: PreferencesHelper = Injekt.get() - val viewScope = MainScope() + lateinit var viewScope: CoroutineScope private var themedContext: Context? = null override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedInstanceState: Bundle?): View { + viewScope = MainScope() val view = super.onCreateView(inflater, container, savedInstanceState) if (this is RootController) { @@ -79,6 +82,7 @@ abstract class SettingsController : PreferenceController() { override fun onDestroyView(view: View) { super.onDestroyView(view) + viewScope.cancel() themedContext = null } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index f52a9e3e1..e2ef97a56 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -35,7 +35,7 @@ class SettingsReaderController : SettingsController() { R.string.vertical_plus_viewer ) entryValues = ReadingModeType.values().drop(1) - .map { value -> "${value.flagValue}" }.toTypedArray() + .map { value -> "${value.flagValue}" }.toTypedArray() defaultValue = "${ReadingModeType.RIGHT_TO_LEFT.flagValue}" summary = "%s" }