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

262 lines
12 KiB
Java
Raw Normal View History

2017-03-31 01:58:05 +02:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2017-03-31 01:58:05 +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-03-31 01:58:05 +02:00
*/
package org.telegram.ui.Cells;
import android.content.Context;
2019-12-31 14:08:08 +01:00
import android.graphics.Canvas;
2019-06-04 12:14:50 +02:00
import android.text.TextUtils;
2017-03-31 01:58:05 +02:00
import android.view.Gravity;
import android.widget.FrameLayout;
import org.telegram.messenger.AndroidUtilities;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2017-03-31 01:58:05 +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-03-31 01:58:05 +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;
2019-06-04 12:14:50 +02:00
import org.telegram.ui.Components.CheckBox2;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.Components.LayoutHelper;
public class GroupCreateUserCell extends FrameLayout {
private BackupImageView avatarImageView;
private SimpleTextView nameTextView;
private SimpleTextView statusTextView;
2019-06-04 12:14:50 +02:00
private CheckBox2 checkBox;
2017-03-31 01:58:05 +02:00
private AvatarDrawable avatarDrawable;
2019-06-04 12:14:50 +02:00
private TLObject currentObject;
2017-03-31 01:58:05 +02:00
private CharSequence currentName;
private CharSequence currentStatus;
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
2017-03-31 01:58:05 +02:00
private String lastName;
private int lastStatus;
private TLRPC.FileLocation lastAvatar;
2019-12-31 14:08:08 +01:00
private boolean drawDivider;
private int padding;
2019-01-23 18:03:33 +01:00
public GroupCreateUserCell(Context context, boolean needCheck, int padding) {
2017-03-31 01:58:05 +02:00
super(context);
2019-12-31 14:08:08 +01:00
drawDivider = false;
this.padding = padding;
2017-03-31 01:58:05 +02:00
avatarDrawable = new AvatarDrawable();
avatarImageView = new BackupImageView(context);
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 : (13 + padding), 6, LocaleController.isRTL ? (13 + padding) : 0, 0));
2017-03-31 01:58:05 +02:00
nameTextView = new SimpleTextView(context);
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
nameTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
2019-01-23 18:03:33 +01:00
nameTextView.setTextSize(16);
2017-03-31 01:58:05 +02:00
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 : 72) + padding, 10, (LocaleController.isRTL ? 72 : 28) + padding, 0));
2017-03-31 01:58:05 +02:00
statusTextView = new SimpleTextView(context);
2019-12-31 14:08:08 +01:00
statusTextView.setTextSize(14);
2017-03-31 01:58:05 +02:00
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 : 72) + padding, 32, (LocaleController.isRTL ? 72 : 28) + padding, 0));
2017-03-31 01:58:05 +02:00
if (needCheck) {
2019-08-22 01:53:26 +02:00
checkBox = new CheckBox2(context, 21);
2019-06-04 12:14:50 +02:00
checkBox.setColor(null, Theme.key_windowBackgroundWhite, Theme.key_checkboxCheck);
checkBox.setDrawUnchecked(false);
checkBox.setDrawBackgroundAsArc(3);
addView(checkBox, LayoutHelper.createFrame(24, 24, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 40, 33, LocaleController.isRTL ? 39 : 0, 0));
2017-03-31 01:58:05 +02:00
}
2019-12-31 14:08:08 +01:00
setWillNotDraw(false);
}
public void setObject(TLObject object, CharSequence name, CharSequence status, boolean drawDivider) {
setObject(object, name, status);
this.drawDivider = drawDivider;
2017-03-31 01:58:05 +02:00
}
2019-06-04 12:14:50 +02:00
public void setObject(TLObject object, CharSequence name, CharSequence status) {
currentObject = object;
2017-03-31 01:58:05 +02:00
currentStatus = status;
currentName = name;
2019-12-31 14:08:08 +01:00
drawDivider = false;
2017-03-31 01:58:05 +02:00
update(0);
}
public void setChecked(boolean checked, boolean animated) {
checkBox.setChecked(checked, animated);
}
2019-06-04 12:14:50 +02:00
public void setCheckBoxEnabled(boolean enabled) {
checkBox.setEnabled(enabled);
}
public TLObject getObject() {
return currentObject;
2017-03-31 01:58:05 +02: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), MeasureSpec.EXACTLY));
2017-03-31 01:58:05 +02:00
}
public void recycle() {
avatarImageView.getImageReceiver().cancelLoadImage();
}
public void update(int mask) {
2019-06-04 12:14:50 +02:00
if (currentObject == null) {
2017-03-31 01:58:05 +02:00
return;
}
TLRPC.FileLocation photo = null;
String newName = null;
2019-06-04 12:14:50 +02:00
if (currentObject instanceof TLRPC.User) {
TLRPC.User currentUser = (TLRPC.User) currentObject;
if (currentUser.photo != null) {
photo = currentUser.photo.photo_small;
2017-03-31 01:58:05 +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-03-31 01:58:05 +02:00
}
2019-06-04 12:14:50 +02:00
if (currentUser != null && currentStatus == 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-03-31 01:58:05 +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-03-31 01:58:05 +02:00
}
}
2019-06-04 12:14:50 +02:00
avatarDrawable.setInfo(currentUser);
lastStatus = currentUser.status != null ? currentUser.status.expires : 0;
if (currentName != null) {
lastName = null;
nameTextView.setText(currentName, true);
} else {
lastName = newName == null ? UserObject.getUserName(currentUser) : newName;
nameTextView.setText(lastName);
2017-03-31 01:58:05 +02:00
}
2019-06-04 12:14:50 +02:00
if (currentStatus == null) {
if (currentUser.bot) {
statusTextView.setTag(Theme.key_windowBackgroundWhiteGrayText);
statusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
statusTextView.setText(LocaleController.getString("Bot", R.string.Bot));
} else {
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.setTag(Theme.key_windowBackgroundWhiteBlueText);
statusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText));
statusTextView.setText(LocaleController.getString("Online", R.string.Online));
} else {
statusTextView.setTag(Theme.key_windowBackgroundWhiteGrayText);
statusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
statusTextView.setText(LocaleController.formatUserStatus(currentAccount, currentUser));
}
}
}
2017-03-31 01:58:05 +02:00
2019-06-04 12:14:50 +02:00
avatarImageView.setImage(ImageLocation.getForUser(currentUser, false), "50_50", avatarDrawable, currentUser);
2017-03-31 01:58:05 +02:00
} else {
2019-06-04 12:14:50 +02:00
TLRPC.Chat currentChat = (TLRPC.Chat) currentObject;
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;
}
}
2017-03-31 01:58:05 +02:00
2019-06-04 12:14:50 +02:00
avatarDrawable.setInfo(currentChat);
if (currentName != null) {
lastName = null;
nameTextView.setText(currentName, true);
} else {
lastName = newName == null ? currentChat.title : newName;
nameTextView.setText(lastName);
}
if (currentStatus == null) {
2019-01-23 18:03:33 +01:00
statusTextView.setTag(Theme.key_windowBackgroundWhiteGrayText);
statusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
2019-06-04 12:14:50 +02:00
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-03-31 01:58:05 +02:00
} else {
2019-06-04 12:14:50 +02:00
statusTextView.setText(LocaleController.getString("MegaPublic", R.string.MegaPublic));
2017-03-31 01:58:05 +02:00
}
}
2019-06-04 12:14:50 +02:00
avatarImageView.setImage(ImageLocation.getForChat(currentChat, false), "50_50", avatarDrawable, currentChat);
2017-03-31 01:58:05 +02:00
}
2019-06-04 12:14:50 +02:00
if (currentStatus != null) {
statusTextView.setText(currentStatus, true);
statusTextView.setTag(Theme.key_windowBackgroundWhiteGrayText);
statusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
}
2017-03-31 01:58:05 +02:00
}
2019-12-31 14:08:08 +01:00
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
if (drawDivider) {
int start = AndroidUtilities.dp(LocaleController.isRTL ? 0 : 72 + padding);
int end = getMeasuredWidth() - AndroidUtilities.dp(!LocaleController.isRTL ? 0 : 72 + padding);
canvas.drawRect(start, getMeasuredHeight() - 1, end, getMeasuredHeight(), Theme.dividerPaint);
}
}
2017-03-31 01:58:05 +02:00
@Override
public boolean hasOverlappingRendering() {
return false;
}
}