Fix possible crash and remove old fastRecord system.

fork-5.53.8
Greyson Parrelli 2022-03-23 11:44:37 -04:00
rodzic 65a12767f9
commit 74e630aacb
1 zmienionych plików z 7 dodań i 56 usunięć

Wyświetl plik

@ -113,8 +113,6 @@ public class ConversationAdapter
private final Recipient recipient;
private final Set<MultiselectPart> selected;
private final List<ConversationMessage> fastRecords;
private final Set<Long> 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<ConversationMessage> 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<ConversationMessage> 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;
}