From f6f5b6aeaba6825974f4b05d279fab54a2633d76 Mon Sep 17 00:00:00 2001 From: arkon Date: Sat, 16 Jul 2022 18:26:30 -0400 Subject: [PATCH] Fix library column setting jumping in --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 4 +-- .../source/browse/BrowseSourceController.kt | 4 +-- .../tachiyomi/ui/library/LibraryController.kt | 31 +++++-------------- .../tachiyomi/ui/library/LibraryMangaEvent.kt | 3 -- .../tachiyomi/ui/library/LibraryPresenter.kt | 13 -------- .../kanade/tachiyomi/ui/main/MainActivity.kt | 8 ++--- .../tachiyomi/ui/manga/MangaPresenter.kt | 6 ++-- .../reader/setting/ReaderGeneralSettings.kt | 4 +-- .../setting/ReaderReadingModeSettings.kt | 12 +++---- .../ui/setting/SettingsController.kt | 4 +-- .../util/preference/PreferenceExtensions.kt | 2 +- .../tachiyomi/widget/TachiyomiSearchView.kt | 4 +-- .../widget/TachiyomiTextInputEditText.kt | 4 +-- 13 files changed, 33 insertions(+), 66 deletions(-) delete mode 100644 app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMangaEvent.kt diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 65469a634c..bd62bc98dd 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -35,7 +35,7 @@ import eu.kanade.tachiyomi.data.preference.PreferenceValues import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.network.NetworkHelper import eu.kanade.tachiyomi.ui.base.delegate.SecureActivityDelegate -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.AuthenticatorUtil import eu.kanade.tachiyomi.util.system.WebViewUtil import eu.kanade.tachiyomi.util.system.animatorDurationScale @@ -114,7 +114,7 @@ class App : Application(), DefaultLifecycleObserver, ImageLoaderFactory { .launchIn(ProcessLifecycleOwner.get().lifecycleScope) preferences.themeMode() - .asImmediateFlow { + .asHotFlow { AppCompatDelegate.setDefaultNightMode( when (it) { PreferenceValues.ThemeMode.light -> AppCompatDelegate.MODE_NIGHT_NO diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt index c964dfea44..590f03deae 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/source/browse/BrowseSourceController.kt @@ -45,7 +45,7 @@ import eu.kanade.tachiyomi.ui.more.MoreController import eu.kanade.tachiyomi.ui.webview.WebViewActivity import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.withUIContext -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.connectivityManager import eu.kanade.tachiyomi.util.system.logcat import eu.kanade.tachiyomi.util.system.openInBrowser @@ -218,7 +218,7 @@ open class BrowseSourceController(bundle: Bundle) : } } else { (binding.catalogueView.inflate(R.layout.source_recycler_autofit) as AutofitRecyclerView).apply { - numColumnsJob = getColumnsPreferenceForCurrentOrientation().asImmediateFlow { spanCount = it } + numColumnsJob = getColumnsPreferenceForCurrentOrientation().asHotFlow { spanCount = it } .drop(1) // Set again the adapter to recalculate the covers height .onEach { adapter = this@BrowseSourceController.adapter } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt index 8e90d1ed3e..005ef4bff8 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryController.kt @@ -32,6 +32,7 @@ import eu.kanade.tachiyomi.ui.main.MainActivity import eu.kanade.tachiyomi.ui.manga.MangaController import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.getResourceColor import eu.kanade.tachiyomi.util.system.openInBrowser import eu.kanade.tachiyomi.util.system.toast @@ -71,14 +72,8 @@ class LibraryController( */ private var actionMode: ActionModeWithToolbar? = null - /** - * Relay to notify the library's viewpager for updates. - */ - val libraryMangaRelay: BehaviorRelay = BehaviorRelay.create() + private var mangaMap: LibraryMap = emptyMap() - /** - * Adapter of the view pager. - */ private var adapter: LibraryAdapter? = null /** @@ -121,11 +116,9 @@ class LibraryController( currentCategory?.name } - if (preferences.categoryNumberOfItems().get() && libraryMangaRelay.hasValue()) { - libraryMangaRelay.value.mangas.let { mangaMap -> - if (!showCategoryTabs || adapter?.categories?.size == 1) { - title += " (${mangaMap[currentCategory?.id]?.size ?: 0})" - } + if (preferences.categoryNumberOfItems().get()) { + if (!showCategoryTabs || adapter?.categories?.size == 1) { + title += " (${mangaMap[currentCategory?.id]?.size ?: 0})" } } @@ -149,8 +142,7 @@ class LibraryController( ) getColumnsPreferenceForCurrentOrientation() - .asFlow() - .onEach { presenter.columns = it } + .asHotFlow { presenter.columns = it } .launchIn(viewScope) binding.libraryPager.adapter = adapter @@ -299,7 +291,7 @@ class LibraryController( presenter.loadedMangaFlow.value = presenter.loadedManga // Send the manga map to child fragments after the adapter is updated. - libraryMangaRelay.call(LibraryMangaEvent(mangaMap)) + this.mangaMap = mangaMap // Finally update the title updateTitle() @@ -322,9 +314,6 @@ class LibraryController( updateTitle() } - /** - * Called when the sorting mode is changed. - */ private fun onSortChanged() { presenter.requestSortUpdate() } @@ -343,9 +332,6 @@ class LibraryController( adapter.recycle = true } - /** - * Creates the action mode if it's not created already. - */ fun createActionModeIfNeeded() { val activity = activity if (actionMode == null && activity is MainActivity) { @@ -354,9 +340,6 @@ class LibraryController( } } - /** - * Destroys the action mode. - */ private fun destroyActionModeIfNeeded() { actionMode?.finish() } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMangaEvent.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMangaEvent.kt deleted file mode 100644 index fa7ad06b8c..0000000000 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryMangaEvent.kt +++ /dev/null @@ -1,3 +0,0 @@ -package eu.kanade.tachiyomi.ui.library - -class LibraryMangaEvent(val mangas: LibraryMap) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt index 5bda485086..4e319aa279 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/library/LibraryPresenter.kt @@ -44,9 +44,6 @@ import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.widget.ExtendedNavigationView.Item.TriStateGroup.State import kotlinx.coroutines.flow.MutableStateFlow -import kotlinx.coroutines.flow.drop -import kotlinx.coroutines.flow.launchIn -import kotlinx.coroutines.flow.onEach import kotlinx.coroutines.runBlocking import rx.Observable import rx.Subscription @@ -126,20 +123,10 @@ class LibraryPresenter( */ private val sortTriggerRelay = BehaviorRelay.create(Unit) - /** - * Library subscription. - */ private var librarySubscription: Subscription? = null override fun onCreate(savedState: Bundle?) { super.onCreate(savedState) - preferences.libraryDisplayMode() - .asFlow() - .drop(1) - .onEach { - currentDisplayMode = it - } - .launchIn(presenterScope) subscribeLibrary() } 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 06bc2f1454..ff3501b494 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 @@ -62,7 +62,7 @@ import eu.kanade.tachiyomi.ui.recent.updates.UpdatesController import eu.kanade.tachiyomi.ui.setting.SettingsMainController import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.dpToPx import eu.kanade.tachiyomi.util.system.getThemeColor import eu.kanade.tachiyomi.util.system.isTablet @@ -145,7 +145,7 @@ class MainActivity : BaseActivity() { if (binding.sideNav != null) { preferences.sideNavIconAlignment() - .asImmediateFlow { + .asHotFlow { binding.sideNav?.menuGravity = when (it) { 1 -> Gravity.CENTER 2 -> Gravity.BOTTOM @@ -255,11 +255,11 @@ class MainActivity : BaseActivity() { .launchIn(lifecycleScope) preferences.extensionUpdatesCount() - .asImmediateFlow { setExtensionsBadge() } + .asHotFlow { setExtensionsBadge() } .launchIn(lifecycleScope) preferences.downloadedOnly() - .asImmediateFlow { binding.downloadedOnly.isVisible = it } + .asHotFlow { binding.downloadedOnly.isVisible = it } .launchIn(lifecycleScope) binding.incognitoMode.isVisible = preferences.incognitoMode().get() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt index f0e9801789..2bc4596dc4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/manga/MangaPresenter.kt @@ -45,7 +45,7 @@ import eu.kanade.tachiyomi.util.lang.launchIO import eu.kanade.tachiyomi.util.lang.launchUI import eu.kanade.tachiyomi.util.lang.toRelativeString import eu.kanade.tachiyomi.util.lang.withUIContext -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.removeCovers import eu.kanade.tachiyomi.util.shouldDownloadNewChapters import eu.kanade.tachiyomi.util.system.logcat @@ -207,13 +207,13 @@ class MangaPresenter( } preferences.incognitoMode() - .asImmediateFlow { incognito -> + .asHotFlow { incognito -> incognitoMode = incognito } .launchIn(presenterScope) preferences.downloadedOnly() - .asImmediateFlow { downloadedOnly -> + .asHotFlow { downloadedOnly -> downloadedOnlyMode = downloadedOnly } .launchIn(presenterScope) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt index 51ad4596b9..84cc4f2be3 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderGeneralSettings.kt @@ -10,7 +10,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.databinding.ReaderGeneralSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.preference.bindToPreference import kotlinx.coroutines.flow.launchIn import uy.kohesive.injekt.injectLazy @@ -39,7 +39,7 @@ class ReaderGeneralSettings @JvmOverloads constructor(context: Context, attrs: A binding.showPageNumber.bindToPreference(preferences.showPageNumber()) binding.fullscreen.bindToPreference(preferences.fullscreen()) preferences.fullscreen() - .asImmediateFlow { + .asHotFlow { // If the preference is explicitly disabled, that means the setting was configured since there is a cutout binding.cutoutShort.isVisible = it && ((context as ReaderActivity).hasCutout || !preferences.cutoutShort().get()) binding.cutoutShort.bindToPreference(preferences.cutoutShort()) diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt index 7ce06531c8..23df4fcdca 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/setting/ReaderReadingModeSettings.kt @@ -12,7 +12,7 @@ import eu.kanade.tachiyomi.databinding.ReaderReadingModeSettingsBinding import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.pager.PagerViewer import eu.kanade.tachiyomi.ui.reader.viewer.webtoon.WebtoonViewer -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.preference.bindToPreference import kotlinx.coroutines.flow.launchIn import uy.kohesive.injekt.injectLazy @@ -73,12 +73,12 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr binding.pagerPrefsGroup.pagerNav.bindToPreference(preferences.navigationModePager()) preferences.navigationModePager() - .asImmediateFlow { binding.pagerPrefsGroup.tappingInverted.isVisible = it != 5 } + .asHotFlow { binding.pagerPrefsGroup.tappingInverted.isVisible = it != 5 } .launchIn((context as ReaderActivity).lifecycleScope) // Makes so that landscape zoom gets hidden away when image scale type is not fit screen binding.pagerPrefsGroup.scaleType.bindToPreference(preferences.imageScaleType(), 1) preferences.imageScaleType() - .asImmediateFlow { binding.pagerPrefsGroup.landscapeZoom.isVisible = it == 1 } + .asHotFlow { binding.pagerPrefsGroup.landscapeZoom.isVisible = it == 1 } .launchIn((context as ReaderActivity).lifecycleScope) binding.pagerPrefsGroup.landscapeZoom.bindToPreference(preferences.landscapeZoom()) @@ -89,7 +89,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr // Makes so that dual page invert gets hidden away when turning of dual page split binding.pagerPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitPaged()) preferences.dualPageSplitPaged() - .asImmediateFlow { binding.pagerPrefsGroup.dualPageInvert.isVisible = it } + .asHotFlow { binding.pagerPrefsGroup.dualPageInvert.isVisible = it } .launchIn((context as ReaderActivity).lifecycleScope) binding.pagerPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertPaged()) } @@ -105,7 +105,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr binding.webtoonPrefsGroup.webtoonNav.bindToPreference(preferences.navigationModeWebtoon()) preferences.navigationModeWebtoon() - .asImmediateFlow { binding.webtoonPrefsGroup.tappingInverted.isVisible = it != 5 } + .asHotFlow { binding.webtoonPrefsGroup.tappingInverted.isVisible = it != 5 } .launchIn((context as ReaderActivity).lifecycleScope) binding.webtoonPrefsGroup.cropBordersWebtoon.bindToPreference(preferences.cropBordersWebtoon()) binding.webtoonPrefsGroup.webtoonSidePadding.bindToIntPreference(preferences.webtoonSidePadding(), R.array.webtoon_side_padding_values) @@ -113,7 +113,7 @@ class ReaderReadingModeSettings @JvmOverloads constructor(context: Context, attr // Makes so that dual page invert gets hidden away when turning of dual page split binding.webtoonPrefsGroup.dualPageSplit.bindToPreference(preferences.dualPageSplitWebtoon()) preferences.dualPageSplitWebtoon() - .asImmediateFlow { binding.webtoonPrefsGroup.dualPageInvert.isVisible = it } + .asHotFlow { binding.webtoonPrefsGroup.dualPageInvert.isVisible = it } .launchIn((context as ReaderActivity).lifecycleScope) binding.webtoonPrefsGroup.dualPageInvert.bindToPreference(preferences.dualPageInvertWebtoon()) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index 48c7ec22da..436197b432 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -24,7 +24,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper import eu.kanade.tachiyomi.ui.base.controller.BaseController import eu.kanade.tachiyomi.ui.base.controller.RootController -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.util.system.getResourceColor import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.MainScope @@ -138,7 +138,7 @@ abstract class SettingsController : PreferenceController() { } inline fun Preference.visibleIf(preference: com.fredporciuncula.flow.preferences.Preference, crossinline block: (T) -> Boolean) { - preference.asImmediateFlow { isVisible = block(it) } + preference.asHotFlow { isVisible = block(it) } .launchIn(viewScope) } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt index d9098333e4..1c7db68e07 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/util/preference/PreferenceExtensions.kt @@ -13,7 +13,7 @@ fun CompoundButton.bindToPreference(pref: Preference) { setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) } } -fun Preference.asImmediateFlow(block: (T) -> Unit): Flow { +fun Preference.asHotFlow(block: (T) -> Unit): Flow { block(get()) return asFlow() .onEach { block(it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt index cc913f618a..eeb3085b71 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiSearchView.kt @@ -7,7 +7,7 @@ import androidx.appcompat.widget.SearchView import androidx.core.view.inputmethod.EditorInfoCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.SupervisorJob @@ -31,7 +31,7 @@ class TachiyomiSearchView @JvmOverloads constructor( override fun onAttachedToWindow() { super.onAttachedToWindow() scope = CoroutineScope(SupervisorJob() + Dispatchers.Main) - Injekt.get().incognitoMode().asImmediateFlow { + Injekt.get().incognitoMode().asHotFlow { imeOptions = if (it) { imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING } else { diff --git a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt index 0bbd328a66..7951062db7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/widget/TachiyomiTextInputEditText.kt @@ -7,7 +7,7 @@ import androidx.core.view.inputmethod.EditorInfoCompat import com.google.android.material.textfield.TextInputEditText import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.util.preference.asImmediateFlow +import eu.kanade.tachiyomi.util.preference.asHotFlow import eu.kanade.tachiyomi.widget.TachiyomiTextInputEditText.Companion.setIncognito import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers @@ -49,7 +49,7 @@ class TachiyomiTextInputEditText @JvmOverloads constructor( * if [PreferencesHelper.incognitoMode] is true. Some IMEs may not respect this flag. */ fun EditText.setIncognito(viewScope: CoroutineScope) { - Injekt.get().incognitoMode().asImmediateFlow { + Injekt.get().incognitoMode().asHotFlow { imeOptions = if (it) { imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING } else {