fix crash in notifications fragment, save account only when notificationid changed

This commit is contained in:
Conny Duck 2018-09-03 21:23:12 +02:00
parent 5131c44e93
commit f72e08cae4
1 changed files with 14 additions and 10 deletions

View File

@ -691,19 +691,23 @@ public class NotificationsFragment extends SFragment implements
private void saveNewestNotificationId(List<Notification> notifications) {
AccountEntity account = accountManager.getActiveAccount();
BigInteger lastNoti = new BigInteger(account.getLastNotificationId());
if(account != null) {
BigInteger lastNoti = new BigInteger(account.getLastNotificationId());
for (Notification noti : notifications) {
BigInteger a = new BigInteger(noti.getId());
if (isBiggerThan(a, lastNoti)) {
lastNoti = a;
for (Notification noti : notifications) {
BigInteger a = new BigInteger(noti.getId());
if (isBiggerThan(a, lastNoti)) {
lastNoti = a;
}
}
String lastNotificationId = lastNoti.toString();
if(!account.getLastNotificationId().equals(lastNotificationId)) {
Log.d(TAG, "saving newest noti id: " + lastNotificationId);
account.setLastNotificationId(lastNotificationId);
accountManager.saveAccount(account);
}
}
Log.d(TAG, "saving newest noti id: " + lastNoti);
account.setLastNotificationId(lastNoti.toString());
accountManager.saveAccount(account);
}
private boolean isBiggerThan(BigInteger newId, BigInteger lastShownNotificationId) {