AkshayChordiya / News

A sample News 🗞 app built using Modern Android Development [Architecture Components, Coroutines, Retrofit, Room, Kotlin, Dagger]
MIT License
848 stars 166 forks source link

Proxing ListAdapter with AsyncListDiffer #34

Closed radityagumay closed 4 years ago

radityagumay commented 4 years ago

Continuing our discussion on twitter. So, it's always better if engineers could collaborate with open source projects.

I just create a PR for proxying a few functions that ListAdapter has and override by AsyncListDiffer.

these the list of functions that changes:

override fun submitList(list: MutableList<NewsArticles>?) {
      differ.submitList(list)
}

override fun getItem(position: Int): NewsArticles {
     return differ.currentList.get(position)
 }

 override fun getItemCount(): Int {
      return differ.currentList.size
 }

Under the hood, AsyncListDiffer will execute submitList in the form of background thread. See here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-master-dev:recyclerview/recyclerview/src/main/java/androidx/recyclerview/widget/AsyncListDiffer.java;l=289;bpv=1

Thank you!

iNoles commented 4 years ago

According to https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter?hl=en, "This class is a convenience wrapper around AsyncListDiffer that implements Adapter common default behavior for item access and counting. "

radityagumay commented 4 years ago

According to https://developer.android.com/reference/androidx/recyclerview/widget/ListAdapter?hl=en, "This class is a convenience wrapper around AsyncListDiffer that implements Adapter common default behavior for item access and counting. "

omg, I missed that.

ListAdapter is available both support and androidx. will close this PR

here's the old one https://cs.android.com/android/platform/superproject/+/master:frameworks/base/core/java/android/widget/ListAdapter.java;l=26?q=ListAda&sq=&ss=android

AkshayChordiya commented 4 years ago

So technically we are already using AsyncListDiffer by using ListAdapter, that's nice! Thank you @iNoles and @radityagumay for your efforts 🙏