mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
re-add mark-read action button
This commit is contained in:
@@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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); }
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user