Add refresh download cache, and remove size check for force delete non library cover cache (#872)

* add option to force refresh download cache.
Removed size check on clear non library covers because what it does did not match what it said it did

* forgot }
This commit is contained in:
Carlos 2021-06-22 22:31:25 -04:00 committed by GitHub
parent d0b4b33466
commit 7585c24566
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 25 additions and 6 deletions

View File

@ -94,15 +94,13 @@ class CoverCache(val context: Context) {
} }
/** /**
* Clear out online covers until its under a certain size * Clear out all online covers
*/ */
fun deleteAllCachedCovers() { fun deleteAllCachedCovers() {
GlobalScope.launch(Dispatchers.IO) { GlobalScope.launch(Dispatchers.IO) {
val directory = onlineCoverDirectory val directory = onlineCoverDirectory
val size = DiskUtil.getDirectorySize(directory) val size = DiskUtil.getDirectorySize(directory)
if (size <= maxOnlineCacheSize) {
return@launch
}
var deletedSize = 0L var deletedSize = 0L
val files = val files =
directory.listFiles()?.sortedBy { it.lastModified() }?.iterator() ?: return@launch directory.listFiles()?.sortedBy { it.lastModified() }?.iterator() ?: return@launch

View File

@ -118,6 +118,12 @@ class DownloadCache(
} }
} }
fun forceRenewCache() {
renew()
lastRenew = System.currentTimeMillis()
}
/** /**
* Renews the downloads cache. * Renews the downloads cache.
*/ */

View File

@ -372,6 +372,11 @@ class DownloadManager(val context: Context) {
} }
} }
// forceRefresh the download cache
fun refreshCache() {
cache.forceRenewCache()
}
fun addListener(listener: DownloadQueue.DownloadListener) = queue.addListener(listener) fun addListener(listener: DownloadQueue.DownloadListener) = queue.addListener(listener)
fun removeListener(listener: DownloadQueue.DownloadListener) = queue.removeListener(listener) fun removeListener(listener: DownloadQueue.DownloadListener) = queue.removeListener(listener)
} }

View File

@ -52,6 +52,8 @@ class SettingsAdvancedController : SettingsController() {
private val coverCache: CoverCache by injectLazy() private val coverCache: CoverCache by injectLazy()
private val downloadManager: DownloadManager by injectLazy()
@SuppressLint("BatteryLife") @SuppressLint("BatteryLife")
override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply { override fun setupPreferenceScreen(screen: PreferenceScreen) = screen.apply {
titleRes = R.string.advanced titleRes = R.string.advanced
@ -103,6 +105,12 @@ class SettingsAdvancedController : SettingsController() {
onClick { clearChapterCache() } onClick { clearChapterCache() }
} }
preference {
titleRes = R.string.force_download_cache_refresh
summaryRes = R.string.force_download_cache_refresh_summary
onClick { downloadManager.refreshCache() }
}
preference { preference {
key = "clean_cached_covers" key = "clean_cached_covers"
titleRes = R.string.clean_up_cached_covers titleRes = R.string.clean_up_cached_covers
@ -220,7 +228,6 @@ class SettingsAdvancedController : SettingsController() {
job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) { job = GlobalScope.launch(Dispatchers.IO, CoroutineStart.DEFAULT) {
val mangaList = db.getMangas().executeAsBlocking() val mangaList = db.getMangas().executeAsBlocking()
val sourceManager: SourceManager = Injekt.get() val sourceManager: SourceManager = Injekt.get()
val downloadManager: DownloadManager = Injekt.get()
val downloadProvider = DownloadProvider(activity!!) val downloadProvider = DownloadProvider(activity!!)
var foldersCleared = 0 var foldersCleared = 0
val sources = sourceManager.getOnlineSources() val sources = sourceManager.getOnlineSources()

View File

@ -668,6 +668,9 @@
<!-- Advanced section --> <!-- Advanced section -->
<string name="clear_chapter_cache">Clear chapter cache</string> <string name="clear_chapter_cache">Clear chapter cache</string>
<string name="force_download_cache_refresh">Refresh the download cache</string>
<string name="force_download_cache_refresh_summary">This will force the download cache to recalculate. Useful if you copied downloads outside of this app and want the app to pick them up</string>
<string name="data_management">Data Management</string> <string name="data_management">Data Management</string>
<string name="crash_logs">Crash logs</string> <string name="crash_logs">Crash logs</string>
<string name="dump_crash_logs">Dump crash logs</string> <string name="dump_crash_logs">Dump crash logs</string>