Search code examples
androidkotlinandroid-paging-3

Migrate to Paging 3


I want to migrate an older PagedListAdapter to PagingDataAdapter, but cant find analogue of onCurrentListChanged method from PagedListAdapter.

How can I implement similar behavior on PagingDataAdapter?


Solution

  • I'm not a Paging 3 specialist, but I took a look and saw that Paging 3 uses Kotlin Coroutines and works with Flows and I think you can observe the onPagesUpdatedFlow atribute from your PagingDataAdapter

    Since this will give you a Flow, you will have to retrieve the itens by hand using snapshot().items. You can save the elements on a field called previousList and when they change, you'll have both currentList and previousList.

    Maybe there's a better way to do it, but if it works for you, great :)