public XImageSpan createAndPutChipForUser(TLRPC.User user) {
    LayoutInflater lf =
        (LayoutInflater)
            ApplicationLoader.applicationContext.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
    View textView = lf.inflate(R.layout.group_create_bubble, null);
    TextView text = (TextView) textView.findViewById(R.id.bubble_text_view);
    String name = ContactsController.formatName(user.first_name, user.last_name);
    if (name.length() == 0 && user.phone != null && user.phone.length() != 0) {
      name = PhoneFormat.getInstance().format("+" + user.phone);
    }
    text.setText(name + ", ");

    int spec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
    textView.measure(spec, spec);
    textView.layout(0, 0, textView.getMeasuredWidth(), textView.getMeasuredHeight());
    Bitmap b =
        Bitmap.createBitmap(textView.getWidth(), textView.getHeight(), Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(b);
    canvas.translate(-textView.getScrollX(), -textView.getScrollY());
    textView.draw(canvas);
    textView.setDrawingCacheEnabled(true);
    Bitmap cacheBmp = textView.getDrawingCache();
    Bitmap viewBmp = cacheBmp.copy(Bitmap.Config.ARGB_8888, true);
    textView.destroyDrawingCache();

    final BitmapDrawable bmpDrawable = new BitmapDrawable(b);
    bmpDrawable.setBounds(0, 0, b.getWidth(), b.getHeight());

    SpannableStringBuilder ssb = new SpannableStringBuilder("");
    XImageSpan span = new XImageSpan(bmpDrawable, ImageSpan.ALIGN_BASELINE);
    allSpans.add(span);
    selectedContacts.put(user.id, span);
    for (ImageSpan sp : allSpans) {
      ssb.append("<<");
      ssb.setSpan(
          sp, ssb.length() - 2, ssb.length(), SpannableStringBuilder.SPAN_EXCLUSIVE_EXCLUSIVE);
    }
    userSelectEditText.setText(ssb);
    userSelectEditText.setSelection(ssb.length());
    return span;
  }
 private void updateSubtitle() {
   if (actionBar == null) {
     return;
   }
   if (currentChat != null || currentUser == null) {
     return;
   }
   if (currentUser.id / 1000 != 777
       && currentUser.id / 1000 != 333
       && ContactsController.getInstance().contactsDict.get(currentUser.id) == null
       && (ContactsController.getInstance().contactsDict.size() != 0
           || !ContactsController.getInstance().isLoadingContacts())) {
     if (currentUser.phone != null && currentUser.phone.length() != 0) {
       nameTextView.setText(PhoneFormat.getInstance().format("+" + currentUser.phone));
     } else {
       nameTextView.setText(
           ContactsController.formatName(currentUser.first_name, currentUser.last_name));
     }
   } else {
     nameTextView.setText(
         ContactsController.formatName(currentUser.first_name, currentUser.last_name));
   }
   CharSequence printString =
       MessagesController.getInstance().printingStrings.get(currentMessageObject.getDialogId());
   if (printString == null || printString.length() == 0) {
     lastPrintString = null;
     setTypingAnimation(false);
     TLRPC.User user = MessagesController.getInstance().getUser(currentUser.id);
     if (user != null) {
       currentUser = user;
     }
     onlineTextView.setText(LocaleController.formatUserStatus(currentUser));
   } else {
     lastPrintString = printString;
     onlineTextView.setText(printString);
     setTypingAnimation(true);
   }
 }
  public void buildLayout() {
    CharSequence nameString;
    TextPaint currentNamePaint;

    drawNameBroadcast = false;
    drawNameLock = false;
    drawNameGroup = false;
    drawCheck = false;
    drawNameBot = false;

    if (encryptedChat != null) {
      drawNameLock = true;
      dialog_id = ((long) encryptedChat.id) << 32;
      if (!LocaleController.isRTL) {
        nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        nameLeft =
            AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                + lockDrawable.getIntrinsicWidth();
      } else {
        nameLockLeft =
            getMeasuredWidth()
                - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                - lockDrawable.getIntrinsicWidth();
        nameLeft = AndroidUtilities.dp(11);
      }
      nameLockTop = AndroidUtilities.dp(16.5f);
    } else {
      if (chat != null) {
        if (chat.id < 0) {
          dialog_id = AndroidUtilities.makeBroadcastId(chat.id);
          drawNameBroadcast = true;
          nameLockTop = AndroidUtilities.dp(28.5f);
        } else {
          dialog_id = -chat.id;
          if (ChatObject.isChannel(chat) && !chat.megagroup) {
            drawNameBroadcast = true;
            nameLockTop = AndroidUtilities.dp(28.5f);
          } else {
            drawNameGroup = true;
            nameLockTop = AndroidUtilities.dp(30);
          }
        }
        drawCheck = chat.verified;
        if (!LocaleController.isRTL) {
          nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
          nameLeft =
              AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                  + (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
        } else {
          nameLockLeft =
              getMeasuredWidth()
                  - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                  - (drawNameGroup
                      ? groupDrawable.getIntrinsicWidth()
                      : broadcastDrawable.getIntrinsicWidth());
          nameLeft = AndroidUtilities.dp(11);
        }
      } else {
        dialog_id = user.id;
        if (!LocaleController.isRTL) {
          nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
        } else {
          nameLeft = AndroidUtilities.dp(11);
        }
        if (user.bot) {
          drawNameBot = true;
          if (!LocaleController.isRTL) {
            nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
            nameLeft =
                AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4)
                    + botDrawable.getIntrinsicWidth();
          } else {
            nameLockLeft =
                getMeasuredWidth()
                    - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2)
                    - botDrawable.getIntrinsicWidth();
            nameLeft = AndroidUtilities.dp(11);
          }
          nameLockTop = AndroidUtilities.dp(16.5f);
        } else {
          nameLockTop = AndroidUtilities.dp(17);
        }
        drawCheck = user.verified;
      }
    }

    if (currentName != null) {
      nameString = currentName;
    } else {
      String nameString2 = "";
      if (chat != null) {
        nameString2 = chat.title;
      } else if (user != null) {
        nameString2 = UserObject.getUserName(user);
      }
      nameString = nameString2.replace('\n', ' ');
    }
    if (nameString.length() == 0) {
      if (user != null && user.phone != null && user.phone.length() != 0) {
        nameString = PhoneFormat.getInstance().format("+" + user.phone);
      } else {
        nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
      }
    }
    if (encryptedChat != null) {
      currentNamePaint = nameEncryptedPaint;
    } else {
      currentNamePaint = namePaint;
    }

    int onlineWidth;
    int nameWidth;
    if (!LocaleController.isRTL) {
      onlineWidth = nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14);
    } else {
      onlineWidth =
          nameWidth =
              getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline);
    }
    if (drawNameLock) {
      nameWidth -= AndroidUtilities.dp(6) + lockDrawable.getIntrinsicWidth();
    } else if (drawNameBroadcast) {
      nameWidth -= AndroidUtilities.dp(6) + broadcastDrawable.getIntrinsicWidth();
    } else if (drawNameGroup) {
      nameWidth -= AndroidUtilities.dp(6) + groupDrawable.getIntrinsicWidth();
    } else if (drawNameBot) {
      nameWidth -= AndroidUtilities.dp(6) + botDrawable.getIntrinsicWidth();
    }

    if (drawCount) {
      TLRPC.TL_dialog dialog = MessagesController.getInstance().dialogs_dict.get(dialog_id);
      if (dialog != null && dialog.unread_count != 0) {
        lastUnreadCount = dialog.unread_count;
        String countString = String.format("%d", dialog.unread_count);
        countWidth =
            Math.max(AndroidUtilities.dp(12), (int) Math.ceil(countPaint.measureText(countString)));
        countLayout =
            new StaticLayout(
                countString,
                countPaint,
                countWidth,
                Layout.Alignment.ALIGN_CENTER,
                1.0f,
                0.0f,
                false);
        int w = countWidth + AndroidUtilities.dp(18);
        nameWidth -= w;
        if (!LocaleController.isRTL) {
          countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(19);
        } else {
          countLeft = AndroidUtilities.dp(19);
          nameLeft += w;
        }
      } else {
        lastUnreadCount = 0;
        countLayout = null;
      }
    } else {
      lastUnreadCount = 0;
      countLayout = null;
    }

    CharSequence nameStringFinal =
        TextUtils.ellipsize(
            nameString,
            currentNamePaint,
            nameWidth - AndroidUtilities.dp(12),
            TextUtils.TruncateAt.END);
    nameLayout =
        new StaticLayout(
            nameStringFinal,
            currentNamePaint,
            nameWidth,
            Layout.Alignment.ALIGN_NORMAL,
            1.0f,
            0.0f,
            false);

    if (chat == null || subLabel != null) {
      if (!LocaleController.isRTL) {
        onlineLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
      } else {
        onlineLeft = AndroidUtilities.dp(11);
      }

      CharSequence onlineString = "";
      TextPaint currentOnlinePaint = offlinePaint;

      if (subLabel != null) {
        onlineString = subLabel;
      } else if (user != null) {
        if (user.bot) {
          onlineString = LocaleController.getString("Bot", R.string.Bot);
        } else {
          onlineString = LocaleController.formatUserStatus(user);
          if (user != null
              && (user.id == UserConfig.getClientUserId()
                  || user.status != null
                      && user.status.expires > ConnectionsManager.getInstance().getCurrentTime())) {
            currentOnlinePaint = onlinePaint;
            onlineString = LocaleController.getString("Online", R.string.Online);
          }
        }
      }

      CharSequence onlineStringFinal =
          TextUtils.ellipsize(
              onlineString,
              currentOnlinePaint,
              onlineWidth - AndroidUtilities.dp(12),
              TextUtils.TruncateAt.END);
      onlineLayout =
          new StaticLayout(
              onlineStringFinal,
              currentOnlinePaint,
              onlineWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);
      nameTop = AndroidUtilities.dp(13);
      if (subLabel != null && chat != null) {
        nameLockTop -= AndroidUtilities.dp(12);
      }
    } else {
      onlineLayout = null;
      nameTop = AndroidUtilities.dp(25);
    }

    int avatarLeft;
    if (!LocaleController.isRTL) {
      avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
    } else {
      avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
    }

    avatarImage.setImageCoords(
        avatarLeft, AndroidUtilities.dp(10), AndroidUtilities.dp(52), AndroidUtilities.dp(52));

    double widthpx;
    float left;
    if (LocaleController.isRTL) {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft += (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineLeft(0);
        if (left == 0) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft += (onlineWidth - widthpx);
          }
        }
      }
    } else {
      if (nameLayout.getLineCount() > 0) {
        left = nameLayout.getLineRight(0);
        if (left == nameWidth) {
          widthpx = Math.ceil(nameLayout.getLineWidth(0));
          if (widthpx < nameWidth) {
            nameLeft -= (nameWidth - widthpx);
          }
        }
      }
      if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
        left = onlineLayout.getLineRight(0);
        if (left == onlineWidth) {
          widthpx = Math.ceil(onlineLayout.getLineWidth(0));
          if (widthpx < onlineWidth) {
            onlineLeft -= (onlineWidth - widthpx);
          }
        }
      }
    }
  }
Exemple #4
0
    public void build(int width, int height) {
      CharSequence nameString = "";
      TextPaint currentNamePaint;

      if (encryptedChat != null) {
        drawNameLock = true;
        if (!LocaleController.isRTL) {
          nameLockLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
          nameLeft = Utilities.dp(65 + (usePadding ? 11 : 0)) + lockDrawable.getIntrinsicWidth();
        } else {
          nameLockLeft =
              width - Utilities.dp(63 + (usePadding ? 11 : 0)) - lockDrawable.getIntrinsicWidth();
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      } else {
        drawNameLock = false;
        if (!LocaleController.isRTL) {
          nameLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          nameLeft = usePadding ? Utilities.dp(11) : 0;
        }
      }

      if (currentName != null) {
        nameString = currentName;
      } else {
        String nameString2 = "";
        if (chat != null) {
          nameString2 = chat.title;
        } else if (user != null) {
          nameString2 = Utilities.formatName(user.first_name, user.last_name);
        }
        nameString = nameString2.replace("\n", " ");
      }
      if (nameString.length() == 0) {
        if (user.phone != null && user.phone.length() != 0) {
          nameString = PhoneFormat.getInstance().format("+" + user.phone);
        } else {
          nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
        }
      }
      if (encryptedChat != null) {
        currentNamePaint = nameEncryptedPaint;
      } else {
        currentNamePaint = namePaint;
      }

      if (!LocaleController.isRTL) {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(3 + (usePadding ? 11 : 0));
      } else {
        onlineWidth = nameWidth = width - nameLeft - Utilities.dp(61 + (usePadding ? 11 : 0));
      }
      if (drawNameLock) {
        nameWidth -= Utilities.dp(6) + lockDrawable.getIntrinsicWidth();
      }

      CharSequence nameStringFinal =
          TextUtils.ellipsize(
              nameString, currentNamePaint, nameWidth - Utilities.dp(12), TextUtils.TruncateAt.END);
      nameLayout =
          new StaticLayout(
              nameStringFinal,
              currentNamePaint,
              nameWidth,
              Layout.Alignment.ALIGN_NORMAL,
              1.0f,
              0.0f,
              false);

      if (chat == null) {
        if (!LocaleController.isRTL) {
          onlineLeft = Utilities.dp(61 + (usePadding ? 11 : 0));
        } else {
          onlineLeft = usePadding ? Utilities.dp(11) : 0;
        }

        String onlineString = "";
        TextPaint currentOnlinePaint = offlinePaint;

        if (subLabel != null) {
          onlineString = subLabel;
        } else {
          if (user != null) {
            if (user.status == null) {
              onlineString = getResources().getString(R.string.Offline);
            } else {
              int currentTime = ConnectionsManager.getInstance().getCurrentTime();
              if (user.id == UserConfig.clientUserId || user.status.expires > currentTime) {
                currentOnlinePaint = onlinePaint;
                onlineString = getResources().getString(R.string.Online);
              } else {
                if (user.status.expires <= 10000) {
                  onlineString = getResources().getString(R.string.Invisible);
                } else {
                  onlineString = LocaleController.formatDateOnline(user.status.expires);
                }
              }
            }
          }
        }

        CharSequence onlineStringFinal =
            TextUtils.ellipsize(
                onlineString,
                currentOnlinePaint,
                nameWidth - Utilities.dp(12),
                TextUtils.TruncateAt.END);
        onlineLayout =
            new StaticLayout(
                onlineStringFinal,
                currentOnlinePaint,
                nameWidth,
                Layout.Alignment.ALIGN_NORMAL,
                1.0f,
                0.0f,
                false);
        nameTop = Utilities.dp(12);
      } else {
        onlineLayout = null;
        nameTop = Utilities.dp(22);
      }

      if (!LocaleController.isRTL) {
        avatarLeft = usePadding ? Utilities.dp(11) : 0;
      } else {
        avatarLeft = width - Utilities.dp(50 + (usePadding ? 11 : 0));
      }
      avatarImage.imageX = avatarLeft;
      avatarImage.imageY = avatarTop;
      avatarImage.imageW = Utilities.dp(50);
      avatarImage.imageH = Utilities.dp(50);

      double widthpx = 0;
      float left = 0;
      if (LocaleController.isRTL) {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft += (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineLeft(0);
          if (left == 0) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft += (onlineWidth - widthpx);
            }
          }
        }
      } else {
        if (nameLayout.getLineCount() > 0) {
          left = nameLayout.getLineRight(0);
          if (left == nameWidth) {
            widthpx = Math.ceil(nameLayout.getLineWidth(0));
            if (widthpx < nameWidth) {
              nameLeft -= (nameWidth - widthpx);
            }
          }
        }
        if (onlineLayout != null && onlineLayout.getLineCount() > 0) {
          left = onlineLayout.getLineRight(0);
          if (left == onlineWidth) {
            widthpx = Math.ceil(onlineLayout.getLineWidth(0));
            if (widthpx < onlineWidth) {
              onlineLeft -= (onlineWidth - widthpx);
            }
          }
        }
      }
    }
    @Override
    public View getItemView(int section, int position, View convertView, ViewGroup parent) {
      TLRPC.User user;
      int size;

      if (searchWas && searching) {
        user = MessagesController.getInstance().getUser(searchResult.get(position).id);
        size = searchResult.size();
      } else {
        ArrayList<TLRPC.TL_contact> arr =
            ContactsController.getInstance()
                .usersSectionsDict
                .get(ContactsController.getInstance().sortedUsersSectionsArray.get(section));
        user = MessagesController.getInstance().getUser(arr.get(position).user_id);
        size = arr.size();
      }

      if (convertView == null) {
        LayoutInflater li =
            (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = li.inflate(R.layout.group_create_row_layout, parent, false);
      }
      ContactListRowHolder holder = (ContactListRowHolder) convertView.getTag();
      if (holder == null) {
        holder = new ContactListRowHolder(convertView);
        convertView.setTag(holder);
      }

      ImageView checkButton = (ImageView) convertView.findViewById(R.id.settings_row_check_button);
      if (selectedContacts.containsKey(user.id)) {
        checkButton.setImageResource(R.drawable.btn_check_on_holo_light);
      } else {
        checkButton.setImageResource(R.drawable.btn_check_off_holo_light);
      }

      View divider = convertView.findViewById(R.id.settings_row_divider);
      if (position == size - 1) {
        divider.setVisibility(View.INVISIBLE);
      } else {
        divider.setVisibility(View.VISIBLE);
      }

      if (searchWas && searching) {
        holder.nameTextView.setText(searchResultNames.get(position));
      } else {
        String name = ContactsController.formatName(user.first_name, user.last_name);
        if (name.length() == 0) {
          if (user.phone != null && user.phone.length() != 0) {
            name = PhoneFormat.getInstance().format("+" + user.phone);
          } else {
            name = LocaleController.getString("HiddenName", R.string.HiddenName);
          }
        }
        holder.nameTextView.setText(name);
      }

      TLRPC.FileLocation photo = null;
      if (user.photo != null) {
        photo = user.photo.photo_small;
      }
      int placeHolderId = AndroidUtilities.getUserAvatarForId(user.id);
      holder.avatarImage.setImage(photo, "50_50", placeHolderId);

      holder.messageTextView.setText(LocaleController.formatUserStatus(user));
      if (user.status != null
          && user.status.expires > ConnectionsManager.getInstance().getCurrentTime()) {
        holder.messageTextView.setTextColor(0xff357aa8);
      } else {
        holder.messageTextView.setTextColor(0xff808080);
      }

      return convertView;
    }
  @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);
    }
  }
    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
      int type = getItemViewType(i);
      if (type == 0) {
        BackupImageView avatarImage;
        TextView onlineText;
        TLRPC.User user = MessagesController.getInstance().users.get(user_id);
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_avatar_layout, viewGroup, false);

          onlineText = (TextView) view.findViewById(R.id.settings_online);
          avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image);
          avatarImage.processDetach = false;
          avatarImage.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                  if (user.photo != null && user.photo.photo_big != null) {
                    PhotoViewer.getInstance()
                        .openPhoto(user.photo.photo_big, UserProfileActivity.this);
                  }
                }
              });
        } else {
          avatarImage = (BackupImageView) view.findViewById(R.id.settings_avatar_image);
          onlineText = (TextView) view.findViewById(R.id.settings_online);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_name);
        Typeface typeface = Utilities.getTypeface("fonts/rmedium.ttf");
        textView.setTypeface(typeface);

        textView.setText(Utilities.formatName(user.first_name, user.last_name));
        onlineText.setText(LocaleController.formatUserStatus(user));

        TLRPC.FileLocation photo = null;
        TLRPC.FileLocation photoBig = null;
        if (user.photo != null) {
          photo = user.photo.photo_small;
          photoBig = user.photo.photo_big;
        }
        avatarImage.setImage(photo, "50_50", Utilities.getUserAvatarForId(user.id));
        avatarImage.imageReceiver.setVisible(
            !PhotoViewer.getInstance().isShowingImage(photoBig), false);
        return view;
      } else if (type == 1) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_section_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_section_text);
        if (i == phoneSectionRow) {
          textView.setText(LocaleController.getString("PHONE", R.string.PHONE));
        } else if (i == settingsSectionRow) {
          textView.setText(LocaleController.getString("SETTINGS", R.string.SETTINGS));
        } else if (i == sharedMediaSectionRow) {
          textView.setText(LocaleController.getString("SHAREDMEDIA", R.string.SHAREDMEDIA));
        }
      } else if (type == 2) {
        final TLRPC.User user = MessagesController.getInstance().users.get(user_id);
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_phone_layout, viewGroup, false);
          view.setOnClickListener(
              new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                  if (user.phone == null
                      || user.phone.length() == 0
                      || getParentActivity() == null) {
                    return;
                  }
                  selectedPhone = user.phone;

                  AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());

                  builder.setItems(
                      new CharSequence[] {
                        LocaleController.getString("Copy", R.string.Copy),
                        LocaleController.getString("Call", R.string.Call)
                      },
                      new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                          if (i == 1) {
                            try {
                              Intent intent =
                                  new Intent(
                                      Intent.ACTION_DIAL, Uri.parse("tel:+" + selectedPhone));
                              intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                              getParentActivity().startActivity(intent);
                            } catch (Exception e) {
                              FileLog.e("tmessages", e);
                            }
                          } else if (i == 0) {
                            int sdk = android.os.Build.VERSION.SDK_INT;
                            if (sdk < android.os.Build.VERSION_CODES.HONEYCOMB) {
                              android.text.ClipboardManager clipboard =
                                  (android.text.ClipboardManager)
                                      ApplicationLoader.applicationContext.getSystemService(
                                          Context.CLIPBOARD_SERVICE);
                              clipboard.setText(selectedPhone);
                            } else {
                              android.content.ClipboardManager clipboard =
                                  (android.content.ClipboardManager)
                                      ApplicationLoader.applicationContext.getSystemService(
                                          Context.CLIPBOARD_SERVICE);
                              android.content.ClipData clip =
                                  android.content.ClipData.newPlainText("label", selectedPhone);
                              clipboard.setPrimaryClip(clip);
                            }
                          }
                        }
                      });
                  showAlertDialog(builder);
                }
              });
        }
        ImageButton button = (ImageButton) view.findViewById(R.id.settings_edit_name);
        button.setOnClickListener(
            new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                TLRPC.User user = MessagesController.getInstance().users.get(user_id);
                if (user == null || user instanceof TLRPC.TL_userEmpty) {
                  return;
                }
                NotificationCenter.getInstance()
                    .postNotificationName(MessagesController.closeChats);
                Bundle args = new Bundle();
                args.putInt("user_id", user_id);
                presentFragment(new ChatActivity(args), true);
              }
            });
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);
        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == phoneRow) {
          if (user.phone != null && user.phone.length() != 0) {
            textView.setText(PhoneFormat.getInstance().format("+" + user.phone));
          } else {
            textView.setText("Unknown");
          }
          divider.setVisibility(View.INVISIBLE);
          detailTextView.setText(LocaleController.getString("PhoneMobile", R.string.PhoneMobile));
        }
      } else if (type == 3) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_leftright_row_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        TextView detailTextView = (TextView) view.findViewById(R.id.settings_row_text_detail);

        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == sharedMediaRow) {
          textView.setText(LocaleController.getString("SharedMedia", R.string.SharedMedia));
          if (totalMediaCount == -1) {
            detailTextView.setText(LocaleController.getString("Loading", R.string.Loading));
          } else {
            detailTextView.setText(String.format("%d", totalMediaCount));
          }
          divider.setVisibility(View.INVISIBLE);
        } else if (i == settingsTimerRow) {
          TLRPC.EncryptedChat encryptedChat =
              MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32));
          textView.setText(LocaleController.getString("MessageLifetime", R.string.MessageLifetime));
          divider.setVisibility(View.VISIBLE);
          if (encryptedChat.ttl == 0) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetimeForever", R.string.ShortMessageLifetimeForever));
          } else if (encryptedChat.ttl == 2) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime2s", R.string.ShortMessageLifetime2s));
          } else if (encryptedChat.ttl == 5) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime5s", R.string.ShortMessageLifetime5s));
          } else if (encryptedChat.ttl == 60) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1m", R.string.ShortMessageLifetime1m));
          } else if (encryptedChat.ttl == 60 * 60) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1h", R.string.ShortMessageLifetime1h));
          } else if (encryptedChat.ttl == 60 * 60 * 24) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1d", R.string.ShortMessageLifetime1d));
          } else if (encryptedChat.ttl == 60 * 60 * 24 * 7) {
            detailTextView.setText(
                LocaleController.getString(
                    "ShortMessageLifetime1w", R.string.ShortMessageLifetime1w));
          } else {
            detailTextView.setText(String.format("%d", encryptedChat.ttl));
          }
        }
      } else if (type == 4) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.user_profile_identicon_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        View divider = view.findViewById(R.id.settings_row_divider);
        divider.setVisibility(View.VISIBLE);
        IdenticonView identiconView = (IdenticonView) view.findViewById(R.id.identicon_view);
        TLRPC.EncryptedChat encryptedChat =
            MessagesController.getInstance().encryptedChats.get((int) (dialog_id >> 32));
        identiconView.setBytes(encryptedChat.auth_key);
        textView.setText(LocaleController.getString("EncryptionKey", R.string.EncryptionKey));
      } else if (type == 5) {
        if (view == null) {
          LayoutInflater li =
              (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          view = li.inflate(R.layout.settings_row_button_layout, viewGroup, false);
        }
        TextView textView = (TextView) view.findViewById(R.id.settings_row_text);
        View divider = view.findViewById(R.id.settings_row_divider);
        if (i == settingsNotificationsRow) {
          textView.setText(
              LocaleController.getString(
                  "NotificationsAndSounds", R.string.NotificationsAndSounds));
          divider.setVisibility(View.INVISIBLE);
        }
      }
      return view;
    }