Search in sources :

Example 11 with Extra

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

the class TimelineCacheUtility method addCacheData.

@Override
public void addCacheData(Setting action, Params params, IResult responseObj) {
    // 如果是离线请求,忽略数据缓存
    if (action.getExtras() != null && action.getExtras().containsKey("offline_action"))
        return;
    // 如果是用户微博
    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;
        }
    }
    try {
        StatusContents statusContents = (StatusContents) responseObj;
        if (statusContents.getStatuses().size() == 0)
            return;
        boolean clear = false;
        // 刷新
        if (!TextUtils.isEmpty(params.getParameter("since_id"))) {
            int diff = Math.abs(statusContents.getStatuses().size() - AppSettings.getTimelineCount());
            clear = diff <= 3;
        } else // 加载更多
        if (!TextUtils.isEmpty(params.getParameter("max_id"))) {
        } else // 重置
        {
            clear = true;
        }
        Extra extra = new Extra(AppContext.getAccount().getUser().getId(), getCacheKey(action, params));
        if (clear) {
            SinaDB.getTimelineDB().deleteAll(extra, StatusContent.class);
            Logger.d(TAG, "清理数据");
        }
        long time = System.currentTimeMillis();
        SinaDB.getTimelineDB().insert(extra, statusContents.getStatuses());
        Logger.w(TAG, String.format("写入微博数据,共%d条,共耗时%sms", statusContents.getStatuses().size(), String.valueOf(System.currentTimeMillis() - time)));
        CacheTimeUtils.saveTime(getCacheKey(action, params), AppContext.getAccount().getUser());
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra) StatusContents(org.aisen.weibo.sina.sinasdk.bean.StatusContents)

Example 12 with Extra

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

the class PublishDB method deletePublish.

public static void deletePublish(PublishBean bean, WeiBoUser user) {
    Extra extra = new Extra(user.getIdstr(), null);
    SinaDB.getDB().deleteById(extra, PublishBean.class, bean.getId());
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra)

Example 13 with Extra

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

the class PublishDB method updatePublish.

public static void updatePublish(PublishBean bean, WeiBoUser user) {
    Extra extra = new Extra(user.getIdstr(), null);
    SinaDB.getDB().insertOrReplace(extra, bean);
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra)

Example 14 with Extra

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

the class OfflineSettingsFragment method onPreferenceClick.

@Override
public boolean onPreferenceClick(Preference preference) {
    if (preference.getKey().equals("pOfflineGroups")) {
        final List<Group> groups = SinaDB.getOfflineSqlite().select(new Extra(AppContext.getAccount().getUser().getIdstr(), null), Group.class);
        OfflineUtils.showOfflineGroupsModifyDialog(getActivity(), groups, new OfflineUtils.OnOfflineGroupSetCallback() {

            @Override
            public void onChanged(List<Group> newGroups) {
                SinaDB.getOfflineSqlite().deleteAll(OfflineUtils.getLoggedExtra(null), Group.class);
                if (newGroups == null || newGroups.size() == 0) {
                } else {
                    SinaDB.getOfflineSqlite().insertOrReplace(OfflineUtils.getLoggedExtra(null), newGroups);
                }
                setGroupsSummary();
            }
        }, R.string.offline_groups_dialog);
    }
    return true;
}
Also used : Group(org.aisen.weibo.sina.sinasdk.bean.Group) Extra(org.aisen.android.component.orm.extra.Extra) OfflineUtils(org.aisen.weibo.sina.support.utils.OfflineUtils)

Example 15 with Extra

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

the class BizFragment method statusDestory.

/* 结束回复评论 */
// XXX /*删除微博*/
/* 开始删除微博 */
public void statusDestory(final String id, final OnStatusDestoryCallback callback) {
    final WeiBoUser user = AppContext.getAccount().getUser();
    new WorkTask<String, Void, StatusContent>() {

        protected void onPrepare() {
            super.onPrepare();
            ViewUtils.createProgressDialog(getRealActivity(), getRealString(R.string.biz_delete_status_loading), ThemeUtils.getThemeColor()).show();
        }

        ;

        protected void onFinished() {
            super.onFinished();
            ViewUtils.dismissProgressDialog();
        }

        ;

        protected void onSuccess(StatusContent result) {
            super.onSuccess(result);
            if (getRealActivity() == null) {
                return;
            }
            callback.onStatusDestory(result);
            showMessage(R.string.delete_success);
            SinaDB.getTimelineDB().deleteById(new Extra(user.getIdstr(), null), StatusContent.class, result.getId());
        }

        ;

        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            if (getRealActivity() == null) {
                return;
            }
            if (exception != null && "20101".equals(exception.getMessage())) {
                StatusContent status = new StatusContent();
                status.setId(Long.parseLong(id));
                onSuccess(status);
            } else if (!callback.onFaild(exception)) {
                showMessage(exception.getMessage());
            }
        }

        ;

        @Override
        public StatusContent workInBackground(String... params) throws TaskException {
            return SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).statusDestroy(params[0]);
        }
    }.execute(id);
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) Extra(org.aisen.android.component.orm.extra.Extra) TaskException(org.aisen.android.network.task.TaskException) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)

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