mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-09 09:28:34 +00:00
Consolidate Notification Ids to a centralized constants class.
This commit is contained in:
parent
72e10ac597
commit
b10ce080a9
@ -15,13 +15,12 @@ import androidx.viewpager.widget.ViewPager;
|
||||
import android.view.View;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import com.nineoldandroids.animation.ArgbEvaluator;
|
||||
|
||||
import org.thoughtcrime.securesms.IntroPagerAdapter.IntroPage;
|
||||
import org.thoughtcrime.securesms.database.model.Sticker;
|
||||
import org.thoughtcrime.securesms.experienceupgrades.StickersIntroFragment;
|
||||
import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationIds;
|
||||
import org.thoughtcrime.securesms.util.DynamicNoActionBarTheme;
|
||||
import org.thoughtcrime.securesms.util.DynamicTheme;
|
||||
import org.thoughtcrime.securesms.util.ServiceUtil;
|
||||
@ -40,7 +39,6 @@ public class ExperienceUpgradeActivity extends BaseActionBarActivity
|
||||
{
|
||||
private static final String TAG = ExperienceUpgradeActivity.class.getSimpleName();
|
||||
private static final String DISMISS_ACTION = "org.thoughtcrime.securesms.ExperienceUpgradeActivity.DISMISS_ACTION";
|
||||
private static final int NOTIFICATION_ID = 1339;
|
||||
|
||||
private final DynamicTheme dynamicTheme = new DynamicNoActionBarTheme();
|
||||
|
||||
@ -196,7 +194,7 @@ public class ExperienceUpgradeActivity extends BaseActionBarActivity
|
||||
}
|
||||
|
||||
getWindow().setBackgroundDrawable(new ColorDrawable(upgrade.get().getPage(0).backgroundColor));
|
||||
ServiceUtil.getNotificationManager(this).cancel(NOTIFICATION_ID);
|
||||
ServiceUtil.getNotificationManager(this).cancel(NotificationIds.EXPERIENCE_UPGRADE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -206,7 +204,7 @@ public class ExperienceUpgradeActivity extends BaseActionBarActivity
|
||||
}
|
||||
|
||||
private void onContinue(Optional<ExperienceUpgrade> seenUpgrade) {
|
||||
ServiceUtil.getNotificationManager(this).cancel(NOTIFICATION_ID);
|
||||
ServiceUtil.getNotificationManager(this).cancel(NotificationIds.EXPERIENCE_UPGRADE);
|
||||
int latestVersion = seenUpgrade.isPresent() ? seenUpgrade.get().getVersion()
|
||||
: Util.getCanonicalVersionCode();
|
||||
TextSecurePreferences.setLastExperienceVersionCode(this, latestVersion);
|
||||
@ -281,7 +279,7 @@ public class ExperienceUpgradeActivity extends BaseActionBarActivity
|
||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.build();
|
||||
|
||||
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
|
||||
ServiceUtil.getNotificationManager(context).notify(NotificationIds.EXPERIENCE_UPGRADE, notification);
|
||||
}
|
||||
|
||||
Optional<ExperienceUpgrade> experienceUpgrade = getExperienceUpgrade(context);
|
||||
@ -313,7 +311,7 @@ public class ExperienceUpgradeActivity extends BaseActionBarActivity
|
||||
dismissIntent,
|
||||
PendingIntent.FLAG_UPDATE_CURRENT))
|
||||
.build();
|
||||
ServiceUtil.getNotificationManager(context).notify(NOTIFICATION_ID, notification);
|
||||
ServiceUtil.getNotificationManager(context).notify(NotificationIds.EXPERIENCE_UPGRADE, notification);
|
||||
} else if (DISMISS_ACTION.equals(intent.getAction())) {
|
||||
TextSecurePreferences.setExperienceDismissedVersionCode(context, Util.getCanonicalVersionCode());
|
||||
}
|
||||
|
@ -37,6 +37,7 @@ import org.thoughtcrime.securesms.logging.Log;
|
||||
import org.thoughtcrime.securesms.PlayServicesProblemActivity;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationIds;
|
||||
import org.thoughtcrime.securesms.transport.RetryLaterException;
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
@ -134,7 +135,7 @@ public class FcmRefreshJob extends BaseJob {
|
||||
builder.setContentIntent(pendingIntent);
|
||||
|
||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.notify(12, builder.build());
|
||||
.notify(NotificationIds.FCM_FAILURE, builder.build());
|
||||
}
|
||||
|
||||
public static final class Factory implements Job.Factory<FcmRefreshJob> {
|
||||
|
@ -95,8 +95,6 @@ public class MessageNotifier {
|
||||
public static final String EXTRA_REMOTE_REPLY = "extra_remote_reply";
|
||||
|
||||
private static final String EMOJI_REPLACEMENT_STRING = "__EMOJI__";
|
||||
private static final int SUMMARY_NOTIFICATION_ID = 1338;
|
||||
private static final int PENDING_MESSAGES_ID = 1111;
|
||||
private static final String NOTIFICATION_GROUP = "messages";
|
||||
private static final long MIN_AUDIBLE_PERIOD_MILLIS = TimeUnit.SECONDS.toMillis(2);
|
||||
private static final long DESKTOP_ACTIVITY_PERIOD = TimeUnit.MINUTES.toMillis(1);
|
||||
@ -135,11 +133,11 @@ public class MessageNotifier {
|
||||
}
|
||||
|
||||
PendingMessageNotificationBuilder builder = new PendingMessageNotificationBuilder(context, TextSecurePreferences.getNotificationPrivacy(context));
|
||||
ServiceUtil.getNotificationManager(context).notify(PENDING_MESSAGES_ID, builder.build());
|
||||
ServiceUtil.getNotificationManager(context).notify(NotificationIds.PENDING_MESSAGES, builder.build());
|
||||
}
|
||||
|
||||
public static void cancelMessagesPending(Context context) {
|
||||
ServiceUtil.getNotificationManager(context).cancel(PENDING_MESSAGES_ID);
|
||||
ServiceUtil.getNotificationManager(context).cancel(NotificationIds.PENDING_MESSAGES);
|
||||
}
|
||||
|
||||
public static void cancelDelayedNotifications() {
|
||||
@ -148,7 +146,7 @@ public class MessageNotifier {
|
||||
|
||||
private static void cancelActiveNotifications(@NonNull Context context) {
|
||||
NotificationManager notifications = ServiceUtil.getNotificationManager(context);
|
||||
notifications.cancel(SUMMARY_NOTIFICATION_ID);
|
||||
notifications.cancel(NotificationIds.MESSAGE_SUMMARY);
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
try {
|
||||
@ -174,7 +172,7 @@ public class MessageNotifier {
|
||||
StatusBarNotification[] activeNotifications = notificationManager.getActiveNotifications();
|
||||
|
||||
for (StatusBarNotification activeNotification : activeNotifications) {
|
||||
if (activeNotification.getId() == SUMMARY_NOTIFICATION_ID) {
|
||||
if (activeNotification.getId() == NotificationIds.MESSAGE_SUMMARY) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -200,14 +198,14 @@ public class MessageNotifier {
|
||||
for (StatusBarNotification notification : activeNotifications) {
|
||||
boolean validNotification = false;
|
||||
|
||||
if (notification.getId() != SUMMARY_NOTIFICATION_ID &&
|
||||
if (notification.getId() != NotificationIds.MESSAGE_SUMMARY &&
|
||||
notification.getId() != KeyCachingService.SERVICE_RUNNING_ID &&
|
||||
notification.getId() != IncomingMessageObserver.FOREGROUND_ID &&
|
||||
notification.getId() != PENDING_MESSAGES_ID &&
|
||||
notification.getId() != NotificationIds.PENDING_MESSAGES &&
|
||||
!CallNotificationBuilder.isWebRtcNotification(notification.getId()))
|
||||
{
|
||||
for (NotificationItem item : notificationState.getNotifications()) {
|
||||
if (notification.getId() == (SUMMARY_NOTIFICATION_ID + item.getThreadId())) {
|
||||
if (notification.getId() == NotificationIds.getNotificationIdForThread(item.getThreadId())) {
|
||||
validNotification = true;
|
||||
break;
|
||||
}
|
||||
@ -352,9 +350,9 @@ public class MessageNotifier {
|
||||
int notificationId;
|
||||
|
||||
if (Build.VERSION.SDK_INT >= 23) {
|
||||
notificationId = (int) (SUMMARY_NOTIFICATION_ID + notifications.get(0).getThreadId());
|
||||
notificationId = NotificationIds.getNotificationIdForThread(notifications.get(0).getThreadId());
|
||||
} else {
|
||||
notificationId = SUMMARY_NOTIFICATION_ID;
|
||||
notificationId = NotificationIds.MESSAGE_SUMMARY;
|
||||
}
|
||||
|
||||
builder.setThread(notifications.get(0).getRecipient());
|
||||
@ -426,7 +424,7 @@ public class MessageNotifier {
|
||||
long timestamp = notifications.get(0).getTimestamp();
|
||||
if (timestamp != 0) builder.setWhen(timestamp);
|
||||
|
||||
builder.addActions(notificationState.getMarkAsReadIntent(context, SUMMARY_NOTIFICATION_ID));
|
||||
builder.addActions(notificationState.getMarkAsReadIntent(context, NotificationIds.MESSAGE_SUMMARY));
|
||||
|
||||
ListIterator<NotificationItem> iterator = notifications.listIterator(notifications.size());
|
||||
|
||||
@ -442,7 +440,7 @@ public class MessageNotifier {
|
||||
}
|
||||
|
||||
Notification notification = builder.build();
|
||||
NotificationManagerCompat.from(context).notify(SUMMARY_NOTIFICATION_ID, builder.build());
|
||||
NotificationManagerCompat.from(context).notify(NotificationIds.MESSAGE_SUMMARY, builder.build());
|
||||
Log.i(TAG, "Posted notification. " + notification.toString());
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,19 @@
|
||||
package org.thoughtcrime.securesms.notifications;
|
||||
|
||||
public final class NotificationIds {
|
||||
|
||||
public static final int FCM_FAILURE = 12;
|
||||
public static final int PENDING_MESSAGES = 1111;
|
||||
public static final int MESSAGE_SUMMARY = 1338;
|
||||
public static final int EXPERIENCE_UPGRADE = 1339;
|
||||
public static final int APPLICATION_MIGRATION = 4242;
|
||||
public static final int SMS_IMPORT_COMPLETE = 31337;
|
||||
public static final int THREAD = 50000;
|
||||
|
||||
private NotificationIds() { }
|
||||
|
||||
public static int getNotificationIdForThread(long threadId) {
|
||||
return THREAD + (int) threadId;
|
||||
}
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.SmsMigrator;
|
||||
import org.thoughtcrime.securesms.database.SmsMigrator.ProgressDescription;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationChannels;
|
||||
import org.thoughtcrime.securesms.notifications.NotificationIds;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.concurrent.Executor;
|
||||
@ -121,7 +122,7 @@ public class ApplicationMigrationService extends Service
|
||||
notification.setProgress(total, complete, false);
|
||||
|
||||
((NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE))
|
||||
.notify(4242, notification.build());
|
||||
.notify(NotificationIds.APPLICATION_MIGRATION, notification.build());
|
||||
}
|
||||
|
||||
private NotificationCompat.Builder initializeBackgroundNotification() {
|
||||
@ -137,7 +138,7 @@ public class ApplicationMigrationService extends Service
|
||||
builder.setContentIntent(PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0));
|
||||
|
||||
stopForeground(true);
|
||||
startForeground(4242, builder.build());
|
||||
startForeground(NotificationIds.APPLICATION_MIGRATION, builder.build());
|
||||
|
||||
return builder;
|
||||
}
|
||||
@ -192,7 +193,7 @@ public class ApplicationMigrationService extends Service
|
||||
builder.setAutoCancel(true);
|
||||
|
||||
Notification notification = builder.build();
|
||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(31337, notification);
|
||||
((NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE)).notify(NotificationIds.SMS_IMPORT_COMPLETE, notification);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user