There is no direct way to get list of data from PagingData object. If you are not using/or don't want to use PagingDataAdapter, you can use AsyncPagingDataDiffer, which is quick and easy to implement. If you are planning to write unit test for paging then also it is useful.
Create an instance of AsyncPagingDataDiffer
val differ = AsyncPagingDataDiffer(
diffCallback = TestDiffCallback<RecentChatUi>(),
updateCallback = TestListCallback(),
workerDispatcher = Dispatchers.Main
)
you have to pass one DiffUtil.ItemCallback and ListUpdateCallback
class TestListCallback : ListUpdateCallback {
override fun onChanged(position: Int, count: Int, payload: Any?) {}
override fun onMoved(fromPosition: Int, toPosition: Int) {}
override fun onInserted(position: Int, count: Int) {}
override fun onRemoved(position: Int, count: Int) {}
}
class TestDiffCallback<T> : DiffUtil.ItemCallback<T>() {
override fun areItemsTheSame(oldItem: T, newItem: T): Boolean {
return oldItem == newItem
}
override fun areContentsTheSame(oldItem: T, newItem: T): Boolean {
return oldItem == newItem
}
}
then submit the paging data to the adapter and get the list
differ.submitData(pagerData)
val list = differ.snapshot().items