Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using recyclerview selection with paging 3

I'm trying to use Selection ( https://developer.android.com/reference/androidx/recyclerview/selection/package-summary ) with the new paging library ( so paging 3 )

With Paging 2 that was doable because we were using PagedListAdapter and that was working will with the Selection library but now with the new PagingDataAdapter I can't make it work anymore.

https://developer.android.com/reference/kotlin/androidx/paging/PagingDataAdapter

We are losing getCurrentList(), setHasStableIds() will now return UnsupportedOperationException.

So if anyone have it woring I would greatly appreciate some help on this.

like image 924
Neodigi Avatar asked Apr 25 '26 06:04

Neodigi


1 Answers

In the new Paging3 library, you can get the currentlist with the snapShot() method of the PagingDataAdapter class.

I recently had the same key provider problem so I implemented a custom one like so:

class MyItemKeyProvider(private val adapter: MyPagingAdapter) :
    ItemKeyProvider<String>(SCOPE_CACHED) {
    override fun getKey(position: Int): String = adapter.snapshot().items[position].id
    override fun getPosition(key: String): Int = adapter.snapshot().items.indexOfFirst { it.id == key }
like image 162
Joseph Geoffery Avatar answered Apr 27 '26 19:04

Joseph Geoffery



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!