示例#1
0
  @Override
  protected boolean isUserDataChanged() {
    if (currentMessageObject == null) {
      return false;
    }

    int uid = currentMessageObject.messageOwner.media.user_id;
    boolean newDrawAdd =
        contactUser != null
            && uid != UserConfig.getClientUserId()
            && ContactsController.getInstance().contactsDict.get(uid) == null;
    if (newDrawAdd != drawAddButton) {
      return true;
    }

    contactUser =
        MessagesController.getInstance().getUser(currentMessageObject.messageOwner.media.user_id);

    TLRPC.FileLocation newPhoto = null;
    if (contactUser != null && contactUser.photo != null) {
      newPhoto = contactUser.photo.photo_small;
    }

    return currentPhoto == null && newPhoto != null
        || currentPhoto != null && newPhoto == null
        || currentPhoto != null
            && newPhoto != null
            && (currentPhoto.local_id != newPhoto.local_id
                || currentPhoto.volume_id != newPhoto.volume_id)
        || super.isUserDataChanged();
  }
  private void createActionBarMenu() {
    ActionBarMenu menu = actionBarLayer.createMenu();
    menu.clearItems();

    if (ContactsController.getInstance().contactsDict.get(user_id) == null) {
      TLRPC.User user = MessagesController.getInstance().users.get(user_id);
      if (user == null) {
        return;
      }
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      if (user.phone != null && user.phone.length() != 0) {
        item.addSubItem(
            add_contact, LocaleController.getString("AddContact", R.string.AddContact), 0);
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      } else {
        item.addSubItem(
            block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      }
    } else {
      ActionBarMenuItem item = menu.addItem(0, R.drawable.ic_ab_other);
      item.addSubItem(
          share_contact, LocaleController.getString("ShareContact", R.string.ShareContact), 0);
      item.addSubItem(
          block_contact, LocaleController.getString("BlockContact", R.string.BlockContact), 0);
      item.addSubItem(
          edit_contact, LocaleController.getString("EditContact", R.string.EditContact), 0);
      item.addSubItem(
          delete_contact, LocaleController.getString("DeleteContact", R.string.DeleteContact), 0);
    }
  }
示例#3
0
  @Override
  public void setMessageObject(MessageObject messageObject) {
    if (currentMessageObject != messageObject || isUserDataChanged()) {

      int uid = messageObject.messageOwner.media.user_id;
      contactUser = MessagesController.getInstance().getUser(uid);

      drawAddButton =
          contactUser != null
              && uid != UserConfig.getClientUserId()
              && ContactsController.getInstance().contactsDict.get(uid) == null;

      int maxWidth;
      if (AndroidUtilities.isTablet()) {
        maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
      } else {
        maxWidth =
            (int) (Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) * 0.7f);
      }
      maxWidth -= AndroidUtilities.dp(58 + (drawAddButton ? 42 : 0));

      if (contactUser != null) {
        if (contactUser.photo != null) {
          currentPhoto = contactUser.photo.photo_small;
        } else {
          currentPhoto = null;
        }
        avatarDrawable.setInfo(contactUser);
      } else {
        currentPhoto = null;
        avatarDrawable.setInfo(uid, null, null, false);
      }
      avatarImage.setImage(currentPhoto, "50_50", avatarDrawable, null, false);

      String currentNameString =
          ContactsController.formatName(
              messageObject.messageOwner.media.first_name,
              messageObject.messageOwner.media.last_name);
      int nameWidth = Math.min((int) Math.ceil(namePaint.measureText(currentNameString)), maxWidth);

      CharSequence stringFinal =
          TextUtils.ellipsize(
              currentNameString.replace("\n", " "), namePaint, nameWidth, TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              stringFinal, namePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
      if (nameLayout.getLineCount() > 0) {
        nameWidth = (int) Math.ceil(nameLayout.getLineWidth(0));
      } else {
        nameWidth = 0;
      }

      String phone = messageObject.messageOwner.media.phone_number;
      if (phone != null && phone.length() != 0) {
        if (!phone.startsWith("+")) {
          phone = "+" + phone;
        }
        phone = PhoneFormat.getInstance().format(phone);
      } else {
        phone = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
      }
      int phoneWidth = Math.min((int) Math.ceil(phonePaint.measureText(phone)), maxWidth);
      stringFinal =
          TextUtils.ellipsize(
              phone.replace("\n", " "), phonePaint, phoneWidth, TextUtils.TruncateAt.END);
      phoneLayout =
          new StaticLayout(
              stringFinal,
              phonePaint,
              phoneWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      if (phoneLayout.getLineCount() > 0) {
        phoneWidth = (int) Math.ceil(phoneLayout.getLineWidth(0));
      } else {
        phoneWidth = 0;
      }

      namesWidth = Math.max(nameWidth, phoneWidth);
      backgroundWidth = AndroidUtilities.dp(77 + (drawAddButton ? 42 : 0)) + namesWidth;

      super.setMessageObject(messageObject);
    }
  }