kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix possible crash and remove old fastRecord system.
rodzic
65a12767f9
commit
74e630aacb
|
@ -113,8 +113,6 @@ public class ConversationAdapter
|
||||||
private final Recipient recipient;
|
private final Recipient recipient;
|
||||||
|
|
||||||
private final Set<MultiselectPart> selected;
|
private final Set<MultiselectPart> selected;
|
||||||
private final List<ConversationMessage> fastRecords;
|
|
||||||
private final Set<Long> releasedFastRecords;
|
|
||||||
private final Calendar calendar;
|
private final Calendar calendar;
|
||||||
private final MessageDigest digest;
|
private final MessageDigest digest;
|
||||||
|
|
||||||
|
@ -157,8 +155,6 @@ public class ConversationAdapter
|
||||||
this.clickListener = clickListener;
|
this.clickListener = clickListener;
|
||||||
this.recipient = recipient;
|
this.recipient = recipient;
|
||||||
this.selected = new HashSet<>();
|
this.selected = new HashSet<>();
|
||||||
this.fastRecords = new ArrayList<>();
|
|
||||||
this.releasedFastRecords = new HashSet<>();
|
|
||||||
this.calendar = Calendar.getInstance();
|
this.calendar = Calendar.getInstance();
|
||||||
this.digest = getMessageDigestOrThrow();
|
this.digest = getMessageDigestOrThrow();
|
||||||
this.hasWallpaper = recipient.hasWallpaper();
|
this.hasWallpaper = recipient.hasWallpaper();
|
||||||
|
@ -308,7 +304,7 @@ public class ConversationAdapter
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
boolean hasFooter = footerView != null;
|
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
|
@Override
|
||||||
|
@ -369,30 +365,22 @@ public class ConversationAdapter
|
||||||
public @Nullable ConversationMessage getItem(int position) {
|
public @Nullable ConversationMessage getItem(int position) {
|
||||||
position = isTypingViewEnabled() ? position - 1 : position;
|
position = isTypingViewEnabled() ? position - 1 : position;
|
||||||
|
|
||||||
if (position == -1) {
|
if (position < 0) {
|
||||||
return null;
|
return null;
|
||||||
} else if (position < fastRecords.size()) {
|
|
||||||
return fastRecords.get(position);
|
|
||||||
} else {
|
} else {
|
||||||
int correctedPosition = position - fastRecords.size();
|
|
||||||
if (pagingController != null) {
|
if (pagingController != null) {
|
||||||
pagingController.onDataNeededAroundIndex(correctedPosition);
|
pagingController.onDataNeededAroundIndex(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (correctedPosition < getItemCount()) {
|
if (position < getItemCount()) {
|
||||||
return super.getItem(correctedPosition);
|
return super.getItem(position);
|
||||||
} else {
|
} 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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void submitList(@Nullable List<ConversationMessage> pagedList) {
|
|
||||||
cleanFastRecords();
|
|
||||||
super.submitList(pagedList);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPagingController(@Nullable PagingController pagingController) {
|
public void setPagingController(@Nullable PagingController pagingController) {
|
||||||
this.pagingController = pagingController;
|
this.pagingController = pagingController;
|
||||||
}
|
}
|
||||||
|
@ -416,7 +404,7 @@ public class ConversationAdapter
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean hasNoConversationMessages() {
|
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.
|
* Returns set of records that are selected in multi-select mode.
|
||||||
*/
|
*/
|
||||||
|
@ -590,22 +557,6 @@ public class ConversationAdapter
|
||||||
pool.setMaxRecycledViews(MESSAGE_TYPE_UPDATE, 5);
|
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() {
|
public boolean isTypingViewEnabled() {
|
||||||
return isTypingViewEnabled;
|
return isTypingViewEnabled;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue