Skip to content

Commit

Permalink
fix: Fix notification worker (#2200)
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel authored Feb 26, 2025
2 parents 9b3bc96 + 6e86f3c commit 914c80c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
29 changes: 23 additions & 6 deletions app/src/main/java/com/infomaniak/mail/utils/NotificationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,18 @@ class NotificationUtils @Inject constructor(
)
}

fun buildDraftActionsNotification(): NotificationCompat.Builder = with(appContext) {
val channelId = getString(R.string.notification_channel_id_draft_service)
return NotificationCompat.Builder(this, channelId)
.setContentTitle(getString(R.string.notificationSyncDraftChannelName))
.setSmallIcon(defaultSmallIcon)
.setProgress(100, 0, true)
fun buildDraftActionsNotification(): Notification {
return appContext.undeterminedProgressMessageNotificationBuilder(
channelIdRes = R.string.notification_channel_id_draft_service,
titleRes = R.string.notificationSyncDraftChannelName,
).build()
}

fun buildSyncMessagesServiceNotification(): Notification {
return appContext.undeterminedProgressMessageNotificationBuilder(
channelIdRes = R.string.notification_channel_id_sync_messages_service,
titleRes = R.string.notificationSyncMessagesChannelName,
).build()
}

fun buildDraftErrorNotification(
Expand Down Expand Up @@ -201,6 +207,16 @@ class NotificationUtils @Inject constructor(
).setCategory(Notification.CATEGORY_EMAIL)
}

private fun Context.undeterminedProgressMessageNotificationBuilder(
@StringRes channelIdRes: Int,
@StringRes titleRes: Int,
priority: Int = NotificationCompat.PRIORITY_MIN,
) = NotificationCompat.Builder(this, getString(channelIdRes))
.setContentTitle(getString(titleRes))
.setSmallIcon(defaultSmallIcon)
.setProgress(100, 0, true)
.setPriority(priority)

private fun initMessageNotificationContent(
mailbox: Mailbox,
contentIntent: PendingIntent?,
Expand Down Expand Up @@ -328,6 +344,7 @@ class NotificationUtils @Inject constructor(
private val defaultSmallIcon = R.drawable.ic_logo_notification

const val DRAFT_ACTIONS_ID = 1
const val SYNC_MESSAGES_ID = 2
const val EXTRA_MESSAGE_UID = "messageUid"

fun Context.deleteMailNotificationChannel(mailbox: List<Mailbox>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ class DraftsActionsWorker @AssistedInject constructor(
}

override suspend fun getForegroundInfo(): ForegroundInfo {
val builder = notificationUtils.buildDraftActionsNotification()
return ForegroundInfo(NotificationUtils.DRAFT_ACTIONS_ID, builder.build())
val notification = notificationUtils.buildDraftActionsNotification()
return ForegroundInfo(NotificationUtils.DRAFT_ACTIONS_ID, notification)
}

private suspend fun handleDraftsActions(): Result {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ class ProcessMessageNotificationsWorker @AssistedInject constructor(
}
}

override suspend fun getForegroundInfo(): ForegroundInfo {
val notification = notificationUtils.buildSyncMessagesServiceNotification()
return ForegroundInfo(NotificationUtils.SYNC_MESSAGES_ID, notification)
}

@Singleton
class Scheduler @Inject constructor(private val workManager: WorkManager) {

Expand Down

0 comments on commit 914c80c

Please sign in to comment.