From d6d6155f2c477d0c9349c181427d4ec0b9ef8f41 Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Mon, 10 Apr 2023 15:12:23 -0300 Subject: [PATCH] refactor: move LatestNotificationID preference away from GlobalUserPreferences This is solely for the purpose of organization, as I think GlobalUserPreferences should only directly contain Global user preferences --- .../org/joinmastodon/android/GlobalUserPreferences.java | 5 +---- .../org/joinmastodon/android/PushNotificationReceiver.java | 7 +++++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index bcd85af70..e26faccee 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -52,7 +52,6 @@ public class GlobalUserPreferences{ public static boolean compactReblogReplyLine; public static boolean replyLineAboveHeader; public static boolean swapBookmarkWithBoostAction; - public static int latestNotificationId = 0; public static String publishButtonText; public static ThemePreference theme; public static ColorPreference color; @@ -73,7 +72,7 @@ public class GlobalUserPreferences{ public static String replyVisibility; - private static SharedPreferences getPrefs(){ + public static SharedPreferences getPrefs(){ return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); } @@ -127,7 +126,6 @@ public class GlobalUserPreferences{ accountsWithLocalOnlySupport=prefs.getStringSet("accountsWithLocalOnlySupport", new HashSet<>()); accountsInGlitchMode=prefs.getStringSet("accountsInGlitchMode", new HashSet<>()); replyVisibility=prefs.getString("replyVisibility", null); - latestNotificationId=prefs.getInt("latestNotificationId", 0); try { if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ @@ -184,7 +182,6 @@ public class GlobalUserPreferences{ .putStringSet("accountsWithLocalOnlySupport", accountsWithLocalOnlySupport) .putStringSet("accountsInGlitchMode", accountsInGlitchMode) .putString("replyVisibility", replyVisibility) - .putInt("latestNotificationId", latestNotificationId) .apply(); } diff --git a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java index 41fae8d6a..4748b4429 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java @@ -1,5 +1,7 @@ package org.joinmastodon.android; +import static org.joinmastodon.android.GlobalUserPreferences.getPrefs; + import android.app.Notification; import android.app.NotificationChannel; import android.app.NotificationChannelGroup; @@ -54,7 +56,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{ private static final String ACTION_KEY_TEXT_REPLY = "ACTION_KEY_TEXT_REPLY"; private static final int SUMMARY_ID = 791; - private static int notificationId = GlobalUserPreferences.latestNotificationId; + private static int notificationId; @Override public void onReceive(Context context, Intent intent){ @@ -143,6 +145,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{ private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){ NotificationManager nm=context.getSystemService(NotificationManager.class); + notificationId=getPrefs().getInt("latestNotificationId", 0); Account self=AccountSessionManager.getInstance().getAccount(accountID).self; String accountName="@"+self.username+"@"+AccountSessionManager.getInstance().getAccount(accountID).domain; Notification.Builder builder; @@ -214,7 +217,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{ } int id = GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId++; - GlobalUserPreferences.save(); + getPrefs().edit().putInt("latestNotificationId", notificationId).apply(); if (notification != null){ switch (pn.notificationType){