I'm implemented paging feature based on PagedListAdapter
and I've been checked that works fine. I try implementation to feature as If ListAdapter items are empty then showing EmptyHolder. I have tried that based on commitCallback
after called submitList
as follows code.
Question
Why has PagedListAdapter item count shows as 0 even though the response contains items? How to solve this problem?
FooDataSource
private suspend fun loadItems(beforeId: String) = withContext(Dispatchers.IO) {
getFooUseCase(beforeId)
}
override fun loadInitial(
params: LoadInitialParams<String>,
callback: LoadInitialCallback<String, Foo>
) {
launch {
loadItems(null)
.run {
Timber.d("loadInitial : ${list.size}") // onResponse : 20
callback.onResult(list, null, beforeId)
}
}
}
FooListFragment
observe(fooList) { items ->
// items.size or loadedCount always 0
fooAdapter.submitList(items) {
//fooAdapter.itemCount, fooAdapter.currentList.size or loadedSize
//always 0...
if(fooAdapter.itemCount == 0) {
//show EmptyHolder
}
}
}