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
1 changed files with 14 additions and 15 deletions

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,15 +325,15 @@ 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) { }
mBuilder.addAction( if ((message = getFirstDownloadableMessage(messages)) != null) {
Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? mBuilder.addAction(
R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download, Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ?
mXmppConnectionService.getResources().getString(R.string.download_x_file, R.drawable.ic_file_download_white_24dp : R.drawable.ic_action_download,
UIHelper.getFileDescriptionString(mXmppConnectionService, message)), mXmppConnectionService.getResources().getString(R.string.download_x_file,
createDownloadIntent(message) UIHelper.getFileDescriptionString(mXmppConnectionService, 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,
@ -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()) {