2015-01-02 23:15:07 +01:00
|
|
|
/*
|
|
|
|
* This is the source code of Telegram for Android v. 2.0.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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2015-01-02 23:15:07 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2019-08-22 01:53:26 +02:00
|
|
|
import android.graphics.Canvas;
|
|
|
|
import android.graphics.Paint;
|
2020-06-04 18:47:15 +02:00
|
|
|
import android.graphics.Path;
|
|
|
|
import android.graphics.RectF;
|
2018-07-30 04:07:02 +02:00
|
|
|
import android.graphics.drawable.Drawable;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.util.TypedValue;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.view.Gravity;
|
2019-08-22 01:53:26 +02:00
|
|
|
import android.view.View;
|
2015-01-02 23:15:07 +01:00
|
|
|
import android.widget.FrameLayout;
|
2017-07-08 18:32:04 +02:00
|
|
|
import android.widget.ImageView;
|
|
|
|
import android.widget.TextView;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2015-09-24 22:52:02 +02:00
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.messenger.FileLoader;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.messenger.LocaleController;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.MediaController;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.messenger.MessageObject;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.messenger.R;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2019-08-22 01:53:26 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2015-01-02 23:15:07 +01:00
|
|
|
import org.telegram.ui.Components.BackupImageView;
|
2020-06-04 18:47:15 +02:00
|
|
|
import org.telegram.ui.Components.CheckBox2;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
public class PhotoPickerPhotoCell extends FrameLayout {
|
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
public BackupImageView imageView;
|
2015-01-02 23:15:07 +01:00
|
|
|
public FrameLayout checkFrame;
|
2020-06-04 18:47:15 +02:00
|
|
|
public CheckBox2 checkBox;
|
2017-07-08 18:32:04 +02:00
|
|
|
public TextView videoTextView;
|
|
|
|
public FrameLayout videoInfoContainer;
|
2020-06-04 18:47:15 +02:00
|
|
|
private int itemWidth;
|
|
|
|
private int extraWidth;
|
2019-08-22 01:53:26 +02:00
|
|
|
private Paint backgroundPaint = new Paint();
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public PhotoPickerPhotoCell(Context context) {
|
2015-01-02 23:15:07 +01:00
|
|
|
super(context);
|
2019-08-22 01:53:26 +02:00
|
|
|
setWillNotDraw(false);
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView = new BackupImageView(context);
|
2020-06-04 18:47:15 +02:00
|
|
|
imageView.setRoundRadius(AndroidUtilities.dp(4));
|
2019-08-22 01:53:26 +02:00
|
|
|
addView(imageView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
|
2015-01-02 23:15:07 +01:00
|
|
|
|
|
|
|
checkFrame = new FrameLayout(context);
|
2015-05-21 23:27:27 +02:00
|
|
|
addView(checkFrame, LayoutHelper.createFrame(42, 42, Gravity.RIGHT | Gravity.TOP));
|
2015-01-02 23:15:07 +01:00
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
videoInfoContainer = new FrameLayout(context) {
|
|
|
|
|
|
|
|
private Path path = new Path();
|
|
|
|
float[] radii = new float[8];
|
|
|
|
private RectF rect = new RectF();
|
|
|
|
private Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
rect.set(0, 0, getMeasuredWidth(), getMeasuredHeight());
|
|
|
|
radii[0] = radii[1] = radii[2] = radii[3] = 0;
|
|
|
|
radii[4] = radii[5] = radii[6] = radii[7] = AndroidUtilities.dp(4);
|
|
|
|
path.reset();
|
|
|
|
path.addRoundRect(rect, radii, Path.Direction.CW);
|
|
|
|
path.close();
|
|
|
|
paint.setColor(0x7f000000);
|
|
|
|
canvas.drawPath(path, paint);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
videoInfoContainer.setWillNotDraw(false);
|
2017-07-08 18:32:04 +02:00
|
|
|
videoInfoContainer.setPadding(AndroidUtilities.dp(3), 0, AndroidUtilities.dp(3), 0);
|
|
|
|
addView(videoInfoContainer, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 16, Gravity.BOTTOM | Gravity.LEFT));
|
|
|
|
|
|
|
|
ImageView imageView1 = new ImageView(context);
|
|
|
|
imageView1.setImageResource(R.drawable.ic_video);
|
|
|
|
videoInfoContainer.addView(imageView1, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL));
|
|
|
|
|
|
|
|
videoTextView = new TextView(context);
|
|
|
|
videoTextView.setTextColor(0xffffffff);
|
|
|
|
videoTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 12);
|
2019-05-14 14:08:05 +02:00
|
|
|
videoTextView.setImportantForAccessibility(IMPORTANT_FOR_ACCESSIBILITY_NO);
|
2017-07-08 18:32:04 +02:00
|
|
|
videoInfoContainer.addView(videoTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.CENTER_VERTICAL, 18, -0.7f, 0, 0));
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
checkBox = new CheckBox2(context, 24);
|
|
|
|
checkBox.setDrawBackgroundAsArc(11);
|
|
|
|
checkBox.setColor(Theme.key_chat_attachCheckBoxBackground, Theme.key_chat_attachPhotoBackground, Theme.key_chat_attachCheckBoxCheck);
|
|
|
|
addView(checkBox, LayoutHelper.createFrame(26, 26, Gravity.LEFT | Gravity.TOP, 55, 4, 0, 0));
|
|
|
|
checkBox.setVisibility(VISIBLE);
|
2019-05-14 14:08:05 +02:00
|
|
|
|
|
|
|
setFocusable(true);
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
2020-06-04 18:47:15 +02:00
|
|
|
super.onMeasure(MeasureSpec.makeMeasureSpec(itemWidth + extraWidth, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(itemWidth, MeasureSpec.EXACTLY));
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|
2015-10-29 18:10:07 +01:00
|
|
|
|
2020-01-03 16:45:22 +01:00
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
updateColors();
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setItemWidth(int width, int extra) {
|
|
|
|
itemWidth = width;
|
|
|
|
extraWidth = extra;
|
|
|
|
|
|
|
|
FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) checkFrame.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = extra;
|
|
|
|
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) imageView.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = extra;
|
|
|
|
|
|
|
|
layoutParams = (FrameLayout.LayoutParams) videoInfoContainer.getLayoutParams();
|
|
|
|
layoutParams.rightMargin = extra;
|
2020-01-03 16:45:22 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void updateColors() {
|
|
|
|
checkBox.setColor(Theme.key_chat_attachCheckBoxBackground, Theme.key_chat_attachPhotoBackground, Theme.key_chat_attachCheckBoxCheck);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setNum(int num) {
|
|
|
|
checkBox.setNum(num);
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setImage(MediaController.PhotoEntry photoEntry) {
|
|
|
|
Drawable thumb = getResources().getDrawable(R.drawable.nophotos);
|
2019-08-22 01:53:26 +02:00
|
|
|
if (photoEntry.thumbPath != null) {
|
|
|
|
imageView.setImage(photoEntry.thumbPath, null, thumb);
|
|
|
|
} else if (photoEntry.path != null) {
|
|
|
|
imageView.setOrientation(photoEntry.orientation, true);
|
|
|
|
if (photoEntry.isVideo) {
|
|
|
|
videoInfoContainer.setVisibility(View.VISIBLE);
|
2019-12-31 14:08:08 +01:00
|
|
|
videoTextView.setText(AndroidUtilities.formatShortDuration(photoEntry.duration));
|
2020-07-26 10:03:38 +02:00
|
|
|
setContentDescription(LocaleController.getString("AttachVideo", R.string.AttachVideo) + ", " + LocaleController.formatDuration(photoEntry.duration));
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage("vthumb://" + photoEntry.imageId + ":" + photoEntry.path, null, thumb);
|
|
|
|
} else {
|
|
|
|
videoInfoContainer.setVisibility(View.INVISIBLE);
|
|
|
|
setContentDescription(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
|
|
|
imageView.setImage("thumb://" + photoEntry.imageId + ":" + photoEntry.path, null, thumb);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
imageView.setImageDrawable(thumb);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
public void setImage(MediaController.SearchImage searchImage) {
|
2020-06-04 18:47:15 +02:00
|
|
|
Drawable thumb = getResources().getDrawable(R.drawable.nophotos);
|
2018-07-30 04:07:02 +02:00
|
|
|
if (searchImage.thumbPhotoSize != null) {
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage(ImageLocation.getForPhoto(searchImage.thumbPhotoSize, searchImage.photo), null, thumb, searchImage);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (searchImage.photoSize != null) {
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage(ImageLocation.getForPhoto(searchImage.photoSize, searchImage.photo), "80_80", thumb, searchImage);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (searchImage.thumbPath != null) {
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage(searchImage.thumbPath, null, thumb);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (searchImage.thumbUrl != null && searchImage.thumbUrl.length() > 0) {
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage(searchImage.thumbUrl, null, thumb);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (MessageObject.isDocumentHasThumb(searchImage.document)) {
|
|
|
|
TLRPC.PhotoSize photoSize = FileLoader.getClosestPhotoSizeWithSize(searchImage.document.thumbs, 320);
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImage(ImageLocation.getForDocument(photoSize, searchImage.document), null, thumb, searchImage);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else {
|
2019-08-22 01:53:26 +02:00
|
|
|
imageView.setImageDrawable(thumb);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-08 18:35:59 +01:00
|
|
|
public void setChecked(final int num, final boolean checked, final boolean animated) {
|
|
|
|
checkBox.setChecked(num, checked, animated);
|
2019-08-22 01:53:26 +02:00
|
|
|
}
|
2015-01-02 23:15:07 +01:00
|
|
|
}
|