Java Code Examples for androidx.paging.DataSource#Factory

The following examples show how to use androidx.paging.DataSource#Factory . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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 8
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 9
Source File: ThreadAndEmailDao.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Transaction
@Query("select id,receivedAt,preview,email.threadId from thread_item join email on thread_item.emailId=email.id where thread_item.threadId=:threadId order by position")
public abstract DataSource.Factory<Integer, FullEmail> getEmails(String threadId);
 
Example 10
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 11
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 12
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 13
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);
 
Example 14
Source File: RoomTransactionDao.java    From Gander with Apache License 2.0 4 votes vote down vote up
@Query("SELECT * FROM HttpTransaction ORDER BY id DESC")
abstract DataSource.Factory<Integer, PersistentHttpTransaction> getAllTransactions();
 
Example 15
Source File: RoomFileDao.java    From ArchPackages with GNU General Public License v3.0 4 votes vote down vote up
@Query("SELECT * from room_file_table ORDER BY package_name ASC")
DataSource.Factory<Integer, RoomFile> getPagedFiles();
 
Example 16
Source File: DaoMessage.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Transaction
@Query("SELECT message.*" +
        ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
        ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
        ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
        ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
        ", message.`from` AS senders" +
        ", message.`to` AS recipients" +
        ", 1 AS count" +
        ", CASE WHEN message.ui_seen THEN 0 ELSE 1 END AS unseen" +
        ", CASE WHEN message.ui_flagged THEN 0 ELSE 1 END AS unflagged" +
        ", (folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
        ", (message.ui_encrypt IN (2, 4)) AS signed" +
        ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
        ", 1 AS visible" +
        ", NOT message.ui_seen AS visible_unseen" +
        ", message.total AS totalSize" +
        ", message.priority AS ui_priority" +
        ", message.importance AS ui_importance" +
        " FROM message" +
        " JOIN account_view AS account ON account.id = message.account" +
        " LEFT JOIN identity_view AS identity ON identity.id = message.identity" +
        " JOIN folder_view AS folder ON folder.id = message.folder" +
        " WHERE message.account = :account" +
        " AND message.thread = :thread" +
        " AND (:id IS NULL OR message.id = :id)" +
        " AND (NOT :filter_archive OR folder.type <> '" + EntityFolder.ARCHIVE +
        "' OR (SELECT COUNT(m.id) FROM message m" +
        "   WHERE m.account = message.account" +
        "   AND (m.hash = message.hash OR m.msgid = message.msgid)" +
        "   AND NOT m.ui_hide) = 1)" +
        " AND (NOT message.ui_hide OR :debug)" +
        " ORDER BY CASE WHEN :ascending THEN message.received ELSE -message.received END" +
        ", CASE" +
        " WHEN folder.type = '" + EntityFolder.INBOX + "' THEN 1" +
        " WHEN folder.type = '" + EntityFolder.OUTBOX + "' THEN 2" +
        " WHEN folder.type = '" + EntityFolder.DRAFTS + "' THEN 3" +
        " WHEN folder.type = '" + EntityFolder.SENT + "' THEN 4" +
        " WHEN folder.type = '" + EntityFolder.TRASH + "' THEN 5" +
        " WHEN folder.type = '" + EntityFolder.JUNK + "' THEN 6" +
        " WHEN folder.type = '" + EntityFolder.SYSTEM + "' THEN 7" +
        " WHEN folder.type = '" + EntityFolder.USER + "' THEN 8" +
        " WHEN folder.type = '" + EntityFolder.ARCHIVE + "' THEN 9" +
        " ELSE 999 END")
    // The folder type sort order should match the duplicate algorithm
DataSource.Factory<Integer, TupleMessageEx> pagedThread(
        long account, String thread, Long id,
        boolean filter_archive,
        boolean ascending, boolean debug);
 
Example 17
Source File: DaoMessage.java    From FairEmail with GNU General Public License v3.0 4 votes vote down vote up
@Transaction
@SuppressWarnings(RoomWarnings.CURSOR_MISMATCH)
@Query("SELECT message.*" +
        ", account.pop AS accountProtocol, account.name AS accountName, COALESCE(identity.color, folder.color, account.color) AS accountColor" +
        ", account.notify AS accountNotify, account.auto_seen AS accountAutoSeen" +
        ", folder.name AS folderName, folder.color AS folderColor, folder.display AS folderDisplay, folder.type AS folderType, folder.unified AS folderUnified, folder.read_only AS folderReadOnly" +
        ", IFNULL(identity.display, identity.name) AS identityName, identity.email AS identityEmail, identity.synchronize AS identitySynchronize" +
        ", '[' || group_concat(message.`from`, ',') || ']' AS senders" +
        ", '[' || group_concat(message.`to`, ',') || ']' AS recipients" +
        ", COUNT(message.id) AS count" +
        ", SUM(1 - message.ui_seen) AS unseen" +
        ", SUM(1 - message.ui_flagged) AS unflagged" +
        ", SUM(folder.type = '" + EntityFolder.DRAFTS + "') AS drafts" +
        ", (message.ui_encrypt IN (2, 4)) AS signed" +
        ", (message.ui_encrypt IN (1, 3)) AS encrypted" +
        ", COUNT(DISTINCT" +
        "   CASE WHEN NOT message.hash IS NULL THEN message.hash" +
        "   WHEN NOT message.msgid IS NULL THEN message.msgid" +
        "   ELSE message.id END) AS visible" +
        ", COUNT(DISTINCT" +
        "   CASE WHEN message.ui_seen THEN NULL" +
        "   WHEN NOT message.hash IS NULL THEN message.hash" +
        "   WHEN NOT message.msgid IS NULL THEN message.msgid" +
        "   ELSE message.id END) AS visible_unseen" +
        ", SUM(message.total) AS totalSize" +
        ", message.priority AS ui_priority" +
        ", message.importance AS ui_importance" +
        ", MAX(CASE WHEN folder.id = :folder THEN message.received ELSE 0 END) AS dummy" +
        " FROM (SELECT * FROM message" +
        " WHERE message.thread IN" +
        "  (SELECT DISTINCT mm.thread FROM message mm" +
        "   WHERE mm.folder = :folder" +
        "   AND (NOT mm.ui_hide OR :debug)" +
        "   AND (NOT :found OR mm.ui_found))" +
        "   ORDER BY received DESC) AS message" + // group_concat
        " JOIN account_view AS account ON account.id = message.account" +
        " LEFT JOIN identity_view AS identity ON identity.id = message.identity" +
        " JOIN folder_view AS folder ON folder.id = message.folder" +
        " JOIN folder_view AS f ON f.id = :folder" +
        " WHERE (message.account = f.account OR " + is_outbox + ")" +
        " AND (:threading OR folder.id = :folder)" +
        " AND (NOT message.ui_hide OR :debug)" +
        " AND (NOT :found OR message.ui_found = :found)" +
        " GROUP BY CASE WHEN message.thread IS NULL OR NOT :threading THEN message.id ELSE message.thread END" +
        " HAVING (NOT :filter_seen OR SUM(1 - message.ui_seen) > 0 OR " + is_outbox + ")" +
        " AND (NOT :filter_unflagged OR COUNT(message.id) - SUM(1 - message.ui_flagged) > 0 OR " + is_outbox + ")" +
        " AND (NOT :filter_unknown OR SUM(message.avatar IS NOT NULL AND message.sender <> identity.email) > 0" +
        "   OR " + is_outbox + " OR " + is_drafts + " OR " + is_sent + ")" +
        " AND (NOT :filter_snoozed OR message.ui_snoozed IS NULL OR " + is_outbox + " OR " + is_drafts + ")" +
        " AND (:filter_language IS NULL OR SUM(message.language = :filter_language) > 0 OR " + is_outbox + ")" +
        " ORDER BY -IFNULL(message.importance, 1)" +
        ", CASE" +
        "   WHEN 'unread' = :sort THEN SUM(1 - message.ui_seen) = 0" +
        "   WHEN 'starred' = :sort THEN COUNT(message.id) - SUM(1 - message.ui_flagged) = 0" +
        "   WHEN 'priority' = :sort THEN -IFNULL(message.priority, 1)" +
        "   WHEN 'sender' = :sort THEN LOWER(message.sender)" +
        "   WHEN 'subject' = :sort THEN LOWER(message.subject)" +
        "   WHEN 'size' = :sort THEN -SUM(message.total)" +
        "   WHEN 'attachments' = :sort THEN -SUM(message.attachments)" +
        "   WHEN 'snoozed' = :sort THEN SUM(CASE WHEN message.ui_snoozed IS NULL THEN 0 ELSE 1 END) = 0" +
        "   ELSE 0" +
        "  END" +
        ", CASE WHEN :ascending THEN message.received ELSE -message.received END")
DataSource.Factory<Integer, TupleMessageEx> pagedFolder(
        long folder, boolean threading,
        String sort, boolean ascending,
        boolean filter_seen, boolean filter_unflagged, boolean filter_unknown, boolean filter_snoozed, String filter_language,
        boolean found,
        boolean debug);
 
Example 18
Source File: QueryDao.java    From lttrs-android with Apache License 2.0 4 votes vote down vote up
@Transaction
@Query("select query_item.threadId,query_item.emailId from `query` join query_item on `query`.id = query_item.queryId inner join thread on query_item.threadId=thread.threadId where queryString=:queryString  and  query_item.threadId not in (select threadId from query_item_overwrite where queryId=`query`.id) order by position asc")
public abstract DataSource.Factory<Integer, ThreadOverviewItem> getThreadOverviewItems(String queryString);
 
Example 19
Source File: TransactionDao.java    From Gander with Apache License 2.0 votes vote down vote up
DataSource.Factory<Integer, HttpTransaction> getAllTransactions(); 
Example 20
Source File: TransactionDao.java    From Gander with Apache License 2.0 votes vote down vote up
DataSource.Factory<Integer, HttpTransaction> getAllTransactionsWith(String key, SearchType searchType);