From 4ca0fc7a4d2232ef9a48890b42cd1bd27450b585 Mon Sep 17 00:00:00 2001 From: arkon Date: Sun, 26 Jun 2022 19:11:34 -0400 Subject: [PATCH] Fix app update install notification disappearing --- .../data/notification/Notifications.kt | 1 + .../data/updater/AppUpdateNotifier.kt | 38 +++++++++---------- .../data/updater/AppUpdateService.kt | 5 +-- 3 files changed, 22 insertions(+), 22 deletions(-) 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 1a5ed595ef..bccc31140d 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 @@ -79,6 +79,7 @@ object Notifications { private const val GROUP_APK_UPDATES = "group_apk_updates" const val CHANNEL_APP_UPDATE = "app_apk_update_channel" const val ID_APP_UPDATER = 1 + const val ID_APP_UPDATE_PROMPT = 2 const val CHANNEL_EXTENSIONS_UPDATE = "ext_apk_update_channel" const val ID_UPDATES_TO_EXTS = -401 const val ID_EXTENSION_INSTALLER = -402 diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt index ae8846c5ab..53aacd4cfe 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateNotifier.kt @@ -61,22 +61,6 @@ internal class AppUpdateNotifier(private val context: Context) { notificationBuilder.show() } - /** - * Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based - * updates. - * - * We can prompt them to migrate to the GitHub version though. - */ - fun promptFdroidUpdate() { - with(notificationBuilder) { - setContentTitle(context.getString(R.string.update_check_notification_update_available)) - setContentText(context.getString(R.string.update_check_fdroid_migration_info)) - setSmallIcon(R.drawable.ic_tachi) - setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/faq/#how-do-i-migrate-from-the-f-droid-version")) - } - notificationBuilder.show() - } - /** * Call when apk download starts. * @@ -118,7 +102,7 @@ internal class AppUpdateNotifier(private val context: Context) { * * @param uri path location of apk. */ - fun onDownloadFinished(uri: Uri) { + fun promptInstall(uri: Uri) { val installIntent = NotificationHandler.installApkPendingActivity(context, uri) with(notificationBuilder) { setContentText(context.getString(R.string.update_check_notification_download_complete)) @@ -137,10 +121,26 @@ internal class AppUpdateNotifier(private val context: Context) { addAction( R.drawable.ic_close_24dp, context.getString(R.string.action_cancel), - NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATER), + NotificationReceiver.dismissNotificationPendingBroadcast(context, Notifications.ID_APP_UPDATE_PROMPT), ) } - notificationBuilder.show() + notificationBuilder.show(Notifications.ID_APP_UPDATE_PROMPT) + } + + /** + * Some people are still installing the app from F-Droid, so we avoid prompting GitHub-based + * updates. + * + * We can prompt them to migrate to the GitHub version though. + */ + fun promptFdroidUpdate() { + with(notificationBuilder) { + setContentTitle(context.getString(R.string.update_check_notification_update_available)) + setContentText(context.getString(R.string.update_check_fdroid_migration_info)) + setSmallIcon(R.drawable.ic_tachi) + setContentIntent(NotificationHandler.openUrl(context, "https://tachiyomi.org/help/faq/#how-do-i-migrate-from-the-f-droid-version")) + } + notificationBuilder.show(Notifications.ID_APP_UPDATE_PROMPT) } /** diff --git a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt index 00ddbd2f7d..0620676e96 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/data/updater/AppUpdateService.kt @@ -42,7 +42,6 @@ class AppUpdateService : Service() { private lateinit var notifier: AppUpdateNotifier private var runningJob: Job? = null - private var runningCall: Call? = null override fun onCreate() { @@ -133,7 +132,7 @@ class AppUpdateService : Service() { response.close() throw Exception("Unsuccessful response") } - notifier.onDownloadFinished(apkFile.getUriCompat(this)) + notifier.promptInstall(apkFile.getUriCompat(this)) } catch (error: Exception) { logcat(LogPriority.ERROR, error) if (error is CancellationException || @@ -195,7 +194,7 @@ class AppUpdateService : Service() { val intent = Intent(context, AppUpdateService::class.java).apply { putExtra(EXTRA_DOWNLOAD_URL, url) } - return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT) + return PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE) } } }