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;
}
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());
}
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;
}
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));
}
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;
}
Aggregations