mirror of
https://github.com/tachiyomiorg/tachiyomi.git
synced 2024-12-23 18:41:48 +01:00
Added option to clean cache of online covers in advanced
This commit is contained in:
parent
38fac8341d
commit
696ffff401
@ -60,6 +60,10 @@ class CoverCache(val context: Context) {
|
|||||||
return Formatter.formatFileSize(context, DiskUtil.getDirectorySize(cacheDir))
|
return Formatter.formatFileSize(context, DiskUtil.getDirectorySize(cacheDir))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getOnlineCoverCacheSize(): String {
|
||||||
|
return Formatter.formatFileSize(context, DiskUtil.getDirectorySize(onlineCoverDirectory))
|
||||||
|
}
|
||||||
|
|
||||||
fun deleteOldCovers() {
|
fun deleteOldCovers() {
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
val db = Injekt.get<DatabaseHelper>()
|
val db = Injekt.get<DatabaseHelper>()
|
||||||
@ -86,6 +90,35 @@ class CoverCache(val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clear out online covers until its under a certain size
|
||||||
|
*/
|
||||||
|
fun deleteAllCachedCovers() {
|
||||||
|
GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
val directory = onlineCoverDirectory
|
||||||
|
val size = DiskUtil.getDirectorySize(directory)
|
||||||
|
if (size <= maxOnlineCacheSize) {
|
||||||
|
return@launch
|
||||||
|
}
|
||||||
|
var deletedSize = 0L
|
||||||
|
val files =
|
||||||
|
directory.listFiles()?.sortedBy { it.lastModified() }?.iterator() ?: return@launch
|
||||||
|
while (files.hasNext()) {
|
||||||
|
val file = files.next()
|
||||||
|
deletedSize += file.length()
|
||||||
|
file.delete()
|
||||||
|
}
|
||||||
|
withContext(Dispatchers.Main) {
|
||||||
|
context.toast(
|
||||||
|
context.getString(
|
||||||
|
R.string.deleted_, Formatter.formatFileSize(context, deletedSize)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lastClean = System.currentTimeMillis()
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear out online covers until its under a certain size
|
* Clear out online covers until its under a certain size
|
||||||
*/
|
*/
|
||||||
|
@ -75,6 +75,15 @@ class SettingsAdvancedController : SettingsController() {
|
|||||||
coverCache.deleteOldCovers()
|
coverCache.deleteOldCovers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
preference {
|
||||||
|
titleRes = R.string.clean_up_cached_covers_non_library
|
||||||
|
summary = context.getString(R.string.delete_all_covers__not_in_library_used_, coverCache.getOnlineCoverCacheSize())
|
||||||
|
|
||||||
|
onClick {
|
||||||
|
context.toast(R.string.starting_cleanup)
|
||||||
|
coverCache.deleteAllCachedCovers()
|
||||||
|
}
|
||||||
|
}
|
||||||
preference {
|
preference {
|
||||||
titleRes = R.string.clear_cookies
|
titleRes = R.string.clear_cookies
|
||||||
|
|
||||||
|
@ -562,6 +562,10 @@
|
|||||||
<string name="clean_up_cached_covers">Clean up cached covers</string>
|
<string name="clean_up_cached_covers">Clean up cached covers</string>
|
||||||
<string name="delete_old_covers_in_library_used_">Delete old and unused cached covers of
|
<string name="delete_old_covers_in_library_used_">Delete old and unused cached covers of
|
||||||
manga in your library that has been updated.\nCurrently using: %1$s</string>
|
manga in your library that has been updated.\nCurrently using: %1$s</string>
|
||||||
|
<string name="clean_up_cached_covers_non_library">Clean up cached covers not in
|
||||||
|
library</string>
|
||||||
|
<string name="delete_all_covers__not_in_library_used_">Delete all covers cached that are
|
||||||
|
not in your library \nCurrently using: %1$s</string>
|
||||||
|
|
||||||
<!-- Browse Settings -->
|
<!-- Browse Settings -->
|
||||||
<string name="pref_global_search">Global search</string>
|
<string name="pref_global_search">Global search</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user