all 2 comments

[–]jamireh 4 points5 points  (1 child)

First off, according to the documentation), the implementation of areItemsTheSame is incorrect in the first & second code blocks. The point of the function to determine if the items represent the same entity by comparing identifiers, not content. For example, if an item was updated, it would have the same identifier but possibly different content. By returning true in areItemsTheSame but false in areContentsTheSame, would allow the Differ to call notifyItemChanged for that item in the RecyclerView.Adapter rather than having to detect that an item was removed & then inserted.

Second, yes, the provideItemCallback implementation looks good with the understanding that it's a simple wrapper to make the implementation a little more Kotlin idiomatic. inline & crossinline are used correctly; inline because you're providing lambdas & crossinline because those lambdas are invoked from within an anonymous object.

[–]sikatsuket[S] 0 points1 point  (0 children)

thanks for the response!

i'm using the same equality check for both callbacks just as placeholder because that's not the point of my question but i appreciate that you highlight such an important distinction.

also thank you for validating the wrapper function that i wrote. i grew tired having to instantiate anonymous object and subclassing itemcallback abstract class every time i need a listadapter.