2017-07-08 18:32:04 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2017-07-08 18:32:04 +02:00
|
|
|
* 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.
|
2017-07-08 18:32:04 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-01-23 18:03:33 +01:00
|
|
|
import android.graphics.Canvas;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.graphics.PorterDuff;
|
|
|
|
import android.graphics.PorterDuffColorFilter;
|
2019-06-04 12:14:50 +02:00
|
|
|
import android.text.TextUtils;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
|
|
|
import org.telegram.messenger.UserObject;
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2019-06-04 12:14:50 +02:00
|
|
|
import org.telegram.tgnet.TLObject;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.ui.ActionBar.SimpleTextView;
|
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
|
|
|
|
public class ManageChatUserCell extends FrameLayout {
|
|
|
|
|
|
|
|
private BackupImageView avatarImageView;
|
|
|
|
private SimpleTextView nameTextView;
|
|
|
|
private SimpleTextView statusTextView;
|
|
|
|
private ImageView optionsButton;
|
|
|
|
|
|
|
|
private AvatarDrawable avatarDrawable;
|
2019-06-04 12:14:50 +02:00
|
|
|
private TLObject currentObject;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
private CharSequence currentName;
|
|
|
|
private CharSequence currrntStatus;
|
|
|
|
|
|
|
|
private String lastName;
|
|
|
|
private int lastStatus;
|
|
|
|
private TLRPC.FileLocation lastAvatar;
|
2017-12-08 18:35:59 +01:00
|
|
|
private boolean isAdmin;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private boolean needDivider;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private int statusColor;
|
|
|
|
private int statusOnlineColor;
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private int namePadding;
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount = UserConfig.selectedAccount;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
private ManageChatUserCellDelegate delegate;
|
|
|
|
|
|
|
|
public interface ManageChatUserCellDelegate {
|
|
|
|
boolean onOptionsButtonCheck(ManageChatUserCell cell, boolean click);
|
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public ManageChatUserCell(Context context, int avatarPadding, int nPadding, boolean needOption) {
|
2017-07-08 18:32:04 +02:00
|
|
|
super(context);
|
|
|
|
|
|
|
|
statusColor = Theme.getColor(Theme.key_windowBackgroundWhiteGrayText);
|
|
|
|
statusOnlineColor = Theme.getColor(Theme.key_windowBackgroundWhiteBlueText);
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
namePadding = nPadding;
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
avatarDrawable = new AvatarDrawable();
|
|
|
|
|
|
|
|
avatarImageView = new BackupImageView(context);
|
2019-01-23 18:03:33 +01:00
|
|
|
avatarImageView.setRoundRadius(AndroidUtilities.dp(23));
|
|
|
|
addView(avatarImageView, LayoutHelper.createFrame(46, 46, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 7 + avatarPadding, 8, LocaleController.isRTL ? 7 + avatarPadding : 0, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
nameTextView = new SimpleTextView(context);
|
|
|
|
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
|
|
|
nameTextView.setTextSize(17);
|
|
|
|
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
|
|
|
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
2019-01-23 18:03:33 +01:00
|
|
|
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 + 18 : (68 + namePadding), 11.5f, LocaleController.isRTL ? (68 + namePadding) : 28 + 18, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
statusTextView = new SimpleTextView(context);
|
|
|
|
statusTextView.setTextSize(14);
|
|
|
|
statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
2019-01-23 18:03:33 +01:00
|
|
|
addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : (68 + namePadding), 34.5f, LocaleController.isRTL ? (68 + namePadding) : 28, 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
|
|
|
|
if (needOption) {
|
|
|
|
optionsButton = new ImageView(context);
|
|
|
|
optionsButton.setFocusable(false);
|
|
|
|
optionsButton.setBackgroundDrawable(Theme.createSelectorDrawable(Theme.getColor(Theme.key_stickers_menuSelector)));
|
|
|
|
optionsButton.setImageResource(R.drawable.ic_ab_other);
|
2020-06-25 17:12:58 +02:00
|
|
|
optionsButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_stickers_menu), PorterDuff.Mode.SRC_IN));
|
2017-07-08 18:32:04 +02:00
|
|
|
optionsButton.setScaleType(ImageView.ScaleType.CENTER);
|
2019-01-23 18:03:33 +01:00
|
|
|
addView(optionsButton, LayoutHelper.createFrame(52, 64, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.TOP));
|
2018-08-27 10:33:11 +02:00
|
|
|
optionsButton.setOnClickListener(v -> delegate.onOptionsButtonCheck(ManageChatUserCell.this, true));
|
2019-05-14 14:08:05 +02:00
|
|
|
optionsButton.setContentDescription(LocaleController.getString("AccDescrUserOptions", R.string.AccDescrUserOptions));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public void setData(TLObject object, CharSequence name, CharSequence status, boolean divider) {
|
|
|
|
if (object == null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
currrntStatus = null;
|
|
|
|
currentName = null;
|
2019-06-04 12:14:50 +02:00
|
|
|
currentObject = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
nameTextView.setText("");
|
|
|
|
statusTextView.setText("");
|
|
|
|
avatarImageView.setImageDrawable(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currrntStatus = status;
|
|
|
|
currentName = name;
|
2019-06-04 12:14:50 +02:00
|
|
|
currentObject = object;
|
2017-07-08 18:32:04 +02:00
|
|
|
if (optionsButton != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
boolean visible = delegate.onOptionsButtonCheck(ManageChatUserCell.this, false);
|
|
|
|
optionsButton.setVisibility(visible ? VISIBLE : INVISIBLE);
|
|
|
|
nameTextView.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? (visible ? 46 : 28) : (68 + namePadding), status == null || status.length() > 0 ? 11.5f : 20.5f, LocaleController.isRTL ? (68 + namePadding) : (visible ? 46 : 28), 0));
|
|
|
|
statusTextView.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? (visible ? 46 : 28) : (68 + namePadding), 34.5f, LocaleController.isRTL ? (68 + namePadding) : (visible ? 46 : 28), 0));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
needDivider = divider;
|
|
|
|
setWillNotDraw(!needDivider);
|
2017-07-08 18:32:04 +02:00
|
|
|
update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
@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(64) + (needDivider ? 1 : 0), MeasureSpec.EXACTLY));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public int getUserId() {
|
|
|
|
if (currentObject instanceof TLRPC.User) {
|
|
|
|
return ((TLRPC.User) currentObject).id;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void setStatusColors(int color, int onlineColor) {
|
|
|
|
statusColor = color;
|
|
|
|
statusOnlineColor = onlineColor;
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setIsAdmin(boolean value) {
|
|
|
|
isAdmin = value;
|
|
|
|
}
|
|
|
|
|
2020-02-13 19:26:53 +01:00
|
|
|
public boolean hasAvatarSet() {
|
|
|
|
return avatarImageView.getImageReceiver().hasNotThumb();
|
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02:00
|
|
|
public void update(int mask) {
|
2019-06-04 12:14:50 +02:00
|
|
|
if (currentObject == null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
return;
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
if (currentObject instanceof TLRPC.User) {
|
|
|
|
TLRPC.User currentUser = (TLRPC.User) currentObject;
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
String newName = null;
|
|
|
|
if (currentUser.photo != null) {
|
|
|
|
photo = currentUser.photo.photo_small;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
|
|
|
|
if (mask != 0) {
|
|
|
|
boolean continueUpdate = false;
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
|
|
|
|
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;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
if (currentUser != null && !continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
|
|
|
int newStatus = 0;
|
|
|
|
if (currentUser.status != null) {
|
|
|
|
newStatus = currentUser.status.expires;
|
|
|
|
}
|
|
|
|
if (newStatus != lastStatus) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
if (!continueUpdate && currentName == null && lastName != null && (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
newName = UserObject.getUserName(currentUser);
|
|
|
|
if (!newName.equals(lastName)) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!continueUpdate) {
|
|
|
|
return;
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
avatarDrawable.setInfo(currentUser);
|
|
|
|
if (currentUser.status != null) {
|
|
|
|
lastStatus = currentUser.status.expires;
|
|
|
|
} else {
|
|
|
|
lastStatus = 0;
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
if (currentName != null) {
|
|
|
|
lastName = null;
|
|
|
|
nameTextView.setText(currentName);
|
|
|
|
} else {
|
|
|
|
lastName = newName == null ? UserObject.getUserName(currentUser) : newName;
|
|
|
|
nameTextView.setText(lastName);
|
|
|
|
}
|
|
|
|
if (currrntStatus != null) {
|
2017-07-08 18:32:04 +02:00
|
|
|
statusTextView.setTextColor(statusColor);
|
2019-06-04 12:14:50 +02:00
|
|
|
statusTextView.setText(currrntStatus);
|
|
|
|
} else {
|
|
|
|
if (currentUser.bot) {
|
|
|
|
statusTextView.setTextColor(statusColor);
|
|
|
|
if (currentUser.bot_chat_history || isAdmin) {
|
|
|
|
statusTextView.setText(LocaleController.getString("BotStatusRead", R.string.BotStatusRead));
|
|
|
|
} else {
|
|
|
|
statusTextView.setText(LocaleController.getString("BotStatusCantRead", R.string.BotStatusCantRead));
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +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)) {
|
|
|
|
statusTextView.setTextColor(statusOnlineColor);
|
|
|
|
statusTextView.setText(LocaleController.getString("Online", R.string.Online));
|
|
|
|
} else {
|
|
|
|
statusTextView.setTextColor(statusColor);
|
|
|
|
statusTextView.setText(LocaleController.formatUserStatus(currentAccount, currentUser));
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
}
|
|
|
|
lastAvatar = photo;
|
|
|
|
avatarImageView.setImage(ImageLocation.getForUser(currentUser, false), "50_50", avatarDrawable, currentUser);
|
|
|
|
} else if (currentObject instanceof TLRPC.Chat) {
|
|
|
|
TLRPC.Chat currentChat = (TLRPC.Chat) currentObject;
|
|
|
|
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
String newName = null;
|
|
|
|
if (currentChat.photo != null) {
|
|
|
|
photo = currentChat.photo.photo_small;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mask != 0) {
|
|
|
|
boolean continueUpdate = false;
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!continueUpdate && currentName == null && lastName != null && (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
newName = currentChat.title;
|
|
|
|
if (!newName.equals(lastName)) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!continueUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
avatarDrawable.setInfo(currentChat);
|
|
|
|
|
|
|
|
if (currentName != null) {
|
|
|
|
lastName = null;
|
|
|
|
nameTextView.setText(currentName);
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
lastName = newName == null ? currentChat.title : newName;
|
|
|
|
nameTextView.setText(lastName);
|
|
|
|
}
|
|
|
|
if (currrntStatus != null) {
|
|
|
|
statusTextView.setTextColor(statusColor);
|
|
|
|
statusTextView.setText(currrntStatus);
|
|
|
|
} else {
|
|
|
|
statusTextView.setTextColor(statusColor);
|
|
|
|
if (currentChat.participants_count != 0) {
|
|
|
|
statusTextView.setText(LocaleController.formatPluralString("Members", currentChat.participants_count));
|
2019-07-18 15:01:39 +02:00
|
|
|
} else if (currentChat.has_geo) {
|
|
|
|
statusTextView.setText(LocaleController.getString("MegaLocation", R.string.MegaLocation));
|
2019-06-04 12:14:50 +02:00
|
|
|
} else if (TextUtils.isEmpty(currentChat.username)) {
|
|
|
|
statusTextView.setText(LocaleController.getString("MegaPrivate", R.string.MegaPrivate));
|
2017-07-08 18:32:04 +02:00
|
|
|
} else {
|
2019-06-04 12:14:50 +02:00
|
|
|
statusTextView.setText(LocaleController.getString("MegaPublic", R.string.MegaPublic));
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
2019-06-04 12:14:50 +02:00
|
|
|
lastAvatar = photo;
|
|
|
|
avatarImageView.setImage(ImageLocation.getForChat(currentChat, false), "50_50", avatarDrawable, currentChat);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void recycle() {
|
|
|
|
avatarImageView.getImageReceiver().cancelLoadImage();
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(ManageChatUserCellDelegate manageChatUserCellDelegate) {
|
|
|
|
delegate = manageChatUserCellDelegate;
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public TLObject getCurrentObject() {
|
|
|
|
return currentObject;
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
|
|
|
|
2017-07-08 18:32:04 +02: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);
|
|
|
|
}
|
|
|
|
}
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|