From c4dbe80a0574dc6f08886ba4ab7bc79a9a37c0e7 Mon Sep 17 00:00:00 2001 From: Thomas Date: Fri, 30 Sep 2022 16:57:49 +0200 Subject: [PATCH] Some fixes with cache and notifications --- .../android/client/entities/api/Notification.java | 11 +++++++++++ .../timeline/FragmentMastodonNotification.java | 6 ++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java b/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java index daa3ade37..e17c1cfd4 100644 --- a/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java +++ b/app/src/main/java/app/fedilab/android/client/entities/api/Notification.java @@ -14,6 +14,8 @@ package app.fedilab.android.client.entities.api; * You should have received a copy of the GNU General Public License along with Fedilab; if not, * see . */ +import androidx.annotation.Nullable; + import com.google.gson.Gson; import com.google.gson.annotations.SerializedName; import com.google.gson.reflect.TypeToken; @@ -45,6 +47,15 @@ public class Notification { BOTTOM } + @Override + public boolean equals(@Nullable Object obj) { + boolean same = false; + if (obj instanceof Notification) { + same = this.id.equals(((Notification) obj).id); + } + return same; + } + public transient List relatedNotifications; public boolean isFetchMore; public boolean isFetchMoreHidden = false; diff --git a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java index 562c3a08d..33690c2cd 100644 --- a/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java +++ b/app/src/main/java/app/fedilab/android/ui/fragment/timeline/FragmentMastodonNotification.java @@ -508,8 +508,10 @@ public class FragmentMastodonNotification extends Fragment implements Notificati //We compare the date of each status and we only add status having a date greater than the another, it is inserted at this position //Pinned messages are ignored because their date can be older if (notificationReceived.id.compareTo(notificationsAlreadyPresent.id) > 0) { - notificationList.add(position, notificationReceived); - notificationAdapter.notifyItemInserted(position); + if (!notificationList.contains(notificationReceived)) { + notificationList.add(position, notificationReceived); + notificationAdapter.notifyItemInserted(position); + } break; } position++;