0
0
mirror of https://github.com/mediathekview/zapp.git synced 2024-09-20 04:12:14 +02:00

Show notification on retry

This commit is contained in:
Christine Coenen 2022-10-29 10:53:01 +02:00
parent fbe69b211f
commit 405f4fbb9d
5 changed files with 47 additions and 11 deletions

View File

@ -10,6 +10,7 @@ import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exception
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.NoNetworkException
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.exceptions.WrongNetworkConditionException
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.notifications.DownloadQueuedEventNotification
import de.christinecoenen.code.zapp.app.mediathek.controller.downloads.notifications.DownloadQueuedForRetryEventNotification
import de.christinecoenen.code.zapp.app.settings.repository.SettingsRepository
import de.christinecoenen.code.zapp.models.shows.DownloadStatus
import de.christinecoenen.code.zapp.models.shows.PersistedMediathekShow
@ -189,7 +190,7 @@ class WorkManagerDownloadController(
mediathekRepository.updateShow(show)
showStatusChangeNotificationIfNeeded(workInfo.id, show)
showStatusChangeNotificationIfNeeded(workInfo, show)
deleteFileOnStatusChangeIfNeeded(show)
updateMediaCollectionOnStatusChangeIfNeeded(show)
}
@ -218,7 +219,7 @@ class WorkManagerDownloadController(
}
private fun showStatusChangeNotificationIfNeeded(
workId: UUID,
workInfo: WorkInfo,
show: PersistedMediathekShow
) {
if (!notificationManager.areNotificationsEnabled()) {
@ -228,14 +229,24 @@ class WorkManagerDownloadController(
val notificationTitle = show.mediathekShow.title
val notification = when (show.downloadStatus) {
DownloadStatus.QUEUED -> {
// TODO: show different notification if workInfo.runAttemptCount is greater zero
val cancelIntent = workManager.createCancelPendingIntent(workId)
DownloadQueuedEventNotification(
applicationContext,
notificationTitle,
show.id,
cancelIntent
)
val cancelIntent = workManager.createCancelPendingIntent(workInfo.id)
if (workInfo.runAttemptCount == 0) {
DownloadQueuedEventNotification(
applicationContext,
notificationTitle,
show.id,
cancelIntent
)
} else {
DownloadQueuedForRetryEventNotification(
applicationContext,
notificationTitle,
show.id,
workInfo.runAttemptCount,
cancelIntent
)
}
}
DownloadStatus.CANCELLED -> {
notificationManager.cancel(show.downloadId)

View File

@ -5,7 +5,7 @@ import android.app.PendingIntent
import android.content.Context
import de.christinecoenen.code.zapp.R
class DownloadQueuedEventNotification(
open class DownloadQueuedEventNotification(
appContext: Context,
title: String,
persistedShowId: Int,

View File

@ -0,0 +1,23 @@
package de.christinecoenen.code.zapp.app.mediathek.controller.downloads.notifications
import android.app.PendingIntent
import android.content.Context
import de.christinecoenen.code.zapp.R
class DownloadQueuedForRetryEventNotification(
appContext: Context,
title: String,
persistedShowId: Int,
attemptCount: Int,
cancelIntent: PendingIntent
) : DownloadQueuedEventNotification(appContext, title, persistedShowId, cancelIntent) {
init {
notificationBuilder.setContentText(
appContext.getString(
R.string.notification_download_queued_for_retry, attemptCount + 1
)
)
}
}

View File

@ -134,6 +134,7 @@
<!-- download notifications -->
<string name="notification_download_queued">The download starts as soon as all prerequisites are met.</string>
<string name="notification_download_queued_for_retry">Download interrupted waiting for attempt no. %1$d.</string>
<string name="notification_download_downloading">Downloading</string>
<string name="notification_download_downloading_size">%1$s / %2$s</string>
<string name="notification_download_complete">Download complete</string>

View File

@ -134,6 +134,7 @@
<!-- download notifications -->
<string name="notification_download_queued">Der Download beginnt, sobald alle Voraussetzungen dafür erfüllt sind.</string>
<string name="notification_download_queued_for_retry">Download unterbrochen warte auf Versuch Nummer %1$d.</string>
<string name="notification_download_downloading">Lädt herunter</string>
<string name="notification_download_downloading_size">%1$s / %2$s</string>
<string name="notification_download_complete">Download abgeschlossen</string>