androidx.paging.DataSource Java Examples

The following examples show how to use androidx.paging.DataSource. 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: RoomTransactionDao.java    From Gander with Apache License 2.0 6 votes vote down vote up
DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactionsWith(String key, TransactionDao.SearchType searchType) {
    String endWildCard = key + "%";
    String doubleSideWildCard = "%" + key + "%";
    switch (searchType) {
        case DEFAULT:
            return getAllTransactions(endWildCard, doubleSideWildCard);
        case INCLUDE_REQUEST:
            return getAllTransactionsIncludeRequest(endWildCard, doubleSideWildCard);
        case INCLUDE_RESPONSE:
            return getAllTransactionsIncludeResponse(endWildCard, doubleSideWildCard);
        case INCLUDE_REQUEST_RESPONSE:
            return getAllTransactionsIncludeRequestResponse(endWildCard, doubleSideWildCard);
        default:
            return getAllTransactions(endWildCard, doubleSideWildCard);
    }
}
 
Example #2
Source File: IMDBTransactionDao.java    From Gander with Apache License 2.0 6 votes vote down vote up
@Override
public DataSource.Factory<Integer, HttpTransaction> getAllTransactionsWith(String key, SearchType searchType) {
    Predicate<HttpTransaction> predicate;
    switch (searchType) {
        case DEFAULT:
        default:
            predicate = transactionPredicateProvider.getDefaultSearchPredicate(key);
            break;
        case INCLUDE_REQUEST:
            predicate = transactionPredicateProvider.getRequestSearchPredicate(key);
            break;
        case INCLUDE_RESPONSE:
            predicate = transactionPredicateProvider.getResponseSearchPredicate(key);
            break;
        case INCLUDE_REQUEST_RESPONSE:
            predicate = transactionPredicateProvider.getRequestResponseSearchPredicate(key);
            break;
    }
    return transactionArchComponentProvider.getDataSourceFactory(transactionDataStore, predicate);
}
 
Example #3
Source File: PersistentTransactionDao.java    From Gander with Apache License 2.0 6 votes vote down vote up
@Override
public DataSource.Factory<Integer, HttpTransaction> getAllTransactionsWith(String key, SearchType searchType) {
    String endWildCard = key + "%";
    String doubleSideWildCard = "%" + key + "%";

    DataSource.Factory<Integer, PersistentHttpTransaction> factory;
    switch (searchType) {
        case DEFAULT:
            factory = roomTransactionDao.getAllTransactions(endWildCard, doubleSideWildCard);
            break;
        case INCLUDE_REQUEST:
            factory = roomTransactionDao.getAllTransactionsIncludeRequest(endWildCard, doubleSideWildCard);
            break;
        case INCLUDE_RESPONSE:
            factory = roomTransactionDao.getAllTransactionsIncludeResponse(endWildCard, doubleSideWildCard);
            break;
        case INCLUDE_REQUEST_RESPONSE:
            factory = roomTransactionDao.getAllTransactionsIncludeRequestResponse(endWildCard, doubleSideWildCard);
            break;
        default:
            factory = roomTransactionDao.getAllTransactions(endWildCard, doubleSideWildCard);
            break;
    }

    return factory.map(PERSISTENT_TO_DATA_TRANSACTION_FUNCTION);
}
 
Example #4
Source File: PostDataSourceFactory.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 6 votes vote down vote up
@NonNull
@Override
public DataSource<String, Post> create() {
    if (postType == PostDataSource.TYPE_FRONT_PAGE) {
        postDataSource = new PostDataSource(retrofit, accessToken, locale, postType, sortType,
                filter, nsfw);
    } else if (postType == PostDataSource.TYPE_SEARCH) {
        postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, query,
                postType, sortType, filter, nsfw);
    } else if (postType == PostDataSource.TYPE_SUBREDDIT || postType == PostDataSource.TYPE_MULTI_REDDIT) {
        postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
                sortType, filter, nsfw);
    } else {
        postDataSource = new PostDataSource(retrofit, accessToken, locale, subredditName, postType,
                sortType, userWhere, filter, nsfw);
    }

    postDataSourceLiveData.postValue(postDataSource);
    return postDataSource;
}
 
Example #5
Source File: UserListingDataSourceFactory.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public DataSource create() {
    userListingDataSource = new UserListingDataSource(retrofit, query, sortType);
    userListingDataSourceMutableLiveData.postValue(userListingDataSource);
    return userListingDataSource;
}
 
Example #6
Source File: Monarchy.java    From realm-monarchy with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a LiveData that evaluates the new results on a background looper thread.
 *
 * The resulting list is driven by a PositionalDataSource from the Paging Library.
 *
 * The fetch executor of the provided LivePagedListBuilder will be overridden with Monarchy's own FetchExecutor that Monarchy runs its queries on.
 */
public <R, T extends RealmModel> LiveData<PagedList<R>> findAllPagedWithChanges(DataSource.Factory<Integer, T> dataSourceFactory, LivePagedListBuilder<Integer, R> livePagedListBuilder) {
    assertMainThread();
    final MediatorLiveData<PagedList<R>> mediator = new MediatorLiveData<>();
    if(!(dataSourceFactory instanceof RealmDataSourceFactory)) {
        throw new IllegalArgumentException(
                "The DataSource.Factory provided to this method as the first argument must be the one created by Monarchy.");
    }
    RealmDataSourceFactory<T> realmDataSourceFactory = (RealmDataSourceFactory<T>) dataSourceFactory;
    PagedLiveResults<T> liveResults = realmDataSourceFactory.pagedLiveResults;
    mediator.addSource(liveResults, new Observer<PagedList<T>>() {
        @Override
        public void onChanged(@Nullable PagedList<T> ts) {
            // do nothing, this is to intercept `onActive()` calls to ComputableLiveData
        }
    });
    LiveData<PagedList<R>> computableLiveData = livePagedListBuilder
            .setFetchExecutor(new RealmQueryExecutor(this))
            .build();
    mediator.addSource(computableLiveData, new Observer<PagedList<R>>() {
        @Override
        public void onChanged(@Nullable PagedList<R> data) {
            mediator.postValue(data);
        }
    });
    return mediator;
}
 
Example #7
Source File: TransactionArchComponentProvider.java    From Gander with Apache License 2.0 5 votes vote down vote up
DataSource.Factory<Integer, HttpTransaction> getDataSourceFactory(final TransactionDataStore transactionDataStore, final Predicate<HttpTransaction> filter) {
    return new DataSource.Factory<Integer, HttpTransaction>() {
        @NonNull
        @Override
        public DataSource<Integer, HttpTransaction> create() {
            return new HttpTransactionDataSource(transactionDataStore, filter);
        }
    };
}
 
Example #8
Source File: ResultDataSourceFactory.java    From ArchPackages with GNU General Public License v3.0 5 votes vote down vote up
@NotNull
@Override
public DataSource<Integer, Result> create() {
    ResultDataSource resultDataSource = new ResultDataSource(this.keywordsParameter,
            this.query,
            this.listRepo,
            this.listArch,
            this.flagged);
    mutableLiveData.postValue(resultDataSource);
    return resultDataSource;
}
 
Example #9
Source File: MovieDataSourceFactory.java    From PopularMovies with MIT License 5 votes vote down vote up
@Override
public DataSource<Integer, Movie> create() {
    MoviePageKeyedDataSource movieDataSource =
            new MoviePageKeyedDataSource(movieService, networkExecutor, sortBy);
    sourceLiveData.postValue(movieDataSource);
    return movieDataSource;
}
 
Example #10
Source File: MovieDataSourceFactory.java    From android-popular-movies-app with Apache License 2.0 5 votes vote down vote up
@Override
public DataSource<Integer, Movie> create() {
    mMovieDataSource = new MovieDataSource(mSortBy);

    // Keep reference to the data source with a MutableLiveData reference
    mPostLiveData = new MutableLiveData<>();
    mPostLiveData.postValue(mMovieDataSource);

    return mMovieDataSource;
}
 
Example #11
Source File: TrackedEntityInstanceQueryCollectionRepository.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public LiveData<PagedList<TrackedEntityInstance>> getPaged(int pageSize) {
    DataSource.Factory<TrackedEntityInstance, TrackedEntityInstance> factory =
            new DataSource.Factory<TrackedEntityInstance, TrackedEntityInstance>() {
                @Override
                public DataSource<TrackedEntityInstance, TrackedEntityInstance> create() {
                    return getDataSource();
                }
            };

    return new LivePagedListBuilder<>(factory, pageSize).build();
}
 
Example #12
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 #13
Source File: CommentDataSourceFactory.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public DataSource create() {
    commentDataSource = new CommentDataSource(retrofit, locale, accessToken, username, sortType,
            areSavedComments);
    commentDataSourceLiveData.postValue(commentDataSource);
    return commentDataSource;
}
 
Example #14
Source File: SubredditListingDataSourceFactory.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public DataSource create() {
    subredditListingDataSource = new SubredditListingDataSource(retrofit, query, sortType);
    subredditListingDataSourceMutableLiveData.postValue(subredditListingDataSource);
    return subredditListingDataSource;
}
 
Example #15
Source File: MessageDataSourceFactory.java    From Infinity-For-Reddit with GNU Affero General Public License v3.0 5 votes vote down vote up
@NonNull
@Override
public DataSource create() {
    messageDataSource = new MessageDataSource(oauthRetrofit, locale, accessToken, where);
    messageDataSourceLiveData.postValue(messageDataSource);
    return messageDataSource;
}
 
Example #16
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 #17
Source File: ReadOnlyCollectionRepositoryImpl.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Handy method to use in conjunction with PagedListAdapter to build paged lists.
 *
 * @param pageSize Length of the page
 * @return A LiveData object of PagedList of elements
 */
@Override
public LiveData<PagedList<M>> getPaged(int pageSize) {
    DataSource.Factory<M, M> factory = new DataSource.Factory<M, M>() {
        @Override
        public DataSource<M, M> create() {
            return getDataSource();
        }
    };

    return new LivePagedListBuilder<>(factory, pageSize).build();
}
 
Example #18
Source File: RoomTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT id, method, url, path, host, scheme, request_date, error, response_code, took_ms, request_content_length, response_content_length, request_body_is_plain_text, response_body_is_plain_text FROM HttpTransaction WHERE protocol LIKE :endWildCard OR method LIKE :endWildCard OR url LIKE :doubleWildCard OR request_body LIKE :doubleWildCard OR response_code LIKE :endWildCard ORDER BY id DESC")
abstract DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactionsIncludeRequest(String endWildCard, String doubleWildCard);
 
Example #19
Source File: TransactionListViewModel.java    From Gander with Apache License 2.0 4 votes vote down vote up
public TransactionListViewModel(Application application) {
    super(application);
    mTransactionDao = Gander.getGanderStorage().getTransactionDao();
    DataSource.Factory<Integer, HttpTransactionUIHelper> factory = mTransactionDao.getAllTransactions().map(HttpTransactionUIHelper.HTTP_TRANSACTION_UI_HELPER_FUNCTION);
    mTransactions = new LivePagedListBuilder<>(factory, config).build();
}
 
Example #20
Source File: RoomTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT id, method, url, path, host, scheme, request_date, error, response_code, took_ms, request_content_length, response_content_length, request_body_is_plain_text, response_body_is_plain_text FROM HttpTransaction WHERE protocol LIKE :endWildCard OR method LIKE :endWildCard OR url LIKE :doubleWildCard OR response_code LIKE :endWildCard ORDER BY id DESC")
abstract DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactions(String endWildCard, String doubleWildCard);
 
Example #21
Source File: PersistentTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@Override
public DataSource.Factory<Integer, HttpTransaction> getAllTransactions() {
    return roomTransactionDao.getAllTransactions().map(PERSISTENT_TO_DATA_TRANSACTION_FUNCTION);
}
 
Example #22
Source File: Monarchy.java    From realm-monarchy with Apache License 2.0 4 votes vote down vote up
@Override
public final DataSource<Integer, T> create() {
    RealmTiledDataSource<T> dataSource = new RealmTiledDataSource<>(monarchy, pagedLiveResults);
    pagedLiveResults.setDataSource(dataSource);
    return dataSource;
}
 
Example #23
Source File: TrackedEntityInstanceQueryCollectionRepository.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DataSource<TrackedEntityInstance, TrackedEntityInstance> getDataSource() {
    return new TrackedEntityInstanceQueryDataSource(store, onlineCallFactory, scope, childrenAppenders);
}
 
Example #24
Source File: ReadOnlyCollectionRepositoryImpl.java    From dhis2-android-sdk with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public DataSource<M, M> getDataSource() {
    return new RepositoryDataSource<>(store, scope, childrenAppenders);
}
 
Example #25
Source File: ObjectBoxRandomDataSource.java    From Hentoid with Apache License 2.0 4 votes vote down vote up
@NonNull
public DataSource<Integer, I> create() {
    return new ObjectBoxRandomDataSource<>(query);
}
 
Example #26
Source File: FirebaseDataSource.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public DataSource<String, DataSnapshot> create() {
    return new FirebaseDataSource(mQuery);
}
 
Example #27
Source File: FirestoreDataSource.java    From FirebaseUI-Android with Apache License 2.0 4 votes vote down vote up
@Override
@NonNull
public DataSource<PageKey, DocumentSnapshot> create() {
    return new FirestoreDataSource(mQuery, mSource);
}
 
Example #28
Source File: SampleDataSource.java    From AdapterDelegates with Apache License 2.0 4 votes vote down vote up
@Override
public DataSource<Integer, DisplayableItem> create() {
    return new SampleDataSource();
}
 
Example #29
Source File: RoomTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT id, method, url, path, host, scheme, request_date, error, response_code, took_ms, request_content_length, response_content_length, request_body_is_plain_text, response_body_is_plain_text FROM HttpTransaction WHERE protocol LIKE :endWildCard OR method LIKE :endWildCard OR url LIKE :doubleWildCard OR response_body LIKE :doubleWildCard OR response_message LIKE :doubleWildCard OR response_code LIKE :endWildCard ORDER BY id DESC")
abstract DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactionsIncludeResponse(String endWildCard, String doubleWildCard);
 
Example #30
Source File: RoomTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT id, method, url, path, host, scheme, request_date, error, response_code, took_ms, request_content_length, response_content_length, request_body_is_plain_text, response_body_is_plain_text FROM HttpTransaction WHERE protocol LIKE :endWildCard OR method LIKE :endWildCard OR url LIKE :doubleWildCard OR request_body LIKE :doubleWildCard OR response_body LIKE :doubleWildCard OR response_message LIKE :doubleWildCard OR response_code LIKE :endWildCard ORDER BY id DESC")
abstract DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactionsIncludeRequestResponse(String endWildCard, String doubleWildCard);