Esempio n. 1
0
  public MsgDetailReadWorker(WeiboDetailImageView view, MessageBean msg) {
    this.view = view;
    this.pb = this.view.getProgressBar();
    this.msg = msg;
    this.retry = view.getRetryButton();
    retry.setVisibility(View.INVISIBLE);

    oriPath =
        FileManager.getFilePathFromUrl(msg.getOriginal_pic(), FileLocationMethod.picture_large);

    if (ImageUtility.isThisBitmapCanRead(oriPath)
        && TaskCache.isThisUrlTaskFinished(msg.getOriginal_pic())) {

      onPostExecute(oriPath);
      cancel(true);
      return;
    }

    middlePath =
        FileManager.getFilePathFromUrl(msg.getBmiddle_pic(), FileLocationMethod.picture_bmiddle);

    if (ImageUtility.isThisBitmapCanRead(middlePath)
        && TaskCache.isThisUrlTaskFinished(msg.getBmiddle_pic())) {
      onPostExecute(middlePath);
      cancel(true);
      return;
    }

    pb.setVisibility(View.VISIBLE);
    pb.setIndeterminate(true);
  }
  /**
   * 1. this message has repost's message 2. this message is an original message
   *
   * <p>if this message has repost's message,try to include its content, if total word number above
   * 140,discard current msg content
   */
  private ItemBean repost() throws WeiboException {

    String content = ((EditText) findViewById(R.id.status_new_content)).getText().toString();

    if (msg.getRetweeted_status() != null) {
      String msgContent = "//@" + msg.getUser().getScreen_name() + ": " + msg.getText();
      String total = content + msgContent;
      if (total.length() < 140) {
        content = total;
      }
    }

    RepostNewMsgDao dao = new RepostNewMsgDao(token, msg.getId());

    boolean comment = true;
    boolean oriComment = enableCommentOri.isChecked();

    if (comment && oriComment) {
      dao.setIs_comment(RepostNewMsgDao.ENABLE_COMMENT_ALL);
    } else if (comment) {
      dao.setIs_comment(RepostNewMsgDao.ENABLE_COMMENT);
    } else if (oriComment) {
      dao.setIs_comment(RepostNewMsgDao.ENABLE_ORI_COMMENT);
    }

    dao.setStatus(content);

    return dao.sendNewMsg();
  }
  private PendingIntent getPendingIntent(
      Intent clickToOpenAppPendingIntentInner, Parcelable itemBean, AccountBean accountBean) {
    clickToOpenAppPendingIntentInner.setExtrasClassLoader(getClass().getClassLoader());

    UnreadTabIndex unreadTabIndex = UnreadTabIndex.NONE;

    if (itemBean instanceof MessageBean) {
      unreadTabIndex = UnreadTabIndex.MENTION_WEIBO;
    } else if (itemBean instanceof CommentBean) {
      CommentBean commentBean = (CommentBean) itemBean;
      MessageBean messageBean = commentBean.getStatus();
      if (messageBean != null) {
        UserBean userBean = messageBean.getUser();
        if (accountBean.getInfo().equals(userBean)) {
          unreadTabIndex = UnreadTabIndex.COMMENT_TO_ME;
        } else {
          unreadTabIndex = UnreadTabIndex.MENTION_COMMENT;
        }
      } else {
        unreadTabIndex = UnreadTabIndex.MENTION_COMMENT;
      }
    }
    clickToOpenAppPendingIntentInner.putExtra(
        BundleArgsConstants.OPEN_NAVIGATION_INDEX_EXTRA, unreadTabIndex);
    PendingIntent pendingIntent =
        PendingIntent.getActivity(
            getBaseContext(),
            getMentionsWeiboNotificationId(accountBean),
            clickToOpenAppPendingIntentInner,
            PendingIntent.FLAG_UPDATE_CURRENT);
    return pendingIntent;
  }
 private RefreshReCmtCountTask(
     FriendsTimeLineFragment friendsTimeLineFragment, MessageListBean data) {
   fragmentWeakReference = new WeakReference<FriendsTimeLineFragment>(friendsTimeLineFragment);
   msgIds = new ArrayList<String>();
   List<MessageBean> msgList = data.getItemList();
   for (MessageBean msg : msgList) {
     if (msg != null) {
       msgIds.add(msg.getId());
     }
   }
 }
 @Override
 public boolean onPrepareOptionsMenu(Menu menu) {
   if (msg != null && msg.getRetweeted_status() != null) {
     enableCommentOri.setVisible(true);
   }
   return super.onPrepareOptionsMenu(menu);
 }
  private void updateTimeLineMessageCommentAndRepostData(List<MessageReCmtCountBean> value) {

    if (getList().getSize() <= value.size()) {
      return;
    }

    for (int i = 0; i < value.size(); i++) {
      MessageBean msg = getList().getItem(i);
      MessageReCmtCountBean count = value.get(i);
      if (msg != null && msg.getId().equals(count.getId())) {
        msg.setReposts_count(count.getReposts());
        msg.setComments_count(count.getComments());
      }
    }
    getAdapter().notifyDataSetChanged();
    FriendsTimeLineDBTask.asyncReplace(getList(), accountBean.getUid(), currentGroupId);
  }
  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    getActionBar().setTitle(R.string.comments);
    getActionBar().setSubtitle(GlobalContext.getInstance().getCurrentAccountName());

    token = getIntent().getStringExtra("token");
    if (TextUtils.isEmpty(token)) token = GlobalContext.getInstance().getSpecialToken();

    msg = (MessageBean) getIntent().getSerializableExtra("msg");
    if (msg == null) {
      commentDraftBean = (CommentDraftBean) getIntent().getSerializableExtra("draft");
      msg = commentDraftBean.getMessageBean();
      getEditTextView().setText(commentDraftBean.getContent());
    }

    getEditTextView().setHint("@" + msg.getUser().getScreen_name() + ":" + msg.getText());
  }
Esempio n. 8
0
  @Override
  protected String doInBackground(Void... arg) {
    if (isCancelled()) {
      return null;
    }

    if (Utility.isWifi(GlobalContext.getInstance())) {
      boolean result =
          TaskCache.waitForPictureDownload(
              msg.getOriginal_pic(), downloadListener, oriPath, FileLocationMethod.picture_large);
      return result ? oriPath : null;
    } else {
      boolean result =
          TaskCache.waitForPictureDownload(
              msg.getBmiddle_pic(),
              downloadListener,
              middlePath,
              FileLocationMethod.picture_bmiddle);
      return result ? middlePath : null;
    }
  }
  @Override
  protected ItemBean sendData() throws WeiboException {
    if (!enableRepost.isChecked()) {
      CommentNewMsgDao dao =
          new CommentNewMsgDao(
              token,
              msg.getId(),
              ((EditText) findViewById(R.id.status_new_content)).getText().toString());
      if (enableCommentOri.isChecked()) {
        dao.enableComment_ori(true);
      } else {
        dao.enableComment_ori(false);
      }

      return dao.sendNewMsg();
    } else {
      return repost();
    }
  }
 @Override
 public void onActivityResult(int requestCode, int resultCode, Intent data) {
   // use Up instead of Back to reach this fragment
   if (data == null) {
     return;
   }
   final MessageBean msg = (MessageBean) data.getParcelableExtra("msg");
   if (msg != null) {
     for (int i = 0; i < getList().getSize(); i++) {
       if (msg.equals(getList().getItem(i))) {
         MessageBean ori = getList().getItem(i);
         if (ori.getComments_count() != msg.getComments_count()
             || ori.getReposts_count() != msg.getReposts_count()) {
           ori.setReposts_count(msg.getReposts_count());
           ori.setComments_count(msg.getComments_count());
           FriendsTimeLineDBTask.asyncUpdateCount(
               msg.getId(), msg.getComments_count(), msg.getReposts_count());
           getAdapter().notifyDataSetChanged();
         }
         break;
       }
     }
   }
 }
  private void buildRepostContent(
      MessageBean msg, final MessageBean repost_msg, ViewHolder holder, int position) {
    holder.repost_content.setVisibility(View.VISIBLE);
    if (!repost_msg.getId().equals((String) holder.repost_content.getTag())) {
      boolean haveCachedHeight = oriMsgHeights.get(msg.getIdLong()) != null;
      ViewGroup.LayoutParams layoutParams = holder.repost_content.getLayoutParams();
      if (haveCachedHeight) {
        layoutParams.height = oriMsgHeights.get(msg.getIdLong());
      } else {
        layoutParams.height = ViewGroup.LayoutParams.WRAP_CONTENT;
      }

      boolean haveCachedWidth = oriMsgWidths.get(msg.getIdLong()) != null;
      if (haveCachedWidth) {
        layoutParams.width = oriMsgWidths.get(msg.getIdLong());
      } else {
        layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT;
      }

      holder.repost_content.requestLayout();
      holder.repost_content.setText(repost_msg.getListViewSpannableString());

      if (!haveCachedHeight) {
        oriMsgHeights.append(msg.getIdLong(), layoutParams.height);
      }

      if (!haveCachedWidth) {
        oriMsgWidths.append(msg.getIdLong(), layoutParams.width);
      }

      holder.repost_content.setText(repost_msg.getListViewSpannableString());
      holder.repost_content.setTag(repost_msg.getId());
    }

    if (repost_msg.havePicture()) {
      if (repost_msg.isMultiPics()) {
        buildMultiPic(repost_msg, holder.repost_content_pic_multi);
      } else {
        buildPic(repost_msg, holder.repost_content_pic, position);
      }
    }
  }
  @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, f**k 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);
      }
    }
  }