androidx.paging.PagedList Java Examples

The following examples show how to use androidx.paging.PagedList. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UserListingViewModel.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
public UserListingViewModel(Retrofit retrofit, String query, SortType sortType) {
    userListingDataSourceFactory = new UserListingDataSourceFactory(retrofit, query, sortType);

    initialLoadingState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
            UserListingDataSource::getInitialLoadStateLiveData);
    paginationNetworkState = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
            UserListingDataSource::getPaginationNetworkStateLiveData);
    hasUserLiveData = Transformations.switchMap(userListingDataSourceFactory.getUserListingDataSourceMutableLiveData(),
            UserListingDataSource::hasUserLiveData);

    sortTypeLiveData = new MutableLiveData<>();
    sortTypeLiveData.postValue(sortType);

    PagedList.Config pagedListConfig =
            (new PagedList.Config.Builder())
                    .setEnablePlaceholders(false)
                    .setPageSize(25)
                    .build();

    users = Transformations.switchMap(sortTypeLiveData, sort -> {
        userListingDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
        return (new LivePagedListBuilder(userListingDataSourceFactory, pagedListConfig)).build();
    });
}
 
Example #2
Source File: MainActivityViewModel.java    From android-popular-movies-app with Apache License 2.0 6 votes vote down vote up
/**
 * Initialize the paged list
 */
private void init(String sortCriteria) {
    Executor executor = Executors.newFixedThreadPool(NUMBER_OF_FIXED_THREADS_FIVE);

    // Create a MovieDataSourceFactory providing DataSource generations
    MovieDataSourceFactory movieDataFactory = new MovieDataSourceFactory(sortCriteria);

    // Configures how a PagedList loads content from the MovieDataSource
    PagedList.Config config = (new PagedList.Config.Builder())
            .setEnablePlaceholders(false)
            // Size hint for initial load of PagedList
            .setInitialLoadSizeHint(INITIAL_LOAD_SIZE_HINT)
            // Size of each page loaded by the PagedList
            .setPageSize(PAGE_SIZE)
            // Prefetch distance which defines how far ahead to load
            .setPrefetchDistance(PREFETCH_DISTANCE)
            .build();

    // The LivePagedListBuilder class is used to get a LiveData object of type PagedList
    mMoviePagedList = new LivePagedListBuilder<>(movieDataFactory, config)
            .setFetchExecutor(executor)
            .build();
}
 
Example #3
Source File: AbstractQueryFragment.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
private void observeThreadOverviewItems(LiveData<PagedList<ThreadOverviewItem>> liveData) {
    final AtomicBoolean actionModeRefreshed = new AtomicBoolean(false);
    liveData.observe(getViewLifecycleOwner(), threadOverviewItems -> {
        final RecyclerView.LayoutManager layoutManager = binding.threadList.getLayoutManager();
        final boolean atTop;
        if (layoutManager instanceof LinearLayoutManager) {
            atTop = ((LinearLayoutManager) layoutManager).findFirstCompletelyVisibleItemPosition() == 0;
        } else {
            atTop = false;
        }
        threadOverviewAdapter.submitList(threadOverviewItems, () -> {
            if (atTop && binding != null) {
                binding.threadList.scrollToPosition(0);
            }
            if (actionMode != null && actionModeRefreshed.compareAndSet(false, true)) {
                actionMode.invalidate();
            }
        });
    });
}
 
Example #4
Source File: ThreadOverviewItemKeyProvider.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
@Override
public int getPosition(@NonNull String key) {
    final PagedList<ThreadOverviewItem> currentList = threadOverviewAdapter.getCurrentList();
    if (currentList == null) {
        return RecyclerView.NO_POSITION;
    }
    final int offset = currentList.getPositionOffset();
    final List<ThreadOverviewItem> snapshot = currentList.snapshot();
    int i = 0;
    for (final ThreadOverviewItem item : snapshot) {
        if (item != null && key.equals(item.threadId)) {
            return offset + i;
        }
        ++i;
    }
    return RecyclerView.NO_POSITION;
}
 
Example #5
Source File: MainActivity.java    From android-popular-movies-app with Apache License 2.0 6 votes vote down vote up
/**
 * Update the MoviePagedList from LiveData in MainActivityViewModel
 */
private void observeMoviePagedList() {
    mMainViewModel.getMoviePagedList().observe(this, new Observer<PagedList<Movie>>() {
        @Override
        public void onChanged(@Nullable PagedList<Movie> pagedList) {
            showMovieDataView();
            if (pagedList != null) {
                mMoviePagedListAdapter.submitList(pagedList);

                // Restore the scroll position after setting up the adapter with the list of movies
                mMainBinding.rvMovie.getLayoutManager().onRestoreInstanceState(mSavedLayoutState);
            }

            // When offline, make the movie data view visible and show a snackbar message
            if (!isOnline()) {
                showMovieDataView();
                showSnackbarOffline();
            }
        }
    });
}
 
Example #6
Source File: QueryRepository.java    From lttrs-android with Apache License 2.0 6 votes vote down vote up
public LiveData<PagedList<ThreadOverviewItem>> getThreadOverviewItems(final EmailQuery query) {
    return Transformations.switchMap(databaseLiveData, new Function<LttrsDatabase, LiveData<PagedList<ThreadOverviewItem>>>() {
        @Override
        public LiveData<PagedList<ThreadOverviewItem>> apply(LttrsDatabase database) {
            return new LivePagedListBuilder<>(database.queryDao().getThreadOverviewItems(query.toQueryString()), 30)
                    .setBoundaryCallback(new PagedList.BoundaryCallback<ThreadOverviewItem>() {
                        @Override
                        public void onZeroItemsLoaded() {
                            Log.d("lttrs", "onZeroItemsLoaded");
                            requestNextPage(query, null); //conceptually in terms of loading indicators this is more of a page request
                            super.onZeroItemsLoaded();
                        }

                        @Override
                        public void onItemAtEndLoaded(@NonNull ThreadOverviewItem itemAtEnd) {
                            Log.d("lttrs", "onItemAtEndLoaded(" + itemAtEnd.emailId + ")");
                            requestNextPage(query, itemAtEnd.emailId);
                            super.onItemAtEndLoaded(itemAtEnd);
                        }
                    })
                    .build();
        }
    });
}
 
Example #7
Source File: MainActivity.java    From android-popular-movies-app with Apache License 2.0 6 votes vote down vote up
/**
 * Update the MoviePagedList from LiveData in MainActivityViewModel
 */
private void observeMoviePagedList() {
    mMainViewModel.getMoviePagedList().observe(this, new Observer<PagedList<Movie>>() {
        @Override
        public void onChanged(@Nullable PagedList<Movie> pagedList) {
            showMovieDataView();
            if (pagedList != null) {
                mMoviePagedListAdapter.submitList(pagedList);

                // Restore the scroll position after setting up the adapter with the list of movies
                mMainBinding.rvMovie.getLayoutManager().onRestoreInstanceState(mSavedLayoutState);
            }

            // When offline, make the movie data view visible and show a snackbar message
            if (!isOnline()) {
                showMovieDataView();
                showSnackbarOffline();
            }
        }
    });
}
 
Example #8
Source File: MediaFileViewModel.java    From FilePicker with Apache License 2.0 6 votes vote down vote up
private MediaFileViewModel(ContentResolver contentResolver, Configurations configs, Long dirId) {
    this.contentResolver = contentResolver;

    MediaFileDataSource.Factory mediaFileDataSourceFactory = new MediaFileDataSource.Factory(contentResolver, configs, dirId);

    mediaFiles = new LivePagedListBuilder<>(
            mediaFileDataSourceFactory,
            new PagedList.Config.Builder()
                    .setPageSize(Configurations.PAGE_SIZE)
                    .setInitialLoadSizeHint(15)
                    .setMaxSize(Configurations.PAGE_SIZE * 3)
                    .setPrefetchDistance(Configurations.PREFETCH_DISTANCE)
                    .setEnablePlaceholders(false)
                    .build()
    ).build();

    contentResolver.registerContentObserver(mediaFileDataSourceFactory.getUri(), true, contentObserver);
}
 
Example #9
Source File: PagingMockIntegrationShould.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void get_initial_objects_ordered_by_description_desc() throws InterruptedException {
    LiveData<PagedList<CategoryOption>> liveData = d2.categoryModule().categoryOptions()
            .orderByDescription(RepositoryScope.OrderByDirection.DESC)
            .getPaged(2);
    TestObserver.test(liveData)
            .awaitValue()
            .assertHasValue()
            .assertValue(pagedList -> pagedList.size() == 6)
            .assertValue(pagedList -> pagedList.get(0).displayName().equals("default display name"))
            .assertValue(pagedList -> pagedList.get(1).displayName().equals("Female"))
            .assertValue(pagedList -> pagedList.get(2).displayName().equals("Male"))
            .assertValue(pagedList -> pagedList.get(3).displayName().equals("In Community"))
            .assertValue(pagedList -> pagedList.get(4).displayName().equals("At PHU"))
            .assertValue(pagedList -> pagedList.get(5).displayName().equals("MCH Aides"));
}
 
Example #10
Source File: PagingMockIntegrationShould.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void get_initial_objects_ordered_by_display_name_desc() throws InterruptedException {
    LiveData<PagedList<CategoryOption>> liveData = d2.categoryModule().categoryOptions()
            .orderByDisplayName(RepositoryScope.OrderByDirection.DESC)
            .getPaged(2);
    TestObserver.test(liveData)
            .awaitValue()
            .assertHasValue()
            .assertValue(pagedList -> pagedList.size() == 6)
            .assertValue(pagedList -> pagedList.get(0).displayName().equals("default display name"))
            .assertValue(pagedList -> pagedList.get(1).displayName().equals("Trained TBA"))
            .assertValue(pagedList -> pagedList.get(2).displayName().equals("SECHN"))
            .assertValue(pagedList -> pagedList.get(3).displayName().equals("Male"))
            .assertValue(pagedList -> pagedList.get(4).displayName().equals("MCH Aides"))
            .assertValue(pagedList -> pagedList.get(5).displayName().equals("In Community"));
}
 
Example #11
Source File: PagingMockIntegrationShould.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void get_initial_objects_ordered_by_description_and_display_name_desc() throws InterruptedException {
    LiveData<PagedList<CategoryOption>> liveData = d2.categoryModule().categoryOptions()
            .orderByDescription(RepositoryScope.OrderByDirection.DESC)
            .orderByDisplayName(RepositoryScope.OrderByDirection.ASC)
            .getPaged(2);
    TestObserver.test(liveData)
            .awaitValue()
            .assertHasValue()
            .assertValue(pagedList -> pagedList.size() == 6)
            .assertValue(pagedList -> pagedList.get(0).displayName().equals("default display name"))
            .assertValue(pagedList -> pagedList.get(1).displayName().equals("At PHU"))
            .assertValue(pagedList -> pagedList.get(2).displayName().equals("Female"))
            .assertValue(pagedList -> pagedList.get(3).displayName().equals("In Community"))
            .assertValue(pagedList -> pagedList.get(4).displayName().equals("Male"))
            .assertValue(pagedList -> pagedList.get(5).displayName().equals("MCH Aides"));
}
 
Example #12
Source File: PostFragment.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@Subscribe
public void onPostUpdateEvent(PostUpdateEventToPostList event) {
    PagedList<Post> posts = mAdapter.getCurrentList();
    if (posts != null && event.positionInList >= 0 && event.positionInList < posts.size()) {
        Post post = posts.get(event.positionInList);
        if (post != null && post.getFullName().equals(event.post.getFullName())) {
            post.setTitle(event.post.getTitle());
            post.setVoteType(event.post.getVoteType());
            post.setScore(event.post.getScore());
            post.setNSFW(event.post.isNSFW());
            post.setHidden(event.post.isHidden());
            post.setSpoiler(event.post.isSpoiler());
            post.setFlair(event.post.getFlair());
            post.setSaved(event.post.isSaved());
            mAdapter.notifyItemChanged(event.positionInList);
        }
    }
}
 
Example #13
Source File: PagingIntegrationTest_PagedList.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@Test
public void initialPageBind() {
  controller.setConfig(
      new PagedList.Config.Builder()
          .setEnablePlaceholders(false)
          .setPageSize(100)
          .setInitialLoadSizeHint(100)
          .build()
  );
  controller.setPagedListWithSize(500);

  List<EpoxyModel<?>> models = controller.getAdapter().getCopyOfModels();
  assertEquals(100, models.size());

  assertEquals(1, models.get(0).id());
}
 
Example #14
Source File: PagingIntegrationTest_List.java    From epoxy with Apache License 2.0 6 votes vote down vote up
@Test
public void initialPageBind() {
  controller.setConfig(
      new PagedList.Config.Builder()
          .setEnablePlaceholders(false)
          .setPageSize(100)
          .setInitialLoadSizeHint(100)
          .build()
  );
  controller.setListWithSize(500);

  List<EpoxyModel<?>> models = controller.getAdapter().getCopyOfModels();
  assertEquals(100, models.size());

  assertEquals(1, models.get(0).id());
}
 
Example #15
Source File: ProgramEventDetailActivity.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public void setLiveData(LiveData<PagedList<ProgramEventViewModel>> pagedListLiveData) {
    pagedListLiveData.observe(this, pagedList -> {
        binding.programProgress.setVisibility(View.GONE);
        liveAdapter.submitList(pagedList, () -> {
            if (binding.recycler.getAdapter() != null && binding.recycler.getAdapter().getItemCount() == 0) {
                binding.emptyTeis.setVisibility(View.VISIBLE);
                binding.recycler.setVisibility(View.GONE);
            } else {
                binding.emptyTeis.setVisibility(View.GONE);
                binding.recycler.setVisibility(View.VISIBLE);
            }
        });

    });

}
 
Example #16
Source File: PagingEpoxyController.java    From epoxy with Apache License 2.0 6 votes vote down vote up
/**
 * Set a PagedList that should be used to build models in this controller. A listener will be
 * attached to the list so that models are rebuilt as new list items are loaded.
 * <p>
 * By default the Config setting on the PagedList will dictate how many models are built at once,
 * and what prefetch thresholds should be used. This can be overridden with a separate Config via
 * {@link #setConfig(Config)}.
 * <p>
 * See {@link #setConfig(Config)} for details on how the Config settings are used, and for
 * recommended values.
 */
public void setList(@Nullable PagedList<T> list) {
  if (list == this.pagedList) {
    return;
  }

  PagedList<T> previousList = this.pagedList;
  this.pagedList = list;

  if (previousList != null) {
    previousList.removeWeakCallback(callback);
  }

  if (list != null) {
    list.addWeakCallback(null, callback);
  }

  isFirstBuildForList = true;
  updatePagedListSnapshot();
}
 
Example #17
Source File: PagingMockIntegrationShould.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Test
public void get_initial_objects_ordered_by_display_name_asc() throws InterruptedException {
    LiveData<PagedList<CategoryOption>> liveData = d2.categoryModule().categoryOptions()
            .orderByDisplayName(RepositoryScope.OrderByDirection.ASC)
            .getPaged(2);
    TestObserver.test(liveData)
            .awaitValue()
            .assertHasValue()
            .assertValue(pagedList -> pagedList.size() == 6)
            .assertValue(pagedList -> pagedList.get(0).displayName().equals("At PHU"))
            .assertValue(pagedList -> pagedList.get(1).displayName().equals("Female"))
            .assertValue(pagedList -> pagedList.get(2).displayName().equals("In Community"))
            .assertValue(pagedList -> pagedList.get(3).displayName().equals("MCH Aides"))
            .assertValue(pagedList -> pagedList.get(4).displayName().equals("Male"))
            .assertValue(pagedList -> pagedList.get(5).displayName().equals("SECHN"));
}
 
Example #18
Source File: SubredditListingViewModel.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
public SubredditListingViewModel(Retrofit retrofit, String query, SortType sortType) {
    subredditListingDataSourceFactory = new SubredditListingDataSourceFactory(retrofit, query, sortType);

    initialLoadingState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
            SubredditListingDataSource::getInitialLoadStateLiveData);
    paginationNetworkState = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
            SubredditListingDataSource::getPaginationNetworkStateLiveData);
    hasSubredditLiveData = Transformations.switchMap(subredditListingDataSourceFactory.getSubredditListingDataSourceMutableLiveData(),
            SubredditListingDataSource::hasSubredditLiveData);

    sortTypeLiveData = new MutableLiveData<>();
    sortTypeLiveData.postValue(sortType);

    PagedList.Config pagedListConfig =
            (new PagedList.Config.Builder())
                    .setEnablePlaceholders(false)
                    .setPageSize(25)
                    .build();

    subreddits = Transformations.switchMap(sortTypeLiveData, sort -> {
        subredditListingDataSourceFactory.changeSortType(sortTypeLiveData.getValue());
        return new LivePagedListBuilder(subredditListingDataSourceFactory, pagedListConfig).build();
    });
}
 
Example #19
Source File: FirestorePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the query using a custom {@link Source} and a {@link ClassSnapshotParser} based
 * on the given class.
 *
 * See {@link #setQuery(Query, Source, PagedList.Config, SnapshotParser)}.
 */
@NonNull
public Builder<T> setQuery(@NonNull Query query,
                           @NonNull Source source,
                           @NonNull PagedList.Config config,
                           @NonNull Class<T> modelClass) {
    return setQuery(query, source, config, new ClassSnapshotParser<>(modelClass));
}
 
Example #20
Source File: DatabasePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the Database query to paginate.
 *
 * @param query the FirebaseDatabase query. This query should only contain orderByKey(), orderByChild() and
 *              orderByValue() clauses. Any limit will cause an error such as limitToLast() or limitToFirst().
 * @param config paging configuration, passed directly to the support paging library.
 * @param parser the {@link SnapshotParser} to parse {@link DataSnapshot} into model
 *               objects.
 * @return this, for chaining.
 */
@NonNull
public Builder<T> setQuery(@NonNull Query query,
                           @NonNull PagedList.Config config,
                           @NotNull SnapshotParser<T> parser) {
    FirebaseDataSource.Factory factory = new FirebaseDataSource.Factory(query);
    mData = new LivePagedListBuilder<>(factory, config).build();

    mParser = parser;
    return this;
}
 
Example #21
Source File: ObjectBoxDAO.java    From Hentoid with Apache License 2.0 5 votes vote down vote up
private LiveData<PagedList<Content>> getPagedContent(
        int mode,
        String filter,
        List<Attribute> metadata,
        int orderField,
        boolean orderDesc,
        boolean favouritesOnly,
        boolean loadAll) {
    boolean isRandom = (orderField == Preferences.Constant.ORDER_FIELD_RANDOM);

    Query<Content> query;
    if (Mode.SEARCH_CONTENT_MODULAR == mode) {
        query = db.queryContentSearchContent(filter, metadata, favouritesOnly, orderField, orderDesc);
    } else { // Mode.SEARCH_CONTENT_UNIVERSAL
        query = db.queryContentUniversal(filter, favouritesOnly, orderField, orderDesc);
    }

    int nbPages = Preferences.getContentPageQuantity();
    int initialLoad = nbPages * 2;
    if (loadAll) {
        // Trump Android's algorithm by setting a number of pages higher that the actual number of results
        // to avoid having a truncated result set (see issue #501)
        initialLoad = (int) Math.ceil(query.count() * 1.0 / nbPages) * nbPages;
    }

    PagedList.Config cfg = new PagedList.Config.Builder().setEnablePlaceholders(!loadAll).setInitialLoadSizeHint(initialLoad).setPageSize(nbPages).build();

    return new LivePagedListBuilder<>(
            isRandom ? new ObjectBoxRandomDataSource.RandomDataSourceFactory<>(query) : new ObjectBoxDataSource.Factory<>(query),
            cfg
    ).build();
}
 
Example #22
Source File: ProgramEventDetailRepositoryImpl.java    From dhis2-android-capture-app with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@NonNull
@Override
public LiveData<PagedList<ProgramEventViewModel>> filteredProgramEvents(List<DatePeriod> dateFilter, List<String> orgUnitFilter, List<CategoryOptionCombo> catOptCombList,
                                                                        List<EventStatus> eventStatus, List<State> states, boolean assignedToUser) {
    EventCollectionRepository eventRepo = d2.eventModule().events().byProgramUid().eq(programUid).byDeleted().isFalse();
    if (!dateFilter.isEmpty())
        eventRepo = eventRepo.byEventDate().inDatePeriods(dateFilter);
    if (!orgUnitFilter.isEmpty())
        eventRepo = eventRepo.byOrganisationUnitUid().in(orgUnitFilter);
    if (!catOptCombList.isEmpty())
        eventRepo = eventRepo.byAttributeOptionComboUid().in(UidsHelper.getUids(catOptCombList));
    if (!eventStatus.isEmpty())
        eventRepo = eventRepo.byStatus().in(eventStatus);
    if (!states.isEmpty())
        eventRepo = eventRepo.byState().in(states);
    if (assignedToUser)
        eventRepo = eventRepo.byAssignedUser().eq(getCurrentUser());

    DataSource dataSource = eventRepo.orderByEventDate(RepositoryScope.OrderByDirection.DESC).withTrackedEntityDataValues().getDataSource().map(event -> mapper.eventToProgramEvent(event));

    return new LivePagedListBuilder(new DataSource.Factory() {
        @Override
        public DataSource create() {
            return dataSource;
        }
    }, 20).build();
}
 
Example #23
Source File: RoomFileRepository.java    From ArchPackages with GNU General Public License v3.0 5 votes vote down vote up
public RoomFileRepository(Application application) {
    RoomFileDatabase roomFileDatabase = RoomFileDatabase.getRoomFileDatabase(application);
    roomFileDao = roomFileDatabase.roomFileDao();
    listLiveData = roomFileDao.geAlphabetizedFiles();
    PagedList.Config config = new PagedList.Config.Builder()
            .setPageSize(25)
            .setEnablePlaceholders(false)
            .build();
    pagedListLiveData = new LivePagedListBuilder<>(
            roomFileDao.getPagedFiles(), config)
            .setInitialLoadKey(1)
            .build();
}
 
Example #24
Source File: FirebaseRecyclerPagingAdapter.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onChanged(@Nullable PagedList<DataSnapshot> snapshots) {
    if (snapshots == null) {
        return;
    }
    submitList(snapshots);
}
 
Example #25
Source File: TransactionListViewModel.java    From Gander with Apache License 2.0 5 votes vote down vote up
LiveData<PagedList<HttpTransactionUIHelper>> getTransactions(String key) {
    if (key == null || key.trim().length() == 0) {
        return mTransactions;
    } else {
        DataSource.Factory<Integer, HttpTransactionUIHelper> factory = mTransactionDao.getAllTransactionsWith(key, TransactionDao.SearchType.DEFAULT).map(HttpTransactionUIHelper.HTTP_TRANSACTION_UI_HELPER_FUNCTION);
        return new LivePagedListBuilder<>(factory, config).build();
    }
}
 
Example #26
Source File: FirestorePagingOptions.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
/**
 * Sets the query using {@link Source#DEFAULT} and a {@link ClassSnapshotParser} based
 * on the given Class.
 *
 * See {@link #setQuery(Query, Source, PagedList.Config, SnapshotParser)}.
 */
@NonNull
public Builder<T> setQuery(@NonNull Query query,
                           @NonNull PagedList.Config config,
                           @NonNull Class<T> modelClass) {
    return setQuery(query, Source.DEFAULT, config, modelClass);
}
 
Example #27
Source File: RepoMoviesResult.java    From PopularMovies with MIT License 5 votes vote down vote up
public RepoMoviesResult(LiveData<PagedList<Movie>> data,
                        LiveData<Resource> resource,
                        MutableLiveData<MoviePageKeyedDataSource> sourceLiveData) {
    this.data = data;
    this.resource = resource;
    this.sourceLiveData = sourceLiveData;
}
 
Example #28
Source File: TransactionListActivity.java    From Gander with Apache License 2.0 5 votes vote down vote up
private void loadResults(final String searchKey, LiveData<PagedList<HttpTransactionUIHelper>> pagedListLiveData) {
    if (mCurrentSubscription != null && mCurrentSubscription.hasObservers()) {
        mCurrentSubscription.removeObservers(this);
    }
    mCurrentSubscription = pagedListLiveData;
    mCurrentSubscription.observe(TransactionListActivity.this, new Observer<PagedList<HttpTransactionUIHelper>>() {
        @Override
        public void onChanged(@Nullable PagedList<HttpTransactionUIHelper> transactionPagedList) {
            mTransactionSampler.consume(new TransactionListWithSearchKeyModel(searchKey, transactionPagedList));
        }
    });
}
 
Example #29
Source File: FirestorePagingAdapter.java    From FirebaseUI-Android with Apache License 2.0 5 votes vote down vote up
@Override
public void onChanged(@Nullable PagedList<DocumentSnapshot> snapshots) {
    if (snapshots == null) {
        return;
    }

    submitList(snapshots);
}
 
Example #30
Source File: PagingEpoxyController.java    From epoxy with Apache License 2.0 5 votes vote down vote up
public void setList(@Nullable List<T> list) {
  if (list == this.list) {
    return;
  }

  if (pagedList != null) {
    setList((PagedList<T>) null);
  }

  this.list = list == null ? Collections.<T>emptyList() : list;
  isFirstBuildForList = true;
  requestModelBuild();
}