From 765da6b65199b51645ebb98998d2e4ad49c0716c Mon Sep 17 00:00:00 2001 From: MohitMaliFtechiz Date: Thu, 27 Feb 2025 16:44:04 +0530 Subject: [PATCH] Fixed: Duplicate resume/cancel buttons in download notification. * When there is a single download running, and we pause the download from the notification then we push a custom notification and update the foreground service notification. So when we are pushing our custom notification it is performing on the IO thread, and when we are setting it on the foreground service, then instead of updating the same notification it creates a new notification and shows it, and in the meantime, our pushing the cancel notification finishes and push a second notification. Due to the same notification ID, it updates the same notification but its actions(resume/cancel) are added twice. * We fixed it by synchronizing the process. Now, it first pushes the notification for paused download, and then if there is no other downloading going then it will set the current notification to foreground service. --- .../FetchDownloadNotificationManager.kt | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt index 6c64661ec..e4da6d4b8 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/downloader/downloadManager/FetchDownloadNotificationManager.kt @@ -58,10 +58,7 @@ import com.tonyodev.fetch2.R.drawable import com.tonyodev.fetch2.R.string import com.tonyodev.fetch2.Status import com.tonyodev.fetch2.util.DEFAULT_NOTIFICATION_TIMEOUT_AFTER_RESET -import kotlinx.coroutines.CoroutineDispatcher -import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.Dispatchers -import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking import org.kiwix.kiwixmobile.core.CoreApp import org.kiwix.kiwixmobile.core.Intents @@ -212,14 +209,11 @@ class FetchDownloadNotificationManager @Inject constructor( fun showDownloadPauseNotification( fetch: Fetch, - download: Download, - dispatcher: CoroutineDispatcher = Dispatchers.IO + download: Download ) { - CoroutineScope(dispatcher).launch { - val notificationBuilder = getNotificationBuilder(download.id, download.id) - val cancelNotification = getCancelNotification(fetch, download, notificationBuilder) - downloadNotificationManager.notify(download.id, cancelNotification) - } + val notificationBuilder = getNotificationBuilder(download.id, download.id) + val cancelNotification = getCancelNotification(fetch, download, notificationBuilder) + downloadNotificationManager.notify(download.id, cancelNotification) } @Suppress("InjectDispatcher")