mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-10 16:47:48 +01:00
Use lifecycleScope directly
This commit is contained in:
parent
c620c924f9
commit
b18a794eca
6 changed files with 26 additions and 26 deletions
|
@ -1,7 +1,6 @@
|
||||||
package eu.kanade.tachiyomi.ui.base.activity
|
package eu.kanade.tachiyomi.ui.base.activity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
|
||||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||||
|
@ -13,7 +12,6 @@ abstract class BaseRxActivity<VB : ViewBinding, P : BasePresenter<*>> : NucleusA
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
private val secureActivityDelegate = SecureActivityDelegate(this)
|
private val secureActivityDelegate = SecureActivityDelegate(this)
|
||||||
|
|
||||||
val scope = lifecycleScope
|
|
||||||
lateinit var binding: VB
|
lateinit var binding: VB
|
||||||
|
|
||||||
init {
|
init {
|
||||||
|
|
|
@ -1,14 +1,12 @@
|
||||||
package eu.kanade.tachiyomi.ui.base.activity
|
package eu.kanade.tachiyomi.ui.base.activity
|
||||||
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import androidx.lifecycle.lifecycleScope
|
|
||||||
import androidx.viewbinding.ViewBinding
|
import androidx.viewbinding.ViewBinding
|
||||||
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
import eu.kanade.tachiyomi.ui.security.SecureActivityDelegate
|
||||||
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
import eu.kanade.tachiyomi.util.system.LocaleHelper
|
||||||
|
|
||||||
abstract class BaseViewBindingActivity<VB : ViewBinding> : BaseThemedActivity() {
|
abstract class BaseViewBindingActivity<VB : ViewBinding> : BaseThemedActivity() {
|
||||||
|
|
||||||
val scope = lifecycleScope
|
|
||||||
lateinit var binding: VB
|
lateinit var binding: VB
|
||||||
|
|
||||||
@Suppress("LeakingThis")
|
@Suppress("LeakingThis")
|
||||||
|
|
|
@ -9,6 +9,7 @@ import android.widget.Toast
|
||||||
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
import androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.updateLayoutParams
|
import androidx.core.view.updateLayoutParams
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import androidx.preference.PreferenceDialogController
|
import androidx.preference.PreferenceDialogController
|
||||||
import com.bluelinelabs.conductor.Conductor
|
import com.bluelinelabs.conductor.Conductor
|
||||||
import com.bluelinelabs.conductor.Controller
|
import com.bluelinelabs.conductor.Controller
|
||||||
|
@ -89,7 +90,7 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||||
// Set behavior of bottom nav
|
// Set behavior of bottom nav
|
||||||
preferences.hideBottomBar()
|
preferences.hideBottomBar()
|
||||||
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
|
.asImmediateFlow { setBottomNavBehaviorOnScroll() }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
binding.bottomNav.setOnNavigationItemSelectedListener { item ->
|
binding.bottomNav.setOnNavigationItemSelectedListener { item ->
|
||||||
val id = item.itemId
|
val id = item.itemId
|
||||||
|
@ -161,15 +162,15 @@ class MainActivity : BaseViewBindingActivity<MainActivityBinding>() {
|
||||||
|
|
||||||
preferences.extensionUpdatesCount()
|
preferences.extensionUpdatesCount()
|
||||||
.asImmediateFlow { setExtensionsBadge() }
|
.asImmediateFlow { setExtensionsBadge() }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.downloadedOnly()
|
preferences.downloadedOnly()
|
||||||
.asImmediateFlow { binding.downloadedOnly.isVisible = it }
|
.asImmediateFlow { binding.downloadedOnly.isVisible = it }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.incognitoMode()
|
preferences.incognitoMode()
|
||||||
.asImmediateFlow { binding.incognitoMode.isVisible = it }
|
.asImmediateFlow { binding.incognitoMode.isVisible = it }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onNewIntent(intent: Intent) {
|
override fun onNewIntent(intent: Intent) {
|
||||||
|
|
|
@ -24,6 +24,7 @@ import androidx.core.view.ViewCompat
|
||||||
import androidx.core.view.WindowInsetsCompat
|
import androidx.core.view.WindowInsetsCompat
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.view.setPadding
|
import androidx.core.view.setPadding
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
import com.davemorrissey.labs.subscaleview.SubsamplingScaleImageView
|
||||||
import com.google.android.material.snackbar.Snackbar
|
import com.google.android.material.snackbar.Snackbar
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
|
@ -664,42 +665,42 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
delay(250)
|
delay(250)
|
||||||
setOrientation(it)
|
setOrientation(it)
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.readerTheme().asFlow()
|
preferences.readerTheme().asFlow()
|
||||||
.drop(1) // We only care about updates
|
.drop(1) // We only care about updates
|
||||||
.onEach { recreate() }
|
.onEach { recreate() }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.showPageNumber().asFlow()
|
preferences.showPageNumber().asFlow()
|
||||||
.onEach { setPageNumberVisibility(it) }
|
.onEach { setPageNumberVisibility(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.trueColor().asFlow()
|
preferences.trueColor().asFlow()
|
||||||
.onEach { setTrueColor(it) }
|
.onEach { setTrueColor(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||||
preferences.cutoutShort().asFlow()
|
preferences.cutoutShort().asFlow()
|
||||||
.onEach { setCutoutShort(it) }
|
.onEach { setCutoutShort(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
preferences.keepScreenOn().asFlow()
|
preferences.keepScreenOn().asFlow()
|
||||||
.onEach { setKeepScreenOn(it) }
|
.onEach { setKeepScreenOn(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.customBrightness().asFlow()
|
preferences.customBrightness().asFlow()
|
||||||
.onEach { setCustomBrightness(it) }
|
.onEach { setCustomBrightness(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.colorFilter().asFlow()
|
preferences.colorFilter().asFlow()
|
||||||
.onEach { setColorFilter(it) }
|
.onEach { setColorFilter(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
preferences.colorFilterMode().asFlow()
|
preferences.colorFilterMode().asFlow()
|
||||||
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -777,7 +778,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
preferences.customBrightnessValue().asFlow()
|
preferences.customBrightnessValue().asFlow()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setCustomBrightnessValue(it) }
|
.onEach { setCustomBrightnessValue(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
setCustomBrightnessValue(0)
|
setCustomBrightnessValue(0)
|
||||||
}
|
}
|
||||||
|
@ -791,7 +792,7 @@ class ReaderActivity : BaseRxActivity<ReaderActivityBinding, ReaderPresenter>()
|
||||||
preferences.colorFilterValue().asFlow()
|
preferences.colorFilterValue().asFlow()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setColorFilterValue(it) }
|
.onEach { setColorFilterValue(it) }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
binding.colorOverlay.isVisible = false
|
binding.colorOverlay.isVisible = false
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ package eu.kanade.tachiyomi.ui.reader
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
import android.widget.SeekBar
|
import android.widget.SeekBar
|
||||||
import androidx.annotation.ColorInt
|
import androidx.annotation.ColorInt
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
@ -32,15 +33,15 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet
|
||||||
|
|
||||||
preferences.colorFilter().asFlow()
|
preferences.colorFilter().asFlow()
|
||||||
.onEach { setColorFilter(it) }
|
.onEach { setColorFilter(it) }
|
||||||
.launchIn(activity.scope)
|
.launchIn(activity.lifecycleScope)
|
||||||
|
|
||||||
preferences.colorFilterMode().asFlow()
|
preferences.colorFilterMode().asFlow()
|
||||||
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
||||||
.launchIn(activity.scope)
|
.launchIn(activity.lifecycleScope)
|
||||||
|
|
||||||
preferences.customBrightness().asFlow()
|
preferences.customBrightness().asFlow()
|
||||||
.onEach { setCustomBrightness(it) }
|
.onEach { setCustomBrightness(it) }
|
||||||
.launchIn(activity.scope)
|
.launchIn(activity.lifecycleScope)
|
||||||
|
|
||||||
// Get color and update values
|
// Get color and update values
|
||||||
val color = preferences.colorFilterValue().get()
|
val color = preferences.colorFilterValue().get()
|
||||||
|
@ -178,7 +179,7 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet
|
||||||
preferences.customBrightnessValue().asFlow()
|
preferences.customBrightnessValue().asFlow()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setCustomBrightnessValue(it) }
|
.onEach { setCustomBrightnessValue(it) }
|
||||||
.launchIn(activity.scope)
|
.launchIn(activity.lifecycleScope)
|
||||||
} else {
|
} else {
|
||||||
setCustomBrightnessValue(0, true)
|
setCustomBrightnessValue(0, true)
|
||||||
}
|
}
|
||||||
|
@ -206,7 +207,7 @@ class ReaderColorFilterSheet(private val activity: ReaderActivity) : BottomSheet
|
||||||
preferences.colorFilterValue().asFlow()
|
preferences.colorFilterValue().asFlow()
|
||||||
.sample(100)
|
.sample(100)
|
||||||
.onEach { setColorFilterValue(it) }
|
.onEach { setColorFilterValue(it) }
|
||||||
.launchIn(activity.scope)
|
.launchIn(activity.lifecycleScope)
|
||||||
}
|
}
|
||||||
setColorFilterSeekBar(enabled)
|
setColorFilterSeekBar(enabled)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import android.widget.Toast
|
||||||
import androidx.core.graphics.ColorUtils
|
import androidx.core.graphics.ColorUtils
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
|
import androidx.lifecycle.lifecycleScope
|
||||||
import eu.kanade.tachiyomi.BuildConfig
|
import eu.kanade.tachiyomi.BuildConfig
|
||||||
import eu.kanade.tachiyomi.R
|
import eu.kanade.tachiyomi.R
|
||||||
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
import eu.kanade.tachiyomi.databinding.WebviewActivityBinding
|
||||||
|
@ -64,12 +65,12 @@ class WebViewActivity : BaseViewBindingActivity<WebviewActivityBinding>() {
|
||||||
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
binding.toolbar.navigationClicks()
|
binding.toolbar.navigationClicks()
|
||||||
.onEach { super.onBackPressed() }
|
.onEach { super.onBackPressed() }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
binding.swipeRefresh.isEnabled = false
|
binding.swipeRefresh.isEnabled = false
|
||||||
binding.swipeRefresh.refreshes()
|
binding.swipeRefresh.refreshes()
|
||||||
.onEach { refreshPage() }
|
.onEach { refreshPage() }
|
||||||
.launchIn(scope)
|
.launchIn(lifecycleScope)
|
||||||
|
|
||||||
if (bundle == null) {
|
if (bundle == null) {
|
||||||
binding.webview.setDefaultSettings()
|
binding.webview.setDefaultSettings()
|
||||||
|
|
Loading…
Reference in a new issue