Search in sources :

Example 1 with PagedListDelegationAdapter

use of com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter 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);
        }
    });
}
Also used : CatAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.CatAdapterDelegate) DisplayableItem(com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem) PagedList(androidx.paging.PagedList) SnakeListItemAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.SnakeListItemAdapterDelegate) DogAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.DogAdapterDelegate) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) AdapterDelegatesManager(com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager) GeckoAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.GeckoAdapterDelegate) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) NonNull(androidx.annotation.NonNull) AdvertisementAdapterDelegate(com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.AdvertisementAdapterDelegate) RecyclerView(androidx.recyclerview.widget.RecyclerView) PagedList(androidx.paging.PagedList) List(java.util.List) PagedListDelegationAdapter(com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter)

Aggregations

NonNull (androidx.annotation.NonNull)1 LivePagedListBuilder (androidx.paging.LivePagedListBuilder)1 PagedList (androidx.paging.PagedList)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 AdapterDelegatesManager (com.hannesdorfmann.adapterdelegates4.AdapterDelegatesManager)1 PagedListDelegationAdapter (com.hannesdorfmann.adapterdelegates4.paging.PagedListDelegationAdapter)1 AdvertisementAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.AdvertisementAdapterDelegate)1 CatAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.CatAdapterDelegate)1 DogAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.DogAdapterDelegate)1 GeckoAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.GeckoAdapterDelegate)1 SnakeListItemAdapterDelegate (com.hannesdorfmann.adapterdelegates4.sample.adapterdelegates.SnakeListItemAdapterDelegate)1 DisplayableItem (com.hannesdorfmann.adapterdelegates4.sample.model.DisplayableItem)1 List (java.util.List)1