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

198 lines
9.1 KiB
Java
Raw Normal View History

2015-11-26 22:04:02 +01:00
/*
2019-01-23 18:03:33 +01:00
* This is the source code of Telegram for Android v. 5.x.x.
2015-11-26 22:04:02 +01: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.
2015-11-26 22:04:02 +01:00
*/
package org.telegram.ui.Cells;
import android.content.Context;
2019-05-14 14:08:05 +02:00
import android.graphics.Canvas;
import android.os.SystemClock;
2015-11-26 22:04:02 +01:00
import android.text.TextUtils;
import android.util.TypedValue;
import android.view.Gravity;
2019-05-14 14:08:05 +02:00
import android.view.View;
2015-11-26 22:04:02 +01:00
import android.widget.FrameLayout;
import android.widget.TextView;
import org.telegram.messenger.AndroidUtilities;
import org.telegram.messenger.ContactsController;
2019-05-14 14:08:05 +02:00
import org.telegram.messenger.ImageLocation;
2017-12-08 18:35:59 +01:00
import org.telegram.messenger.LocaleController;
2015-11-26 22:04:02 +01:00
import org.telegram.messenger.MessagesController;
import org.telegram.messenger.R;
2018-07-30 04:07:02 +02:00
import org.telegram.messenger.UserConfig;
2017-12-08 18:35:59 +01:00
import org.telegram.messenger.UserObject;
2019-05-14 14:08:05 +02:00
import org.telegram.tgnet.ConnectionsManager;
2015-11-26 22:04:02 +01:00
import org.telegram.tgnet.TLRPC;
2017-03-31 01:58:05 +02:00
import org.telegram.ui.ActionBar.Theme;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Components.AvatarDrawable;
import org.telegram.ui.Components.BackupImageView;
2019-05-14 14:08:05 +02:00
import org.telegram.ui.Components.CheckBox2;
2015-11-26 22:04:02 +01:00
import org.telegram.ui.Components.LayoutHelper;
public class ShareDialogCell extends FrameLayout {
private BackupImageView imageView;
private TextView nameTextView;
2019-05-14 14:08:05 +02:00
private CheckBox2 checkBox;
2015-11-26 22:04:02 +01:00
private AvatarDrawable avatarDrawable = new AvatarDrawable();
2019-05-14 14:08:05 +02:00
private TLRPC.User user;
2021-04-14 03:44:46 +02:00
private int currentType;
2019-05-14 14:08:05 +02:00
private float onlineProgress;
private long lastUpdateTime;
2021-04-14 03:44:46 +02:00
private long currentDialog;
2015-11-26 22:04:02 +01:00
2018-07-30 04:07:02 +02:00
private int currentAccount = UserConfig.selectedAccount;
2021-04-14 03:44:46 +02:00
public static final int TYPE_SHARE = 0;
public static final int TYPE_CALL = 1;
public static final int TYPE_CREATE = 2;
public ShareDialogCell(Context context, int type) {
2015-11-26 22:04:02 +01:00
super(context);
2019-05-14 14:08:05 +02:00
setWillNotDraw(false);
2021-04-14 03:44:46 +02:00
currentType = type;
2019-05-14 14:08:05 +02:00
2015-11-26 22:04:02 +01:00
imageView = new BackupImageView(context);
2019-05-14 14:08:05 +02:00
imageView.setRoundRadius(AndroidUtilities.dp(28));
2021-04-14 03:44:46 +02:00
if (type == TYPE_CREATE) {
addView(imageView, LayoutHelper.createFrame(48, 48, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));
} else {
addView(imageView, LayoutHelper.createFrame(56, 56, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));
}
2015-11-26 22:04:02 +01:00
nameTextView = new TextView(context);
2021-04-14 03:44:46 +02:00
nameTextView.setTextColor(Theme.getColor(type == TYPE_CALL ? Theme.key_voipgroup_nameText : Theme.key_dialogTextBlack));
2015-11-26 22:04:02 +01:00
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
nameTextView.setMaxLines(2);
nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
nameTextView.setLines(2);
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
2021-04-14 03:44:46 +02:00
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, currentType == TYPE_CREATE ? 58 : 66, 6, 0));
2019-05-14 14:08:05 +02:00
2019-08-22 01:53:26 +02:00
checkBox = new CheckBox2(context, 21);
2021-04-14 03:44:46 +02:00
checkBox.setColor(Theme.key_dialogRoundCheckBox, type == TYPE_CALL ? Theme.key_voipgroup_inviteMembersBackground : Theme.key_dialogBackground, Theme.key_dialogRoundCheckBoxCheck);
2019-05-14 14:08:05 +02:00
checkBox.setDrawUnchecked(false);
checkBox.setDrawBackgroundAsArc(4);
checkBox.setProgressDelegate(progress -> {
float scale = 1.0f - (1.0f - 0.857f) * checkBox.getProgress();
imageView.setScaleX(scale);
imageView.setScaleY(scale);
2021-04-14 03:44:46 +02:00
invalidate();
2019-05-14 14:08:05 +02:00
});
2021-04-14 03:44:46 +02:00
addView(checkBox, LayoutHelper.createFrame(24, 24, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 19, currentType == TYPE_CREATE ? -40 : 42, 0, 0));
2015-11-26 22:04:02 +01:00
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
2021-04-14 03:44:46 +02:00
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(currentType == TYPE_CREATE ? 95 : 103), MeasureSpec.EXACTLY));
2015-11-26 22:04:02 +01:00
}
2016-05-25 23:49:47 +02:00
public void setDialog(int uid, boolean checked, CharSequence name) {
if (uid > 0) {
2019-05-14 14:08:05 +02:00
user = MessagesController.getInstance(currentAccount).getUser(uid);
2015-11-26 22:04:02 +01:00
avatarDrawable.setInfo(user);
2021-04-14 03:44:46 +02:00
if (currentType != TYPE_CREATE && UserObject.isReplyUser(user)) {
2020-09-30 15:48:47 +02:00
nameTextView.setText(LocaleController.getString("RepliesTitle", R.string.RepliesTitle));
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_REPLIES);
imageView.setImage(null, null, avatarDrawable, user);
2021-04-14 03:44:46 +02:00
} else if (currentType != TYPE_CREATE && UserObject.isUserSelf(user)) {
2017-12-08 18:35:59 +01:00
nameTextView.setText(LocaleController.getString("SavedMessages", R.string.SavedMessages));
2019-05-14 14:08:05 +02:00
avatarDrawable.setAvatarType(AvatarDrawable.AVATAR_TYPE_SAVED);
imageView.setImage(null, null, avatarDrawable, user);
2017-12-08 18:35:59 +01:00
} else {
if (name != null) {
nameTextView.setText(name);
} else if (user != null) {
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
} else {
nameTextView.setText("");
}
2021-04-14 03:44:46 +02:00
imageView.setImage(ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, user);
2015-11-26 22:04:02 +01:00
}
} else {
2019-05-14 14:08:05 +02:00
user = null;
2018-07-30 04:07:02 +02:00
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-uid);
2015-11-26 22:04:02 +01:00
if (name != null) {
nameTextView.setText(name);
} else if (chat != null) {
nameTextView.setText(chat.title);
} else {
nameTextView.setText("");
}
avatarDrawable.setInfo(chat);
2021-04-14 03:44:46 +02:00
imageView.setImage(ImageLocation.getForUserOrChat(chat, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(chat, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, chat);
2015-11-26 22:04:02 +01:00
}
2021-04-14 03:44:46 +02:00
currentDialog = uid;
2015-11-26 22:04:02 +01:00
checkBox.setChecked(checked, false);
}
2021-04-14 03:44:46 +02:00
public long getCurrentDialog() {
return currentDialog;
}
2015-11-26 22:04:02 +01:00
public void setChecked(boolean checked, boolean animated) {
checkBox.setChecked(checked, animated);
}
2019-05-14 14:08:05 +02:00
@Override
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
boolean result = super.drawChild(canvas, child, drawingTime);
2021-04-14 03:44:46 +02:00
if (child == imageView && currentType != TYPE_CREATE) {
2019-05-14 14:08:05 +02:00
if (user != null && !MessagesController.isSupportUser(user)) {
2020-01-23 07:15:40 +01:00
long newTime = SystemClock.elapsedRealtime();
2019-05-14 14:08:05 +02:00
long dt = newTime - lastUpdateTime;
if (dt > 17) {
dt = 17;
}
lastUpdateTime = newTime;
boolean isOnline = !user.self && !user.bot && (user.status != null && user.status.expires > ConnectionsManager.getInstance(currentAccount).getCurrentTime() || MessagesController.getInstance(currentAccount).onlinePrivacy.containsKey(user.id));
if (isOnline || onlineProgress != 0) {
int top = imageView.getBottom() - AndroidUtilities.dp(6);
int left = imageView.getRight() - AndroidUtilities.dp(10);
2021-04-14 03:44:46 +02:00
Theme.dialogs_onlineCirclePaint.setColor(Theme.getColor(currentType == TYPE_CALL ? Theme.key_voipgroup_inviteMembersBackground : Theme.key_windowBackgroundWhite));
2019-05-14 14:08:05 +02:00
canvas.drawCircle(left, top, AndroidUtilities.dp(7) * onlineProgress, Theme.dialogs_onlineCirclePaint);
Theme.dialogs_onlineCirclePaint.setColor(Theme.getColor(Theme.key_chats_onlineCircle));
canvas.drawCircle(left, top, AndroidUtilities.dp(5) * onlineProgress, Theme.dialogs_onlineCirclePaint);
if (isOnline) {
if (onlineProgress < 1.0f) {
onlineProgress += dt / 150.0f;
if (onlineProgress > 1.0f) {
onlineProgress = 1.0f;
}
imageView.invalidate();
invalidate();
}
} else {
if (onlineProgress > 0.0f) {
onlineProgress -= dt / 150.0f;
if (onlineProgress < 0.0f) {
onlineProgress = 0.0f;
}
imageView.invalidate();
invalidate();
}
}
}
}
}
return result;
}
@Override
protected void onDraw(Canvas canvas) {
int cx = imageView.getLeft() + imageView.getMeasuredWidth() / 2;
int cy = imageView.getTop() + imageView.getMeasuredHeight() / 2;
Theme.checkboxSquare_checkPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
Theme.checkboxSquare_checkPaint.setAlpha((int) (checkBox.getProgress() * 255));
2021-04-14 03:44:46 +02:00
canvas.drawCircle(cx, cy, AndroidUtilities.dp(24), Theme.checkboxSquare_checkPaint);
2019-05-14 14:08:05 +02:00
}
2015-11-26 22:04:02 +01:00
}