don't show duplicate nofications on android 4

This commit is contained in:
Daniel Gultsch 2016-08-31 17:02:42 +02:00
parent 7917c19d18
commit f14ab4c391

View File

@ -1,7 +1,6 @@
package eu.siacs.conversations.services; package eu.siacs.conversations.services;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent; import android.app.PendingIntent;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
@ -13,6 +12,7 @@ import android.os.SystemClock;
import android.support.v4.app.NotificationCompat; import android.support.v4.app.NotificationCompat;
import android.support.v4.app.NotificationCompat.BigPictureStyle; import android.support.v4.app.NotificationCompat.BigPictureStyle;
import android.support.v4.app.NotificationCompat.Builder; import android.support.v4.app.NotificationCompat.Builder;
import android.support.v4.app.NotificationManagerCompat;
import android.support.v4.app.RemoteInput; import android.support.v4.app.RemoteInput;
import android.support.v4.app.TaskStackBuilder; import android.support.v4.app.TaskStackBuilder;
import android.text.Html; import android.text.Html;
@ -183,8 +183,8 @@ public class NotificationService {
synchronized (notifications) { synchronized (notifications) {
markAsReadIfHasDirectReply(conversation); markAsReadIfHasDirectReply(conversation);
notifications.remove(conversation.getUuid()); notifications.remove(conversation.getUuid());
final NotificationManager nm = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
nm.cancel(conversation.getUuid(), NOTIFICATION_ID); notificationManager.cancel(conversation.getUuid(), NOTIFICATION_ID);
updateNotification(false); updateNotification(false);
} }
} }
@ -207,8 +207,7 @@ public class NotificationService {
} }
public void updateNotification(final boolean notify) { public void updateNotification(final boolean notify) {
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
.getSystemService(Context.NOTIFICATION_SERVICE);
final SharedPreferences preferences = mXmppConnectionService.getPreferences(); final SharedPreferences preferences = mXmppConnectionService.getPreferences();
if (notifications.size() == 0) { if (notifications.size() == 0) {
@ -326,6 +325,7 @@ public class NotificationService {
RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build(); RemoteInput remoteInput = new RemoteInput.Builder("text_reply").setLabel(UIHelper.getMessageHint(mXmppConnectionService, conversation)).build();
NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation)).addRemoteInput(remoteInput).build(); NotificationCompat.Action action = new NotificationCompat.Action.Builder(R.drawable.ic_send_text_offline, "Reply", createReplyIntent(conversation)).addRemoteInput(remoteInput).build();
mBuilder.addAction(action); mBuilder.addAction(action);
}
if ((message = getFirstDownloadableMessage(messages)) != null) { if ((message = getFirstDownloadableMessage(messages)) != null) {
mBuilder.addAction( mBuilder.addAction(
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
@ -335,7 +335,6 @@ public class NotificationService {
createDownloadIntent(message) createDownloadIntent(message)
); );
} }
}
if ((message = getFirstLocationMessage(messages)) != null) { if ((message = getFirstLocationMessage(messages)) != null) {
mBuilder.addAction(R.drawable.ic_room_white_24dp, mBuilder.addAction(R.drawable.ic_room_white_24dp,
mXmppConnectionService.getString(R.string.show_location), mXmppConnectionService.getString(R.string.show_location),
@ -613,7 +612,7 @@ public class NotificationService {
} }
public void updateErrorNotification() { public void updateErrorNotification() {
final NotificationManager notificationManager = (NotificationManager) mXmppConnectionService.getSystemService(Context.NOTIFICATION_SERVICE); final NotificationManagerCompat notificationManager = NotificationManagerCompat.from(mXmppConnectionService);
final List<Account> errors = new ArrayList<>(); final List<Account> errors = new ArrayList<>();
for (final Account account : mXmppConnectionService.getAccounts()) { for (final Account account : mXmppConnectionService.getAccounts()) {
if (account.hasErrorStatus()) { if (account.hasErrorStatus()) {