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);
|
titleView.setTitle(glideRequests, dcChat);
|
||||||
|
|
||||||
dcContext.notificationManger.updateVisibleChat(chatId);
|
dcContext.notificationCenter.updateVisibleChat(chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
processComposeControls(ACTION_SAVE_DRAFT);
|
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);
|
if (isFinishing()) overridePendingTransition(R.anim.fade_scale_in, R.anim.slide_to_right);
|
||||||
quickAttachmentDrawer.onPause();
|
quickAttachmentDrawer.onPause();
|
||||||
inputPanel.onPause();
|
inputPanel.onPause();
|
||||||
|
@ -1224,7 +1224,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||||
|
|
||||||
if (refreshFragment) {
|
if (refreshFragment) {
|
||||||
fragment.reload(recipient, chatId);
|
fragment.reload(recipient, chatId);
|
||||||
dcContext.notificationManger.updateVisibleChat(chatId);
|
dcContext.notificationCenter.updateVisibleChat(chatId);
|
||||||
}
|
}
|
||||||
|
|
||||||
fragment.scrollToBottom();
|
fragment.scrollToBottom();
|
||||||
|
|
|
@ -323,7 +323,7 @@ public class ConversationListFragment extends Fragment
|
||||||
dcContext.marknoticedContact(getListAdapter().getDeaddropContactId());
|
dcContext.marknoticedContact(getListAdapter().getDeaddropContactId());
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dcContext.notificationManger.removeNotifications((int) chatId);
|
dcContext.notificationCenter.removeNotifications((int) chatId);
|
||||||
dcContext.deleteChat((int) chatId);
|
dcContext.deleteChat((int) chatId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -53,7 +53,7 @@ public class ApplicationDcContext extends DcContext {
|
||||||
public static final int RECIPIENT_TYPE_CONTACT = 1;
|
public static final int RECIPIENT_TYPE_CONTACT = 1;
|
||||||
|
|
||||||
public Context context;
|
public Context context;
|
||||||
public NotificationCenter notificationManger;
|
public NotificationCenter notificationCenter;
|
||||||
|
|
||||||
public ApplicationDcContext(Context context) {
|
public ApplicationDcContext(Context context) {
|
||||||
super("Android "+BuildConfig.VERSION_NAME);
|
super("Android "+BuildConfig.VERSION_NAME);
|
||||||
|
@ -122,7 +122,7 @@ public class ApplicationDcContext extends DcContext {
|
||||||
Log.e(TAG, "Cannot create wakeLocks");
|
Log.e(TAG, "Cannot create wakeLocks");
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationManger = new NotificationCenter(this);
|
notificationCenter = new NotificationCenter(this);
|
||||||
startThreads(0);
|
startThreads(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -446,6 +446,7 @@ public class ApplicationDcContext extends DcContext {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void stopThreads() {
|
public void stopThreads() {
|
||||||
|
notificationCenter.removeAllNotifiations();
|
||||||
run = false;
|
run = false;
|
||||||
synchronized (threadsCritical) {
|
synchronized (threadsCritical) {
|
||||||
while (true) {
|
while (true) {
|
||||||
|
@ -580,7 +581,7 @@ public class ApplicationDcContext extends DcContext {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DC_EVENT_INCOMING_MSG:
|
case DC_EVENT_INCOMING_MSG:
|
||||||
Util.runOnAnyBackgroundThread(() -> notificationManger.addNotification((int) data1, (int) data2));
|
notificationCenter.addNotification((int) data1, (int) data2);
|
||||||
if (eventCenter != null) {
|
if (eventCenter != null) {
|
||||||
eventCenter.sendToObservers(event, data1, data2); // Other parts of the code are also interested in this event
|
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);
|
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
|
// create a basic notification
|
||||||
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getNotificationChannel(notificationManager, dcChat))
|
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, getNotificationChannel(notificationManager, dcChat))
|
||||||
.setSmallIcon(R.drawable.icon_notification)
|
.setSmallIcon(R.drawable.icon_notification)
|
||||||
|
@ -264,7 +271,7 @@ public class NotificationCenter {
|
||||||
.setPriority(Prefs.getNotificationPriority(context))
|
.setPriority(Prefs.getNotificationPriority(context))
|
||||||
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
|
||||||
.setContentTitle(dcChat.getName())
|
.setContentTitle(dcChat.getName())
|
||||||
.setContentText(dcContext.getMsg(msgId).getSummarytext(100));
|
.setContentText(text);
|
||||||
|
|
||||||
// set sound, vibrate, led for systems that do not have notification channels
|
// set sound, vibrate, led for systems that do not have notification channels
|
||||||
if (!notificationChannelsSupported()) {
|
if (!notificationChannelsSupported()) {
|
||||||
|
@ -282,22 +289,29 @@ public class NotificationCenter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// add notification
|
// add notification, we use one notification per chat,
|
||||||
notificationManager.notify(ID_MSG_OFFSET+msgId, builder.build());
|
// esp. older android are not that great at grouping
|
||||||
|
notificationManager.notify(ID_MSG_OFFSET+chatId, builder.build());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeNotifications(int chatId) {
|
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) {
|
public void updateVisibleChat(int chatId) {
|
||||||
Util.runOnAnyBackgroundThread(() -> {
|
Util.runOnAnyBackgroundThread(() -> {
|
||||||
|
|
||||||
visibleChatId = chatId;
|
visibleChatId = chatId;
|
||||||
removeNotifications(chatId);
|
if (chatId!=0) {
|
||||||
|
removeNotifications(chatId);
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue