Search in sources :

Example 1 with WeiBoUser

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

the class SinaSDK method userShow.

/**
 * 按用户ID或昵称返回用户资料以及用户的最新发布的一条微博消息。<br>
 * <br>
 *
 * @param uid
 *            (true):必须设置
 * @param screenName
 *            (false):微博昵称,主要是用来区分用户UID跟微博昵称,当二者一样而产生歧义的时候,建议使用该参数
 * @return
 */
public WeiBoUser userShow(String uid, String screenName) throws TaskException {
    Params params = new Params();
    if (!TextUtils.isEmpty(uid))
        params.addParameter("uid", uid);
    if (!TextUtils.isEmpty(screenName))
        params.addParameter("screen_name", screenName);
    params.setEncodeAble(false);
    WeiBoUser user = doGet(getSetting("usershow"), configParams(params), WeiBoUser.class);
    if (user != null) {
        // Sina真的是有毛病啊
        if (!TextUtils.isEmpty(user.getDescription()) && user.getDescription().toLowerCase().endsWith("-weibo")) {
            user.setDescription(user.getDescription().substring(0, user.getDescription().length() - 6));
        }
        if (!TextUtils.isEmpty(user.getVerified_reason()) && user.getVerified_reason().toLowerCase().endsWith("-weibo")) {
            user.setVerified_reason(user.getVerified_reason().substring(0, user.getVerified_reason().length() - 6));
        }
    }
    return user;
}
Also used : WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) Params(org.aisen.android.network.http.Params)

Example 2 with WeiBoUser

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

the class FriendDB method findCacheData.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
public IResult findCacheData(Setting action, Params params) {
    if (params.containsKey("uid")) {
        if (!params.getParameter("uid").equals(AppContext.getAccount().getUser().getIdstr()))
            return null;
    } else if (params.containsKey("screen_name")) {
        if (!params.getParameter("screen_name").equals(AppContext.getAccount().getUser().getScreen_name()))
            return null;
    }
    List<WeiBoUser> userList = selectAll();
    if (userList.size() > 0) {
        Friendship users = new Friendship();
        users.setUsers(userList);
        users.setFromCache(true);
        users.setOutofdate(CacheTimeUtils.isOutofdate("Friends", AppContext.getAccount().getUser()));
        users.setNext_cursor(ActivityHelper.getIntShareData(GlobalContext.getInstance(), "Friends" + AppContext.getAccount().getUser().getIdstr(), 0));
        return users;
    }
    return null;
}
Also used : Friendship(org.aisen.weibo.sina.sinasdk.bean.Friendship) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)

Example 3 with WeiBoUser

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

the class CommentsHotHttpUtility method parseResponse.

@Override
protected <T> T parseResponse(String resultStr, Class<T> responseCls) throws TaskException {
    try {
        JSONArray jsonArray = JSONArray.parseArray(resultStr);
        StatusComments comments = new StatusComments();
        comments.setComments(new ArrayList<StatusComment>());
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            if (jsonObject.containsKey("card_group")) {
                JSONArray card_group = jsonObject.getJSONArray("card_group");
                for (int j = 0; j < card_group.size(); j++) {
                    try {
                        JSONObject card = card_group.getJSONObject(j);
                        StatusComment comment = new StatusComment();
                        comment.setId(card.getString("id"));
                        comment.setText(Html.fromHtml(card.getString("text")).toString());
                        comment.setCreated_at(card.getString("created_at"));
                        comment.setSource(card.getString("source"));
                        comment.setLikedCount(card.getLong("like_counts"));
                        comment.setLiked(card.getBoolean("liked"));
                        JSONObject user = card.getJSONObject("user");
                        comment.setUser(new WeiBoUser());
                        comment.getUser().setInfoAll(false);
                        comment.getUser().setId(user.getString("id"));
                        comment.getUser().setScreen_name(user.getString("screen_name"));
                        comment.getUser().setProfile_image_url(user.getString("profile_image_url"));
                        comments.getComments().add(comment);
                    } catch (Exception e) {
                        Logger.printExc(CommentsHotHttpUtility.class, e);
                    }
                }
            }
        }
        return (T) comments;
    } catch (Exception e) {
        throw new TaskException(TaskException.TaskError.resultIllegal.toString());
    }
}
Also used : JSONObject(com.alibaba.fastjson.JSONObject) TaskException(org.aisen.android.network.task.TaskException) JSONArray(com.alibaba.fastjson.JSONArray) StatusComment(org.aisen.weibo.sina.sinasdk.bean.StatusComment) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) StatusComments(org.aisen.weibo.sina.sinasdk.bean.StatusComments) TaskException(org.aisen.android.network.task.TaskException)

Example 4 with WeiBoUser

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

the class BizFragment method destoryFollower.

/* 结束查看用户好友列表 */
// XXX /*开始移除粉丝*/
public void destoryFollower(final WeiBoUser user, final OnDestoryFollowerCallback callback) {
    Token token = AppContext.getAccount().getAccessToken();
    if (AppContext.getAccount().getAdvancedToken() != null)
        token = AppContext.getAccount().getAdvancedToken();
    final Token trueToken = token;
    new MaterialDialog.Builder(getRealActivity()).title(R.string.title_destory_friend).content(R.string.biz_destory_follower).negativeText(R.string.cancel).positiveText(R.string.confirm).onPositive(new MaterialDialog.SingleButtonCallback() {

        @Override
        public void onClick(@NonNull MaterialDialog dialog, @NonNull DialogAction which) {
            new WorkTask<Void, Void, WeiBoUser>() {

                @Override
                public WeiBoUser workInBackground(Void... params) throws TaskException {
                    return SinaSDK.getInstance(trueToken).friendshipsFollowersDestory(user.getIdstr());
                }

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

                @Override
                protected void onFailure(TaskException exception) {
                    super.onFailure(exception);
                    showMessage(exception.getMessage());
                }

                @Override
                protected void onSuccess(WeiBoUser result) {
                    super.onSuccess(result);
                    if (getRealActivity() != null)
                        callback.onDestoryFollower(result);
                }

                @Override
                protected void onFinished() {
                    super.onFinished();
                    ViewUtils.dismissProgressDialog();
                }
            }.execute();
        }
    }).show();
}
Also used : MaterialDialog(com.afollestad.materialdialogs.MaterialDialog) TaskException(org.aisen.android.network.task.TaskException) DialogAction(com.afollestad.materialdialogs.DialogAction) NonNull(android.support.annotation.NonNull) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) Token(org.aisen.weibo.sina.sinasdk.bean.Token)

Example 5 with WeiBoUser

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

the class BizFragment method commentDestory.

// XXX /*删除评论*/
/* 删除评论 */
public void commentDestory(final StatusComment commnet, final OnCommentDestoryCallback callback) {
    final WeiBoUser user = AppContext.getAccount().getUser();
    new WorkTask<Void, Void, StatusComment>() {

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

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

        protected void onSuccess(StatusComment result) {
            super.onSuccess(result);
            if (getRealActivity() == null) {
                return;
            }
            if (callback != null)
                callback.onCommentDestory(commnet);
            showMessage(R.string.delete_success);
            // 删除成功后,DB同时也删除
            SinaDB.getTimelineDB().deleteById(new Extra(user.getIdstr(), null), StatusComment.class, result.getId());
        }

        protected void onFailure(TaskException exception) {
            super.onFailure(exception);
            if (getRealActivity() == null) {
                return;
            }
            if (!TextUtils.isEmpty(exception.getMessage()))
                showMessage(exception.getMessage());
            else
                showMessage(R.string.delete_faild);
        }

        @Override
        public StatusComment workInBackground(Void... params) throws TaskException {
            return SinaSDK.getInstance(AppContext.getAccount().getAccessToken()).commentsDestory(commnet.getId());
        }
    }.execute();
}
Also used : Extra(org.aisen.android.component.orm.extra.Extra) TaskException(org.aisen.android.network.task.TaskException) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser) StatusComment(org.aisen.weibo.sina.sinasdk.bean.StatusComment)

Aggregations

WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)21 TaskException (org.aisen.android.network.task.TaskException)8 StatusContent (org.aisen.weibo.sina.sinasdk.bean.StatusContent)6 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)4 View (android.view.View)3 ImageView (android.widget.ImageView)3 TextView (android.widget.TextView)3 Friendship (org.aisen.weibo.sina.sinasdk.bean.Friendship)3 Token (org.aisen.weibo.sina.sinasdk.bean.Token)3 Bitmap (android.graphics.Bitmap)2 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 NonNull (android.support.annotation.NonNull)2 LayoutInflater (android.view.LayoutInflater)2 FrameLayout (android.widget.FrameLayout)2 DialogAction (com.afollestad.materialdialogs.DialogAction)2 MaterialDialog (com.afollestad.materialdialogs.MaterialDialog)2 FadeInDisplayer (org.aisen.android.component.bitmaploader.display.FadeInDisplayer)2 Extra (org.aisen.android.component.orm.extra.Extra)2 StatusComment (org.aisen.weibo.sina.sinasdk.bean.StatusComment)2 Intent (android.content.Intent)1