2014-02-04 19:36:55 +01:00
|
|
|
/*
|
2014-11-12 23:16:59 +01:00
|
|
|
* This is the source code of Telegram for Android v. 1.7.x.
|
2014-02-04 19:36:55 +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).
|
|
|
|
*
|
2014-11-12 23:16:59 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2014.
|
2014-02-04 19:36:55 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2014-11-12 23:16:59 +01:00
|
|
|
import android.view.Gravity;
|
|
|
|
import android.widget.FrameLayout;
|
|
|
|
import android.widget.ImageView;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2014-09-24 04:17:27 +02:00
|
|
|
import org.telegram.android.ContactsController;
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.LocaleController;
|
|
|
|
import org.telegram.android.MessagesController;
|
2014-11-12 23:16:59 +01:00
|
|
|
import org.telegram.messenger.ConnectionsManager;
|
2014-02-04 19:36:55 +01:00
|
|
|
import org.telegram.messenger.R;
|
2014-11-12 23:16:59 +01:00
|
|
|
import org.telegram.messenger.TLRPC;
|
2014-02-04 19:36:55 +01:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2014-12-01 18:56:31 +01:00
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
|
|
|
import org.telegram.ui.Components.CheckBox;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
import org.telegram.ui.Components.SimpleTextView;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
public class UserCell extends FrameLayout {
|
|
|
|
|
|
|
|
private BackupImageView avatarImageView;
|
2015-05-03 13:48:36 +02:00
|
|
|
private SimpleTextView nameTextView;
|
|
|
|
private SimpleTextView statusTextView;
|
2014-11-12 23:16:59 +01:00
|
|
|
private ImageView imageView;
|
2014-11-13 21:10:14 +01:00
|
|
|
private CheckBox checkBox;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-11-06 22:34:47 +01:00
|
|
|
private AvatarDrawable avatarDrawable;
|
2014-11-12 23:16:59 +01:00
|
|
|
private TLRPC.User currentUser = null;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
private CharSequence currentName;
|
|
|
|
private CharSequence currrntStatus;
|
|
|
|
private int currentDrawable;
|
2014-02-04 19:36:55 +01:00
|
|
|
|
|
|
|
private String lastName = null;
|
|
|
|
private int lastStatus = 0;
|
|
|
|
private TLRPC.FileLocation lastAvatar = null;
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
private int statusColor = 0xffa8a8a8;
|
|
|
|
private int statusOnlineColor = 0xff3b84c0;
|
2014-11-06 22:34:47 +01:00
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
public UserCell(Context context, int padding) {
|
2014-02-04 19:36:55 +01:00
|
|
|
super(context);
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
avatarDrawable = new AvatarDrawable();
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
avatarImageView = new BackupImageView(context);
|
2015-04-09 20:00:14 +02:00
|
|
|
avatarImageView.setRoundRadius(AndroidUtilities.dp(24));
|
2015-05-03 13:48:36 +02:00
|
|
|
addView(avatarImageView, LayoutHelper.createFrame(48, 48, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 7 + padding, 8, LocaleController.isRTL ? 7 + padding : 0, 0));
|
2014-02-04 19:36:55 +01:00
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
nameTextView = new SimpleTextView(context);
|
2014-11-13 21:10:14 +01:00
|
|
|
nameTextView.setTextColor(0xff212121);
|
2015-05-03 13:48:36 +02:00
|
|
|
nameTextView.setTextSize(17);
|
|
|
|
nameTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : (68 + padding), 11.5f, LocaleController.isRTL ? (68 + padding) : 28, 0));
|
|
|
|
|
|
|
|
statusTextView = new SimpleTextView(context);
|
|
|
|
statusTextView.setTextSize(14);
|
|
|
|
statusTextView.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP);
|
|
|
|
addView(statusTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 20, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 28 : (68 + padding), 34.5f, LocaleController.isRTL ? (68 + padding) : 28, 0));
|
2014-11-12 23:16:59 +01:00
|
|
|
|
|
|
|
imageView = new ImageView(context);
|
|
|
|
imageView.setScaleType(ImageView.ScaleType.CENTER);
|
2015-05-03 13:48:36 +02:00
|
|
|
imageView.setVisibility(GONE);
|
|
|
|
addView(imageView, LayoutHelper.createFrame(LayoutParams.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL, LocaleController.isRTL ? 0 : 16, 0, LocaleController.isRTL ? 16 : 0, 0));
|
2014-11-14 16:40:15 +01:00
|
|
|
|
2015-01-02 23:15:07 +01:00
|
|
|
checkBox = new CheckBox(context, R.drawable.round_check2);
|
2015-04-09 20:00:14 +02:00
|
|
|
checkBox.setVisibility(INVISIBLE);
|
2015-05-03 13:48:36 +02:00
|
|
|
addView(checkBox, LayoutHelper.createFrame(22, 22, (LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.TOP, LocaleController.isRTL ? 0 : 37 + padding, 38, LocaleController.isRTL ? 37 + padding : 0, 0));
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
public void setData(TLRPC.User user, CharSequence name, CharSequence status, int resId) {
|
|
|
|
if (user == null) {
|
|
|
|
currrntStatus = null;
|
|
|
|
currentName = null;
|
|
|
|
currentUser = null;
|
|
|
|
nameTextView.setText("");
|
|
|
|
statusTextView.setText("");
|
|
|
|
avatarImageView.setImageDrawable(null);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
currrntStatus = status;
|
|
|
|
currentName = name;
|
|
|
|
currentUser = user;
|
|
|
|
currentDrawable = resId;
|
2014-02-04 19:36:55 +01:00
|
|
|
update(0);
|
|
|
|
}
|
|
|
|
|
2014-11-21 20:36:21 +01:00
|
|
|
public void setChecked(boolean checked, boolean animated) {
|
2014-11-14 16:40:15 +01:00
|
|
|
if (checkBox.getVisibility() != VISIBLE) {
|
|
|
|
checkBox.setVisibility(VISIBLE);
|
|
|
|
}
|
2014-11-21 20:36:21 +01:00
|
|
|
checkBox.setChecked(checked, animated);
|
2014-11-14 16:40:15 +01:00
|
|
|
}
|
|
|
|
|
2014-02-04 19:36:55 +01:00
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2014-11-12 23:16:59 +01:00
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64), MeasureSpec.EXACTLY));
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
public void setStatusColors(int color, int onlineColor) {
|
|
|
|
statusColor = color;
|
|
|
|
statusOnlineColor = onlineColor;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void update(int mask) {
|
2014-11-12 23:16:59 +01:00
|
|
|
if (currentUser == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-04 19:36:55 +01:00
|
|
|
TLRPC.FileLocation photo = null;
|
2015-05-03 13:48:36 +02:00
|
|
|
String newName = null;
|
2014-11-12 23:16:59 +01:00
|
|
|
if (currentUser.photo != null) {
|
|
|
|
photo = currentUser.photo.photo_small;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mask != 0) {
|
|
|
|
boolean continueUpdate = false;
|
2014-11-12 23:16:59 +01:00
|
|
|
if ((mask & MessagesController.UPDATE_MASK_AVATAR) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
if (!continueUpdate && (mask & MessagesController.UPDATE_MASK_STATUS) != 0) {
|
2014-02-04 19:36:55 +01:00
|
|
|
int newStatus = 0;
|
2014-11-12 23:16:59 +01:00
|
|
|
if (currentUser.status != null) {
|
|
|
|
newStatus = currentUser.status.expires;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
if (newStatus != lastStatus) {
|
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!continueUpdate && currentName == null && lastName != null && (mask & MessagesController.UPDATE_MASK_NAME) != 0) {
|
|
|
|
newName = ContactsController.formatName(currentUser.first_name, currentUser.last_name);
|
|
|
|
if (!newName.equals(lastName)) {
|
2014-02-04 19:36:55 +01:00
|
|
|
continueUpdate = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!continueUpdate) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
avatarDrawable.setInfo(currentUser);
|
|
|
|
if (currentUser.status != null) {
|
|
|
|
lastStatus = currentUser.status.expires;
|
|
|
|
} else {
|
|
|
|
lastStatus = 0;
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
|
2014-11-12 23:16:59 +01:00
|
|
|
if (currentName != null) {
|
2015-05-03 13:48:36 +02:00
|
|
|
lastName = null;
|
2014-11-12 23:16:59 +01:00
|
|
|
nameTextView.setText(currentName);
|
2014-02-04 19:36:55 +01:00
|
|
|
} else {
|
2015-05-03 13:48:36 +02:00
|
|
|
lastName = newName == null ? ContactsController.formatName(currentUser.first_name, currentUser.last_name) : newName;
|
|
|
|
nameTextView.setText(lastName);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
if (currrntStatus != null) {
|
|
|
|
statusTextView.setTextColor(statusColor);
|
2015-05-03 13:48:36 +02:00
|
|
|
statusTextView.setText(currrntStatus);
|
2014-11-12 23:16:59 +01:00
|
|
|
} else {
|
|
|
|
if (currentUser.id == UserConfig.getClientUserId() || currentUser.status != null && currentUser.status.expires > ConnectionsManager.getInstance().getCurrentTime()) {
|
|
|
|
statusTextView.setTextColor(statusOnlineColor);
|
2015-05-03 13:48:36 +02:00
|
|
|
statusTextView.setText(LocaleController.getString("Online", R.string.Online));
|
2014-10-21 22:35:16 +02:00
|
|
|
} else {
|
2014-11-12 23:16:59 +01:00
|
|
|
statusTextView.setTextColor(statusColor);
|
2015-05-03 13:48:36 +02:00
|
|
|
statusTextView.setText(LocaleController.formatUserStatus(currentUser));
|
2014-10-21 22:35:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-03 13:48:36 +02:00
|
|
|
if (imageView.getVisibility() == VISIBLE && currentDrawable == 0 || imageView.getVisibility() == GONE && currentDrawable != 0) {
|
|
|
|
imageView.setVisibility(currentDrawable == 0 ? GONE : VISIBLE);
|
|
|
|
imageView.setImageResource(currentDrawable);
|
|
|
|
}
|
2014-11-12 23:16:59 +01:00
|
|
|
avatarImageView.setImage(photo, "50_50", avatarDrawable);
|
2014-02-04 19:36:55 +01:00
|
|
|
}
|
|
|
|
}
|