diff --git a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java index 74b037be8..a6e98f970 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java +++ b/mastodon/src/main/java/org/joinmastodon/android/GlobalUserPreferences.java @@ -47,7 +47,6 @@ public class GlobalUserPreferences{ public static boolean collapseLongPosts; public static boolean spectatorMode; public static boolean autoHideFab; - public static boolean unreadNotifications; public static boolean defaultToUnlistedReplies; public static boolean disableDoubleTapToSwipe; public static String publishButtonText; @@ -104,7 +103,6 @@ public class GlobalUserPreferences{ collapseLongPosts=prefs.getBoolean("collapseLongPosts", true); spectatorMode=prefs.getBoolean("spectatorMode", false); autoHideFab=prefs.getBoolean("autoHideFab", true); - unreadNotifications=prefs.getBoolean("unreadNotifications", false); defaultToUnlistedReplies=prefs.getBoolean("defaultToUnlistedReplies", false); disableDoubleTapToSwipe=prefs.getBoolean("disableDoubleTapToSwipe", false); publishButtonText=prefs.getString("publishButtonText", ""); @@ -156,7 +154,6 @@ public class GlobalUserPreferences{ .putBoolean("collapseLongPosts", collapseLongPosts) .putBoolean("spectatorMode", spectatorMode) .putBoolean("autoHideFab", autoHideFab) - .putBoolean("unreadNotifications", unreadNotifications) .putString("publishButtonText", publishButtonText) .putBoolean("bottomEncoding", bottomEncoding) .putBoolean("defaultToUnlistedReplies", defaultToUnlistedReplies) diff --git a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java index 1c81cdca6..575431370 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java +++ b/mastodon/src/main/java/org/joinmastodon/android/PushNotificationReceiver.java @@ -89,8 +89,6 @@ public class PushNotificationReceiver extends BroadcastReceiver{ @Override public void onSuccess(org.joinmastodon.android.model.Notification result){ MastodonAPIController.runInBackground(()->PushNotificationReceiver.this.notify(context, pn, accountID, result)); - GlobalUserPreferences.unreadNotifications = true; - GlobalUserPreferences.save(); } @Override diff --git a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java index f10aa1c0c..0e2280d23 100644 --- a/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java +++ b/mastodon/src/main/java/org/joinmastodon/android/fragments/HomeFragment.java @@ -58,6 +58,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene private View tabBarWrap; private ImageView tabBarAvatar; private ImageView notificationTabIcon; + private boolean notificationBadged = false; @IdRes private int currentTab=R.id.tab_home; @@ -124,7 +125,21 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene ViewImageLoader.load(tabBarAvatar, null, new UrlImageLoaderRequest(self.avatar, V.dp(28), V.dp(28))); notificationTabIcon=content.findViewById(R.id.tab_notifications); - setNotificationBadge(); + + AccountSessionManager.getInstance() + .getAccount(accountID).getCacheController() + .getNotifications(null, 1, false, false, true, new Callback<>() { + @Override + public void onSuccess(PaginatedResponse> result) { + notificationBadged = result.items.get(0).createdAt.isAfter(Instant.ofEpochMilli(GlobalUserPreferences.lastNotificationOpenedTime)); + setNotificationBadge(); + } + + @Override + public void onError(ErrorResponse error) { + error.showToast(getContext()); + } + }); if(savedInstanceState==null){ getChildFragmentManager().beginTransaction() @@ -268,7 +283,8 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene } if(tab == R.id.tab_notifications){ - GlobalUserPreferences.unreadNotifications = false; + notificationBadged=false; + GlobalUserPreferences.lastNotificationOpenedTime = System.currentTimeMillis(); GlobalUserPreferences.save(); setNotificationBadge(); } @@ -354,6 +370,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene } private void setNotificationBadge() { - notificationTabIcon.setImageDrawable(getContext().getDrawable(GlobalUserPreferences.unreadNotifications ? R.drawable.ic_notifications_tab_badged : R.drawable.ic_fluent_alert_28_selector)); + notificationTabIcon.setImageDrawable(getContext().getDrawable(notificationBadged ? R.drawable.ic_notifications_tab_badged : R.drawable.ic_fluent_alert_28_selector)); } }