Java源码示例:com.raizlabs.android.dbflow.list.FlowCursorList

示例1
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());
}
 
示例2
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;
    }
 
示例3
@NonNull
@Override
public FlowCursorList<TModel> cursorList() {
    return new FlowCursorList.Builder<>(getTable())
            .cacheModels(cachingEnabled)
            .modelQueriable(this).build();
}
 
示例4
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;
}
 
示例5
/**
 * @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();