mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-11-09 19:55:11 +01:00
Helper method for list of preferences flow
This commit is contained in:
parent
820d240997
commit
47f6c54412
@ -43,6 +43,17 @@ fun <T> com.tfcporciuncula.flow.Preference<T>.asImmediateFlowIn(scope: Coroutine
|
|||||||
.launchIn(scope)
|
.launchIn(scope)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun <T> Collection<com.tfcporciuncula.flow.Preference<out T>>.asFlowsIn(scope: CoroutineScope, dropFirst: Boolean = false, block: () -> Unit): Collection<Job> {
|
||||||
|
return map { pref ->
|
||||||
|
pref.asFlow()
|
||||||
|
.apply {
|
||||||
|
if (dropFirst) drop(1)
|
||||||
|
}
|
||||||
|
.onEach { block() }
|
||||||
|
.launchIn(scope)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fun com.tfcporciuncula.flow.Preference<Boolean>.toggle() = set(!get())
|
fun com.tfcporciuncula.flow.Preference<Boolean>.toggle() = set(!get())
|
||||||
|
|
||||||
private class DateFormatConverter : Preference.Adapter<DateFormat> {
|
private class DateFormatConverter : Preference.Adapter<DateFormat> {
|
||||||
|
@ -51,6 +51,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asFlowsIn
|
||||||
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.databinding.LibraryControllerBinding
|
import eu.kanade.tachiyomi.databinding.LibraryControllerBinding
|
||||||
import eu.kanade.tachiyomi.source.LocalSource
|
import eu.kanade.tachiyomi.source.LocalSource
|
||||||
@ -106,9 +107,6 @@ import kotlinx.coroutines.Dispatchers
|
|||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.delay
|
import kotlinx.coroutines.delay
|
||||||
import kotlinx.coroutines.flow.drop
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
import uy.kohesive.injekt.api.get
|
import uy.kohesive.injekt.api.get
|
||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
@ -840,14 +838,9 @@ class LibraryController(
|
|||||||
preferences.uniformGrid(),
|
preferences.uniformGrid(),
|
||||||
preferences.gridSize(),
|
preferences.gridSize(),
|
||||||
preferences.unreadBadgeType()
|
preferences.unreadBadgeType()
|
||||||
).forEach {
|
).asFlowsIn(scope, true) {
|
||||||
it.asFlow()
|
|
||||||
.drop(1)
|
|
||||||
.onEach {
|
|
||||||
reattachAdapter()
|
reattachAdapter()
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) {
|
||||||
|
@ -45,6 +45,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
|||||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||||
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.data.preference.getOrDefault
|
import eu.kanade.tachiyomi.data.preference.getOrDefault
|
||||||
import eu.kanade.tachiyomi.data.updater.UpdateChecker
|
import eu.kanade.tachiyomi.data.updater.UpdateChecker
|
||||||
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
||||||
@ -339,11 +340,10 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
|
|||||||
}
|
}
|
||||||
|
|
||||||
preferences.incognitoMode()
|
preferences.incognitoMode()
|
||||||
.asImmediateFlow {
|
.asImmediateFlowIn(lifecycleScope) {
|
||||||
binding.toolbar.setIncognitoMode(it)
|
binding.toolbar.setIncognitoMode(it)
|
||||||
binding.cardToolbar.setIncognitoMode(it)
|
binding.cardToolbar.setIncognitoMode(it)
|
||||||
}
|
}
|
||||||
.launchIn(lifecycleScope)
|
|
||||||
setExtensionsBadge()
|
setExtensionsBadge()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +42,7 @@ 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.asImmediateFlowIn
|
import eu.kanade.tachiyomi.data.preference.asImmediateFlowIn
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asFlowsIn
|
||||||
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
|
||||||
@ -688,11 +689,7 @@ class ReaderActivity :
|
|||||||
}
|
}
|
||||||
|
|
||||||
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
|
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
|
||||||
.forEach { pref ->
|
.asFlowsIn(scope) { updateCropBordersShortcut() }
|
||||||
pref.asFlow()
|
|
||||||
.onEach { updateCropBordersShortcut() }
|
|
||||||
.launchIn(scope)
|
|
||||||
}
|
|
||||||
preferences.rotation().asImmediateFlowIn(scope) { updateRotationShortcut(it) }
|
preferences.rotation().asImmediateFlowIn(scope) { updateRotationShortcut(it) }
|
||||||
|
|
||||||
binding.chaptersSheet.shiftPageButton.setOnClickListener {
|
binding.chaptersSheet.shiftPageButton.setOnClickListener {
|
||||||
|
@ -12,15 +12,13 @@ import eu.kanade.tachiyomi.data.download.model.DownloadQueue
|
|||||||
import eu.kanade.tachiyomi.data.library.LibraryServiceListener
|
import eu.kanade.tachiyomi.data.library.LibraryServiceListener
|
||||||
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||||
|
import eu.kanade.tachiyomi.data.preference.asFlowsIn
|
||||||
import eu.kanade.tachiyomi.source.SourceManager
|
import eu.kanade.tachiyomi.source.SourceManager
|
||||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.Job
|
import kotlinx.coroutines.Job
|
||||||
import kotlinx.coroutines.cancel
|
import kotlinx.coroutines.cancel
|
||||||
import kotlinx.coroutines.flow.drop
|
|
||||||
import kotlinx.coroutines.flow.launchIn
|
|
||||||
import kotlinx.coroutines.flow.onEach
|
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
import kotlinx.coroutines.withContext
|
import kotlinx.coroutines.withContext
|
||||||
import uy.kohesive.injekt.Injekt
|
import uy.kohesive.injekt.Injekt
|
||||||
@ -78,15 +76,10 @@ class RecentsPresenter(
|
|||||||
preferences.groupChaptersHistory(),
|
preferences.groupChaptersHistory(),
|
||||||
preferences.showReadInAllRecents(),
|
preferences.showReadInAllRecents(),
|
||||||
preferences.groupChaptersUpdates()
|
preferences.groupChaptersUpdates()
|
||||||
).forEach {
|
).asFlowsIn(scope, true) {
|
||||||
it.asFlow()
|
|
||||||
.drop(1)
|
|
||||||
.onEach {
|
|
||||||
resetOffsets()
|
resetOffsets()
|
||||||
getRecents()
|
getRecents()
|
||||||
}
|
}
|
||||||
.launchIn(scope)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fun onCreate() {
|
fun onCreate() {
|
||||||
|
Loading…
Reference in New Issue
Block a user