From 74e630aacbae06208ec53c54da3dabf2a34b8ffd Mon Sep 17 00:00:00 2001 From: Greyson Parrelli Date: Wed, 23 Mar 2022 11:44:37 -0400 Subject: [PATCH] Fix possible crash and remove old fastRecord system. --- .../conversation/ConversationAdapter.java | 63 +++---------------- 1 file changed, 7 insertions(+), 56 deletions(-) diff --git a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java index 996d0f251..a6ff93798 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java +++ b/app/src/main/java/org/thoughtcrime/securesms/conversation/ConversationAdapter.java @@ -113,8 +113,6 @@ public class ConversationAdapter private final Recipient recipient; private final Set selected; - private final List fastRecords; - private final Set releasedFastRecords; private final Calendar calendar; private final MessageDigest digest; @@ -157,8 +155,6 @@ public class ConversationAdapter this.clickListener = clickListener; this.recipient = recipient; this.selected = new HashSet<>(); - this.fastRecords = new ArrayList<>(); - this.releasedFastRecords = new HashSet<>(); this.calendar = Calendar.getInstance(); this.digest = getMessageDigestOrThrow(); this.hasWallpaper = recipient.hasWallpaper(); @@ -308,7 +304,7 @@ public class ConversationAdapter @Override public int getItemCount() { boolean hasFooter = footerView != null; - return super.getItemCount() + fastRecords.size() + (isTypingViewEnabled ? 1 : 0) + (hasFooter ? 1 : 0); + return super.getItemCount() + (isTypingViewEnabled ? 1 : 0) + (hasFooter ? 1 : 0); } @Override @@ -369,30 +365,22 @@ public class ConversationAdapter public @Nullable ConversationMessage getItem(int position) { position = isTypingViewEnabled() ? position - 1 : position; - if (position == -1) { + if (position < 0) { return null; - } else if (position < fastRecords.size()) { - return fastRecords.get(position); } else { - int correctedPosition = position - fastRecords.size(); if (pagingController != null) { - pagingController.onDataNeededAroundIndex(correctedPosition); + pagingController.onDataNeededAroundIndex(position); } - if (correctedPosition < getItemCount()) { - return super.getItem(correctedPosition); + if (position < getItemCount()) { + return super.getItem(position); } else { - Log.d(TAG, "Could not access corrected position " + correctedPosition + " as it is out of bounds."); + Log.d(TAG, "Could not access corrected position " + position + " as it is out of bounds."); return null; } } } - public void submitList(@Nullable List pagedList) { - cleanFastRecords(); - super.submitList(pagedList); - } - public void setPagingController(@Nullable PagingController pagingController) { this.pagingController = pagingController; } @@ -416,7 +404,7 @@ public class ConversationAdapter } boolean hasNoConversationMessages() { - return super.getItemCount() + fastRecords.size() == 0; + return super.getItemCount() == 0; } /** @@ -525,27 +513,6 @@ public class ConversationAdapter } } - /** - * Adds a record to a memory cache to allow it to be rendered immediately, as opposed to waiting - * for a database change. - */ - @MainThread - void addFastRecord(ConversationMessage conversationMessage) { - fastRecords.add(0, conversationMessage); - notifyDataSetChanged(); - } - - /** - * Marks a record as no-longer-needed. Will be removed from the adapter the next time the database - * changes. - */ - @AnyThread - void releaseFastRecord(long id) { - synchronized (releasedFastRecords) { - releasedFastRecords.add(id); - } - } - /** * Returns set of records that are selected in multi-select mode. */ @@ -590,22 +557,6 @@ public class ConversationAdapter pool.setMaxRecycledViews(MESSAGE_TYPE_UPDATE, 5); } - @MainThread - private void cleanFastRecords() { - ThreadUtil.assertMainThread(); - - synchronized (releasedFastRecords) { - Iterator messageIterator = fastRecords.iterator(); - while (messageIterator.hasNext()) { - long id = messageIterator.next().getMessageRecord().getId(); - if (releasedFastRecords.contains(id)) { - messageIterator.remove(); - releasedFastRecords.remove(id); - } - } - } - } - public boolean isTypingViewEnabled() { return isTypingViewEnabled; }