diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt index 68fa2e86a..47c1ecde6 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/preference/PreferencesHelper.kt @@ -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 RxPreference.getOrDefault(): T = get() ?: defaultValue()!! fun Preference.asImmediateFlow(block: (value: T) -> Unit): Flow { block(get()) return asFlow() - .startWithCurrentValue { get() } .onEach { block(it) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt index 0a1ee1786..70723fab9 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/source/browse/BrowseSourceController.kt @@ -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,12 +191,12 @@ 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 - - // Set the adapter again to recalculate the covers height - adapter = this@BrowseSourceController.adapter - } + getColumnsPreferenceForCurrentOrientation().asImmediateFlow { spanCount = it } + .drop(1) + .onEach { + // Set the adapter again to recalculate the covers height + adapter = this@BrowseSourceController.adapter + } .launchIn(numColumnsScope!!) (layoutManager as GridLayoutManager).spanSizeLookup = object : GridLayoutManager.SpanSizeLookup() { @@ -452,7 +453,7 @@ open class BrowseSourceController(bundle: Bundle) : * * @return the preference. */ - fun getColumnsPreferenceForCurrentOrientation(): Preference { + private fun getColumnsPreferenceForCurrentOrientation(): Preference { return if (resources?.configuration?.orientation == Configuration.ORIENTATION_PORTRAIT) { preferences.portraitColumns() } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/lang/CoroutinesExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/lang/CoroutinesExtensions.kt index 576493d7c..c126c028a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/lang/CoroutinesExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/lang/CoroutinesExtensions.kt @@ -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 Flow.startWithCurrentValue(block: () -> T?): Flow { - return onStart { - block()?.let { emit(it) } - } -}