Пример #1
0
 public void onItemLoaded(ImageLoaded imageLoaded, Throwable exception) {
   if (DEBUG_DONT_LOAD_IMAGES) {
     return;
   }
   // Make sure we're still pointing to the same message. The list item could have
   // been recycled.
   MessageItem msgItem = mListItem.mMessageItem;
   if (msgItem != null && msgItem.getMessageId() == mMessageId) {
     if (imageLoaded.mIsVideo) {
       mListItem.setVideoThumbnail(null, imageLoaded.mBitmap);
     } else {
       mListItem.setImage(null, imageLoaded.mBitmap);
     }
   }
 }
Пример #2
0
  private void bindCommonMessage() {
    if (mDownloadButton != null) {
      mDownloadButton.setVisibility(View.GONE);
      mDownloadingLabel.setVisibility(View.GONE);
    }
    // Since the message text should be concatenated with the sender's
    // address(or name), I have to display it here instead of
    // displaying it by the Presenter.
    mBodyTextView.setTransformationMethod(HideReturnsTransformationMethod.getInstance());

    boolean isSelf = Sms.isOutgoingFolder(mMessageItem.mBoxId);
    String addr = isSelf ? null : mMessageItem.mAddress;
    updateAvatarView(addr, isSelf);

    // Get and/or lazily set the formatted message from/on the
    // MessageItem.  Because the MessageItem instances come from a
    // cache (currently of size ~50), the hit rate on avoiding the
    // expensive formatMessage() call is very high.
    CharSequence formattedMessage = mMessageItem.getCachedFormattedMessage();
    if (formattedMessage == null) {
      formattedMessage =
          formatMessage(
              mMessageItem,
              mMessageItem.mContact,
              mMessageItem.mBody,
              mMessageItem.mSubject,
              mMessageItem.mHighlight,
              mMessageItem.mTextContentType);
      mMessageItem.setCachedFormattedMessage(formattedMessage);
    }
    mBodyTextView.setText(formattedMessage);

    // Debugging code to put the URI of the image attachment in the body of the list item.
    if (DEBUG) {
      String debugText = null;
      if (mMessageItem.mSlideshow == null) {
        debugText = "NULL slideshow";
      } else {
        SlideModel slide = ((SlideshowModel) mMessageItem.mSlideshow).get(0);
        if (slide == null) {
          debugText = "NULL first slide";
        } else if (!slide.hasImage()) {
          debugText = "Not an image";
        } else {
          debugText = slide.getImage().getUri().toString();
        }
      }
      mBodyTextView.setText(mPosition + ": " + debugText);
    }

    // If we're in the process of sending a message (i.e. pending), then we show a "SENDING..."
    // string in place of the timestamp.
    mDateView.setText(
        mMessageItem.isSending()
            ? mContext.getResources().getString(R.string.sending_message)
            : mMessageItem.mTimestamp);

    if (mMessageItem.isSms()) {
      showMmsView(false);
      mMessageItem.setOnPduLoaded(null);
    } else {
      if (DEBUG) {
        Log.v(
            TAG,
            "bindCommonMessage for item: "
                + mPosition
                + " "
                + mMessageItem.toString()
                + " mMessageItem.mAttachmentType: "
                + mMessageItem.mAttachmentType);
      }
      if (mMessageItem.mAttachmentType != WorkingMessage.TEXT) {
        setImage(null, null);
        setOnClickListener(mMessageItem);
        drawPlaybackButton(mMessageItem);
      } else {
        showMmsView(false);
      }
      if (mMessageItem.mSlideshow == null) {
        mMessageItem.setOnPduLoaded(
            new MessageItem.PduLoadedCallback() {
              public void onPduLoaded(MessageItem messageItem) {
                if (DEBUG) {
                  Log.v(
                      TAG,
                      "PduLoadedCallback in MessageListItem for item: "
                          + mPosition
                          + " "
                          + (mMessageItem == null ? "NULL" : mMessageItem.toString())
                          + " passed in item: "
                          + (messageItem == null ? "NULL" : messageItem.toString()));
                }
                if (messageItem != null
                    && mMessageItem != null
                    && messageItem.getMessageId() == mMessageItem.getMessageId()) {
                  mMessageItem.setCachedFormattedMessage(null);
                  bindCommonMessage();
                }
              }
            });
      } else {
        if (mPresenter == null) {
          mPresenter =
              PresenterFactory.getPresenter(
                  "MmsThumbnailPresenter", mContext, this, mMessageItem.mSlideshow);
        } else {
          mPresenter.setModel(mMessageItem.mSlideshow);
          mPresenter.setView(this);
        }
        if (mImageLoadedCallback == null) {
          mImageLoadedCallback = new ImageLoadedCallback(this);
        } else {
          mImageLoadedCallback.reset(this);
        }
        mPresenter.present(mImageLoadedCallback);
      }
    }
    drawRightStatusIndicator(mMessageItem);

    requestLayout();
  }