Fixes issue #207 - Bug with counters

This commit is contained in:
stom79 2017-12-28 11:25:12 +01:00
parent 3884e7c568
commit cdf8eb64d9
1 changed files with 10 additions and 5 deletions

View File

@ -211,7 +211,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
if( firstLoad) { if( firstLoad) {
//Update the id of the last notification retrieved //Update the id of the last notification retrieved
MainActivity.lastNotificationId = notifications.get(0).getId(); MainActivity.lastNotificationId = notifications.get(0).getId();
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId()); if (notifications.size() > 0)
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId());
} }
notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size()); notificationsListAdapter.notifyItemRangeInserted(previousPosition, notifications.size());
} }
@ -249,8 +250,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
//Store last toot id for home timeline to avoid to notify for those that have been already seen //Store last toot id for home timeline to avoid to notify for those that have been already seen
//Store last notification id to avoid to notify for those that have been already seen //Store last notification id to avoid to notify for those that have been already seen
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE); SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
if (notifications != null && notifications.size() > 0) { if (this.notifications != null && this.notifications.size() > 0) {
updateNotificationLastId(sharedpreferences, this.userId, notifications.get(0).getId()); updateNotificationLastId(sharedpreferences, this.userId, this.notifications.get(0).getId());
} }
} }
@ -307,6 +308,8 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
} }
} }
/** /**
* Records the id of the notification only if its greater than the previous one. * Records the id of the notification only if its greater than the previous one.
* @param sharedPreferences SharedPreferences * @param sharedPreferences SharedPreferences
@ -314,12 +317,14 @@ public class DisplayNotificationsFragment extends Fragment implements OnRetrieve
* @param notificationId String current notification id to check * @param notificationId String current notification id to check
*/ */
private void updateNotificationLastId(SharedPreferences sharedPreferences, String userId, String notificationId){ private void updateNotificationLastId(SharedPreferences sharedPreferences, String userId, String notificationId){
String lastNotif = sharedPreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null); String lastNotif = sharedPreferences.getString(Helper.LAST_NOTIFICATION_MAX_ID + userId, null);
if( lastNotif != null && notificationId != null && Long.parseLong(notificationId) > Long.parseLong(lastNotif)){ if( lastNotif == null || Long.parseLong(notificationId) > Long.parseLong(lastNotif)){
this.lastReadNotifications = notificationId;
SharedPreferences.Editor editor = sharedPreferences.edit(); SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId); editor.putString(Helper.LAST_NOTIFICATION_MAX_ID + userId, notificationId);
editor.apply(); editor.apply();
} }
lastReadNotifications = notificationId;
} }
} }