Search in sources :

Example 6 with StatusContent

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

the class SinaSDK method searchsResultStatuss.

/**
	 * H5接口搜索微博
	 *
	 * @param q
	 * @param page
	 * @param cookies
	 * @return
	 * @throws TaskException
	 */
public ArrayList<StatusContent> searchsResultStatuss(String q, int page, String cookies) throws TaskException {
    ArrayList<StatusContent> resultUsers = new ArrayList<>();
    Setting action = newSetting("searchsResultUsers", "page/pageJson", "获取用户");
    action.getExtras().put(BASE_URL, newSettingExtra(BASE_URL, "http://m.weibo.cn/", ""));
    Params params = new Params();
    params.addParameter("containerid", "100103type%3D2%26q%3D" + q + "&page=" + page);
    try {
        String response = doGet(getHttpConfig(), action, params, String.class);
        JSONObject responseJSON = JSONObject.parseObject(response);
        int ok = responseJSON.getInteger("ok");
        if (ok == 1) {
            JSONArray cardsArray = responseJSON.getJSONArray("cards");
            for (int i = 0; i < cardsArray.size(); i++) {
                JSONObject cardGroupsObject = cardsArray.getJSONObject(i);
                JSONArray cardGroupArray = cardGroupsObject.getJSONArray("card_group");
                for (int j = 0; j < cardGroupArray.size(); j++) {
                    JSONObject cardGroup = cardGroupArray.getJSONObject(j);
                    JSONObject mblogObject = cardGroup.getJSONObject("mblog");
                    StatusContent content = JSON.parseObject(mblogObject.toJSONString(), StatusContent.class);
                    // 图片
                    if (mblogObject.containsKey("pics")) {
                        JSONArray picsArray = mblogObject.getJSONArray("pics");
                        if (picsArray != null && picsArray.size() > 0) {
                            PicUrls picUrls = new PicUrls();
                            picUrls.setThumbnail_pic(picsArray.getJSONObject(0).getString("url"));
                            content.setPic_urls(new PicUrls[] { picUrls });
                        }
                    }
                    // 把Html5文本转换一下
                    content.setText(Html.fromHtml(content.getText()).toString());
                    if (content.getRetweeted_status() != null) {
                        content.getRetweeted_status().setText(Html.fromHtml(content.getRetweeted_status().getText()).toString());
                    }
                    // 把时间转换一下
                    try {
                        Calendar calendar = Calendar.getInstance();
                        int year = calendar.get(Calendar.YEAR);
                        SimpleDateFormat format = new SimpleDateFormat("MM-dd HH:mm");
                        calendar.setTimeInMillis(format.parse(content.getCreated_at()).getTime());
                        calendar.set(Calendar.YEAR, year);
                        content.setCreated_at(calendar.getTimeInMillis() + "");
                    } catch (ParseException e) {
                        try {
                            SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                            content.setCreated_at(format.parse(content.getCreated_at()).getTime() + "");
                        } catch (ParseException ewe) {
                        }
                    }
                    resultUsers.add(content);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        if (e instanceof TaskException) {
            throw (TaskException) e;
        }
    }
    return resultUsers;
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) Setting(org.aisen.android.common.setting.Setting) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) JSONArray(com.alibaba.fastjson.JSONArray) Params(org.aisen.android.network.http.Params) ParseException(java.text.ParseException) TaskException(org.aisen.android.network.task.TaskException) JSONObject(com.alibaba.fastjson.JSONObject) PicUrls(org.aisen.weibo.sina.sinasdk.bean.PicUrls) TaskException(org.aisen.android.network.task.TaskException) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat)

Example 7 with StatusContent

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

the class TimelinePhotosItemView method onBindData.

@Override
public void onBindData(View convertView, StatusContent data, int position) {
    this.data = data;
    // username
    if (data.getUser() != null) {
        txtName.setText(AisenUtils.getUserScreenName(data.getUser()));
    }
    txtName.setOnClickListener(this);
    // 转自
    if (data.getRetweeted_status() != null) {
        txtDesc.setVisibility(View.VISIBLE);
        if (data.getRetweeted_status().getUser() != null) {
            txtDesc.setText(String.format(GlobalContext.getInstance().getResources().getString(R.string.timeline_feature_repost), AisenUtils.getUserScreenName(data.getRetweeted_status().getUser())));
        }
    } else {
        txtDesc.setVisibility(View.GONE);
    }
    // pictures
    StatusContent s = data.getRetweeted_status() != null ? data.getRetweeted_status() : data;
    layPicturs.setPics(s, fragment);
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent)

Example 8 with StatusContent

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

the class MentionCmtItemView method onBindData.

@Override
public void onBindData(View convertView, StatusComment data, int position) {
    WeiBoUser user = data.getUser();
    if (user != null) {
        BitmapLoader.getInstance().display(fragment, AisenUtils.getUserPhoto(user), imgPhoto, ImageConfigUtils.getLargePhotoConfig());
        bizFragment.userShow(imgPhoto, user);
        txtName.setText(AisenUtils.getUserScreenName(user));
    } else {
        bizFragment.userShow(imgPhoto, null);
        txtName.setText(R.string.error_cmts);
        imgPhoto.setImageResource(R.drawable.user_placeholder);
    }
    txtContent.setContent(AisenUtils.getCommentText(data.getText()));
    AisenUtils.setTextSize(txtContent);
    String createAt = AisenUtils.convDate(data.getCreated_at());
    String from = String.format("%s", Html.fromHtml(data.getSource()));
    String desc = String.format("%s %s", createAt, from);
    txtDesc.setText(desc);
    // 源评论
    if (data.getReply_comment() != null) {
        layRe.setVisibility(View.VISIBLE);
        txtReContent.setContent(AisenUtils.getCommentText(data.getReply_comment().getText()));
        AisenUtils.setTextSize(txtReContent);
        if (data.getReply_comment().getUser() != null) {
            BitmapLoader.getInstance().display(fragment, AisenUtils.getUserPhoto(data.getReply_comment().getUser()), imgRePhoto, ImageConfigUtils.getLargePhotoConfig());
            bizFragment.userShow(imgRePhoto, data.getReply_comment().getUser());
        } else {
            bizFragment.userShow(imgRePhoto, null);
        }
    } else {
        layRe.setVisibility(View.GONE);
    }
    if (layStatus != null) {
        if (data.getStatus() != null) {
            layDivider.setVisibility(View.VISIBLE);
            layStatus.setVisibility(View.VISIBLE);
            layStatus.setTag(data.getStatus());
            layStatus.setOnClickListener(this);
            txtStatusContent.setContent(data.getStatus().getText());
            AisenUtils.setTextSize(txtStatusContent);
            String image = null;
            // 先取微博的第一张图
            StatusContent status = data.getStatus();
            if (status != null && status.getRetweeted_status() != null)
                status = status.getRetweeted_status();
            if (status == null || status.getPic_urls() == null || status.getPic_urls().length == 0) {
            } else {
                image = status.getPic_urls()[0].getThumbnail_pic();
            }
            // 没图就取头像
            if (TextUtils.isEmpty(image) && status.getUser() != null) {
                image = status.getUser().getAvatar_large();
            }
            if (!TextUtils.isEmpty(image)) {
                imgView.setVisibility(View.VISIBLE);
                ImageConfig config = new ImageConfig();
                config.setId("comments");
                config.setLoadfaildRes(R.drawable.bg_timeline_loading);
                config.setLoadingRes(R.drawable.bg_timeline_loading);
                config.setMaxWidth(300);
                config.setMaxHeight(300);
                config.setBitmapCompress(TimelineThumbBitmapCompress.class);
                BitmapLoader.getInstance().display(fragment, image, imgView, config);
            } else {
                imgView.setVisibility(View.GONE);
            }
            bizFragment.bindOnTouchListener(txtStatusContent);
        } else {
            layDivider.setVisibility(View.GONE);
            layStatus.setVisibility(View.GONE);
        }
    }
    if (btnMenus != null) {
        btnMenus.setTag(data);
        btnMenus.setOnClickListener(this);
    }
}
Also used : ImageConfig(org.aisen.android.component.bitmaploader.core.ImageConfig) StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) WeiBoUser(org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)

Example 9 with StatusContent

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

the class SinaSDK method statusesUpload.

/**
	 * 发表带图片的微博。必须用POST方式提交pic参数,且Content-Type必须设置为multipart/form-data。图片大小<5M。
	 * <p>
	 * 图片格式定义为png<br>
	 * 
	 * @param status
	 *            (true)要发布的微博文本内容。
	 * @param pic
	 *            (true)要上传的图片数据。仅支持JPEG、GIF、PNG格式,为空返回400错误。图片大小<5M。
	 * @param lat
	 *            (false)纬度。有效范围:-90.0到+90.0,+表示北纬。
	 * @param long (false)经度。有效范围:-180.0到+180.0,+表示东经。
	 * @return
	 */
public StatusContent statusesUpload(Params params, File file) throws TaskException {
    MultipartFile[] files = file == null ? null : new MultipartFile[] { new MultipartFile("image/jpge", "pic", file) };
    StatusContent s = doPostFiles(getHttpConfig(), getSetting("statusesUpload"), null, params, files, StatusContent.class);
    //		tempFile.delete();
    return s;
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent)

Example 10 with StatusContent

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

the class TimelineItemView method onClick.

@Override
public void onClick(View v) {
    // 查看转发微博信息
    if (v.getId() == R.id.layRe) {
        StatusContent reContent = (StatusContent) v.getTag();
        TimelineDetailPagerFragment.launch(fragment.getActivity(), reContent);
    } else // 转发
    if (v.getId() == R.id.btnRepost) {
        StatusContent status = (StatusContent) v.getTag();
        bizFragment.statusRepost(status);
    } else // 评论
    if (v.getId() == R.id.btnCmt) {
        StatusContent status = (StatusContent) v.getTag();
        bizFragment.commentCreate(status);
    } else // 点赞
    if (v.getId() == R.id.btnLike) {
        StatusContent status = (StatusContent) v.getTag();
        LikeBean likeBean = DoLikeAction.likeCache.get(status.getId() + "");
        boolean like = likeBean == null || !likeBean.isLiked();
        v.findViewById(R.id.imgLike).setSelected(like);
        bizFragment.doLike(status, like, v, this);
    } else // 溢出菜单
    if (v.getId() == R.id.btnMenus) {
        final String[] timelineMenuArr = GlobalContext.getInstance().getResources().getStringArray(R.array.timeline_menus);
        final StatusContent status = (StatusContent) v.getTag();
        List<String> menuList = new ArrayList<String>();
        if (status.getRetweeted_status() != null && status.getRetweeted_status().getUser() != null)
            menuList.add(timelineMenuArr[0]);
        //			menuList.add(timelineMenuArr[3]);
        //			if (status.getVisible() == null || "0".equals(status.getVisible().getType()))
        //				menuList.add(timelineMenuArr[2]);
        menuList.add(timelineMenuArr[4]);
        menuList.add(timelineMenuArr[5]);
        menuList.add(timelineMenuArr[1]);
        if (status.getUser() != null && status.getUser().getIdstr().equals(AppContext.getAccount().getUser().getIdstr()))
            menuList.add(timelineMenuArr[6]);
        if (fragment instanceof MentionTimelineFragment)
            menuList.add(timelineMenuArr[7]);
        final String[] menus = new String[menuList.size()];
        for (int i = 0; i < menuList.size(); i++) menus[i] = menuList.get(i);
        AisenUtils.showMenuDialog(fragment, v, menus, new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog, int which) {
                AisenUtils.timelineMenuSelected(fragment, menus[which], status);
            }
        });
    }
}
Also used : StatusContent(org.aisen.weibo.sina.sinasdk.bean.StatusContent) DialogInterface(android.content.DialogInterface) ArrayList(java.util.ArrayList) MentionTimelineFragment(org.aisen.weibo.sina.ui.fragment.mention.MentionTimelineFragment) LikeBean(org.aisen.weibo.sina.support.bean.LikeBean)

Aggregations

StatusContent (org.aisen.weibo.sina.sinasdk.bean.StatusContent)15 WeiBoUser (org.aisen.weibo.sina.sinasdk.bean.WeiBoUser)6 DialogInterface (android.content.DialogInterface)3 ArrayList (java.util.ArrayList)3 ImageConfig (org.aisen.android.component.bitmaploader.core.ImageConfig)2 Extra (org.aisen.android.component.orm.extra.Extra)2 TaskException (org.aisen.android.network.task.TaskException)2 PicUrls (org.aisen.weibo.sina.sinasdk.bean.PicUrls)2 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 JSONArray (com.alibaba.fastjson.JSONArray)1 JSONObject (com.alibaba.fastjson.JSONObject)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Calendar (java.util.Calendar)1 List (java.util.List)1 Setting (org.aisen.android.common.setting.Setting)1 Params (org.aisen.android.network.http.Params)1 ARecycleViewItemView (org.aisen.android.ui.fragment.adapter.ARecycleViewItemView)1