Search in sources :

Example 1 with StatusComments

use of org.aisen.weibo.sina.sinasdk.bean.StatusComments in project AisenWeiBo by wangdan.

the class CommentCacheUtility method addCacheData.

@Override
public void addCacheData(Setting action, Params params, IResult result) {
    if (!AppContext.isLoggedIn())
        return;
    try {
        StatusComments cmts = (StatusComments) result;
        List<StatusComment> newList = new ArrayList<StatusComment>();
        boolean clear = false;
        // 刷新
        if (!TextUtils.isEmpty(params.getParameter("since_id"))) {
            int diff = Math.abs(cmts.getComments().size() - AppSettings.getCommentCount());
            clear = diff <= 3;
        } else // 加载更多
        if (!TextUtils.isEmpty(params.getParameter("max_id"))) {
        } else // 重置
        {
            clear = true;
        }
        Extra extra = getExtra(params, action, AppContext.getAccount().getUser());
        long time = System.currentTimeMillis();
        if (clear) {
            SinaDB.getTimelineDB().deleteAll(extra, StatusComment.class);
            Logger.d(TAG, "清理数据");
        }
        SinaDB.getTimelineDB().insert(extra, cmts.getComments());
        Logger.w(TAG, String.format("写入评论数据,共%d条,共耗时%sms", newList.size(), String.valueOf(System.currentTimeMillis() - time)));
        // 如果是重置数据,刷新缓存时间
        if (!params.containsKey("max_id")) {
            CacheTimeUtils.saveTime(getExtra(params, action, AppContext.getAccount().getUser()).getKey(), AppContext.getAccount().getUser());
        }
    } catch (Exception e) {
    }
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra) ArrayList(java.util.ArrayList) StatusComment(org.aisen.weibo.sina.sinasdk.bean.StatusComment) StatusComments(org.aisen.weibo.sina.sinasdk.bean.StatusComments)

Example 2 with StatusComments

use of org.aisen.weibo.sina.sinasdk.bean.StatusComments in project AisenWeiBo by wangdan.

the class CommentCacheUtility method findCacheData.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IResult findCacheData(Setting action, Params params) {
    if (AppSettings.isDisableCache())
        return null;
    if (!AppContext.isLoggedIn())
        return null;
    try {
        long time = System.currentTimeMillis();
        Extra extra = getExtra(params, action, AppContext.getAccount().getUser());
        List<StatusComment> cmtList = SinaDB.getTimelineDB().select(extra, StatusComment.class);
        if (cmtList.size() > 0) {
            StatusComments cmts = new StatusComments();
            cmts.setFromCache(true);
            cmts.setOutofdate(CacheTimeUtils.isOutofdate(getExtra(params, action, AppContext.getAccount().getUser()).getKey(), AppContext.getAccount().getUser()));
            cmts.setComments(cmtList);
            Logger.w(TAG, String.format("读取缓存耗时%sms", String.valueOf(System.currentTimeMillis() - time)));
            Logger.d(TAG, String.format("返回评论数据%d条, expired = %s", cmts.getComments().size(), String.valueOf(cmts.outofdate())));
            return cmts;
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra) StatusComment(org.aisen.weibo.sina.sinasdk.bean.StatusComment) StatusComments(org.aisen.weibo.sina.sinasdk.bean.StatusComments)

Aggregations

Extra (org.aisen.android.component.orm.extra.Extra)2 StatusComment (org.aisen.weibo.sina.sinasdk.bean.StatusComment)2 StatusComments (org.aisen.weibo.sina.sinasdk.bean.StatusComments)2 ArrayList (java.util.ArrayList)1