use of androidx.paging.LivePagedListBuilder in project AdapterDelegates by sockeqwe.
the class PaginationActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_pagination);
RecyclerView recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
AdapterDelegatesManager<List<DisplayableItem>> delegatesManager = new AdapterDelegatesManager<List<DisplayableItem>>().addDelegate(new AdvertisementAdapterDelegate(this)).addDelegate(new CatAdapterDelegate(this)).addDelegate(new DogAdapterDelegate(this)).addDelegate(new GeckoAdapterDelegate(this)).addDelegate(new SnakeListItemAdapterDelegate(this)).setFallbackDelegate(new LoadingAdapterDelegate(this));
final PagedListDelegationAdapter<DisplayableItem> adapter = new PagedListDelegationAdapter<DisplayableItem>(delegatesManager, callback);
recyclerView.setAdapter(adapter);
LiveData<PagedList<DisplayableItem>> pagedListLiveData = new LivePagedListBuilder<>(new SampleDataSource.Factory(), 20).setBoundaryCallback(new PagedList.BoundaryCallback<DisplayableItem>() {
@Override
public void onZeroItemsLoaded() {
Log.d("PaginationSource", "onZeroItemsLoaded");
super.onZeroItemsLoaded();
}
@Override
public void onItemAtFrontLoaded(@NonNull DisplayableItem itemAtFront) {
Log.d("PaginationSource", "onItemAtFrontLoaded " + itemAtFront);
super.onItemAtFrontLoaded(itemAtFront);
}
@Override
public void onItemAtEndLoaded(@NonNull DisplayableItem itemAtEnd) {
Log.d("PaginationSource", "onItemAtEndLoaded " + itemAtEnd);
super.onItemAtEndLoaded(itemAtEnd);
}
}).build();
pagedListLiveData.observe(this, new Observer<PagedList<DisplayableItem>>() {
@Override
public void onChanged(PagedList<DisplayableItem> displayableItems) {
adapter.submitList(displayableItems);
}
});
}
use of androidx.paging.LivePagedListBuilder in project SORMAS-Project by hzi-braunschweig.
the class TaskListViewModel method initializeList.
private void initializeList() {
PagedList.Config config = new PagedList.Config.Builder().setEnablePlaceholders(true).setInitialLoadSizeHint(16).setPageSize(8).build();
LivePagedListBuilder taskListBuilder = new LivePagedListBuilder(taskDataFactory, config);
tasks = taskListBuilder.build();
}
use of androidx.paging.LivePagedListBuilder in project SORMAS-Project by hzi-braunschweig.
the class TreatmentListViewModel method initializeViewModel.
public void initializeViewModel(Therapy therapy) {
treatmentDataFactory = new TreatmentDataFactory();
TreatmentCriteria treatmentCriteria = new TreatmentCriteria();
treatmentCriteria.therapy(therapy);
treatmentDataFactory.setTreatmentCriteria(treatmentCriteria);
PagedList.Config config = new PagedList.Config.Builder().setEnablePlaceholders(true).setInitialLoadSizeHint(16).setPageSize(8).build();
LivePagedListBuilder treatmentListBuilder = new LivePagedListBuilder(treatmentDataFactory, config);
treatments = treatmentListBuilder.build();
}
use of androidx.paging.LivePagedListBuilder in project SORMAS-Project by hzi-braunschweig.
the class VaccinationListViewModel method initializeList.
private void initializeList() {
PagedList.Config config = new PagedList.Config.Builder().setEnablePlaceholders(true).setInitialLoadSizeHint(16).setPageSize(8).build();
LivePagedListBuilder vaccinationListBuilder = new LivePagedListBuilder(vaccinationDataFactory, config);
vaccinations = vaccinationListBuilder.build();
}
use of androidx.paging.LivePagedListBuilder in project apps-android-commons by commons-app.
the class ContributionsListPresenter method setup.
/**
* Setup the paged list. This method sets the configuration for paged list and ties it up with
* the live data object. This method can be tweaked to update the lazy loading behavior of the
* contributions list
*/
void setup(String userName, boolean isSelf) {
final PagedList.Config pagedListConfig = (new PagedList.Config.Builder()).setPrefetchDistance(50).setPageSize(10).build();
Factory<Integer, Contribution> factory;
boolean shouldSetBoundaryCallback;
if (!isSelf) {
// We don't want to persist contributions for other user's, therefore
// creating a new DataSource for them
contributionsRemoteDataSource.setUserName(userName);
factory = new Factory<Integer, Contribution>() {
@NonNull
@Override
public DataSource<Integer, Contribution> create() {
return contributionsRemoteDataSource;
}
};
shouldSetBoundaryCallback = false;
} else {
contributionBoundaryCallback.setUserName(userName);
shouldSetBoundaryCallback = true;
factory = repository.fetchContributions();
}
LivePagedListBuilder livePagedListBuilder = new LivePagedListBuilder(factory, pagedListConfig);
if (shouldSetBoundaryCallback) {
livePagedListBuilder.setBoundaryCallback(contributionBoundaryCallback);
}
contributionList = livePagedListBuilder.build();
}
Aggregations