com.raizlabs.android.dbflow.list.FlowCursorList Java Examples

The following examples show how to use com.raizlabs.android.dbflow.list.FlowCursorList. 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: ContentDatabaseCache.java    From iview-android-tv with MIT License 6 votes vote down vote up
private List<EpisodeBaseModel> getModelsOfType(Class<?> model, String type, List<EpisodeBaseModel> existing, boolean uniqueSeries) {
    FlowCursorList<EpisodeBaseModel> cursor = new FlowCursorList<>(false, EpisodeBaseModel.class,
            Condition.column(EpisodeBaseModel$Table.DATA_TYPE).eq(type));
    Map<String, EpisodeBaseModel> all = new HashMap<>();
    for (int i = 0, k = cursor.getCount(); i < k; i++) {
        EpisodeBaseModel ep = (EpisodeBaseModel) createInstanceOf(model);
        if (ep != null) {
            int index = existing.indexOf(ep);
            if (index > -1) {
                ep = existing.get(index);
            } else {
                EpisodeBaseModel item = cursor.getItem(i);
                item.unserialize();
                ep.merge(item);
            }
            if (uniqueSeries) {
                all.put(ep.getSeriesTitle(), ep);
            } else {
                all.put(ep.getHref(), ep);
            }
        }
    }
    cursor.close();
    return new ArrayList<>(all.values());
}
 
Example #2
Source File: ContentManagerBase.java    From iview-android-tv with MIT License 6 votes vote down vote up
public List<EpisodeBaseModel> getRecentlyPlayed() {

        FlowCursorList<PlayHistory> cursor = new FlowCursorList<>(false,
                (new Select()).from(PlayHistory.class)
                        .orderBy("CASE WHEN "+PlayHistory$Table.PROGRESS+" >= 75 THEN 1 ELSE 0 END ASC, "+PlayHistory$Table.TIMESTAMP+" DESC")
                        .limit(30));

        List<EpisodeBaseModel> recent = new ArrayList<>();
        for (int i = 0, k = cursor.getCount(); i < k; i++) {
            PlayHistory history = cursor.getItem(i);
            EpisodeBaseModel ep = getEpisode(history.href);
            if (ep != null) {
                if (history.progress < 75) {
                    ep.setResumePosition(history.position);
                }
                ep.setRecent(true);
                recent.add(ep);
            }
        }
        return recent;
    }
 
Example #3
Source File: BaseModelQueriable.java    From Meteorite with Apache License 2.0 5 votes vote down vote up
@NonNull
@Override
public FlowCursorList<TModel> cursorList() {
    return new FlowCursorList.Builder<>(getTable())
            .cacheModels(cachingEnabled)
            .modelQueriable(this).build();
}
 
Example #4
Source File: ContentDatabaseCache.java    From iview-android-tv with MIT License 5 votes vote down vote up
private LinkedHashMap<String, List<EpisodeBaseModel>> getCollections(Class<?> model, List<EpisodeBaseModel> existing) {
    LinkedHashMap<String, List<EpisodeBaseModel>> collections = new LinkedHashMap<>();
    FlowCursorList<EpisodeBaseModel> cursor = new FlowCursorList<>(false,
            (new Select()).from(EpisodeBaseModel.class)
                    .where(Condition.column(EpisodeBaseModel$Table.DATA_TYPE).eq(TYPE_COLLECTIONS))
                    .orderBy(true, EpisodeBaseModel$Table.DATA_COLLECTION_INDEX));
    for (int i = 0, k = cursor.getCount(); i < k; i++) {
        EpisodeBaseModel item = cursor.getItem(i);
        item.unserialize();
        int index = existing.indexOf(item);
        EpisodeBaseModel ep;
        if (index > -1) {
            ep = existing.get(index);
        } else {
            ep = (EpisodeBaseModel) createInstanceOf(model);
            if (ep != null) {
                ep.merge(item);
            }
        }
        if (ep != null) {
            if (!collections.containsKey(item.DATA_COLLECTION_KEY)) {
                collections.put(item.DATA_COLLECTION_KEY, new ArrayList<EpisodeBaseModel>());
            }
            collections.get(item.DATA_COLLECTION_KEY).add(ep);
        }
    }
    for (Map.Entry<String, List<EpisodeBaseModel>> collection : collections.entrySet()) {
        Log.d(TAG, "Loaded collection: " + collection.getKey() + " => " + collection.getValue().size());
    }
    return collections;
}
 
Example #5
Source File: ModelQueriable.java    From Meteorite with Apache License 2.0 2 votes vote down vote up
/**
 * @return A cursor-backed list that handles conversion, retrieval, and caching of lists. Can
 * cache models dynamically by setting {@link FlowCursorList#setCacheModels(boolean)} to true.
 */
@NonNull
FlowCursorList<TModel> cursorList();