Ejemplo n.º 1
0
 public int compare(final Message m1, final Message m2) {
   final Date d1 = m1 == null ? EARLY : m1.getSentDate() != null ? m1.getSentDate() : EARLY;
   final Date d2 = m2 == null ? EARLY : m2.getSentDate() != null ? m2.getSentDate() : EARLY;
   return d1.compareTo(d2);
 }
Ejemplo n.º 2
0
  public void populate(final Message message, final Account account) throws MessagingException {
    final Contacts contacts = K9.showContactName() ? mContacts : null;
    final CharSequence from = Address.toFriendly(message.getFrom(), contacts);
    final CharSequence to =
        Address.toFriendly(message.getRecipients(Message.RecipientType.TO), contacts);
    final CharSequence cc =
        Address.toFriendly(message.getRecipients(Message.RecipientType.CC), contacts);

    Address[] fromAddrs = message.getFrom();
    Address[] toAddrs = message.getRecipients(Message.RecipientType.TO);
    Address[] ccAddrs = message.getRecipients(Message.RecipientType.CC);
    boolean fromMe = mMessageHelper.toMe(account, fromAddrs);

    String counterpartyAddress = null;
    if (fromMe) {
      if (toAddrs.length > 0) {
        counterpartyAddress = toAddrs[0].getAddress();
      } else if (ccAddrs.length > 0) {
        counterpartyAddress = ccAddrs[0].getAddress();
      }
    } else if (fromAddrs.length > 0) {
      counterpartyAddress = fromAddrs[0].getAddress();
    }

    /*
     * Only reset visibility of the subject if populate() was called because a new
     * message is shown. If it is the same, do not force the subject visible, because
     * this breaks the MessageTitleView in the action bar, which may hide our subject
     * if it fits in the action bar but is only called when a new message is shown
     * or the device is rotated.
     */
    if (mMessage == null || mMessage.getId() != message.getId()) {
      mSubjectView.setVisibility(VISIBLE);
    }

    mMessage = message;
    mAccount = account;

    if (K9.showContactPicture()) {
      mContactBadge.setVisibility(View.VISIBLE);
      mContactsPictureLoader = new ContactPictureLoader(mContext, R.drawable.ic_contact_picture);
    } else {
      mContactBadge.setVisibility(View.GONE);
    }

    final String subject = message.getSubject();
    if (StringUtils.isNullOrEmpty(subject)) {
      mSubjectView.setText(mContext.getText(R.string.general_no_subject));
    } else {
      mSubjectView.setText(subject);
    }
    mSubjectView.setTextColor(0xff000000 | defaultSubjectColor);

    String dateTime =
        DateUtils.formatDateTime(
            mContext,
            message.getSentDate().getTime(),
            DateUtils.FORMAT_SHOW_DATE
                | DateUtils.FORMAT_ABBREV_ALL
                | DateUtils.FORMAT_SHOW_TIME
                | DateUtils.FORMAT_SHOW_YEAR);
    mDateView.setText(dateTime);

    if (K9.showContactPicture()) {
      mContactBadge.assignContactFromEmail(counterpartyAddress, true);
      if (counterpartyAddress != null) {
        mContactsPictureLoader.loadContactPicture(counterpartyAddress, mContactBadge);
      } else {
        mContactBadge.setImageResource(R.drawable.ic_contact_picture);
      }
    }

    mFromView.setText(from);

    updateAddressField(mToView, to, mToLabel);
    updateAddressField(mCcView, cc, mCcLabel);
    mAnsweredIcon.setVisibility(message.isSet(Flag.ANSWERED) ? View.VISIBLE : View.GONE);
    mForwardedIcon.setVisibility(message.isSet(Flag.FORWARDED) ? View.VISIBLE : View.GONE);
    mFlagged.setChecked(message.isSet(Flag.FLAGGED));

    int chipColor = mAccount.getChipColor();
    int chipColorAlpha = (!message.isSet(Flag.SEEN)) ? 255 : 127;
    mChip.setBackgroundColor(chipColor);
    mChip.getBackground().setAlpha(chipColorAlpha);

    setVisibility(View.VISIBLE);

    if (mSavedState != null) {
      if (mSavedState.additionalHeadersVisible) {
        showAdditionalHeaders();
      }
      mSavedState = null;
    } else {
      hideAdditionalHeaders();
    }
  }