use of com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.SnakeListItemAdapterDelegate 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);
}
});
}
Aggregations