Skip to content

Commit

Permalink
refactor(ExpeditedNotifWorker): Factorize code to create notif
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Feb 26, 2025
1 parent f3b59c1 commit 612c4ab
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions app/src/main/java/com/infomaniak/mail/utils/NotificationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,20 +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(): NotificationCompat.Builder {
return appContext.buildUndeterminedProgressMessageNotification(
channelIdRes = R.string.notification_channel_id_draft_service,
titleRes = R.string.notificationSyncDraftChannelName,
)
}

fun buildSyncMessagesServiceNotification(): NotificationCompat.Builder = with(appContext) {
val channelId = getString(R.string.notification_channel_id_sync_messages_service)
return NotificationCompat.Builder(this, channelId)
.setContentTitle(getString(R.string.notificationSyncMessagesChannelName))
.setSmallIcon(defaultSmallIcon)
.setProgress(100, 0, true)
fun buildSyncMessagesServiceNotification(): NotificationCompat.Builder {
return appContext.buildUndeterminedProgressMessageNotification(
channelIdRes = R.string.notification_channel_id_sync_messages_service,
titleRes = R.string.notificationSyncMessagesChannelName,
)
}

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

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

private fun initMessageNotificationContent(
mailbox: Mailbox,
contentIntent: PendingIntent?,
Expand Down

0 comments on commit 612c4ab

Please sign in to comment.