download’s cache renew interval configurable
This commit is contained in:
parent
7c11ddfc1e
commit
f6dcb2431f
4 changed files with 53 additions and 4 deletions
|
|
@ -61,6 +61,9 @@ object SettingsDownloadScreen : SearchableSettings {
|
|||
allCategories = allCategories,
|
||||
),
|
||||
getDownloadAheadGroup(downloadPreferences = downloadPreferences),
|
||||
// KMK -->
|
||||
getDownloadCacheRenewInterval(downloadPreferences = downloadPreferences),
|
||||
// KMK <--
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -190,4 +193,30 @@ object SettingsDownloadScreen : SearchableSettings {
|
|||
),
|
||||
)
|
||||
}
|
||||
|
||||
// KMK -->
|
||||
@Composable
|
||||
private fun getDownloadCacheRenewInterval(
|
||||
downloadPreferences: DownloadPreferences,
|
||||
): Preference.PreferenceGroup {
|
||||
return Preference.PreferenceGroup(
|
||||
title = stringResource(MR.strings.download_cache_renew_interval),
|
||||
preferenceItems = persistentListOf(
|
||||
Preference.PreferenceItem.ListPreference(
|
||||
pref = downloadPreferences.downloadCacheRenewInterval(),
|
||||
title = stringResource(MR.strings.download_cache_renew_interval),
|
||||
entries = persistentMapOf(
|
||||
-1 to stringResource(MR.strings.download_cache_renew_interval_manual),
|
||||
1 to stringResource(MR.strings.download_cache_renew_interval_1hour),
|
||||
2 to stringResource(MR.strings.download_cache_renew_interval_2hour),
|
||||
6 to stringResource(MR.strings.download_cache_renew_interval_6hour),
|
||||
12 to stringResource(MR.strings.download_cache_renew_interval_12hour),
|
||||
24 to stringResource(MR.strings.download_cache_renew_interval_24hour),
|
||||
),
|
||||
),
|
||||
Preference.PreferenceItem.InfoPreference(stringResource(MR.strings.download_cache_renew_interval_info)),
|
||||
),
|
||||
)
|
||||
}
|
||||
// KMK <--
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,7 @@ import tachiyomi.core.common.util.lang.launchIO
|
|||
import tachiyomi.core.common.util.lang.launchNonCancellable
|
||||
import tachiyomi.core.common.util.system.logcat
|
||||
import tachiyomi.domain.chapter.model.Chapter
|
||||
import tachiyomi.domain.download.service.DownloadPreferences
|
||||
import tachiyomi.domain.manga.model.Manga
|
||||
import tachiyomi.domain.source.service.SourceManager
|
||||
import tachiyomi.domain.storage.service.StorageManager
|
||||
|
|
@ -69,6 +70,9 @@ class DownloadCache(
|
|||
) {
|
||||
|
||||
private val scope = CoroutineScope(Dispatchers.IO)
|
||||
// KMK -->
|
||||
private val downloadPreferences: DownloadPreferences = Injekt.get()
|
||||
// KMK <--
|
||||
|
||||
private val _changes: Channel<Unit> = Channel(Channel.UNLIMITED)
|
||||
val changes = _changes.receiveAsFlow()
|
||||
|
|
@ -79,7 +83,11 @@ class DownloadCache(
|
|||
* The interval after which this cache should be invalidated. 1 hour shouldn't cause major
|
||||
* issues, as the cache is only used for UI feedback.
|
||||
*/
|
||||
private val renewInterval = 1.hours.inWholeMilliseconds
|
||||
private val renewInterval //= 1.hours.inWholeMilliseconds
|
||||
// KMK -->
|
||||
get() = downloadPreferences.downloadCacheRenewInterval().get()
|
||||
.hours.inWholeMilliseconds
|
||||
// KMK <--
|
||||
|
||||
/**
|
||||
* The last time the cache was refreshed.
|
||||
|
|
@ -320,7 +328,7 @@ class DownloadCache(
|
|||
lastRenew = 0L
|
||||
renewalJob?.cancel()
|
||||
diskCacheFile.delete()
|
||||
renewCache()
|
||||
renewCache(/* KMK --> */ 0L /* KMK <-- */)
|
||||
}
|
||||
|
||||
// KMK -->
|
||||
|
|
@ -335,9 +343,9 @@ class DownloadCache(
|
|||
/**
|
||||
* Renews the downloads cache.
|
||||
*/
|
||||
private fun renewCache() {
|
||||
private fun renewCache(/* KMK --> */ renewInterval: Long = this.renewInterval /* KMK <-- */) {
|
||||
// Avoid renewing cache if in the process nor too often
|
||||
if (lastRenew + renewInterval >= System.currentTimeMillis() || renewalJob?.isActive == true) {
|
||||
if (/* KMK --> */ renewInterval < 0L || /* KMK <-- */ lastRenew + renewInterval >= System.currentTimeMillis() || renewalJob?.isActive == true) {
|
||||
return
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -42,4 +42,8 @@ class DownloadPreferences(
|
|||
"download_new_categories_exclude",
|
||||
emptySet(),
|
||||
)
|
||||
|
||||
// KMK -->
|
||||
fun downloadCacheRenewInterval() = preferenceStore.getInt("download_cache_renew_interval", 1)
|
||||
// KMK <--
|
||||
}
|
||||
|
|
|
|||
|
|
@ -489,6 +489,14 @@
|
|||
<string name="save_chapter_as_cbz">Save as CBZ archive</string>
|
||||
<string name="split_tall_images">Split tall images</string>
|
||||
<string name="split_tall_images_summary">Improves reader performance</string>
|
||||
<string name="download_cache_renew_interval">Download cache renew interval</string>
|
||||
<string name="download_cache_renew_interval_manual">Manual</string>
|
||||
<string name="download_cache_renew_interval_1hour">1 hour</string>
|
||||
<string name="download_cache_renew_interval_2hour">2 hours</string>
|
||||
<string name="download_cache_renew_interval_6hour">6 hours</string>
|
||||
<string name="download_cache_renew_interval_12hour">12 hours</string>
|
||||
<string name="download_cache_renew_interval_24hour">1 day</string>
|
||||
<string name="download_cache_renew_interval_info">If set to "manual", either refresh each manga or using the "Invalidate downloads index" action in "Advanced"</string>
|
||||
|
||||
<!-- Tracking section -->
|
||||
<string name="tracking_guide">Tracking guide</string>
|
||||
|
|
|
|||
Loading…
Reference in a new issue