mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 18:51:51 +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)
|
||||
}
|
||||
|
||||
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())
|
||||
|
||||
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.Notifications
|
||||
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.databinding.LibraryControllerBinding
|
||||
import eu.kanade.tachiyomi.source.LocalSource
|
||||
@ -106,9 +107,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancel
|
||||
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.api.get
|
||||
import java.util.Locale
|
||||
@ -840,13 +838,8 @@ class LibraryController(
|
||||
preferences.uniformGrid(),
|
||||
preferences.gridSize(),
|
||||
preferences.unreadBadgeType()
|
||||
).forEach {
|
||||
it.asFlow()
|
||||
.drop(1)
|
||||
.onEach {
|
||||
reattachAdapter()
|
||||
}
|
||||
.launchIn(scope)
|
||||
).asFlowsIn(scope, true) {
|
||||
reattachAdapter()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,6 +45,7 @@ import eu.kanade.tachiyomi.data.library.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.data.notification.NotificationReceiver
|
||||
import eu.kanade.tachiyomi.data.notification.Notifications
|
||||
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.updater.UpdateChecker
|
||||
import eu.kanade.tachiyomi.data.updater.UpdateResult
|
||||
@ -339,11 +340,10 @@ open class MainActivity : BaseActivity<MainActivityBinding>(), DownloadServiceLi
|
||||
}
|
||||
|
||||
preferences.incognitoMode()
|
||||
.asImmediateFlow {
|
||||
.asImmediateFlowIn(lifecycleScope) {
|
||||
binding.toolbar.setIncognitoMode(it)
|
||||
binding.cardToolbar.setIncognitoMode(it)
|
||||
}
|
||||
.launchIn(lifecycleScope)
|
||||
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.preference.PreferencesHelper
|
||||
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.databinding.ReaderActivityBinding
|
||||
import eu.kanade.tachiyomi.source.model.Page
|
||||
@ -688,11 +689,7 @@ class ReaderActivity :
|
||||
}
|
||||
|
||||
listOf(preferences.cropBorders(), preferences.cropBordersWebtoon())
|
||||
.forEach { pref ->
|
||||
pref.asFlow()
|
||||
.onEach { updateCropBordersShortcut() }
|
||||
.launchIn(scope)
|
||||
}
|
||||
.asFlowsIn(scope) { updateCropBordersShortcut() }
|
||||
preferences.rotation().asImmediateFlowIn(scope) { updateRotationShortcut(it) }
|
||||
|
||||
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.LibraryUpdateService
|
||||
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
|
||||
import eu.kanade.tachiyomi.data.preference.asFlowsIn
|
||||
import eu.kanade.tachiyomi.source.SourceManager
|
||||
import eu.kanade.tachiyomi.util.system.executeOnIO
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
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.withContext
|
||||
import uy.kohesive.injekt.Injekt
|
||||
@ -78,14 +76,9 @@ class RecentsPresenter(
|
||||
preferences.groupChaptersHistory(),
|
||||
preferences.showReadInAllRecents(),
|
||||
preferences.groupChaptersUpdates()
|
||||
).forEach {
|
||||
it.asFlow()
|
||||
.drop(1)
|
||||
.onEach {
|
||||
resetOffsets()
|
||||
getRecents()
|
||||
}
|
||||
.launchIn(scope)
|
||||
).asFlowsIn(scope, true) {
|
||||
resetOffsets()
|
||||
getRecents()
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user