Fixed a couple of bugs where the HomeDiffUtil could incorrectly detect differences

pull/1069/head
Morgan Pretty 2 years ago
parent d68d26cd5d
commit c0bef51fe0

@ -50,7 +50,6 @@ public class ThreadRecord extends DisplayRecord {
private final long expiresIn; private final long expiresIn;
private final long lastSeen; private final long lastSeen;
private final boolean pinned; private final boolean pinned;
private final int recipientHash;
public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri, public ThreadRecord(@NonNull String body, @Nullable Uri snippetUri,
@NonNull Recipient recipient, long date, long count, int unreadCount, @NonNull Recipient recipient, long date, long count, int unreadCount,
@ -67,17 +66,12 @@ public class ThreadRecord extends DisplayRecord {
this.expiresIn = expiresIn; this.expiresIn = expiresIn;
this.lastSeen = lastSeen; this.lastSeen = lastSeen;
this.pinned = pinned; this.pinned = pinned;
this.recipientHash = recipient.hashCode();
} }
public @Nullable Uri getSnippetUri() { public @Nullable Uri getSnippetUri() {
return snippetUri; return snippetUri;
} }
public int getRecipientHash() {
return recipientHash;
}
@Override @Override
public SpannableString getDisplayBody(@NonNull Context context) { public SpannableString getDisplayBody(@NonNull Context context) {
if (isGroupUpdateMessage()) { if (isGroupUpdateMessage()) {

@ -22,22 +22,28 @@ class HomeDiffUtil(
val newItem = new[newItemPosition] val newItem = new[newItemPosition]
// return early to save getDisplayBody or expensive calls // return early to save getDisplayBody or expensive calls
val sameCount = oldItem.count == newItem.count var isSameItem = true
if (!sameCount) return false
val sameUnreads = oldItem.unreadCount == newItem.unreadCount if (isSameItem) { isSameItem = (oldItem.count == newItem.count) }
if (!sameUnreads) return false if (isSameItem) { isSameItem = (oldItem.unreadCount == newItem.unreadCount) }
val samePinned = oldItem.isPinned == newItem.isPinned if (isSameItem) { isSameItem = (oldItem.isPinned == newItem.isPinned) }
if (!samePinned) return false
val sameRecipientHash = oldItem.recipientHash == newItem.recipientHash // Note: For some reason the 'hashCode' value can change after initialisation so we can't cache it
if (!sameRecipientHash) return false if (isSameItem) { isSameItem = (oldItem.recipient.hashCode() == newItem.recipient.hashCode()) }
val sameSnippet = oldItem.getDisplayBody(context) == newItem.getDisplayBody(context)
if (!sameSnippet) return false // Note: Two instances of 'SpannableString' may not equate even though their content matches
val sameSendStatus = oldItem.isFailed == newItem.isFailed && oldItem.isDelivered == newItem.isDelivered if (isSameItem) { isSameItem = (oldItem.getDisplayBody(context).toString() == newItem.getDisplayBody(context).toString()) }
&& oldItem.isSent == newItem.isSent && oldItem.isPending == newItem.isPending
if (!sameSendStatus) return false if (isSameItem) {
isSameItem = (
// all same oldItem.isFailed == newItem.isFailed &&
return true oldItem.isDelivered == newItem.isDelivered &&
oldItem.isSent == newItem.isSent &&
oldItem.isPending == newItem.isPending
)
}
return isSameItem
} }
} }
Loading…
Cancel
Save