Пример #1
0
  @Override
  protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
    super.onLayout(changed, left, top, right, bottom);

    if (currentMessageObject == null) {
      return;
    }

    int x;

    if (currentMessageObject.isOutOwner()) {
      x = layoutWidth - backgroundWidth + AndroidUtilities.dp(8);
    } else {
      if (isChat && currentMessageObject.messageOwner.from_id > 0) {
        x = AndroidUtilities.dp(69);
      } else {
        x = AndroidUtilities.dp(16);
      }
    }
    avatarImage.setImageCoords(
        x, AndroidUtilities.dp(9) + namesOffset, AndroidUtilities.dp(42), AndroidUtilities.dp(42));
  }
Пример #2
0
  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);
          }
        }
      }
    }
  }