From abd6fa1c289d8375de61639a8e9d29f8bf5e156a Mon Sep 17 00:00:00 2001 From: Ammar Githam Date: Fri, 9 Apr 2021 19:13:59 +0900 Subject: [PATCH] Null check. Fixes https://github.com/austinhuang0131/barinsta/issues/1021 --- .../viewholder/directmessages/DirectItemViewHolder.java | 5 +++-- app/src/main/java/awais/instagrabber/utils/DMUtils.java | 9 ++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java index 96476b10..17a0956c 100644 --- a/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java +++ b/app/src/main/java/awais/instagrabber/adapters/viewholder/directmessages/DirectItemViewHolder.java @@ -112,6 +112,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple } public void bind(final int position, final DirectItem item) { + if (item == null) return; this.item = item; messageDirection = isSelf(item) ? MessageDirection.OUTGOING : MessageDirection.INCOMING; // Asynchronous binding causes some weird behaviour @@ -123,7 +124,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple setupLongClickListener(position, messageDirection); } - private void bindBase(final DirectItem item, final MessageDirection messageDirection, final int position) { + private void bindBase(@NonNull final DirectItem item, final MessageDirection messageDirection, final int position) { final FrameLayout.LayoutParams containerLayoutParams = (FrameLayout.LayoutParams) binding.container.getLayoutParams(); final DirectItemType itemType = item.getItemType(); setMessageDirectionGravity(messageDirection, containerLayoutParams); @@ -188,7 +189,7 @@ public abstract class DirectItemViewHolder extends RecyclerView.ViewHolder imple containerLayoutParams.gravity = Gravity.CENTER; } - private void setMessageInfo(final DirectItem item, final MessageDirection messageDirection) { + private void setMessageInfo(@NonNull final DirectItem item, final MessageDirection messageDirection) { if (showMessageInfo()) { binding.messageInfo.setVisibility(View.VISIBLE); binding.deliveryStatus.setVisibility(messageDirection == MessageDirection.OUTGOING ? View.VISIBLE : View.GONE); diff --git a/app/src/main/java/awais/instagrabber/utils/DMUtils.java b/app/src/main/java/awais/instagrabber/utils/DMUtils.java index 12aa2e07..904a7055 100644 --- a/app/src/main/java/awais/instagrabber/utils/DMUtils.java +++ b/app/src/main/java/awais/instagrabber/utils/DMUtils.java @@ -23,18 +23,21 @@ import awais.instagrabber.repositories.responses.directmessages.DirectThreadLast import awais.instagrabber.repositories.responses.directmessages.RavenExpiringMediaActionSummary; public final class DMUtils { - public static boolean isRead(final DirectItem item, + public static boolean isRead(@NonNull final DirectItem item, @NonNull final Map lastSeenAt, - final List userIdsToCheck) { + @NonNull final List userIdsToCheck) { // Further check if directStory exists // if (read && directStory != null) { // read = false; // } + if (item == null) return false; return lastSeenAt.entrySet() .stream() .filter(entry -> userIdsToCheck.contains(entry.getKey())) .anyMatch(entry -> { - final String userLastSeenTsString = entry.getValue().getTimestamp(); + final DirectThreadLastSeenAt threadLastSeenAt = entry.getValue(); + if (threadLastSeenAt == null) return false; + final String userLastSeenTsString = threadLastSeenAt.getTimestamp(); if (userLastSeenTsString == null) return false; final long userTs = Long.parseLong(userLastSeenTsString); final long itemTs = item.getTimestamp();