Fix library column setting jumping in
This commit is contained in:
parent
1b2c12385f
commit
f6f5b6aeab
@ -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
|
||||
|
@ -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 }
|
||||
|
@ -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<LibraryMangaEvent> = 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()
|
||||
}
|
||||
|
@ -1,3 +0,0 @@
|
||||
package eu.kanade.tachiyomi.ui.library
|
||||
|
||||
class LibraryMangaEvent(val mangas: LibraryMap)
|
@ -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()
|
||||
}
|
||||
|
@ -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()
|
||||
|
@ -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)
|
||||
|
@ -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())
|
||||
|
@ -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())
|
||||
}
|
||||
|
@ -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 <T> Preference.visibleIf(preference: com.fredporciuncula.flow.preferences.Preference<T>, crossinline block: (T) -> Boolean) {
|
||||
preference.asImmediateFlow { isVisible = block(it) }
|
||||
preference.asHotFlow { isVisible = block(it) }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
}
|
||||
|
@ -13,7 +13,7 @@ fun CompoundButton.bindToPreference(pref: Preference<Boolean>) {
|
||||
setOnCheckedChangeListener { _, isChecked -> pref.set(isChecked) }
|
||||
}
|
||||
|
||||
fun <T> Preference<T>.asImmediateFlow(block: (T) -> Unit): Flow<T> {
|
||||
fun <T> Preference<T>.asHotFlow(block: (T) -> Unit): Flow<T> {
|
||||
block(get())
|
||||
return asFlow()
|
||||
.onEach { block(it) }
|
||||
|
@ -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<PreferencesHelper>().incognitoMode().asImmediateFlow {
|
||||
Injekt.get<PreferencesHelper>().incognitoMode().asHotFlow {
|
||||
imeOptions = if (it) {
|
||||
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING
|
||||
} else {
|
||||
|
@ -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<PreferencesHelper>().incognitoMode().asImmediateFlow {
|
||||
Injekt.get<PreferencesHelper>().incognitoMode().asHotFlow {
|
||||
imeOptions = if (it) {
|
||||
imeOptions or EditorInfoCompat.IME_FLAG_NO_PERSONALIZED_LEARNING
|
||||
} else {
|
||||
|
Loading…
Reference in New Issue
Block a user