From f5e5df7429efc924c9cec73c503086d047160654 Mon Sep 17 00:00:00 2001 From: Christian Schneppe Date: Fri, 21 Apr 2017 19:42:39 +0200 Subject: reworked unique id generation for notification intents --- .../pixart/messenger/services/NotificationService.java | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'src/main/java/de/pixart/messenger') diff --git a/src/main/java/de/pixart/messenger/services/NotificationService.java b/src/main/java/de/pixart/messenger/services/NotificationService.java index 7cdc6b35b..ce9a9e528 100644 --- a/src/main/java/de/pixart/messenger/services/NotificationService.java +++ b/src/main/java/de/pixart/messenger/services/NotificationService.java @@ -47,9 +47,10 @@ import de.pixart.messenger.utils.UIHelper; public class NotificationService { - public static final int NOTIFICATION_ID = 0x2342; - public static final int FOREGROUND_NOTIFICATION_ID = 0x8899; - public static final int ERROR_NOTIFICATION_ID = 0x5678; + private static final int NOTIFICATION_ID_MULTIPLIER = 1024 * 1024; + public static final int NOTIFICATION_ID = 2 * NOTIFICATION_ID_MULTIPLIER; + public static final int FOREGROUND_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 4; + public static final int ERROR_NOTIFICATION_ID = NOTIFICATION_ID_MULTIPLIER * 6; private static final String CONVERSATIONS_GROUP = "de.pixart.messenger"; private final XmppConnectionService mXmppConnectionService; private final LinkedHashMap> notifications = new LinkedHashMap<>(); @@ -535,12 +536,12 @@ public class NotificationService { if (downloadMessageUuid != null) { viewConversationIntent.putExtra(ConversationActivity.EXTRA_DOWNLOAD_UUID, downloadMessageUuid); return PendingIntent.getActivity(mXmppConnectionService, - conversationUuid.hashCode() % 389782, + (conversationUuid.hashCode() % NOTIFICATION_ID_MULTIPLIER) + 8 * NOTIFICATION_ID_MULTIPLIER, viewConversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); } else { return PendingIntent.getActivity(mXmppConnectionService, - conversationUuid.hashCode() % 936236, + (conversationUuid.hashCode() % NOTIFICATION_ID_MULTIPLIER) + 10 * NOTIFICATION_ID_MULTIPLIER, viewConversationIntent, PendingIntent.FLAG_UPDATE_CURRENT); } @@ -559,7 +560,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_CLEAR_NOTIFICATION); if (conversation != null) { intent.putExtra("uuid", conversation.getUuid()); - return PendingIntent.getService(mXmppConnectionService, conversation.getUuid().hashCode() % 247527, intent, 0); + return PendingIntent.getService(mXmppConnectionService, (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + 12 * NOTIFICATION_ID_MULTIPLIER, intent, 0); } return PendingIntent.getService(mXmppConnectionService, 0, intent, 0); } @@ -569,7 +570,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_REPLY_TO_CONVERSATION); intent.putExtra("uuid", conversation.getUuid()); intent.putExtra("dismiss_notification", dismissAfterReply); - int id = conversation.getUuid().hashCode() % (dismissAfterReply ? 402359 : 426583); + int id = (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + (dismissAfterReply ? 12 : 14) * NOTIFICATION_ID_MULTIPLIER; return PendingIntent.getService(mXmppConnectionService, id, intent, 0); } @@ -578,7 +579,7 @@ public class NotificationService { intent.setAction(XmppConnectionService.ACTION_MARK_AS_READ); intent.putExtra("uuid", conversation.getUuid()); intent.setPackage(mXmppConnectionService.getPackageName()); - return PendingIntent.getService(mXmppConnectionService, conversation.getUuid().hashCode() % 247527, intent, PendingIntent.FLAG_UPDATE_CURRENT); + return PendingIntent.getService(mXmppConnectionService, (conversation.getUuid().hashCode() % NOTIFICATION_ID_MULTIPLIER) + 16 * NOTIFICATION_ID_MULTIPLIER, intent, PendingIntent.FLAG_UPDATE_CURRENT); } private PendingIntent createDisableForeground() { -- cgit v1.2.3