2014-02-11 15:32:09 +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).
|
|
|
|
*
|
|
|
|
* Copyright Nikolai Kudashov, 2013.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.telegram.ui.Cells;
|
|
|
|
|
|
|
|
import android.content.Context;
|
2015-04-09 20:00:14 +02:00
|
|
|
import android.content.Intent;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.graphics.Canvas;
|
2015-04-09 20:00:14 +02:00
|
|
|
import android.graphics.Paint;
|
|
|
|
import android.graphics.drawable.Drawable;
|
|
|
|
import android.net.Uri;
|
2015-05-21 23:27:27 +02:00
|
|
|
import android.os.Build;
|
2015-04-09 20:00:14 +02:00
|
|
|
import android.provider.Browser;
|
|
|
|
import android.text.Layout;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.text.Spannable;
|
2015-04-09 20:00:14 +02:00
|
|
|
import android.text.SpannableStringBuilder;
|
|
|
|
import android.text.StaticLayout;
|
|
|
|
import android.text.TextPaint;
|
|
|
|
import android.text.TextUtils;
|
2014-02-28 23:28:25 +01:00
|
|
|
import android.text.style.ClickableSpan;
|
|
|
|
import android.view.MotionEvent;
|
2015-08-13 11:23:31 +02:00
|
|
|
import android.view.SoundEffectConstants;
|
2014-02-11 15:32:09 +01:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
import org.telegram.android.AndroidUtilities;
|
2015-08-13 11:23:31 +02:00
|
|
|
import org.telegram.android.ImageLoader;
|
2015-04-09 20:00:14 +02:00
|
|
|
import org.telegram.android.ImageReceiver;
|
|
|
|
import org.telegram.android.MediaController;
|
|
|
|
import org.telegram.messenger.FileLoader;
|
2014-03-10 10:27:49 +01:00
|
|
|
import org.telegram.messenger.FileLog;
|
2014-08-22 16:24:33 +02:00
|
|
|
import org.telegram.android.MessageObject;
|
2015-04-09 20:00:14 +02:00
|
|
|
import org.telegram.messenger.R;
|
|
|
|
import org.telegram.messenger.TLRPC;
|
2015-08-13 11:23:31 +02:00
|
|
|
import org.telegram.ui.Components.RadialProgress;
|
2015-05-03 13:48:36 +02:00
|
|
|
import org.telegram.ui.Components.ResourceLoader;
|
2015-04-09 20:00:14 +02:00
|
|
|
import org.telegram.ui.Components.StaticLayoutEx;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
import java.io.File;
|
2015-04-09 20:00:14 +02:00
|
|
|
import java.util.Locale;
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
public class ChatMessageCell extends ChatBaseCell {
|
|
|
|
|
|
|
|
private int textX, textY;
|
|
|
|
private int totalHeight = 0;
|
2015-04-09 20:00:14 +02:00
|
|
|
private int linkBlockNum;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
private int lastVisibleBlockNum = 0;
|
|
|
|
private int firstVisibleBlockNum = 0;
|
|
|
|
private int totalVisibleBlocksCount = 0;
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private RadialProgress radialProgress;
|
2015-04-09 20:00:14 +02:00
|
|
|
private ImageReceiver linkImageView;
|
|
|
|
private boolean isSmallImage;
|
2015-08-13 11:23:31 +02:00
|
|
|
private boolean drawImageButton;
|
2015-04-09 20:00:14 +02:00
|
|
|
private boolean drawLinkImageView;
|
|
|
|
private boolean hasLinkPreview;
|
|
|
|
private int linkPreviewHeight;
|
|
|
|
private boolean isInstagram;
|
|
|
|
private int descriptionY;
|
|
|
|
private int durationWidth;
|
2015-05-21 23:27:27 +02:00
|
|
|
private int descriptionX;
|
|
|
|
private int titleX;
|
|
|
|
private int authorX;
|
2015-04-09 20:00:14 +02:00
|
|
|
private StaticLayout siteNameLayout;
|
|
|
|
private StaticLayout titleLayout;
|
|
|
|
private StaticLayout descriptionLayout;
|
|
|
|
private StaticLayout durationLayout;
|
|
|
|
private StaticLayout authorLayout;
|
|
|
|
private static TextPaint durationPaint;
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
private int buttonX;
|
|
|
|
private int buttonY;
|
|
|
|
private int buttonState;
|
|
|
|
private boolean buttonPressed;
|
|
|
|
private boolean photoNotSet;
|
|
|
|
private TLRPC.PhotoSize currentPhotoObject;
|
|
|
|
private TLRPC.PhotoSize currentPhotoObjectThumb;
|
|
|
|
private String currentPhotoFilter;
|
|
|
|
private String currentPhotoFilterThumb;
|
|
|
|
private boolean cancelLoading;
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
private static Drawable igvideoDrawable;
|
|
|
|
|
2014-03-31 16:14:49 +02:00
|
|
|
public ChatMessageCell(Context context) {
|
2014-08-29 23:06:04 +02:00
|
|
|
super(context);
|
2014-02-28 23:28:25 +01:00
|
|
|
drawForwardedName = true;
|
2015-04-09 20:00:14 +02:00
|
|
|
linkImageView = new ImageReceiver(this);
|
2015-08-13 11:23:31 +02:00
|
|
|
radialProgress = new RadialProgress(this);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
@Override
|
|
|
|
public boolean onTouchEvent(MotionEvent event) {
|
2015-04-09 20:00:14 +02:00
|
|
|
boolean result = false;
|
2015-06-29 19:12:11 +02:00
|
|
|
if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && !currentMessageObject.textLayoutBlocks.isEmpty() && currentMessageObject.messageText instanceof Spannable && delegate.canPerformActions()) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN || (linkPreviewPressed || pressedLink != null || buttonPressed) && event.getAction() == MotionEvent.ACTION_UP) {
|
2015-05-03 13:48:36 +02:00
|
|
|
int x = (int) event.getX();
|
|
|
|
int y = (int) event.getY();
|
2014-02-28 23:28:25 +01:00
|
|
|
if (x >= textX && y >= textY && x <= textX + currentMessageObject.textWidth && y <= textY + currentMessageObject.textHeight) {
|
2014-05-17 01:32:05 +02:00
|
|
|
y -= textY;
|
2014-05-18 23:44:30 +02:00
|
|
|
int blockNum = Math.max(0, y / currentMessageObject.blockHeight);
|
2014-02-28 23:28:25 +01:00
|
|
|
if (blockNum < currentMessageObject.textLayoutBlocks.size()) {
|
2014-10-22 22:01:07 +02:00
|
|
|
try {
|
|
|
|
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(blockNum);
|
2015-05-03 13:48:36 +02:00
|
|
|
x -= textX - (int) Math.ceil(block.textXOffset);
|
2014-10-22 22:01:07 +02:00
|
|
|
y -= block.textYOffset;
|
|
|
|
final int line = block.textLayout.getLineForVertical(y);
|
|
|
|
final int off = block.textLayout.getOffsetForHorizontal(line, x) + block.charactersOffset;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2014-10-22 22:01:07 +02:00
|
|
|
final float left = block.textLayout.getLineLeft(line);
|
|
|
|
if (left <= x && left + block.textLayout.getLineWidth(line) >= x) {
|
2015-05-03 13:48:36 +02:00
|
|
|
Spannable buffer = (Spannable) currentMessageObject.messageText;
|
2014-10-22 22:01:07 +02:00
|
|
|
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
|
|
|
|
if (link.length != 0) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
2014-10-22 22:01:07 +02:00
|
|
|
pressedLink = link[0];
|
2015-04-09 20:00:14 +02:00
|
|
|
linkBlockNum = blockNum;
|
|
|
|
try {
|
|
|
|
int start = buffer.getSpanStart(pressedLink) - block.charactersOffset;
|
|
|
|
urlPath.setCurrentLayout(block.textLayout, start);
|
|
|
|
block.textLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink) - block.charactersOffset, urlPath);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
result = true;
|
2014-10-22 22:01:07 +02:00
|
|
|
} else {
|
|
|
|
if (link[0] == pressedLink) {
|
|
|
|
try {
|
2015-09-02 00:14:21 +02:00
|
|
|
delegate.didPressUrl(currentMessageObject, pressedLink);
|
2014-10-22 22:01:07 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
|
|
|
result = true;
|
2014-10-22 22:01:07 +02:00
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-10-22 22:01:07 +02:00
|
|
|
} catch (Exception e) {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
2014-10-22 22:01:07 +02:00
|
|
|
FileLog.e("tmessages", e);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
|
|
|
}
|
|
|
|
} else if (hasLinkPreview && x >= textX && x <= textX + backgroundWidth && y >= textY + currentMessageObject.textHeight && y <= textY + currentMessageObject.textHeight + linkPreviewHeight + AndroidUtilities.dp(8)) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
resetPressedLink();
|
|
|
|
if (drawLinkImageView && linkImageView.isInsideImage(x, y)) {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (drawImageButton && buttonState != -1 && x >= buttonX && x <= buttonX + AndroidUtilities.dp(48) && y >= buttonY && y <= buttonY + AndroidUtilities.dp(48)) {
|
|
|
|
buttonPressed = true;
|
|
|
|
result = true;
|
|
|
|
} else {
|
|
|
|
linkPreviewPressed = true;
|
|
|
|
result = true;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
if (descriptionLayout != null && y >= descriptionY) {
|
|
|
|
try {
|
2015-05-21 23:27:27 +02:00
|
|
|
x -= textX + AndroidUtilities.dp(10) + descriptionX;
|
2015-04-09 20:00:14 +02:00
|
|
|
y -= descriptionY;
|
|
|
|
final int line = descriptionLayout.getLineForVertical(y);
|
|
|
|
final int off = descriptionLayout.getOffsetForHorizontal(line, x);
|
|
|
|
|
|
|
|
final float left = descriptionLayout.getLineLeft(line);
|
|
|
|
if (left <= x && left + descriptionLayout.getLineWidth(line) >= x) {
|
|
|
|
Spannable buffer = (Spannable) currentMessageObject.linkDescription;
|
|
|
|
ClickableSpan[] link = buffer.getSpans(off, off, ClickableSpan.class);
|
|
|
|
if (link.length != 0) {
|
|
|
|
resetPressedLink();
|
|
|
|
pressedLink = link[0];
|
|
|
|
linkPreviewPressed = true;
|
|
|
|
linkBlockNum = -10;
|
|
|
|
result = true;
|
|
|
|
try {
|
|
|
|
int start = buffer.getSpanStart(pressedLink);
|
|
|
|
urlPath.setCurrentLayout(descriptionLayout, start);
|
|
|
|
descriptionLayout.getSelectionPath(start, buffer.getSpanEnd(pressedLink), urlPath);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resetPressedLink();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
resetPressedLink();
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
resetPressedLink();
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (linkPreviewPressed) {
|
|
|
|
try {
|
|
|
|
if (pressedLink != null) {
|
|
|
|
pressedLink.onClick(this);
|
|
|
|
} else {
|
2015-08-13 11:23:31 +02:00
|
|
|
if (drawImageButton && delegate != null) {
|
2015-09-02 00:14:21 +02:00
|
|
|
if (buttonState == -1) {
|
|
|
|
playSoundEffect(SoundEffectConstants.CLICK);
|
|
|
|
delegate.didClickedImage(this);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
} else {
|
2015-08-13 11:23:31 +02:00
|
|
|
TLRPC.WebPage webPage = currentMessageObject.messageOwner.media.webpage;
|
|
|
|
if (Build.VERSION.SDK_INT >= 16 && webPage.embed_url != null && webPage.embed_url.length() != 0) {
|
|
|
|
delegate.needOpenWebView(webPage.embed_url, webPage.site_name, webPage.url, webPage.embed_width, webPage.embed_height);
|
|
|
|
} else {
|
|
|
|
Uri uri = Uri.parse(webPage.url);
|
|
|
|
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
|
|
|
intent.putExtra(Browser.EXTRA_APPLICATION_ID, getContext().getPackageName());
|
|
|
|
getContext().startActivity(intent);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
resetPressedLink();
|
|
|
|
result = true;
|
2015-08-13 11:23:31 +02:00
|
|
|
} else if (buttonPressed) {
|
|
|
|
if (event.getAction() == MotionEvent.ACTION_UP) {
|
|
|
|
buttonPressed = false;
|
|
|
|
playSoundEffect(SoundEffectConstants.CLICK);
|
|
|
|
didPressedButton(false);
|
|
|
|
invalidate();
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
buttonPressed = false;
|
|
|
|
invalidate();
|
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_MOVE) {
|
|
|
|
if (!(x >= buttonX && x <= buttonX + AndroidUtilities.dp(48) && y >= buttonY && y <= buttonY + AndroidUtilities.dp(48))) {
|
|
|
|
buttonPressed = false;
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
} else if (event.getAction() == MotionEvent.ACTION_CANCEL) {
|
|
|
|
resetPressedLink();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
} else {
|
2015-04-09 20:00:14 +02:00
|
|
|
resetPressedLink();
|
|
|
|
}
|
|
|
|
if (result && event.getAction() == MotionEvent.ACTION_DOWN) {
|
|
|
|
startCheckLongPress();
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
if (event.getAction() != MotionEvent.ACTION_DOWN && event.getAction() != MotionEvent.ACTION_MOVE) {
|
|
|
|
cancelCheckLongPress();
|
|
|
|
}
|
|
|
|
return result || super.onTouchEvent(event);
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
public void setVisiblePart(int position, int height) {
|
2014-03-10 10:27:49 +01:00
|
|
|
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null) {
|
|
|
|
return;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
int newFirst = -1, newLast = -1, newCount = 0;
|
|
|
|
|
2014-03-04 20:29:32 +01:00
|
|
|
for (int a = Math.max(0, (position - textY) / currentMessageObject.blockHeight); a < currentMessageObject.textLayoutBlocks.size(); a++) {
|
2014-02-28 23:28:25 +01:00
|
|
|
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
|
|
|
|
float y = textY + block.textYOffset;
|
2014-03-04 20:29:32 +01:00
|
|
|
if (intersect(y, y + currentMessageObject.blockHeight, position, position + height)) {
|
2014-02-28 23:28:25 +01:00
|
|
|
if (newFirst == -1) {
|
|
|
|
newFirst = a;
|
|
|
|
}
|
|
|
|
newLast = a;
|
|
|
|
newCount++;
|
2014-03-04 20:29:32 +01:00
|
|
|
} else if (y > position) {
|
2014-02-28 23:28:25 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (lastVisibleBlockNum != newLast || firstVisibleBlockNum != newFirst || totalVisibleBlocksCount != newCount) {
|
|
|
|
lastVisibleBlockNum = newLast;
|
|
|
|
firstVisibleBlockNum = newFirst;
|
|
|
|
totalVisibleBlocksCount = newCount;
|
|
|
|
invalidate();
|
|
|
|
}
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
private boolean intersect(float left1, float right1, float left2, float right2) {
|
|
|
|
if (left1 <= left2) {
|
|
|
|
return right1 >= left2;
|
|
|
|
}
|
|
|
|
return left1 <= right2;
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
public static StaticLayout generateStaticLayout(CharSequence text, TextPaint paint, int maxWidth, int smallWidth, int linesCount, int maxLines) {
|
2015-04-09 20:00:14 +02:00
|
|
|
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(text);
|
|
|
|
int addedChars = 0;
|
|
|
|
StaticLayout layout = new StaticLayout(text, paint, smallWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
for (int a = 0; a < linesCount; a++) {
|
2015-05-21 23:27:27 +02:00
|
|
|
if (layout.getLineLeft(a) != 0) {
|
|
|
|
maxWidth = smallWidth;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
int pos = layout.getLineEnd(a);
|
|
|
|
if (pos == text.length()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
pos--;
|
|
|
|
if (stringBuilder.charAt(pos + addedChars) == ' ') {
|
|
|
|
stringBuilder.replace(pos + addedChars, pos + addedChars + 1, "\n");
|
2015-05-03 13:48:36 +02:00
|
|
|
} else if (stringBuilder.charAt(pos + addedChars) != '\n') {
|
2015-04-09 20:00:14 +02:00
|
|
|
stringBuilder.insert(pos + addedChars, "\n");
|
|
|
|
addedChars++;
|
|
|
|
}
|
|
|
|
if (a == layout.getLineCount() - 1 || a == maxLines - 1) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return StaticLayoutEx.createStaticLayout(stringBuilder, paint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, maxWidth, maxLines);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isUserDataChanged() {
|
2015-05-03 13:48:36 +02:00
|
|
|
if (!hasLinkPreview && currentMessageObject.messageOwner.media != null && currentMessageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
|
2015-04-09 20:00:14 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
//suppress warning
|
|
|
|
return super.isUserDataChanged();
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
@Override
|
|
|
|
public ImageReceiver getPhotoImage() {
|
|
|
|
return linkImageView;
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
@Override
|
|
|
|
protected void onDetachedFromWindow() {
|
|
|
|
super.onDetachedFromWindow();
|
2015-05-03 13:48:36 +02:00
|
|
|
linkImageView.onDetachedFromWindow();
|
2015-08-13 11:23:31 +02:00
|
|
|
MediaController.getInstance().removeLoadingFileObserver(this);
|
2015-05-03 13:48:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onAttachedToWindow() {
|
|
|
|
super.onAttachedToWindow();
|
2015-08-13 11:23:31 +02:00
|
|
|
if (linkImageView.onAttachedToWindow()) {
|
|
|
|
updateButtonState(false);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
@Override
|
|
|
|
public void setMessageObject(MessageObject messageObject) {
|
2015-08-13 11:23:31 +02:00
|
|
|
boolean dataChanged = currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet);
|
|
|
|
if (currentMessageObject != messageObject || dataChanged) {
|
2014-03-10 10:27:49 +01:00
|
|
|
if (currentMessageObject != messageObject) {
|
|
|
|
firstVisibleBlockNum = 0;
|
|
|
|
lastVisibleBlockNum = 0;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
drawLinkImageView = false;
|
|
|
|
hasLinkPreview = false;
|
|
|
|
resetPressedLink();
|
|
|
|
linkPreviewPressed = false;
|
2015-08-13 11:23:31 +02:00
|
|
|
buttonPressed = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
linkPreviewHeight = 0;
|
|
|
|
isInstagram = false;
|
|
|
|
durationLayout = null;
|
|
|
|
descriptionLayout = null;
|
|
|
|
titleLayout = null;
|
|
|
|
siteNameLayout = null;
|
|
|
|
authorLayout = null;
|
2015-08-13 11:23:31 +02:00
|
|
|
drawImageButton = false;
|
|
|
|
currentPhotoObject = null;
|
|
|
|
currentPhotoObjectThumb = null;
|
|
|
|
currentPhotoFilter = null;
|
2014-02-28 23:28:25 +01:00
|
|
|
int maxWidth;
|
2014-09-24 04:17:27 +02:00
|
|
|
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (isChat && !messageObject.isOut()) {
|
2014-09-25 05:54:35 +02:00
|
|
|
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
|
2014-09-24 04:17:27 +02:00
|
|
|
drawName = true;
|
|
|
|
} else {
|
2014-09-25 05:54:35 +02:00
|
|
|
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
|
2014-09-24 04:17:27 +02:00
|
|
|
drawName = false;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
2014-09-24 04:17:27 +02:00
|
|
|
if (isChat && !messageObject.isOut()) {
|
2014-12-01 18:56:31 +01:00
|
|
|
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
|
2014-09-24 04:17:27 +02:00
|
|
|
drawName = true;
|
|
|
|
} else {
|
2014-12-01 18:56:31 +01:00
|
|
|
maxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
|
2014-09-24 04:17:27 +02:00
|
|
|
drawName = false;
|
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
backgroundWidth = maxWidth;
|
|
|
|
|
|
|
|
super.setMessageObject(messageObject);
|
|
|
|
|
|
|
|
backgroundWidth = messageObject.textWidth;
|
2014-11-06 22:34:47 +01:00
|
|
|
totalHeight = messageObject.textHeight + AndroidUtilities.dp(19.5f) + namesOffset;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
|
|
|
int maxChildWidth = Math.max(backgroundWidth, nameWidth);
|
|
|
|
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
|
2015-03-19 00:09:45 +01:00
|
|
|
maxChildWidth = Math.max(maxChildWidth, replyNameWidth);
|
|
|
|
maxChildWidth = Math.max(maxChildWidth, replyTextWidth);
|
2015-05-21 23:27:27 +02:00
|
|
|
int maxWebWidth = 0;
|
2014-02-28 23:28:25 +01:00
|
|
|
|
2014-07-03 00:39:05 +02:00
|
|
|
int timeMore = timeWidth + AndroidUtilities.dp(6);
|
2014-04-03 23:18:54 +02:00
|
|
|
if (messageObject.isOut()) {
|
2014-11-06 22:34:47 +01:00
|
|
|
timeMore += AndroidUtilities.dp(20.5f);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage) {
|
|
|
|
int linkPreviewMaxWidth;
|
|
|
|
if (AndroidUtilities.isTablet()) {
|
|
|
|
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
|
|
|
|
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
|
|
|
|
} else {
|
|
|
|
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (currentMessageObject.messageOwner.to_id.chat_id != 0 && !currentMessageObject.isOut()) {
|
|
|
|
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
|
|
|
|
} else {
|
|
|
|
linkPreviewMaxWidth = Math.min(AndroidUtilities.displaySize.x, AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
|
|
|
|
}
|
|
|
|
}
|
2015-05-03 13:48:36 +02:00
|
|
|
|
|
|
|
TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) messageObject.messageOwner.media.webpage;
|
|
|
|
|
|
|
|
if (webPage.site_name != null && webPage.photo != null && webPage.site_name.toLowerCase().equals("instagram")) {
|
|
|
|
linkPreviewMaxWidth = Math.max(AndroidUtilities.displaySize.y / 3, currentMessageObject.textWidth);
|
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
int additinalWidth = AndroidUtilities.dp(10);
|
|
|
|
int restLinesCount = 3;
|
|
|
|
int additionalHeight = 0;
|
|
|
|
linkPreviewMaxWidth -= additinalWidth;
|
|
|
|
|
|
|
|
hasLinkPreview = true;
|
|
|
|
|
|
|
|
if (currentMessageObject.photoThumbs == null && webPage.photo != null) {
|
|
|
|
currentMessageObject.generateThumbs(true);
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
isSmallImage = webPage.description != null && webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article")) && currentMessageObject.photoThumbs != null;
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (webPage.site_name != null) {
|
|
|
|
try {
|
|
|
|
int width = (int) Math.ceil(replyNamePaint.measureText(webPage.site_name));
|
|
|
|
siteNameLayout = new StaticLayout(webPage.site_name, replyNamePaint, Math.min(width, linkPreviewMaxWidth), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
int height = siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
|
|
|
|
linkPreviewHeight += height;
|
|
|
|
totalHeight += height;
|
|
|
|
additionalHeight += height;
|
2015-05-21 23:27:27 +02:00
|
|
|
width = siteNameLayout.getWidth();
|
2015-04-09 20:00:14 +02:00
|
|
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
2015-05-21 23:27:27 +02:00
|
|
|
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
|
2015-04-09 20:00:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
boolean titleIsRTL = false;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (webPage.title != null) {
|
|
|
|
try {
|
2015-05-21 23:27:27 +02:00
|
|
|
titleX = 0;
|
2015-04-09 20:00:14 +02:00
|
|
|
if (linkPreviewHeight != 0) {
|
|
|
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
|
|
|
totalHeight += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
int restLines = 0;
|
|
|
|
if (!isSmallImage || webPage.description == null) {
|
2015-05-21 23:27:27 +02:00
|
|
|
titleLayout = StaticLayoutEx.createStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 4);
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
restLines = restLinesCount;
|
2015-05-21 23:27:27 +02:00
|
|
|
titleLayout = generateStaticLayout(webPage.title, replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 4);
|
2015-04-09 20:00:14 +02:00
|
|
|
restLinesCount -= titleLayout.getLineCount();
|
|
|
|
}
|
|
|
|
int height = titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
|
|
|
|
linkPreviewHeight += height;
|
|
|
|
totalHeight += height;
|
|
|
|
for (int a = 0; a < titleLayout.getLineCount(); a++) {
|
2015-05-21 23:27:27 +02:00
|
|
|
int lineLeft = (int) titleLayout.getLineLeft(a);
|
|
|
|
if (lineLeft != 0) {
|
|
|
|
titleIsRTL = true;
|
|
|
|
if (titleX == 0) {
|
|
|
|
titleX = -lineLeft;
|
|
|
|
} else {
|
|
|
|
titleX = Math.max(titleX, -lineLeft);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int width;
|
|
|
|
if (lineLeft != 0) {
|
|
|
|
width = titleLayout.getWidth() - lineLeft;
|
|
|
|
} else {
|
|
|
|
width = (int) Math.ceil(titleLayout.getLineWidth(a));
|
|
|
|
}
|
|
|
|
if (a < restLines || lineLeft != 0 && isSmallImage) {
|
2015-04-09 20:00:14 +02:00
|
|
|
width += AndroidUtilities.dp(48 + 2);
|
|
|
|
}
|
|
|
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
2015-05-21 23:27:27 +02:00
|
|
|
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (webPage.author != null) {
|
|
|
|
try {
|
|
|
|
if (linkPreviewHeight != 0) {
|
|
|
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
|
|
|
totalHeight += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
int width = Math.min((int) Math.ceil(replyNamePaint.measureText(webPage.author)), linkPreviewMaxWidth);
|
|
|
|
if (restLinesCount == 3 && (!isSmallImage || webPage.description == null)) {
|
|
|
|
authorLayout = new StaticLayout(webPage.author, replyNamePaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
} else {
|
|
|
|
authorLayout = generateStaticLayout(webPage.author, replyNamePaint, width, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 1);
|
|
|
|
restLinesCount -= authorLayout.getLineCount();
|
|
|
|
}
|
|
|
|
int height = authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
|
|
|
|
linkPreviewHeight += height;
|
|
|
|
totalHeight += height;
|
2015-05-21 23:27:27 +02:00
|
|
|
int lineLeft = (int) authorLayout.getLineLeft(0);
|
|
|
|
authorX = -lineLeft;
|
2015-04-09 20:00:14 +02:00
|
|
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
2015-05-21 23:27:27 +02:00
|
|
|
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
|
2015-04-09 20:00:14 +02:00
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (webPage.description != null) {
|
|
|
|
try {
|
2015-05-21 23:27:27 +02:00
|
|
|
descriptionX = 0;
|
2015-04-09 20:00:14 +02:00
|
|
|
currentMessageObject.generateLinkDescription();
|
|
|
|
if (linkPreviewHeight != 0) {
|
|
|
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
|
|
|
totalHeight += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
int restLines = 0;
|
|
|
|
if (restLinesCount == 3 && !isSmallImage) {
|
|
|
|
descriptionLayout = StaticLayoutEx.createStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 6);
|
|
|
|
} else {
|
|
|
|
restLines = restLinesCount;
|
|
|
|
descriptionLayout = generateStaticLayout(messageObject.linkDescription, replyTextPaint, linkPreviewMaxWidth, linkPreviewMaxWidth - AndroidUtilities.dp(48 + 2), restLinesCount, 6);
|
|
|
|
}
|
|
|
|
int height = descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
|
|
|
|
linkPreviewHeight += height;
|
|
|
|
totalHeight += height;
|
|
|
|
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
|
2015-05-21 23:27:27 +02:00
|
|
|
int lineLeft = (int) Math.ceil(descriptionLayout.getLineLeft(a));
|
|
|
|
if (descriptionX == 0) {
|
|
|
|
descriptionX = -lineLeft;
|
|
|
|
} else {
|
|
|
|
descriptionX = Math.max(descriptionX, -lineLeft);
|
|
|
|
}
|
|
|
|
|
|
|
|
int width;
|
|
|
|
if (lineLeft != 0) {
|
|
|
|
width = descriptionLayout.getWidth() - lineLeft;
|
|
|
|
} else {
|
|
|
|
width = (int) Math.ceil(descriptionLayout.getLineWidth(a));
|
|
|
|
}
|
|
|
|
if (a < restLines || lineLeft != 0 && isSmallImage) {
|
2015-04-09 20:00:14 +02:00
|
|
|
width += AndroidUtilities.dp(48 + 2);
|
|
|
|
}
|
2015-05-21 23:27:27 +02:00
|
|
|
if (maxWebWidth < width + additinalWidth) {
|
|
|
|
if (titleIsRTL) {
|
|
|
|
titleX += (width + additinalWidth - maxWebWidth);
|
|
|
|
}
|
|
|
|
maxWebWidth = width + additinalWidth;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
|
|
|
|
}
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-21 23:27:27 +02:00
|
|
|
if (webPage.photo != null) {
|
2015-04-09 20:00:14 +02:00
|
|
|
boolean smallImage = webPage.type != null && (webPage.type.equals("app") || webPage.type.equals("profile") || webPage.type.equals("article"));
|
2015-07-22 20:56:37 +02:00
|
|
|
if (smallImage && (descriptionLayout == null || descriptionLayout != null && descriptionLayout.getLineCount() == 1)) {
|
2015-04-09 20:00:14 +02:00
|
|
|
smallImage = false;
|
|
|
|
isSmallImage = false;
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
drawImageButton = webPage.type != null && webPage.type.equals("photo");
|
2015-04-09 20:00:14 +02:00
|
|
|
int maxPhotoWidth = smallImage ? AndroidUtilities.dp(48) : linkPreviewMaxWidth;
|
2015-08-13 11:23:31 +02:00
|
|
|
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, drawImageButton ? AndroidUtilities.getPhotoSize() : maxPhotoWidth, !drawImageButton);
|
|
|
|
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 80);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentPhotoObjectThumb == currentPhotoObject) {
|
|
|
|
currentPhotoObjectThumb = null;
|
|
|
|
}
|
|
|
|
if (currentPhotoObject != null) {
|
|
|
|
if (linkPreviewHeight != 0) {
|
|
|
|
linkPreviewHeight += AndroidUtilities.dp(2);
|
|
|
|
totalHeight += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
maxChildWidth = Math.max(maxChildWidth, maxPhotoWidth + additinalWidth);
|
|
|
|
currentPhotoObject.size = -1;
|
|
|
|
if (currentPhotoObjectThumb != null) {
|
|
|
|
currentPhotoObjectThumb.size = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int width;
|
|
|
|
int height;
|
|
|
|
if (smallImage) {
|
|
|
|
width = height = maxPhotoWidth;
|
|
|
|
} else {
|
|
|
|
width = currentPhotoObject.w;
|
|
|
|
height = currentPhotoObject.h;
|
|
|
|
float scale = width / (float) maxPhotoWidth;
|
|
|
|
width /= scale;
|
|
|
|
height /= scale;
|
2015-05-03 13:48:36 +02:00
|
|
|
if (webPage.site_name != null && !webPage.site_name.toLowerCase().equals("instagram")) {
|
|
|
|
if (height > AndroidUtilities.displaySize.y / 3) {
|
|
|
|
height = AndroidUtilities.displaySize.y / 3;
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (isSmallImage) {
|
|
|
|
if (AndroidUtilities.dp(50) + additionalHeight > linkPreviewHeight) {
|
|
|
|
totalHeight += AndroidUtilities.dp(50) + additionalHeight - linkPreviewHeight + AndroidUtilities.dp(8);
|
|
|
|
linkPreviewHeight = AndroidUtilities.dp(50) + additionalHeight;
|
|
|
|
}
|
|
|
|
linkPreviewHeight -= AndroidUtilities.dp(8);
|
|
|
|
} else {
|
|
|
|
totalHeight += height + AndroidUtilities.dp(12);
|
|
|
|
linkPreviewHeight += height;
|
|
|
|
}
|
|
|
|
|
|
|
|
linkImageView.setImageCoords(0, 0, width, height);
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
|
|
|
|
|
|
|
|
boolean photoExist = true;
|
|
|
|
File cacheFile = FileLoader.getPathToAttach(currentPhotoObject, true);
|
|
|
|
if (!cacheFile.exists()) {
|
|
|
|
photoExist = false;
|
|
|
|
}
|
|
|
|
|
2015-08-13 11:23:31 +02:00
|
|
|
currentPhotoFilter = String.format(Locale.US, "%d_%d", width, height);
|
|
|
|
currentPhotoFilterThumb = String.format(Locale.US, "%d_%d_b", width, height);
|
2015-05-21 23:27:27 +02:00
|
|
|
|
|
|
|
if (photoExist || MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO) || FileLoader.getInstance().isLoadingFile(fileName)) {
|
2015-08-13 11:23:31 +02:00
|
|
|
photoNotSet = false;
|
|
|
|
linkImageView.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilterThumb, 0, null, false);
|
2015-05-21 23:27:27 +02:00
|
|
|
} else {
|
2015-08-13 11:23:31 +02:00
|
|
|
photoNotSet = true;
|
2015-05-21 23:27:27 +02:00
|
|
|
if (currentPhotoObjectThumb != null) {
|
|
|
|
linkImageView.setImage(null, null, currentPhotoObjectThumb.location, String.format(Locale.US, "%d_%d_b", width, height), 0, null, false);
|
|
|
|
} else {
|
|
|
|
linkImageView.setImageBitmap((Drawable) null);
|
|
|
|
}
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
drawLinkImageView = true;
|
|
|
|
|
|
|
|
if (webPage.site_name != null) {
|
|
|
|
if (webPage.site_name.toLowerCase().equals("instagram") && webPage.type != null && webPage.type.equals("video")) {
|
|
|
|
isInstagram = true;
|
|
|
|
if (igvideoDrawable == null) {
|
|
|
|
igvideoDrawable = getResources().getDrawable(R.drawable.igvideo);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-29 19:12:11 +02:00
|
|
|
if (webPage.type != null && webPage.type.equals("video") && webPage.duration != 0) {
|
2015-04-09 20:00:14 +02:00
|
|
|
if (durationPaint == null) {
|
|
|
|
durationPaint = new TextPaint(Paint.ANTI_ALIAS_FLAG);
|
|
|
|
durationPaint.setTextSize(AndroidUtilities.dp(12));
|
|
|
|
durationPaint.setColor(0xffffffff);
|
|
|
|
}
|
|
|
|
int minutes = webPage.duration / 60;
|
|
|
|
int seconds = webPage.duration - minutes * 60;
|
|
|
|
String str = String.format("%d:%02d", minutes, seconds);
|
|
|
|
durationWidth = (int) Math.ceil(durationPaint.measureText(str));
|
|
|
|
durationLayout = new StaticLayout(str, durationPaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
linkPreviewHeight -= AndroidUtilities.dp(6);
|
|
|
|
totalHeight += AndroidUtilities.dp(4);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasLinkPreview || maxWidth - messageObject.lastLineWidth < timeMore) {
|
2014-07-03 00:39:05 +02:00
|
|
|
totalHeight += AndroidUtilities.dp(14);
|
|
|
|
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(29);
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
|
|
|
int diff = maxChildWidth - messageObject.lastLineWidth;
|
|
|
|
if (diff >= 0 && diff <= timeMore) {
|
2014-07-03 00:39:05 +02:00
|
|
|
backgroundWidth = maxChildWidth + timeMore - diff + AndroidUtilities.dp(29);
|
2014-02-28 23:28:25 +01:00
|
|
|
} else {
|
2014-07-03 00:39:05 +02:00
|
|
|
backgroundWidth = Math.max(maxChildWidth, messageObject.lastLineWidth + timeMore) + AndroidUtilities.dp(29);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
updateButtonState(dataChanged);
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
|
|
|
setMeasuredDimension(MeasureSpec.getSize(widthMeasureSpec), totalHeight);
|
|
|
|
}
|
|
|
|
|
2014-03-10 10:27:49 +01:00
|
|
|
@Override
|
|
|
|
protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
|
|
|
|
super.onLayout(changed, left, top, right, bottom);
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
if (currentMessageObject.isOut()) {
|
2014-07-03 00:39:05 +02:00
|
|
|
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
|
|
|
|
textY = AndroidUtilities.dp(10) + namesOffset;
|
2014-03-10 10:27:49 +01:00
|
|
|
} else {
|
2014-07-03 00:39:05 +02:00
|
|
|
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
|
|
|
|
textY = AndroidUtilities.dp(10) + namesOffset;
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-28 23:28:25 +01:00
|
|
|
@Override
|
|
|
|
protected void onDraw(Canvas canvas) {
|
|
|
|
super.onDraw(canvas);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (currentMessageObject == null || currentMessageObject.textLayoutBlocks == null || currentMessageObject.textLayoutBlocks.isEmpty()) {
|
2014-02-28 23:28:25 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-03 23:18:54 +02:00
|
|
|
if (currentMessageObject.isOut()) {
|
2014-07-03 00:39:05 +02:00
|
|
|
textX = layoutWidth - backgroundWidth + AndroidUtilities.dp(10);
|
|
|
|
textY = AndroidUtilities.dp(10) + namesOffset;
|
2014-03-04 20:29:32 +01:00
|
|
|
} else {
|
2014-07-03 00:39:05 +02:00
|
|
|
textX = AndroidUtilities.dp(19) + (isChat ? AndroidUtilities.dp(52) : 0);
|
|
|
|
textY = AndroidUtilities.dp(10) + namesOffset;
|
2014-03-04 20:29:32 +01:00
|
|
|
}
|
|
|
|
|
2015-04-09 20:00:14 +02:00
|
|
|
if (firstVisibleBlockNum >= 0) {
|
|
|
|
for (int a = firstVisibleBlockNum; a <= lastVisibleBlockNum; a++) {
|
|
|
|
if (a >= currentMessageObject.textLayoutBlocks.size()) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
MessageObject.TextLayoutBlock block = currentMessageObject.textLayoutBlocks.get(a);
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(textX - (int) Math.ceil(block.textXOffset), textY + block.textYOffset);
|
|
|
|
if (pressedLink != null && a == linkBlockNum) {
|
|
|
|
canvas.drawPath(urlPath, urlPaint);
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
block.textLayout.draw(canvas);
|
|
|
|
} catch (Exception e) {
|
|
|
|
FileLog.e("tmessages", e);
|
|
|
|
}
|
|
|
|
canvas.restore();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hasLinkPreview) {
|
|
|
|
int startY = textY + currentMessageObject.textHeight + AndroidUtilities.dp(8);
|
|
|
|
int linkPreviewY = startY;
|
|
|
|
int smallImageStartY = 0;
|
|
|
|
replyLinePaint.setColor(currentMessageObject.isOut() ? 0xff8dc97a : 0xff6c9fd2);
|
|
|
|
|
|
|
|
canvas.drawRect(textX, linkPreviewY - AndroidUtilities.dp(3), textX + AndroidUtilities.dp(2), linkPreviewY + linkPreviewHeight + AndroidUtilities.dp(3), replyLinePaint);
|
|
|
|
|
|
|
|
if (siteNameLayout != null) {
|
|
|
|
replyNamePaint.setColor(currentMessageObject.isOut() ? 0xff70b15c : 0xff4b91cf);
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(textX + AndroidUtilities.dp(10), linkPreviewY - AndroidUtilities.dp(3));
|
|
|
|
siteNameLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
linkPreviewY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (titleLayout != null) {
|
|
|
|
if (linkPreviewY != startY) {
|
|
|
|
linkPreviewY += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
replyNamePaint.setColor(0xff000000);
|
|
|
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
|
|
|
canvas.save();
|
2015-05-21 23:27:27 +02:00
|
|
|
canvas.translate(textX + AndroidUtilities.dp(10) + titleX, linkPreviewY - AndroidUtilities.dp(3));
|
2015-04-09 20:00:14 +02:00
|
|
|
titleLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
linkPreviewY += titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (authorLayout != null) {
|
|
|
|
if (linkPreviewY != startY) {
|
|
|
|
linkPreviewY += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
if (smallImageStartY == 0) {
|
|
|
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
|
|
|
}
|
|
|
|
replyNamePaint.setColor(0xff000000);
|
|
|
|
canvas.save();
|
2015-05-21 23:27:27 +02:00
|
|
|
canvas.translate(textX + AndroidUtilities.dp(10) + authorX, linkPreviewY - AndroidUtilities.dp(3));
|
2015-04-09 20:00:14 +02:00
|
|
|
authorLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
linkPreviewY += authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (descriptionLayout != null) {
|
|
|
|
if (linkPreviewY != startY) {
|
|
|
|
linkPreviewY += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
if (smallImageStartY == 0) {
|
|
|
|
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
|
|
|
|
}
|
|
|
|
replyTextPaint.setColor(0xff000000);
|
|
|
|
descriptionY = linkPreviewY - AndroidUtilities.dp(3);
|
|
|
|
canvas.save();
|
2015-05-21 23:27:27 +02:00
|
|
|
canvas.translate(textX + AndroidUtilities.dp(10) + descriptionX, descriptionY);
|
2015-04-09 20:00:14 +02:00
|
|
|
if (pressedLink != null && linkBlockNum == -10) {
|
|
|
|
canvas.drawPath(urlPath, urlPaint);
|
|
|
|
}
|
|
|
|
descriptionLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
linkPreviewY += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (drawLinkImageView) {
|
|
|
|
if (linkPreviewY != startY) {
|
|
|
|
linkPreviewY += AndroidUtilities.dp(2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isSmallImage) {
|
2015-05-03 13:48:36 +02:00
|
|
|
linkImageView.setImageCoords(textX + backgroundWidth - AndroidUtilities.dp(77), smallImageStartY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
|
2015-04-09 20:00:14 +02:00
|
|
|
} else {
|
|
|
|
linkImageView.setImageCoords(textX + AndroidUtilities.dp(10), linkPreviewY, linkImageView.getImageWidth(), linkImageView.getImageHeight());
|
2015-08-13 11:23:31 +02:00
|
|
|
if (drawImageButton) {
|
|
|
|
int size = AndroidUtilities.dp(48);
|
|
|
|
buttonX = (int) (linkImageView.getImageX() + (linkImageView.getImageWidth() - size) / 2.0f);
|
2015-09-02 00:14:21 +02:00
|
|
|
buttonY = (int) (linkImageView.getImageY() + (linkImageView.getImageHeight() - size) / 2.0f);
|
2015-08-13 11:23:31 +02:00
|
|
|
radialProgress.setProgressRect(buttonX, buttonY, buttonX + AndroidUtilities.dp(48), buttonY + AndroidUtilities.dp(48));
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
}
|
|
|
|
linkImageView.draw(canvas);
|
2015-08-13 11:23:31 +02:00
|
|
|
if (drawImageButton) {
|
|
|
|
radialProgress.draw(canvas);
|
|
|
|
}
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
if (isInstagram && igvideoDrawable != null) {
|
|
|
|
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - igvideoDrawable.getIntrinsicWidth() - AndroidUtilities.dp(4);
|
|
|
|
int y = linkImageView.getImageY() + AndroidUtilities.dp(4);
|
|
|
|
igvideoDrawable.setBounds(x, y, x + igvideoDrawable.getIntrinsicWidth(), y + igvideoDrawable.getIntrinsicHeight());
|
|
|
|
igvideoDrawable.draw(canvas);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (durationLayout != null) {
|
|
|
|
int x = linkImageView.getImageX() + linkImageView.getImageWidth() - AndroidUtilities.dp(8) - durationWidth;
|
|
|
|
int y = linkImageView.getImageY() + linkImageView.getImageHeight() - AndroidUtilities.dp(19);
|
2015-05-03 13:48:36 +02:00
|
|
|
ResourceLoader.mediaBackgroundDrawable.setBounds(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + durationWidth + AndroidUtilities.dp(4), y + AndroidUtilities.dp(14.5f));
|
|
|
|
ResourceLoader.mediaBackgroundDrawable.draw(canvas);
|
2015-04-09 20:00:14 +02:00
|
|
|
|
|
|
|
canvas.save();
|
|
|
|
canvas.translate(x, y);
|
|
|
|
durationLayout.draw(canvas);
|
|
|
|
canvas.restore();
|
|
|
|
}
|
2014-03-10 10:27:49 +01:00
|
|
|
}
|
2014-02-28 23:28:25 +01:00
|
|
|
}
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|
2015-08-13 11:23:31 +02:00
|
|
|
|
|
|
|
private Drawable getDrawableForCurrentState() {
|
|
|
|
if (buttonState >= 0 && buttonState < 4) {
|
|
|
|
if (buttonState == 1) {
|
|
|
|
return ResourceLoader.buttonStatesDrawables[4];
|
|
|
|
} else {
|
|
|
|
return ResourceLoader.buttonStatesDrawables[buttonState];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void updateButtonState(boolean animated) {
|
|
|
|
if (currentPhotoObject == null || !drawImageButton) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
|
|
|
|
File cacheFile = FileLoader.getPathToAttach(currentPhotoObject, true);
|
|
|
|
if (fileName == null) {
|
|
|
|
radialProgress.setBackground(null, false, false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (!cacheFile.exists()) {
|
|
|
|
MediaController.getInstance().addLoadingFileObserver(fileName, this);
|
|
|
|
float setProgress = 0;
|
|
|
|
boolean progressVisible = false;
|
|
|
|
if (!FileLoader.getInstance().isLoadingFile(fileName)) {
|
|
|
|
if (cancelLoading || !MediaController.getInstance().canDownloadMedia(MediaController.AUTODOWNLOAD_MASK_PHOTO)) {
|
|
|
|
buttonState = 0;
|
|
|
|
} else {
|
|
|
|
progressVisible = true;
|
|
|
|
buttonState = 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
progressVisible = true;
|
|
|
|
buttonState = 1;
|
|
|
|
Float progress = ImageLoader.getInstance().getFileProgress(fileName);
|
|
|
|
setProgress = progress != null ? progress : 0;
|
|
|
|
}
|
|
|
|
radialProgress.setProgress(setProgress, false);
|
|
|
|
radialProgress.setBackground(getDrawableForCurrentState(), progressVisible, animated);
|
|
|
|
invalidate();
|
|
|
|
} else {
|
|
|
|
MediaController.getInstance().removeLoadingFileObserver(this);
|
|
|
|
buttonState = -1;
|
|
|
|
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void didPressedButton(boolean animated) {
|
|
|
|
if (buttonState == 0) {
|
|
|
|
cancelLoading = false;
|
|
|
|
radialProgress.setProgress(0, false);
|
|
|
|
linkImageView.setImage(currentPhotoObject.location, currentPhotoFilter, currentPhotoObjectThumb != null ? currentPhotoObjectThumb.location : null, currentPhotoFilterThumb, 0, null, false);
|
|
|
|
buttonState = 1;
|
|
|
|
radialProgress.setBackground(getDrawableForCurrentState(), true, animated);
|
|
|
|
invalidate();
|
|
|
|
} else if (buttonState == 1) {
|
|
|
|
if (currentMessageObject.isOut() && currentMessageObject.isSending()) {
|
|
|
|
if (delegate != null) {
|
|
|
|
delegate.didPressedCancelSendButton(this);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
cancelLoading = true;
|
|
|
|
linkImageView.cancelLoadImage();
|
|
|
|
buttonState = 0;
|
|
|
|
radialProgress.setBackground(getDrawableForCurrentState(), false, animated);
|
|
|
|
invalidate();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onFailedDownload(String fileName) {
|
|
|
|
updateButtonState(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onSuccessDownload(String fileName) {
|
|
|
|
radialProgress.setProgress(1, true);
|
|
|
|
if (!photoNotSet) {
|
|
|
|
updateButtonState(true);
|
|
|
|
} else {
|
|
|
|
setMessageObject(currentMessageObject);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onProgressDownload(String fileName, float progress) {
|
|
|
|
radialProgress.setProgress(progress, true);
|
|
|
|
if (buttonState != 1) {
|
|
|
|
updateButtonState(false);
|
|
|
|
}
|
|
|
|
}
|
2014-02-11 15:32:09 +01:00
|
|
|
}
|