NekoX/TMessagesProj/src/main/java/org/telegram/ui/Cells/UserCell.java

539 lines
25 KiB
Java
Raw Normal View History

/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
* It is licensed under GNU GPL v. 2 or later.
* You should have received a copy of the license in this archive (see LICENSE).
*
2019-01-23 18:03:33 +01:00
* Copyright Nikolai Kudashov, 2013-2018.
*/
package org.telegram.ui.Cells;
import android.content.Context;
2019-01-23 18:03:33 +01:00
import android.graphics.Canvas;
2017-03-31 01:58:05 +02:00
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
2018-07-30 04:07:02 +02:00
import android.graphics.Typeface;
2019-01-23 18:03:33 +01:00
import android.util.TypedValue;
2014-11-12 23:16:59 +01:00
import android.view.Gravity;
2019-05-14 14:08:05 +02:00
import android.view.accessibility.AccessibilityNodeInfo;
2014-11-12 23:16:59 +01:00
import android.widget.FrameLayout;
import android.widget.ImageView;
2019-01-23 18:03:33 +01:00
import android.widget.TextView;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.AndroidUtilities;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2015-09-24 22:52:02 +02:00
import org.telegram.messenger.LocaleController;
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.UserObject;
import org.telegram.messenger.R;
2015-09-24 22:52:02 +02:00
import org.telegram.tgnet.ConnectionsManager;
import org.telegram.tgnet.TLRPC;
import org.telegram.messenger.UserConfig;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
import org.telegram.ui.Components.CheckBox;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Components.CheckBoxSquare;
import org.telegram.ui.Components.LayoutHelper;
2016-04-22 15:49:00 +02:00
import org.telegram.ui.ActionBar.SimpleTextView;
2019-02-08 03:30:32 +01:00
import org.telegram.ui.NotificationsSettingsActivity;
2014-11-12 23:16:59 +01:00
public class UserCell extends FrameLayout {
private BackupImageView avatarImageView;
private SimpleTextView nameTextView;
private SimpleTextView statusTextView;
2014-11-12 23:16:59 +01:00
private ImageView imageView;
2014-11-13 21:10:14 +01:00
private CheckBox checkBox;
2015-11-26 22:04:02 +01:00
private CheckBoxSquare checkBoxBig;
2019-01-23 18:03:33 +01:00
private TextView adminTextView;
2019-07-18 15:01:39 +02:00
private TextView addButton;
private AvatarDrawable avatarDrawable;
2020-03-30 14:00:09 +02:00
private Object currentObject;
2019-02-08 03:30:32 +01:00
private TLRPC.EncryptedChat encryptedChat;
2014-11-12 23:16:59 +01:00
private CharSequence currentName;
2019-05-14 14:08:05 +02:00
private CharSequence currentStatus;
2018-07-30 04:07:02 +02:00
private int currentId;
2014-11-12 23:16:59 +01:00
private int currentDrawable;
2020-03-30 14:00:09 +02:00
private boolean selfAsSavedMessages;
2016-05-25 23:49:47 +02:00
private String lastName;
private int lastStatus;
private TLRPC.FileLocation lastAvatar;
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
2017-03-31 01:58:05 +02:00
private int statusColor;
private int statusOnlineColor;
2019-01-23 18:03:33 +01:00
private boolean needDivider;
2016-03-16 13:26:32 +01:00
public UserCell(Context context, int padding, int checkbox, boolean admin) {
2019-07-18 15:01:39 +02:00
this(context, padding, checkbox, admin, false);
}
public UserCell(Context context, int padding, int checkbox, boolean admin, boolean needAddButton) {
super(context);
2019-07-18 15:01:39 +02:00
int additionalPadding;
if (needAddButton) {
addButton = new TextView(context);
addButton.setGravity(Gravity.CENTER);
addButton.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
addButton.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
addButton.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
addButton.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(4), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
addButton.setText(LocaleController.getString("Add", R.string.Add));
addButton.setPadding(AndroidUtilities.dp(17), 0, AndroidUtilities.dp(17), 0);
addView(addButton, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, 28, Gravity.TOP | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT), LocaleController.isRTL ? 14 : 0, 15, LocaleController.isRTL ? 0 : 14, 0));
additionalPadding = (int) Math.ceil((addButton.getPaint().measureText(addButton.getText().toString()) + AndroidUtilities.dp(34 + 14)) / AndroidUtilities.density);
} else {
additionalPadding = 0;
}
2017-03-31 01:58:05 +02:00
statusColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText);
statusOnlineColor = Theme.getColor(Theme.key_windowBackgroundWhiteBlueText);
avatarDrawable = new AvatarDrawable();
2014-11-12 23:16:59 +01:00
avatarImageView = new BackupImageView(context);
2015-04-09 20:00:14 +02:00
avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
2019-01-23 18:03:33 +01:00
addView(avatarImageView, LayoutHelper.createFrame(46, 46, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 7 + padding, 6, LocaleController.isRTL ? 7 + padding : 0, 0));
nameTextView = new SimpleTextView(context);
2017-03-31 01:58:05 +02:00
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
2019-01-23 18:03:33 +01:00
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
nameTextView.setTextSize(16);
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2019-07-18 15:01:39 +02:00
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + (checkbox == 2 ? 18 : 0) + additionalPadding : (64 + padding), 10, LocaleController.isRTL ? (64 + padding) : 28 + (checkbox == 2 ? 18 : 0) + additionalPadding, 0));
statusTextView = new SimpleTextView(context);
2019-01-23 18:03:33 +01:00
statusTextView.setTextSize(15);
statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
2019-07-18 15:01:39 +02:00
addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + additionalPadding : (64 + padding), 32, LocaleController.isRTL ? (64 + padding) : 28 + additionalPadding, 0));
2014-11-12 23:16:59 +01:00
imageView = new ImageView(context);
imageView.setScaleType(ImageView.ScaleType.CENTER);
2018-07-30 04:07:02 +02:00
imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteGrayIcon), PorterDuff.Mode.MULTIPLY));
imageView.setVisibility(GONE);
addView(imageView, LayoutHelper.createFrame(LayoutParams.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 0 : 16, 0, LocaleController.isRTL ? 16 : 0, 0));
2014-11-14 16:40:15 +01:00
2015-11-26 22:04:02 +01:00
if (checkbox == 2) {
2017-03-31 01:58:05 +02:00
checkBoxBig = new CheckBoxSquare(context, false);
2015-11-26 22:04:02 +01:00
addView(checkBoxBig, LayoutHelper.createFrame(18, 18, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 19 : 0, 0, LocaleController.isRTL ? 0 : 19, 0));
} else if (checkbox == 1) {
checkBox = new CheckBox(context, R.drawable.round_check2);
checkBox.setVisibility(INVISIBLE);
2017-03-31 01:58:05 +02:00
checkBox.setColor(Theme.getColor(Theme.key_checkbox), Theme.getColor(Theme.key_checkboxCheck));
2019-01-23 18:03:33 +01:00
addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 37 + padding, 40, LocaleController.isRTL ? 37 + padding : 0, 0));
2015-11-26 22:04:02 +01:00
}
2016-03-16 13:26:32 +01:00
if (admin) {
2019-01-23 18:03:33 +01:00
adminTextView = new TextView(context);
adminTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
adminTextView.setTextColor(Theme.getColor(Theme.key_profile_creatorIcon));
2019-06-04 12:14:50 +02:00
addView(adminTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP, LocaleController.isRTL ? 23 : 0, 10, LocaleController.isRTL ? 0 : 23, 0));
2019-01-23 18:03:33 +01:00
}
2019-07-18 15:01:39 +02:00
2019-05-14 14:08:05 +02:00
setFocusable(true);
2019-01-23 18:03:33 +01:00
}
public void setAvatarPadding(int padding) {
2020-03-30 14:00:09 +02:00
LayoutParams layoutParams = (LayoutParams) avatarImageView.getLayoutParams();
2019-01-23 18:03:33 +01:00
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 7 + padding);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 7 + padding : 0);
avatarImageView.setLayoutParams(layoutParams);
2020-03-30 14:00:09 +02:00
layoutParams = (LayoutParams) nameTextView.getLayoutParams();
2019-01-23 18:03:33 +01:00
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 28 + (checkBoxBig != null ? 18 : 0) : (64 + padding));
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? (64 + padding) : 28 + (checkBoxBig != null ? 18 : 0));
layoutParams = (FrameLayout.LayoutParams) statusTextView.getLayoutParams();
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 28 : (64 + padding));
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? (64 + padding) : 28);
if (checkBox != null) {
layoutParams = (FrameLayout.LayoutParams) checkBox.getLayoutParams();
layoutParams.leftMargin = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 37 + padding);
layoutParams.rightMargin = AndroidUtilities.dp(LocaleController.isRTL ? 37 + padding : 0);
2016-03-16 13:26:32 +01:00
}
}
2019-07-18 15:01:39 +02:00
public void setAddButtonVisible(boolean value) {
if (addButton == null) {
return;
}
addButton.setVisibility(value ? VISIBLE : GONE);
}
2019-08-22 01:53:26 +02:00
public void setAdminRole(String role) {
2019-01-23 18:03:33 +01:00
if (adminTextView == null) {
2016-03-16 13:26:32 +01:00
return;
}
2019-08-22 01:53:26 +02:00
adminTextView.setVisibility(role != null ? VISIBLE : GONE);
adminTextView.setText(role);
if (role != null) {
2019-01-23 18:03:33 +01:00
CharSequence text = adminTextView.getText();
int size = (int) Math.ceil(adminTextView.getPaint().measureText(text, 0, text.length()));
nameTextView.setPadding(LocaleController.isRTL ? size + AndroidUtilities.dp(6) : 0, 0, !LocaleController.isRTL ? size + AndroidUtilities.dp(6) : 0, 0);
} else {
nameTextView.setPadding(0, 0, 0, 0);
2016-04-22 15:49:00 +02:00
}
}
2020-03-30 14:00:09 +02:00
public CharSequence getName() {
return nameTextView.getText();
}
public void setData(Object object, CharSequence name, CharSequence status, int resId) {
2019-02-08 03:30:32 +01:00
setData(object, null, name, status, resId, false);
2019-01-23 18:03:33 +01:00
}
2020-03-30 14:00:09 +02:00
public void setData(Object object, CharSequence name, CharSequence status, int resId, boolean divider) {
2019-02-08 03:30:32 +01:00
setData(object, null, name, status, resId, divider);
}
2020-03-30 14:00:09 +02:00
public void setData(Object object, TLRPC.EncryptedChat ec, CharSequence name, CharSequence status, int resId, boolean divider) {
2018-08-27 10:33:11 +02:00
if (object == null && name == null && status == null) {
2019-05-14 14:08:05 +02:00
currentStatus = null;
2014-11-12 23:16:59 +01:00
currentName = null;
2015-09-24 22:52:02 +02:00
currentObject = null;
2014-11-12 23:16:59 +01:00
nameTextView.setText("");
statusTextView.setText("");
avatarImageView.setImageDrawable(null);
return;
}
2019-02-08 03:30:32 +01:00
encryptedChat = ec;
2019-05-14 14:08:05 +02:00
currentStatus = status;
2014-11-12 23:16:59 +01:00
currentName = name;
2018-08-27 10:33:11 +02:00
currentObject = object;
2014-11-12 23:16:59 +01:00
currentDrawable = resId;
2019-01-23 18:03:33 +01:00
needDivider = divider;
setWillNotDraw(!needDivider);
update(0);
}
2020-03-30 14:00:09 +02:00
public Object getCurrentObject() {
return currentObject;
}
2019-02-08 03:30:32 +01:00
public void setException(NotificationsSettingsActivity.NotificationException exception, CharSequence name, boolean divider) {
String text;
boolean enabled;
boolean custom = exception.hasCustom;
int value = exception.notify;
int delta = exception.muteUntil;
if (value == 3 && delta != Integer.MAX_VALUE) {
delta -= ConnectionsManager.getInstance(currentAccount).getCurrentTime();
if (delta <= 0) {
if (custom) {
text = LocaleController.getString("NotificationsCustom", R.string.NotificationsCustom);
} else {
text = LocaleController.getString("NotificationsUnmuted", R.string.NotificationsUnmuted);
}
} else if (delta < 60 * 60) {
text = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Minutes", delta / 60));
} else if (delta < 60 * 60 * 24) {
text = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Hours", (int) Math.ceil(delta / 60.0f / 60)));
} else if (delta < 60 * 60 * 24 * 365) {
text = LocaleController.formatString("WillUnmuteIn", R.string.WillUnmuteIn, LocaleController.formatPluralString("Days", (int) Math.ceil(delta / 60.0f / 60 / 24)));
} else {
text = null;
}
} else {
if (value == 0) {
enabled = true;
} else if (value == 1) {
enabled = true;
} else if (value == 2) {
enabled = false;
} else {
enabled = false;
}
if (enabled && custom) {
text = LocaleController.getString("NotificationsCustom", R.string.NotificationsCustom);
} else {
text = enabled ? LocaleController.getString("NotificationsUnmuted", R.string.NotificationsUnmuted) : LocaleController.getString("NotificationsMuted", R.string.NotificationsMuted);
}
}
if (text == null) {
text = LocaleController.getString("NotificationsOff", R.string.NotificationsOff);
}
int lower_id = (int) exception.did;
int high_id = (int) (exception.did >> 32);
if (lower_id != 0) {
if (lower_id > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(lower_id);
if (user != null) {
setData(user, null, name, text, 0, divider);
}
} else {
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-lower_id);
if (chat != null) {
setData(chat, null, name, text, 0, divider);
}
}
} else {
TLRPC.EncryptedChat encryptedChat = MessagesController.getInstance(currentAccount).getEncryptedChat(high_id);
if (encryptedChat != null) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(encryptedChat.user_id);
if (user != null) {
setData(user, encryptedChat, name, text, 0, false);
}
}
}
}
2018-07-30 04:07:02 +02:00
public void setNameTypeface(Typeface typeface) {
nameTextView.setTypeface(typeface);
}
public void setCurrentId(int id) {
currentId = id;
}
2014-11-21 20:36:21 +01:00
public void setChecked(boolean checked, boolean animated) {
2015-11-26 22:04:02 +01:00
if (checkBox != null) {
if (checkBox.getVisibility() != VISIBLE) {
checkBox.setVisibility(VISIBLE);
}
checkBox.setChecked(checked, animated);
} else if (checkBoxBig != null) {
if (checkBoxBig.getVisibility() != VISIBLE) {
checkBoxBig.setVisibility(VISIBLE);
}
checkBoxBig.setChecked(checked, animated);
}
}
public void setCheckDisabled(boolean disabled) {
if (checkBoxBig != null) {
checkBoxBig.setDisabled(disabled);
2014-11-14 16:40:15 +01:00
}
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2019-01-23 18:03:33 +01:00
super.onMeasure(MeasureSpec.makeMeasureSpec(MeasureSpec.getSize(widthMeasureSpec), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(58) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
}
2014-11-12 23:16:59 +01:00
public void setStatusColors(int color, int onlineColor) {
statusColor = color;
statusOnlineColor = onlineColor;
}
2017-03-31 01:58:05 +02:00
@Override
public void invalidate() {
super.invalidate();
if (checkBoxBig != null) {
checkBoxBig.invalidate();
}
}
public void update(int mask) {
TLRPC.FileLocation photo = null;
String newName = null;
2015-09-24 22:52:02 +02:00
TLRPC.User currentUser = null;
TLRPC.Chat currentChat = null;
if (currentObject instanceof TLRPC.User) {
currentUser = (TLRPC.User) currentObject;
if (currentUser.photo != null) {
photo = currentUser.photo.photo_small;
}
2019-02-08 03:30:32 +01:00
/*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) + Theme.dialogs_lockDrawable.getIntrinsicWidth();
} else {
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 2) - Theme.dialogs_lockDrawable.getIntrinsicWidth();
nameLeft = AndroidUtilities.dp(11);
}
nameLockTop = AndroidUtilities.dp(16.5f);
}*/
2018-07-30 04:07:02 +02:00
} else if (currentObject instanceof TLRPC.Chat) {
2015-09-24 22:52:02 +02:00
currentChat = (TLRPC.Chat) currentObject;
if (currentChat.photo != null) {
photo = currentChat.photo.photo_small;
}
}
if (mask != 0) {
boolean continueUpdate = false;
2014-11-12 23:16:59 +01:00
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
2019-07-18 15:01:39 +02:00
if (lastAvatar != null && photo == null || lastAvatar == null && photo != null || lastAvatar != null && photo != null && (lastAvatar.volume_id != photo.volume_id || lastAvatar.local_id != photo.local_id)) {
continueUpdate = true;
}
}
2015-09-24 22:52:02 +02:00
if (currentUser != null && !continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
int newStatus = 0;
2014-11-12 23:16:59 +01:00
if (currentUser.status != null) {
newStatus = currentUser.status.expires;
}
if (newStatus != lastStatus) {
continueUpdate = true;
}
}
if (!continueUpdate && currentName == null && lastName != null && (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
2015-09-24 22:52:02 +02:00
if (currentUser != null) {
newName = UserObject.getUserName(currentUser);
} else {
newName = currentChat.title;
}
if (!newName.equals(lastName)) {
continueUpdate = true;
}
}
if (!continueUpdate) {
return;
}
}
2020-03-30 14:00:09 +02:00
if (currentObject instanceof String) {
((LayoutParams) nameTextView.getLayoutParams()).topMargin = AndroidUtilities.dp(19);
String str = (String) currentObject;
switch (str) {
case "contacts":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_CONTACTS);
break;
case "non_contacts":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_NON_CONTACTS);
break;
case "groups":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_GROUPS);
break;
case "channels":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_CHANNELS);
break;
case "bots":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_BOTS);
break;
case "muted":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_MUTED);
break;
case "read":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_READ);
break;
case "archived":
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_FILTER_ARCHIVED);
break;
2015-09-24 22:52:02 +02:00
}
2020-03-30 14:00:09 +02:00
avatarImageView.setImage(null, "50_50", avatarDrawable);
currentStatus = "";
2018-07-30 04:07:02 +02:00
} else {
2020-03-30 14:00:09 +02:00
((LayoutParams) nameTextView.getLayoutParams()).topMargin = AndroidUtilities.dp(10);
if (currentUser != null) {
if (selfAsSavedMessages && UserObject.isUserSelf(currentUser)) {
nameTextView.setText(LocaleController.getString("SavedMessages", R.string.SavedMessages), true);
statusTextView.setText(null);
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
avatarImageView.setImage(null, "50_50", avatarDrawable, currentUser);
((LayoutParams) nameTextView.getLayoutParams()).topMargin = AndroidUtilities.dp(19);
return;
}
avatarDrawable.setInfo(currentUser);
if (currentUser.status != null) {
lastStatus = currentUser.status.expires;
} else {
lastStatus = 0;
}
} else if (currentChat != null) {
avatarDrawable.setInfo(currentChat);
} else if (currentName != null) {
avatarDrawable.setInfo(currentId, currentName.toString(), null);
} else {
avatarDrawable.setInfo(currentId, "#", null);
}
}
2014-11-12 23:16:59 +01:00
if (currentName != null) {
lastName = null;
2014-11-12 23:16:59 +01:00
nameTextView.setText(currentName);
} else {
2015-09-24 22:52:02 +02:00
if (currentUser != null) {
lastName = newName == null ? UserObject.getUserName(currentUser) : newName;
2019-09-10 12:56:11 +02:00
} else if (currentChat != null) {
2015-09-24 22:52:02 +02:00
lastName = newName == null ? currentChat.title : newName;
2019-09-10 12:56:11 +02:00
} else {
lastName = "";
2015-09-24 22:52:02 +02:00
}
nameTextView.setText(lastName);
}
2019-05-14 14:08:05 +02:00
if (currentStatus != null) {
2014-11-12 23:16:59 +01:00
statusTextView.setTextColor(statusColor);
2019-05-14 14:08:05 +02:00
statusTextView.setText(currentStatus);
2015-09-24 22:52:02 +02:00
} else if (currentUser != null) {
2015-11-26 22:04:02 +01:00
if (currentUser.bot) {
2014-11-12 23:16:59 +01:00
statusTextView.setTextColor(statusColor);
2019-01-23 18:03:33 +01:00
if (currentUser.bot_chat_history || adminTextView != null && adminTextView.getVisibility() == VISIBLE) {
2015-06-29 19:12:11 +02:00
statusTextView.setText(LocaleController.getString("BotStatusRead", R.string.BotStatusRead));
} else {
statusTextView.setText(LocaleController.getString("BotStatusCantRead", R.string.BotStatusCantRead));
}
} else {
2018-07-30 04:07:02 +02:00
if (currentUser.id == UserConfig.getInstance(currentAccount).getClientUserId() || currentUser.status != null && currentUser.status.expires > ConnectionsManager.getInstance(currentAccount).getCurrentTime() || MessagesController.getInstance(currentAccount).onlinePrivacy.containsKey(currentUser.id)) {
2015-06-29 19:12:11 +02:00
statusTextView.setTextColor(statusOnlineColor);
statusTextView.setText(LocaleController.getString("Online", R.string.Online));
} else {
statusTextView.setTextColor(statusColor);
2018-07-30 04:07:02 +02:00
statusTextView.setText(LocaleController.formatUserStatus(currentAccount, currentUser));
2015-06-29 19:12:11 +02:00
}
2014-10-21 22:35:16 +02:00
}
}
if (imageView.getVisibility() == VISIBLE && currentDrawable == 0 || imageView.getVisibility() == GONE && currentDrawable != 0) {
imageView.setVisibility(currentDrawable == 0 ? GONE : VISIBLE);
imageView.setImageResource(currentDrawable);
}
2019-05-14 14:08:05 +02:00
lastAvatar = photo;
if (currentUser != null) {
2021-04-14 03:44:46 +02:00
avatarImageView.setImage(ImageLocation.getForUserOrChat(currentUser, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(currentUser, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, currentUser);
2019-05-14 14:08:05 +02:00
} else if (currentChat != null) {
2021-04-14 03:44:46 +02:00
avatarImageView.setImage(ImageLocation.getForUserOrChat(currentChat, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(currentChat, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, currentChat);
2019-08-22 01:53:26 +02:00
} else {
avatarImageView.setImageDrawable(avatarDrawable);
2019-05-14 14:08:05 +02:00
}
2021-01-28 15:15:51 +01:00
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
if (adminTextView != null) {
adminTextView.setTextColor(Theme.getColor(Theme.key_profile_creatorIcon));
}
}
2015-10-29 18:10:07 +01:00
2020-03-30 14:00:09 +02:00
public void setSelfAsSavedMessages(boolean value) {
selfAsSavedMessages = value;
}
2015-10-29 18:10:07 +01:00
@Override
public boolean hasOverlappingRendering() {
return false;
}
2019-01-23 18:03:33 +01:00
@Override
protected void onDraw(Canvas canvas) {
if (needDivider) {
canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(68), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(68) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
}
}
2019-05-14 14:08:05 +02:00
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
super.onInitializeAccessibilityNodeInfo(info);
if (checkBoxBig != null && checkBoxBig.getVisibility() == VISIBLE) {
info.setCheckable(true);
info.setChecked(checkBoxBig.isChecked());
info.setClassName("android.widget.CheckBox");
} else if (checkBox != null && checkBox.getVisibility() == VISIBLE) {
info.setCheckable(true);
info.setChecked(checkBox.isChecked());
info.setClassName("android.widget.CheckBox");
}
}
}