From cca2fc4199b6e46cf84d0eb88f7fdbc0f04d4a5c Mon Sep 17 00:00:00 2001 From: LucasGGamerM Date: Tue, 10 Jan 2023 21:45:35 -0300 Subject: [PATCH] Possibly fixing #29 for good, but the mastodon servers of the accounts I own are slow, so there is basically no way to test it (cherry picked from commit a48dc18df5e417c5182b5f7cff4639fec807a2b6) --- .../java/org/joinmastodon/android/MainActivity.java | 2 +- .../joinmastodon/android/PushNotificationReceiver.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java index ba3aecb1f..671fc02ca 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java +++ b/mastodon/src/main/java/org/joinmastodon/android/MainActivity.java @@ -56,7 +56,7 @@ public class MainActivity extends FragmentStackActivity{ fragment.setArguments(args); showFragmentClearingBackStack(fragment); if(intent.getBooleanExtra("fromNotification", false) && intent.hasExtra("notification")){ - Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification")); + Notification notification=Parcels.unwrap(intent.getParcelableExtra("notification"+intent.getParcelableExtra("notificationID"))); showFragmentForNotification(notification, session.getID()); }else if(intent.getBooleanExtra("compose", false)){ showCompose(); diff --git a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java index 560127c64..0d1f1bb85 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java @@ -38,6 +38,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{ public static final int NOTIFICATION_ID=178; + private static int notificationID; + @Override public void onReceive(Context context, Intent intent){ if(BuildConfig.DEBUG){ @@ -125,12 +127,16 @@ public class PushNotificationReceiver extends BroadcastReceiver{ .setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE); } Drawable avatar=ImageCache.getInstance(context).get(new UrlImageLoaderRequest(pn.icon, V.dp(50), V.dp(50))); + + notificationID = GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : (int)System.currentTimeMillis(); + Intent contentIntent=new Intent(context, MainActivity.class); contentIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); contentIntent.putExtra("fromNotification", true); contentIntent.putExtra("accountID", accountID); + contentIntent.putExtra("notificationID", notificationID); if(notification!=null){ - contentIntent.putExtra("notification", Parcels.wrap(notification)); + contentIntent.putExtra("notification" + notificationID, Parcels.wrap(notification)); } builder.setContentTitle(pn.title) .setContentText(pn.body) @@ -160,6 +166,6 @@ public class PushNotificationReceiver extends BroadcastReceiver{ if(AccountSessionManager.getInstance().getLoggedInAccounts().size()>1){ builder.setSubText(accountName); } - nm.notify(accountID, GlobalUserPreferences.keepOnlyLatestNotification ? NOTIFICATION_ID : (int)System.currentTimeMillis(), builder.build()); + nm.notify(accountID, notificationID, builder.build()); } }