refactor(notifications-tab/badge): use improved implementation
Removes the now unecessary network call, by hooking into the notification reciever instead.
This commit is contained in:
parent
4ecd525f13
commit
ac5615497b
3 changed files with 8 additions and 22 deletions
|
@ -47,7 +47,7 @@ public class GlobalUserPreferences{
|
|||
public static boolean collapseLongPosts;
|
||||
public static boolean spectatorMode;
|
||||
public static boolean autoHideFab;
|
||||
public static long lastNotificationOpenedTime;
|
||||
public static boolean unreadNotifications;
|
||||
public static String publishButtonText;
|
||||
public static ThemePreference theme;
|
||||
public static ColorPreference color;
|
||||
|
@ -102,7 +102,7 @@ public class GlobalUserPreferences{
|
|||
collapseLongPosts=prefs.getBoolean("collapseLongPosts", true);
|
||||
spectatorMode=prefs.getBoolean("spectatorMode", false);
|
||||
autoHideFab=prefs.getBoolean("autoHideFab", true);
|
||||
lastNotificationOpenedTime=prefs.getLong("lastNotificationOpenedTime", 0);
|
||||
unreadNotifications=prefs.getBoolean("unreadNotifications", false);
|
||||
publishButtonText=prefs.getString("publishButtonText", "");
|
||||
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
|
||||
recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>());
|
||||
|
@ -152,7 +152,7 @@ public class GlobalUserPreferences{
|
|||
.putBoolean("collapseLongPosts", collapseLongPosts)
|
||||
.putBoolean("spectatorMode", spectatorMode)
|
||||
.putBoolean("autoHideFab", autoHideFab)
|
||||
.putLong("lastNotificationOpenedTime", lastNotificationOpenedTime)
|
||||
.putBoolean("unreadNotifications", unreadNotifications)
|
||||
.putString("publishButtonText", publishButtonText)
|
||||
.putBoolean("bottomEncoding", bottomEncoding)
|
||||
.putInt("theme", theme.ordinal())
|
||||
|
|
|
@ -76,6 +76,8 @@ 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
|
||||
|
|
|
@ -64,7 +64,6 @@ 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;
|
||||
|
||||
|
@ -131,21 +130,7 @@ 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);
|
||||
|
||||
AccountSessionManager.getInstance()
|
||||
.getAccount(accountID).getCacheController()
|
||||
.getNotifications(null, 1, false, false, true, new Callback<>() {
|
||||
@Override
|
||||
public void onSuccess(PaginatedResponse<List<Notification>> result) {
|
||||
notificationBadged = result.items.get(0).createdAt.isAfter(Instant.ofEpochMilli(GlobalUserPreferences.lastNotificationOpenedTime));
|
||||
setNotificationBadge();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(ErrorResponse error) {
|
||||
error.showToast(getContext());
|
||||
}
|
||||
});
|
||||
setNotificationBadge();
|
||||
|
||||
if(savedInstanceState==null){
|
||||
getChildFragmentManager().beginTransaction()
|
||||
|
@ -287,8 +272,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
|||
}
|
||||
|
||||
if(tab == R.id.tab_notifications){
|
||||
notificationBadged=false;
|
||||
GlobalUserPreferences.lastNotificationOpenedTime = System.currentTimeMillis();
|
||||
GlobalUserPreferences.unreadNotifications = false;
|
||||
GlobalUserPreferences.save();
|
||||
setNotificationBadge();
|
||||
}
|
||||
|
@ -367,6 +351,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
|||
}
|
||||
|
||||
private void setNotificationBadge() {
|
||||
notificationTabIcon.setImageDrawable(getContext().getDrawable(notificationBadged ? R.drawable.ic_notifications_tab_badged : R.drawable.ic_fluent_alert_28_selector));
|
||||
notificationTabIcon.setImageDrawable(getContext().getDrawable(GlobalUserPreferences.unreadNotifications ? R.drawable.ic_notifications_tab_badged : R.drawable.ic_fluent_alert_28_selector));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue