From 2d86f69caa79b17b000ec1139a4283f8e9d1db35 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 20 Nov 2022 14:29:56 -0500 Subject: [PATCH] Add reindex downloads description Closes #8546 Also disable sound for the notification and cancel running indexing job if invalidating. --- .../settings/screen/SettingsAdvancedScreen.kt | 1 + .../tachiyomi/data/download/DownloadCache.kt | 98 +++++++++---------- .../data/notification/Notifications.kt | 1 + i18n/src/main/res/values/strings.xml | 1 + 4 files changed, 51 insertions(+), 50 deletions(-) diff --git a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt index 5469836d2..051ad2f83 100644 --- a/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt +++ b/app/src/main/java/eu/kanade/presentation/more/settings/screen/SettingsAdvancedScreen.kt @@ -191,6 +191,7 @@ class SettingsAdvancedScreen : SearchableSettings { ), Preference.PreferenceItem.TextPreference( title = stringResource(R.string.pref_invalidate_download_cache), + subtitle = stringResource(R.string.pref_invalidate_download_cache_summary), onClick = { Injekt.get().invalidateCache() }, ), Preference.PreferenceItem.TextPreference( diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt index a02953fb2..9d2df3e28 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/download/DownloadCache.kt @@ -222,6 +222,7 @@ class DownloadCache( fun invalidateCache() { lastRenew = 0L + renewalJob?.cancel() } /** @@ -242,70 +243,67 @@ class DownloadCache( } renewalJob = scope.launchIO { - try { - notifier.onCacheProgress() + notifier.onCacheProgress() - var sources = getSources() + var sources = getSources() - // Try to wait until extensions and sources have loaded - withTimeout(30.seconds) { - while (!extensionManager.isInitialized) { - delay(2.seconds) - } - - while (sources.isEmpty()) { - delay(2.seconds) - sources = getSources() - } + // Try to wait until extensions and sources have loaded + withTimeout(30.seconds) { + while (!extensionManager.isInitialized) { + delay(2.seconds) } - 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 - } + while (sources.isEmpty()) { + delay(2.seconds) + sources = getSources() + } + } - 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 - .map { sourceDir -> - async { - val mangaDirs = sourceDir.dir.listFiles().orEmpty() - .filterNot { it.name.isNullOrBlank() } - .associate { it.name!! to MangaDirectory(it) } + rootDownloadsDir.sourceDirs = sourceDirs - 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 -> - val chapterDirs = mangaDir.dir.listFiles().orEmpty() - .mapNotNull { - when { - // Ignore incomplete downloads - it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true -> null - // Folder of images - it.isDirectory -> it.name - // CBZ files - it.isFile && it.name?.endsWith(".cbz") == true -> it.name!!.replace(".cbz", "") - // Anything else is irrelevant - else -> null - } + sourceDir.mangaDirs = ConcurrentHashMap(mangaDirs) + + mangaDirs.values.forEach { mangaDir -> + val chapterDirs = mangaDir.dir.listFiles().orEmpty() + .mapNotNull { + when { + // Ignore incomplete downloads + it.name?.endsWith(Downloader.TMP_DIR_SUFFIX) == true -> null + // Folder of images + it.isDirectory -> it.name + // CBZ files + 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() - notifyChanges() - } finally { - notifier.dismissCacheProgress() - } + lastRenew = System.currentTimeMillis() + notifyChanges() } + renewalJob?.invokeOnCompletion { notifier.dismissCacheProgress() } } private fun getSources(): List { diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt index b091a78bb..41a879e5e 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/notification/Notifications.kt @@ -159,6 +159,7 @@ object Notifications { setName(context.getString(R.string.channel_downloader_cache)) setGroup(GROUP_DOWNLOADER) setShowBadge(false) + setSound(null, null) }, buildNotificationChannel(CHANNEL_BACKUP_RESTORE_PROGRESS, IMPORTANCE_LOW) { setName(context.getString(R.string.channel_progress)) diff --git a/i18n/src/main/res/values/strings.xml b/i18n/src/main/res/values/strings.xml index f44817b71..8f3f8323a 100644 --- a/i18n/src/main/res/values/strings.xml +++ b/i18n/src/main/res/values/strings.xml @@ -505,6 +505,7 @@ Error occurred while clearing Clear chapter cache on app close Invalidate downloads index + Force app to recheck downloaded chapters Clear database Delete history for entries that are not saved in your library %1$d non-library entries in database