Search in sources :

Example 16 with MessageBean

use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.

the class MyStatusDBTask method add.

public static void add(MessageListBean list, String accountId) {
    if (list == null || list.getSize() == 0) {
        return;
    }
    Gson gson = new Gson();
    List<MessageBean> msgList = list.getItemList();
    DatabaseUtils.InsertHelper ih = new DatabaseUtils.InsertHelper(getWsd(), MyStatusTable.StatusDataTable.TABLE_NAME);
    final int mblogidColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.MBLOGID);
    final int accountidColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.ACCOUNTID);
    final int jsondataColumn = ih.getColumnIndex(MyStatusTable.StatusDataTable.JSONDATA);
    try {
        getWsd().beginTransaction();
        for (int i = 0; i < msgList.size(); i++) {
            MessageBean msg = msgList.get(i);
            ih.prepareForInsert();
            if (msg != null) {
                ih.bind(mblogidColumn, msg.getId());
                ih.bind(accountidColumn, accountId);
                String json = gson.toJson(msg);
                ih.bind(jsondataColumn, json);
            } else {
                ih.bind(mblogidColumn, "-1");
                ih.bind(accountidColumn, accountId);
                ih.bind(jsondataColumn, "");
            }
            ih.execute();
        }
        getWsd().setTransactionSuccessful();
    } catch (SQLException e) {
    } finally {
        getWsd().endTransaction();
        ih.close();
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) SQLException(android.database.SQLException) DatabaseUtils(android.database.DatabaseUtils) Gson(com.google.gson.Gson)

Example 17 with MessageBean

use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.

the class StatusListAdapter method bindViewData.

@Override
protected void bindViewData(final ViewHolder holder, int position) {
    Drawable drawable = bg.get(holder);
    if (drawable != null) {
        holder.listview_root.setBackgroundDrawable(drawable);
    } else {
        drawable = holder.listview_root.getBackground();
        bg.put(holder, drawable);
    }
    if (listView.getCheckedItemPosition() == position + listView.getHeaderViewsCount()) {
        holder.listview_root.setBackgroundColor(checkedBG);
    }
    final MessageBean msg = bean.get(position);
    UserBean user = msg.getUser();
    if (user != null) {
        holder.username.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(user.getRemark())) {
            holder.username.setText(new StringBuilder(user.getScreen_name()).append("(").append(user.getRemark()).append(")").toString());
        } else {
            holder.username.setText(user.getScreen_name());
        }
        if (!showOriStatus && !SettingUtility.getEnableCommentRepostListAvatar()) {
            holder.avatar.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
        } else {
            buildAvatar(holder.avatar, position, user);
        }
    } else {
        holder.username.setVisibility(View.INVISIBLE);
        holder.avatar.setVisibility(View.INVISIBLE);
    }
    if (!TextUtils.isEmpty(msg.getListViewSpannableString())) {
        boolean haveCachedHeight = msgHeights.get(msg.getIdLong()) != null;
        ViewGroup.LayoutParams layoutParams = holder.content.getLayoutParams();
        if (haveCachedHeight) {
            layoutParams.height = msgHeights.get(msg.getIdLong());
        } else {
            layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        boolean haveCachedWidth = msgWidths.get(msg.getIdLong()) != null;
        if (haveCachedWidth) {
            layoutParams.width = msgWidths.get(msg.getIdLong());
        } else {
            layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
        }
        holder.content.requestLayout();
        holder.content.setText(msg.getListViewSpannableString());
        if (!haveCachedHeight) {
            msgHeights.append(msg.getIdLong(), layoutParams.height);
        }
        if (!haveCachedWidth) {
            msgWidths.append(msg.getIdLong(), layoutParams.width);
        }
    } else {
        TimeLineUtility.addJustHighLightLinks(msg);
        holder.content.setText(msg.getListViewSpannableString());
    }
    holder.time.setTime(msg.getMills());
    if (holder.source != null) {
        holder.source.setText(msg.getSourceString());
    }
    if (showOriStatus) {
        boolean checkRepostsCount = (msg.getReposts_count() != 0);
        boolean checkCommentsCount = (msg.getComments_count() != 0);
        boolean checkPic = msg.havePicture() || (msg.getRetweeted_status() != null && msg.getRetweeted_status().havePicture());
        checkPic = (checkPic && !SettingUtility.isEnablePic());
        boolean checkGps = (msg.getGeo() != null);
        if (!checkRepostsCount && !checkCommentsCount && !checkPic && !checkGps) {
            holder.count_layout.setVisibility(View.INVISIBLE);
        } else {
            holder.count_layout.setVisibility(View.VISIBLE);
            if (checkPic) {
                holder.timeline_pic.setVisibility(View.VISIBLE);
            } else {
                holder.timeline_pic.setVisibility(View.GONE);
            }
            if (checkGps) {
                holder.timeline_gps.setVisibility(View.VISIBLE);
            } else {
                holder.timeline_gps.setVisibility(View.INVISIBLE);
            }
            if (checkRepostsCount) {
                holder.repost_count.setText(String.valueOf(msg.getReposts_count()));
                holder.repost_count.setVisibility(View.VISIBLE);
            } else {
                holder.repost_count.setVisibility(View.GONE);
            }
            if (checkCommentsCount) {
                holder.comment_count.setText(String.valueOf(msg.getComments_count()));
                holder.comment_count.setVisibility(View.VISIBLE);
            } else {
                holder.comment_count.setVisibility(View.GONE);
            }
        }
    }
    holder.repost_content.setVisibility(View.GONE);
    holder.repost_content_pic.setVisibility(View.GONE);
    holder.repost_content_pic_multi.setVisibility(View.GONE);
    holder.content_pic.setVisibility(View.GONE);
    holder.content_pic_multi.setVisibility(View.GONE);
    if (msg.havePicture()) {
        if (msg.isMultiPics()) {
            buildMultiPic(msg, holder.content_pic_multi);
        } else {
            buildPic(msg, holder.content_pic, position);
        }
    }
    MessageBean repost_msg = msg.getRetweeted_status();
    if (repost_msg != null && showOriStatus) {
        if (holder.repost_layout != null) {
            holder.repost_layout.setVisibility(View.VISIBLE);
        }
        holder.repost_flag.setVisibility(View.VISIBLE);
        //sina weibo official account can send repost message with picture, fuck sina weibo
        if (holder.content_pic.getVisibility() != View.GONE) {
            holder.content_pic.setVisibility(View.GONE);
        }
        buildRepostContent(msg, repost_msg, holder, position);
        if (holder.content_pic_multi != holder.repost_content_pic_multi) {
            interruptPicDownload(holder.content_pic_multi);
        }
        if (holder.repost_content_pic != holder.content_pic) {
            interruptPicDownload(holder.repost_content_pic);
        }
    } else {
        if (holder.content_pic_multi != holder.repost_content_pic_multi) {
            interruptPicDownload(holder.repost_content_pic_multi);
        }
        if (holder.repost_content_pic != holder.content_pic) {
            interruptPicDownload(holder.repost_content_pic);
        }
        if (holder.repost_layout != null) {
            holder.repost_layout.setVisibility(View.GONE);
        }
        holder.repost_flag.setVisibility(View.GONE);
    }
    boolean interruptPic = false;
    boolean interruptMultiPic = false;
    boolean interruptRepostPic = false;
    boolean interruptRepostMultiPic = false;
    if (msg.havePicture()) {
        if (msg.isMultiPics()) {
            interruptPic = true;
        } else {
            interruptMultiPic = true;
        }
    }
    if (repost_msg != null && showOriStatus) {
        if (repost_msg.havePicture()) {
            if (repost_msg.isMultiPics()) {
                interruptRepostPic = true;
            } else {
                interruptRepostMultiPic = true;
            }
        }
    }
    if (interruptPic && interruptRepostPic) {
        interruptPicDownload(holder.content_pic);
        interruptPicDownload(holder.repost_content_pic);
    }
    if (interruptMultiPic && interruptRepostMultiPic) {
        interruptPicDownload(holder.content_pic_multi);
        interruptPicDownload(holder.repost_content_pic_multi);
    }
    if (interruptPic && !interruptRepostPic) {
        if (holder.content_pic != holder.repost_content_pic) {
            interruptPicDownload(holder.content_pic);
        }
    }
    if (!interruptPic && interruptRepostPic) {
        if (holder.content_pic != holder.repost_content_pic) {
            interruptPicDownload(holder.repost_content_pic);
        }
    }
    if (interruptMultiPic && !interruptRepostMultiPic) {
        if (holder.content_pic_multi != holder.repost_content_pic_multi) {
            interruptPicDownload(holder.content_pic_multi);
        }
    }
    if (!interruptMultiPic && interruptRepostMultiPic) {
        if (holder.content_pic_multi != holder.repost_content_pic_multi) {
            interruptPicDownload(holder.repost_content_pic_multi);
        }
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) UserBean(org.qii.weiciyuan.bean.UserBean) ViewGroup(android.view.ViewGroup) Drawable(android.graphics.drawable.Drawable) RelativeLayout(android.widget.RelativeLayout)

Example 18 with MessageBean

use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.

the class BrowserWeiboMsgFragment method buildViewData.

public void buildViewData(final boolean refreshPic) {
    layout.avatar.checkVerified(msg.getUser());
    if (msg.getUser() != null) {
        if (TextUtils.isEmpty(msg.getUser().getRemark())) {
            layout.username.setText(msg.getUser().getScreen_name());
        } else {
            layout.username.setText(msg.getUser().getScreen_name() + "(" + msg.getUser().getRemark() + ")");
        }
        TimeLineBitmapDownloader.getInstance().downloadAvatar(layout.avatar.getImageView(), msg.getUser());
    }
    layout.content.setText(msg.getListViewSpannableString());
    layout.content.setOnTouchListener(new ClickableTextViewMentionLinkOnTouchListener());
    layout.time.setText(msg.getTimeInFormat());
    if (msg.getGeo() != null) {
        layout.mapView.setVisibility(View.VISIBLE);
        if (Utility.isTaskStopped(geoTask)) {
            geoTask = new GetWeiboLocationInfoTask(getActivity(), msg.getGeo(), layout.mapView, layout.location);
            geoTask.executeOnExecutor(MyAsyncTask.THREAD_POOL_EXECUTOR);
        }
    } else {
        layout.mapView.setVisibility(View.GONE);
    }
    if (!TextUtils.isEmpty(msg.getSource())) {
        layout.source.setText(Html.fromHtml(msg.getSource()).toString());
    }
    layout.content_pic.setVisibility(View.GONE);
    layout.content_pic_multi.setVisibility(View.GONE);
    //sina weibo official account can send repost message with picture, fuck sina weibo
    if (msg.havePicture() && msg.getRetweeted_status() == null) {
        displayPictures(msg, layout.content_pic_multi, layout.content_pic, refreshPic);
    }
    final MessageBean repostMsg = msg.getRetweeted_status();
    layout.repost_layout.setVisibility(repostMsg != null ? View.VISIBLE : View.GONE);
    if (repostMsg != null) {
        //sina weibo official account can send repost message with picture, fuck sina weibo
        layout.content_pic.setVisibility(View.GONE);
        layout.repost_layout.setVisibility(View.VISIBLE);
        layout.recontent.setVisibility(View.VISIBLE);
        layout.recontent.setOnTouchListener(new ClickableTextViewMentionLinkOnTouchListener());
        if (repostMsg.getUser() != null) {
            layout.recontent.setText(repostMsg.getListViewSpannableString());
            buildRepostCount();
        } else {
            layout.recontent.setText(repostMsg.getListViewSpannableString());
        }
        layout.repost_pic.setVisibility(View.GONE);
        layout.repost_pic_multi.setVisibility(View.GONE);
        if (repostMsg.havePicture()) {
            displayPictures(repostMsg, layout.repost_pic_multi, layout.repost_pic, refreshPic);
        }
    }
    Utility.buildTabCount(commentTab, getString(R.string.comments), msg.getComments_count());
    Utility.buildTabCount(repostTab, getString(R.string.repost), msg.getReposts_count());
    ((BrowserWeiboMsgActivity) getActivity()).updateCommentCount(msg.getComments_count());
    ((BrowserWeiboMsgActivity) getActivity()).updateRepostCount(msg.getReposts_count());
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) ClickableTextViewMentionLinkOnTouchListener(org.qii.weiciyuan.support.lib.ClickableTextViewMentionLinkOnTouchListener)

Example 19 with MessageBean

use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.

the class CommentListAdapter method bindViewData.

@Override
protected void bindViewData(final ViewHolder holder, int position) {
    Drawable drawable = bg.get(holder);
    if (drawable != null) {
        holder.listview_root.setBackgroundDrawable(drawable);
    } else {
        drawable = holder.listview_root.getBackground();
        bg.put(holder, drawable);
    }
    if (listView.getCheckedItemPosition() == position + 1) {
        holder.listview_root.setBackgroundColor(checkedBG);
    }
    final CommentBean comment = getList().get(position);
    UserBean user = comment.getUser();
    if (user != null) {
        holder.username.setVisibility(View.VISIBLE);
        if (!TextUtils.isEmpty(user.getRemark())) {
            holder.username.setText(new StringBuilder(user.getScreen_name()).append("(").append(user.getRemark()).append(")").toString());
        } else {
            holder.username.setText(user.getScreen_name());
        }
        if (!showOriStatus && !SettingUtility.getEnableCommentRepostListAvatar()) {
            holder.avatar.setLayoutParams(new RelativeLayout.LayoutParams(0, 0));
        } else {
            buildAvatar(holder.avatar, position, user);
        }
    } else {
        holder.username.setVisibility(View.INVISIBLE);
        holder.avatar.setVisibility(View.INVISIBLE);
    }
    holder.content.setText(comment.getListViewSpannableString());
    holder.time.setTime(comment.getMills());
    if (holder.source != null) {
        holder.source.setText(comment.getSourceString());
    }
    holder.repost_content.setVisibility(View.GONE);
    holder.repost_content_pic.setVisibility(View.GONE);
    CommentBean reply = comment.getReply_comment();
    if (holder.replyIV != null) {
        holder.replyIV.setVisibility(View.GONE);
    }
    if (reply != null && showOriStatus) {
        if (holder.repost_layout != null) {
            holder.repost_layout.setVisibility(View.VISIBLE);
        }
        holder.repost_flag.setVisibility(View.VISIBLE);
        holder.repost_content.setVisibility(View.VISIBLE);
        holder.repost_content.setText(reply.getListViewSpannableString());
        holder.repost_content.setTag(reply.getId());
    } else {
        MessageBean repost_msg = comment.getStatus();
        if (repost_msg != null && showOriStatus) {
            buildOriWeiboContent(repost_msg, holder, position);
        } else {
            if (holder.repost_layout != null) {
                holder.repost_layout.setVisibility(View.GONE);
            }
            holder.repost_flag.setVisibility(View.GONE);
            if (holder.replyIV != null) {
                holder.replyIV.setVisibility(View.VISIBLE);
                holder.replyIV.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Intent intent = new Intent(getActivity(), WriteReplyToCommentActivity.class);
                        intent.putExtra("token", GlobalContext.getInstance().getSpecialToken());
                        intent.putExtra("msg", comment);
                        getActivity().startActivity(intent);
                    }
                });
            }
        }
    }
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) UserBean(org.qii.weiciyuan.bean.UserBean) WriteReplyToCommentActivity(org.qii.weiciyuan.ui.send.WriteReplyToCommentActivity) Drawable(android.graphics.drawable.Drawable) RelativeLayout(android.widget.RelativeLayout) Intent(android.content.Intent) CommentBean(org.qii.weiciyuan.bean.CommentBean) AbsListView(android.widget.AbsListView) AutoScrollListView(org.qii.weiciyuan.support.lib.AutoScrollListView) View(android.view.View) ListView(android.widget.ListView)

Example 20 with MessageBean

use of org.qii.weiciyuan.bean.MessageBean in project weiciyuan by qii.

the class TimeLineUtility method haveFilterWord.

public static boolean haveFilterWord(MessageBean content, List<String> keywordFilter, List<String> userFilter, List<String> topicFilter, List<String> sourceFilter) {
    //if this message is sent myself, ignore it;
    if (content.getUser().getId().equals(GlobalContext.getInstance().getCurrentAccountId())) {
        return false;
    }
    boolean hasOriMessage = content.getRetweeted_status() != null;
    MessageBean oriMessage = content.getRetweeted_status();
    for (String filterWord : keywordFilter) {
        if (content.getText().contains(filterWord)) {
            return true;
        }
        if (hasOriMessage && oriMessage.getText().contains(filterWord)) {
            return true;
        }
    }
    for (String filterWord : userFilter) {
        if (content.getUser() != null && content.getUser().getScreen_name().equals(filterWord)) {
            return true;
        }
        if (hasOriMessage && oriMessage.getUser() != null && oriMessage.getUser().getScreen_name().equals(filterWord)) {
            return true;
        }
    }
    for (String filterWord : topicFilter) {
        Matcher localMatcher = WeiboPatterns.TOPIC_URL.matcher(content.getText());
        while (localMatcher.find()) {
            String str2 = localMatcher.group(0);
            if (TextUtils.isEmpty(str2) || str2.length() < 3) {
                continue;
            }
            if (filterWord.equals(str2.substring(1, str2.length() - 1))) {
                return true;
            }
        }
        if (content.getRetweeted_status() != null) {
            localMatcher = WeiboPatterns.TOPIC_URL.matcher(content.getRetweeted_status().getText());
            while (localMatcher.find()) {
                String str2 = localMatcher.group(0);
                if (TextUtils.isEmpty(str2) || str2.length() < 3) {
                    continue;
                }
                if (filterWord.equals(str2.substring(1, str2.length() - 1))) {
                    return true;
                }
            }
        }
    }
    for (String filterWord : sourceFilter) {
        if (filterWord.equals(content.getSourceString())) {
            return true;
        }
        if (hasOriMessage && filterWord.equals(content.getRetweeted_status().getSourceString())) {
            return true;
        }
    }
    return false;
}
Also used : MessageBean(org.qii.weiciyuan.bean.MessageBean) Matcher(java.util.regex.Matcher) SpannableString(android.text.SpannableString)

Aggregations

MessageBean (org.qii.weiciyuan.bean.MessageBean)52 Gson (com.google.gson.Gson)21 JsonSyntaxException (com.google.gson.JsonSyntaxException)16 ArrayList (java.util.ArrayList)9 HashMap (java.util.HashMap)8 MessageListBean (org.qii.weiciyuan.bean.MessageListBean)8 Cursor (android.database.Cursor)7 Intent (android.content.Intent)6 CommentBean (org.qii.weiciyuan.bean.CommentBean)6 UserBean (org.qii.weiciyuan.bean.UserBean)6 DatabaseUtils (android.database.DatabaseUtils)4 SQLException (android.database.SQLException)4 View (android.view.View)4 PendingIntent (android.app.PendingIntent)3 Drawable (android.graphics.drawable.Drawable)3 SpannableString (android.text.SpannableString)3 AbsListView (android.widget.AbsListView)3 ListView (android.widget.ListView)3 RelativeLayout (android.widget.RelativeLayout)3 TextView (android.widget.TextView)3