From e8a3bae004f730ee5499cca657dd5f90b0faf079 Mon Sep 17 00:00:00 2001 From: "B. Petersen" Date: Mon, 25 May 2020 14:18:00 +0200 Subject: [PATCH] re-add mark-read action button --- .../notifications/MarkReadReceiver.java | 24 ++++++++++++------- .../notifications/NotificationCenter.java | 20 +++++++++++++--- .../notifications/NotificationState.java | 4 ++-- 3 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index 7ffe4b61b..add98df8b 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -5,26 +5,32 @@ package org.thoughtcrime.securesms.notifications; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; -import android.os.AsyncTask; import org.thoughtcrime.securesms.connect.ApplicationDcContext; import org.thoughtcrime.securesms.connect.DcHelper; +import org.thoughtcrime.securesms.util.Util; public class MarkReadReceiver extends BroadcastReceiver { - private static final String TAG = MarkReadReceiver.class.getSimpleName(); public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR"; - public static final String CHAT_IDS_EXTRA = "chat_ids"; - public static final String NOTIFICATION_ID_EXTRA = "notification_id"; + public static final String CHAT_ID_EXTRA = "chat_id"; @Override public void onReceive(final Context context, Intent intent) { - if (!CLEAR_ACTION.equals(intent.getAction())) + if (!CLEAR_ACTION.equals(intent.getAction())) { return; + } - final int[] chatIds = intent.getIntArrayExtra(CHAT_IDS_EXTRA); - MessageNotifierCompat.removeNotifications(chatIds); - ApplicationDcContext dcContext = DcHelper.getContext(context); - new MarkAsNoticedAsyncTask(chatIds, dcContext, true).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + final int chatId = intent.getIntExtra(CHAT_ID_EXTRA, 0); + if (chatId==0) { + return; + } + + final ApplicationDcContext dcContext = DcHelper.getContext(context); + + Util.runOnAnyBackgroundThread(() -> { + dcContext.notificationCenter.removeNotifications(chatId); + dcContext.marknoticedChat(chatId); + }); } } diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java index 8788e7a67..3e9503b3a 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationCenter.java @@ -116,6 +116,14 @@ public class NotificationCenter { return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); } + private PendingIntent getMarkAsReadIntent(int chatId) { + Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); + intent.setClass(context, MarkReadReceiver.class); + intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); + intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId); + intent.setPackage(context.getPackageName()); + return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); + } // Groups and Notification channel groups @@ -395,12 +403,17 @@ public class NotificationCenter { } catch (Exception e) { Log.w(TAG, e); } } - // add a reply-button that allows answering without opening Delta Chat. - // the reply-button is useful only if sender+message is displayed and if app-lock is disabled. + // add buttons that allow some actions without opening Delta Chat. + // if privacy options are enabled, the buttons are not added. if (privacy.isDisplayContact() && privacy.isDisplayMessage() && !Prefs.isScreenLockEnabled(context)) { try { PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatId); + PendingIntent markReadIntent = getMarkAsReadIntent(chatId); + + NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check, + context.getString(R.string.notify_mark_read), + markReadIntent); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { NotificationCompat.Action replyAction = new NotificationCompat.Action.Builder(R.drawable.ic_reply_white_36dp, @@ -418,7 +431,8 @@ public class NotificationCenter { .addRemoteInput(new RemoteInput.Builder(RemoteReplyReceiver.EXTRA_REMOTE_REPLY) .setLabel(context.getString(R.string.notify_reply_button)).build()) .build(); - builder.extend(new NotificationCompat.WearableExtender().addAction(wearableReplyAction)); + builder.addAction(markAsReadAction); + builder.extend(new NotificationCompat.WearableExtender().addAction(markAsReadAction).addAction(wearableReplyAction)); } catch(Exception e) { Log.w(TAG, e); } } diff --git a/src/org/thoughtcrime/securesms/notifications/NotificationState.java b/src/org/thoughtcrime/securesms/notifications/NotificationState.java index 79bc723ac..2d3f37825 100644 --- a/src/org/thoughtcrime/securesms/notifications/NotificationState.java +++ b/src/org/thoughtcrime/securesms/notifications/NotificationState.java @@ -134,8 +134,8 @@ public class NotificationState { Intent intent = new Intent(MarkReadReceiver.CLEAR_ACTION); intent.setClass(context, MarkReadReceiver.class); intent.setData((Uri.parse("custom://"+System.currentTimeMillis()))); - intent.putExtra(MarkReadReceiver.CHAT_IDS_EXTRA, chatArray); - intent.putExtra(MarkReadReceiver.NOTIFICATION_ID_EXTRA, notificationId); + //intent.putExtra(MarkReadReceiver.CHAT_IDS_EXTRA, chatArray); + //intent.putExtra(MarkReadReceiver.NOTIFICATION_ID_EXTRA, notificationId); return PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); }