I am using AsyncListDiffer in my project, in which i have lots of quotes in main page
Below is the code i've written in my recyclerview adapter
private val diffCallback = object : DiffUtil.ItemCallback<Quote>() {
override fun areItemsTheSame(oldItem: Quote, newItem: Quote): Boolean {
return oldItem.id == newItem.id
}
override fun areContentsTheSame(oldItem: Quote, newItem: Quote): Boolean {
Log.d("mytag", "$oldItem , $newItem")
return oldItem == newItem
}
}
When i change something in quote object, i then submit it to the ListDiffer. And as you can see i am logging newItem and oldItem inside areContentsTheSame
function. Here both oldItem
and newItem
are the same objects( i mean their contents are the one i updated recently), which i think oldItem should give me old non-updated item, but it doesn't
(I already tried to make copy of the list and then submit it to differ, it doesn't work)
fun updateQuote(quoteId :String,newQuote: Map<String,String>) = viewModelScope.launch(Dispatchers.IO) {
_updateQuote.postValue(DataState.Loading())
val response = mainRepository.updateQuote(quoteId, newQuote)
val handledResponse = handleQuoteResponse(response)
val quoteToUpdate = quoteList.find { quote -> quote.id == quoteId}
quoteToUpdate?.genre = newQuote["genre"]
quoteToUpdate?.quote = newQuote["quote"]
_quotes.postValue(DataState.Success(QuotesResponse(quoteList.map { it.copy() })))
_updateQuote.postValue(handledResponse)
}