mirror of
https://github.com/deltachat/deltachat-android.git
synced 2025-10-05 10:39:24 +02:00
delete handled notifications
This commit is contained in:
parent
f54d076e0b
commit
ddc770a9c9
4 changed files with 28 additions and 13 deletions
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue