Skip to content

Commit

Permalink
chore(ExpeditedNotifWorker): Apply suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
FabianDevel committed Feb 26, 2025
1 parent 612c4ab commit 6e86f3c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
16 changes: 9 additions & 7 deletions app/src/main/java/com/infomaniak/mail/utils/NotificationUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -123,18 +123,18 @@ class NotificationUtils @Inject constructor(
)
}

fun buildDraftActionsNotification(): NotificationCompat.Builder {
return appContext.buildUndeterminedProgressMessageNotification(
fun buildDraftActionsNotification(): Notification {
return appContext.undeterminedProgressMessageNotificationBuilder(
channelIdRes = R.string.notification_channel_id_draft_service,
titleRes = R.string.notificationSyncDraftChannelName,
)
).build()
}

fun buildSyncMessagesServiceNotification(): NotificationCompat.Builder {
return appContext.buildUndeterminedProgressMessageNotification(
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 @@ -207,13 +207,15 @@ class NotificationUtils @Inject constructor(
).setCategory(Notification.CATEGORY_EMAIL)
}

private fun Context.buildUndeterminedProgressMessageNotification(
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,
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 @@ -101,8 +101,8 @@ class ProcessMessageNotificationsWorker @AssistedInject constructor(
}

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

@Singleton
Expand Down

0 comments on commit 6e86f3c

Please sign in to comment.