Search in sources :

Example 6 with Extra

use of org.aisen.android.component.orm.extra.Extra 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)

Example 7 with Extra

use of org.aisen.android.component.orm.extra.Extra in project AisenWeiBo by wangdan.

the class JokesCacheUtility method addCacheData.

@Override
public void addCacheData(Setting action, Params params, IResult result) {
    long id = Long.parseLong(params.getParameter("id"));
    int type = Integer.parseInt(params.getParameter("mode"));
    String direction = params.getParameter("direction");
    JokeBeans beans = (JokeBeans) result;
    if (id == 0 || ("down".equalsIgnoreCase(direction) && beans.getData().getContents().size() >= 20)) {
        SinaDB.getDB().deleteAll(new Extra(null, String.valueOf(type)), JokeBean.class);
    }
    CacheTimeUtils.saveTime("Jokes" + type, null);
    SinaDB.getDB().insert(new Extra(null, String.valueOf(type)), beans.getData().getContents());
}
Also used : JokeBeans(org.aisen.weibo.sina.support.bean.JokeBeans) Extra(org.aisen.android.component.orm.extra.Extra)

Example 8 with Extra

use of org.aisen.android.component.orm.extra.Extra in project AisenWeiBo by wangdan.

the class TimelineCacheUtility method findCacheData.

@Override
public IResult findCacheData(Setting action, Params params) {
    if (AppSettings.isDisableCache())
        return null;
    if (!AppContext.isLoggedIn())
        return null;
    // 如果是用户微博,只返回用户的微博
    if (action.getValue().equals("statuses/user_timeline.json")) {
        // 是当前登录用户
        if (params.containsKey("user_id") && params.getParameter("user_id").equals(AppContext.getAccount().getUser().getIdstr())) {
        } else if (params.containsKey("screen_name") && params.getParameter("screen_name").equals(AppContext.getAccount().getUser().getScreen_name())) {
        } else {
            return null;
        }
    }
    try {
        long time = System.currentTimeMillis();
        Extra extra = new Extra(AppContext.getAccount().getUser().getId(), getCacheKey(action, params));
        List<StatusContent> statusList = SinaDB.getTimelineDB().select(extra, StatusContent.class);
        if (statusList.size() > 0) {
            StatusContents statusContents = new StatusContents();
            statusContents.setFromCache(true);
            statusContents.setOutofdate(CacheTimeUtils.isOutofdate(getCacheKey(action, params), AppContext.getAccount().getUser()));
            statusContents.setStatuses(statusList);
            Logger.w(TAG, String.format("读取缓存耗时%sms", String.valueOf(System.currentTimeMillis() - time)));
            Logger.d(TAG, String.format("返回微博数据%d条, expired = %s", statusContents.getStatuses().size(), String.valueOf(statusContents.isOutofdate())));
            return statusContents;
        }
    } catch (Exception e) {
    }
    return null;
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) Extra(org.aisen.android.component.orm.extra.Extra) StatusContents(org.aisen.weibo.sina.sinasdk.bean.StatusContents)

Example 9 with Extra

use of org.aisen.android.component.orm.extra.Extra in project AisenWeiBo by wangdan.

the class OfflineSettingsFragment method setGroupsSummary.

private void setGroupsSummary() {
    List<Group> groups = SinaDB.getOfflineSqlite().select(new Extra(AppContext.getAccount().getUser().getIdstr(), null), Group.class);
    String summary = "";
    if (groups.size() == 0) {
        summary = getString(R.string.offline_none_groups) + ",";
    } else {
        for (Group group : groups) {
            summary = summary + group.getName() + ",";
        }
    }
    pOfflineGroups.setSummary(summary.substring(0, summary.length() - 1));
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) Extra(org.aisen.android.component.orm.extra.Extra)

Example 10 with Extra

use of org.aisen.android.component.orm.extra.Extra in project AisenWeiBo by wangdan.

the class CommentCacheUtility method getExtra.

public static Extra getExtra(Params params, Setting action, WeiBoUser user) {
    String key = null;
    // 提及的评论
    if (action.getValue().equals("comments/mentions.json"))
        key = action.getDescription() + ":" + action.getValue() + ":" + params.getParameter("filter_by_author");
    else
        // 我发出的、我收到的
        key = action.getDescription() + ":" + action.getValue() + ":all";
    Extra extra = new Extra(user.getIdstr(), KeyGenerator.generateMD5(key));
    return extra;
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra)

Aggregations

Extra (org.aisen.android.component.orm.extra.Extra)15 TaskException (org.aisen.android.network.task.TaskException)3 Group (org.aisen.weibo.sina.sinasdk.bean.Group)3 StatusComment (org.aisen.weibo.sina.sinasdk.bean.StatusComment)3 StatusComments (org.aisen.weibo.sina.sinasdk.bean.StatusComments)2 StatusContent (org.aisen.weibo.sina.sinasdk.bean.StatusContent)2 StatusContents (org.aisen.weibo.sina.sinasdk.bean.StatusContents)2 WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)2 DialogInterface (android.content.DialogInterface)1 ArrayList (java.util.ArrayList)1 UnreadCountNotifier (org.aisen.weibo.sina.service.notifier.UnreadCountNotifier)1 SetCount (org.aisen.weibo.sina.sinasdk.bean.SetCount)1 UnreadCount (org.aisen.weibo.sina.sinasdk.bean.UnreadCount)1 JokeBeans (org.aisen.weibo.sina.support.bean.JokeBeans)1 OfflineUtils (org.aisen.weibo.sina.support.utils.OfflineUtils)1