2014-02-04 19:36:55 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 1.3.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).
|
|
|
|
*
|
2015-10-29 18:10:07 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2015.
|
2014-02-04 19:36:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
2014-10-21 22:35:16 +02:00
|
|
|
import android.graphics.Paint;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.graphics.drawable.Drawable;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.os.Build;
|
2014-02-04 19:36:55 +01:00
|
|
|
import android.text.Layout;
|
|
|
|
import android.text.StaticLayout;
|
|
|
|
import android.text.TextPaint;
|
|
|
|
import android.text.TextUtils;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.view.MotionEvent;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2014-02-04 19:36:55 +01:00
|
|
|
import org.telegram.PhoneFormat.PhoneFormat;
|
2015-11-26 22:04:02 +01:00
|
|
|
import org.telegram.messenger.ChatObject;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
|
|
|
import org.telegram.messenger.UserObject;
|
2014-09-14 01:40:36 +02:00
|
|
|
import org.telegram.messenger.FileLog;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.messenger.ContactsController;
|
|
|
|
import org.telegram.messenger.Emoji;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
2014-02-04 19:36:55 +01:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.UserConfig;
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
public class DialogCell extends BaseCell {
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private static TextPaint namePaint;
|
|
|
|
private static TextPaint nameEncryptedPaint;
|
|
|
|
private static TextPaint messagePaint;
|
|
|
|
private static TextPaint messagePrintingPaint;
|
|
|
|
private static TextPaint timePaint;
|
|
|
|
private static TextPaint countPaint;
|
|
|
|
|
|
|
|
private static Drawable checkDrawable;
|
|
|
|
private static Drawable halfCheckDrawable;
|
|
|
|
private static Drawable clockDrawable;
|
|
|
|
private static Drawable errorDrawable;
|
|
|
|
private static Drawable lockDrawable;
|
|
|
|
private static Drawable countDrawable;
|
2015-10-29 18:10:07 +01:00
|
|
|
private static Drawable countDrawableGrey;
|
2014-03-26 00:38:23 +01:00
|
|
|
private static Drawable groupDrawable;
|
2014-07-27 00:28:33 +02:00
|
|
|
private static Drawable broadcastDrawable;
|
2015-11-26 22:04:02 +01:00
|
|
|
private static Drawable botDrawable;
|
2015-02-01 19:51:02 +01:00
|
|
|
private static Drawable muteDrawable;
|
2015-10-29 18:10:07 +01:00
|
|
|
private static Drawable verifiedDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
private static Paint linePaint;
|
2015-05-21 23:27:27 +02:00
|
|
|
private static Paint backPaint;
|
2014-10-21 22:35:16 +02:00
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
private long currentDialogId;
|
2015-02-26 02:32:51 +01:00
|
|
|
private boolean isDialogCell;
|
2014-10-31 20:02:29 +01:00
|
|
|
private int lastMessageDate;
|
|
|
|
private int unreadCount;
|
2014-11-11 23:16:17 +01:00
|
|
|
private boolean lastUnreadState;
|
2015-02-26 02:32:51 +01:00
|
|
|
private int lastSendState;
|
2015-02-01 19:51:02 +01:00
|
|
|
private boolean dialogMuted;
|
2014-10-31 20:02:29 +01:00
|
|
|
private MessageObject message;
|
2015-02-26 02:32:51 +01:00
|
|
|
private int index;
|
2015-06-29 19:12:11 +02:00
|
|
|
private int dialogsType;
|
2014-10-31 20:02:29 +01:00
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
private ImageReceiver avatarImage;
|
2014-11-06 22:34:47 +01:00
|
|
|
private AvatarDrawable avatarDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
private TLRPC.User user = null;
|
|
|
|
private TLRPC.Chat chat = null;
|
|
|
|
private TLRPC.EncryptedChat encryptedChat = null;
|
|
|
|
private CharSequence lastPrintString = null;
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
public boolean useSeparator = false;
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private int nameLeft;
|
|
|
|
private StaticLayout nameLayout;
|
|
|
|
private boolean drawNameLock;
|
|
|
|
private boolean drawNameGroup;
|
|
|
|
private boolean drawNameBroadcast;
|
2015-11-26 22:04:02 +01:00
|
|
|
private boolean drawNameBot;
|
2015-02-01 19:51:02 +01:00
|
|
|
private int nameMuteLeft;
|
2014-11-06 22:34:47 +01:00
|
|
|
private int nameLockLeft;
|
|
|
|
private int nameLockTop;
|
|
|
|
|
|
|
|
private int timeLeft;
|
|
|
|
private int timeTop = AndroidUtilities.dp(17);
|
|
|
|
private StaticLayout timeLayout;
|
|
|
|
|
|
|
|
private boolean drawCheck1;
|
|
|
|
private boolean drawCheck2;
|
|
|
|
private boolean drawClock;
|
|
|
|
private int checkDrawLeft;
|
|
|
|
private int checkDrawTop = AndroidUtilities.dp(18);
|
|
|
|
private int halfCheckDrawLeft;
|
|
|
|
|
|
|
|
private int messageTop = AndroidUtilities.dp(40);
|
|
|
|
private int messageLeft;
|
|
|
|
private StaticLayout messageLayout;
|
|
|
|
|
|
|
|
private boolean drawError;
|
|
|
|
private int errorTop = AndroidUtilities.dp(39);
|
|
|
|
private int errorLeft;
|
|
|
|
|
|
|
|
private boolean drawCount;
|
|
|
|
private int countTop = AndroidUtilities.dp(39);
|
|
|
|
private int countLeft;
|
|
|
|
private int countWidth;
|
|
|
|
private StaticLayout countLayout;
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
private boolean drawVerified;
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private int avatarTop = AndroidUtilities.dp(10);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
private boolean isSelected;
|
|
|
|
|
|
|
|
public DialogCell(Context context) {
|
|
|
|
super(context);
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
if (namePaint == null) {
|
|
|
|
namePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-11-06 22:34:47 +01:00
|
|
|
namePaint.setTextSize(AndroidUtilities.dp(17));
|
2014-11-13 21:10:14 +01:00
|
|
|
namePaint.setColor(0xff212121);
|
2014-07-03 00:39:05 +02:00
|
|
|
namePaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
nameEncryptedPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-11-06 22:34:47 +01:00
|
|
|
nameEncryptedPaint.setTextSize(AndroidUtilities.dp(17));
|
2014-02-04 19:36:55 +01:00
|
|
|
nameEncryptedPaint.setColor(0xff00a60e);
|
2014-07-03 00:39:05 +02:00
|
|
|
nameEncryptedPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
messagePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-07-03 00:39:05 +02:00
|
|
|
messagePaint.setTextSize(AndroidUtilities.dp(16));
|
2014-11-06 22:34:47 +01:00
|
|
|
messagePaint.setColor(0xff8f8f8f);
|
2015-04-09 20:00:14 +02:00
|
|
|
messagePaint.linkColor = 0xff8f8f8f;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
linePaint = new Paint();
|
|
|
|
linePaint.setColor(0xffdcdcdc);
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
backPaint = new Paint();
|
|
|
|
backPaint.setColor(0x0f000000);
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
messagePrintingPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-07-03 00:39:05 +02:00
|
|
|
messagePrintingPaint.setTextSize(AndroidUtilities.dp(16));
|
2014-11-17 23:04:31 +01:00
|
|
|
messagePrintingPaint.setColor(0xff4d83b3);
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
timePaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-11-06 22:34:47 +01:00
|
|
|
timePaint.setTextSize(AndroidUtilities.dp(13));
|
|
|
|
timePaint.setColor(0xff999999);
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
countPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
|
2014-07-03 00:39:05 +02:00
|
|
|
countPaint.setTextSize(AndroidUtilities.dp(13));
|
2014-02-04 19:36:55 +01:00
|
|
|
countPaint.setColor(0xffffffff);
|
2014-11-06 22:34:47 +01:00
|
|
|
countPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-11-10 12:05:22 +01:00
|
|
|
lockDrawable = getResources().getDrawable(R.drawable.list_secret);
|
2014-02-04 19:36:55 +01:00
|
|
|
checkDrawable = getResources().getDrawable(R.drawable.dialogs_check);
|
|
|
|
halfCheckDrawable = getResources().getDrawable(R.drawable.dialogs_halfcheck);
|
|
|
|
clockDrawable = getResources().getDrawable(R.drawable.msg_clock);
|
|
|
|
errorDrawable = getResources().getDrawable(R.drawable.dialogs_warning);
|
|
|
|
countDrawable = getResources().getDrawable(R.drawable.dialogs_badge);
|
2015-10-29 18:10:07 +01:00
|
|
|
countDrawableGrey = getResources().getDrawable(R.drawable.dialogs_badge2);
|
2014-11-10 12:05:22 +01:00
|
|
|
groupDrawable = getResources().getDrawable(R.drawable.list_group);
|
2014-11-11 23:16:17 +01:00
|
|
|
broadcastDrawable = getResources().getDrawable(R.drawable.list_broadcast);
|
2015-02-01 19:51:02 +01:00
|
|
|
muteDrawable = getResources().getDrawable(R.drawable.mute_grey);
|
2015-10-29 18:10:07 +01:00
|
|
|
verifiedDrawable = getResources().getDrawable(R.drawable.check_list);
|
2015-11-26 22:04:02 +01:00
|
|
|
botDrawable = getResources().getDrawable(R.drawable.bot_list);
|
2014-07-27 00:28:33 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
setBackgroundResource(R.drawable.list_selector);
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarImage = new ImageReceiver(this);
|
|
|
|
avatarImage.setRoundRadius(AndroidUtilities.dp(26));
|
|
|
|
avatarDrawable = new AvatarDrawable();
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
public void setDialog(TLRPC.Dialog dialog, int i, int type) {
|
2015-02-26 02:32:51 +01:00
|
|
|
currentDialogId = dialog.id;
|
|
|
|
isDialogCell = true;
|
|
|
|
index = i;
|
2015-06-29 19:12:11 +02:00
|
|
|
dialogsType = type;
|
2015-02-26 02:32:51 +01:00
|
|
|
update(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDialog(long dialog_id, MessageObject messageObject, int date) {
|
2014-10-31 20:02:29 +01:00
|
|
|
currentDialogId = dialog_id;
|
|
|
|
message = messageObject;
|
2015-02-26 02:32:51 +01:00
|
|
|
isDialogCell = false;
|
2014-10-31 20:02:29 +01:00
|
|
|
lastMessageDate = date;
|
2015-02-26 02:32:51 +01:00
|
|
|
unreadCount = 0;
|
2014-11-11 23:16:17 +01:00
|
|
|
lastUnreadState = messageObject != null && messageObject.isUnread();
|
2015-02-26 02:32:51 +01:00
|
|
|
if (message != null) {
|
|
|
|
lastSendState = message.messageOwner.send_state;
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
update(0);
|
|
|
|
}
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
public long getDialogId() {
|
|
|
|
return currentDialogId;
|
2014-09-24 04:17:27 +02:00
|
|
|
}
|
|
|
|
|
2014-03-27 15:25:53 +01:00
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
2015-05-03 13:48:36 +02:00
|
|
|
avatarImage.onDetachedFromWindow();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
avatarImage.onAttachedToWindow();
|
2014-03-27 15:25:53 +01:00
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2015-05-21 23:27:27 +02:00
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), AndroidUtilities.dp(72) + (useSeparator ? 1 : 0));
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (currentDialogId == 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (changed) {
|
|
|
|
buildLayout();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
|
|
|
if (Build.VERSION.SDK_INT >= 21 && getBackground() != null) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
getBackground().setHotspot(event.getX(), event.getY());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
public void buildLayout() {
|
2014-11-06 22:34:47 +01:00
|
|
|
String nameString = "";
|
|
|
|
String timeString = "";
|
|
|
|
String countString = null;
|
|
|
|
CharSequence messageString = "";
|
|
|
|
CharSequence printingString = null;
|
2015-02-26 02:32:51 +01:00
|
|
|
if (isDialogCell) {
|
2014-11-06 22:34:47 +01:00
|
|
|
printingString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
|
|
|
}
|
|
|
|
TextPaint currentNamePaint = namePaint;
|
|
|
|
TextPaint currentMessagePaint = messagePaint;
|
|
|
|
boolean checkMessage = true;
|
|
|
|
|
|
|
|
drawNameGroup = false;
|
|
|
|
drawNameBroadcast = false;
|
|
|
|
drawNameLock = false;
|
2015-11-26 22:04:02 +01:00
|
|
|
drawNameBot = false;
|
2015-10-29 18:10:07 +01:00
|
|
|
drawVerified = false;
|
2014-11-06 22:34:47 +01:00
|
|
|
|
|
|
|
if (encryptedChat != null) {
|
|
|
|
drawNameLock = true;
|
2014-11-10 12:05:22 +01:00
|
|
|
nameLockTop = AndroidUtilities.dp(16.5f);
|
2014-11-06 22:34:47 +01:00
|
|
|
if (!LocaleController.isRTL) {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
|
|
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + lockDrawable.getIntrinsicWidth();
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - lockDrawable.getIntrinsicWidth();
|
2014-11-06 22:34:47 +01:00
|
|
|
nameLeft = AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (chat != null) {
|
2015-11-26 22:04:02 +01:00
|
|
|
if (chat.id < 0 || ChatObject.isChannel(chat) && !chat.megagroup) {
|
2014-11-06 22:34:47 +01:00
|
|
|
drawNameBroadcast = true;
|
2014-11-10 12:05:22 +01:00
|
|
|
nameLockTop = AndroidUtilities.dp(16.5f);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
|
|
|
drawNameGroup = true;
|
2014-11-10 12:05:22 +01:00
|
|
|
nameLockTop = AndroidUtilities.dp(17.5f);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
drawVerified = chat.verified;
|
2014-11-10 12:05:22 +01:00
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (!LocaleController.isRTL) {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
|
|
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - (drawNameGroup ? groupDrawable.getIntrinsicWidth() : broadcastDrawable.getIntrinsicWidth());
|
2014-11-06 22:34:47 +01:00
|
|
|
nameLeft = AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!LocaleController.isRTL) {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
|
|
|
nameLeft = AndroidUtilities.dp(14);
|
|
|
|
}
|
2015-11-26 22:04:02 +01:00
|
|
|
if (user != null) {
|
|
|
|
if (user.bot) {
|
|
|
|
drawNameBot = true;
|
|
|
|
nameLockTop = AndroidUtilities.dp(16.5f);
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
nameLockLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
|
|
|
nameLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline + 4) + botDrawable.getIntrinsicWidth();
|
|
|
|
} else {
|
|
|
|
nameLockLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - botDrawable.getIntrinsicWidth();
|
|
|
|
nameLeft = AndroidUtilities.dp(14);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drawVerified = user.verified;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (message == null) {
|
|
|
|
if (printingString != null) {
|
|
|
|
lastPrintString = messageString = printingString;
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
|
|
|
} else {
|
|
|
|
lastPrintString = null;
|
|
|
|
if (encryptedChat != null) {
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
|
|
|
if (encryptedChat instanceof TLRPC.TL_encryptedChatRequested) {
|
|
|
|
messageString = LocaleController.getString("EncryptionProcessing", R.string.EncryptionProcessing);
|
|
|
|
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatWaiting) {
|
|
|
|
if (user != null && user.first_name != null) {
|
|
|
|
messageString = LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, user.first_name);
|
|
|
|
} else {
|
|
|
|
messageString = LocaleController.formatString("AwaitingEncryption", R.string.AwaitingEncryption, "");
|
|
|
|
}
|
|
|
|
} else if (encryptedChat instanceof TLRPC.TL_encryptedChatDiscarded) {
|
|
|
|
messageString = LocaleController.getString("EncryptionRejected", R.string.EncryptionRejected);
|
|
|
|
} else if (encryptedChat instanceof TLRPC.TL_encryptedChat) {
|
|
|
|
if (encryptedChat.admin_id == UserConfig.getClientUserId()) {
|
|
|
|
if (user != null && user.first_name != null) {
|
|
|
|
messageString = LocaleController.formatString("EncryptedChatStartedOutgoing", R.string.EncryptedChatStartedOutgoing, user.first_name);
|
|
|
|
} else {
|
|
|
|
messageString = LocaleController.formatString("EncryptedChatStartedOutgoing", R.string.EncryptedChatStartedOutgoing, "");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
messageString = LocaleController.getString("EncryptedChatStartedIncoming", R.string.EncryptedChatStartedIncoming);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (lastMessageDate != 0) {
|
|
|
|
timeString = LocaleController.stringForMessageListDate(lastMessageDate);
|
|
|
|
}
|
|
|
|
drawCheck1 = false;
|
|
|
|
drawCheck2 = false;
|
|
|
|
drawClock = false;
|
|
|
|
drawCount = false;
|
|
|
|
drawError = false;
|
|
|
|
} else {
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.User fromUser = null;
|
|
|
|
TLRPC.Chat fromChat = null;
|
|
|
|
if (message.messageOwner.from_id > 0) {
|
|
|
|
fromUser = MessagesController.getInstance().getUser(message.messageOwner.from_id);
|
|
|
|
} else if (message.messageOwner.from_id < 0) {
|
|
|
|
fromChat = MessagesController.getInstance().getChat(-message.messageOwner.from_id);
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
|
|
|
if (lastMessageDate != 0) {
|
|
|
|
timeString = LocaleController.stringForMessageListDate(lastMessageDate);
|
|
|
|
} else {
|
|
|
|
timeString = LocaleController.stringForMessageListDate(message.messageOwner.date);
|
|
|
|
}
|
|
|
|
if (printingString != null) {
|
|
|
|
lastPrintString = messageString = printingString;
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
|
|
|
} else {
|
|
|
|
lastPrintString = null;
|
|
|
|
if (message.messageOwner instanceof TLRPC.TL_messageService) {
|
|
|
|
messageString = message.messageText;
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
|
|
|
} else {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (chat != null && chat.id > 0 && fromChat == null) {
|
2015-06-29 19:12:11 +02:00
|
|
|
String name;
|
2015-09-24 22:52:02 +02:00
|
|
|
if (message.isOutOwner()) {
|
2014-11-06 22:34:47 +01:00
|
|
|
name = LocaleController.getString("FromYou", R.string.FromYou);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (fromUser != null) {
|
2015-07-22 20:56:37 +02:00
|
|
|
name = UserObject.getFirstName(fromUser);
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (fromChat != null) {
|
|
|
|
name = fromChat.title;
|
|
|
|
} else {
|
|
|
|
name = "DELETED";
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
checkMessage = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (message.caption != null) {
|
|
|
|
String mess = message.caption.toString();
|
|
|
|
if (mess.length() > 150) {
|
|
|
|
mess = mess.substring(0, 150);
|
|
|
|
}
|
|
|
|
mess = mess.replace("\n", " ");
|
2015-11-26 22:04:02 +01:00
|
|
|
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name.replace("\n", ""), mess), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
2015-11-26 22:04:02 +01:00
|
|
|
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff4d83b3>%s</c>", name.replace("\n", ""), message.messageText), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2015-05-03 13:48:36 +02:00
|
|
|
} else {
|
|
|
|
if (message.messageOwner.message != null) {
|
|
|
|
String mess = message.messageOwner.message;
|
|
|
|
if (mess.length() > 150) {
|
|
|
|
mess = mess.substring(0, 150);
|
|
|
|
}
|
|
|
|
mess = mess.replace("\n", " ");
|
2015-11-26 22:04:02 +01:00
|
|
|
messageString = Emoji.replaceEmoji(AndroidUtilities.replaceTags(String.format("<c#ff4d83b3>%s:</c> <c#ff808080>%s</c>", name.replace("\n", ""), mess), AndroidUtilities.FLAG_TAG_COLOR), messagePaint.getFontMetricsInt(), AndroidUtilities.dp(20), false);
|
2014-11-21 20:36:21 +01:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (message.caption != null) {
|
|
|
|
messageString = message.caption;
|
|
|
|
} else {
|
|
|
|
messageString = message.messageText;
|
|
|
|
if (message.messageOwner.media != null && !message.isMediaEmpty()) {
|
|
|
|
currentMessagePaint = messagePrintingPaint;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (unreadCount != 0) {
|
|
|
|
drawCount = true;
|
|
|
|
countString = String.format("%d", unreadCount);
|
|
|
|
} else {
|
|
|
|
drawCount = false;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (message.isOut()) {
|
2014-11-06 22:34:47 +01:00
|
|
|
if (message.isSending()) {
|
|
|
|
drawCheck1 = false;
|
|
|
|
drawCheck2 = false;
|
|
|
|
drawClock = true;
|
|
|
|
drawError = false;
|
|
|
|
} else if (message.isSendError()) {
|
|
|
|
drawCheck1 = false;
|
|
|
|
drawCheck2 = false;
|
|
|
|
drawClock = false;
|
|
|
|
drawError = true;
|
|
|
|
drawCount = false;
|
|
|
|
} else if (message.isSent()) {
|
|
|
|
if (!message.isUnread()) {
|
|
|
|
drawCheck1 = true;
|
|
|
|
drawCheck2 = true;
|
|
|
|
} else {
|
|
|
|
drawCheck1 = false;
|
|
|
|
drawCheck2 = true;
|
|
|
|
}
|
|
|
|
drawClock = false;
|
|
|
|
drawError = false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
drawCheck1 = false;
|
|
|
|
drawCheck2 = false;
|
|
|
|
drawClock = false;
|
|
|
|
drawError = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int timeWidth = (int) Math.ceil(timePaint.measureText(timeString));
|
|
|
|
timeLayout = new StaticLayout(timeString, timePaint, timeWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
timeLeft = getMeasuredWidth() - AndroidUtilities.dp(15) - timeWidth;
|
|
|
|
} else {
|
|
|
|
timeLeft = AndroidUtilities.dp(15);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (chat != null) {
|
|
|
|
nameString = chat.title;
|
|
|
|
} else if (user != null) {
|
|
|
|
if (user.id / 1000 != 777 && user.id / 1000 != 333 && ContactsController.getInstance().contactsDict.get(user.id) == null) {
|
|
|
|
if (ContactsController.getInstance().contactsDict.size() == 0 && (!ContactsController.getInstance().contactsLoaded || ContactsController.getInstance().isLoadingContacts())) {
|
2015-06-29 19:12:11 +02:00
|
|
|
nameString = UserObject.getUserName(user);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
|
|
|
if (user.phone != null && user.phone.length() != 0) {
|
|
|
|
nameString = PhoneFormat.getInstance().format("+" + user.phone);
|
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
nameString = UserObject.getUserName(user);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2015-06-29 19:12:11 +02:00
|
|
|
nameString = UserObject.getUserName(user);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
if (encryptedChat != null) {
|
|
|
|
currentNamePaint = nameEncryptedPaint;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (nameString.length() == 0) {
|
|
|
|
nameString = LocaleController.getString("HiddenName", R.string.HiddenName);
|
|
|
|
}
|
|
|
|
|
|
|
|
int nameWidth;
|
|
|
|
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(14) - timeWidth;
|
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
nameWidth = getMeasuredWidth() - nameLeft - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - timeWidth;
|
2014-11-06 22:34:47 +01:00
|
|
|
nameLeft += timeWidth;
|
|
|
|
}
|
|
|
|
if (drawNameLock) {
|
|
|
|
nameWidth -= AndroidUtilities.dp(4) + lockDrawable.getIntrinsicWidth();
|
|
|
|
} else if (drawNameGroup) {
|
|
|
|
nameWidth -= AndroidUtilities.dp(4) + groupDrawable.getIntrinsicWidth();
|
|
|
|
} else if (drawNameBroadcast) {
|
|
|
|
nameWidth -= AndroidUtilities.dp(4) + broadcastDrawable.getIntrinsicWidth();
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (drawNameBot) {
|
|
|
|
nameWidth -= AndroidUtilities.dp(4) + botDrawable.getIntrinsicWidth();
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
if (drawClock) {
|
|
|
|
int w = clockDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5);
|
|
|
|
nameWidth -= w;
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
checkDrawLeft = timeLeft - w;
|
|
|
|
} else {
|
|
|
|
checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5);
|
|
|
|
nameLeft += w;
|
|
|
|
}
|
|
|
|
} else if (drawCheck2) {
|
|
|
|
int w = checkDrawable.getIntrinsicWidth() + AndroidUtilities.dp(5);
|
|
|
|
nameWidth -= w;
|
|
|
|
if (drawCheck1) {
|
|
|
|
nameWidth -= halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8);
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
halfCheckDrawLeft = timeLeft - w;
|
|
|
|
checkDrawLeft = halfCheckDrawLeft - AndroidUtilities.dp(5.5f);
|
|
|
|
} else {
|
|
|
|
checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5);
|
|
|
|
halfCheckDrawLeft = checkDrawLeft + AndroidUtilities.dp(5.5f);
|
|
|
|
nameLeft += w + halfCheckDrawable.getIntrinsicWidth() - AndroidUtilities.dp(8);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
checkDrawLeft = timeLeft - w;
|
|
|
|
} else {
|
|
|
|
checkDrawLeft = timeLeft + timeWidth + AndroidUtilities.dp(5);
|
|
|
|
nameLeft += w;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
if (dialogMuted && !drawVerified) {
|
2015-02-01 19:51:02 +01:00
|
|
|
int w = AndroidUtilities.dp(6) + muteDrawable.getIntrinsicWidth();
|
|
|
|
nameWidth -= w;
|
|
|
|
if (LocaleController.isRTL) {
|
|
|
|
nameLeft += w;
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
} else if (drawVerified) {
|
|
|
|
int w = AndroidUtilities.dp(6) + verifiedDrawable.getIntrinsicWidth();
|
|
|
|
nameWidth -= w;
|
|
|
|
if (LocaleController.isRTL) {
|
|
|
|
nameLeft += w;
|
|
|
|
}
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2014-11-21 11:59:05 +01:00
|
|
|
nameWidth = Math.max(AndroidUtilities.dp(12), nameWidth);
|
2014-11-06 22:34:47 +01:00
|
|
|
CharSequence nameStringFinal = TextUtils.ellipsize(nameString.replace("\n", " "), currentNamePaint, nameWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
|
|
|
|
try {
|
|
|
|
nameLayout = new StaticLayout(nameStringFinal, currentNamePaint, nameWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
|
2015-03-26 18:34:47 +01:00
|
|
|
int messageWidth = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline + 16);
|
2014-11-06 22:34:47 +01:00
|
|
|
int avatarLeft;
|
|
|
|
if (!LocaleController.isRTL) {
|
2015-03-26 18:34:47 +01:00
|
|
|
messageLeft = AndroidUtilities.dp(AndroidUtilities.leftBaseline);
|
|
|
|
avatarLeft = AndroidUtilities.dp(AndroidUtilities.isTablet() ? 13 : 9);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else {
|
|
|
|
messageLeft = AndroidUtilities.dp(16);
|
2015-03-26 18:34:47 +01:00
|
|
|
avatarLeft = getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.isTablet() ? 65 : 61);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
|
|
|
avatarImage.setImageCoords(avatarLeft, avatarTop, AndroidUtilities.dp(52), AndroidUtilities.dp(52));
|
|
|
|
if (drawError) {
|
|
|
|
int w = errorDrawable.getIntrinsicWidth() + AndroidUtilities.dp(8);
|
|
|
|
messageWidth -= w;
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
errorLeft = getMeasuredWidth() - errorDrawable.getIntrinsicWidth() - AndroidUtilities.dp(11);
|
|
|
|
} else {
|
|
|
|
errorLeft = AndroidUtilities.dp(11);
|
|
|
|
messageLeft += w;
|
|
|
|
}
|
|
|
|
} else if (countString != null) {
|
|
|
|
countWidth = Math.max(AndroidUtilities.dp(12), (int)Math.ceil(countPaint.measureText(countString)));
|
|
|
|
countLayout = new StaticLayout(countString, countPaint, countWidth, Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
|
|
|
|
int w = countWidth + AndroidUtilities.dp(18);
|
|
|
|
messageWidth -= w;
|
|
|
|
if (!LocaleController.isRTL) {
|
|
|
|
countLeft = getMeasuredWidth() - countWidth - AndroidUtilities.dp(19);
|
|
|
|
} else {
|
|
|
|
countLeft = AndroidUtilities.dp(19);
|
|
|
|
messageLeft += w;
|
|
|
|
}
|
|
|
|
drawCount = true;
|
|
|
|
} else {
|
|
|
|
drawCount = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (checkMessage) {
|
|
|
|
if (messageString == null) {
|
|
|
|
messageString = "";
|
|
|
|
}
|
2014-11-21 20:36:21 +01:00
|
|
|
String mess = messageString.toString();
|
2014-11-06 22:34:47 +01:00
|
|
|
if (mess.length() > 150) {
|
|
|
|
mess = mess.substring(0, 150);
|
|
|
|
}
|
2014-11-21 20:36:21 +01:00
|
|
|
mess = mess.replace("\n", " ");
|
2015-07-22 20:56:37 +02:00
|
|
|
messageString = Emoji.replaceEmoji(mess, messagePaint.getFontMetricsInt(), AndroidUtilities.dp(17), false);
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2014-11-21 11:59:05 +01:00
|
|
|
messageWidth = Math.max(AndroidUtilities.dp(12), messageWidth);
|
2014-11-06 22:34:47 +01:00
|
|
|
CharSequence messageStringFinal = TextUtils.ellipsize(messageString, currentMessagePaint, messageWidth - AndroidUtilities.dp(12), TextUtils.TruncateAt.END);
|
2014-11-21 11:59:05 +01:00
|
|
|
try {
|
|
|
|
messageLayout = new StaticLayout(messageStringFinal, currentMessagePaint, messageWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
double widthpx;
|
|
|
|
float left;
|
2014-11-06 22:34:47 +01:00
|
|
|
if (LocaleController.isRTL) {
|
|
|
|
if (nameLayout != null && nameLayout.getLineCount() > 0) {
|
|
|
|
left = nameLayout.getLineLeft(0);
|
2015-02-26 02:32:51 +01:00
|
|
|
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
2015-10-29 18:10:07 +01:00
|
|
|
if (dialogMuted && !drawVerified) {
|
2015-02-26 02:32:51 +01:00
|
|
|
nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - muteDrawable.getIntrinsicWidth());
|
2015-10-29 18:10:07 +01:00
|
|
|
} else if (drawVerified) {
|
|
|
|
nameMuteLeft = (int) (nameLeft + (nameWidth - widthpx) - AndroidUtilities.dp(6) - verifiedDrawable.getIntrinsicWidth());
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
if (left == 0) {
|
|
|
|
if (widthpx < nameWidth) {
|
|
|
|
nameLeft += (nameWidth - widthpx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-21 11:59:05 +01:00
|
|
|
if (messageLayout != null && messageLayout.getLineCount() > 0) {
|
2014-11-06 22:34:47 +01:00
|
|
|
left = messageLayout.getLineLeft(0);
|
|
|
|
if (left == 0) {
|
|
|
|
widthpx = Math.ceil(messageLayout.getLineWidth(0));
|
|
|
|
if (widthpx < messageWidth) {
|
|
|
|
messageLeft += (messageWidth - widthpx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (nameLayout != null && nameLayout.getLineCount() > 0) {
|
|
|
|
left = nameLayout.getLineRight(0);
|
|
|
|
if (left == nameWidth) {
|
|
|
|
widthpx = Math.ceil(nameLayout.getLineWidth(0));
|
|
|
|
if (widthpx < nameWidth) {
|
|
|
|
nameLeft -= (nameWidth - widthpx);
|
|
|
|
}
|
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
if (dialogMuted || drawVerified) {
|
2015-02-01 19:51:02 +01:00
|
|
|
nameMuteLeft = (int) (nameLeft + left + AndroidUtilities.dp(6));
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
}
|
2014-11-21 11:59:05 +01:00
|
|
|
if (messageLayout != null && messageLayout.getLineCount() > 0) {
|
2014-11-06 22:34:47 +01:00
|
|
|
left = messageLayout.getLineRight(0);
|
|
|
|
if (left == messageWidth) {
|
|
|
|
widthpx = Math.ceil(messageLayout.getLineWidth(0));
|
|
|
|
if (widthpx < messageWidth) {
|
|
|
|
messageLeft -= (messageWidth - widthpx);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
public void setDialogSelected(boolean value) {
|
|
|
|
if (isSelected != value) {
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
isSelected = value;
|
|
|
|
}
|
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
private ArrayList<TLRPC.Dialog> getDialogsArray() {
|
2015-06-29 19:12:11 +02:00
|
|
|
if (dialogsType == 0) {
|
|
|
|
return MessagesController.getInstance().dialogs;
|
|
|
|
} else if (dialogsType == 1) {
|
|
|
|
return MessagesController.getInstance().dialogsServerOnly;
|
2015-09-24 22:52:02 +02:00
|
|
|
} else if (dialogsType == 2) {
|
2015-06-29 19:12:11 +02:00
|
|
|
return MessagesController.getInstance().dialogsGroupsOnly;
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
2015-06-29 19:12:11 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void checkCurrentDialogIndex() {
|
|
|
|
if (index < getDialogsArray().size()) {
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog = getDialogsArray().get(index);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (currentDialogId != dialog.id || message != null && message.getId() != dialog.top_message || unreadCount != dialog.unread_count || message == null && MessagesController.getInstance().dialogMessage.get(dialog.id) != null) {
|
2015-02-26 15:36:15 +01:00
|
|
|
currentDialogId = dialog.id;
|
|
|
|
update(0);
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
public void update(int mask) {
|
2015-02-26 02:32:51 +01:00
|
|
|
if (isDialogCell) {
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
2015-02-26 02:32:51 +01:00
|
|
|
if (dialog != null && mask == 0) {
|
2015-09-24 22:52:02 +02:00
|
|
|
message = MessagesController.getInstance().dialogMessage.get(dialog.id);
|
2015-02-26 02:32:51 +01:00
|
|
|
lastUnreadState = message != null && message.isUnread();
|
|
|
|
unreadCount = dialog.unread_count;
|
|
|
|
lastMessageDate = dialog.last_message_date;
|
|
|
|
if (message != null) {
|
|
|
|
lastSendState = message.messageOwner.send_state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
if (mask != 0) {
|
|
|
|
boolean continueUpdate = false;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (isDialogCell) {
|
|
|
|
if ((mask & MessagesController.UPDATE_MASK_USER_PRINT) != 0) {
|
|
|
|
CharSequence printString = MessagesController.getInstance().printingStrings.get(currentDialogId);
|
|
|
|
if (lastPrintString != null && printString == null || lastPrintString == null && printString != null || lastPrintString != null && printString != null && !lastPrintString.equals(printString)) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (chat == null) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (chat == null) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_CHAT_AVATAR) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (user == null) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_CHAT_NAME) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
if (user == null) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-11-17 03:44:57 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_READ_DIALOG_MESSAGE) != 0) {
|
2014-11-11 23:16:17 +01:00
|
|
|
if (message != null && lastUnreadState != message.isUnread()) {
|
2015-02-26 02:32:51 +01:00
|
|
|
lastUnreadState = message.isUnread();
|
2014-11-11 23:16:17 +01:00
|
|
|
continueUpdate = true;
|
2015-02-26 02:32:51 +01:00
|
|
|
} else if (isDialogCell) {
|
2015-09-24 22:52:02 +02:00
|
|
|
TLRPC.Dialog dialog = MessagesController.getInstance().dialogs_dict.get(currentDialogId);
|
2014-11-17 03:44:57 +01:00
|
|
|
if (dialog != null && unreadCount != dialog.unread_count) {
|
|
|
|
unreadCount = dialog.unread_count;
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
2014-11-11 23:16:17 +01:00
|
|
|
}
|
2014-03-22 23:31:55 +01:00
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_SEND_STATE) != 0) {
|
|
|
|
if (message != null && lastSendState != message.messageOwner.send_state) {
|
|
|
|
lastSendState = message.messageOwner.send_state;
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
if (!continueUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2015-02-26 02:32:51 +01:00
|
|
|
|
|
|
|
dialogMuted = isDialogCell && MessagesController.getInstance().isDialogMuted(currentDialogId);
|
2014-02-04 19:36:55 +01:00
|
|
|
user = null;
|
|
|
|
chat = null;
|
|
|
|
encryptedChat = null;
|
|
|
|
|
2014-10-31 20:02:29 +01:00
|
|
|
int lower_id = (int)currentDialogId;
|
|
|
|
int high_id = (int)(currentDialogId >> 32);
|
2014-02-04 19:36:55 +01:00
|
|
|
if (lower_id != 0) {
|
2014-07-27 12:53:00 +02:00
|
|
|
if (high_id == 1) {
|
2014-08-22 16:24:33 +02:00
|
|
|
chat = MessagesController.getInstance().getChat(lower_id);
|
2014-02-04 19:36:55 +01:00
|
|
|
} else {
|
2014-07-27 12:53:00 +02:00
|
|
|
if (lower_id < 0) {
|
2014-08-22 16:24:33 +02:00
|
|
|
chat = MessagesController.getInstance().getChat(-lower_id);
|
2015-11-26 22:04:02 +01:00
|
|
|
if (!isDialogCell && chat != null && chat.migrated_to != null) {
|
|
|
|
TLRPC.Chat chat2 = MessagesController.getInstance().getChat(chat.migrated_to.channel_id);
|
|
|
|
if (chat2 != null) {
|
|
|
|
chat = chat2;
|
|
|
|
}
|
|
|
|
}
|
2014-07-27 12:53:00 +02:00
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
user = MessagesController.getInstance().getUser(lower_id);
|
2014-07-27 12:53:00 +02:00
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
} else {
|
2014-08-22 16:24:33 +02:00
|
|
|
encryptedChat = MessagesController.getInstance().getEncryptedChat(high_id);
|
2014-07-27 12:53:00 +02:00
|
|
|
if (encryptedChat != null) {
|
2014-08-22 16:24:33 +02:00
|
|
|
user = MessagesController.getInstance().getUser(encryptedChat.user_id);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (user != null) {
|
|
|
|
if (user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable.setInfo(user);
|
2014-02-04 19:36:55 +01:00
|
|
|
} else if (chat != null) {
|
|
|
|
if (chat.photo != null) {
|
|
|
|
photo = chat.photo.photo_small;
|
|
|
|
}
|
2014-11-06 22:34:47 +01:00
|
|
|
avatarDrawable.setInfo(chat);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
avatarImage.setImage(photo, "50_50", avatarDrawable, null, false);
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
if (getMeasuredWidth() != 0 || getMeasuredHeight() != 0) {
|
|
|
|
buildLayout();
|
|
|
|
} else {
|
|
|
|
requestLayout();
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
2014-10-31 20:02:29 +01:00
|
|
|
if (currentDialogId == 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (isSelected) {
|
|
|
|
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backPaint);
|
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (drawNameLock) {
|
|
|
|
setDrawableBounds(lockDrawable, nameLockLeft, nameLockTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
lockDrawable.draw(canvas);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else if (drawNameGroup) {
|
|
|
|
setDrawableBounds(groupDrawable, nameLockLeft, nameLockTop);
|
2014-03-26 00:38:23 +01:00
|
|
|
groupDrawable.draw(canvas);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else if (drawNameBroadcast) {
|
|
|
|
setDrawableBounds(broadcastDrawable, nameLockLeft, nameLockTop);
|
2014-07-27 00:28:33 +02:00
|
|
|
broadcastDrawable.draw(canvas);
|
2015-11-26 22:04:02 +01:00
|
|
|
} else if (drawNameBot) {
|
|
|
|
setDrawableBounds(botDrawable, nameLockLeft, nameLockTop);
|
|
|
|
botDrawable.draw(canvas);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (nameLayout != null) {
|
2014-09-14 01:40:36 +02:00
|
|
|
canvas.save();
|
2014-11-10 12:05:22 +01:00
|
|
|
canvas.translate(nameLeft, AndroidUtilities.dp(13));
|
2014-11-06 22:34:47 +01:00
|
|
|
nameLayout.draw(canvas);
|
2014-09-14 01:40:36 +02:00
|
|
|
canvas.restore();
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
canvas.save();
|
2014-11-06 22:34:47 +01:00
|
|
|
canvas.translate(timeLeft, timeTop);
|
|
|
|
timeLayout.draw(canvas);
|
2014-02-04 19:36:55 +01:00
|
|
|
canvas.restore();
|
|
|
|
|
2014-11-21 11:59:05 +01:00
|
|
|
if (messageLayout != null) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(messageLeft, messageTop);
|
|
|
|
messageLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (drawClock) {
|
|
|
|
setDrawableBounds(clockDrawable, checkDrawLeft, checkDrawTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
clockDrawable.draw(canvas);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else if (drawCheck2) {
|
|
|
|
if (drawCheck1) {
|
|
|
|
setDrawableBounds(halfCheckDrawable, halfCheckDrawLeft, checkDrawTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
halfCheckDrawable.draw(canvas);
|
2014-11-06 22:34:47 +01:00
|
|
|
setDrawableBounds(checkDrawable, checkDrawLeft, checkDrawTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
checkDrawable.draw(canvas);
|
|
|
|
} else {
|
2014-11-06 22:34:47 +01:00
|
|
|
setDrawableBounds(checkDrawable, checkDrawLeft, checkDrawTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
checkDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-29 18:10:07 +01:00
|
|
|
if (dialogMuted && !drawVerified) {
|
2015-02-01 19:51:02 +01:00
|
|
|
setDrawableBounds(muteDrawable, nameMuteLeft, AndroidUtilities.dp(16.5f));
|
|
|
|
muteDrawable.draw(canvas);
|
2015-10-29 18:10:07 +01:00
|
|
|
} else if (drawVerified) {
|
|
|
|
setDrawableBounds(verifiedDrawable, nameMuteLeft, AndroidUtilities.dp(16.5f));
|
|
|
|
verifiedDrawable.draw(canvas);
|
2015-02-01 19:51:02 +01:00
|
|
|
}
|
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
if (drawError) {
|
|
|
|
setDrawableBounds(errorDrawable, errorLeft, errorTop);
|
2014-02-04 19:36:55 +01:00
|
|
|
errorDrawable.draw(canvas);
|
2014-11-06 22:34:47 +01:00
|
|
|
} else if (drawCount) {
|
2015-10-29 18:10:07 +01:00
|
|
|
if (dialogMuted) {
|
|
|
|
setDrawableBounds(countDrawableGrey, countLeft - AndroidUtilities.dp(5.5f), countTop, countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight());
|
|
|
|
countDrawableGrey.draw(canvas);
|
|
|
|
} else {
|
|
|
|
setDrawableBounds(countDrawable, countLeft - AndroidUtilities.dp(5.5f), countTop, countWidth + AndroidUtilities.dp(11), countDrawable.getIntrinsicHeight());
|
|
|
|
countDrawable.draw(canvas);
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
canvas.save();
|
2014-11-06 22:34:47 +01:00
|
|
|
canvas.translate(countLeft, countTop + AndroidUtilities.dp(4));
|
|
|
|
countLayout.draw(canvas);
|
2014-02-04 19:36:55 +01:00
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
2014-10-21 22:35:16 +02:00
|
|
|
if (useSeparator) {
|
2014-03-25 01:25:32 +01:00
|
|
|
if (LocaleController.isRTL) {
|
2015-03-26 18:34:47 +01:00
|
|
|
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, linePaint);
|
2014-02-04 19:36:55 +01:00
|
|
|
} else {
|
2015-03-26 18:34:47 +01:00
|
|
|
canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, linePaint);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
|
|
|
|
avatarImage.draw(canvas);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|