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) }
}
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())
return asFlow()
.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.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
}
}

View File

@ -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) {

View File

@ -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 {