Add reindex downloads description
Closes #8546 Also disable sound for the notification and cancel running indexing job if invalidating.
This commit is contained in:
parent
e22896a956
commit
2d86f69caa
4 changed files with 51 additions and 50 deletions
|
@ -191,6 +191,7 @@ class SettingsAdvancedScreen : SearchableSettings {
|
||||||
),
|
),
|
||||||
Preference.PreferenceItem.TextPreference(
|
Preference.PreferenceItem.TextPreference(
|
||||||
title = stringResource(R.string.pref_invalidate_download_cache),
|
title = stringResource(R.string.pref_invalidate_download_cache),
|
||||||
|
subtitle = stringResource(R.string.pref_invalidate_download_cache_summary),
|
||||||
onClick = { Injekt.get<DownloadCache>().invalidateCache() },
|
onClick = { Injekt.get<DownloadCache>().invalidateCache() },
|
||||||
),
|
),
|
||||||
Preference.PreferenceItem.TextPreference(
|
Preference.PreferenceItem.TextPreference(
|
||||||
|
|
|
@ -222,6 +222,7 @@ class DownloadCache(
|
||||||
|
|
||||||
fun invalidateCache() {
|
fun invalidateCache() {
|
||||||
lastRenew = 0L
|
lastRenew = 0L
|
||||||
|
renewalJob?.cancel()
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -242,70 +243,67 @@ class DownloadCache(
|
||||||
}
|
}
|
||||||
|
|
||||||
renewalJob = scope.launchIO {
|
renewalJob = scope.launchIO {
|
||||||
try {
|
notifier.onCacheProgress()
|
||||||
notifier.onCacheProgress()
|
|
||||||
|
|
||||||
var sources = getSources()
|
var sources = getSources()
|
||||||
|
|
||||||
// Try to wait until extensions and sources have loaded
|
// Try to wait until extensions and sources have loaded
|
||||||
withTimeout(30.seconds) {
|
withTimeout(30.seconds) {
|
||||||
while (!extensionManager.isInitialized) {
|
while (!extensionManager.isInitialized) {
|
||||||
delay(2.seconds)
|
delay(2.seconds)
|
||||||
}
|
|
||||||
|
|
||||||
while (sources.isEmpty()) {
|
|
||||||
delay(2.seconds)
|
|
||||||
sources = getSources()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
val sourceDirs = rootDownloadsDir.dir.listFiles().orEmpty()
|
while (sources.isEmpty()) {
|
||||||
.associate { it.name to SourceDirectory(it) }
|
delay(2.seconds)
|
||||||
.mapNotNullKeys { entry ->
|
sources = getSources()
|
||||||
sources.find {
|
}
|
||||||
provider.getSourceDirName(it).equals(entry.key, ignoreCase = true)
|
}
|
||||||
}?.id
|
|
||||||
}
|
|
||||||
|
|
||||||
rootDownloadsDir.sourceDirs = sourceDirs
|
val sourceDirs = rootDownloadsDir.dir.listFiles().orEmpty()
|
||||||
|
.associate { it.name to SourceDirectory(it) }
|
||||||
|
.mapNotNullKeys { entry ->
|
||||||
|
sources.find {
|
||||||
|
provider.getSourceDirName(it).equals(entry.key, ignoreCase = true)
|
||||||
|
}?.id
|
||||||
|
}
|
||||||
|
|
||||||
sourceDirs.values
|
rootDownloadsDir.sourceDirs = sourceDirs
|
||||||
.map { sourceDir ->
|
|
||||||
async {
|
|
||||||
val mangaDirs = sourceDir.dir.listFiles().orEmpty()
|
|
||||||
.filterNot { it.name.isNullOrBlank() }
|
|
||||||
.associate { it.name!! to MangaDirectory(it) }
|
|
||||||
|
|
||||||
sourceDir.mangaDirs = ConcurrentHashMap(mangaDirs)
|
sourceDirs.values
|
||||||
|
.map { sourceDir ->
|
||||||
|
async {
|
||||||
|
val mangaDirs = sourceDir.dir.listFiles().orEmpty()
|
||||||
|
.filterNot { it.name.isNullOrBlank() }
|
||||||
|
.associate { it.name!! to MangaDirectory(it) }
|
||||||
|
|
||||||
mangaDirs.values.forEach { mangaDir ->
|
sourceDir.mangaDirs = ConcurrentHashMap(mangaDirs)
|
||||||
val chapterDirs = mangaDir.dir.listFiles().orEmpty()
|
|
||||||
.mapNotNull {
|
mangaDirs.values.forEach { mangaDir ->
|
||||||
when {
|
val chapterDirs = mangaDir.dir.listFiles().orEmpty()
|
||||||
// Ignore incomplete downloads
|
.mapNotNull {
|
||||||
it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true -> null
|
when {
|
||||||
// Folder of images
|
// Ignore incomplete downloads
|
||||||
it.isDirectory -> it.name
|
it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true -> null
|
||||||
// CBZ files
|
// Folder of images
|
||||||
it.isFile && it.name?.endsWith(".cbz") == true -> it.name!!.replace(".cbz", "")
|
it.isDirectory -> it.name
|
||||||
// Anything else is irrelevant
|
// CBZ files
|
||||||
else -> null
|
it.isFile && it.name?.endsWith(".cbz") == true -> it.name!!.replace(".cbz", "")
|
||||||
}
|
// Anything else is irrelevant
|
||||||
|
else -> null
|
||||||
}
|
}
|
||||||
.toMutableSet()
|
}
|
||||||
|
.toMutableSet()
|
||||||
|
|
||||||
mangaDir.chapterDirs = chapterDirs
|
mangaDir.chapterDirs = chapterDirs
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.awaitAll()
|
}
|
||||||
|
.awaitAll()
|
||||||
|
|
||||||
lastRenew = System.currentTimeMillis()
|
lastRenew = System.currentTimeMillis()
|
||||||
notifyChanges()
|
notifyChanges()
|
||||||
} finally {
|
|
||||||
notifier.dismissCacheProgress()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
renewalJob?.invokeOnCompletion { notifier.dismissCacheProgress() }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun getSources(): List<Source> {
|
private fun getSources(): List<Source> {
|
||||||
|
|
|
@ -159,6 +159,7 @@ object Notifications {
|
||||||
setName(context.getString(R.string.channel_downloader_cache))
|
setName(context.getString(R.string.channel_downloader_cache))
|
||||||
setGroup(GROUP_DOWNLOADER)
|
setGroup(GROUP_DOWNLOADER)
|
||||||
setShowBadge(false)
|
setShowBadge(false)
|
||||||
|
setSound(null, null)
|
||||||
},
|
},
|
||||||
buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) {
|
buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) {
|
||||||
setName(context.getString(R.string.channel_progress))
|
setName(context.getString(R.string.channel_progress))
|
||||||
|
|
|
@ -505,6 +505,7 @@
|
||||||
<string name="cache_delete_error">Error occurred while clearing</string>
|
<string name="cache_delete_error">Error occurred while clearing</string>
|
||||||
<string name="pref_auto_clear_chapter_cache">Clear chapter cache on app close</string>
|
<string name="pref_auto_clear_chapter_cache">Clear chapter cache on app close</string>
|
||||||
<string name="pref_invalidate_download_cache">Invalidate downloads index</string>
|
<string name="pref_invalidate_download_cache">Invalidate downloads index</string>
|
||||||
|
<string name="pref_invalidate_download_cache_summary">Force app to recheck downloaded chapters</string>
|
||||||
<string name="pref_clear_database">Clear database</string>
|
<string name="pref_clear_database">Clear database</string>
|
||||||
<string name="pref_clear_database_summary">Delete history for entries that are not saved in your library</string>
|
<string name="pref_clear_database_summary">Delete history for entries that are not saved in your library</string>
|
||||||
<string name="clear_database_source_item_count">%1$d non-library entries in database</string>
|
<string name="clear_database_source_item_count">%1$d non-library entries in database</string>
|
||||||
|
|
Reference in a new issue