Search in sources :

Example 1 with LivePagedListBuilder

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);
        }
    });
}
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)

Example 2 with LivePagedListBuilder

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();
}
Also used : PagedList(androidx.paging.PagedList) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) LivePagedListBuilder(androidx.paging.LivePagedListBuilder)

Example 3 with LivePagedListBuilder

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();
}
Also used : PagedList(androidx.paging.PagedList) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) TreatmentCriteria(de.symeda.sormas.app.backend.therapy.TreatmentCriteria)

Example 4 with LivePagedListBuilder

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();
}
Also used : PagedList(androidx.paging.PagedList) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) LivePagedListBuilder(androidx.paging.LivePagedListBuilder)

Example 5 with LivePagedListBuilder

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();
}
Also used : PagedList(androidx.paging.PagedList) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) LivePagedListBuilder(androidx.paging.LivePagedListBuilder) NonNull(androidx.annotation.NonNull) DataSource(androidx.paging.DataSource)

Aggregations

LivePagedListBuilder (androidx.paging.LivePagedListBuilder)12 PagedList (androidx.paging.PagedList)12 NonNull (androidx.annotation.NonNull)2 DataSource (androidx.paging.DataSource)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 ClinicalVisitCriteria (de.symeda.sormas.app.backend.clinicalcourse.ClinicalVisitCriteria)1 PrescriptionCriteria (de.symeda.sormas.app.backend.therapy.PrescriptionCriteria)1 TreatmentCriteria (de.symeda.sormas.app.backend.therapy.TreatmentCriteria)1 List (java.util.List)1