From b18a794eca05f4c4befb8606b9af8913d7520215 Mon Sep 17 00:00:00 2001 From: arkon Date: Thu, 7 Jan 2021 19:12:30 -0500 Subject: [PATCH] Use lifecycleScope directly --- .../ui/base/activity/BaseRxActivity.kt | 2 -- .../base/activity/BaseViewBindingActivity.kt | 2 -- .../kanade/tachiyomi/ui/main/MainActivity.kt | 9 ++++---- .../tachiyomi/ui/reader/ReaderActivity.kt | 23 ++++++++++--------- .../ui/reader/ReaderColorFilterSheet.kt | 11 +++++---- .../tachiyomi/ui/webview/WebViewActivity.kt | 5 ++-- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt index 9358da75b..396e9e64f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseRxActivity.kt @@ -1,7 +1,6 @@ package eu.kanade.tachiyomi.ui.base.activity import android.os.Bundle -import androidx.lifecycle.lifecycleScope import androidx.viewbinding.ViewBinding import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate @@ -13,7 +12,6 @@ abstract class BaseRxActivity> : NucleusA @Suppress("LeakingThis") private val secureActivityDelegate = SecureActivityDelegate(this) - val scope = lifecycleScope lateinit var binding: VB init { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseViewBindingActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseViewBindingActivity.kt index aa34eaea9..f72119e01 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseViewBindingActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/activity/BaseViewBindingActivity.kt @@ -1,14 +1,12 @@ package eu.kanade.tachiyomi.ui.base.activity import android.os.Bundle -import androidx.lifecycle.lifecycleScope import androidx.viewbinding.ViewBinding import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate import eu.kanade.tachiyomi.util.system.LocaleHelper abstract class BaseViewBindingActivity : BaseThemedActivity() { - val scope = lifecycleScope lateinit var binding: VB @Suppress("LeakingThis") 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 b8a47483c..911411b80 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 @@ -9,6 +9,7 @@ import android.widget.Toast import androidx.coordinatorlayout.widget.CoordinatorLayout import androidx.core.view.isVisible import androidx.core.view.updateLayoutParams +import androidx.lifecycle.lifecycleScope import androidx.preference.PreferenceDialogController import com.bluelinelabs.conductor.Conductor import com.bluelinelabs.conductor.Controller @@ -89,7 +90,7 @@ class MainActivity : BaseViewBindingActivity() { // Set behavior of bottom nav preferences.hideBottomBar() .asImmediateFlow { setBottomNavBehaviorOnScroll() } - .launchIn(scope) + .launchIn(lifecycleScope) binding.bottomNav.setOnNavigationItemSelectedListener { item -> val id = item.itemId @@ -161,15 +162,15 @@ class MainActivity : BaseViewBindingActivity() { preferences.extensionUpdatesCount() .asImmediateFlow { setExtensionsBadge() } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.downloadedOnly() .asImmediateFlow { binding.downloadedOnly.isVisible = it } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.incognitoMode() .asImmediateFlow { binding.incognitoMode.isVisible = it } - .launchIn(scope) + .launchIn(lifecycleScope) } override fun onNewIntent(intent: Intent) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 9e102b853..205c0d605 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -24,6 +24,7 @@ import androidx.core.view.ViewCompat import androidx.core.view.WindowInsetsCompat import androidx.core.view.isVisible import androidx.core.view.setPadding +import androidx.lifecycle.lifecycleScope import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView import com.google.android.material.snackbar.Snackbar import eu.kanade.tachiyomi.R @@ -664,42 +665,42 @@ class ReaderActivity : BaseRxActivity() delay(250) setOrientation(it) } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.readerTheme().asFlow() .drop(1) // We only care about updates .onEach { recreate() } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.showPageNumber().asFlow() .onEach { setPageNumberVisibility(it) } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.trueColor().asFlow() .onEach { setTrueColor(it) } - .launchIn(scope) + .launchIn(lifecycleScope) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) { preferences.cutoutShort().asFlow() .onEach { setCutoutShort(it) } - .launchIn(scope) + .launchIn(lifecycleScope) } preferences.keepScreenOn().asFlow() .onEach { setKeepScreenOn(it) } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.customBrightness().asFlow() .onEach { setCustomBrightness(it) } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.colorFilter().asFlow() .onEach { setColorFilter(it) } - .launchIn(scope) + .launchIn(lifecycleScope) preferences.colorFilterMode().asFlow() .onEach { setColorFilter(preferences.colorFilter().get()) } - .launchIn(scope) + .launchIn(lifecycleScope) } /** @@ -777,7 +778,7 @@ class ReaderActivity : BaseRxActivity() preferences.customBrightnessValue().asFlow() .sample(100) .onEach { setCustomBrightnessValue(it) } - .launchIn(scope) + .launchIn(lifecycleScope) } else { setCustomBrightnessValue(0) } @@ -791,7 +792,7 @@ class ReaderActivity : BaseRxActivity() preferences.colorFilterValue().asFlow() .sample(100) .onEach { setColorFilterValue(it) } - .launchIn(scope) + .launchIn(lifecycleScope) } else { binding.colorOverlay.isVisible = false } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt index 8dee52cb5..04efa20d2 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderColorFilterSheet.kt @@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader import android.view.ViewGroup import android.widget.SeekBar import androidx.annotation.ColorInt +import androidx.lifecycle.lifecycleScope import com.google.android.material.bottomsheet.BottomSheetBehavior import com.google.android.material.bottomsheet.BottomSheetDialog import eu.kanade.tachiyomi.data.preference.PreferencesHelper @@ -32,15 +33,15 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet preferences.colorFilter().asFlow() .onEach { setColorFilter(it) } - .launchIn(activity.scope) + .launchIn(activity.lifecycleScope) preferences.colorFilterMode().asFlow() .onEach { setColorFilter(preferences.colorFilter().get()) } - .launchIn(activity.scope) + .launchIn(activity.lifecycleScope) preferences.customBrightness().asFlow() .onEach { setCustomBrightness(it) } - .launchIn(activity.scope) + .launchIn(activity.lifecycleScope) // Get color and update values val color = preferences.colorFilterValue().get() @@ -178,7 +179,7 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet preferences.customBrightnessValue().asFlow() .sample(100) .onEach { setCustomBrightnessValue(it) } - .launchIn(activity.scope) + .launchIn(activity.lifecycleScope) } else { setCustomBrightnessValue(0, true) } @@ -206,7 +207,7 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet preferences.colorFilterValue().asFlow() .sample(100) .onEach { setColorFilterValue(it) } - .launchIn(activity.scope) + .launchIn(activity.lifecycleScope) } setColorFilterSeekBar(enabled) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt index ef3161fba..c43fa01c1 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/webview/WebViewActivity.kt @@ -13,6 +13,7 @@ import android.widget.Toast import androidx.core.graphics.ColorUtils import androidx.core.view.isInvisible import androidx.core.view.isVisible +import androidx.lifecycle.lifecycleScope import eu.kanade.tachiyomi.BuildConfig import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.databinding.WebviewActivityBinding @@ -64,12 +65,12 @@ class WebViewActivity : BaseViewBindingActivity() { supportActionBar?.setDisplayHomeAsUpEnabled(true) binding.toolbar.navigationClicks() .onEach { super.onBackPressed() } - .launchIn(scope) + .launchIn(lifecycleScope) binding.swipeRefresh.isEnabled = false binding.swipeRefresh.refreshes() .onEach { refreshPage() } - .launchIn(scope) + .launchIn(lifecycleScope) if (bundle == null) { binding.webview.setDefaultSettings()