I've trying to integrate the architecture components in my app, viz Pagination, LiveData, ViewModel.
Room is already integrated and tested before so I can return a DataSource.Factory<Integer, DbEntity>
from my DAO class. This is my code for creating LiveData of PagedList:
PagedList.Config pagedListConfig =
(new PagedList.Config.Builder()).setEnablePlaceholders(true)
.setPrefetchDistance(5)
.setPageSize(10)
.setInitialLoadSizeHint(10)
.build();
LiveData<PagedList<DbEntity>> dbEntities = new
LivePagedListBuilder<>(DAO.getItemList(timeNow), pagedListConfig).build();
And I am observing on this livedata in my fragment class:
viewModel.dbEntities.observe(this, new Observer<PagedList<DbEntity>>() {
@Override
public void onChanged(@Nullable PagedList<DbEntity> inboxEntities) {
adapter.submitList(inboxEntities);
}
});
The problem is the list is taking too long to draw and it seems that all the items in the list (1300) are being drawn on the first go.
I verified this at two places : onChanged
is called with the PagedList size equal to 1300 and onBindViewHolder
of adapter is being called for all the positions upto 1300.
Am I doing sth wrong here?
Got it working. It's returning correct no of elements after disabling placeholders
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With