2016-05-25 23:49:47 +02:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2016-05-25 23:49:47 +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.
|
2016-05-25 23:49:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
2017-03-31 01:58:05 +02:00
|
|
|
import android.graphics.RectF;
|
2016-05-25 23:49:47 +02:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
|
|
|
import android.view.View;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.messenger.UserObject;
|
|
|
|
import org.telegram.tgnet.ConnectionsManager;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2017-03-31 01:58:05 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2021-01-28 15:15:51 +01:00
|
|
|
import org.telegram.ui.Components.CounterView;
|
2016-05-25 23:49:47 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
|
|
|
|
public class HintDialogCell extends FrameLayout {
|
|
|
|
|
|
|
|
private BackupImageView imageView;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private AvatarDrawable avatarDrawable = new AvatarDrawable();
|
2017-03-31 01:58:05 +02:00
|
|
|
private RectF rect = new RectF();
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
private int lastUnreadCount;
|
2019-01-23 18:03:33 +01:00
|
|
|
private TLRPC.User currentUser;
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
private long dialog_id;
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount = UserConfig.selectedAccount;
|
2021-01-28 15:15:51 +01:00
|
|
|
float showOnlineProgress;
|
|
|
|
boolean wasDraw;
|
|
|
|
|
|
|
|
CounterView counterView;
|
2016-05-25 23:49:47 +02:00
|
|
|
|
|
|
|
public HintDialogCell(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
|
|
|
imageView = new BackupImageView(context);
|
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(27));
|
|
|
|
addView(imageView, LayoutHelper.createFrame(54, 54, Gravity.TOP | Gravity.CENTER_HORIZONTAL, 0, 7, 0, 0));
|
|
|
|
|
|
|
|
nameTextView = new TextView(context);
|
2017-03-31 01:58:05 +02:00
|
|
|
nameTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
|
2016-05-25 23:49:47 +02:00
|
|
|
nameTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
2019-01-23 18:03:33 +01:00
|
|
|
nameTextView.setMaxLines(1);
|
2016-05-25 23:49:47 +02:00
|
|
|
nameTextView.setGravity(Gravity.TOP | Gravity.CENTER_HORIZONTAL);
|
2019-01-23 18:03:33 +01:00
|
|
|
nameTextView.setLines(1);
|
2016-05-25 23:49:47 +02:00
|
|
|
nameTextView.setEllipsize(TextUtils.TruncateAt.END);
|
|
|
|
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));
|
2021-01-28 15:15:51 +01:00
|
|
|
|
|
|
|
counterView = new CounterView(context);
|
|
|
|
addView(counterView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 28, Gravity.TOP,0 ,4,0,0));
|
|
|
|
counterView.setColors(Theme.key_chats_unreadCounterText, Theme.key_chats_unreadCounter);
|
|
|
|
counterView.setGravity(Gravity.RIGHT);
|
2016-05-25 23:49:47 +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(86), MeasureSpec.EXACTLY));
|
2021-01-28 15:15:51 +01:00
|
|
|
counterView.horizontalPadding = AndroidUtilities.dp(13);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void update(int mask) {
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
|
|
|
if (currentUser != null) {
|
|
|
|
currentUser = MessagesController.getInstance(currentAccount).getUser(currentUser.id);
|
|
|
|
imageView.invalidate();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
if (mask != 0 && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) == 0 && (mask & MessagesController.UPDATE_MASK_NEW_MESSAGE) == 0) {
|
|
|
|
return;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance(currentAccount).dialogs_dict.get(dialog_id);
|
2016-05-25 23:49:47 +02:00
|
|
|
if (dialog != null && dialog.unread_count != 0) {
|
|
|
|
if (lastUnreadCount != dialog.unread_count) {
|
|
|
|
lastUnreadCount = dialog.unread_count;
|
2021-01-28 15:15:51 +01:00
|
|
|
counterView.setCount(lastUnreadCount, wasDraw);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
} else {
|
2016-05-25 23:49:47 +02:00
|
|
|
lastUnreadCount = 0;
|
2021-01-28 15:15:51 +01:00
|
|
|
counterView.setCount(0, wasDraw);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-03-31 01:58:05 +02:00
|
|
|
public void update() {
|
|
|
|
int uid = (int) dialog_id;
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (uid > 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
currentUser = MessagesController.getInstance(currentAccount).getUser(uid);
|
|
|
|
avatarDrawable.setInfo(currentUser);
|
2017-03-31 01:58:05 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-uid);
|
2017-03-31 01:58:05 +02:00
|
|
|
avatarDrawable.setInfo(chat);
|
2019-01-23 18:03:33 +01:00
|
|
|
currentUser = null;
|
2017-03-31 01:58:05 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public void setDialog(int uid, boolean counter, CharSequence name) {
|
2021-01-28 15:15:51 +01:00
|
|
|
if (dialog_id != uid) {
|
|
|
|
wasDraw = false;
|
|
|
|
invalidate();
|
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
dialog_id = uid;
|
|
|
|
if (uid > 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
currentUser = MessagesController.getInstance(currentAccount).getUser(uid);
|
2016-05-25 23:49:47 +02:00
|
|
|
if (name != null) {
|
|
|
|
nameTextView.setText(name);
|
2019-01-23 18:03:33 +01:00
|
|
|
} else if (currentUser != null) {
|
|
|
|
nameTextView.setText(UserObject.getFirstName(currentUser));
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
avatarDrawable.setInfo(currentUser);
|
2021-04-14 03:44:46 +02:00
|
|
|
imageView.setImage(ImageLocation.getForUserOrChat(currentUser, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(currentUser, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, currentUser);
|
2016-05-25 23:49:47 +02:00
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
TLRPC.Chat chat = MessagesController.getInstance(currentAccount).getChat(-uid);
|
2016-05-25 23:49:47 +02:00
|
|
|
if (name != null) {
|
|
|
|
nameTextView.setText(name);
|
|
|
|
} else if (chat != null) {
|
|
|
|
nameTextView.setText(chat.title);
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
|
|
|
avatarDrawable.setInfo(chat);
|
2019-01-23 18:03:33 +01:00
|
|
|
currentUser = null;
|
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);
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (counter) {
|
2019-01-23 18:03:33 +01:00
|
|
|
update(0);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
|
|
|
|
boolean result = super.drawChild(canvas, child, drawingTime);
|
2019-01-23 18:03:33 +01:00
|
|
|
if (child == imageView) {
|
2021-01-28 15:15:51 +01:00
|
|
|
boolean showOnline = currentUser != null && !currentUser.bot && (currentUser.status != null && currentUser.status.expires > ConnectionsManager.getInstance(currentAccount).getCurrentTime() || MessagesController.getInstance(currentAccount).onlinePrivacy.containsKey(currentUser.id));
|
|
|
|
if (!wasDraw) {
|
|
|
|
showOnlineProgress = showOnline ? 1f : 0f;
|
|
|
|
}
|
|
|
|
if (showOnline && showOnlineProgress != 1f) {
|
|
|
|
showOnlineProgress += 16f / 150;
|
|
|
|
if (showOnlineProgress > 1) {
|
|
|
|
showOnlineProgress = 1f;
|
|
|
|
}
|
|
|
|
invalidate();
|
|
|
|
} else if (!showOnline && showOnlineProgress != 0) {
|
|
|
|
showOnlineProgress -= 16f / 150;
|
|
|
|
if (showOnlineProgress < 0) {
|
|
|
|
showOnlineProgress = 0;
|
|
|
|
}
|
|
|
|
invalidate();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
if (showOnlineProgress != 0) {
|
2019-01-23 18:03:33 +01:00
|
|
|
int top = AndroidUtilities.dp(53);
|
|
|
|
int left = AndroidUtilities.dp(59);
|
2021-01-28 15:15:51 +01:00
|
|
|
canvas.save();
|
|
|
|
canvas.scale(showOnlineProgress, showOnlineProgress, left, top);
|
2019-01-23 18:03:33 +01:00
|
|
|
Theme.dialogs_onlineCirclePaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
|
|
|
|
canvas.drawCircle(left, top, AndroidUtilities.dp(7), Theme.dialogs_onlineCirclePaint);
|
|
|
|
Theme.dialogs_onlineCirclePaint.setColor(Theme.getColor(Theme.key_chats_onlineCircle));
|
|
|
|
canvas.drawCircle(left, top, AndroidUtilities.dp(5), Theme.dialogs_onlineCirclePaint);
|
2021-01-28 15:15:51 +01:00
|
|
|
canvas.restore();
|
2019-01-23 18:03:33 +01:00
|
|
|
}
|
2021-01-28 15:15:51 +01:00
|
|
|
wasDraw = true;
|
2016-05-25 23:49:47 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|