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
This commit is contained in:
LucasGGamerM 2023-04-10 15:12:23 -03:00
parent 0a1c42f90b
commit d6d6155f2c
2 changed files with 6 additions and 6 deletions

View File

@ -52,7 +52,6 @@ public class GlobalUserPreferences{
public static boolean compactReblogReplyLine; public static boolean compactReblogReplyLine;
public static boolean replyLineAboveHeader; public static boolean replyLineAboveHeader;
public static boolean swapBookmarkWithBoostAction; public static boolean swapBookmarkWithBoostAction;
public static int latestNotificationId = 0;
public static String publishButtonText; public static String publishButtonText;
public static ThemePreference theme; public static ThemePreference theme;
public static ColorPreference color; public static ColorPreference color;
@ -73,7 +72,7 @@ public class GlobalUserPreferences{
public static String replyVisibility; public static String replyVisibility;
private static SharedPreferences getPrefs(){ public static SharedPreferences getPrefs(){
return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE); return MastodonApp.context.getSharedPreferences("global", Context.MODE_PRIVATE);
} }
@ -127,7 +126,6 @@ public class GlobalUserPreferences{
accountsWithLocalOnlySupport=prefs.getStringSet("accountsWithLocalOnlySupport", new HashSet<>()); accountsWithLocalOnlySupport=prefs.getStringSet("accountsWithLocalOnlySupport", new HashSet<>());
accountsInGlitchMode=prefs.getStringSet("accountsInGlitchMode", new HashSet<>()); accountsInGlitchMode=prefs.getStringSet("accountsInGlitchMode", new HashSet<>());
replyVisibility=prefs.getString("replyVisibility", null); replyVisibility=prefs.getString("replyVisibility", null);
latestNotificationId=prefs.getInt("latestNotificationId", 0);
try { try {
if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){ if(android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.S){
@ -184,7 +182,6 @@ public class GlobalUserPreferences{
.putStringSet("accountsWithLocalOnlySupport", accountsWithLocalOnlySupport) .putStringSet("accountsWithLocalOnlySupport", accountsWithLocalOnlySupport)
.putStringSet("accountsInGlitchMode", accountsInGlitchMode) .putStringSet("accountsInGlitchMode", accountsInGlitchMode)
.putString("replyVisibility", replyVisibility) .putString("replyVisibility", replyVisibility)
.putInt("latestNotificationId", latestNotificationId)
.apply(); .apply();
} }

View File

@ -1,5 +1,7 @@
package org.joinmastodon.android; package org.joinmastodon.android;
import static org.joinmastodon.android.GlobalUserPreferences.getPrefs;
import android.app.Notification; import android.app.Notification;
import android.app.NotificationChannel; import android.app.NotificationChannel;
import android.app.NotificationChannelGroup; 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 String ACTION_KEY_TEXT_REPLY = "ACTION_KEY_TEXT_REPLY";
private static final int SUMMARY_ID = 791; private static final int SUMMARY_ID = 791;
private static int notificationId = GlobalUserPreferences.latestNotificationId; private static int notificationId;
@Override @Override
public void onReceive(Context context, Intent intent){ 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){ private void notify(Context context, PushNotification pn, String accountID, org.joinmastodon.android.model.Notification notification){
NotificationManager nm=context.getSystemService(NotificationManager.class); NotificationManager nm=context.getSystemService(NotificationManager.class);
notificationId=getPrefs().getInt("latestNotificationId", 0);
Account self=AccountSessionManager.getInstance().getAccount(accountID).self; Account self=AccountSessionManager.getInstance().getAccount(accountID).self;
String accountName="@"+self.username+"@"+AccountSessionManager.getInstance().getAccount(accountID).domain; String accountName="@"+self.username+"@"+AccountSessionManager.getInstance().getAccount(accountID).domain;
Notification.Builder builder; Notification.Builder builder;
@ -214,7 +217,7 @@ public class PushNotificationReceiver extends BroadcastReceiver{
} }
int id = GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId++; int id = GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : notificationId++;
GlobalUserPreferences.save(); getPrefs().edit().putInt("latestNotificationId", notificationId).apply();
if (notification != null){ if (notification != null){
switch (pn.notificationType){ switch (pn.notificationType){