mirror of
https://github.com/mihonapp/mihon.git
synced 2024-12-24 01:48:24 +01:00
Use lifecycleScope directly
This commit is contained in:
parent
c620c924f9
commit
b18a794eca
@ -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<VB : ViewBinding, P : BasePresenter<*>> : NucleusA
|
||||
@Suppress("LeakingThis")
|
||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||
|
||||
val scope = lifecycleScope
|
||||
lateinit var binding: VB
|
||||
|
||||
init {
|
||||
|
@ -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<VB : ViewBinding> : BaseThemedActivity() {
|
||||
|
||||
val scope = lifecycleScope
|
||||
lateinit var binding: VB
|
||||
|
||||
@Suppress("LeakingThis")
|
||||
|
@ -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<MainActivityBinding>() {
|
||||
// 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<MainActivityBinding>() {
|
||||
|
||||
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) {
|
||||
|
@ -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<ReaderActivityBinding, ReaderPresenter>()
|
||||
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<ReaderActivityBinding, ReaderPresenter>()
|
||||
preferences.customBrightnessValue().asFlow()
|
||||
.sample(100)
|
||||
.onEach { setCustomBrightnessValue(it) }
|
||||
.launchIn(scope)
|
||||
.launchIn(lifecycleScope)
|
||||
} else {
|
||||
setCustomBrightnessValue(0)
|
||||
}
|
||||
@ -791,7 +792,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||
preferences.colorFilterValue().asFlow()
|
||||
.sample(100)
|
||||
.onEach { setColorFilterValue(it) }
|
||||
.launchIn(scope)
|
||||
.launchIn(lifecycleScope)
|
||||
} else {
|
||||
binding.colorOverlay.isVisible = false
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
@ -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<WebviewActivityBinding>() {
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user