Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pagedList loading all items at once

Tags:

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?

like image 988
Yash Avatar asked Apr 27 '18 13:04

Yash


1 Answers

Got it working. It's returning correct no of elements after disabling placeholders

like image 81
Yash Avatar answered Oct 04 '22 02:10

Yash