mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
manually remove summary-notification; this is needed when we cancel the other notifications from within the app
This commit is contained in:
+2
-1
@@ -285,7 +285,8 @@
|
||||
android:enabled="true"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="org.thoughtcrime.securesms.notifications.CLEAR"/>
|
||||
<action android:name="org.thoughtcrime.securesms.notifications.MARK_NOTICED"/>
|
||||
<action android:name="org.thoughtcrime.securesms.notifications.CANCEL"/>
|
||||
</intent-filter>
|
||||
</receiver>
|
||||
|
||||
|
||||
@@ -11,13 +11,14 @@ import org.thoughtcrime.securesms.connect.DcHelper;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
|
||||
public class MarkReadReceiver extends BroadcastReceiver {
|
||||
|
||||
public static final String CLEAR_ACTION = "org.thoughtcrime.securesms.notifications.CLEAR";
|
||||
public static final String MARK_NOTICED_ACTION = "org.thoughtcrime.securesms.notifications.MARK_NOTICED";
|
||||
public static final String CANCEL_ACTION = "org.thoughtcrime.securesms.notifications.CANCEL";
|
||||
public static final String CHAT_ID_EXTRA = "chat_id";
|
||||
|
||||
@Override
|
||||
public void onReceive(final Context context, Intent intent) {
|
||||
if (!CLEAR_ACTION.equals(intent.getAction())) {
|
||||
boolean markNoticed = MARK_NOTICED_ACTION.equals(intent.getAction());
|
||||
if (!markNoticed && !CANCEL_ACTION.equals(intent.getAction())) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -30,7 +31,9 @@ public class MarkReadReceiver extends BroadcastReceiver {
|
||||
|
||||
Util.runOnAnyBackgroundThread(() -> {
|
||||
dcContext.notificationCenter.removeNotifications(chatId);
|
||||
dcContext.marknoticedChat(chatId);
|
||||
if (markNoticed) {
|
||||
dcContext.marknoticedChat(chatId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,8 +116,8 @@ 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);
|
||||
private PendingIntent getMarkAsReadIntent(int chatId, boolean markNoticed) {
|
||||
Intent intent = new Intent(markNoticed? MarkReadReceiver.MARK_NOTICED_ACTION : MarkReadReceiver.CANCEL_ACTION);
|
||||
intent.setClass(context, MarkReadReceiver.class);
|
||||
intent.setData((Uri.parse("custom://"+System.currentTimeMillis())));
|
||||
intent.putExtra(MarkReadReceiver.CHAT_ID_EXTRA, chatId);
|
||||
@@ -351,7 +351,7 @@ public class NotificationCenter {
|
||||
.setGroup(GRP_MSG)
|
||||
.setOnlyAlertOnce(!signal)
|
||||
.setContentText(line)
|
||||
.setDeleteIntent(getDeleteIntent())
|
||||
.setDeleteIntent(getMarkAsReadIntent(chatId, false))
|
||||
.setContentIntent(getOpenChatIntent(chatId));
|
||||
if (privacy.isDisplayContact()) {
|
||||
builder.setContentTitle(dcChat.getName());
|
||||
@@ -417,7 +417,7 @@ public class NotificationCenter {
|
||||
&& !Prefs.isScreenLockEnabled(context)) {
|
||||
try {
|
||||
PendingIntent inNotificationReplyIntent = getRemoteReplyIntent(chatId);
|
||||
PendingIntent markReadIntent = getMarkAsReadIntent(chatId);
|
||||
PendingIntent markReadIntent = getMarkAsReadIntent(chatId, true);
|
||||
|
||||
NotificationCompat.Action markAsReadAction = new NotificationCompat.Action(R.drawable.check,
|
||||
context.getString(R.string.notify_mark_read),
|
||||
@@ -492,11 +492,19 @@ public class NotificationCenter {
|
||||
}
|
||||
|
||||
public void removeNotifications(int chatId) {
|
||||
boolean removeSummary = false;
|
||||
synchronized (inboxes) {
|
||||
inboxes.remove(chatId);
|
||||
removeSummary = inboxes.isEmpty();
|
||||
}
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
notificationManager.cancel(ID_MSG_OFFSET + chatId);
|
||||
|
||||
try {
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
notificationManager.cancel(ID_MSG_OFFSET + chatId);
|
||||
if (removeSummary) {
|
||||
notificationManager.cancel(ID_MSG_SUMMARY);
|
||||
}
|
||||
} catch (Exception e) { Log.w(TAG, e); }
|
||||
}
|
||||
|
||||
public void removeAllNotifiations() {
|
||||
|
||||
Reference in New Issue
Block a user