Use 1.x preference abstraction (#8020)
* Use 1.x preference abstraction - Uses SharedPreferences compared to 1.x impl which uses DataStore but it breaks all settings screens currently - Move PreferencesHelper to new PreferenceStore - PreferencesHelper should be split into smaller preference stores and be in core or domain - Remove flow preferences as new PreferenceStore handles changes for us Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com> * Fix PreferenceMutableState not updating * Fix changes not emitting on first subscription Co-authored-by: inorichi <3521738+inorichi@users.noreply.github.com>
This commit is contained in:
@@ -82,8 +82,8 @@ class SecureActivityDelegateImpl : SecureActivityDelegate, DefaultLifecycleObser
|
||||
}
|
||||
|
||||
private fun setSecureScreen() {
|
||||
val secureScreenFlow = preferences.secureScreen().asFlow()
|
||||
val incognitoModeFlow = preferences.incognitoMode().asFlow()
|
||||
val secureScreenFlow = preferences.secureScreen().changes()
|
||||
val incognitoModeFlow = preferences.incognitoMode().changes()
|
||||
combine(secureScreenFlow, incognitoModeFlow) { secureScreen, incognitoMode ->
|
||||
secureScreen == PreferenceValues.SecureScreenMode.ALWAYS ||
|
||||
secureScreen == PreferenceValues.SecureScreenMode.INCOGNITO && incognitoMode
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package eu.kanade.tachiyomi.ui.base.presenter
|
||||
|
||||
import android.os.Bundle
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import eu.kanade.core.prefs.PreferenceMutableState
|
||||
import eu.kanade.tachiyomi.core.preference.Preference
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.MainScope
|
||||
import kotlinx.coroutines.cancel
|
||||
|
||||
@@ -123,7 +123,7 @@ class ExtensionsPresenter(
|
||||
|
||||
presenterScope.launchIO { findAvailableExtensions() }
|
||||
|
||||
preferences.extensionUpdatesCount().asFlow()
|
||||
preferences.extensionUpdatesCount().changes()
|
||||
.onEach { state.updates = it }
|
||||
.launchIn(presenterScope)
|
||||
}
|
||||
|
||||
+2
-2
@@ -42,11 +42,11 @@ class MigrationSourcesPresenter(
|
||||
}
|
||||
}
|
||||
|
||||
preferences.migrationSortingDirection().asFlow()
|
||||
preferences.migrationSortingDirection().changes()
|
||||
.onEach { state.sortingDirection = it }
|
||||
.launchIn(presenterScope)
|
||||
|
||||
preferences.migrationSortingMode().asFlow()
|
||||
preferences.migrationSortingMode().changes()
|
||||
.onEach { state.sortingMode = it }
|
||||
.launchIn(presenterScope)
|
||||
}
|
||||
|
||||
+2
-2
@@ -111,7 +111,7 @@ open class BrowseSourcePresenter(
|
||||
val isLandscape = LocalConfiguration.current.orientation == Configuration.ORIENTATION_LANDSCAPE
|
||||
return produceState<GridCells>(initialValue = GridCells.Adaptive(128.dp), isLandscape) {
|
||||
(if (isLandscape) preferences.landscapeColumns() else preferences.portraitColumns())
|
||||
.asFlow()
|
||||
.changes()
|
||||
.collectLatest { columns ->
|
||||
value = if (columns == 0) GridCells.Adaptive(128.dp) else GridCells.Fixed(columns)
|
||||
}
|
||||
@@ -257,7 +257,7 @@ open class BrowseSourcePresenter(
|
||||
fun addFavorite(manga: DomainManga) {
|
||||
presenterScope.launch {
|
||||
val categories = getCategories()
|
||||
val defaultCategoryId = preferences.defaultCategory()
|
||||
val defaultCategoryId = preferences.defaultCategory().get()
|
||||
val defaultCategory = categories.find { it.id == defaultCategoryId.toLong() }
|
||||
|
||||
when {
|
||||
|
||||
+1
-1
@@ -174,7 +174,7 @@ open class GlobalSearchController(
|
||||
* @param searchResult result of search.
|
||||
*/
|
||||
fun setItems(searchResult: List<GlobalSearchItem>) {
|
||||
if (searchResult.isEmpty() && preferences.searchPinnedSourcesOnly()) {
|
||||
if (searchResult.isEmpty() && preferences.searchPinnedSourcesOnly().get()) {
|
||||
binding.emptyView.show(R.string.no_pinned_sources)
|
||||
} else {
|
||||
binding.emptyView.hide()
|
||||
|
||||
+1
-1
@@ -123,7 +123,7 @@ open class GlobalSearchPresenter(
|
||||
return filteredSources
|
||||
}
|
||||
|
||||
val onlyPinnedSources = preferences.searchPinnedSourcesOnly()
|
||||
val onlyPinnedSources = preferences.searchPinnedSourcesOnly().get()
|
||||
val pinnedSourceIds = preferences.pinnedSources().get()
|
||||
|
||||
return enabledSources
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.library.setting
|
||||
|
||||
import eu.kanade.domain.category.model.Category
|
||||
import com.fredporciuncula.flow.preferences.Serializer as PreferencesSerializer
|
||||
|
||||
sealed class LibraryDisplayMode(
|
||||
override val flag: Long,
|
||||
@@ -14,12 +13,12 @@ sealed class LibraryDisplayMode(
|
||||
object List : LibraryDisplayMode(0b00000010)
|
||||
object CoverOnlyGrid : LibraryDisplayMode(0b00000011)
|
||||
|
||||
object Serializer : PreferencesSerializer<LibraryDisplayMode> {
|
||||
override fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
object Serializer {
|
||||
fun deserialize(serialized: String): LibraryDisplayMode {
|
||||
return LibraryDisplayMode.deserialize(serialized)
|
||||
}
|
||||
|
||||
override fun serialize(value: LibraryDisplayMode): String {
|
||||
fun serialize(value: LibraryDisplayMode): String {
|
||||
return value.serialize()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.library.setting
|
||||
|
||||
import eu.kanade.domain.category.model.Category
|
||||
import com.fredporciuncula.flow.preferences.Serializer as PreferencesSerializer
|
||||
|
||||
data class LibrarySort(
|
||||
val type: Type,
|
||||
@@ -57,12 +56,12 @@ data class LibrarySort(
|
||||
}
|
||||
}
|
||||
|
||||
object Serializer : PreferencesSerializer<LibrarySort> {
|
||||
override fun deserialize(serialized: String): LibrarySort {
|
||||
object Serializer {
|
||||
fun deserialize(serialized: String): LibrarySort {
|
||||
return LibrarySort.deserialize(serialized)
|
||||
}
|
||||
|
||||
override fun serialize(value: LibrarySort): String {
|
||||
fun serialize(value: LibrarySort): String {
|
||||
return value.serialize()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +72,8 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.merge
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import logcat.LogPriority
|
||||
import uy.kohesive.injekt.Injekt
|
||||
import uy.kohesive.injekt.api.get
|
||||
import uy.kohesive.injekt.injectLazy
|
||||
|
||||
class MainActivity : BaseActivity() {
|
||||
@@ -105,7 +107,15 @@ class MainActivity : BaseActivity() {
|
||||
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
val didMigration = if (savedInstanceState == null) Migrations.upgrade(preferences) else false
|
||||
val didMigration = if (savedInstanceState == null) {
|
||||
Migrations.upgrade(
|
||||
context = applicationContext,
|
||||
preferences = preferences,
|
||||
networkPreferences = Injekt.get(),
|
||||
)
|
||||
} else {
|
||||
false
|
||||
}
|
||||
|
||||
binding = MainActivityBinding.inflate(layoutInflater)
|
||||
|
||||
@@ -240,7 +250,7 @@ class MainActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
merge(preferences.showUpdatesNavBadge().asFlow(), preferences.unreadUpdatesCount().asFlow())
|
||||
merge(preferences.showUpdatesNavBadge().changes(), preferences.unreadUpdatesCount().changes())
|
||||
.onEach { setUnreadUpdatesBadge() }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
@@ -253,7 +263,7 @@ class MainActivity : BaseActivity() {
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
binding.incognitoMode.isVisible = preferences.incognitoMode().get()
|
||||
preferences.incognitoMode().asFlow()
|
||||
preferences.incognitoMode().changes()
|
||||
.drop(1)
|
||||
.onEach {
|
||||
binding.incognitoMode.isVisible = it
|
||||
@@ -490,7 +500,7 @@ class MainActivity : BaseActivity() {
|
||||
lifecycleScope.launchUI { resetExitConfirmation() }
|
||||
} else if (backstackSize == 1 || !router.handleBack()) {
|
||||
// Regular back (i.e. closing the app)
|
||||
if (preferences.autoClearChapterCache()) {
|
||||
if (preferences.autoClearChapterCache().get()) {
|
||||
chapterCache.clear()
|
||||
}
|
||||
super.onBackPressed()
|
||||
@@ -534,7 +544,7 @@ class MainActivity : BaseActivity() {
|
||||
private fun shouldHandleExitConfirmation(): Boolean {
|
||||
return router.backstackSize == 1 &&
|
||||
router.getControllerWithTag("$startScreenId") != null &&
|
||||
preferences.confirmExit() &&
|
||||
preferences.confirmExit().get() &&
|
||||
!isConfirmingExit
|
||||
}
|
||||
|
||||
|
||||
@@ -283,7 +283,7 @@ class MangaPresenter(
|
||||
|
||||
// Now check if user previously set categories, when available
|
||||
val categories = getCategories()
|
||||
val defaultCategoryId = preferences.defaultCategory().toLong()
|
||||
val defaultCategoryId = preferences.defaultCategory().get().toLong()
|
||||
val defaultCategory = categories.find { it.id == defaultCategoryId }
|
||||
when {
|
||||
// Default category set
|
||||
|
||||
@@ -194,7 +194,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
initializeMenu()
|
||||
|
||||
// Finish when incognito mode is disabled
|
||||
preferences.incognitoMode().asFlow()
|
||||
preferences.incognitoMode().changes()
|
||||
.drop(1)
|
||||
.onEach { if (!it) finish() }
|
||||
.launchIn(lifecycleScope)
|
||||
@@ -446,7 +446,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
presenter.setMangaReadingMode(newReadingMode.flagValue)
|
||||
|
||||
menuToggleToast?.cancel()
|
||||
if (!preferences.showReadingMode()) {
|
||||
if (!preferences.showReadingMode().get()) {
|
||||
menuToggleToast = toast(newReadingMode.stringRes)
|
||||
}
|
||||
|
||||
@@ -480,7 +480,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
updateCropBordersShortcut()
|
||||
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
|
||||
.forEach { pref ->
|
||||
pref.asFlow()
|
||||
pref.changes()
|
||||
.onEach { updateCropBordersShortcut() }
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
@@ -493,7 +493,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
popupMenu(
|
||||
items = OrientationType.values().map { it.flagValue to it.stringRes },
|
||||
selectedItemId = presenter.manga?.orientationType
|
||||
?: preferences.defaultOrientationType(),
|
||||
?: preferences.defaultOrientationType().get(),
|
||||
) {
|
||||
val newOrientation = OrientationType.fromPreference(itemId)
|
||||
|
||||
@@ -635,7 +635,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
updateViewerInset(preferences.fullscreen().get())
|
||||
binding.viewerContainer.addView(newViewer.getView())
|
||||
|
||||
if (preferences.showReadingMode()) {
|
||||
if (preferences.showReadingMode().get()) {
|
||||
showReadingModeToast(presenter.getMangaReadingMode())
|
||||
}
|
||||
|
||||
@@ -949,7 +949,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
* Initializes the reader subscriptions.
|
||||
*/
|
||||
init {
|
||||
preferences.readerTheme().asFlow()
|
||||
preferences.readerTheme().changes()
|
||||
.onEach {
|
||||
binding.readerContainer.setBackgroundResource(
|
||||
when (preferences.readerTheme().get()) {
|
||||
@@ -962,41 +962,41 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.showPageNumber().asFlow()
|
||||
preferences.showPageNumber().changes()
|
||||
.onEach { setPageNumberVisibility(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.trueColor().asFlow()
|
||||
preferences.trueColor().changes()
|
||||
.onEach { setTrueColor(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
|
||||
preferences.cutoutShort().asFlow()
|
||||
preferences.cutoutShort().changes()
|
||||
.onEach { setCutoutShort(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
}
|
||||
|
||||
preferences.keepScreenOn().asFlow()
|
||||
preferences.keepScreenOn().changes()
|
||||
.onEach { setKeepScreenOn(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.customBrightness().asFlow()
|
||||
preferences.customBrightness().changes()
|
||||
.onEach { setCustomBrightness(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.colorFilter().asFlow()
|
||||
preferences.colorFilter().changes()
|
||||
.onEach { setColorFilter(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.colorFilterMode().asFlow()
|
||||
preferences.colorFilterMode().changes()
|
||||
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
merge(preferences.grayscale().asFlow(), preferences.invertedColors().asFlow())
|
||||
merge(preferences.grayscale().changes(), preferences.invertedColors().changes())
|
||||
.onEach { setLayerPaint(preferences.grayscale().get(), preferences.invertedColors().get()) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
preferences.fullscreen().asFlow()
|
||||
preferences.fullscreen().changes()
|
||||
.onEach {
|
||||
WindowCompat.setDecorFitsSystemWindows(window, !it)
|
||||
updateViewerInset(it)
|
||||
@@ -1060,7 +1060,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
*/
|
||||
private fun setCustomBrightness(enabled: Boolean) {
|
||||
if (enabled) {
|
||||
preferences.customBrightnessValue().asFlow()
|
||||
preferences.customBrightnessValue().changes()
|
||||
.sample(100)
|
||||
.onEach { setCustomBrightnessValue(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
@@ -1074,7 +1074,7 @@ class ReaderActivity : BaseRxActivity<ReaderPresenter>() {
|
||||
*/
|
||||
private fun setColorFilter(enabled: Boolean) {
|
||||
if (enabled) {
|
||||
preferences.colorFilterValue().asFlow()
|
||||
preferences.colorFilterValue().changes()
|
||||
.sample(100)
|
||||
.onEach { setColorFilterValue(it) }
|
||||
.launchIn(lifecycleScope)
|
||||
|
||||
@@ -140,11 +140,11 @@ class ReaderPresenter(
|
||||
?: error("Requested chapter of id $chapterId not found in chapter list")
|
||||
|
||||
val chaptersForReader = when {
|
||||
(preferences.skipRead() || preferences.skipFiltered()) -> {
|
||||
(preferences.skipRead().get() || preferences.skipFiltered().get()) -> {
|
||||
val filteredChapters = chapters.filterNot {
|
||||
when {
|
||||
preferences.skipRead() && it.read -> true
|
||||
preferences.skipFiltered() -> {
|
||||
preferences.skipRead().get() && it.read -> true
|
||||
preferences.skipFiltered().get() -> {
|
||||
(manga.readFilter == DomainManga.CHAPTER_SHOW_READ.toInt() && !it.read) ||
|
||||
(manga.readFilter == DomainManga.CHAPTER_SHOW_UNREAD.toInt() && it.read) ||
|
||||
(manga.downloadedFilter == DomainManga.CHAPTER_SHOW_DOWNLOADED.toInt() && !downloadManager.isChapterDownloaded(it.name, it.scanlator, manga.title, manga.source)) ||
|
||||
@@ -502,7 +502,7 @@ class ReaderPresenter(
|
||||
private fun deleteChapterIfNeeded(currentChapter: ReaderChapter) {
|
||||
// Determine which chapter should be deleted and enqueue
|
||||
val currentChapterPosition = chapterList.indexOf(currentChapter)
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots()
|
||||
val removeAfterReadSlots = preferences.removeAfterReadSlots().get()
|
||||
val chapterToDelete = chapterList.getOrNull(currentChapterPosition - removeAfterReadSlots)
|
||||
|
||||
if (removeAfterReadSlots != 0 && chapterDownload != null) {
|
||||
@@ -619,7 +619,7 @@ class ReaderPresenter(
|
||||
* Returns the viewer position used by this manga or the default one.
|
||||
*/
|
||||
fun getMangaReadingMode(resolveDefault: Boolean = true): Int {
|
||||
val default = preferences.defaultReadingMode()
|
||||
val default = preferences.defaultReadingMode().get()
|
||||
val readingMode = ReadingModeType.fromPreference(manga?.readingModeType)
|
||||
return when {
|
||||
resolveDefault && readingMode == ReadingModeType.DEFAULT -> default
|
||||
@@ -656,7 +656,7 @@ class ReaderPresenter(
|
||||
* Returns the orientation type used by this manga or the default one.
|
||||
*/
|
||||
fun getMangaOrientationType(resolveDefault: Boolean = true): Int {
|
||||
val default = preferences.defaultOrientationType()
|
||||
val default = preferences.defaultOrientationType().get()
|
||||
val orientation = OrientationType.fromPreference(manga?.orientationType)
|
||||
return when {
|
||||
resolveDefault && orientation == OrientationType.DEFAULT -> default
|
||||
@@ -714,7 +714,7 @@ class ReaderPresenter(
|
||||
val filename = generateFilename(manga, page)
|
||||
|
||||
// Pictures directory.
|
||||
val relativePath = if (preferences.folderPerManga()) DiskUtil.buildValidFilename(manga.title) else ""
|
||||
val relativePath = if (preferences.folderPerManga().get()) DiskUtil.buildValidFilename(manga.title) else ""
|
||||
|
||||
// Copy file in background.
|
||||
try {
|
||||
@@ -818,7 +818,7 @@ class ReaderPresenter(
|
||||
* will run in a background thread and errors are ignored.
|
||||
*/
|
||||
private fun updateTrackChapterRead(readerChapter: ReaderChapter) {
|
||||
if (!preferences.autoUpdateTrack()) return
|
||||
if (!preferences.autoUpdateTrack().get()) return
|
||||
val manga = manga ?: return
|
||||
|
||||
val chapterRead = readerChapter.chapter.chapter_number.toDouble()
|
||||
|
||||
+5
-5
@@ -32,15 +32,15 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
||||
init {
|
||||
addView(binding.root)
|
||||
|
||||
preferences.colorFilter().asFlow()
|
||||
preferences.colorFilter().changes()
|
||||
.onEach { setColorFilter(it) }
|
||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||
|
||||
preferences.colorFilterMode().asFlow()
|
||||
preferences.colorFilterMode().changes()
|
||||
.onEach { setColorFilter(preferences.colorFilter().get()) }
|
||||
.launchIn(context.lifecycleScope)
|
||||
|
||||
preferences.customBrightness().asFlow()
|
||||
preferences.customBrightness().changes()
|
||||
.onEach { setCustomBrightness(it) }
|
||||
.launchIn(context.lifecycleScope)
|
||||
|
||||
@@ -139,7 +139,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
||||
*/
|
||||
private fun setCustomBrightness(enabled: Boolean) {
|
||||
if (enabled) {
|
||||
preferences.customBrightnessValue().asFlow()
|
||||
preferences.customBrightnessValue().changes()
|
||||
.sample(100)
|
||||
.onEach { setCustomBrightnessValue(it) }
|
||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||
@@ -167,7 +167,7 @@ class ReaderColorFilterSettings @JvmOverloads constructor(context: Context, attr
|
||||
*/
|
||||
private fun setColorFilter(enabled: Boolean) {
|
||||
if (enabled) {
|
||||
preferences.colorFilterValue().asFlow()
|
||||
preferences.colorFilterValue().changes()
|
||||
.sample(100)
|
||||
.onEach { setColorFilterValue(it) }
|
||||
.launchIn((context as ReaderActivity).lifecycleScope)
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package eu.kanade.tachiyomi.ui.reader.viewer
|
||||
|
||||
import com.fredporciuncula.flow.preferences.Preference
|
||||
import eu.kanade.tachiyomi.core.preference.Preference
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues.TappingInvertMode
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
@@ -80,7 +80,7 @@ abstract class ViewerConfig(preferences: PreferencesHelper, private val scope: C
|
||||
valueAssignment: (T) -> Unit,
|
||||
onChanged: (T) -> Unit = {},
|
||||
) {
|
||||
asFlow()
|
||||
changes()
|
||||
.onEach { valueAssignment(it) }
|
||||
.distinctUntilChanged()
|
||||
.onEach { onChanged(it) }
|
||||
|
||||
@@ -78,7 +78,7 @@ class PagerConfig(
|
||||
|
||||
preferences.pagerNavInverted()
|
||||
.register({ tappingInverted = it }, { navigator.invertMode = it })
|
||||
preferences.pagerNavInverted().asFlow()
|
||||
preferences.pagerNavInverted().changes()
|
||||
.drop(1)
|
||||
.onEach { navigationModeChangedListener?.invoke() }
|
||||
.launchIn(scope)
|
||||
|
||||
@@ -51,7 +51,7 @@ class WebtoonConfig(
|
||||
|
||||
preferences.webtoonNavInverted()
|
||||
.register({ tappingInverted = it }, { navigator.invertMode = it })
|
||||
preferences.webtoonNavInverted().asFlow()
|
||||
preferences.webtoonNavInverted().changes()
|
||||
.drop(1)
|
||||
.onEach { navigationModeChangedListener?.invoke() }
|
||||
.launchIn(scope)
|
||||
@@ -71,7 +71,7 @@ class WebtoonConfig(
|
||||
},
|
||||
)
|
||||
|
||||
preferences.readerTheme().asFlow()
|
||||
preferences.readerTheme().changes()
|
||||
.drop(1)
|
||||
.distinctUntilChanged()
|
||||
.onEach { themeChangedListener?.invoke() }
|
||||
|
||||
@@ -17,6 +17,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService.Target
|
||||
import eu.kanade.tachiyomi.data.preference.PreferenceValues
|
||||
import eu.kanade.tachiyomi.data.track.TrackManager
|
||||
import eu.kanade.tachiyomi.network.NetworkHelper
|
||||
import eu.kanade.tachiyomi.network.NetworkPreferences
|
||||
import eu.kanade.tachiyomi.network.PREF_DOH_360
|
||||
import eu.kanade.tachiyomi.network.PREF_DOH_ADGUARD
|
||||
import eu.kanade.tachiyomi.network.PREF_DOH_ALIDNS
|
||||
@@ -69,6 +70,7 @@ class SettingsAdvancedController(
|
||||
private val network: NetworkHelper by injectLazy()
|
||||
private val chapterCache: ChapterCache by injectLazy()
|
||||
private val trackManager: TrackManager by injectLazy()
|
||||
private val networkPreferences: NetworkPreferences by injectLazy()
|
||||
|
||||
@SuppressLint("BatteryLife")
|
||||
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
|
||||
@@ -96,7 +98,7 @@ class SettingsAdvancedController(
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
key = Keys.verboseLogging
|
||||
key = networkPreferences.verboseLogging().key()
|
||||
titleRes = R.string.pref_verbose_logging
|
||||
summaryRes = R.string.pref_verbose_logging_summary
|
||||
defaultValue = isDevFlavor
|
||||
@@ -189,7 +191,7 @@ class SettingsAdvancedController(
|
||||
onClick { clearWebViewData() }
|
||||
}
|
||||
intListPreference {
|
||||
key = Keys.dohProvider
|
||||
key = networkPreferences.dohProvider().key()
|
||||
titleRes = R.string.pref_dns_over_https
|
||||
entries = arrayOf(
|
||||
context.getString(R.string.disabled),
|
||||
@@ -227,10 +229,11 @@ class SettingsAdvancedController(
|
||||
true
|
||||
}
|
||||
}
|
||||
val defaultUserAgent = networkPreferences.defaultUserAgent()
|
||||
editTextPreference {
|
||||
key = Keys.defaultUserAgent
|
||||
key = defaultUserAgent.key()
|
||||
titleRes = R.string.pref_user_agent_string
|
||||
text = preferences.defaultUserAgent().get()
|
||||
text = defaultUserAgent.get()
|
||||
summary = network.defaultUserAgent
|
||||
|
||||
onChange {
|
||||
@@ -247,10 +250,10 @@ class SettingsAdvancedController(
|
||||
key = "pref_reset_user_agent"
|
||||
titleRes = R.string.pref_reset_user_agent_string
|
||||
|
||||
visibleIf(preferences.defaultUserAgent()) { it != preferences.defaultUserAgent().defaultValue }
|
||||
visibleIf(defaultUserAgent) { it != defaultUserAgent.defaultValue() }
|
||||
|
||||
onClick {
|
||||
preferences.defaultUserAgent().delete()
|
||||
defaultUserAgent.delete()
|
||||
activity?.toast(R.string.requires_app_restart)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ class SettingsBackupController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
preferences.backupsDirectory().asFlow()
|
||||
preferences.backupsDirectory().changes()
|
||||
.onEach { path ->
|
||||
val dir = UniFile.fromUri(context, path.toUri())
|
||||
summary = dir.filePath + "/automatic"
|
||||
|
||||
@@ -130,7 +130,7 @@ abstract class SettingsController : PreferenceController() {
|
||||
(activity as? AppCompatActivity)?.supportActionBar?.title = getTitle()
|
||||
}
|
||||
|
||||
inline fun <T> Preference.visibleIf(preference: com.fredporciuncula.flow.preferences.Preference<T>, crossinline block: (T) -> Boolean) {
|
||||
inline fun <T> Preference.visibleIf(preference: eu.kanade.tachiyomi.core.preference.Preference<T>, crossinline block: (T) -> Boolean) {
|
||||
preference.asHotFlow { isVisible = block(it) }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class SettingsDownloadController : SettingsController() {
|
||||
ctrl.showDialog(router)
|
||||
}
|
||||
|
||||
preferences.downloadsDirectory().asFlow()
|
||||
preferences.downloadsDirectory().changes()
|
||||
.onEach { path ->
|
||||
val dir = UniFile.fromUri(context, path.toUri())
|
||||
summary = dir.filePath ?: path
|
||||
@@ -114,7 +114,7 @@ class SettingsDownloadController : SettingsController() {
|
||||
entries = categories.map { it.visualName(context) }.toTypedArray()
|
||||
entryValues = categories.map { it.id.toString() }.toTypedArray()
|
||||
|
||||
preferences.removeExcludeCategories().asFlow()
|
||||
preferences.removeExcludeCategories().changes()
|
||||
.onEach { mutable ->
|
||||
val selected = mutable
|
||||
.mapNotNull { id -> categories.find { it.id == id.toLong() } }
|
||||
@@ -171,10 +171,10 @@ class SettingsDownloadController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
preferences.downloadNewChapterCategories().asFlow()
|
||||
preferences.downloadNewChapterCategories().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
preferences.downloadNewChapterCategoriesExclude().asFlow()
|
||||
preferences.downloadNewChapterCategoriesExclude().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
combine(preferences.portraitColumns().asFlow(), preferences.landscapeColumns().asFlow()) { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) }
|
||||
combine(preferences.portraitColumns().changes(), preferences.landscapeColumns().changes()) { portraitCols, landscapeCols -> Pair(portraitCols, landscapeCols) }
|
||||
.onEach { (portraitCols, landscapeCols) ->
|
||||
val portrait = getColumnValue(portraitCols)
|
||||
val landscape = getColumnValue(landscapeCols)
|
||||
@@ -114,7 +114,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
entryValues = arrayOf("-1") + allCategories.map { it.id.toString() }.toTypedArray()
|
||||
defaultValue = "-1"
|
||||
|
||||
val selectedCategory = allCategories.find { it.id == preferences.defaultCategory().toLong() }
|
||||
val selectedCategory = allCategories.find { it.id == preferences.defaultCategory().get().toLong() }
|
||||
summary = selectedCategory?.visualName(context)
|
||||
?: context.getString(R.string.default_category_summary)
|
||||
onChange { newValue ->
|
||||
@@ -129,7 +129,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
bindTo(preferences.categorizedDisplaySettings())
|
||||
titleRes = R.string.categorized_display_settings
|
||||
|
||||
preferences.categorizedDisplaySettings().asFlow()
|
||||
preferences.categorizedDisplaySettings().changes()
|
||||
.onEach {
|
||||
if (it.not()) {
|
||||
resetCategoryFlags.await()
|
||||
@@ -197,7 +197,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
summary = context.getString(R.string.restrictions, restrictionsText)
|
||||
}
|
||||
|
||||
preferences.libraryUpdateDeviceRestriction().asFlow()
|
||||
preferences.libraryUpdateDeviceRestriction().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
@@ -226,7 +226,7 @@ class SettingsLibraryController : SettingsController() {
|
||||
summary = restrictionsText
|
||||
}
|
||||
|
||||
preferences.libraryUpdateMangaRestriction().asFlow()
|
||||
preferences.libraryUpdateMangaRestriction().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
@@ -269,10 +269,10 @@ class SettingsLibraryController : SettingsController() {
|
||||
}
|
||||
}
|
||||
|
||||
preferences.libraryUpdateCategories().asFlow()
|
||||
preferences.libraryUpdateCategories().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
preferences.libraryUpdateCategoriesExclude().asFlow()
|
||||
preferences.libraryUpdateCategoriesExclude().changes()
|
||||
.onEach { updateSummary() }
|
||||
.launchIn(viewScope)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user