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 collapseLongPosts;
|
||||||
public static boolean spectatorMode;
|
public static boolean spectatorMode;
|
||||||
public static boolean autoHideFab;
|
public static boolean autoHideFab;
|
||||||
public static long lastNotificationOpenedTime;
|
public static boolean unreadNotifications;
|
||||||
public static String publishButtonText;
|
public static String publishButtonText;
|
||||||
public static ThemePreference theme;
|
public static ThemePreference theme;
|
||||||
public static ColorPreference color;
|
public static ColorPreference color;
|
||||||
|
@ -102,7 +102,7 @@ public class GlobalUserPreferences{
|
||||||
collapseLongPosts=prefs.getBoolean("collapseLongPosts", true);
|
collapseLongPosts=prefs.getBoolean("collapseLongPosts", true);
|
||||||
spectatorMode=prefs.getBoolean("spectatorMode", false);
|
spectatorMode=prefs.getBoolean("spectatorMode", false);
|
||||||
autoHideFab=prefs.getBoolean("autoHideFab", true);
|
autoHideFab=prefs.getBoolean("autoHideFab", true);
|
||||||
lastNotificationOpenedTime=prefs.getLong("lastNotificationOpenedTime", 0);
|
unreadNotifications=prefs.getBoolean("unreadNotifications", false);
|
||||||
publishButtonText=prefs.getString("publishButtonText", "");
|
publishButtonText=prefs.getString("publishButtonText", "");
|
||||||
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
|
theme=ThemePreference.values()[prefs.getInt("theme", 0)];
|
||||||
recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>());
|
recentLanguages=fromJson(prefs.getString("recentLanguages", "{}"), recentLanguagesType, new HashMap<>());
|
||||||
|
@ -152,7 +152,7 @@ public class GlobalUserPreferences{
|
||||||
.putBoolean("collapseLongPosts", collapseLongPosts)
|
.putBoolean("collapseLongPosts", collapseLongPosts)
|
||||||
.putBoolean("spectatorMode", spectatorMode)
|
.putBoolean("spectatorMode", spectatorMode)
|
||||||
.putBoolean("autoHideFab", autoHideFab)
|
.putBoolean("autoHideFab", autoHideFab)
|
||||||
.putLong("lastNotificationOpenedTime", lastNotificationOpenedTime)
|
.putBoolean("unreadNotifications", unreadNotifications)
|
||||||
.putString("publishButtonText", publishButtonText)
|
.putString("publishButtonText", publishButtonText)
|
||||||
.putBoolean("bottomEncoding", bottomEncoding)
|
.putBoolean("bottomEncoding", bottomEncoding)
|
||||||
.putInt("theme", theme.ordinal())
|
.putInt("theme", theme.ordinal())
|
||||||
|
|
|
@ -76,6 +76,8 @@ public class PushNotificationReceiver extends BroadcastReceiver{
|
||||||
@Override
|
@Override
|
||||||
public void onSuccess(org.joinmastodon.android.model.Notification result){
|
public void onSuccess(org.joinmastodon.android.model.Notification result){
|
||||||
MastodonAPIController.runInBackground(()->PushNotificationReceiver.this.notify(context, pn, accountID, result));
|
MastodonAPIController.runInBackground(()->PushNotificationReceiver.this.notify(context, pn, accountID, result));
|
||||||
|
GlobalUserPreferences.unreadNotifications = true;
|
||||||
|
GlobalUserPreferences.save();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -64,7 +64,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
||||||
private View tabBarWrap;
|
private View tabBarWrap;
|
||||||
private ImageView tabBarAvatar;
|
private ImageView tabBarAvatar;
|
||||||
private ImageView notificationTabIcon;
|
private ImageView notificationTabIcon;
|
||||||
private boolean notificationBadged = false;
|
|
||||||
@IdRes
|
@IdRes
|
||||||
private int currentTab=R.id.tab_home;
|
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)));
|
ViewImageLoader.load(tabBarAvatar, null, new UrlImageLoaderRequest(self.avatar, V.dp(28), V.dp(28)));
|
||||||
|
|
||||||
notificationTabIcon=content.findViewById(R.id.tab_notifications);
|
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();
|
setNotificationBadge();
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onError(ErrorResponse error) {
|
|
||||||
error.showToast(getContext());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
if(savedInstanceState==null){
|
if(savedInstanceState==null){
|
||||||
getChildFragmentManager().beginTransaction()
|
getChildFragmentManager().beginTransaction()
|
||||||
|
@ -287,8 +272,7 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
||||||
}
|
}
|
||||||
|
|
||||||
if(tab == R.id.tab_notifications){
|
if(tab == R.id.tab_notifications){
|
||||||
notificationBadged=false;
|
GlobalUserPreferences.unreadNotifications = false;
|
||||||
GlobalUserPreferences.lastNotificationOpenedTime = System.currentTimeMillis();
|
|
||||||
GlobalUserPreferences.save();
|
GlobalUserPreferences.save();
|
||||||
setNotificationBadge();
|
setNotificationBadge();
|
||||||
}
|
}
|
||||||
|
@ -367,6 +351,6 @@ public class HomeFragment extends AppKitFragment implements OnBackPressedListene
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNotificationBadge() {
|
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