I have just added paged library into my project. This is my implementation.
PagedList.Config pagedListConfig = new PagedList.Config.Builder().setEnablePlaceholders(false).setPageSize(10).build();
videos = new LivePagedListBuilder<>(
videosDAO.getPagedVideos(tontonHomePageItem.getId()), pagedListConfig)
.setBoundaryCallback(boundaryCallBack).build();
private class VideosBoundaryCallBack extends PagedList.BoundaryCallback<Video> {
public VideosBoundaryCallBack() {
}
@Override
public void onItemAtEndLoaded(@NonNull Video itemAtEnd) {
KLog.d(TAG, "onItemAtEndLoaded + next page token = " + mNextPageToken);
if (loadVideoState != Defines.LOADING_STATE.BUFFERING) {
KLog.d(TAG, "onItemAtEndLoaded LOAD");
loadVideoState = Defines.LOADING_STATE.BUFFERING;
//load more data from web service
}
}
}
@DAO
@Query("SELECT * from video_table WHERE channelId=:channelId ORDER BY year DESC")
DataSource.Factory<Integer, Video> getPagedVideos(String channelId);
@Entity
public class Video{
@NonNull
@PrimaryKey()
@ColumnInfo(name = "id")
public String id;
...
I added these log into activity
model.data.observe(this,(list)->{
Log.d(Defines.TAG,"list page size = " + list.size());
});
There are 13 records in database. After checking above log I got
" list page size = 13"
all 13 items of the list are not null.
I have two questions:
onItemAtEndLoaded
didn't trigger.Finally, I found the solution for this problem.
To solve this, I have to custom
VideoDataSource extends ItemKeyedDataSource<Long, Video>
VideoDataSourceFactory extends DataSource.Factory<Long, Video>
VideoDataSourceFactory videoDataSourceFactory = new VideoDataSourceFactory(this, pageSize);
videos = new LivePagedListBuilder<>(
videoDataSourceFactory,
pagedListConfig).build();
I hope someone have the same problem can solve this problem quickly.