2015-11-26 22:04:02 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 3.x.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).
|
|
|
|
*
|
2016-01-11 18:19:48 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2016.
|
2015-11-26 22:04:02 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.os.Build;
|
2015-11-26 22:04:02 +01:00
|
|
|
import android.text.TextUtils;
|
|
|
|
import android.util.TypedValue;
|
|
|
|
import android.view.Gravity;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.view.MotionEvent;
|
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;
|
|
|
|
import org.telegram.messenger.MessagesController;
|
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.tgnet.TLRPC;
|
|
|
|
import org.telegram.ui.Components.AvatarDrawable;
|
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
|
|
|
import org.telegram.ui.Components.CheckBox;
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
|
|
|
|
|
|
|
public class ShareDialogCell extends FrameLayout {
|
|
|
|
|
|
|
|
private BackupImageView imageView;
|
|
|
|
private TextView nameTextView;
|
|
|
|
private CheckBox checkBox;
|
|
|
|
private AvatarDrawable avatarDrawable = new AvatarDrawable();
|
|
|
|
|
|
|
|
public ShareDialogCell(Context context) {
|
|
|
|
super(context);
|
2016-04-22 15:49:00 +02:00
|
|
|
setBackgroundResource(R.drawable.list_selector);
|
2015-11-26 22:04:02 +01:00
|
|
|
|
|
|
|
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);
|
|
|
|
nameTextView.setTextColor(0xff212121);
|
|
|
|
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);
|
|
|
|
addView(nameTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 6, 64, 6, 0));
|
|
|
|
|
|
|
|
checkBox = new CheckBox(context, R.drawable.round_check2);
|
|
|
|
checkBox.setSize(24);
|
|
|
|
checkBox.setCheckOffset(AndroidUtilities.dp(1));
|
|
|
|
checkBox.setVisibility(VISIBLE);
|
|
|
|
checkBox.setColor(0xff3ec1f9);
|
|
|
|
addView(checkBox, LayoutHelper.createFrame(24, 24, Gravity.CENTER_HORIZONTAL | Gravity.TOP, 17, 39, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
super.onMeasure(widthMeasureSpec, MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100), MeasureSpec.EXACTLY));
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +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);
|
|
|
|
}
|
|
|
|
|
2015-11-26 22:04:02 +01:00
|
|
|
public void setDialog(TLRPC.Dialog dialog, boolean checked, CharSequence name) {
|
|
|
|
int lower_id = (int) dialog.id;
|
|
|
|
TLRPC.FileLocation photo = null;
|
|
|
|
if (lower_id > 0) {
|
|
|
|
TLRPC.User user = MessagesController.getInstance().getUser(lower_id);
|
|
|
|
if (name != null) {
|
|
|
|
nameTextView.setText(name);
|
|
|
|
} else if (user != null) {
|
|
|
|
nameTextView.setText(ContactsController.formatName(user.first_name, user.last_name));
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
|
|
|
avatarDrawable.setInfo(user);
|
|
|
|
if (user != null && user.photo != null) {
|
|
|
|
photo = user.photo.photo_small;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
TLRPC.Chat chat = MessagesController.getInstance().getChat(-lower_id);
|
|
|
|
if (name != null) {
|
|
|
|
nameTextView.setText(name);
|
|
|
|
} else if (chat != null) {
|
|
|
|
nameTextView.setText(chat.title);
|
|
|
|
} else {
|
|
|
|
nameTextView.setText("");
|
|
|
|
}
|
|
|
|
avatarDrawable.setInfo(chat);
|
|
|
|
if (chat != null && chat.photo != null) {
|
|
|
|
photo = chat.photo.photo_small;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
imageView.setImage(photo, "50_50", avatarDrawable);
|
|
|
|
checkBox.setChecked(checked, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setChecked(boolean checked, boolean animated) {
|
|
|
|
checkBox.setChecked(checked, animated);
|
|
|
|
}
|
|
|
|
}
|