Minor code consistency change

This commit is contained in:
Naveen 2022-11-18 01:45:17 +05:30
parent 9fbf6fa581
commit 89f378b973
3 changed files with 16 additions and 14 deletions

View File

@ -257,7 +257,7 @@ class MainActivity : SimpleActivity() {
} }
cachedConversations.forEach { cachedConv -> cachedConversations.forEach { cachedConv ->
val conv = conversations.find { it.threadId == cachedConv.threadId && !cachedConv.areContentsTheSame(it) } val conv = conversations.find { it.threadId == cachedConv.threadId && !Conversation.areContentsTheSame(cachedConv, it) }
if (conv != null) { if (conv != null) {
val conversation = conv.copy(date = maxOf(cachedConv.date, conv.date)) val conversation = conv.copy(date = maxOf(cachedConv.date, conv.date))
conversationsDB.insertOrUpdate(conversation) conversationsDB.insertOrUpdate(conversation)

View File

@ -374,11 +374,11 @@ class ConversationsAdapter(
private class ConversationDiffCallback : DiffUtil.ItemCallback<Conversation>() { private class ConversationDiffCallback : DiffUtil.ItemCallback<Conversation>() {
override fun areItemsTheSame(oldItem: Conversation, newItem: Conversation): Boolean { override fun areItemsTheSame(oldItem: Conversation, newItem: Conversation): Boolean {
return oldItem.areItemsTheSame(newItem) return Conversation.areItemsTheSame(oldItem, newItem)
} }
override fun areContentsTheSame(oldItem: Conversation, newItem: Conversation): Boolean { override fun areContentsTheSame(oldItem: Conversation, newItem: Conversation): Boolean {
return oldItem.areContentsTheSame(newItem) return Conversation.areContentsTheSame(oldItem, newItem)
} }
} }
} }

View File

@ -18,17 +18,19 @@ data class Conversation(
@ColumnInfo(name = "is_scheduled") var isScheduled: Boolean = false @ColumnInfo(name = "is_scheduled") var isScheduled: Boolean = false
) { ) {
fun areItemsTheSame(other: Conversation): Boolean { companion object {
return threadId == other.threadId fun areItemsTheSame(old: Conversation, new: Conversation): Boolean {
return old.threadId == new.threadId
} }
fun areContentsTheSame(other: Conversation): Boolean { fun areContentsTheSame(old: Conversation, new: Conversation): Boolean {
return snippet == other.snippet && return old.snippet == new.snippet &&
date == other.date && old.date == new.date &&
read == other.read && old.read == new.read &&
title == other.title && old.title == new.title &&
photoUri == other.photoUri && old.photoUri == new.photoUri &&
isGroupConversation == other.isGroupConversation && old.isGroupConversation == new.isGroupConversation &&
phoneNumber == other.phoneNumber old.phoneNumber == new.phoneNumber
}
} }
} }