|
|
@ -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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|