mirror of
https://github.com/kiwix/kiwix-android.git
synced 2025-09-09 07:16:04 -04:00
Merge pull request #4240 from kiwix/Fixes#4237
Fixed: Duplicate download completed notifications showing.
This commit is contained in:
commit
ed5f7160f1
@ -48,6 +48,8 @@ import org.kiwix.kiwixmobile.core.main.CoreMainActivity
|
||||
import org.kiwix.kiwixmobile.core.utils.DOWNLOAD_NOTIFICATION_CHANNEL_ID
|
||||
import javax.inject.Inject
|
||||
|
||||
const val THIRTY_TREE = 33
|
||||
|
||||
class DownloadMonitorService : Service() {
|
||||
private val updater = PublishSubject.create<() -> Unit>()
|
||||
private var updaterDisposable: Disposable? = null
|
||||
@ -265,7 +267,6 @@ class DownloadMonitorService : Service() {
|
||||
}
|
||||
}
|
||||
|
||||
@Suppress("MagicNumber")
|
||||
private fun showDownloadCompletedNotification(download: Download) {
|
||||
downloadNotificationChannel()
|
||||
val notificationBuilder = getNotificationBuilder(download.id)
|
||||
@ -287,7 +288,10 @@ class DownloadMonitorService : Service() {
|
||||
// notification. If we use the same ID, changing the foreground notification for another
|
||||
// ongoing download cancels the previous notification for that id, preventing the download
|
||||
// complete notification from being displayed.
|
||||
val downloadCompleteNotificationId = download.id + 33
|
||||
val downloadCompleteNotificationId = download.id + THIRTY_TREE
|
||||
// Cancel the complete download notification if already shown due to the application's
|
||||
// lifecycle fetch. See #4237 for more details.
|
||||
cancelNotificationForId(download.id - THIRTY_TREE)
|
||||
notificationManager.notify(downloadCompleteNotificationId, notificationBuilder.build())
|
||||
}
|
||||
|
||||
|
@ -181,6 +181,28 @@ class FetchDownloadNotificationManager @Inject constructor(
|
||||
else -> notificationBuilder.setTimeoutAfter(DEFAULT_NOTIFICATION_TIMEOUT_AFTER_RESET)
|
||||
}
|
||||
notificationCustomisation(downloadNotification, notificationBuilder, context)
|
||||
// Remove the already shown notification if any, because fetch now pushes a
|
||||
// download complete notification.
|
||||
removeNotificationIfAlreadyShowingForCompletedDownload(downloadNotification)
|
||||
}
|
||||
|
||||
/**
|
||||
* We are adding 33 to the groupId (which is the download ID) because the download
|
||||
* complete notification is shown by DownloadMonitorService. If the application resumes
|
||||
* just before the download completes, Fetch in the application might also push a
|
||||
* download complete notification.
|
||||
*
|
||||
* To avoid duplicate notifications, we clear the previous notification if it is already shown.
|
||||
* See #4237 for more information.
|
||||
*
|
||||
* @see DownloadMonitorService.showDownloadCompletedNotification
|
||||
*/
|
||||
private fun removeNotificationIfAlreadyShowingForCompletedDownload(
|
||||
downloadNotification: DownloadNotification
|
||||
) {
|
||||
if (downloadNotification.isCompleted) {
|
||||
downloadNotificationManager.cancel(downloadNotification.groupId + THIRTY_TREE)
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("UnspecifiedImmutableFlag")
|
||||
|
Loading…
x
Reference in New Issue
Block a user