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

Unverified Commit 300076c5 authored by cketti's avatar cketti Committed by GitHub
Browse files

Merge pull request #3612 from k9mail/fix_notification_actions

Fix notification actions
parents cd08af28 032c6b3e
Loading
Loading
Loading
Loading
+0 −6
Original line number Diff line number Diff line
@@ -32,9 +32,6 @@ public interface NotificationActionCreator {
    PendingIntent createMarkAllAsReadPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId);

    PendingIntent getMarkAllAsReadPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId);

    PendingIntent getEditIncomingServerSettingsIntent(Account account);

    PendingIntent getEditOutgoingServerSettingsIntent(Account account);
@@ -44,9 +41,6 @@ public interface NotificationActionCreator {
    PendingIntent createDeleteAllPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId);

    PendingIntent getDeleteAllPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId);

    PendingIntent createArchiveMessagePendingIntent(MessageReference messageReference, int notificationId);

    PendingIntent createArchiveAllPendingIntent(Account account, List<MessageReference> messageReferences,
+3 −2
Original line number Diff line number Diff line
@@ -61,7 +61,8 @@ class WearNotifications extends BaseNotifications {
        Account account = notificationData.getAccount();
        ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences();
        int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
        PendingIntent action = actionCreator.getMarkAllAsReadPendingIntent(account, messageReferences, notificationId);
        PendingIntent action = actionCreator.createMarkAllAsReadPendingIntent(
                account, messageReferences, notificationId);

        NotificationCompat.Action markAsReadAction = new NotificationCompat.Action.Builder(icon, title, action).build();
        wearableExtender.addAction(markAsReadAction);
@@ -74,7 +75,7 @@ class WearNotifications extends BaseNotifications {
        Account account = notificationData.getAccount();
        ArrayList<MessageReference> messageReferences = notificationData.getAllMessageReferences();
        int notificationId = NotificationIds.getNewMailSummaryNotificationId(account);
        PendingIntent action = actionCreator.getDeleteAllPendingIntent(account, messageReferences, notificationId);
        PendingIntent action = actionCreator.createDeleteAllPendingIntent(account, messageReferences, notificationId);

        NotificationCompat.Action deleteAction = new NotificationCompat.Action.Builder(icon, title, action).build();
        wearableExtender.addAction(deleteAction);
+2 −2
Original line number Diff line number Diff line
@@ -143,7 +143,7 @@ public class WearNotificationsTest extends RobolectricTest {
        ArrayList<MessageReference> messageReferences = createMessageReferenceList();
        NotificationData notificationData = createNotificationData(messageReferences);
        PendingIntent markAllAsReadPendingIntent = createFakePendingIntent(1);
        when(actionCreator.getMarkAllAsReadPendingIntent(account, messageReferences, notificationId))
        when(actionCreator.createMarkAllAsReadPendingIntent(account, messageReferences, notificationId))
                .thenReturn(markAllAsReadPendingIntent);

        wearNotifications.addSummaryActions(builder, notificationData);
@@ -160,7 +160,7 @@ public class WearNotificationsTest extends RobolectricTest {
        ArrayList<MessageReference> messageReferences = createMessageReferenceList();
        NotificationData notificationData = createNotificationData(messageReferences);
        PendingIntent deletePendingIntent = createFakePendingIntent(1);
        when(actionCreator.getDeleteAllPendingIntent(account, messageReferences, notificationId))
        when(actionCreator.createDeleteAllPendingIntent(account, messageReferences, notificationId))
                .thenReturn(deletePendingIntent);

        wearNotifications.addSummaryActions(builder, notificationData);
+21 −56
Original line number Diff line number Diff line
@@ -44,13 +44,13 @@ class K9NotificationActionCreator implements NotificationActionCreator {
    @Override
    public PendingIntent createViewMessagePendingIntent(MessageReference messageReference, int notificationId) {
        TaskStackBuilder stack = buildMessageViewBackStack(messageReference);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createViewFolderPendingIntent(Account account, String folderServerId, int notificationId) {
        TaskStackBuilder stack = buildMessageListBackStack(account, folderServerId);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
@@ -70,21 +70,20 @@ class K9NotificationActionCreator implements NotificationActionCreator {
            }
        }

        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createViewFolderListPendingIntent(Account account, int notificationId) {
        TaskStackBuilder stack = buildFolderListBackStack(account);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return stack.getPendingIntent(notificationId, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createDismissAllMessagesPendingIntent(Account account, int notificationId) {
        Intent intent = NotificationActionService.createDismissAllMessagesIntent(context, account);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
@@ -93,38 +92,30 @@ class K9NotificationActionCreator implements NotificationActionCreator {

        Intent intent = NotificationActionService.createDismissMessageIntent(context, messageReference);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createReplyPendingIntent(MessageReference messageReference, int notificationId) {
        Intent intent = MessageActions.getActionReplyIntent(context, messageReference);

        return PendingIntent.getActivity(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createMarkMessageAsReadPendingIntent(MessageReference messageReference, int notificationId) {
        Intent intent = NotificationActionService.createMarkMessageAsReadIntent(context, messageReference);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createMarkAllAsReadPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId) {
        return getMarkAsReadPendingIntent(account, messageReferences, notificationId, context,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
    }
        String accountUuid = account.getUuid();
        Intent intent = NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences);

    @Override
    public PendingIntent getMarkAllAsReadPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId) {
        return getMarkAsReadPendingIntent(account, messageReferences, notificationId, context,
                PendingIntent.FLAG_NO_CREATE);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
@@ -143,14 +134,6 @@ class K9NotificationActionCreator implements NotificationActionCreator {
                PendingIntent.FLAG_UPDATE_CURRENT);
    }

    private PendingIntent getMarkAsReadPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId, Context context, int flags) {
        String accountUuid = account.getUuid();
        Intent intent = NotificationActionService.createMarkAllAsReadIntent(context, accountUuid, messageReferences);

        return PendingIntent.getService(context, notificationId, intent, flags);
    }

    @Override
    public PendingIntent createDeleteMessagePendingIntent(MessageReference messageReference, int notificationId) {
        if (K9.confirmDeleteFromNotification()) {
@@ -163,8 +146,7 @@ class K9NotificationActionCreator implements NotificationActionCreator {
    private PendingIntent createDeleteServicePendingIntent(MessageReference messageReference, int notificationId) {
        Intent intent = NotificationActionService.createDeleteMessageIntent(context, messageReference);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    private PendingIntent createDeleteConfirmationPendingIntent(MessageReference messageReference, int notificationId) {
@@ -177,48 +159,33 @@ class K9NotificationActionCreator implements NotificationActionCreator {
    public PendingIntent createDeleteAllPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId) {
        if (K9.confirmDeleteFromNotification()) {
            return getDeleteAllConfirmationPendingIntent(messageReferences, notificationId,
                    PendingIntent.FLAG_CANCEL_CURRENT);
        } else {
            return getDeleteAllServicePendingIntent(account, messageReferences, notificationId,
                    PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        }
    }

    @Override
    public PendingIntent getDeleteAllPendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId) {
        if (K9.confirmDeleteFromNotification()) {
            return getDeleteAllConfirmationPendingIntent(messageReferences, notificationId,
                    PendingIntent.FLAG_NO_CREATE);
            return getDeleteAllConfirmationPendingIntent(messageReferences, notificationId);
        } else {
            return getDeleteAllServicePendingIntent(account, messageReferences, notificationId,
                    PendingIntent.FLAG_NO_CREATE);
            return getDeleteAllServicePendingIntent(account, messageReferences, notificationId);
        }
    }

    private PendingIntent getDeleteAllConfirmationPendingIntent(List<MessageReference> messageReferences,
            int notificationId, int flags) {
            int notificationId) {
        Intent intent = NotificationDeleteConfirmation.getIntent(context, messageReferences);

        return PendingIntent.getActivity(context, notificationId, intent, flags);
        return PendingIntent.getActivity(context, notificationId, intent, PendingIntent.FLAG_CANCEL_CURRENT);
    }

    private PendingIntent getDeleteAllServicePendingIntent(Account account, List<MessageReference> messageReferences,
            int notificationId, int flags) {
            int notificationId) {
        String accountUuid = account.getUuid();
        Intent intent = NotificationActionService.createDeleteAllMessagesIntent(
                context, accountUuid, messageReferences);

        return PendingIntent.getService(context, notificationId, intent, flags);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createArchiveMessagePendingIntent(MessageReference messageReference, int notificationId) {
        Intent intent = NotificationActionService.createArchiveMessageIntent(context, messageReference);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
@@ -226,16 +193,14 @@ class K9NotificationActionCreator implements NotificationActionCreator {
            int notificationId) {
        Intent intent = NotificationActionService.createArchiveAllIntent(context, account, messageReferences);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    @Override
    public PendingIntent createMarkMessageAsSpamPendingIntent(MessageReference messageReference, int notificationId) {
        Intent intent = NotificationActionService.createMarkMessageAsSpamIntent(context, messageReference);

        return PendingIntent.getService(context, notificationId, intent,
                PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_ONE_SHOT);
        return PendingIntent.getService(context, notificationId, intent, PendingIntent.FLAG_UPDATE_CURRENT);
    }

    private TaskStackBuilder buildAccountsBackStack() {