2016-01-11 18:19:48 +01:00
|
|
|
/*
|
2019-01-23 18:03:33 +01:00
|
|
|
* This is the source code of Telegram for Android v. 5.x.x.
|
2016-01-11 18:19:48 +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).
|
|
|
|
*
|
2019-01-23 18:03:33 +01:00
|
|
|
* Copyright Nikolai Kudashov, 2013-2018.
|
2016-01-11 18:19:48 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.animation.Animator;
|
|
|
|
import android.animation.AnimatorListenerAdapter;
|
|
|
|
import android.animation.AnimatorSet;
|
|
|
|
import android.animation.ObjectAnimator;
|
2016-01-11 18:19:48 +01:00
|
|
|
import android.annotation.SuppressLint;
|
|
|
|
import android.content.Context;
|
|
|
|
import android.graphics.Canvas;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.graphics.Paint;
|
2016-01-11 18:19:48 +01:00
|
|
|
import android.text.Layout;
|
|
|
|
import android.text.StaticLayout;
|
|
|
|
import android.text.TextUtils;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.util.Property;
|
|
|
|
import android.view.Gravity;
|
2016-01-11 18:19:48 +01:00
|
|
|
import android.view.MotionEvent;
|
|
|
|
import android.view.SoundEffectConstants;
|
2019-05-14 14:08:05 +02:00
|
|
|
import android.view.accessibility.AccessibilityNodeInfo;
|
2016-04-22 15:49:00 +02:00
|
|
|
import android.view.animation.AccelerateInterpolator;
|
2020-03-30 14:00:09 +02:00
|
|
|
import android.widget.FrameLayout;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
import org.telegram.messenger.AndroidUtilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.DownloadController;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.messenger.Emoji;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.FileLoader;
|
|
|
|
import org.telegram.messenger.FileLog;
|
|
|
|
import org.telegram.messenger.ImageLoader;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.ImageLocation;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.ImageReceiver;
|
|
|
|
import org.telegram.messenger.LocaleController;
|
|
|
|
import org.telegram.messenger.MediaController;
|
|
|
|
import org.telegram.messenger.MessageObject;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.MessagesController;
|
2019-05-14 14:08:05 +02:00
|
|
|
import org.telegram.messenger.R;
|
2016-10-11 13:57:01 +02:00
|
|
|
import org.telegram.messenger.UserConfig;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.messenger.Utilities;
|
2018-07-30 04:07:02 +02:00
|
|
|
import org.telegram.messenger.WebFile;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.tgnet.TLRPC;
|
2020-03-30 14:00:09 +02:00
|
|
|
import org.telegram.ui.Components.AnimationProperties;
|
|
|
|
import org.telegram.ui.Components.CheckBox2;
|
|
|
|
import org.telegram.ui.Components.LayoutHelper;
|
2016-01-11 18:19:48 +01:00
|
|
|
import org.telegram.ui.Components.LetterDrawable;
|
2016-04-22 15:49:00 +02:00
|
|
|
import org.telegram.ui.ActionBar.Theme;
|
2019-01-23 18:03:33 +01:00
|
|
|
import org.telegram.ui.Components.MediaActionDrawable;
|
|
|
|
import org.telegram.ui.Components.RadialProgress2;
|
2017-07-08 18:32:04 +02:00
|
|
|
import org.telegram.ui.PhotoViewer;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
import java.io.File;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Locale;
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public class ContextLinkCell extends FrameLayout implements DownloadController.FileDownloadProgressListener {
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_NONE = 0;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_DOCUMENT = 1;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_GIF = 2;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_AUDIO = 3;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_VIDEO = 4;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_MUSIC = 5;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_STICKER = 6;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_PHOTO = 7;
|
|
|
|
private final static int DOCUMENT_ATTACH_TYPE_GEO = 8;
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public interface ContextLinkCellDelegate {
|
|
|
|
void didPressedImage(ContextLinkCell cell);
|
|
|
|
}
|
|
|
|
|
|
|
|
private ImageReceiver linkImageView;
|
|
|
|
private boolean drawLinkImageView;
|
|
|
|
private LetterDrawable letterDrawable;
|
2018-07-30 04:07:02 +02:00
|
|
|
private int currentAccount = UserConfig.selectedAccount;
|
2019-01-23 18:03:33 +01:00
|
|
|
private Object parentObject;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
private boolean needDivider;
|
|
|
|
private boolean buttonPressed;
|
2016-04-22 15:49:00 +02:00
|
|
|
private boolean needShadow;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
private boolean canPreviewGif;
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
private boolean isForceGif;
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private int linkY;
|
|
|
|
private StaticLayout linkLayout;
|
|
|
|
|
|
|
|
private int titleY = AndroidUtilities.dp(7);
|
|
|
|
private StaticLayout titleLayout;
|
|
|
|
|
|
|
|
private int descriptionY = AndroidUtilities.dp(27);
|
|
|
|
private StaticLayout descriptionLayout;
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
private TLRPC.BotInlineResult inlineResult;
|
2020-06-04 18:47:15 +02:00
|
|
|
private TLRPC.User inlineBot;
|
2016-04-22 15:49:00 +02:00
|
|
|
private TLRPC.Document documentAttach;
|
2020-03-30 14:00:09 +02:00
|
|
|
private int currentDate;
|
2019-05-14 14:08:05 +02:00
|
|
|
private TLRPC.Photo photoAttach;
|
2017-07-08 18:32:04 +02:00
|
|
|
private TLRPC.PhotoSize currentPhotoObject;
|
2016-04-22 15:49:00 +02:00
|
|
|
private int documentAttachType;
|
2016-01-11 18:19:48 +01:00
|
|
|
private boolean mediaWebpage;
|
2016-10-11 13:57:01 +02:00
|
|
|
private MessageObject currentMessageObject;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private AnimatorSet animator;
|
|
|
|
|
|
|
|
private Paint backgroundPaint;
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private int TAG;
|
|
|
|
private int buttonState;
|
2019-01-23 18:03:33 +01:00
|
|
|
private RadialProgress2 radialProgress;
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
private long lastUpdateTime;
|
|
|
|
private boolean scaled;
|
|
|
|
private float scale;
|
|
|
|
private static AccelerateInterpolator interpolator = new AccelerateInterpolator(0.5f);
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
private boolean hideLoadProgress;
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
private CheckBox2 checkBox;
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
private ContextLinkCellDelegate delegate;
|
|
|
|
|
|
|
|
public ContextLinkCell(Context context) {
|
2020-03-30 14:00:09 +02:00
|
|
|
this(context, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public ContextLinkCell(Context context, boolean needsCheckBox) {
|
2016-01-11 18:19:48 +01:00
|
|
|
super(context);
|
|
|
|
|
|
|
|
linkImageView = new ImageReceiver(this);
|
2019-07-18 15:01:39 +02:00
|
|
|
linkImageView.setLayerNum(1);
|
2019-05-14 14:08:05 +02:00
|
|
|
linkImageView.setUseSharedAnimationQueue(true);
|
2016-01-11 18:19:48 +01:00
|
|
|
letterDrawable = new LetterDrawable();
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress = new RadialProgress2(this);
|
2018-07-30 04:07:02 +02:00
|
|
|
TAG = DownloadController.getInstance(currentAccount).generateObserverTag();
|
2019-05-14 14:08:05 +02:00
|
|
|
setFocusable(true);
|
2020-03-30 14:00:09 +02:00
|
|
|
|
|
|
|
if (needsCheckBox) {
|
|
|
|
backgroundPaint = new Paint();
|
|
|
|
backgroundPaint.setColor(Theme.getColor(Theme.key_sharedMedia_photoPlaceholder));
|
|
|
|
|
|
|
|
checkBox = new CheckBox2(context, 21);
|
|
|
|
checkBox.setVisibility(INVISIBLE);
|
|
|
|
checkBox.setColor(null, Theme.key_sharedMedia_photoPlaceholder, Theme.key_checkboxCheck);
|
|
|
|
checkBox.setDrawUnchecked(false);
|
|
|
|
checkBox.setDrawBackgroundAsArc(1);
|
|
|
|
addView(checkBox, LayoutHelper.createFrame(24, 24, Gravity.RIGHT | Gravity.TOP, 0, 1, 1, 0));
|
|
|
|
}
|
|
|
|
setWillNotDraw(false);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@SuppressLint("DrawAllocation")
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
drawLinkImageView = false;
|
|
|
|
descriptionLayout = null;
|
|
|
|
titleLayout = null;
|
|
|
|
linkLayout = null;
|
2017-07-08 18:32:04 +02:00
|
|
|
currentPhotoObject = null;
|
2016-01-11 18:19:48 +01:00
|
|
|
linkY = AndroidUtilities.dp(27);
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (inlineResult == null && documentAttach == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
setMeasuredDimension(AndroidUtilities.dp(100), AndroidUtilities.dp(100));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
int viewWidth = MeasureSpec.getSize(widthMeasureSpec);
|
|
|
|
int maxWidth = viewWidth - AndroidUtilities.dp(AndroidUtilities.leftBaseline) - AndroidUtilities.dp(8);
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
TLRPC.PhotoSize currentPhotoObjectThumb = null;
|
|
|
|
ArrayList<TLRPC.PhotoSize> photoThumbs = null;
|
2018-07-30 04:07:02 +02:00
|
|
|
WebFile webFile = null;
|
|
|
|
TLRPC.TL_webDocument webDocument = null;
|
|
|
|
String urlLocation = null;
|
2016-04-22 15:49:00 +02:00
|
|
|
|
|
|
|
if (documentAttach != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
photoThumbs = new ArrayList<>(documentAttach.thumbs);
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (inlineResult != null && inlineResult.photo != null) {
|
|
|
|
photoThumbs = new ArrayList<>(inlineResult.photo.sizes);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (!mediaWebpage && inlineResult != null) {
|
|
|
|
if (inlineResult.title != null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
try {
|
2017-03-31 01:58:05 +02:00
|
|
|
int width = (int) Math.ceil(Theme.chat_contextResult_titleTextPaint.measureText(inlineResult.title));
|
|
|
|
CharSequence titleFinal = TextUtils.ellipsize(Emoji.replaceEmoji(inlineResult.title.replace('\n', ' '), Theme.chat_contextResult_titleTextPaint.getFontMetricsInt(), AndroidUtilities.dp(15), false), Theme.chat_contextResult_titleTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.END);
|
|
|
|
titleLayout = new StaticLayout(titleFinal, Theme.chat_contextResult_titleTextPaint, maxWidth + AndroidUtilities.dp(4), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
letterDrawable.setTitle(inlineResult.title);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (inlineResult.description != null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
try {
|
2017-03-31 01:58:05 +02:00
|
|
|
descriptionLayout = ChatMessageCell.generateStaticLayout(Emoji.replaceEmoji(inlineResult.description, Theme.chat_contextResult_descriptionTextPaint.getFontMetricsInt(), AndroidUtilities.dp(13), false), Theme.chat_contextResult_descriptionTextPaint, maxWidth, maxWidth, 0, 3);
|
2016-01-11 18:19:48 +01:00
|
|
|
if (descriptionLayout.getLineCount() > 0) {
|
|
|
|
linkY = descriptionY + descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1) + AndroidUtilities.dp(1);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (inlineResult.url != null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
try {
|
2017-03-31 01:58:05 +02:00
|
|
|
int width = (int) Math.ceil(Theme.chat_contextResult_descriptionTextPaint.measureText(inlineResult.url));
|
|
|
|
CharSequence linkFinal = TextUtils.ellipsize(inlineResult.url.replace('\n', ' '), Theme.chat_contextResult_descriptionTextPaint, Math.min(width, maxWidth), TextUtils.TruncateAt.MIDDLE);
|
|
|
|
linkLayout = new StaticLayout(linkFinal, Theme.chat_contextResult_descriptionTextPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
} catch (Exception e) {
|
2017-03-31 01:58:05 +02:00
|
|
|
FileLog.e(e);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
String ext = null;
|
|
|
|
if (documentAttach != null) {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (isForceGif || MessageObject.isGifDocument(documentAttach)) {
|
2019-01-23 18:03:33 +01:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(documentAttach.thumbs, 90);
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (MessageObject.isStickerDocument(documentAttach) || MessageObject.isAnimatedStickerDocument(documentAttach, true)) {
|
2019-01-23 18:03:33 +01:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(documentAttach.thumbs, 90);
|
2016-04-22 15:49:00 +02:00
|
|
|
ext = "webp";
|
|
|
|
} else {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType != DOCUMENT_ATTACH_TYPE_MUSIC && documentAttachType != DOCUMENT_ATTACH_TYPE_AUDIO) {
|
2019-01-23 18:03:33 +01:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(documentAttach.thumbs, 90);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
|
|
|
} else if (inlineResult != null && inlineResult.photo != null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, AndroidUtilities.getPhotoSize(), true);
|
|
|
|
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(photoThumbs, 80);
|
|
|
|
if (currentPhotoObjectThumb == currentPhotoObject) {
|
|
|
|
currentPhotoObjectThumb = null;
|
|
|
|
}
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (inlineResult != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (inlineResult.content instanceof TLRPC.TL_webDocument) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (inlineResult.type != null) {
|
|
|
|
if (inlineResult.type.startsWith("gif")) {
|
2020-06-04 18:47:15 +02:00
|
|
|
if (inlineResult.thumb instanceof TLRPC.TL_webDocument && "video/mp4".equals(inlineResult.thumb.mime_type)) {
|
|
|
|
webDocument = (TLRPC.TL_webDocument) inlineResult.thumb;
|
|
|
|
} else {
|
|
|
|
webDocument = (TLRPC.TL_webDocument) inlineResult.content;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (inlineResult.type.equals("photo")) {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (inlineResult.thumb instanceof TLRPC.TL_webDocument) {
|
|
|
|
webDocument = (TLRPC.TL_webDocument) inlineResult.thumb;
|
|
|
|
} else {
|
|
|
|
webDocument = (TLRPC.TL_webDocument) inlineResult.content;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (webDocument == null && (inlineResult.thumb instanceof TLRPC.TL_webDocument)) {
|
|
|
|
webDocument = (TLRPC.TL_webDocument) inlineResult.thumb;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (webDocument == null && currentPhotoObject == null && currentPhotoObjectThumb == null) {
|
|
|
|
if (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo) {
|
|
|
|
double lat = inlineResult.send_message.geo.lat;
|
|
|
|
double lon = inlineResult.send_message.geo._long;
|
|
|
|
if (MessagesController.getInstance(currentAccount).mapProvider == 2) {
|
|
|
|
webFile = WebFile.createWithGeoPoint(inlineResult.send_message.geo, 72, 72, 15, Math.min(2, (int) Math.ceil(AndroidUtilities.density)));
|
|
|
|
} else {
|
2019-12-31 14:08:08 +01:00
|
|
|
urlLocation = AndroidUtilities.formapMapUrl(currentAccount, lat, lon, 72, 72, true, 15, -1);
|
2018-07-30 04:07:02 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (webDocument != null) {
|
|
|
|
webFile = WebFile.createWithWebDocument(webDocument);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-24 12:27:15 +02:00
|
|
|
int width;
|
2016-01-11 18:19:48 +01:00
|
|
|
int w = 0;
|
|
|
|
int h = 0;
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (documentAttach != null) {
|
|
|
|
for (int b = 0; b < documentAttach.attributes.size(); b++) {
|
|
|
|
TLRPC.DocumentAttribute attribute = documentAttach.attributes.get(b);
|
2016-01-11 18:19:48 +01:00
|
|
|
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
|
|
|
|
w = attribute.w;
|
|
|
|
h = attribute.h;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (w == 0 || h == 0) {
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
if (currentPhotoObjectThumb != null) {
|
|
|
|
currentPhotoObjectThumb.size = -1;
|
|
|
|
}
|
|
|
|
w = currentPhotoObject.w;
|
|
|
|
h = currentPhotoObject.h;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (inlineResult != null) {
|
2019-05-14 14:08:05 +02:00
|
|
|
int[] result = MessageObject.getInlineResultWidthAndHeight(inlineResult);
|
2018-07-30 04:07:02 +02:00
|
|
|
w = result[0];
|
|
|
|
h = result[1];
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (w == 0 || h == 0) {
|
|
|
|
w = h = AndroidUtilities.dp(80);
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
if (documentAttach != null || currentPhotoObject != null || webFile != null || urlLocation != null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
String currentPhotoFilter;
|
|
|
|
String currentPhotoFilterThumb = "52_52_b";
|
|
|
|
|
|
|
|
if (mediaWebpage) {
|
|
|
|
width = (int) (w / (h / (float) AndroidUtilities.dp(80)));
|
2016-06-24 12:27:15 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) {
|
2016-01-11 18:19:48 +01:00
|
|
|
currentPhotoFilterThumb = currentPhotoFilter = String.format(Locale.US, "%d_%d_b", (int) (width / AndroidUtilities.density), 80);
|
|
|
|
} else {
|
|
|
|
currentPhotoFilter = String.format(Locale.US, "%d_%d", (int) (width / AndroidUtilities.density), 80);
|
|
|
|
currentPhotoFilterThumb = currentPhotoFilter + "_b";
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
currentPhotoFilter = "52_52";
|
|
|
|
}
|
2016-06-24 12:27:15 +02:00
|
|
|
linkImageView.setAspectFit(documentAttachType == DOCUMENT_ATTACH_TYPE_STICKER);
|
2016-01-11 18:19:48 +01:00
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) {
|
2016-06-24 12:27:15 +02:00
|
|
|
if (documentAttach != null) {
|
2020-07-26 10:03:38 +02:00
|
|
|
TLRPC.VideoSize thumb = MessageObject.getDocumentVideoThumb(documentAttach);
|
2020-06-04 18:47:15 +02:00
|
|
|
if (thumb != null) {
|
|
|
|
linkImageView.setImage(ImageLocation.getForDocument(thumb, documentAttach), null, ImageLocation.getForDocument(currentPhotoObject, documentAttach), currentPhotoFilter, -1, ext, parentObject, 1);
|
|
|
|
} else {
|
|
|
|
ImageLocation location = ImageLocation.getForDocument(documentAttach);
|
|
|
|
if (isForceGif) {
|
|
|
|
location.imageType = FileLoader.IMAGE_TYPE_ANIMATION;
|
|
|
|
}
|
|
|
|
linkImageView.setImage(location, null, ImageLocation.getForDocument(currentPhotoObject, documentAttach), currentPhotoFilter, documentAttach.size, ext, parentObject, 0);
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
} else if (webFile != null) {
|
|
|
|
linkImageView.setImage(ImageLocation.getForWebFile(webFile), null, ImageLocation.getForPhoto(currentPhotoObject, photoAttach), currentPhotoFilter, -1, ext, parentObject, 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
linkImageView.setImage(ImageLocation.getForPath(urlLocation), null, ImageLocation.getForPhoto(currentPhotoObject, photoAttach), currentPhotoFilter, -1, ext, parentObject, 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (currentPhotoObject != null) {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (MessageObject.canAutoplayAnimatedSticker(documentAttach)) {
|
|
|
|
linkImageView.setImage(ImageLocation.getForDocument(documentAttach), "80_80", ImageLocation.getForDocument(currentPhotoObject, documentAttach), currentPhotoFilterThumb, currentPhotoObject.size, null, parentObject, 0);
|
2019-05-14 14:08:05 +02:00
|
|
|
} else {
|
2019-07-18 15:01:39 +02:00
|
|
|
if (documentAttach != null) {
|
|
|
|
linkImageView.setImage(ImageLocation.getForDocument(currentPhotoObject, documentAttach), currentPhotoFilter, ImageLocation.getForPhoto(currentPhotoObjectThumb, photoAttach), currentPhotoFilterThumb, currentPhotoObject.size, ext, parentObject, 0);
|
|
|
|
} else {
|
|
|
|
linkImageView.setImage(ImageLocation.getForPhoto(currentPhotoObject, photoAttach), currentPhotoFilter, ImageLocation.getForPhoto(currentPhotoObjectThumb, photoAttach), currentPhotoFilterThumb, currentPhotoObject.size, ext, parentObject, 0);
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
} else if (webFile != null) {
|
|
|
|
linkImageView.setImage(ImageLocation.getForWebFile(webFile), currentPhotoFilter, ImageLocation.getForPhoto(currentPhotoObjectThumb, photoAttach), currentPhotoFilterThumb, -1, ext, parentObject, 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2019-05-14 14:08:05 +02:00
|
|
|
linkImageView.setImage(ImageLocation.getForPath(urlLocation), currentPhotoFilter, ImageLocation.getForPhoto(currentPhotoObjectThumb, photoAttach), currentPhotoFilterThumb, -1, ext, parentObject, 1);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
drawLinkImageView = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mediaWebpage) {
|
2016-10-11 13:57:01 +02:00
|
|
|
width = viewWidth;
|
|
|
|
int height = MeasureSpec.getSize(heightMeasureSpec);
|
|
|
|
if (height == 0) {
|
|
|
|
height = AndroidUtilities.dp(100);
|
|
|
|
}
|
|
|
|
setMeasuredDimension(width, height);
|
|
|
|
int x = (width - AndroidUtilities.dp(24)) / 2;
|
|
|
|
int y = (height - AndroidUtilities.dp(24)) / 2;
|
|
|
|
radialProgress.setProgressRect(x, y, x + AndroidUtilities.dp(24), y + AndroidUtilities.dp(24));
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setCircleRadius(AndroidUtilities.dp(12));
|
2016-10-11 13:57:01 +02:00
|
|
|
linkImageView.setImageCoords(0, 0, width, height);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
|
|
|
int height = 0;
|
|
|
|
if (titleLayout != null && titleLayout.getLineCount() != 0) {
|
|
|
|
height += titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
if (descriptionLayout != null && descriptionLayout.getLineCount() != 0) {
|
|
|
|
height += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
if (linkLayout != null && linkLayout.getLineCount() > 0) {
|
|
|
|
height += linkLayout.getLineBottom(linkLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
height = Math.max(AndroidUtilities.dp(52), height);
|
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), Math.max(AndroidUtilities.dp(68), height + AndroidUtilities.dp(16)) + (needDivider ? 1 : 0));
|
|
|
|
|
|
|
|
int maxPhotoWidth = AndroidUtilities.dp(52);
|
|
|
|
int x = LocaleController.isRTL ? MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(8) - maxPhotoWidth : AndroidUtilities.dp(8);
|
2016-04-22 15:49:00 +02:00
|
|
|
letterDrawable.setBounds(x, AndroidUtilities.dp(8), x + maxPhotoWidth, AndroidUtilities.dp(60));
|
2016-01-11 18:19:48 +01:00
|
|
|
linkImageView.setImageCoords(x, AndroidUtilities.dp(8), maxPhotoWidth, maxPhotoWidth);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setCircleRadius(AndroidUtilities.dp(24));
|
2016-10-11 13:57:01 +02:00
|
|
|
radialProgress.setProgressRect(x + AndroidUtilities.dp(4), AndroidUtilities.dp(12), x + AndroidUtilities.dp(48), AndroidUtilities.dp(56));
|
|
|
|
}
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
if (checkBox != null) {
|
|
|
|
measureChildWithMargins(checkBox, widthMeasureSpec, 0, heightMeasureSpec, 0);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private void setAttachType() {
|
|
|
|
currentMessageObject = null;
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_NONE;
|
|
|
|
if (documentAttach != null) {
|
|
|
|
if (MessageObject.isGifDocument(documentAttach)) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
|
2019-12-31 14:08:08 +01:00
|
|
|
} else if (MessageObject.isStickerDocument(documentAttach) || MessageObject.isAnimatedStickerDocument(documentAttach, true)) {
|
2016-10-11 13:57:01 +02:00
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_STICKER;
|
|
|
|
} else if (MessageObject.isMusicDocument(documentAttach)) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_MUSIC;
|
|
|
|
} else if (MessageObject.isVoiceDocument(documentAttach)) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_AUDIO;
|
|
|
|
}
|
|
|
|
} else if (inlineResult != null) {
|
|
|
|
if (inlineResult.photo != null) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_PHOTO;
|
|
|
|
} else if (inlineResult.type.equals("audio")) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_MUSIC;
|
|
|
|
} else if (inlineResult.type.equals("voice")) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_AUDIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
|
|
|
TLRPC.TL_message message = new TLRPC.TL_message();
|
|
|
|
message.out = true;
|
|
|
|
message.id = -Utilities.random.nextInt();
|
|
|
|
message.to_id = new TLRPC.TL_peerUser();
|
2018-07-30 04:07:02 +02:00
|
|
|
message.to_id.user_id = message.from_id = UserConfig.getInstance(currentAccount).getClientUserId();
|
2016-10-11 13:57:01 +02:00
|
|
|
message.date = (int) (System.currentTimeMillis() / 1000);
|
2018-07-30 04:07:02 +02:00
|
|
|
message.message = "";
|
2016-10-11 13:57:01 +02:00
|
|
|
message.media = new TLRPC.TL_messageMediaDocument();
|
2017-07-23 14:56:38 +02:00
|
|
|
message.media.flags |= 3;
|
2016-10-11 13:57:01 +02:00
|
|
|
message.media.document = new TLRPC.TL_document();
|
2019-01-23 18:03:33 +01:00
|
|
|
message.media.document.file_reference = new byte[0];
|
2016-10-11 13:57:01 +02:00
|
|
|
message.flags |= TLRPC.MESSAGE_FLAG_HAS_MEDIA | TLRPC.MESSAGE_FLAG_HAS_FROM_ID;
|
|
|
|
|
|
|
|
if (documentAttach != null) {
|
|
|
|
message.media.document = documentAttach;
|
|
|
|
message.attachPath = "";
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
String ext = ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg");
|
2016-10-11 13:57:01 +02:00
|
|
|
message.media.document.id = 0;
|
|
|
|
message.media.document.access_hash = 0;
|
|
|
|
message.media.document.date = message.date;
|
|
|
|
message.media.document.mime_type = "audio/" + ext;
|
|
|
|
message.media.document.size = 0;
|
|
|
|
message.media.document.dc_id = 0;
|
|
|
|
|
|
|
|
TLRPC.TL_documentAttributeAudio attributeAudio = new TLRPC.TL_documentAttributeAudio();
|
2018-07-30 04:07:02 +02:00
|
|
|
attributeAudio.duration = MessageObject.getInlineResultDuration(inlineResult);
|
2016-10-11 13:57:01 +02:00
|
|
|
attributeAudio.title = inlineResult.title != null ? inlineResult.title : "";
|
|
|
|
attributeAudio.performer = inlineResult.description != null ? inlineResult.description : "";
|
|
|
|
attributeAudio.flags |= 3;
|
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
|
|
|
|
attributeAudio.voice = true;
|
|
|
|
}
|
|
|
|
message.media.document.attributes.add(attributeAudio);
|
|
|
|
|
|
|
|
TLRPC.TL_documentAttributeFilename fileName = new TLRPC.TL_documentAttributeFilename();
|
2018-07-30 04:07:02 +02:00
|
|
|
fileName.file_name = Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg");
|
2016-10-11 13:57:01 +02:00
|
|
|
message.media.document.attributes.add(fileName);
|
|
|
|
|
2018-07-30 04:07:02 +02:00
|
|
|
message.attachPath = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg")).getAbsolutePath();
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
|
2020-08-14 18:58:22 +02:00
|
|
|
currentMessageObject = new MessageObject(currentAccount, message, false, true);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public void setLink(TLRPC.BotInlineResult contextResult, TLRPC.User bot, boolean media, boolean divider, boolean shadow) {
|
|
|
|
setLink(contextResult, bot, media, divider, shadow, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setLink(TLRPC.BotInlineResult contextResult, TLRPC.User bot, boolean media, boolean divider, boolean shadow, boolean forceGif) {
|
2016-01-11 18:19:48 +01:00
|
|
|
needDivider = divider;
|
2016-04-22 15:49:00 +02:00
|
|
|
needShadow = shadow;
|
2020-06-04 18:47:15 +02:00
|
|
|
inlineBot = bot;
|
2019-01-23 18:03:33 +01:00
|
|
|
parentObject = inlineResult = contextResult;
|
2019-05-14 14:08:05 +02:00
|
|
|
if (inlineResult != null) {
|
2016-04-22 15:49:00 +02:00
|
|
|
documentAttach = inlineResult.document;
|
2019-05-14 14:08:05 +02:00
|
|
|
photoAttach = inlineResult.photo;
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
|
|
|
documentAttach = null;
|
2019-05-14 14:08:05 +02:00
|
|
|
photoAttach = null;
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
mediaWebpage = media;
|
2020-06-04 18:47:15 +02:00
|
|
|
isForceGif = forceGif;
|
2016-10-11 13:57:01 +02:00
|
|
|
setAttachType();
|
2020-06-04 18:47:15 +02:00
|
|
|
if (forceGif) {
|
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
requestLayout();
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2020-06-04 18:47:15 +02:00
|
|
|
public TLRPC.User getInlineBot() {
|
|
|
|
return inlineBot;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public Object getParentObject() {
|
|
|
|
return parentObject;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
public void setGif(TLRPC.Document document, boolean divider) {
|
2020-03-30 14:00:09 +02:00
|
|
|
setGif(document, "gif" + document, 0, divider);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setGif(TLRPC.Document document, Object parent, int date, boolean divider) {
|
2016-01-11 18:19:48 +01:00
|
|
|
needDivider = divider;
|
2016-04-22 15:49:00 +02:00
|
|
|
needShadow = false;
|
2020-03-30 14:00:09 +02:00
|
|
|
currentDate = date;
|
2016-04-22 15:49:00 +02:00
|
|
|
inlineResult = null;
|
2020-03-30 14:00:09 +02:00
|
|
|
parentObject = parent;
|
2016-04-22 15:49:00 +02:00
|
|
|
documentAttach = document;
|
2019-05-14 14:08:05 +02:00
|
|
|
photoAttach = null;
|
2016-01-11 18:19:48 +01:00
|
|
|
mediaWebpage = true;
|
2020-06-04 18:47:15 +02:00
|
|
|
isForceGif = true;
|
2016-10-11 13:57:01 +02:00
|
|
|
setAttachType();
|
2020-06-04 18:47:15 +02:00
|
|
|
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
|
2016-01-11 18:19:48 +01:00
|
|
|
requestLayout();
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public boolean isSticker() {
|
|
|
|
return documentAttachType == DOCUMENT_ATTACH_TYPE_STICKER;
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public boolean isGif() {
|
|
|
|
return documentAttachType == DOCUMENT_ATTACH_TYPE_GIF && canPreviewGif;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public boolean showingBitmap() {
|
|
|
|
return linkImageView.getBitmap() != null;
|
|
|
|
}
|
|
|
|
|
2020-03-30 14:00:09 +02:00
|
|
|
public int getDate() {
|
|
|
|
return currentDate;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public TLRPC.Document getDocument() {
|
|
|
|
return documentAttach;
|
|
|
|
}
|
|
|
|
|
2019-06-04 12:14:50 +02:00
|
|
|
public TLRPC.BotInlineResult getBotInlineResult() {
|
|
|
|
return inlineResult;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public ImageReceiver getPhotoImage() {
|
|
|
|
return linkImageView;
|
|
|
|
}
|
|
|
|
|
2016-04-22 15:49:00 +02:00
|
|
|
public void setScaled(boolean value) {
|
|
|
|
scaled = value;
|
|
|
|
lastUpdateTime = System.currentTimeMillis();
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
2019-05-14 14:08:05 +02:00
|
|
|
public void setCanPreviewGif(boolean value) {
|
|
|
|
canPreviewGif = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isCanPreviewGif() {
|
|
|
|
return canPreviewGif;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
|
|
|
if (drawLinkImageView) {
|
|
|
|
linkImageView.onDetachedFromWindow();
|
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
radialProgress.onDetachedFromWindow();
|
2018-07-30 04:07:02 +02:00
|
|
|
DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
|
|
|
if (drawLinkImageView) {
|
|
|
|
if (linkImageView.onAttachedToWindow()) {
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-08 03:30:32 +01:00
|
|
|
radialProgress.onAttachedToWindow();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
public MessageObject getMessageObject() {
|
|
|
|
return currentMessageObject;
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2016-04-22 15:49:00 +02:00
|
|
|
if (mediaWebpage || delegate == null || inlineResult == null) {
|
2016-01-11 18:19:48 +01:00
|
|
|
return super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
int x = (int) event.getX();
|
|
|
|
int y = (int) event.getY();
|
|
|
|
|
|
|
|
boolean result = false;
|
|
|
|
int side = AndroidUtilities.dp(48);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
|
|
|
boolean area = letterDrawable.getBounds().contains(x, y);
|
2016-04-22 15:49:00 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (area) {
|
2016-04-22 15:49:00 +02:00
|
|
|
buttonPressed = true;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setPressed(buttonPressed, false);
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
2016-04-22 15:49:00 +02:00
|
|
|
result = true;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
} else if (buttonPressed) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
buttonPressed = false;
|
|
|
|
playSoundEffect(SoundEffectConstants.CLICK);
|
|
|
|
didPressedButton();
|
|
|
|
invalidate();
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
buttonPressed = false;
|
|
|
|
invalidate();
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (!area) {
|
2016-04-22 15:49:00 +02:00
|
|
|
buttonPressed = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setPressed(buttonPressed, false);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
if (inlineResult != null && inlineResult.content != null && !TextUtils.isEmpty(inlineResult.content.url)) {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
if (letterDrawable.getBounds().contains(x, y)) {
|
|
|
|
buttonPressed = true;
|
|
|
|
result = true;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (buttonPressed) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
2016-04-22 15:49:00 +02:00
|
|
|
buttonPressed = false;
|
2016-10-11 13:57:01 +02:00
|
|
|
playSoundEffect(SoundEffectConstants.CLICK);
|
|
|
|
delegate.didPressedImage(this);
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
buttonPressed = false;
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (!letterDrawable.getBounds().contains(x, y)) {
|
|
|
|
buttonPressed = false;
|
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!result) {
|
|
|
|
result = super.onTouchEvent(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
private void didPressedButton() {
|
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
|
|
|
if (buttonState == 0) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (MediaController.getInstance().playMessage(currentMessageObject)) {
|
2016-10-11 13:57:01 +02:00
|
|
|
buttonState = 1;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
} else if (buttonState == 1) {
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean result = MediaController.getInstance().pauseMessage(currentMessageObject);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (result) {
|
|
|
|
buttonState = 0;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
} else if (buttonState == 2) {
|
|
|
|
radialProgress.setProgress(0, false);
|
|
|
|
if (documentAttach != null) {
|
2019-01-23 18:03:33 +01:00
|
|
|
FileLoader.getInstance(currentAccount).loadFile(documentAttach, inlineResult, 1, 0);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (inlineResult.content instanceof TLRPC.TL_webDocument) {
|
2019-01-23 18:03:33 +01:00
|
|
|
FileLoader.getInstance(currentAccount).loadFile(WebFile.createWithWebDocument(inlineResult.content), 1, 1);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
buttonState = 4;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
|
|
|
} else if (buttonState == 4) {
|
|
|
|
if (documentAttach != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
FileLoader.getInstance(currentAccount).cancelLoadFile(documentAttach);
|
|
|
|
} else if (inlineResult.content instanceof TLRPC.TL_webDocument) {
|
|
|
|
FileLoader.getInstance(currentAccount).cancelLoadFile(WebFile.createWithWebDocument(inlineResult.content));
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
buttonState = 2;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-11 18:19:48 +01:00
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
2020-03-30 14:00:09 +02:00
|
|
|
if (checkBox != null) {
|
|
|
|
if (checkBox.isChecked() || !linkImageView.hasBitmapImage() || linkImageView.getCurrentAlpha() != 1.0f || PhotoViewer.isShowingImage((MessageObject) parentObject)) {
|
|
|
|
canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), backgroundPaint);
|
|
|
|
}
|
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
if (titleLayout != null) {
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), titleY);
|
|
|
|
titleLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptionLayout != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_contextResult_descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
|
2016-01-11 18:19:48 +01:00
|
|
|
canvas.save();
|
|
|
|
canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), descriptionY);
|
|
|
|
descriptionLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (linkLayout != null) {
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_contextResult_descriptionTextPaint.setColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkText));
|
2016-01-11 18:19:48 +01:00
|
|
|
canvas.save();
|
|
|
|
canvas.translate(AndroidUtilities.dp(LocaleController.isRTL ? 8 : AndroidUtilities.leftBaseline), linkY);
|
|
|
|
linkLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!mediaWebpage) {
|
2019-08-22 01:53:26 +02:00
|
|
|
if (drawLinkImageView && !PhotoViewer.isShowingImage(inlineResult)) {
|
|
|
|
letterDrawable.setAlpha((int) (255 * (1.0f - linkImageView.getCurrentAlpha())));
|
|
|
|
} else {
|
|
|
|
letterDrawable.setAlpha(255);
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
2017-03-31 01:58:05 +02:00
|
|
|
radialProgress.setProgressColor(Theme.getColor(buttonPressed ? Theme.key_chat_inAudioSelectedProgress : Theme.key_chat_inAudioProgress));
|
2016-10-11 13:57:01 +02:00
|
|
|
radialProgress.draw(canvas);
|
|
|
|
} else if (inlineResult != null && inlineResult.type.equals("file")) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int w = Theme.chat_inlineResultFile.getIntrinsicWidth();
|
|
|
|
int h = Theme.chat_inlineResultFile.getIntrinsicHeight();
|
2020-06-04 18:47:15 +02:00
|
|
|
int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
|
|
|
|
int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_inlineResultFile.setBounds(x, y, x + w, y + h);
|
|
|
|
Theme.chat_inlineResultFile.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (inlineResult != null && (inlineResult.type.equals("audio") || inlineResult.type.equals("voice"))) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int w = Theme.chat_inlineResultAudio.getIntrinsicWidth();
|
|
|
|
int h = Theme.chat_inlineResultAudio.getIntrinsicHeight();
|
2020-06-04 18:47:15 +02:00
|
|
|
int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
|
|
|
|
int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_inlineResultAudio.setBounds(x, y, x + w, y + h);
|
|
|
|
Theme.chat_inlineResultAudio.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
} else if (inlineResult != null && (inlineResult.type.equals("venue") || inlineResult.type.equals("geo"))) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int w = Theme.chat_inlineResultLocation.getIntrinsicWidth();
|
|
|
|
int h = Theme.chat_inlineResultLocation.getIntrinsicHeight();
|
2020-06-04 18:47:15 +02:00
|
|
|
int x = (int) (linkImageView.getImageX() + (AndroidUtilities.dp(52) - w) / 2);
|
|
|
|
int y = (int) (linkImageView.getImageY() + (AndroidUtilities.dp(52) - h) / 2);
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + AndroidUtilities.dp(52), linkImageView.getImageY() + AndroidUtilities.dp(52), LetterDrawable.paint);
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_inlineResultLocation.setBounds(x, y, x + w, y + h);
|
|
|
|
Theme.chat_inlineResultLocation.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
} else {
|
|
|
|
letterDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (inlineResult != null && (inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaGeo || inlineResult.send_message instanceof TLRPC.TL_botInlineMessageMediaVenue)) {
|
2017-03-31 01:58:05 +02:00
|
|
|
int w = Theme.chat_inlineResultLocation.getIntrinsicWidth();
|
|
|
|
int h = Theme.chat_inlineResultLocation.getIntrinsicHeight();
|
2020-06-04 18:47:15 +02:00
|
|
|
int x = (int) (linkImageView.getImageX() + (linkImageView.getImageWidth() - w) / 2);
|
|
|
|
int y = (int) (linkImageView.getImageY() + (linkImageView.getImageHeight() - h) / 2);
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.drawRect(linkImageView.getImageX(), linkImageView.getImageY(), linkImageView.getImageX() + linkImageView.getImageWidth(), linkImageView.getImageY() + linkImageView.getImageHeight(), LetterDrawable.paint);
|
2017-03-31 01:58:05 +02:00
|
|
|
Theme.chat_inlineResultLocation.setBounds(x, y, x + w, y + h);
|
|
|
|
Theme.chat_inlineResultLocation.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
if (drawLinkImageView) {
|
2017-07-08 18:32:04 +02:00
|
|
|
if (inlineResult != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
linkImageView.setVisible(!PhotoViewer.isShowingImage(inlineResult), false);
|
2017-07-08 18:32:04 +02:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.save();
|
|
|
|
if (scaled && scale != 0.8f || !scaled && scale != 1.0f) {
|
|
|
|
long newTime = System.currentTimeMillis();
|
|
|
|
long dt = (newTime - lastUpdateTime);
|
|
|
|
lastUpdateTime = newTime;
|
|
|
|
if (scaled && scale != 0.8f) {
|
|
|
|
scale -= dt / 400.0f;
|
|
|
|
if (scale < 0.8f) {
|
|
|
|
scale = 0.8f;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scale += dt / 400.0f;
|
|
|
|
if (scale > 1.0f) {
|
|
|
|
scale = 1.0f;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
invalidate();
|
|
|
|
}
|
2020-03-30 14:00:09 +02:00
|
|
|
canvas.scale(scale * imageScale, scale * imageScale, getMeasuredWidth() / 2, getMeasuredHeight() / 2);
|
2016-01-11 18:19:48 +01:00
|
|
|
linkImageView.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
canvas.restore();
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
2016-04-22 15:49:00 +02:00
|
|
|
if (mediaWebpage && (documentAttachType == DOCUMENT_ATTACH_TYPE_PHOTO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF)) {
|
2016-01-11 18:19:48 +01:00
|
|
|
radialProgress.draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (needDivider && !mediaWebpage) {
|
|
|
|
if (LocaleController.isRTL) {
|
2017-03-31 01:58:05 +02:00
|
|
|
canvas.drawLine(0, getMeasuredHeight() - 1, getMeasuredWidth() - AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, Theme.dividerPaint);
|
2016-01-11 18:19:48 +01:00
|
|
|
} else {
|
2017-03-31 01:58:05 +02:00
|
|
|
canvas.drawLine(AndroidUtilities.dp(AndroidUtilities.leftBaseline), getMeasuredHeight() - 1, getMeasuredWidth(), getMeasuredHeight() - 1, Theme.dividerPaint);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
2017-03-31 01:58:05 +02:00
|
|
|
if (needShadow) {
|
|
|
|
Theme.chat_contextResult_shadowUnderSwitchDrawable.setBounds(0, 0, getMeasuredWidth(), AndroidUtilities.dp(3));
|
|
|
|
Theme.chat_contextResult_shadowUnderSwitchDrawable.draw(canvas);
|
2016-04-22 15:49:00 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
private int getIconForCurrentState() {
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setColors(Theme.key_chat_inLoader, Theme.key_chat_inLoaderSelected, Theme.key_chat_inMediaIcon, Theme.key_chat_inMediaIconSelected);
|
|
|
|
if (buttonState == 1) {
|
|
|
|
return MediaActionDrawable.ICON_PAUSE;
|
|
|
|
} else if (buttonState == 2) {
|
|
|
|
return MediaActionDrawable.ICON_DOWNLOAD;
|
|
|
|
} else if (buttonState == 4) {
|
|
|
|
return MediaActionDrawable.ICON_CANCEL;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
return MediaActionDrawable.ICON_PLAY;
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setColors(Theme.key_chat_mediaLoaderPhoto, Theme.key_chat_mediaLoaderPhotoSelected, Theme.key_chat_mediaLoaderPhotoIcon, Theme.key_chat_mediaLoaderPhotoIconSelected);
|
|
|
|
return buttonState == 1 ? MediaActionDrawable.ICON_EMPTY : MediaActionDrawable.ICON_NONE;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
2019-01-23 18:03:33 +01:00
|
|
|
public void updateButtonState(boolean ifSame, boolean animated) {
|
2016-01-11 18:19:48 +01:00
|
|
|
String fileName = null;
|
|
|
|
File cacheFile = null;
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC || documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
|
|
|
|
if (documentAttach != null) {
|
|
|
|
fileName = FileLoader.getAttachFileName(documentAttach);
|
|
|
|
cacheFile = FileLoader.getPathToAttach(documentAttach);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (inlineResult.content instanceof TLRPC.TL_webDocument) {
|
|
|
|
fileName = Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC ? "mp3" : "ogg");
|
|
|
|
cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else if (mediaWebpage) {
|
|
|
|
if (inlineResult != null) {
|
|
|
|
if (inlineResult.document instanceof TLRPC.TL_document) {
|
|
|
|
fileName = FileLoader.getAttachFileName(inlineResult.document);
|
|
|
|
cacheFile = FileLoader.getPathToAttach(inlineResult.document);
|
|
|
|
} else if (inlineResult.photo instanceof TLRPC.TL_photo) {
|
2017-07-08 18:32:04 +02:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(inlineResult.photo.sizes, AndroidUtilities.getPhotoSize(), true);
|
2016-10-11 13:57:01 +02:00
|
|
|
fileName = FileLoader.getAttachFileName(currentPhotoObject);
|
|
|
|
cacheFile = FileLoader.getPathToAttach(currentPhotoObject);
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (inlineResult.content instanceof TLRPC.TL_webDocument) {
|
2020-06-04 18:47:15 +02:00
|
|
|
fileName = Utilities.MD5(inlineResult.content.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.content.url, FileLoader.getMimeTypePart(inlineResult.content.mime_type));
|
2018-07-30 04:07:02 +02:00
|
|
|
cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
2020-06-04 18:47:15 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF && inlineResult.thumb instanceof TLRPC.TL_webDocument && "video/mp4".equals(inlineResult.thumb.mime_type)) {
|
|
|
|
fileName = null;
|
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
} else if (inlineResult.thumb instanceof TLRPC.TL_webDocument) {
|
2020-06-04 18:47:15 +02:00
|
|
|
fileName = Utilities.MD5(inlineResult.thumb.url) + "." + ImageLoader.getHttpUrlExtension(inlineResult.thumb.url, FileLoader.getMimeTypePart(inlineResult.thumb.mime_type));
|
2018-07-30 04:07:02 +02:00
|
|
|
cacheFile = new File(FileLoader.getDirectory(FileLoader.MEDIA_DIR_CACHE), fileName);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else if (documentAttach != null) {
|
|
|
|
fileName = FileLoader.getAttachFileName(documentAttach);
|
|
|
|
cacheFile = FileLoader.getPathToAttach(documentAttach);
|
|
|
|
}
|
2020-06-04 18:47:15 +02:00
|
|
|
|
|
|
|
if (documentAttach != null && documentAttachType == DOCUMENT_ATTACH_TYPE_GIF && MessageObject.getDocumentVideoThumb(documentAttach) != null) {
|
|
|
|
fileName = null;
|
|
|
|
}
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2018-07-30 04:07:02 +02:00
|
|
|
|
2016-10-11 13:57:01 +02:00
|
|
|
if (TextUtils.isEmpty(fileName)) {
|
2020-06-04 18:47:15 +02:00
|
|
|
buttonState = -1;
|
|
|
|
radialProgress.setIcon(MediaActionDrawable.ICON_NONE, ifSame, false);
|
2016-01-11 18:19:48 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!cacheFile.exists()) {
|
2018-07-30 04:07:02 +02:00
|
|
|
DownloadController.getInstance(currentAccount).addLoadingFileObserver(fileName, this);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC || documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
|
|
|
|
boolean isLoading;
|
|
|
|
if (documentAttach != null) {
|
2018-07-30 04:07:02 +02:00
|
|
|
isLoading = FileLoader.getInstance(currentAccount).isLoadingFile(fileName);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
isLoading = ImageLoader.getInstance().isLoadingHttpFile(fileName);
|
|
|
|
}
|
|
|
|
if (!isLoading) {
|
|
|
|
buttonState = 2;
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), ifSame, animated);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
buttonState = 4;
|
|
|
|
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
|
|
|
|
if (progress != null) {
|
|
|
|
radialProgress.setProgress(progress, animated);
|
|
|
|
} else {
|
|
|
|
radialProgress.setProgress(0, animated);
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), ifSame, animated);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
buttonState = 1;
|
|
|
|
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
|
|
|
|
float setProgress = progress != null ? progress : 0;
|
|
|
|
radialProgress.setProgress(setProgress, false);
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), ifSame, animated);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
invalidate();
|
|
|
|
} else {
|
2018-07-30 04:07:02 +02:00
|
|
|
DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC || documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO) {
|
2017-07-08 18:32:04 +02:00
|
|
|
boolean playing = MediaController.getInstance().isPlayingMessage(currentMessageObject);
|
|
|
|
if (!playing || playing && MediaController.getInstance().isMessagePaused()) {
|
2016-10-11 13:57:01 +02:00
|
|
|
buttonState = 0;
|
|
|
|
} else {
|
|
|
|
buttonState = 1;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setProgress(1, animated);
|
2016-10-11 13:57:01 +02:00
|
|
|
} else {
|
|
|
|
buttonState = -1;
|
|
|
|
}
|
2019-01-23 18:03:33 +01:00
|
|
|
radialProgress.setIcon(getIconForCurrentState(), ifSame, animated);
|
2016-01-11 18:19:48 +01:00
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void setDelegate(ContextLinkCellDelegate contextLinkCellDelegate) {
|
|
|
|
delegate = contextLinkCellDelegate;
|
|
|
|
}
|
|
|
|
|
|
|
|
public TLRPC.BotInlineResult getResult() {
|
2016-04-22 15:49:00 +02:00
|
|
|
return inlineResult;
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2019-01-23 18:03:33 +01:00
|
|
|
public void onFailedDownload(String fileName, boolean canceled) {
|
|
|
|
updateButtonState(true, canceled);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccessDownload(String fileName) {
|
|
|
|
radialProgress.setProgress(1, true);
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, true);
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-23 07:15:40 +01:00
|
|
|
public void onProgressDownload(String fileName, long downloadedSize, long totalSize) {
|
|
|
|
radialProgress.setProgress(Math.min(1f, downloadedSize / (float) totalSize), true);
|
2016-10-11 13:57:01 +02:00
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO || documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
|
|
|
|
if (buttonState != 4) {
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (buttonState != 1) {
|
2019-01-23 18:03:33 +01:00
|
|
|
updateButtonState(false, true);
|
2016-10-11 13:57:01 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2020-01-23 07:15:40 +01:00
|
|
|
public void onProgressUpload(String fileName, long uploadedSize, long totalSize, boolean isEncrypted) {
|
2016-01-11 18:19:48 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public int getObserverTag() {
|
|
|
|
return TAG;
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
|
|
|
|
super.onInitializeAccessibilityNodeInfo(info);
|
|
|
|
StringBuilder sbuf = new StringBuilder();
|
|
|
|
switch (documentAttachType) {
|
|
|
|
case DOCUMENT_ATTACH_TYPE_DOCUMENT:
|
|
|
|
sbuf.append(LocaleController.getString("AttachDocument", R.string.AttachDocument));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_GIF:
|
|
|
|
sbuf.append(LocaleController.getString("AttachGif", R.string.AttachGif));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_AUDIO:
|
|
|
|
sbuf.append(LocaleController.getString("AttachAudio", R.string.AttachAudio));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_VIDEO:
|
|
|
|
sbuf.append(LocaleController.getString("AttachVideo", R.string.AttachVideo));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_MUSIC:
|
|
|
|
sbuf.append(LocaleController.getString("AttachMusic", R.string.AttachMusic));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_STICKER:
|
|
|
|
sbuf.append(LocaleController.getString("AttachSticker", R.string.AttachSticker));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_PHOTO:
|
|
|
|
sbuf.append(LocaleController.getString("AttachPhoto", R.string.AttachPhoto));
|
|
|
|
break;
|
|
|
|
case DOCUMENT_ATTACH_TYPE_GEO:
|
|
|
|
sbuf.append(LocaleController.getString("AttachLocation", R.string.AttachLocation));
|
|
|
|
break;
|
2020-07-26 10:03:38 +02:00
|
|
|
}
|
|
|
|
final boolean hasTitle = titleLayout != null && !TextUtils.isEmpty(titleLayout.getText());
|
|
|
|
final boolean hasDescription = descriptionLayout != null && !TextUtils.isEmpty(descriptionLayout.getText());
|
|
|
|
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC && hasTitle && hasDescription) {
|
|
|
|
sbuf.append(", ");
|
|
|
|
sbuf.append(LocaleController.formatString("AccDescrMusicInfo", R.string.AccDescrMusicInfo, descriptionLayout.getText(), titleLayout.getText()));
|
|
|
|
} else {
|
|
|
|
if (hasTitle) {
|
|
|
|
if (sbuf.length() > 0) {
|
|
|
|
sbuf.append(", ");
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
sbuf.append(titleLayout.getText());
|
|
|
|
}
|
|
|
|
if (hasDescription) {
|
|
|
|
if (sbuf.length() > 0) {
|
|
|
|
sbuf.append(", ");
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2020-07-26 10:03:38 +02:00
|
|
|
sbuf.append(descriptionLayout.getText());
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
|
|
|
info.setText(sbuf);
|
2020-03-30 14:00:09 +02:00
|
|
|
if (checkBox != null && checkBox.isChecked()) {
|
|
|
|
info.setCheckable(true);
|
|
|
|
info.setChecked(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private float imageScale = 1.0f;
|
|
|
|
|
|
|
|
public final Property<ContextLinkCell, Float> IMAGE_SCALE = new AnimationProperties.FloatProperty<ContextLinkCell>("animationValue") {
|
|
|
|
@Override
|
|
|
|
public void setValue(ContextLinkCell object, float value) {
|
|
|
|
imageScale = value;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Float get(ContextLinkCell object) {
|
|
|
|
return imageScale;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public void setChecked(boolean checked, boolean animated) {
|
|
|
|
if (checkBox == null) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (checkBox.getVisibility() != VISIBLE) {
|
|
|
|
checkBox.setVisibility(VISIBLE);
|
|
|
|
}
|
|
|
|
checkBox.setChecked(checked, animated);
|
|
|
|
if (animator != null) {
|
|
|
|
animator.cancel();
|
|
|
|
animator = null;
|
|
|
|
}
|
|
|
|
if (animated) {
|
|
|
|
animator = new AnimatorSet();
|
|
|
|
animator.playTogether(
|
|
|
|
ObjectAnimator.ofFloat(this, IMAGE_SCALE, checked ? 0.81f : 1.0f));
|
|
|
|
animator.setDuration(200);
|
|
|
|
animator.addListener(new AnimatorListenerAdapter() {
|
|
|
|
@Override
|
|
|
|
public void onAnimationEnd(Animator animation) {
|
|
|
|
if (animator != null && animator.equals(animation)) {
|
|
|
|
animator = null;
|
|
|
|
if (!checked) {
|
|
|
|
setBackgroundColor(0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onAnimationCancel(Animator animation) {
|
|
|
|
if (animator != null && animator.equals(animation)) {
|
|
|
|
animator = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
animator.start();
|
|
|
|
} else {
|
|
|
|
imageScale = checked ? 0.85f : 1.0f;
|
|
|
|
invalidate();
|
|
|
|
}
|
2019-05-14 14:08:05 +02:00
|
|
|
}
|
2016-01-11 18:19:48 +01:00
|
|
|
}
|