import android.arch.lifecycle.LiveData;
import android.arch.lifecycle.ViewModel;
import android.arch.paging.LivePagedListBuilder;
import android.arch.paging.PagedList;
public class ConcertViewModel extends ViewModel {
private static final int PAGE_SIZE = 10;//初始加载数量
private static final int RELOAD_SIZE = 20;//往下滑动加载数量
private final LiveData<PagedList<Concert>> mConcertListLiveData;
public ConcertViewModel() {
PagedList.Config config = new PagedList.Config.Builder()
.setPageSize(PAGE_SIZE) // 分页加载的数量
.setEnablePlaceholders(false) // 当item为null是否使用PlaceHolder展示
.setInitialLoadSizeHint(RELOAD_SIZE) // 预加载的数量, 与分页加载的数量成倍数关系
.setPrefetchDistance(5) //设置距离最后还有多少个item时,开始加载下一页的数据.
.build();
mConcertListLiveData = new LivePagedListBuilder<>(new ConcertFactory(), config)
.setBoundaryCallback(new ConcertListBoundaryCallback())
.build();
}
public LiveData<PagedList<Concert>> getConcertListLiveData() {
return mConcertListLiveData;
}
}
网友评论