Fix BrowseSourceController losing scroll position when navigating back
This commit is contained in:
parent
850654dccc
commit
2a41e4ce68
@ -14,7 +14,6 @@ import eu.kanade.tachiyomi.data.preference.PreferenceKeys as Keys
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues as Values
|
||||
import eu.kanade.tachiyomi.data.track.TrackService
|
||||
import eu.kanade.tachiyomi.data.track.anilist.Anilist
|
||||
import eu.kanade.tachiyomi.util.lang.startWithCurrentValue
|
||||
import java.io.File
|
||||
import java.text.DateFormat
|
||||
import java.text.SimpleDateFormat
|
||||
@ -29,7 +28,6 @@ fun <T> RxPreference<T>.getOrDefault(): T = get() ?: defaultValue()!!
|
||||
fun <T> Preference<T>.asImmediateFlow(block: (value: T) -> Unit): Flow<T> {
|
||||
block(get())
|
||||
return asFlow()
|
||||
.startWithCurrentValue { get() }
|
||||
.onEach { block(it) }
|
||||
}
|
||||
|
||||
|
@ -48,6 +48,7 @@ import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancel
|
||||
import kotlinx.coroutines.flow.drop
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
@ -190,9 +191,9 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
} else {
|
||||
(binding.catalogueView.inflate(R.layout.source_recycler_autofit) as AutofitRecyclerView).apply {
|
||||
numColumnsScope = CoroutineScope(Job() + Dispatchers.Main)
|
||||
getColumnsPreferenceForCurrentOrientation().asImmediateFlow {
|
||||
spanCount = it
|
||||
|
||||
getColumnsPreferenceForCurrentOrientation().asImmediateFlow { spanCount = it }
|
||||
.drop(1)
|
||||
.onEach {
|
||||
// Set the adapter again to recalculate the covers height
|
||||
adapter = this@BrowseSourceController.adapter
|
||||
}
|
||||
@ -452,7 +453,7 @@ open class BrowseSourceController(bundle: Bundle) :
|
||||
*
|
||||
* @return the preference.
|
||||
*/
|
||||
fun getColumnsPreferenceForCurrentOrientation(): Preference<Int> {
|
||||
private fun getColumnsPreferenceForCurrentOrientation(): Preference<Int> {
|
||||
return if (resources?.configuration?.orientation == Configuration.ORIENTATION_PORTRAIT) {
|
||||
preferences.portraitColumns()
|
||||
} else {
|
||||
|
@ -6,8 +6,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.GlobalScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
import kotlinx.coroutines.flow.onStart
|
||||
import kotlinx.coroutines.launch
|
||||
|
||||
fun launchUI(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
@ -19,10 +17,3 @@ fun launchIO(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun launchNow(block: suspend CoroutineScope.() -> Unit): Job =
|
||||
GlobalScope.launch(Dispatchers.Main, CoroutineStart.UNDISPATCHED, block)
|
||||
|
||||
@OptIn(ExperimentalCoroutinesApi::class)
|
||||
fun <T> Flow<T>.startWithCurrentValue(block: () -> T?): Flow<T> {
|
||||
return onStart {
|
||||
block()?.let { emit(it) }
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user