Update sync notification instead of recreating it for every folder

This commit is contained in:
cketti 2021-09-17 05:11:18 +02:00
parent 2cf8d2afc3
commit 29e1593d79
4 changed files with 54 additions and 3 deletions

View file

@ -2427,6 +2427,8 @@ public class MessagingController {
public void run() {
Timber.v("Clearing notification flag for %s", account.getDescription());
clearFetchingMailNotification(account);
if (getUnreadMessageCount(account) == 0) {
notificationController.clearNewMailNotifications(account);
}
@ -2471,7 +2473,7 @@ public class MessagingController {
try {
synchronizeMailboxSynchronous(account, folder.getDatabaseId(), listener, notificationState);
} finally {
clearFetchingMailNotificationIfNecessary(account);
showEmptyFetchingMailNotificationIfNecessary(account);
}
} catch (Exception e) {
Timber.e(e, "Exception while processing folder %s:%s", account.getDescription(), folder.getServerId());
@ -2484,12 +2486,15 @@ public class MessagingController {
}
}
private void clearFetchingMailNotificationIfNecessary(Account account) {
private void showEmptyFetchingMailNotificationIfNecessary(Account account) {
if (account.isNotifySync()) {
notificationController.clearFetchingMailNotification(account);
notificationController.showEmptyFetchingMailNotification(account);
}
}
private void clearFetchingMailNotification(Account account) {
notificationController.clearFetchingMailNotification(account);
}
public void compact(final Account account, final MessagingListener ml) {
putBackground("compact:" + account.getDescription(), ml, new Runnable() {

View file

@ -48,6 +48,10 @@ class NotificationController internal constructor(
syncNotifications.showFetchingMailNotification(account, folder)
}
fun showEmptyFetchingMailNotification(account: Account) {
syncNotifications.showEmptyFetchingMailNotification(account)
}
fun clearFetchingMailNotification(account: Account) {
syncNotifications.clearFetchingMailNotification(account)
}

View file

@ -94,6 +94,35 @@ internal class SyncNotifications(
notificationManager.notify(notificationId, notificationBuilder.build())
}
fun showEmptyFetchingMailNotification(account: Account) {
val title = resourceProvider.checkingMailTitle()
val text = account.description
val notificationId = NotificationIds.getFetchingMailNotificationId(account)
val notificationBuilder = notificationHelper
.createNotificationBuilder(account, NotificationChannelManager.ChannelType.MISCELLANEOUS)
.setSmallIcon(resourceProvider.iconCheckingMail)
.setWhen(System.currentTimeMillis())
.setOngoing(true)
.setContentTitle(title)
.setContentText(text)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCategory(NotificationCompat.CATEGORY_SERVICE)
if (NOTIFICATION_LED_WHILE_SYNCING) {
notificationHelper.configureNotification(
builder = notificationBuilder,
ringtone = null,
vibrationPattern = null,
ledColor = account.notificationSetting.ledColor,
ledSpeed = NotificationHelper.NOTIFICATION_LED_BLINK_FAST,
ringAndVibrate = true
)
}
notificationManager.notify(notificationId, notificationBuilder.build())
}
fun clearFetchingMailNotification(account: Account) {
val notificationId = NotificationIds.getFetchingMailNotificationId(account)
notificationManager.cancel(notificationId)

View file

@ -77,6 +77,19 @@ class SyncNotificationsTest : RobolectricTest() {
verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
}
@Test
fun testShowEmptyFetchingMailNotification() {
val notificationId = getFetchingMailNotificationId(account)
syncNotifications.showEmptyFetchingMailNotification(account)
verify(notificationManager).notify(notificationId, notification)
verify(builder).setSmallIcon(resourceProvider.iconCheckingMail)
verify(builder).setContentTitle("Checking mail")
verify(builder).setContentText(ACCOUNT_NAME)
verify(builder).setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
}
@Test
fun testClearSendFailedNotification() {
val notificationId = getFetchingMailNotificationId(account)