From f61456d8b37f8b28b115fab28de680f1c5baf908 Mon Sep 17 00:00:00 2001 From: Conny Duck Date: Mon, 3 Sep 2018 21:23:12 +0200 Subject: [PATCH] fix crash in notifications fragment, save account only when notificationid changed --- .../tusky/fragment/NotificationsFragment.java | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java index bf0749bf..726a084b 100644 --- a/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java +++ b/app/src/main/java/com/keylesspalace/tusky/fragment/NotificationsFragment.java @@ -691,19 +691,23 @@ public class NotificationsFragment extends SFragment implements private void saveNewestNotificationId(List 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; + } } - } - - Log.d(TAG, "saving newest noti id: " + lastNoti); - account.setLastNotificationId(lastNoti.toString()); - accountManager.saveAccount(account); + String lastNotificationId = lastNoti.toString(); + if(!account.getLastNotificationId().equals(lastNotificationId)) { + Log.d(TAG, "saving newest noti id: " + lastNotificationId); + account.setLastNotificationId(lastNotificationId); + accountManager.saveAccount(account); + } + } } private boolean isBiggerThan(BigInteger newId, BigInteger lastShownNotificationId) {