Rename asFlow helper method

for asImmediateFlow with scope to asImmediateFlowIn
This commit is contained in:
Jays2Kings 2021-04-23 23:32:59 -04:00
parent ec87df7056
commit a33f339c19
4 changed files with 22 additions and 41 deletions

View File

@ -36,7 +36,7 @@ fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlow(block: (value: T)
.onEach { block(it) } .onEach { block(it) }
} }
fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlow(scope: CoroutineScope, block: (value: T) -> Unit): Job { fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlowIn(scope: CoroutineScope, block: (value: T) -> Unit): Job {
block(get()) block(get())
return asFlow() return asFlow()
.onEach { block(it) } .onEach { block(it) }

View File

@ -42,7 +42,7 @@ import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.models.Chapter import eu.kanade.tachiyomi.data.database.models.Chapter
import eu.kanade.tachiyomi.data.database.models.Manga import eu.kanade.tachiyomi.data.database.models.Manga
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.data.preference.toggle
import eu.kanade.tachiyomi.databinding.ReaderActivityBinding import eu.kanade.tachiyomi.databinding.ReaderActivityBinding
import eu.kanade.tachiyomi.source.model.Page import eu.kanade.tachiyomi.source.model.Page
@ -1432,51 +1432,31 @@ class ReaderActivity :
} }
.launchIn(scope) .launchIn(scope)
preferences.showPageNumber().asFlow() preferences.showPageNumber().asImmediateFlowIn(scope) { setPageNumberVisibility(it) }
.onEach { setPageNumberVisibility(it) }
.launchIn(scope)
preferences.trueColor().asFlow() preferences.trueColor().asImmediateFlowIn(scope) { setTrueColor(it) }
.onEach { setTrueColor(it) }
.launchIn(scope)
preferences.fullscreen().asFlow() preferences.fullscreen().asImmediateFlowIn(scope) { setFullscreen(it) }
.onEach { setFullscreen(it) }
.launchIn(scope)
preferences.keepScreenOn().asFlow() preferences.keepScreenOn().asImmediateFlowIn(scope) { setKeepScreenOn(it) }
.onEach { setKeepScreenOn(it) }
.launchIn(scope)
preferences.customBrightness().asFlow() preferences.customBrightness().asImmediateFlowIn(scope) { setCustomBrightness(it) }
.onEach { setCustomBrightness(it) }
.launchIn(scope)
preferences.colorFilter().asFlow() preferences.colorFilter().asImmediateFlowIn(scope) { setColorFilter(it) }
.onEach { setColorFilter(it) }
.launchIn(scope)
preferences.colorFilterMode().asFlow() preferences.colorFilterMode().asImmediateFlowIn(scope) {
.onEach { setColorFilter(preferences.colorFilter().get()) } setColorFilter(preferences.colorFilter().get())
.launchIn(scope)
preferences.alwaysShowChapterTransition().asFlow()
.onEach { showNewChapter = it }
.launchIn(scope)
preferences.pageLayout().asFlow()
.onEach {
setBottomNavButtons(it)
} }
.launchIn(scope)
preferences.readerBottomButtons().asFlow() preferences.alwaysShowChapterTransition().asImmediateFlowIn(scope) {
.onEach { showNewChapter = it
updateBottomShortcuts()
} }
.launchIn(scope)
preferences.readWithTapping().asImmediateFlow(scope) { preferences.pageLayout().asImmediateFlowIn(scope) { setBottomNavButtons(it) }
preferences.readerBottomButtons().asImmediateFlowIn(scope) { updateBottomShortcuts() }
preferences.readWithTapping().asImmediateFlowIn(scope) {
binding?.navigationOverlay.tappingEnabled = it binding?.navigationOverlay.tappingEnabled = it
} }
} }

View File

@ -16,7 +16,7 @@ import com.hippo.unifile.UniFile
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.database.DatabaseHelper import eu.kanade.tachiyomi.data.database.DatabaseHelper
import eu.kanade.tachiyomi.data.preference.PreferencesHelper 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.data.preference.getOrDefault
import eu.kanade.tachiyomi.ui.base.controller.DialogController import eu.kanade.tachiyomi.ui.base.controller.DialogController
import eu.kanade.tachiyomi.util.system.getFilePicker import eu.kanade.tachiyomi.util.system.getFilePicker
@ -94,7 +94,7 @@ class SettingsDownloadController : SettingsController() {
entryValues = dbCategories.map { it.id.toString() } entryValues = dbCategories.map { it.id.toString() }
allSelectionRes = R.string.all allSelectionRes = R.string.all
preferences.downloadNew().asImmediateFlow(viewScope) { isVisible = it } preferences.downloadNew().asImmediateFlowIn(viewScope) { isVisible = it }
} }
preferenceCategory { preferenceCategory {
intListPreference(activity) { intListPreference(activity) {

View File

@ -4,6 +4,7 @@ import android.os.Build
import androidx.preference.PreferenceScreen import androidx.preference.PreferenceScreen
import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.asImmediateFlow 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.ReaderActivity
import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation import eu.kanade.tachiyomi.ui.reader.viewer.ViewerNavigation
import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout import eu.kanade.tachiyomi.ui.reader.viewer.pager.PageLayout
@ -260,13 +261,13 @@ class SettingsReaderController : SettingsController() {
defaultValue = 2 defaultValue = 2
} }
infoPreference(R.string.automatic_can_still_switch).apply { 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 { switchPreference {
key = Keys.invertDoublePages key = Keys.invertDoublePages
titleRes = R.string.invert_double_pages titleRes = R.string.invert_double_pages
defaultValue = false defaultValue = false
preferences.pageLayout().asImmediateFlow(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE } preferences.pageLayout().asImmediateFlowIn(viewScope) { isVisible = it != PageLayout.SINGLE_PAGE }
} }
} }
preferenceCategory { preferenceCategory {