From ef600c09562f86b6f9c930d19c15c875b2f72751 Mon Sep 17 00:00:00 2001 From: Ivan Iskandar <12537387+ivaniskandar@users.noreply.github.com> Date: Fri, 25 Mar 2022 22:11:16 +0700 Subject: [PATCH] Fix extension update badge reset when app resumed (#6822) --- .../java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt | 2 +- .../eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt | 4 ++-- .../main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt | 5 +++-- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt index 8373366448..1c4deb199c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionUpdateJob.kt @@ -34,7 +34,7 @@ class ExtensionUpdateJob(private val context: Context, workerParams: WorkerParam return@coroutineScope Result.failure() } - if (pendingUpdates.isNotEmpty()) { + if (!pendingUpdates.isNullOrEmpty()) { createUpdateNotification(pendingUpdates.map { it.name }) } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt index 4971000e56..87d1de650a 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionGithubApi.kt @@ -39,10 +39,10 @@ internal class ExtensionGithubApi { } } - suspend fun checkForUpdates(context: Context): List { + suspend fun checkForUpdates(context: Context): List? { // Limit checks to once a day at most if (Date().time < preferences.lastExtCheck().get() + TimeUnit.DAYS.toMillis(1)) { - return emptyList() + return null } val extensions = findExtensions() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt index 566ebe9f0e..3bd4c1d74f 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/main/MainActivity.kt @@ -361,8 +361,9 @@ class MainActivity : BaseViewBindingActivity() { // Extension updates try { - val pendingUpdates = ExtensionGithubApi().checkForUpdates(this@MainActivity) - preferences.extensionUpdatesCount().set(pendingUpdates.size) + ExtensionGithubApi().checkForUpdates(this@MainActivity)?.let { pendingUpdates -> + preferences.extensionUpdatesCount().set(pendingUpdates.size) + } } catch (e: Exception) { logcat(LogPriority.ERROR, e) }