Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 06e16478 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #1726 from k9mail/fix_notification_grouping

Don't use same notification group key for all accounts
parents 6459f542 ffd051b0
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -14,9 +14,6 @@ import com.fsck.k9.R;


abstract class BaseNotifications {
    protected static final String NOTIFICATION_GROUP_KEY = "newMailNotifications";


    protected final Context context;
    protected final NotificationController controller;
    protected final NotificationActionCreator actionCreator;
@@ -32,10 +29,11 @@ abstract class BaseNotifications {
            int notificationId) {
        String accountName = controller.getAccountName(account);
        NotificationContent content = holder.content;
        String groupKey = NotificationGroupKeys.getGroupKey(account);

        NotificationCompat.Builder builder = createAndInitializeNotificationBuilder(account)
                .setTicker(content.summary)
                .setGroup(NOTIFICATION_GROUP_KEY)
                .setGroup(groupKey)
                .setContentTitle(content.sender)
                .setContentText(content.subject)
                .setSubText(accountName);
+2 −1
Original line number Diff line number Diff line
@@ -130,11 +130,12 @@ class DeviceNotifications extends BaseNotifications {
                context.getString(R.string.notification_additional_messages,
                        notificationData.getAdditionalMessagesCount(), accountName) :
                accountName;
        String groupKey = NotificationGroupKeys.getGroupKey(account);

        NotificationCompat.Builder builder = createAndInitializeNotificationBuilder(account)
                .setNumber(unreadMessageCount)
                .setTicker(latestNotification.content.summary)
                .setGroup(NOTIFICATION_GROUP_KEY)
                .setGroup(groupKey)
                .setGroupSummary(true)
                .setContentTitle(title)
                .setSubText(accountName);
+14 −0
Original line number Diff line number Diff line
package com.fsck.k9.notification;


import com.fsck.k9.Account;


public class NotificationGroupKeys {
    private static final String NOTIFICATION_GROUP_KEY_PREFIX = "newMailNotifications-";
    
    
    public static String getGroupKey(Account account) {
        return NOTIFICATION_GROUP_KEY_PREFIX + account.getAccountNumber();
    }
}
+3 −1
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ import static org.mockito.Mockito.when;
public class BaseNotificationsTest {
    private static final int ACCOUNT_COLOR = 0xAABBCC;
    private static final String ACCOUNT_NAME = "AccountName";
    private static final int ACCOUNT_NUMBER = 2;
    private static final String NOTIFICATION_SUMMARY = "Summary";
    private static final String SENDER = "MessageSender";
    private static final String SUBJECT = "Subject";
@@ -89,7 +90,7 @@ public class BaseNotificationsTest {
        Builder builder = notifications.createBigTextStyleNotification(account, holder, notificationId);

        verify(builder).setTicker(NOTIFICATION_SUMMARY);
        verify(builder).setGroup(BaseNotifications.NOTIFICATION_GROUP_KEY);
        verify(builder).setGroup("newMailNotifications-" + ACCOUNT_NUMBER);
        verify(builder).setContentTitle(SENDER);
        verify(builder).setContentText(SUBJECT);
        verify(builder).setSubText(ACCOUNT_NAME);
@@ -123,6 +124,7 @@ public class BaseNotificationsTest {

    private Account createFakeAccount() {
        Account account = mock(Account.class);
        when(account.getAccountNumber()).thenReturn(ACCOUNT_NUMBER);
        when(account.getChipColor()).thenReturn(ACCOUNT_COLOR);
        return account;
    }
+1 −1
Original line number Diff line number Diff line
@@ -128,7 +128,7 @@ public class DeviceNotificationsTest {
        verify(builder).setTicker(SUMMARY);
        verify(builder).setContentTitle(NEW_MESSAGE_COUNT + " new messages");
        verify(builder).setSubText(ACCOUNT_NAME);
        verify(builder).setGroup("newMailNotifications");
        verify(builder).setGroup("newMailNotifications-" + ACCOUNT_NUMBER);
        verify(builder).setGroupSummary(true);
        verify(builder).setPriority(NotificationCompat.PRIORITY_HIGH);
        verify(builder).setStyle(notifications.inboxStyle);