delete handled notifications

This commit is contained in:
B. Petersen 2020-05-20 01:18:53 +02:00
parent f54d076e0b
commit ddc770a9c9
No known key found for this signature in database
GPG key ID: 3B88E92DEA8E9AFC
4 changed files with 28 additions and 13 deletions

View file

@ -302,14 +302,14 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
titleView.setTitle(glideRequests, dcChat);
dcContext.notificationManger.updateVisibleChat(chatId);
dcContext.notificationCenter.updateVisibleChat(chatId);
}
@Override
protected void onPause() {
super.onPause();
processComposeControls(ACTION_SAVE_DRAFT);
dcContext.notificationManger.updateVisibleChat(0);
dcContext.notificationCenter.updateVisibleChat(0);
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
quickAttachmentDrawer.onPause();
inputPanel.onPause();
@ -1224,7 +1224,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
if (refreshFragment) {
fragment.reload(recipient, chatId);
dcContext.notificationManger.updateVisibleChat(chatId);
dcContext.notificationCenter.updateVisibleChat(chatId);
}
fragment.scrollToBottom();

View file

@ -323,7 +323,7 @@ public class ConversationListFragment extends Fragment
dcContext.marknoticedContact(getListAdapter().getDeaddropContactId());
}
else {
dcContext.notificationManger.removeNotifications((int) chatId);
dcContext.notificationCenter.removeNotifications((int) chatId);
dcContext.deleteChat((int) chatId);
}
}

View file

@ -53,7 +53,7 @@ public class ApplicationDcContext extends DcContext {
public static final int RECIPIENT_TYPE_CONTACT = 1;
public Context context;
public NotificationCenter notificationManger;
public NotificationCenter notificationCenter;
public ApplicationDcContext(Context context) {
super("Android "+BuildConfig.VERSION_NAME);
@ -122,7 +122,7 @@ public class ApplicationDcContext extends DcContext {
Log.e(TAG, "Cannot create wakeLocks");
}
notificationManger = new NotificationCenter(this);
notificationCenter = new NotificationCenter(this);
startThreads(0);
}
@ -446,6 +446,7 @@ public class ApplicationDcContext extends DcContext {
}
public void stopThreads() {
notificationCenter.removeAllNotifiations();
run = false;
synchronized (threadsCritical) {
while (true) {
@ -580,7 +581,7 @@ public class ApplicationDcContext extends DcContext {
break;
case DC_EVENT_INCOMING_MSG:
Util.runOnAnyBackgroundThread(() -> notificationManger.addNotification((int) data1, (int) data2));
notificationCenter.addNotification((int) data1, (int) data2);
if (eventCenter != null) {
eventCenter.sendToObservers(event, data1, data2); // Other parts of the code are also interested in this event
}

View file

@ -257,6 +257,13 @@ public class NotificationCenter {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
// get notification text
DcMsg dcMsg = dcContext.getMsg(msgId);
String text = dcMsg.getSummarytext(100);
if (dcChat.isGroup()) {
text = dcContext.getContact(dcMsg.getFromId()).getFirstName() + ": " + text;
}
// create a basic notification
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getNotificationChannel(notificationManager, dcChat))
.setSmallIcon(R.drawable.icon_notification)
@ -264,7 +271,7 @@ public class NotificationCenter {
.setPriority(Prefs.getNotificationPriority(context))
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setContentTitle(dcChat.getName())
.setContentText(dcContext.getMsg(msgId).getSummarytext(100));
.setContentText(text);
// set sound, vibrate, led for systems that do not have notification channels
if (!notificationChannelsSupported()) {
@ -282,22 +289,29 @@ public class NotificationCenter {
}
}
// add notification
notificationManager.notify(ID_MSG_OFFSET+msgId, builder.build());
// add notification, we use one notification per chat,
// esp. older android are not that great at grouping
notificationManager.notify(ID_MSG_OFFSET+chatId, builder.build());
});
}
public void removeNotifications(int chatId) {
Util.runOnAnyBackgroundThread(() -> {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancel(ID_MSG_OFFSET + chatId);
}
});
public void removeAllNotifiations() {
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.cancelAll();
}
public void updateVisibleChat(int chatId) {
Util.runOnAnyBackgroundThread(() -> {
visibleChatId = chatId;
if (chatId!=0) {
removeNotifications(chatId);
}
});
}