Clean up preference extensions/items a bit

This commit is contained in:
arkon
2023-07-19 21:57:22 -04:00
parent 7a4680603d
commit cf14831fbe
24 changed files with 101 additions and 219 deletions
@@ -73,7 +73,6 @@ import eu.kanade.tachiyomi.ui.reader.setting.ReadingModeType
import eu.kanade.tachiyomi.ui.reader.viewer.ReaderProgressIndicator
import eu.kanade.tachiyomi.ui.reader.viewer.pager.R2LPagerViewer
import eu.kanade.tachiyomi.ui.webview.WebViewActivity
import eu.kanade.tachiyomi.util.preference.toggle
import eu.kanade.tachiyomi.util.system.applySystemAnimatorScale
import eu.kanade.tachiyomi.util.system.hasDisplayCutout
import eu.kanade.tachiyomi.util.system.isNightMode
@@ -95,6 +94,7 @@ import kotlinx.coroutines.flow.sample
import kotlinx.coroutines.launch
import logcat.LogPriority
import tachiyomi.core.Constants
import tachiyomi.core.preference.toggle
import tachiyomi.core.util.lang.launchIO
import tachiyomi.core.util.lang.launchNonCancellable
import tachiyomi.core.util.lang.withUIContext
@@ -50,9 +50,7 @@ internal class HttpPageLoader(
}
}
.filter { it.status == Page.State.QUEUE }
.collect {
_loadPage(it)
}
.collect(::internalLoadPage)
}
}
@@ -80,32 +78,30 @@ internal class HttpPageLoader(
/**
* Loads a page through the queue. Handles re-enqueueing pages if they were evicted from the cache.
*/
override suspend fun loadPage(page: ReaderPage) {
withIOContext {
val imageUrl = page.imageUrl
override suspend fun loadPage(page: ReaderPage) = withIOContext {
val imageUrl = page.imageUrl
// Check if the image has been deleted
if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) {
page.status = Page.State.QUEUE
}
// Check if the image has been deleted
if (page.status == Page.State.READY && imageUrl != null && !chapterCache.isImageInCache(imageUrl)) {
page.status = Page.State.QUEUE
}
// Automatically retry failed pages when subscribed to this page
if (page.status == Page.State.ERROR) {
page.status = Page.State.QUEUE
}
// Automatically retry failed pages when subscribed to this page
if (page.status == Page.State.ERROR) {
page.status = Page.State.QUEUE
}
val queuedPages = mutableListOf<PriorityPage>()
if (page.status == Page.State.QUEUE) {
queuedPages += PriorityPage(page, 1).also { queue.offer(it) }
}
queuedPages += preloadNextPages(page, preloadSize)
val queuedPages = mutableListOf<PriorityPage>()
if (page.status == Page.State.QUEUE) {
queuedPages += PriorityPage(page, 1).also { queue.offer(it) }
}
queuedPages += preloadNextPages(page, preloadSize)
suspendCancellableCoroutine<Nothing> { continuation ->
continuation.invokeOnCancellation {
queuedPages.forEach {
if (it.page.status == Page.State.QUEUE) {
queue.remove(it)
}
suspendCancellableCoroutine<Nothing> { continuation ->
continuation.invokeOnCancellation {
queuedPages.forEach {
if (it.page.status == Page.State.QUEUE) {
queue.remove(it)
}
}
}
@@ -128,8 +124,7 @@ internal class HttpPageLoader(
queue.clear()
// Cache current page list progress for online chapters to allow a faster reopen
val pages = chapter.pages
if (pages != null) {
chapter.pages?.let { pages ->
launchIO {
try {
// Convert to pages without reader information
@@ -171,7 +166,7 @@ internal class HttpPageLoader(
*
* @param page the page whose source image has to be downloaded.
*/
private suspend fun _loadPage(page: ReaderPage) {
private suspend fun internalLoadPage(page: ReaderPage) {
try {
if (page.imageUrl.isNullOrEmpty()) {
page.status = Page.State.LOAD_PAGE
@@ -3,13 +3,11 @@ package eu.kanade.tachiyomi.ui.reader.setting
import cafe.adriel.voyager.core.model.ScreenModel
import eu.kanade.presentation.util.ioCoroutineScope
import eu.kanade.tachiyomi.ui.reader.ReaderViewModel
import eu.kanade.tachiyomi.util.preference.toggle
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import tachiyomi.core.preference.Preference
import uy.kohesive.injekt.Injekt
import uy.kohesive.injekt.api.get
@@ -29,8 +27,4 @@ class ReaderSettingsScreenModel(
.map { it.manga }
.distinctUntilChanged()
.stateIn(ioCoroutineScope, SharingStarted.Lazily, null)
fun togglePreference(preference: (ReaderPreferences) -> Preference<Boolean>) {
preference(preferences).toggle()
}
}