From 00945d79e7be7980019dd03e519377122c1b3873 Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Tue, 13 Jul 2021 20:56:51 +0900 Subject: [PATCH] Make Notification pk nullable. Fixes austinhuang0131/barinsta#1450 --- .../instagrabber/adapters/NotificationsAdapter.java | 9 +++++---- .../repositories/responses/notification/Notification.kt | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java index 55fd2b19..22d11000 100644 --- a/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java +++ b/app/src/main/java/awais/instagrabber/adapters/NotificationsAdapter.java @@ -11,6 +11,7 @@ import androidx.recyclerview.widget.ListAdapter; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import awais.instagrabber.adapters.viewholder.NotificationViewHolder; @@ -24,12 +25,12 @@ public final class NotificationsAdapter extends ListAdapter DIFF_CALLBACK = new DiffUtil.ItemCallback() { @Override public boolean areItemsTheSame(final Notification oldItem, final Notification newItem) { - return oldItem.getPk().equals(newItem.getPk()); + return Objects.requireNonNull(oldItem.getPk()).equals(newItem.getPk()); } @Override public boolean areContentsTheSame(@NonNull final Notification oldItem, @NonNull final Notification newItem) { - return oldItem.getPk().equals(newItem.getPk()) && oldItem.getType() == newItem.getType(); + return Objects.requireNonNull(oldItem.getPk()).equals(newItem.getPk()) && Objects.equals(oldItem.getType(), newItem.getType()); } }; @@ -72,8 +73,8 @@ public final class NotificationsAdapter extends ListAdapter sort(final List list) { final List listCopy = new ArrayList<>(list).stream() - .filter(i -> i.getType() != null) - .collect(Collectors.toList()); + .filter(i -> i.getType() != null) + .collect(Collectors.toList()); Collections.sort(listCopy, (o1, o2) -> { // keep requests at top if (o1.getType() == o2.getType() diff --git a/app/src/main/java/awais/instagrabber/repositories/responses/notification/Notification.kt b/app/src/main/java/awais/instagrabber/repositories/responses/notification/Notification.kt index 0cd35777..f6ad44e2 100644 --- a/app/src/main/java/awais/instagrabber/repositories/responses/notification/Notification.kt +++ b/app/src/main/java/awais/instagrabber/repositories/responses/notification/Notification.kt @@ -5,7 +5,7 @@ import awais.instagrabber.models.enums.NotificationType.Companion.valueOfType class Notification(val args: NotificationArgs, private val storyType: Int, - val pk: String) { + val pk: String?) { val type: NotificationType? get() = valueOfType(storyType) } \ No newline at end of file