How to avoid duplicate items in PagingAdapter?

38
September 23, 2021, at 2:40 PM

I have implemented paging3 for my android project. To avoid duplicated items, I created a DiffUtil.ItemCallback object as follow;

companion object {
    val diffCallback = object : DiffUtil.ItemCallback<Person>() {
        override fun areItemsTheSame(oldItem: Person, newItem: Person): Boolean {
            return oldItem.id == newItem.id
        }
        override fun areContentsTheSame(oldItem: Person, newItem: Person): Boolean {
            return oldItem.id == newItem.id
        }
    }
}

And I used that object in PagingDataAdapter;

class PersonAdapter : PagingDataAdapter<Person, PersonViewHolder>(diffCallback) 

In View, I got the PaginData from viewModel and submit it into the adapter.

    private fun observeData() {
    lifecycleScope.launch {
        viewModel.getPeople().observe(this@MainActivity, {
            pagingAdapter.submitData(lifecycle, it)
        })
    }

In my opinion, the persons who have the same id will not be included in the adapter thanks to DiffUtil.ItemCallback. But it didn't happen. RecyclerView prints every person object even if they have the same id.

How can I distinct the data by id? Why didn't DiffUtil.ItemCallback work? Thanks.

READ ALSO
WebRTC Force Stereo in Chrome by editing the sdp config

WebRTC Force Stereo in Chrome by editing the sdp config

I'm trying to implement a workaround for what appears to be a known issue in all browsers but firefox where webRTC audio stream is downgraded to mono from stereo

47
get origin url of 301/302 Forward in PHP/Javascript

get origin url of 301/302 Forward in PHP/Javascript

I have a small question: From different Domains I'm forwarding via 301/302 to one distinct target domainOn the target Server I have a running apache

40
Puppeteer page.$$ returns empty array

Puppeteer page.$$ returns empty array

I'm working on a simple scrapper but I can't get past this issueIt returns an empty array everytime I run it, however the site does contain the elements and returns a NodeList when I run querySelectorAll on the console

54
How can I obtain the date based on geographical coordinates? (JavaScript)

How can I obtain the date based on geographical coordinates? (JavaScript)

I am making a weather application, and I have a simple P-tag which is populated with the date using JavaScript:

14