From 10b0ef9b6dbe94b80e9cfcaf244883a99b42737f Mon Sep 17 00:00:00 2001 From: arkon Date: Wed, 2 Aug 2023 18:00:06 -0400 Subject: [PATCH] Dismiss extension update notification if all updates installed --- .../eu/kanade/tachiyomi/extension/ExtensionManager.kt | 11 ++++++++--- .../extension/api/ExtensionUpdateNotifier.kt | 5 +++++ .../ui/browse/extension/ExtensionsScreenModel.kt | 8 ++++---- .../domain/manga/interactor/SetFetchInterval.kt | 2 +- 4 files changed, 18 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt index 7d3ddd198f..f35e919d19 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/ExtensionManager.kt @@ -5,6 +5,7 @@ import android.graphics.drawable.Drawable import eu.kanade.domain.source.service.SourcePreferences import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.extension.api.ExtensionGithubApi +import eu.kanade.tachiyomi.extension.api.ExtensionUpdateNotifier import eu.kanade.tachiyomi.extension.model.Extension import eu.kanade.tachiyomi.extension.model.InstallStep import eu.kanade.tachiyomi.extension.model.LoadResult @@ -195,7 +196,7 @@ class ExtensionManager( } /** - * Returns an observable of the installation process for the given extension. It will complete + * Returns a flow of the installation process for the given extension. It will complete * once the extension is installed or throws an error. The process will be canceled if * unsubscribed before its completion. * @@ -206,7 +207,7 @@ class ExtensionManager( } /** - * Returns an observable of the installation process for the given extension. It will complete + * Returns a flow of the installation process for the given extension. It will complete * once the extension is updated or throws an error. The process will be canceled if * unsubscribed before its completion. * @@ -356,6 +357,10 @@ class ExtensionManager( } private fun updatePendingUpdatesCount() { - preferences.extensionUpdatesCount().set(_installedExtensionsFlow.value.count { it.hasUpdate }) + val pendingUpdateCount = _installedExtensionsFlow.value.count { it.hasUpdate } + preferences.extensionUpdatesCount().set(pendingUpdateCount) + if (pendingUpdateCount == 0) { + ExtensionUpdateNotifier(context).dismiss() + } } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionUpdateNotifier.kt index f891607f6e..9080c0c62c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/extension/api/ExtensionUpdateNotifier.kt @@ -5,6 +5,7 @@ import androidx.core.app.NotificationCompat import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.notification.NotificationReceiver import eu.kanade.tachiyomi.data.notification.Notifications +import eu.kanade.tachiyomi.util.system.cancelNotification import eu.kanade.tachiyomi.util.system.notify class ExtensionUpdateNotifier(private val context: Context) { @@ -29,4 +30,8 @@ class ExtensionUpdateNotifier(private val context: Context) { setAutoCancel(true) } } + + fun dismiss() { + context.cancelNotification(Notifications.ID_UPDATES_TO_EXTS) + } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt index 2edd8f7210..a1a92f1420 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/browse/extension/ExtensionsScreenModel.kt @@ -157,14 +157,14 @@ class ExtensionsScreenModel( extensionManager.cancelInstallUpdateExtension(extension) } - private fun removeDownloadState(extension: Extension) { - _currentDownloads.update { it - extension.pkgName } - } - private fun addDownloadState(extension: Extension, installStep: InstallStep) { _currentDownloads.update { it + Pair(extension.pkgName, installStep) } } + private fun removeDownloadState(extension: Extension) { + _currentDownloads.update { it - extension.pkgName } + } + private suspend fun Flow.collectToInstallUpdate(extension: Extension) = this .onEach { installStep -> addDownloadState(extension, installStep) } diff --git a/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt b/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt index 35c6bb22e4..6dc77819eb 100644 --- a/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt +++ b/domain/src/main/java/tachiyomi/domain/manga/interactor/SetFetchInterval.kt @@ -40,7 +40,7 @@ class SetFetchInterval( fun getWindow(dateTime: ZonedDateTime): Pair { val today = dateTime.toLocalDate().atStartOfDay(dateTime.zone) val lowerBound = today.minusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong()) - val upperBound = lowerBound.plusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong()) + val upperBound = today.plusDays(FETCH_INTERVAL_GRACE_PERIOD.toLong()) return Pair(lowerBound.toEpochSecond() * 1000, upperBound.toEpochSecond() * 1000 - 1) }