From a33f339c191dc9fbb6ec19b43cd4d4415a965a52 Mon Sep 17 00:00:00 2001 From: Jays2Kings Date: Fri, 23 Apr 2021 23:32:59 -0400 Subject: [PATCH] Rename asFlow helper method for asImmediateFlow with scope to asImmediateFlowIn --- .../data/preference/PreferencesHelper.kt | 2 +- .../tachiyomi/ui/reader/ReaderActivity.kt | 52 ++++++------------- .../ui/setting/SettingsDownloadController.kt | 4 +- .../ui/setting/SettingsReaderController.kt | 5 +- 4 files changed, 22 insertions(+), 41 deletions(-) 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 d2af243862..138c8f127c 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 @@ -36,7 +36,7 @@ fun com.tfcporciuncula.flow.Preference.asImmediateFlow(block: (value: T) .onEach { block(it) } } -fun com.tfcporciuncula.flow.Preference.asImmediateFlow(scope: CoroutineScope, block: (value: T) -> Unit): Job { +fun com.tfcporciuncula.flow.Preference.asImmediateFlowIn(scope: CoroutineScope, block: (value: T) -> Unit): Job { block(get()) return asFlow() .onEach { block(it) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt index 38bd0a6f06..bdd232ef4a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/reader/ReaderActivity.kt @@ -42,7 +42,7 @@ import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.asImmediateFlow +import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn import eu.kanade.tachiyomi.data.preference.toggle import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.source.model.Page @@ -1432,51 +1432,31 @@ class ReaderActivity : } .launchIn(scope) - preferences.showPageNumber().asFlow() - .onEach { setPageNumberVisibility(it) } - .launchIn(scope) + preferences.showPageNumber().asImmediateFlowIn(scope) { setPageNumberVisibility(it) } - preferences.trueColor().asFlow() - .onEach { setTrueColor(it) } - .launchIn(scope) + preferences.trueColor().asImmediateFlowIn(scope) { setTrueColor(it) } - preferences.fullscreen().asFlow() - .onEach { setFullscreen(it) } - .launchIn(scope) + preferences.fullscreen().asImmediateFlowIn(scope) { setFullscreen(it) } - preferences.keepScreenOn().asFlow() - .onEach { setKeepScreenOn(it) } - .launchIn(scope) + preferences.keepScreenOn().asImmediateFlowIn(scope) { setKeepScreenOn(it) } - preferences.customBrightness().asFlow() - .onEach { setCustomBrightness(it) } - .launchIn(scope) + preferences.customBrightness().asImmediateFlowIn(scope) { setCustomBrightness(it) } - preferences.colorFilter().asFlow() - .onEach { setColorFilter(it) } - .launchIn(scope) + preferences.colorFilter().asImmediateFlowIn(scope) { setColorFilter(it) } - preferences.colorFilterMode().asFlow() - .onEach { setColorFilter(preferences.colorFilter().get()) } - .launchIn(scope) + preferences.colorFilterMode().asImmediateFlowIn(scope) { + setColorFilter(preferences.colorFilter().get()) + } - preferences.alwaysShowChapterTransition().asFlow() - .onEach { showNewChapter = it } - .launchIn(scope) + preferences.alwaysShowChapterTransition().asImmediateFlowIn(scope) { + showNewChapter = it + } - preferences.pageLayout().asFlow() - .onEach { - setBottomNavButtons(it) - } - .launchIn(scope) + preferences.pageLayout().asImmediateFlowIn(scope) { setBottomNavButtons(it) } - preferences.readerBottomButtons().asFlow() - .onEach { - updateBottomShortcuts() - } - .launchIn(scope) + preferences.readerBottomButtons().asImmediateFlowIn(scope) { updateBottomShortcuts() } - preferences.readWithTapping().asImmediateFlow(scope) { + preferences.readWithTapping().asImmediateFlowIn(scope) { binding?.navigationOverlay.tappingEnabled = it } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt index 171e8591d0..bbda9da822 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsDownloadController.kt @@ -16,7 +16,7 @@ import com.hippo.unifile.UniFile import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.preference.PreferencesHelper -import eu.kanade.tachiyomi.data.preference.asImmediateFlow +import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn import eu.kanade.tachiyomi.data.preference.getOrDefault import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.util.system.getFilePicker @@ -94,7 +94,7 @@ class SettingsDownloadController : SettingsController() { entryValues = dbCategories.map { it.id.toString() } allSelectionRes = R.string.all - preferences.downloadNew().asImmediateFlow(viewScope) { isVisible = it } + preferences.downloadNew().asImmediateFlowIn(viewScope) { isVisible = it } } preferenceCategory { intListPreference(activity) { diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt index 319ad2d413..76590c95b7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsReaderController.kt @@ -4,6 +4,7 @@ import android.os.Build import androidx.preference.PreferenceScreen import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.asImmediateFlow +import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn import eu.kanade.tachiyomi.ui.reader.ReaderActivity import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout @@ -260,13 +261,13 @@ class SettingsReaderController : SettingsController() { defaultValue = 2 } infoPreference(R.string.automatic_can_still_switch).apply { - preferences.pageLayout().asImmediateFlow(viewScope) { isVisible = it == PageLayout.AUTOMATIC } + preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it == PageLayout.AUTOMATIC } } switchPreference { key = Keys.invertDoublePages titleRes = R.string.invert_double_pages defaultValue = false - preferences.pageLayout().asImmediateFlow(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE } + preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE } } } preferenceCategory {