Setting for pre-load cover's library color

This commit is contained in:
Cuong-Tran 2024-07-19 14:04:55 +07:00 committed by Tran M. Cuong
parent 314ced0e8d
commit c7bab00379
3 changed files with 18 additions and 3 deletions

View file

@ -29,6 +29,8 @@ class UiPreferences(
fun themeCoverBased() = preferenceStore.getBoolean("pref_theme_cover_based_key", true)
fun themeCoverBasedStyle() = preferenceStore.getEnum("pref_theme_cover_based_style_key", PaletteStyle.Vibrant)
fun preloadLibraryColor() = preferenceStore.getBoolean("pref_preload_library_color_key", true)
// KMK <--
fun relativeTime() = preferenceStore.getBoolean("relative_time_v2", true)

View file

@ -33,6 +33,7 @@ import eu.kanade.domain.base.BasePreferences
import eu.kanade.domain.extension.interactor.TrustExtension
import eu.kanade.domain.source.service.SourcePreferences
import eu.kanade.domain.source.service.SourcePreferences.DataSaver
import eu.kanade.domain.ui.UiPreferences
import eu.kanade.presentation.more.settings.Preference
import eu.kanade.presentation.more.settings.screen.advanced.ClearDatabaseScreen
import eu.kanade.presentation.more.settings.screen.debug.DebugInfoScreen
@ -100,6 +101,8 @@ import uy.kohesive.injekt.api.get
import java.io.File
object SettingsAdvancedScreen : SearchableSettings {
@Suppress("unused")
private fun readResolve(): Any = SettingsAdvancedScreen
@ReadOnlyComposable
@Composable
@ -333,6 +336,9 @@ object SettingsAdvancedScreen : SearchableSettings {
private fun getLibraryGroup(): Preference.PreferenceGroup {
val scope = rememberCoroutineScope()
val context = LocalContext.current
// KMK -->
val uiPreferences = remember { Injekt.get<UiPreferences>() }
// KMK <--
return Preference.PreferenceGroup(
title = stringResource(MR.strings.label_library),
@ -341,6 +347,12 @@ object SettingsAdvancedScreen : SearchableSettings {
title = stringResource(MR.strings.pref_refresh_library_covers),
onClick = { LibraryUpdateJob.startNow(context, target = LibraryUpdateJob.Target.COVERS) },
),
// KMK -->
Preference.PreferenceItem.SwitchPreference(
pref = uiPreferences.preloadLibraryColor(),
title = "Preload library's cover color",
),
// KMK <--
Preference.PreferenceItem.TextPreference(
title = stringResource(MR.strings.pref_reset_viewer_flags),
subtitle = stringResource(MR.strings.pref_reset_viewer_flags_summary),

View file

@ -19,7 +19,6 @@ import eu.kanade.tachiyomi.network.await
import eu.kanade.tachiyomi.source.online.HttpSource
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import logcat.LogPriority
import okhttp3.CacheControl
@ -72,9 +71,10 @@ class MangaCoverFetcher(
) : Fetcher {
// KMK -->
private val fileScope by lazy { CoroutineScope(Job() + Dispatchers.IO) }
private val scope by lazy { CoroutineScope(Dispatchers.IO) }
private val uiPreferences = Injekt.get<UiPreferences>()
private val themeCoverBased = uiPreferences.themeCoverBased().get()
private val preloadLibraryColor = uiPreferences.preloadLibraryColor().get()
// KMK <--
private val diskCacheKey: String
@ -351,7 +351,8 @@ class MangaCoverFetcher(
onlyFavorite: Boolean = !themeCoverBased,
force: Boolean = false,
) {
fileScope.launch {
if (!preloadLibraryColor) return
scope.launch {
MangaCoverMetadata.setRatioAndColors(mangaCover, bufferedSource, ogFile, onlyFavorite, force)
}
}