use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class Theme method applyChatServiceMessageColor.
public static void applyChatServiceMessageColor(int[] custom, Drawable wallpaperOverride, Drawable currentWallpaper) {
if (chat_actionBackgroundPaint == null) {
return;
}
Integer serviceColor;
Integer servicePressedColor;
serviceMessageColor = serviceMessageColorBackup;
serviceSelectedMessageColor = serviceSelectedMessageColorBackup;
if (custom != null && custom.length >= 2) {
serviceColor = custom[0];
servicePressedColor = custom[1];
serviceMessageColor = custom[0];
serviceSelectedMessageColor = custom[1];
} else {
serviceColor = currentColors.get(key_chat_serviceBackground);
servicePressedColor = currentColors.get(key_chat_serviceBackgroundSelected);
}
Integer serviceColor2 = serviceColor;
Integer servicePressedColor2 = servicePressedColor;
if (serviceColor == null) {
serviceColor = serviceMessageColor;
serviceColor2 = serviceMessage2Color;
}
if (servicePressedColor == null) {
servicePressedColor = serviceSelectedMessageColor;
}
if (servicePressedColor2 == null) {
servicePressedColor2 = serviceSelectedMessage2Color;
}
Drawable drawable = wallpaperOverride != null ? wallpaperOverride : currentWallpaper;
boolean drawServiceGradient = drawable instanceof MotionBackgroundDrawable && SharedConfig.getDevicePerformanceClass() != SharedConfig.PERFORMANCE_CLASS_LOW;
if (drawServiceGradient) {
Bitmap newBitmap = ((MotionBackgroundDrawable) drawable).getBitmap();
if (serviceBitmap != newBitmap) {
serviceBitmap = newBitmap;
serviceBitmapShader = new BitmapShader(serviceBitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP);
if (serviceBitmapMatrix == null) {
serviceBitmapMatrix = new Matrix();
}
}
setDrawableColor(chat_msgStickerPinnedDrawable, 0xffffffff);
setDrawableColor(chat_msgStickerCheckDrawable, 0xffffffff);
setDrawableColor(chat_msgStickerHalfCheckDrawable, 0xffffffff);
setDrawableColor(chat_msgStickerViewsDrawable, 0xffffffff);
setDrawableColor(chat_msgStickerRepliesDrawable, 0xffffffff);
chat_actionTextPaint.setColor(0xffffffff);
chat_actionTextPaint.linkColor = 0xffffffff;
chat_botButtonPaint.setColor(0xffffffff);
setDrawableColor(chat_commentStickerDrawable, 0xffffffff);
setDrawableColor(chat_shareIconDrawable, 0xffffffff);
setDrawableColor(chat_replyIconDrawable, 0xffffffff);
setDrawableColor(chat_goIconDrawable, 0xffffffff);
setDrawableColor(chat_botInlineDrawable, 0xffffffff);
setDrawableColor(chat_botLinkDrawalbe, 0xffffffff);
} else {
serviceBitmap = null;
serviceBitmapShader = null;
setDrawableColorByKey(chat_msgStickerPinnedDrawable, key_chat_serviceText);
setDrawableColorByKey(chat_msgStickerCheckDrawable, key_chat_serviceText);
setDrawableColorByKey(chat_msgStickerHalfCheckDrawable, key_chat_serviceText);
setDrawableColorByKey(chat_msgStickerViewsDrawable, key_chat_serviceText);
setDrawableColorByKey(chat_msgStickerRepliesDrawable, key_chat_serviceText);
chat_actionTextPaint.setColor(getColor(key_chat_serviceText));
chat_actionTextPaint.linkColor = getColor(key_chat_serviceLink);
setDrawableColorByKey(chat_commentStickerDrawable, key_chat_serviceIcon);
setDrawableColorByKey(chat_shareIconDrawable, key_chat_serviceIcon);
setDrawableColorByKey(chat_replyIconDrawable, key_chat_serviceIcon);
setDrawableColorByKey(chat_goIconDrawable, key_chat_serviceIcon);
setDrawableColorByKey(chat_botInlineDrawable, key_chat_serviceIcon);
setDrawableColorByKey(chat_botLinkDrawalbe, key_chat_serviceIcon);
chat_botButtonPaint.setColor(getColor(key_chat_botButtonText));
}
chat_actionBackgroundPaint.setColor(serviceColor);
chat_actionBackgroundSelectedPaint.setColor(servicePressedColor);
chat_actionBackgroundPaint2.setColor(serviceColor2);
chat_actionBackgroundSelectedPaint2.setColor(servicePressedColor2);
currentColor = serviceColor;
if (serviceBitmapShader != null && (currentColors.get(key_chat_serviceBackground) == null || drawable instanceof MotionBackgroundDrawable)) {
chat_actionBackgroundPaint.setShader(serviceBitmapShader);
ColorMatrix colorMatrix = new ColorMatrix();
colorMatrix.setSaturation(((MotionBackgroundDrawable) drawable).getIntensity() >= 0 ? 1.8f : 0.5f);
chat_actionBackgroundPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
chat_actionBackgroundPaint.setAlpha(127);
chat_actionBackgroundSelectedPaint.setShader(serviceBitmapShader);
chat_actionBackgroundSelectedPaint.setColorFilter(new ColorMatrixColorFilter(colorMatrix));
chat_actionBackgroundSelectedPaint.setAlpha(200);
} else {
chat_actionBackgroundPaint.setColorFilter(null);
chat_actionBackgroundPaint.setShader(null);
chat_actionBackgroundSelectedPaint.setColorFilter(null);
chat_actionBackgroundSelectedPaint.setShader(null);
}
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatMessageCell method setMessageContent.
private void setMessageContent(MessageObject messageObject, MessageObject.GroupedMessages groupedMessages, boolean bottomNear, boolean topNear) {
if (messageObject.checkLayout() || currentPosition != null && lastHeight != AndroidUtilities.displaySize.y) {
currentMessageObject = null;
}
boolean widthChanged = lastWidth != getParentWidth();
lastHeight = AndroidUtilities.displaySize.y;
lastWidth = getParentWidth();
isRoundVideo = messageObject != null && messageObject.isRoundVideo();
TLRPC.Message newReply = messageObject.hasValidReplyMessageObject() ? messageObject.replyMessageObject.messageOwner : null;
boolean messageIdChanged = currentMessageObject == null || currentMessageObject.getId() != messageObject.getId();
boolean messageChanged = currentMessageObject != messageObject || messageObject.forceUpdate || (isRoundVideo && isPlayingRound != (MediaController.getInstance().isPlayingMessage(currentMessageObject) && delegate != null && !delegate.keyboardIsOpened()));
boolean dataChanged = currentMessageObject != null && currentMessageObject.getId() == messageObject.getId() && lastSendState == MessageObject.MESSAGE_SEND_STATE_EDITING && messageObject.isSent() || currentMessageObject == messageObject && (isUserDataChanged() || photoNotSet) || lastPostAuthor != messageObject.messageOwner.post_author || wasPinned != isPinned || newReply != lastReplyMessage;
boolean groupChanged = groupedMessages != currentMessagesGroup;
boolean pollChanged = false;
if (dataChanged || messageChanged || messageIdChanged) {
accessibilityText = null;
}
if (drawCommentButton || drawSideButton == 3 && !((hasDiscussion && messageObject.isLinkedToChat(linkedChatId) || isRepliesChat) && (currentPosition == null || currentPosition.siblingHeights == null && (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0 || currentPosition.siblingHeights != null && (currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0))) {
dataChanged = true;
}
if (!messageChanged && messageObject.isDice()) {
setCurrentDiceValue(isUpdating);
}
if (!messageChanged && messageObject.isPoll()) {
ArrayList<TLRPC.TL_pollAnswerVoters> newResults = null;
TLRPC.Poll newPoll = null;
int newVoters = 0;
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaPoll) {
TLRPC.TL_messageMediaPoll mediaPoll = (TLRPC.TL_messageMediaPoll) messageObject.messageOwner.media;
newResults = mediaPoll.results.results;
newPoll = mediaPoll.poll;
newVoters = mediaPoll.results.total_voters;
}
if (newResults != null && lastPollResults != null && newVoters != lastPollResultsVoters) {
pollChanged = true;
}
if (!pollChanged && newResults != lastPollResults) {
pollChanged = true;
}
if (lastPoll != newPoll && lastPoll.closed != newPoll.closed) {
pollChanged = true;
if (!pollVoted) {
pollVoteInProgress = true;
vibrateOnPollVote = false;
}
}
animatePollAvatars = false;
if (pollChanged && attachedToWindow) {
pollAnimationProgressTime = 0.0f;
if (pollVoted && !messageObject.isVoted()) {
pollUnvoteInProgress = true;
}
animatePollAvatars = lastPollResultsVoters == 0 || lastPollResultsVoters != 0 && newVoters == 0;
}
}
if (!groupChanged && groupedMessages != null) {
MessageObject.GroupedMessagePosition newPosition;
if (groupedMessages.messages.size() > 1) {
newPosition = currentMessagesGroup.positions.get(currentMessageObject);
} else {
newPosition = null;
}
groupChanged = newPosition != currentPosition;
}
if (messageChanged || dataChanged || groupChanged || pollChanged || widthChanged && messageObject.isPoll() || isPhotoDataChanged(messageObject) || pinnedBottom != bottomNear || pinnedTop != topNear) {
wasPinned = isPinned;
pinnedBottom = bottomNear;
pinnedTop = topNear;
currentMessageObject = messageObject;
currentMessagesGroup = groupedMessages;
lastTime = -2;
lastPostAuthor = messageObject.messageOwner.post_author;
isHighlightedAnimated = false;
widthBeforeNewTimeLine = -1;
if (currentMessagesGroup != null && (currentMessagesGroup.posArray.size() > 1)) {
currentPosition = currentMessagesGroup.positions.get(currentMessageObject);
if (currentPosition == null) {
currentMessagesGroup = null;
}
} else {
currentMessagesGroup = null;
currentPosition = null;
}
if (currentMessagesGroup == null || currentMessagesGroup.isDocuments) {
drawPinnedTop = pinnedTop;
drawPinnedBottom = pinnedBottom;
} else {
drawPinnedTop = pinnedTop && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_TOP) != 0);
drawPinnedBottom = pinnedBottom && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0);
}
isPlayingRound = isRoundVideo && MediaController.getInstance().isPlayingMessage(currentMessageObject) && delegate != null && !delegate.keyboardIsOpened() && !delegate.isLandscape();
photoImage.setCrossfadeWithOldImage(false);
photoImage.setCrossfadeDuration(ImageReceiver.DEFAULT_CROSSFADE_DURATION);
photoImage.setGradientBitmap(null);
lastSendState = messageObject.messageOwner.send_state;
lastDeleteDate = messageObject.messageOwner.destroyTime;
lastViewsCount = messageObject.messageOwner.views;
lastRepliesCount = getRepliesCount();
isPressed = false;
gamePreviewPressed = false;
sideButtonPressed = false;
isCheckPressed = true;
hasNewLineForTime = false;
isThreadPost = isThreadChat && messageObject.messageOwner.fwd_from != null && messageObject.messageOwner.fwd_from.channel_post != 0;
isAvatarVisible = !isThreadPost && isChat && !messageObject.isOutOwner() && messageObject.needDrawAvatar() && (currentPosition == null || currentPosition.edge);
boolean drawAvatar = isChat && !isThreadPost && !messageObject.isOutOwner() && messageObject.needDrawAvatar();
if (messageObject.customAvatarDrawable != null) {
isAvatarVisible = true;
drawAvatar = true;
}
wasLayout = false;
groupPhotoInvisible = false;
animatingDrawVideoImageButton = 0;
drawVideoSize = false;
canStreamVideo = false;
animatingNoSound = 0;
if (MessagesController.getInstance(currentAccount).isChatNoForwards(messageObject.getChatId()) || (messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) {
drawSideButton = 0;
} else {
drawSideButton = !isRepliesChat && checkNeedDrawShareButton(messageObject) && (currentPosition == null || currentPosition.last) ? 1 : 0;
if (isPinnedChat || drawSideButton == 1 && messageObject.messageOwner.fwd_from != null && !messageObject.isOutOwner() && messageObject.messageOwner.fwd_from.saved_from_peer != null && messageObject.getDialogId() == UserConfig.getInstance(currentAccount).getClientUserId()) {
drawSideButton = 2;
}
}
replyNameLayout = null;
adminLayout = null;
checkOnlyButtonPressed = false;
replyTextLayout = null;
lastReplyMessage = null;
hasEmbed = false;
autoPlayingMedia = false;
replyNameWidth = 0;
replyTextWidth = 0;
viaWidth = 0;
viaNameWidth = 0;
addedCaptionHeight = 0;
currentReplyPhoto = null;
currentUser = null;
currentChat = null;
currentViaBotUser = null;
instantViewLayout = null;
drawNameLayout = false;
lastLoadingSizeTotal = 0;
if (scheduledInvalidate) {
AndroidUtilities.cancelRunOnUIThread(invalidateRunnable);
scheduledInvalidate = false;
}
resetPressedLink(-1);
messageObject.forceUpdate = false;
drawPhotoImage = false;
drawMediaCheckBox = false;
hasLinkPreview = false;
hasOldCaptionPreview = false;
hasGamePreview = false;
hasInvoicePreview = false;
instantPressed = instantButtonPressed = commentButtonPressed = false;
if (!pollChanged && Build.VERSION.SDK_INT >= 21) {
for (int a = 0; a < selectorDrawable.length; a++) {
if (selectorDrawable[a] != null) {
selectorDrawable[a].setVisible(false, false);
selectorDrawable[a].setState(StateSet.NOTHING);
}
}
}
spoilerPressed = null;
isCaptionSpoilerPressed = false;
isSpoilerRevealing = false;
linkPreviewPressed = false;
buttonPressed = 0;
additionalTimeOffsetY = 0;
miniButtonPressed = 0;
pressedBotButton = -1;
pressedVoteButton = -1;
pollHintPressed = false;
psaHintPressed = false;
linkPreviewHeight = 0;
mediaOffsetY = 0;
documentAttachType = DOCUMENT_ATTACH_TYPE_NONE;
documentAttach = null;
descriptionLayout = null;
titleLayout = null;
videoInfoLayout = null;
photosCountLayout = null;
siteNameLayout = null;
authorLayout = null;
captionLayout = null;
captionWidth = 0;
captionHeight = 0;
captionOffsetX = 0;
currentCaption = null;
docTitleLayout = null;
drawImageButton = false;
drawVideoImageButton = false;
currentPhotoObject = null;
photoParentObject = null;
currentPhotoObjectThumb = null;
currentPhotoObjectThumbStripped = null;
if (messageChanged || messageIdChanged || dataChanged) {
currentPhotoFilter = null;
}
buttonState = -1;
miniButtonState = -1;
hasMiniProgress = 0;
if (addedForTest && currentUrl != null && currentWebFile != null) {
ImageLoader.getInstance().removeTestWebFile(currentUrl);
}
addedForTest = false;
photoNotSet = false;
drawBackground = true;
drawName = false;
useSeekBarWaweform = false;
drawInstantView = false;
drawInstantViewType = 0;
drawForwardedName = false;
drawCommentButton = false;
photoImage.setSideClip(0);
photoImage.setAspectFit(false);
gradientShader = null;
motionBackgroundDrawable = null;
imageBackgroundColor = 0;
imageBackgroundGradientColor1 = 0;
imageBackgroundGradientColor2 = 0;
imageBackgroundIntensity = 0;
imageBackgroundGradientColor3 = 0;
imageBackgroundGradientRotation = 45;
imageBackgroundSideColor = 0;
mediaBackground = false;
isMedia = false;
hasPsaHint = messageObject.messageOwner.fwd_from != null && !TextUtils.isEmpty(messageObject.messageOwner.fwd_from.psa_type);
if (hasPsaHint) {
createSelectorDrawable(0);
}
photoImage.setAlpha(1.0f);
if ((messageChanged || dataChanged) && !pollUnvoteInProgress) {
pollButtons.clear();
}
int captionNewLine = 0;
availableTimeWidth = 0;
photoImage.setForceLoading(false);
photoImage.setNeedsQualityThumb(false);
photoImage.setShouldGenerateQualityThumb(false);
photoImage.setAllowDecodeSingleFrame(false);
photoImage.setColorFilter(null);
photoImage.setMediaStartEndTime(-1, -1);
boolean canChangeRadius = true;
if (messageIdChanged || messageObject.reactionsChanged) {
messageObject.reactionsChanged = false;
if (currentPosition == null || ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0)) {
if (currentPosition != null) {
reactionsLayoutInBubble.setMessage(groupedMessages.findPrimaryMessageObject(), !messageObject.shouldDrawReactionsInLayout(), resourcesProvider);
} else {
reactionsLayoutInBubble.setMessage(messageObject, !messageObject.shouldDrawReactionsInLayout(), resourcesProvider);
}
} else {
reactionsLayoutInBubble.setMessage(null, false, resourcesProvider);
}
}
if (messageChanged) {
firstVisibleBlockNum = 0;
lastVisibleBlockNum = 0;
if (currentMessageObject != null && currentMessageObject.textLayoutBlocks != null && currentMessageObject.textLayoutBlocks.size() > 1) {
needNewVisiblePart = true;
}
}
boolean linked = false;
if (currentMessagesGroup != null && currentMessagesGroup.messages.size() > 0) {
MessageObject object = currentMessagesGroup.messages.get(0);
if (object.isLinkedToChat(linkedChatId)) {
linked = true;
}
} else {
linked = messageObject.isLinkedToChat(linkedChatId);
}
if ((hasDiscussion && linked || isRepliesChat && !messageObject.isOutOwner()) && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0)) {
int commentCount = getRepliesCount();
if (!messageObject.shouldDrawWithoutBackground() && !messageObject.isAnimatedEmoji()) {
drawCommentButton = true;
int avatarsOffset = 0;
String comment;
if (commentProgress == null) {
commentProgress = new InfiniteProgress(AndroidUtilities.dp(7));
}
if (isRepliesChat) {
comment = LocaleController.getString("ViewInChat", R.string.ViewInChat);
} else {
if (LocaleController.isRTL) {
comment = commentCount == 0 ? LocaleController.getString("LeaveAComment", R.string.LeaveAComment) : LocaleController.formatPluralString("CommentsCount", commentCount);
} else {
comment = commentCount == 0 ? LocaleController.getString("LeaveAComment", R.string.LeaveAComment) : LocaleController.getPluralString("CommentsNoNumber", commentCount);
}
ArrayList<TLRPC.Peer> recentRepliers = getRecentRepliers();
if (commentCount != 0 && recentRepliers != null && !recentRepliers.isEmpty()) {
createCommentUI();
int size = recentRepliers.size();
for (int a = 0; a < commentAvatarImages.length; a++) {
if (a < size) {
commentAvatarImages[a].setImageCoords(0, 0, AndroidUtilities.dp(24), AndroidUtilities.dp(24));
long id = MessageObject.getPeerId(recentRepliers.get(a));
TLRPC.User user = null;
TLRPC.Chat chat = null;
if (DialogObject.isUserDialog(id)) {
user = MessagesController.getInstance(currentAccount).getUser(id);
} else if (DialogObject.isChatDialog(id)) {
chat = MessagesController.getInstance(currentAccount).getChat(-id);
}
if (user != null) {
commentAvatarDrawables[a].setInfo(user);
commentAvatarImages[a].setForUserOrChat(user, commentAvatarDrawables[a]);
} else if (chat != null) {
commentAvatarDrawables[a].setInfo(chat);
commentAvatarImages[a].setForUserOrChat(chat, commentAvatarDrawables[a]);
} else {
commentAvatarDrawables[a].setInfo(id, "", "");
}
commentAvatarImagesVisible[a] = true;
avatarsOffset += a == 0 ? 2 : 17;
} else if (size != 0) {
commentAvatarImages[a].setImageBitmap((Drawable) null);
commentAvatarImagesVisible[a] = false;
}
}
} else if (commentAvatarImages != null) {
for (int a = 0; a < commentAvatarImages.length; a++) {
commentAvatarImages[a].setImageBitmap((Drawable) null);
commentAvatarImagesVisible[a] = false;
}
}
}
commentWidth = totalCommentWidth = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(comment));
commentLayout = new StaticLayout(comment, Theme.chat_replyNamePaint, commentWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (commentCount != 0 && !LocaleController.isRTL) {
drawCommentNumber = true;
if (commentNumberLayout == null) {
commentNumberLayout = new AnimatedNumberLayout(this, Theme.chat_replyNamePaint);
commentNumberLayout.setNumber(commentCount, false);
} else {
commentNumberLayout.setNumber(commentCount, messageObject.animateComments);
}
messageObject.animateComments = false;
commentNumberWidth = commentNumberLayout.getWidth();
totalCommentWidth += commentNumberWidth + AndroidUtilities.dp(4);
} else {
drawCommentNumber = false;
if (commentNumberLayout != null) {
commentNumberLayout.setNumber(1, false);
}
}
totalCommentWidth += AndroidUtilities.dp(70 + avatarsOffset);
} else {
if (!isRepliesChat && commentCount > 0) {
String comment = LocaleController.formatShortNumber(commentCount, null);
commentWidth = totalCommentWidth = (int) Math.ceil(Theme.chat_stickerCommentCountPaint.measureText(comment));
commentLayout = new StaticLayout(comment, Theme.chat_stickerCommentCountPaint, commentWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else {
commentLayout = null;
}
drawCommentNumber = false;
drawSideButton = isRepliesChat ? 2 : 3;
}
} else {
commentLayout = null;
drawCommentNumber = false;
}
if (messageObject.type == 0) {
drawForwardedName = !isRepliesChat;
int maxWidth;
if (drawAvatar) {
if (AndroidUtilities.isTablet()) {
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(122);
} else {
maxWidth = Math.min(getParentWidth(), AndroidUtilities.displaySize.y) - AndroidUtilities.dp(122);
}
drawName = true;
} else {
if (AndroidUtilities.isTablet()) {
maxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
} else {
maxWidth = Math.min(getParentWidth(), AndroidUtilities.displaySize.y) - AndroidUtilities.dp(80);
}
drawName = isPinnedChat || messageObject.messageOwner.peer_id.channel_id != 0 && (!messageObject.isOutOwner() || messageObject.isSupergroup()) || messageObject.isImportedForward() && messageObject.messageOwner.fwd_from.from_id == null;
}
availableTimeWidth = maxWidth;
if (messageObject.isRoundVideo()) {
availableTimeWidth -= Math.ceil(Theme.chat_audioTimePaint.measureText("00:00")) + (messageObject.isOutOwner() ? 0 : AndroidUtilities.dp(64));
}
measureTime(messageObject);
int timeMore = timeWidth + AndroidUtilities.dp(6);
if (messageObject.isOutOwner()) {
timeMore += AndroidUtilities.dp(20.5f);
}
timeMore += getExtraTimeX();
hasGamePreview = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGame && messageObject.messageOwner.media.game instanceof TLRPC.TL_game;
hasInvoicePreview = messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaInvoice;
hasLinkPreview = !messageObject.isRestrictedMessage && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage instanceof TLRPC.TL_webPage;
drawInstantView = hasLinkPreview && messageObject.messageOwner.media.webpage.cached_page != null;
String siteName = hasLinkPreview ? messageObject.messageOwner.media.webpage.site_name : null;
hasEmbed = hasLinkPreview && !TextUtils.isEmpty(messageObject.messageOwner.media.webpage.embed_url) && !messageObject.isGif() && !"instangram".equalsIgnoreCase(siteName);
boolean slideshow = false;
String webpageType = hasLinkPreview ? messageObject.messageOwner.media.webpage.type : null;
TLRPC.Document androidThemeDocument = null;
TLRPC.ThemeSettings androidThemeSettings = null;
if (!drawInstantView) {
if ("telegram_livestream".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 11;
} else if ("telegram_voicechat".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 9;
} else if ("telegram_channel".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 1;
} else if ("telegram_user".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 13;
} else if ("telegram_megagroup".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 2;
} else if ("telegram_message".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 3;
} else if ("telegram_theme".equals(webpageType)) {
for (int b = 0, N2 = messageObject.messageOwner.media.webpage.attributes.size(); b < N2; b++) {
TLRPC.TL_webPageAttributeTheme attribute = messageObject.messageOwner.media.webpage.attributes.get(b);
ArrayList<TLRPC.Document> documents = attribute.documents;
for (int a = 0, N = documents.size(); a < N; a++) {
TLRPC.Document document = documents.get(a);
if ("application/x-tgtheme-android".equals(document.mime_type)) {
drawInstantView = true;
drawInstantViewType = 7;
androidThemeDocument = document;
break;
}
}
if (drawInstantView) {
break;
}
if (attribute.settings != null) {
drawInstantView = true;
drawInstantViewType = 7;
androidThemeSettings = attribute.settings;
break;
}
}
} else if ("telegram_background".equals(webpageType)) {
drawInstantView = true;
drawInstantViewType = 6;
try {
Uri url = Uri.parse(messageObject.messageOwner.media.webpage.url);
imageBackgroundIntensity = Utilities.parseInt(url.getQueryParameter("intensity"));
String bgColor = url.getQueryParameter("bg_color");
String rotation = url.getQueryParameter("rotation");
if (rotation != null) {
imageBackgroundGradientRotation = Utilities.parseInt(rotation);
}
if (TextUtils.isEmpty(bgColor)) {
TLRPC.Document document = messageObject.getDocument();
if (document != null && "image/png".equals(document.mime_type)) {
bgColor = "ffffff";
}
if (imageBackgroundIntensity == 0) {
imageBackgroundIntensity = 50;
}
}
if (bgColor != null) {
imageBackgroundColor = Integer.parseInt(bgColor.substring(0, 6), 16) | 0xff000000;
int averageColor = imageBackgroundColor;
if (bgColor.length() >= 13 && AndroidUtilities.isValidWallChar(bgColor.charAt(6))) {
imageBackgroundGradientColor1 = Integer.parseInt(bgColor.substring(7, 13), 16) | 0xff000000;
averageColor = AndroidUtilities.getAverageColor(imageBackgroundColor, imageBackgroundGradientColor1);
}
if (bgColor.length() >= 20 && AndroidUtilities.isValidWallChar(bgColor.charAt(13))) {
imageBackgroundGradientColor2 = Integer.parseInt(bgColor.substring(14, 20), 16) | 0xff000000;
}
if (bgColor.length() == 27 && AndroidUtilities.isValidWallChar(bgColor.charAt(20))) {
imageBackgroundGradientColor3 = Integer.parseInt(bgColor.substring(21), 16) | 0xff000000;
}
if (imageBackgroundIntensity < 0) {
imageBackgroundSideColor = 0xff111111;
} else {
imageBackgroundSideColor = AndroidUtilities.getPatternSideColor(averageColor);
}
photoImage.setColorFilter(new PorterDuffColorFilter(AndroidUtilities.getPatternColor(averageColor), PorterDuff.Mode.SRC_IN));
photoImage.setAlpha(Math.abs(imageBackgroundIntensity) / 100.0f);
} else {
String color = url.getLastPathSegment();
if (color != null && color.length() >= 6) {
imageBackgroundColor = Integer.parseInt(color.substring(0, 6), 16) | 0xff000000;
if (color.length() >= 13 && AndroidUtilities.isValidWallChar(color.charAt(6))) {
imageBackgroundGradientColor1 = Integer.parseInt(color.substring(7, 13), 16) | 0xff000000;
}
if (color.length() >= 20 && AndroidUtilities.isValidWallChar(color.charAt(13))) {
imageBackgroundGradientColor2 = Integer.parseInt(color.substring(14, 20), 16) | 0xff000000;
}
if (color.length() == 27 && AndroidUtilities.isValidWallChar(color.charAt(20))) {
imageBackgroundGradientColor3 = Integer.parseInt(color.substring(21), 16) | 0xff000000;
}
currentPhotoObject = new TLRPC.TL_photoSizeEmpty();
currentPhotoObject.type = "s";
currentPhotoObject.w = AndroidUtilities.dp(180);
currentPhotoObject.h = AndroidUtilities.dp(150);
currentPhotoObject.location = new TLRPC.TL_fileLocationUnavailable();
}
}
} catch (Exception ignore) {
}
}
} else if (siteName != null) {
siteName = siteName.toLowerCase();
if ((siteName.equals("instagram") || siteName.equals("twitter") || "telegram_album".equals(webpageType)) && messageObject.messageOwner.media.webpage.cached_page instanceof TLRPC.TL_page && (messageObject.messageOwner.media.webpage.photo instanceof TLRPC.TL_photo || MessageObject.isVideoDocument(messageObject.messageOwner.media.webpage.document))) {
drawInstantView = false;
slideshow = true;
ArrayList<TLRPC.PageBlock> blocks = messageObject.messageOwner.media.webpage.cached_page.blocks;
int count = 1;
for (int a = 0; a < blocks.size(); a++) {
TLRPC.PageBlock block = blocks.get(a);
if (block instanceof TLRPC.TL_pageBlockSlideshow) {
TLRPC.TL_pageBlockSlideshow b = (TLRPC.TL_pageBlockSlideshow) block;
count = b.items.size();
} else if (block instanceof TLRPC.TL_pageBlockCollage) {
TLRPC.TL_pageBlockCollage b = (TLRPC.TL_pageBlockCollage) block;
count = b.items.size();
}
}
String str = LocaleController.formatString("Of", R.string.Of, 1, count);
photosCountWidth = (int) Math.ceil(Theme.chat_durationPaint.measureText(str));
photosCountLayout = new StaticLayout(str, Theme.chat_durationPaint, photosCountWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
}
backgroundWidth = maxWidth;
if (hasLinkPreview || hasGamePreview || hasInvoicePreview || maxWidth - messageObject.lastLineWidth < timeMore) {
backgroundWidth = Math.max(backgroundWidth, messageObject.lastLineWidth) + AndroidUtilities.dp(31);
backgroundWidth = Math.max(backgroundWidth, timeWidth + AndroidUtilities.dp(31));
} else {
int diff = backgroundWidth - messageObject.lastLineWidth;
if (diff >= 0 && diff <= timeMore) {
backgroundWidth = backgroundWidth + timeMore - diff + AndroidUtilities.dp(31);
} else {
backgroundWidth = Math.max(backgroundWidth, messageObject.lastLineWidth + timeMore) + AndroidUtilities.dp(31);
}
}
availableTimeWidth = backgroundWidth - AndroidUtilities.dp(31);
if (messageObject.isRoundVideo()) {
availableTimeWidth -= Math.ceil(Theme.chat_audioTimePaint.measureText("00:00")) + (messageObject.isOutOwner() ? 0 : AndroidUtilities.dp(64));
}
setMessageObjectInternal(messageObject);
backgroundWidth = messageObject.textWidth + getExtraTextX() * 2 + (hasGamePreview || hasInvoicePreview ? AndroidUtilities.dp(10) : 0);
totalHeight = messageObject.textHeight + AndroidUtilities.dp(19.5f) + namesOffset;
if (!reactionsLayoutInBubble.isSmall) {
reactionsLayoutInBubble.measure(maxWidth);
if (!reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(8);
if (reactionsLayoutInBubble.width > backgroundWidth) {
backgroundWidth = reactionsLayoutInBubble.width;
}
totalHeight += reactionsLayoutInBubble.totalHeight;
}
}
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
int maxChildWidth = Math.max(backgroundWidth, nameWidth);
maxChildWidth = Math.max(maxChildWidth, forwardedNameWidth);
maxChildWidth = Math.max(maxChildWidth, replyNameWidth);
maxChildWidth = Math.max(maxChildWidth, replyTextWidth);
if (commentLayout != null && drawSideButton != 3) {
maxChildWidth = Math.max(maxChildWidth, totalCommentWidth);
}
int maxWebWidth = 0;
if (hasLinkPreview || hasGamePreview || hasInvoicePreview) {
int linkPreviewMaxWidth;
if (AndroidUtilities.isTablet()) {
if (drawAvatar) {
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(132);
} else {
linkPreviewMaxWidth = AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(80);
}
} else {
if (drawAvatar) {
linkPreviewMaxWidth = getParentWidth() - AndroidUtilities.dp(132);
} else {
linkPreviewMaxWidth = getParentWidth() - AndroidUtilities.dp(80);
}
}
if (drawSideButton != 0) {
linkPreviewMaxWidth -= AndroidUtilities.dp(20);
}
String site_name;
String title;
String author;
String description;
TLRPC.Photo photo;
TLRPC.Document document;
WebFile webDocument;
int duration;
boolean smallImage;
String type;
final int smallImageSide = AndroidUtilities.dp(48), smallSideMargin = AndroidUtilities.dp(10);
if (hasLinkPreview) {
TLRPC.TL_webPage webPage = (TLRPC.TL_webPage) messageObject.messageOwner.media.webpage;
site_name = webPage.site_name;
title = drawInstantViewType != 6 && drawInstantViewType != 7 ? webPage.title : null;
author = drawInstantViewType != 6 && drawInstantViewType != 7 ? webPage.author : null;
description = drawInstantViewType != 6 && drawInstantViewType != 7 ? webPage.description : null;
photo = webPage.photo;
webDocument = null;
if (drawInstantViewType == 7) {
if (androidThemeSettings != null) {
document = new DocumentObject.ThemeDocument(androidThemeSettings);
} else {
document = androidThemeDocument;
}
} else {
document = webPage.document;
}
type = webPage.type;
duration = webPage.duration;
if (site_name != null && photo != null && site_name.toLowerCase().equals("instagram")) {
linkPreviewMaxWidth = Math.max(AndroidUtilities.displaySize.y / 3, currentMessageObject.textWidth);
}
boolean isSmallImageType = "app".equals(type) || "profile".equals(type) || "article".equals(type) || "telegram_bot".equals(type) || "telegram_user".equals(type) || "telegram_channel".equals(type) || "telegram_megagroup".equals(type) || "telegram_voicechat".equals(type) || "telegram_livestream".equals(type);
smallImage = !slideshow && (!drawInstantView || drawInstantViewType == 1 || drawInstantViewType == 9 || drawInstantViewType == 11 || drawInstantViewType == 13) && document == null && isSmallImageType;
isSmallImage = smallImage && type != null && currentMessageObject.photoThumbs != null;
} else if (hasInvoicePreview) {
TLRPC.TL_messageMediaInvoice invoice = (TLRPC.TL_messageMediaInvoice) messageObject.messageOwner.media;
site_name = messageObject.messageOwner.media.title;
title = null;
description = null;
photo = null;
author = null;
document = null;
if (invoice.photo instanceof TLRPC.TL_webDocument) {
webDocument = WebFile.createWithWebDocument(invoice.photo);
} else {
webDocument = null;
}
duration = 0;
type = "invoice";
isSmallImage = false;
smallImage = false;
} else {
TLRPC.TL_game game = messageObject.messageOwner.media.game;
site_name = game.title;
title = null;
webDocument = null;
description = TextUtils.isEmpty(messageObject.messageText) ? game.description : null;
photo = game.photo;
author = null;
document = game.document;
duration = 0;
type = "game";
isSmallImage = false;
smallImage = false;
}
if (drawInstantViewType == 11) {
site_name = LocaleController.getString("VoipChannelVoiceChat", R.string.VoipChannelVoiceChat);
} else if (drawInstantViewType == 9) {
site_name = LocaleController.getString("VoipGroupVoiceChat", R.string.VoipGroupVoiceChat);
} else if (drawInstantViewType == 6) {
site_name = LocaleController.getString("ChatBackground", R.string.ChatBackground);
} else if ("telegram_theme".equals(webpageType)) {
site_name = LocaleController.getString("ColorTheme", R.string.ColorTheme);
}
int additinalWidth = hasInvoicePreview ? 0 : AndroidUtilities.dp(10);
int restLinesCount = 3;
linkPreviewMaxWidth -= additinalWidth;
if (currentMessageObject.photoThumbs == null && photo != null) {
currentMessageObject.generateThumbs(true);
}
if (site_name != null) {
try {
int width = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(site_name) + 1);
int restLines = 0;
if (!isSmallImage) {
siteNameLayout = new StaticLayout(site_name, Theme.chat_replyNamePaint, Math.min(width, linkPreviewMaxWidth), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else {
restLines = restLinesCount;
siteNameLayout = generateStaticLayout(site_name, Theme.chat_replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - smallImageSide - smallSideMargin, restLinesCount, 1);
restLinesCount -= siteNameLayout.getLineCount();
}
siteNameRtl = Math.max(siteNameLayout.getLineLeft(0), 0) != 0;
int height = siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
int layoutWidth = 0;
for (int a = 0; a < siteNameLayout.getLineCount(); ++a) {
int lineLeft = (int) Math.max(0, siteNameLayout.getLineLeft(a));
int lineWidth;
if (lineLeft != 0) {
lineWidth = siteNameLayout.getWidth() - lineLeft;
} else {
int max = linkPreviewMaxWidth;
if (a < restLines || lineLeft != 0 && isSmallImage) {
max -= smallImageSide + smallSideMargin;
}
lineWidth = (int) Math.min(max, Math.ceil(siteNameLayout.getLineWidth(a)));
}
if (a < restLines || lineLeft != 0 && isSmallImage) {
lineWidth += smallImageSide + smallSideMargin;
}
layoutWidth = Math.max(layoutWidth, lineWidth);
}
siteNameWidth = width = layoutWidth;
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
} catch (Exception e) {
FileLog.e(e);
}
}
boolean titleIsRTL = false;
if (title != null) {
try {
titleX = Integer.MAX_VALUE;
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
int restLines = 0;
if (!isSmallImage) {
titleLayout = StaticLayoutEx.createStaticLayout(title, Theme.chat_replyNamePaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 4);
} else {
restLines = restLinesCount;
titleLayout = generateStaticLayout(title, Theme.chat_replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - smallImageSide - smallSideMargin, restLinesCount, 4);
restLinesCount -= titleLayout.getLineCount();
}
int height = titleLayout.getLineBottom(titleLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
for (int a = 0; a < titleLayout.getLineCount(); a++) {
int lineLeft = (int) Math.max(0, titleLayout.getLineLeft(a));
if (lineLeft != 0) {
titleIsRTL = true;
}
if (titleX == Integer.MAX_VALUE) {
titleX = -lineLeft;
} else {
titleX = Math.max(titleX, -lineLeft);
}
int width;
if (lineLeft != 0) {
width = titleLayout.getWidth() - lineLeft;
} else {
int max = linkPreviewMaxWidth;
if (a < restLines || lineLeft != 0 && isSmallImage) {
max -= smallImageSide + smallSideMargin;
}
width = (int) Math.min(max, Math.ceil(titleLayout.getLineWidth(a)));
}
if (a < restLines || lineLeft != 0 && isSmallImage) {
width += smallImageSide + smallSideMargin;
}
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
}
} catch (Exception e) {
FileLog.e(e);
}
if (titleIsRTL && isSmallImage) {
linkPreviewMaxWidth -= AndroidUtilities.dp(48);
}
}
boolean authorIsRTL = false;
if (author != null && title == null) {
try {
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
if (restLinesCount == 3 && (!isSmallImage || description == null)) {
authorLayout = new StaticLayout(author, Theme.chat_replyNamePaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else {
authorLayout = generateStaticLayout(author, Theme.chat_replyNamePaint, linkPreviewMaxWidth, linkPreviewMaxWidth - smallImageSide - smallSideMargin, restLinesCount, 1);
restLinesCount -= authorLayout.getLineCount();
}
int height = authorLayout.getLineBottom(authorLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
int lineLeft = (int) Math.max(authorLayout.getLineLeft(0), 0);
authorX = -lineLeft;
int width;
if (lineLeft != 0) {
width = authorLayout.getWidth() - lineLeft;
authorIsRTL = true;
} else {
width = (int) Math.ceil(authorLayout.getLineWidth(0));
}
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
maxWebWidth = Math.max(maxWebWidth, width + additinalWidth);
} catch (Exception e) {
FileLog.e(e);
}
}
if (description != null) {
try {
descriptionX = 0;
currentMessageObject.generateLinkDescription();
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
int restLines = 0;
boolean allowAllLines = site_name != null && site_name.toLowerCase().equals("twitter");
if (restLinesCount == 3 && !isSmallImage) {
descriptionLayout = StaticLayoutEx.createStaticLayout(messageObject.linkDescription, Theme.chat_replyTextPaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, allowAllLines ? 100 : 6);
} else {
restLines = restLinesCount;
descriptionLayout = generateStaticLayout(messageObject.linkDescription, Theme.chat_replyTextPaint, linkPreviewMaxWidth, linkPreviewMaxWidth - smallImageSide - smallSideMargin, restLinesCount, allowAllLines ? 100 : 6);
}
int height = descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
boolean hasRTL = false;
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
int lineLeft = (int) Math.ceil(descriptionLayout.getLineLeft(a));
if (lineLeft > 0) {
hasRTL = true;
if (descriptionX == 0) {
descriptionX = -lineLeft;
} else {
descriptionX = Math.max(descriptionX, -lineLeft);
}
}
}
int textWidth = descriptionLayout.getWidth();
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
int lineLeft = (int) Math.ceil(descriptionLayout.getLineLeft(a));
if (lineLeft == 0 && descriptionX != 0) {
descriptionX = 0;
}
int width;
if (lineLeft > 0) {
width = textWidth - lineLeft;
} else {
if (hasRTL) {
width = textWidth;
} else {
width = Math.min((int) Math.ceil(descriptionLayout.getLineWidth(a)), textWidth);
}
}
if (a < restLines || restLines != 0 && lineLeft != 0 && isSmallImage) {
width += smallImageSide + smallSideMargin;
}
if (maxWebWidth < width + additinalWidth) {
if (titleIsRTL) {
titleX += (width + additinalWidth - maxWebWidth);
}
if (authorIsRTL) {
authorX += (width + additinalWidth - maxWebWidth);
}
maxWebWidth = width + additinalWidth;
}
maxChildWidth = Math.max(maxChildWidth, width + additinalWidth);
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (smallImage && (descriptionLayout == null && titleLayout == null)) {
smallImage = false;
isSmallImage = false;
}
int maxPhotoWidth = smallImage ? smallImageSide : linkPreviewMaxWidth;
if (document != null) {
if (MessageObject.isRoundVideoDocument(document)) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
photoParentObject = document;
documentAttach = document;
documentAttachType = DOCUMENT_ATTACH_TYPE_ROUND;
} else if (MessageObject.isGifDocument(document, messageObject.hasValidGroupId())) {
if (!messageObject.isGame() && !SharedConfig.autoplayGifs) {
messageObject.gifState = 1;
}
photoImage.setAllowStartAnimation(messageObject.gifState != 1);
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
if (currentPhotoObject != null) {
photoParentObject = document;
} else if (photo != null) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 90);
photoParentObject = photo;
}
if (currentPhotoObject != null && (currentPhotoObject.w == 0 || currentPhotoObject.h == 0)) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
currentPhotoObject.w = attribute.w;
currentPhotoObject.h = attribute.h;
break;
}
}
if (currentPhotoObject.w == 0 || currentPhotoObject.h == 0) {
currentPhotoObject.w = currentPhotoObject.h = AndroidUtilities.dp(150);
}
}
documentAttach = document;
documentAttachType = DOCUMENT_ATTACH_TYPE_GIF;
} else if (MessageObject.isVideoDocument(document)) {
if (photo != null) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, AndroidUtilities.getPhotoSize(), true);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(photo.sizes, 40);
photoParentObject = photo;
}
if (currentPhotoObject == null) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
photoParentObject = document;
}
if (currentPhotoObject == currentPhotoObjectThumb) {
currentPhotoObjectThumb = null;
}
if (currentMessageObject.strippedThumb != null) {
currentPhotoObjectThumb = null;
currentPhotoObjectThumbStripped = currentMessageObject.strippedThumb;
}
if (currentPhotoObject == null) {
currentPhotoObject = new TLRPC.TL_photoSize();
currentPhotoObject.type = "s";
currentPhotoObject.location = new TLRPC.TL_fileLocationUnavailable();
}
if (currentPhotoObject != null && (currentPhotoObject.w == 0 || currentPhotoObject.h == 0 || currentPhotoObject instanceof TLRPC.TL_photoStrippedSize)) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
if (currentPhotoObject instanceof TLRPC.TL_photoStrippedSize) {
float scale = Math.max(attribute.w, attribute.w) / 50.0f;
currentPhotoObject.w = (int) (attribute.w / scale);
currentPhotoObject.h = (int) (attribute.h / scale);
} else {
currentPhotoObject.w = attribute.w;
currentPhotoObject.h = attribute.h;
}
break;
}
}
if (currentPhotoObject.w == 0 || currentPhotoObject.h == 0) {
currentPhotoObject.w = currentPhotoObject.h = AndroidUtilities.dp(150);
}
}
createDocumentLayout(0, messageObject);
} else if (MessageObject.isStickerDocument(document) || MessageObject.isAnimatedStickerDocument(document, true)) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 90);
photoParentObject = document;
if (currentPhotoObject != null && (currentPhotoObject.w == 0 || currentPhotoObject.h == 0)) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
currentPhotoObject.w = attribute.w;
currentPhotoObject.h = attribute.h;
break;
}
}
if (currentPhotoObject.w == 0 || currentPhotoObject.h == 0) {
currentPhotoObject.w = currentPhotoObject.h = AndroidUtilities.dp(150);
}
}
documentAttach = document;
documentAttachType = DOCUMENT_ATTACH_TYPE_STICKER;
} else if (drawInstantViewType == 6) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 320);
photoParentObject = document;
if (currentPhotoObject != null && (currentPhotoObject.w == 0 || currentPhotoObject.h == 0)) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
currentPhotoObject.w = attribute.w;
currentPhotoObject.h = attribute.h;
break;
}
}
if (currentPhotoObject.w == 0 || currentPhotoObject.h == 0) {
currentPhotoObject.w = currentPhotoObject.h = AndroidUtilities.dp(150);
}
}
documentAttach = document;
documentAttachType = DOCUMENT_ATTACH_TYPE_WALLPAPER;
String str = AndroidUtilities.formatFileSize(documentAttach.size);
durationWidth = (int) Math.ceil(Theme.chat_durationPaint.measureText(str));
videoInfoLayout = new StaticLayout(str, Theme.chat_durationPaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else if (drawInstantViewType == 7) {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 700);
if (currentMessageObject.strippedThumb == null) {
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
} else {
currentPhotoObjectThumbStripped = currentMessageObject.strippedThumb;
}
photoParentObject = document;
if (currentPhotoObject != null && (currentPhotoObject.w == 0 || currentPhotoObject.h == 0)) {
for (int a = 0; a < document.attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = document.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
currentPhotoObject.w = attribute.w;
currentPhotoObject.h = attribute.h;
break;
}
}
if (currentPhotoObject.w == 0 || currentPhotoObject.h == 0) {
currentPhotoObject.w = currentPhotoObject.h = AndroidUtilities.dp(150);
}
}
documentAttach = document;
documentAttachType = DOCUMENT_ATTACH_TYPE_THEME;
} else {
calcBackgroundWidth(maxWidth, timeMore, maxChildWidth);
if (backgroundWidth < maxWidth + AndroidUtilities.dp(20)) {
backgroundWidth = maxWidth + AndroidUtilities.dp(20);
}
if (MessageObject.isVoiceDocument(document)) {
createDocumentLayout(backgroundWidth - AndroidUtilities.dp(10), messageObject);
mediaOffsetY = currentMessageObject.textHeight + AndroidUtilities.dp(8) + linkPreviewHeight;
totalHeight += AndroidUtilities.dp(30 + 14);
linkPreviewHeight += AndroidUtilities.dp(44);
maxWidth = maxWidth - AndroidUtilities.dp(86);
if (AndroidUtilities.isTablet()) {
maxChildWidth = Math.max(maxChildWidth, Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 52 : 0), AndroidUtilities.dp(220)) - AndroidUtilities.dp(30) + additinalWidth);
} else {
maxChildWidth = Math.max(maxChildWidth, Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 52 : 0), AndroidUtilities.dp(220)) - AndroidUtilities.dp(30) + additinalWidth);
}
calcBackgroundWidth(maxWidth, timeMore, maxChildWidth);
} else if (MessageObject.isMusicDocument(document)) {
int durationWidth = createDocumentLayout(backgroundWidth - AndroidUtilities.dp(10), messageObject);
mediaOffsetY = currentMessageObject.textHeight + AndroidUtilities.dp(8) + linkPreviewHeight;
totalHeight += AndroidUtilities.dp(42 + 14);
linkPreviewHeight += AndroidUtilities.dp(56);
maxWidth = maxWidth - AndroidUtilities.dp(86);
maxChildWidth = Math.max(maxChildWidth, durationWidth + additinalWidth + AndroidUtilities.dp(86 + 8));
if (songLayout != null && songLayout.getLineCount() > 0) {
maxChildWidth = (int) Math.max(maxChildWidth, songLayout.getLineWidth(0) + additinalWidth + AndroidUtilities.dp(86));
}
if (performerLayout != null && performerLayout.getLineCount() > 0) {
maxChildWidth = (int) Math.max(maxChildWidth, performerLayout.getLineWidth(0) + additinalWidth + AndroidUtilities.dp(86));
}
calcBackgroundWidth(maxWidth, timeMore, maxChildWidth);
} else {
createDocumentLayout(backgroundWidth - AndroidUtilities.dp(86 + 24 + 58), messageObject);
drawImageButton = true;
if (drawPhotoImage) {
totalHeight += AndroidUtilities.dp(86 + 14);
linkPreviewHeight += AndroidUtilities.dp(86);
photoImage.setImageCoords(0, totalHeight + namesOffset, AndroidUtilities.dp(86), AndroidUtilities.dp(86));
} else {
mediaOffsetY = currentMessageObject.textHeight + AndroidUtilities.dp(8) + linkPreviewHeight;
photoImage.setImageCoords(0, totalHeight + namesOffset - AndroidUtilities.dp(14), AndroidUtilities.dp(56), AndroidUtilities.dp(56));
totalHeight += AndroidUtilities.dp(50 + 14);
linkPreviewHeight += AndroidUtilities.dp(50);
if (docTitleLayout != null && docTitleLayout.getLineCount() > 1) {
int h = (docTitleLayout.getLineCount() - 1) * AndroidUtilities.dp(16);
totalHeight += h;
linkPreviewHeight += h;
}
}
}
}
} else if (photo != null) {
boolean isPhoto = type != null && type.equals("photo");
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, isPhoto || !smallImage ? AndroidUtilities.getPhotoSize() : maxPhotoWidth, !isPhoto);
photoParentObject = messageObject.photoThumbsObject;
checkOnlyButtonPressed = !isPhoto;
if (currentMessageObject.strippedThumb == null) {
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
} else {
currentPhotoObjectThumbStripped = currentMessageObject.strippedThumb;
}
if (currentPhotoObjectThumb == currentPhotoObject) {
currentPhotoObjectThumb = null;
}
} else if (webDocument != null) {
if (!webDocument.mime_type.startsWith("image/")) {
webDocument = null;
}
drawImageButton = false;
}
if (documentAttachType != DOCUMENT_ATTACH_TYPE_MUSIC && documentAttachType != DOCUMENT_ATTACH_TYPE_AUDIO && documentAttachType != DOCUMENT_ATTACH_TYPE_DOCUMENT) {
if (currentPhotoObject != null || webDocument != null || documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER || documentAttachType == DOCUMENT_ATTACH_TYPE_THEME) {
drawImageButton = photo != null && !smallImage || type != null && (type.equals("photo") || type.equals("document") && documentAttachType != DOCUMENT_ATTACH_TYPE_STICKER || type.equals("gif") || documentAttachType == DOCUMENT_ATTACH_TYPE_VIDEO || documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER);
if (linkPreviewHeight != 0) {
linkPreviewHeight += AndroidUtilities.dp(2);
totalHeight += AndroidUtilities.dp(2);
}
if (imageBackgroundSideColor != 0) {
maxPhotoWidth = AndroidUtilities.dp(208);
} else if (currentPhotoObject instanceof TLRPC.TL_photoSizeEmpty && currentPhotoObject.w != 0) {
maxPhotoWidth = currentPhotoObject.w;
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_STICKER || documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER || documentAttachType == DOCUMENT_ATTACH_TYPE_THEME) {
if (AndroidUtilities.isTablet()) {
maxPhotoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
} else {
maxPhotoWidth = (int) (getParentWidth() * 0.5f);
}
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_ROUND) {
maxPhotoWidth = AndroidUtilities.roundMessageSize;
photoImage.setAllowDecodeSingleFrame(true);
}
maxChildWidth = Math.max(maxChildWidth, maxPhotoWidth - (hasInvoicePreview ? AndroidUtilities.dp(12) : 0) + additinalWidth);
if (currentPhotoObject != null) {
currentPhotoObject.size = -1;
if (currentPhotoObjectThumb != null) {
currentPhotoObjectThumb.size = -1;
}
} else if (webDocument != null) {
webDocument.size = -1;
}
if (imageBackgroundSideColor != 0) {
imageBackgroundSideWidth = maxChildWidth - AndroidUtilities.dp(13);
}
int width;
int height;
if (smallImage || documentAttachType == DOCUMENT_ATTACH_TYPE_ROUND) {
width = height = maxPhotoWidth;
} else {
if (hasGamePreview || hasInvoicePreview) {
if (hasInvoicePreview) {
width = 640;
height = 360;
for (int a = 0, N = webDocument.attributes.size(); a < N; a++) {
TLRPC.DocumentAttribute attribute = webDocument.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
width = attribute.w;
height = attribute.h;
break;
}
}
} else {
width = 640;
height = 360;
}
float scale = width / (float) (maxPhotoWidth - AndroidUtilities.dp(2));
width /= scale;
height /= scale;
} else {
if (drawInstantViewType == 7) {
width = 560;
height = 678;
} else if (currentPhotoObject != null) {
width = currentPhotoObject.w;
height = currentPhotoObject.h;
} else {
width = 30;
height = 50;
}
float scale = width / (float) (maxPhotoWidth - AndroidUtilities.dp(2));
width /= scale;
height /= scale;
if (site_name == null || site_name != null && !site_name.toLowerCase().equals("instagram") && documentAttachType == 0) {
if (height > AndroidUtilities.displaySize.y / 3) {
height = AndroidUtilities.displaySize.y / 3;
}
} else {
if (height > AndroidUtilities.displaySize.y / 2) {
height = AndroidUtilities.displaySize.y / 2;
}
}
if (imageBackgroundSideColor != 0) {
scale = height / (float) AndroidUtilities.dp(160);
width /= scale;
height /= scale;
}
if (height < AndroidUtilities.dp(60)) {
height = AndroidUtilities.dp(60);
}
}
}
if (isSmallImage) {
if (AndroidUtilities.dp(50) > linkPreviewHeight) {
totalHeight += AndroidUtilities.dp(50) - linkPreviewHeight + AndroidUtilities.dp(8);
linkPreviewHeight = AndroidUtilities.dp(50);
}
linkPreviewHeight -= AndroidUtilities.dp(8);
} else {
totalHeight += height + AndroidUtilities.dp(12);
linkPreviewHeight += height;
}
if (documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER && imageBackgroundSideColor == 0) {
photoImage.setImageCoords(0, 0, Math.max(maxChildWidth - AndroidUtilities.dp(13), width), height);
} else {
photoImage.setImageCoords(0, 0, width, height);
}
int w = (int) (width / AndroidUtilities.density);
int h = (int) (height / AndroidUtilities.density);
currentPhotoFilter = String.format(Locale.US, "%d_%d", w, h);
currentPhotoFilterThumb = String.format(Locale.US, "%d_%d_b", w, h);
if (webDocument != null) {
/*TODO*/
photoImage.setImage(ImageLocation.getForWebFile(webDocument), currentPhotoFilter, null, null, webDocument.size, null, messageObject, 1);
} else {
if (documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER) {
if (messageObject.mediaExists) {
photoImage.setImage(ImageLocation.getForDocument(documentAttach), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObject, document), "b1", 0, "jpg", messageObject, 1);
} else {
photoImage.setImage(null, null, ImageLocation.getForDocument(currentPhotoObject, document), "b1", 0, "jpg", messageObject, 1);
}
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_THEME) {
if (document instanceof DocumentObject.ThemeDocument) {
photoImage.setImage(ImageLocation.getForDocument(document), currentPhotoFilter, null, "b1", 0, "jpg", messageObject, 1);
} else {
photoImage.setImage(ImageLocation.getForDocument(currentPhotoObject, document), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObjectThumb, document), "b1", currentPhotoObjectThumbStripped, 0, "jpg", messageObject, 1);
}
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_STICKER) {
boolean isWebpSticker = messageObject.isSticker();
if (SharedConfig.loopStickers || (isWebpSticker && !messageObject.isVideoSticker())) {
photoImage.setAutoRepeat(1);
} else {
currentPhotoFilter = String.format(Locale.US, "%d_%d_nr_%s", w, h, messageObject.toString());
photoImage.setAutoRepeat(delegate != null && delegate.shouldRepeatSticker(messageObject) ? 2 : 3);
}
photoImage.setImage(ImageLocation.getForDocument(documentAttach), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObject, documentAttach), "b1", documentAttach.size, "webp", messageObject, 1);
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_VIDEO) {
photoImage.setNeedsQualityThumb(true);
photoImage.setShouldGenerateQualityThumb(true);
if (SharedConfig.autoplayVideo && (currentMessageObject.mediaExists || messageObject.canStreamVideo() && DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject))) {
photoImage.setAllowDecodeSingleFrame(true);
photoImage.setAllowStartAnimation(true);
photoImage.startAnimation();
photoImage.setImage(ImageLocation.getForDocument(documentAttach), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObjectThumb, documentAttach), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, documentAttach.size, null, messageObject, 0);
autoPlayingMedia = true;
} else {
if (currentPhotoObjectThumb != null || currentPhotoObjectThumbStripped != null) {
photoImage.setImage(ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
} else {
photoImage.setImage(null, null, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoObject instanceof TLRPC.TL_photoStrippedSize || "s".equals(currentPhotoObject.type) ? currentPhotoFilterThumb : currentPhotoFilter, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
}
}
} else if (documentAttachType == DOCUMENT_ATTACH_TYPE_GIF || documentAttachType == DOCUMENT_ATTACH_TYPE_ROUND) {
photoImage.setAllowDecodeSingleFrame(true);
boolean autoDownload = false;
if (MessageObject.isRoundVideoDocument(document)) {
photoImage.setRoundRadius(AndroidUtilities.roundMessageSize / 2);
canChangeRadius = false;
autoDownload = DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject);
} else if (MessageObject.isGifDocument(document, messageObject.hasValidGroupId())) {
autoDownload = DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject);
}
String filter = currentPhotoObject instanceof TLRPC.TL_photoStrippedSize || "s".equals(currentPhotoObject.type) ? currentPhotoFilterThumb : currentPhotoFilter;
if (messageObject.mediaExists || autoDownload) {
autoPlayingMedia = true;
TLRPC.VideoSize videoSize = MessageObject.getDocumentVideoThumb(document);
if (!messageObject.mediaExists && videoSize != null && (currentPhotoObject == null || currentPhotoObjectThumb == null)) {
photoImage.setImage(ImageLocation.getForDocument(document), document.size < 1024 * 32 ? null : ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForDocument(videoSize, documentAttach), null, ImageLocation.getForDocument(currentPhotoObject != null ? currentPhotoObject : currentPhotoObjectThumb, documentAttach), currentPhotoObject != null ? filter : currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
} else {
photoImage.setImage(ImageLocation.getForDocument(document), document.size < 1024 * 32 ? null : ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForDocument(currentPhotoObject, documentAttach), filter, ImageLocation.getForDocument(currentPhotoObjectThumb, documentAttach), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
}
} else {
photoImage.setImage(null, null, ImageLocation.getForDocument(currentPhotoObject, documentAttach), filter, 0, null, currentMessageObject, 0);
}
} else {
boolean photoExist = messageObject.mediaExists;
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
if (hasGamePreview || photoExist || DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject) || FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
photoNotSet = false;
photoImage.setImage(ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
} else {
photoNotSet = true;
if (currentPhotoObjectThumb != null || currentPhotoObjectThumbStripped != null) {
photoImage.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), String.format(Locale.US, "%d_%d_b", w, h), currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
} else {
photoImage.setImageBitmap((Drawable) null);
}
}
}
}
drawPhotoImage = true;
if (type != null && type.equals("video") && duration != 0) {
String str = AndroidUtilities.formatShortDuration(duration);
durationWidth = (int) Math.ceil(Theme.chat_durationPaint.measureText(str));
videoInfoLayout = new StaticLayout(str, Theme.chat_durationPaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else if (hasGamePreview) {
boolean showGameOverlay = true;
try {
long bot_id = messageObject.messageOwner.via_bot_id != 0 ? messageObject.messageOwner.via_bot_id : messageObject.messageOwner.from_id.user_id;
if (bot_id != 0) {
TLRPC.User botUser = MessagesController.getInstance(currentAccount).getUser(bot_id);
if (botUser != null && botUser.username != null && botUser.username.equals("donate")) {
showGameOverlay = false;
}
}
} catch (Exception e) {
}
if (showGameOverlay) {
String str = LocaleController.getString("AttachGame", R.string.AttachGame).toUpperCase();
durationWidth = (int) Math.ceil(Theme.chat_gamePaint.measureText(str));
videoInfoLayout = new StaticLayout(str, Theme.chat_gamePaint, durationWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
}
} else {
photoImage.setImageBitmap((Drawable) null);
linkPreviewHeight -= AndroidUtilities.dp(6);
totalHeight += AndroidUtilities.dp(4);
}
if (hasInvoicePreview) {
CharSequence str;
if ((messageObject.messageOwner.media.flags & 4) != 0) {
str = LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt).toUpperCase();
} else {
if (messageObject.messageOwner.media.test) {
str = LocaleController.getString("PaymentTestInvoice", R.string.PaymentTestInvoice).toUpperCase();
} else {
str = LocaleController.getString("PaymentInvoice", R.string.PaymentInvoice).toUpperCase();
}
}
String price = LocaleController.getInstance().formatCurrencyString(messageObject.messageOwner.media.total_amount, messageObject.messageOwner.media.currency);
SpannableStringBuilder stringBuilder = new SpannableStringBuilder(price + " " + str);
stringBuilder.setSpan(new TypefaceSpan(AndroidUtilities.getTypeface("fonts/rmedium.ttf")), 0, price.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
durationWidth = (int) Math.ceil(Theme.chat_shipmentPaint.measureText(stringBuilder, 0, stringBuilder.length()));
videoInfoLayout = new StaticLayout(stringBuilder, Theme.chat_shipmentPaint, durationWidth + AndroidUtilities.dp(10), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (!drawPhotoImage) {
totalHeight += AndroidUtilities.dp(6);
int timeWidthTotal = timeWidth + AndroidUtilities.dp(14 + (messageObject.isOutOwner() ? 20 : 0));
if (durationWidth + timeWidthTotal > maxWidth) {
maxChildWidth = Math.max(durationWidth, maxChildWidth);
totalHeight += AndroidUtilities.dp(12);
} else {
maxChildWidth = Math.max(durationWidth + timeWidthTotal, maxChildWidth);
}
}
}
if (hasGamePreview && messageObject.textHeight != 0) {
linkPreviewHeight += messageObject.textHeight + AndroidUtilities.dp(6);
totalHeight += AndroidUtilities.dp(4);
}
calcBackgroundWidth(maxWidth, timeMore, maxChildWidth);
}
createInstantViewButton();
} else {
photoImage.setImageBitmap((Drawable) null);
calcBackgroundWidth(maxWidth, timeMore, maxChildWidth);
}
} else if (messageObject.type == 16) {
createSelectorDrawable(0);
drawName = false;
drawForwardedName = false;
drawPhotoImage = false;
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
}
availableTimeWidth = backgroundWidth - AndroidUtilities.dp(31);
int maxWidth = getMaxNameWidth() - AndroidUtilities.dp(50);
if (maxWidth < 0) {
maxWidth = AndroidUtilities.dp(10);
}
String text;
String time = LocaleController.getInstance().formatterDay.format((long) (messageObject.messageOwner.date) * 1000);
TLRPC.TL_messageActionPhoneCall call = (TLRPC.TL_messageActionPhoneCall) messageObject.messageOwner.action;
boolean isMissed = call.reason instanceof TLRPC.TL_phoneCallDiscardReasonMissed;
if (messageObject.isOutOwner()) {
if (isMissed) {
if (call.video) {
text = LocaleController.getString("CallMessageVideoOutgoingMissed", R.string.CallMessageVideoOutgoingMissed);
} else {
text = LocaleController.getString("CallMessageOutgoingMissed", R.string.CallMessageOutgoingMissed);
}
} else {
if (call.video) {
text = LocaleController.getString("CallMessageVideoOutgoing", R.string.CallMessageVideoOutgoing);
} else {
text = LocaleController.getString("CallMessageOutgoing", R.string.CallMessageOutgoing);
}
}
} else {
if (isMissed) {
if (call.video) {
text = LocaleController.getString("CallMessageVideoIncomingMissed", R.string.CallMessageVideoIncomingMissed);
} else {
text = LocaleController.getString("CallMessageIncomingMissed", R.string.CallMessageIncomingMissed);
}
} else if (call.reason instanceof TLRPC.TL_phoneCallDiscardReasonBusy) {
if (call.video) {
text = LocaleController.getString("CallMessageVideoIncomingDeclined", R.string.CallMessageVideoIncomingDeclined);
} else {
text = LocaleController.getString("CallMessageIncomingDeclined", R.string.CallMessageIncomingDeclined);
}
} else {
if (call.video) {
text = LocaleController.getString("CallMessageVideoIncoming", R.string.CallMessageVideoIncoming);
} else {
text = LocaleController.getString("CallMessageIncoming", R.string.CallMessageIncoming);
}
}
}
if (call.duration > 0) {
time += ", " + LocaleController.formatCallDuration(call.duration);
}
titleLayout = new StaticLayout(TextUtils.ellipsize(text, Theme.chat_audioTitlePaint, maxWidth, TextUtils.TruncateAt.END), Theme.chat_audioTitlePaint, maxWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
docTitleLayout = new StaticLayout(TextUtils.ellipsize(time, Theme.chat_contactPhonePaint, maxWidth, TextUtils.TruncateAt.END), Theme.chat_contactPhonePaint, maxWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
setMessageObjectInternal(messageObject);
totalHeight = AndroidUtilities.dp(65) + namesOffset;
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
} else if (messageObject.type == 12) {
drawName = messageObject.isFromGroup() && messageObject.isSupergroup() || messageObject.isImportedForward() && messageObject.messageOwner.fwd_from.from_id == null;
drawForwardedName = !isRepliesChat;
drawPhotoImage = true;
photoImage.setRoundRadius(AndroidUtilities.dp(22));
canChangeRadius = false;
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
}
availableTimeWidth = backgroundWidth - AndroidUtilities.dp(31);
long uid = messageObject.messageOwner.media.user_id;
TLRPC.User user = null;
if (uid != 0) {
user = MessagesController.getInstance(currentAccount).getUser(uid);
}
int maxWidth = getMaxNameWidth() - AndroidUtilities.dp(80);
if (maxWidth < 0) {
maxWidth = AndroidUtilities.dp(10);
}
boolean hasName;
if (user != null) {
contactAvatarDrawable.setInfo(user);
hasName = true;
} else if (!TextUtils.isEmpty(messageObject.messageOwner.media.first_name) || !TextUtils.isEmpty(messageObject.messageOwner.media.last_name)) {
contactAvatarDrawable.setInfo(0, messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name);
hasName = true;
} else {
hasName = false;
}
photoImage.setForUserOrChat(user, hasName ? contactAvatarDrawable : Theme.chat_contactDrawable[messageObject.isOutOwner() ? 1 : 0], messageObject);
CharSequence phone;
if (!TextUtils.isEmpty(messageObject.vCardData)) {
phone = messageObject.vCardData;
drawInstantView = true;
drawInstantViewType = 5;
} else {
if (user != null && !TextUtils.isEmpty(user.phone)) {
phone = PhoneFormat.getInstance().format("+" + user.phone);
} else {
phone = messageObject.messageOwner.media.phone_number;
if (!TextUtils.isEmpty(phone)) {
phone = PhoneFormat.getInstance().format((String) phone);
} else {
phone = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
}
}
}
CharSequence currentNameString = ContactsController.formatName(messageObject.messageOwner.media.first_name, messageObject.messageOwner.media.last_name).replace('\n', ' ');
if (currentNameString.length() == 0) {
currentNameString = messageObject.messageOwner.media.phone_number;
if (currentNameString == null) {
currentNameString = "";
}
}
titleLayout = new StaticLayout(TextUtils.ellipsize(currentNameString, Theme.chat_contactNamePaint, maxWidth, TextUtils.TruncateAt.END), Theme.chat_contactNamePaint, maxWidth + AndroidUtilities.dp(4), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
docTitleLayout = new StaticLayout(phone, Theme.chat_contactPhonePaint, maxWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false);
setMessageObjectInternal(messageObject);
if (drawForwardedName && messageObject.needDrawForwarded() && (currentPosition == null || currentPosition.minY == 0)) {
namesOffset += AndroidUtilities.dp(5);
} else if (drawNameLayout && messageObject.getReplyMsgId() == 0) {
namesOffset += AndroidUtilities.dp(7);
}
totalHeight = AndroidUtilities.dp(70 - 15) + namesOffset + docTitleLayout.getHeight();
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
if (drawInstantView) {
createInstantViewButton();
} else {
if (docTitleLayout.getLineCount() > 0) {
int timeLeft = backgroundWidth - AndroidUtilities.dp(40 + 18 + 44 + 8) - (int) Math.ceil(docTitleLayout.getLineWidth(docTitleLayout.getLineCount() - 1));
if (timeLeft < timeWidth) {
totalHeight += AndroidUtilities.dp(8);
}
}
}
if (!reactionsLayoutInBubble.isSmall) {
if (!reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.measure(backgroundWidth - AndroidUtilities.dp(32));
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY += -AndroidUtilities.dp(4);
if (backgroundWidth - AndroidUtilities.dp(32) - reactionsLayoutInBubble.lastLineX < timeWidth) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY += -AndroidUtilities.dp(12);
}
totalHeight += reactionsLayoutInBubble.totalHeight;
}
}
} else if (messageObject.type == 2) {
drawForwardedName = !isRepliesChat;
drawName = messageObject.isFromGroup() && messageObject.isSupergroup() || messageObject.isImportedForward() && messageObject.messageOwner.fwd_from.from_id == null;
int maxWidth;
if (AndroidUtilities.isTablet()) {
backgroundWidth = maxWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
} else {
backgroundWidth = maxWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
}
createDocumentLayout(backgroundWidth, messageObject);
setMessageObjectInternal(messageObject);
totalHeight = AndroidUtilities.dp(70) + namesOffset;
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
if (!reactionsLayoutInBubble.isSmall) {
reactionsLayoutInBubble.measure(maxWidth - AndroidUtilities.dp(24));
if (!reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height;
if (TextUtils.isEmpty(messageObject.caption)) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
} else {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(8);
}
measureTime(messageObject);
if (reactionsLayoutInBubble.width > backgroundWidth) {
backgroundWidth = reactionsLayoutInBubble.width;
}
if (reactionsLayoutInBubble.lastLineX + timeWidth + AndroidUtilities.dp(24) > backgroundWidth) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(12);
}
totalHeight += reactionsLayoutInBubble.totalHeight;
}
}
} else if (messageObject.type == 14) {
drawName = (messageObject.isFromGroup() && messageObject.isSupergroup() || messageObject.isImportedForward() && messageObject.messageOwner.fwd_from.from_id == null) && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_TOP) != 0);
int maxWidth;
if (AndroidUtilities.isTablet()) {
backgroundWidth = maxWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
} else {
backgroundWidth = maxWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(270));
}
createDocumentLayout(backgroundWidth, messageObject);
setMessageObjectInternal(messageObject);
totalHeight = AndroidUtilities.dp(82) + namesOffset;
if (currentPosition != null && currentMessagesGroup != null && currentMessagesGroup.messages.size() > 1) {
if ((currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0) {
totalHeight -= AndroidUtilities.dp(6);
mediaOffsetY -= AndroidUtilities.dp(6);
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0) {
totalHeight -= AndroidUtilities.dp(6);
}
}
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
if (!reactionsLayoutInBubble.isSmall) {
reactionsLayoutInBubble.measure(maxWidth - AndroidUtilities.dp(24));
if (!reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(12);
measureTime(messageObject);
if (reactionsLayoutInBubble.width > backgroundWidth) {
backgroundWidth = reactionsLayoutInBubble.width;
}
if (reactionsLayoutInBubble.lastLineX + timeWidth + AndroidUtilities.dp(24) > backgroundWidth) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(12);
}
if (!messageObject.isRestrictedMessage && messageObject.caption != null) {
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(14);
}
totalHeight += reactionsLayoutInBubble.totalHeight;
}
}
} else if (messageObject.type == MessageObject.TYPE_POLL) {
if (timerParticles == null) {
timerParticles = new TimerParticles();
}
createSelectorDrawable(0);
drawName = true;
drawForwardedName = !isRepliesChat;
drawPhotoImage = false;
int maxWidth = Math.min(AndroidUtilities.dp(500), messageObject.getMaxMessageTextWidth());
backgroundWidth = maxWidth + AndroidUtilities.dp(31);
TLRPC.TL_messageMediaPoll media = (TLRPC.TL_messageMediaPoll) messageObject.messageOwner.media;
timerTransitionProgress = media.poll.close_date - ConnectionsManager.getInstance(currentAccount).getCurrentTime() < 60 ? 0.0f : 1.0f;
pollClosed = media.poll.closed;
pollVoted = messageObject.isVoted();
if (pollVoted) {
messageObject.checkedVotes.clear();
}
titleLayout = new StaticLayout(Emoji.replaceEmoji(media.poll.question, Theme.chat_audioTitlePaint.getFontMetricsInt(), AndroidUtilities.dp(16), false), Theme.chat_audioTitlePaint, maxWidth + AndroidUtilities.dp(2) - getExtraTextX() * 2, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
boolean titleRtl = false;
if (titleLayout != null) {
for (int a = 0, N = titleLayout.getLineCount(); a < N; a++) {
if (titleLayout.getLineLeft(a) > 0) {
titleRtl = true;
break;
}
}
}
String title;
if (pollClosed) {
title = LocaleController.getString("FinalResults", R.string.FinalResults);
} else {
if (media.poll.quiz) {
if (media.poll.public_voters) {
title = LocaleController.getString("QuizPoll", R.string.QuizPoll);
} else {
title = LocaleController.getString("AnonymousQuizPoll", R.string.AnonymousQuizPoll);
}
} else if (media.poll.public_voters) {
title = LocaleController.getString("PublicPoll", R.string.PublicPoll);
} else {
title = LocaleController.getString("AnonymousPoll", R.string.AnonymousPoll);
}
}
docTitleLayout = new StaticLayout(TextUtils.ellipsize(title, Theme.chat_timePaint, maxWidth, TextUtils.TruncateAt.END), Theme.chat_timePaint, maxWidth + AndroidUtilities.dp(2) - getExtraTextX() * 2, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (docTitleLayout != null && docTitleLayout.getLineCount() > 0) {
if (titleRtl && !LocaleController.isRTL) {
docTitleOffsetX = (int) Math.ceil(maxWidth - docTitleLayout.getLineWidth(0));
} else if (!titleRtl && LocaleController.isRTL) {
docTitleOffsetX = -(int) Math.ceil(docTitleLayout.getLineLeft(0));
} else {
docTitleOffsetX = 0;
}
}
int w = maxWidth - AndroidUtilities.dp(messageObject.isOutOwner() ? 28 : 8);
if (!isBot) {
TextPaint textPaint = !media.poll.public_voters && !media.poll.multiple_choice ? Theme.chat_livePaint : Theme.chat_locationAddressPaint;
CharSequence votes;
if (media.poll.quiz) {
votes = TextUtils.ellipsize(media.results.total_voters == 0 ? LocaleController.getString("NoVotesQuiz", R.string.NoVotesQuiz) : LocaleController.formatPluralString("Answer", media.results.total_voters), textPaint, w, TextUtils.TruncateAt.END);
} else {
votes = TextUtils.ellipsize(media.results.total_voters == 0 ? LocaleController.getString("NoVotes", R.string.NoVotes) : LocaleController.formatPluralString("Vote", media.results.total_voters), textPaint, w, TextUtils.TruncateAt.END);
}
infoLayout = new StaticLayout(votes, textPaint, w, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
if (infoLayout != null) {
if (!media.poll.public_voters && !media.poll.multiple_choice) {
infoX = (int) Math.ceil(infoLayout.getLineCount() > 0 ? -infoLayout.getLineLeft(0) : 0);
availableTimeWidth = (int) (maxWidth - infoLayout.getLineWidth(0) - AndroidUtilities.dp(16));
} else {
infoX = (int) ((backgroundWidth - AndroidUtilities.dp(28) - Math.ceil(infoLayout.getLineWidth(0))) / 2 - infoLayout.getLineLeft(0));
availableTimeWidth = maxWidth;
}
}
}
measureTime(messageObject);
lastPoll = media.poll;
lastPollResults = media.results.results;
lastPollResultsVoters = media.results.total_voters;
if (media.poll.multiple_choice && !pollVoted && !pollClosed || !isBot && (media.poll.public_voters && pollVoted || pollClosed && media.results != null && media.results.total_voters != 0 && media.poll.public_voters)) {
drawInstantView = true;
drawInstantViewType = 8;
createInstantViewButton();
}
if (media.poll.multiple_choice) {
createPollUI();
}
if (media.results != null) {
createPollUI();
int size = media.results.recent_voters.size();
for (int a = 0; a < pollAvatarImages.length; a++) {
if (!isBot && a < size) {
pollAvatarImages[a].setImageCoords(0, 0, AndroidUtilities.dp(16), AndroidUtilities.dp(16));
Long id = media.results.recent_voters.get(a);
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(id);
if (user != null) {
pollAvatarDrawables[a].setInfo(user);
pollAvatarImages[a].setForUserOrChat(user, pollAvatarDrawables[a]);
} else {
pollAvatarDrawables[a].setInfo(id, "", "");
}
pollAvatarImagesVisible[a] = true;
} else if (!pollUnvoteInProgress || size != 0) {
pollAvatarImages[a].setImageBitmap((Drawable) null);
pollAvatarImagesVisible[a] = false;
}
}
} else if (pollAvatarImages != null) {
for (int a = 0; a < pollAvatarImages.length; a++) {
pollAvatarImages[a].setImageBitmap((Drawable) null);
pollAvatarImagesVisible[a] = false;
}
}
int maxVote = 0;
if (!animatePollAnswer && pollVoteInProgress && vibrateOnPollVote) {
performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
}
animatePollAnswerAlpha = animatePollAnswer = attachedToWindow && (pollVoteInProgress || pollUnvoteInProgress);
ArrayList<PollButton> previousPollButtons = null;
ArrayList<PollButton> sortedPollButtons = new ArrayList<>();
if (!pollButtons.isEmpty()) {
previousPollButtons = new ArrayList<>(pollButtons);
pollButtons.clear();
if (!animatePollAnswer) {
animatePollAnswer = attachedToWindow && (pollVoted || pollClosed);
}
if (pollAnimationProgress > 0 && pollAnimationProgress < 1.0f) {
for (int b = 0, N2 = previousPollButtons.size(); b < N2; b++) {
PollButton button = previousPollButtons.get(b);
button.percent = (int) Math.ceil(button.prevPercent + (button.percent - button.prevPercent) * pollAnimationProgress);
button.percentProgress = button.prevPercentProgress + (button.percentProgress - button.prevPercentProgress) * pollAnimationProgress;
}
}
}
pollAnimationProgress = animatePollAnswer ? 0.0f : 1.0f;
byte[] votingFor;
if (!animatePollAnswerAlpha) {
pollVoteInProgress = false;
pollVoteInProgressNum = -1;
votingFor = SendMessagesHelper.getInstance(currentAccount).isSendingVote(currentMessageObject);
} else {
votingFor = null;
}
int height = titleLayout != null ? titleLayout.getHeight() : 0;
int restPercent = 100;
boolean hasDifferent = false;
int previousPercent = 0;
for (int a = 0, N = media.poll.answers.size(); a < N; a++) {
PollButton button = new PollButton();
button.answer = media.poll.answers.get(a);
button.title = new StaticLayout(Emoji.replaceEmoji(button.answer.text, Theme.chat_audioPerformerPaint.getFontMetricsInt(), AndroidUtilities.dp(15), false), Theme.chat_audioPerformerPaint, maxWidth - AndroidUtilities.dp(33), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
button.y = height + AndroidUtilities.dp(52);
button.height = button.title.getHeight();
pollButtons.add(button);
sortedPollButtons.add(button);
height += button.height + AndroidUtilities.dp(26);
if (!media.results.results.isEmpty()) {
for (int b = 0, N2 = media.results.results.size(); b < N2; b++) {
TLRPC.TL_pollAnswerVoters answer = media.results.results.get(b);
if (Arrays.equals(button.answer.option, answer.option)) {
button.chosen = answer.chosen;
button.count = answer.voters;
button.correct = answer.correct;
if ((pollVoted || pollClosed) && media.results.total_voters > 0) {
button.decimal = 100 * (answer.voters / (float) media.results.total_voters);
button.percent = (int) button.decimal;
button.decimal -= button.percent;
} else {
button.percent = 0;
button.decimal = 0;
}
if (previousPercent == 0) {
previousPercent = button.percent;
} else if (button.percent != 0 && previousPercent != button.percent) {
hasDifferent = true;
}
restPercent -= button.percent;
maxVote = Math.max(button.percent, maxVote);
break;
}
}
}
if (previousPollButtons != null) {
for (int b = 0, N2 = previousPollButtons.size(); b < N2; b++) {
PollButton prevButton = previousPollButtons.get(b);
if (Arrays.equals(button.answer.option, prevButton.answer.option)) {
button.prevPercent = prevButton.percent;
button.prevPercentProgress = prevButton.percentProgress;
button.prevChosen = prevButton.chosen;
break;
}
}
}
if (votingFor != null && button.answer.option.length > 0 && Arrays.binarySearch(votingFor, button.answer.option[0]) >= 0) {
pollVoteInProgressNum = a;
pollVoteInProgress = true;
vibrateOnPollVote = true;
votingFor = null;
}
if (currentMessageObject.checkedVotes.contains(button.answer)) {
pollCheckBox[a].setChecked(true, false);
} else {
pollCheckBox[a].setChecked(false, false);
}
}
if (hasDifferent && restPercent != 0) {
Collections.sort(sortedPollButtons, (o1, o2) -> {
if (o1.decimal > o2.decimal) {
return -1;
} else if (o1.decimal < o2.decimal) {
return 1;
}
if (o1.decimal == o2.decimal) {
if (o1.percent > o2.percent) {
return 1;
} else if (o1.percent < o2.percent) {
return -1;
}
}
return 0;
});
for (int a = 0, N = Math.min(restPercent, sortedPollButtons.size()); a < N; a++) {
sortedPollButtons.get(a).percent += 1;
}
}
int width = backgroundWidth - AndroidUtilities.dp(76);
for (int b = 0, N2 = pollButtons.size(); b < N2; b++) {
PollButton button = pollButtons.get(b);
button.percentProgress = Math.max(AndroidUtilities.dp(5) / (float) width, maxVote != 0 ? button.percent / (float) maxVote : 0);
}
setMessageObjectInternal(messageObject);
if (isBot && !drawInstantView) {
height -= AndroidUtilities.dp(10);
} else if (media.poll.public_voters || media.poll.multiple_choice) {
height += AndroidUtilities.dp(13);
}
totalHeight = AndroidUtilities.dp(46 + 27) + namesOffset + height;
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
insantTextNewLine = false;
if (media.poll.public_voters || media.poll.multiple_choice) {
int instantTextWidth = 0;
for (int a = 0; a < 3; a++) {
String str;
if (a == 0) {
str = LocaleController.getString("PollViewResults", R.string.PollViewResults);
} else if (a == 1) {
str = LocaleController.getString("PollSubmitVotes", R.string.PollSubmitVotes);
} else {
str = LocaleController.getString("NoVotes", R.string.NoVotes);
}
instantTextWidth = Math.max(instantTextWidth, (int) Math.ceil(Theme.chat_instantViewPaint.measureText(str)));
}
int timeWidthTotal = timeWidth + (messageObject.isOutOwner() ? AndroidUtilities.dp(20) : 0) + getExtraTimeX();
if (!reactionsLayoutInBubble.isSmall && reactionsLayoutInBubble.isEmpty && timeWidthTotal >= (backgroundWidth - AndroidUtilities.dp(76) - instantTextWidth) / 2) {
totalHeight += AndroidUtilities.dp(18);
insantTextNewLine = true;
}
}
if (!reactionsLayoutInBubble.isSmall) {
if (!reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.measure(maxWidth);
totalHeight += reactionsLayoutInBubble.height + AndroidUtilities.dp(12);
int timeWidthTotal = timeWidth + (messageObject.isOutOwner() ? AndroidUtilities.dp(20) : 0) + getExtraTimeX();
if (timeWidthTotal >= (backgroundWidth - AndroidUtilities.dp(24) - reactionsLayoutInBubble.lastLineX)) {
totalHeight += AndroidUtilities.dp(16);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(16);
}
}
}
} else {
drawForwardedName = messageObject.messageOwner.fwd_from != null && !(messageObject.isAnyKindOfSticker() && messageObject.isDice());
if (!messageObject.isAnyKindOfSticker() && messageObject.type != MessageObject.TYPE_ROUND_VIDEO) {
drawName = (messageObject.isFromGroup() && messageObject.isSupergroup() || messageObject.isImportedForward() && messageObject.messageOwner.fwd_from.from_id == null) && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_TOP) != 0);
}
mediaBackground = isMedia = messageObject.type != 9;
drawImageButton = true;
drawPhotoImage = true;
int photoWidth = 0;
int photoHeight = 0;
int additionHeight = 0;
if (messageObject.gifState != 2 && !SharedConfig.autoplayGifs && (messageObject.type == 8 || messageObject.type == MessageObject.TYPE_ROUND_VIDEO)) {
messageObject.gifState = 1;
}
photoImage.setAllowDecodeSingleFrame(true);
if (messageObject.isVideo()) {
photoImage.setAllowStartAnimation(true);
} else if (messageObject.isRoundVideo()) {
MessageObject playingMessage = MediaController.getInstance().getPlayingMessageObject();
photoImage.setAllowStartAnimation(playingMessage == null || !playingMessage.isRoundVideo());
} else {
photoImage.setAllowStartAnimation(messageObject.gifState == 0);
}
photoImage.setForcePreview(messageObject.needDrawBluredPreview());
if (messageObject.type == 9) {
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(300));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(300));
}
if (checkNeedDrawShareButton(messageObject)) {
backgroundWidth -= AndroidUtilities.dp(20);
}
int maxTextWidth = 0;
int maxWidth = backgroundWidth - AndroidUtilities.dp(86 + 52);
int widthForCaption = 0;
createDocumentLayout(maxWidth, messageObject);
int width = backgroundWidth - AndroidUtilities.dp(31);
widthForCaption = width - AndroidUtilities.dp(10) - getExtraTextX() * 2;
if (!messageObject.isRestrictedMessage && !TextUtils.isEmpty(messageObject.caption)) {
try {
currentCaption = messageObject.caption;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
captionLayout = StaticLayout.Builder.obtain(messageObject.caption, 0, messageObject.caption.length(), Theme.chat_msgTextPaint, widthForCaption).setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY).setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
} else {
captionLayout = new StaticLayout(messageObject.caption, Theme.chat_msgTextPaint, widthForCaption, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
updateCaptionSpoilers();
} catch (Exception e) {
FileLog.e(e);
}
}
if (docTitleLayout != null) {
for (int a = 0, N = docTitleLayout.getLineCount(); a < N; a++) {
maxTextWidth = Math.max(maxTextWidth, (int) Math.ceil(docTitleLayout.getLineWidth(a) + docTitleLayout.getLineLeft(a)) + AndroidUtilities.dp(86 + (drawPhotoImage ? 52 : 22)));
}
}
if (infoLayout != null) {
for (int a = 0, N = infoLayout.getLineCount(); a < N; a++) {
maxTextWidth = Math.max(maxTextWidth, infoWidth + AndroidUtilities.dp(86 + (drawPhotoImage ? 52 : 22)));
}
}
if (captionLayout != null) {
for (int a = 0, N = captionLayout.getLineCount(); a < N; a++) {
int w = (int) Math.ceil(Math.min(widthForCaption, captionLayout.getLineWidth(a) + captionLayout.getLineLeft(a))) + AndroidUtilities.dp(31);
if (w > maxTextWidth) {
maxTextWidth = w;
}
}
}
if (!reactionsLayoutInBubble.isSmall) {
reactionsLayoutInBubble.measure(widthForCaption);
if (!reactionsLayoutInBubble.isEmpty && reactionsLayoutInBubble.width + AndroidUtilities.dp(31) > maxTextWidth) {
maxTextWidth = reactionsLayoutInBubble.width + AndroidUtilities.dp(31);
}
}
if (maxTextWidth > 0 && currentPosition == null) {
backgroundWidth = maxTextWidth;
maxWidth = maxTextWidth - AndroidUtilities.dp(31);
}
availableTimeWidth = maxWidth;
if (drawPhotoImage) {
photoWidth = AndroidUtilities.dp(86);
photoHeight = AndroidUtilities.dp(86);
availableTimeWidth -= photoWidth;
} else {
photoWidth = AndroidUtilities.dp(56);
photoHeight = AndroidUtilities.dp(56);
if (docTitleLayout != null && docTitleLayout.getLineCount() > 1) {
photoHeight += (docTitleLayout.getLineCount() - 1) * AndroidUtilities.dp(16);
}
if (TextUtils.isEmpty(messageObject.caption) && infoLayout != null) {
int lineCount = infoLayout.getLineCount();
measureTime(messageObject);
int timeLeft = backgroundWidth - AndroidUtilities.dp(40 + 18 + 56 + 8) - infoWidth;
if (reactionsLayoutInBubble.isSmall || reactionsLayoutInBubble.isEmpty) {
if (timeLeft < timeWidth) {
photoHeight += AndroidUtilities.dp(12);
} else if (lineCount == 1) {
photoHeight += AndroidUtilities.dp(4);
}
}
}
}
if (!reactionsLayoutInBubble.isSmall && !reactionsLayoutInBubble.isEmpty) {
if (!drawPhotoImage) {
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(2);
}
if (captionLayout != null && currentPosition != null && currentMessagesGroup != null && currentMessagesGroup.isDocuments) {
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(10);
} else if (!drawPhotoImage && !TextUtils.isEmpty(messageObject.caption) && ((docTitleLayout != null && docTitleLayout.getLineCount() > 1) || currentMessageObject.hasValidReplyMessageObject())) {
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(10);
}
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(8);
measureTime(messageObject);
if (drawPhotoImage && captionLayout == null) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(8);
}
int timeLeft = backgroundWidth - reactionsLayoutInBubble.lastLineX - AndroidUtilities.dp(24);
if (timeLeft < timeWidth) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(12);
}
additionHeight += reactionsLayoutInBubble.totalHeight;
}
} else if (messageObject.type == MessageObject.TYPE_GEO) {
TLRPC.GeoPoint point = messageObject.messageOwner.media.geo;
double lat = point.lat;
double lon = point._long;
int provider;
if ((int) messageObject.getDialogId() == 0) {
if (SharedConfig.mapPreviewType == 0) {
provider = -1;
} else if (SharedConfig.mapPreviewType == 1) {
provider = 4;
} else if (SharedConfig.mapPreviewType == 3) {
provider = 1;
} else {
provider = -1;
}
} else {
provider = -1;
}
if (messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaGeoLive) {
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
}
backgroundWidth -= AndroidUtilities.dp(4);
if (checkNeedDrawShareButton(messageObject)) {
backgroundWidth -= AndroidUtilities.dp(20);
}
int maxWidth = backgroundWidth - AndroidUtilities.dp(37);
availableTimeWidth = maxWidth;
maxWidth -= AndroidUtilities.dp(54);
photoWidth = backgroundWidth - AndroidUtilities.dp(17);
photoHeight = AndroidUtilities.dp(195);
int offset = 268435456;
double rad = offset / Math.PI;
double y = Math.round(offset - rad * Math.log((1 + Math.sin(lat * Math.PI / 180.0)) / (1 - Math.sin(lat * Math.PI / 180.0))) / 2) - (AndroidUtilities.dp(10.3f) << (21 - 15));
lat = (Math.PI / 2.0 - 2 * Math.atan(Math.exp((y - offset) / rad))) * 180.0 / Math.PI;
currentUrl = AndroidUtilities.formapMapUrl(currentAccount, lat, lon, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), false, 15, provider);
lastWebFile = currentWebFile;
currentWebFile = WebFile.createWithGeoPoint(lat, lon, point.access_hash, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), 15, Math.min(2, (int) Math.ceil(AndroidUtilities.density)));
if (!(locationExpired = isCurrentLocationTimeExpired(messageObject))) {
photoImage.setCrossfadeWithOldImage(true);
mediaBackground = false;
additionHeight = AndroidUtilities.dp(56);
AndroidUtilities.runOnUIThread(invalidateRunnable, 1000);
scheduledInvalidate = true;
} else {
backgroundWidth -= AndroidUtilities.dp(9);
}
docTitleLayout = new StaticLayout(TextUtils.ellipsize(LocaleController.getString("AttachLiveLocation", R.string.AttachLiveLocation), Theme.chat_locationTitlePaint, maxWidth, TextUtils.TruncateAt.END), Theme.chat_locationTitlePaint, maxWidth + AndroidUtilities.dp(2), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
updateCurrentUserAndChat();
if (currentUser != null) {
contactAvatarDrawable.setInfo(currentUser);
locationImageReceiver.setForUserOrChat(currentUser, contactAvatarDrawable);
} else if (currentChat != null) {
if (currentChat.photo != null) {
currentPhoto = currentChat.photo.photo_small;
}
contactAvatarDrawable.setInfo(currentChat);
locationImageReceiver.setForUserOrChat(currentChat, contactAvatarDrawable);
} else {
locationImageReceiver.setImage(null, null, contactAvatarDrawable, null, null, 0);
}
infoLayout = new StaticLayout(TextUtils.ellipsize(LocaleController.formatLocationUpdateDate(messageObject.messageOwner.edit_date != 0 ? messageObject.messageOwner.edit_date : messageObject.messageOwner.date), Theme.chat_locationAddressPaint, maxWidth + AndroidUtilities.dp(2), TextUtils.TruncateAt.END), Theme.chat_locationAddressPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
} else if (!TextUtils.isEmpty(messageObject.messageOwner.media.title)) {
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
}
backgroundWidth -= AndroidUtilities.dp(4);
if (checkNeedDrawShareButton(messageObject)) {
backgroundWidth -= AndroidUtilities.dp(20);
}
int maxWidth = backgroundWidth - AndroidUtilities.dp(34);
availableTimeWidth = maxWidth;
photoWidth = backgroundWidth - AndroidUtilities.dp(17);
photoHeight = AndroidUtilities.dp(195);
mediaBackground = false;
currentUrl = AndroidUtilities.formapMapUrl(currentAccount, lat, lon, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), true, 15, provider);
currentWebFile = WebFile.createWithGeoPoint(point, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), 15, Math.min(2, (int) Math.ceil(AndroidUtilities.density)));
docTitleLayout = StaticLayoutEx.createStaticLayout(messageObject.messageOwner.media.title, Theme.chat_locationTitlePaint, maxWidth + AndroidUtilities.dp(4), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false, TextUtils.TruncateAt.END, maxWidth, 1);
additionHeight += AndroidUtilities.dp(50);
int lineCount = docTitleLayout.getLineCount();
if (!TextUtils.isEmpty(messageObject.messageOwner.media.address)) {
infoLayout = StaticLayoutEx.createStaticLayout(messageObject.messageOwner.media.address, Theme.chat_locationAddressPaint, maxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false, TextUtils.TruncateAt.END, maxWidth, 1);
measureTime(messageObject);
int timeLeft = backgroundWidth - (int) Math.ceil(infoLayout.getLineWidth(0)) - AndroidUtilities.dp(24);
boolean isRtl = infoLayout.getLineLeft(0) > 0;
if (isRtl || timeLeft < timeWidth + AndroidUtilities.dp(20 + (messageObject.isOutOwner() ? 20 : 0))) {
additionHeight += AndroidUtilities.dp(isRtl ? 10 : 8);
}
} else {
infoLayout = null;
}
} else {
if (AndroidUtilities.isTablet()) {
backgroundWidth = Math.min(AndroidUtilities.getMinTabletSide() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
} else {
backgroundWidth = Math.min(getParentWidth() - AndroidUtilities.dp(drawAvatar ? 102 : 50), AndroidUtilities.dp(252 + 37));
}
backgroundWidth -= AndroidUtilities.dp(4);
if (checkNeedDrawShareButton(messageObject)) {
backgroundWidth -= AndroidUtilities.dp(20);
}
availableTimeWidth = backgroundWidth - AndroidUtilities.dp(34);
photoWidth = backgroundWidth - AndroidUtilities.dp(8);
photoHeight = AndroidUtilities.dp(195);
currentUrl = AndroidUtilities.formapMapUrl(currentAccount, lat, lon, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), true, 15, provider);
currentWebFile = WebFile.createWithGeoPoint(point, (int) (photoWidth / AndroidUtilities.density), (int) (photoHeight / AndroidUtilities.density), 15, Math.min(2, (int) Math.ceil(AndroidUtilities.density)));
}
if ((int) messageObject.getDialogId() == 0) {
if (SharedConfig.mapPreviewType == 0) {
currentMapProvider = 2;
} else if (SharedConfig.mapPreviewType == 1) {
currentMapProvider = 1;
} else if (SharedConfig.mapPreviewType == 3) {
currentMapProvider = 1;
} else {
currentMapProvider = -1;
}
} else {
currentMapProvider = MessagesController.getInstance(messageObject.currentAccount).mapProvider;
// default to Telegram
if (currentMapProvider != -1) {
currentMapProvider = 2;
}
}
if (currentMapProvider == -1) {
photoImage.setImage(null, null, null, null, messageObject, 0);
} else if (currentMapProvider == 2) {
if (currentWebFile != null) {
ImageLocation lastLocation = lastWebFile == null ? null : ImageLocation.getForWebFile(lastWebFile);
photoImage.setImage(ImageLocation.getForWebFile(currentWebFile), null, lastLocation, null, (Drawable) null, messageObject, 0);
}
} else {
if (currentMapProvider == 3 || currentMapProvider == 4) {
ImageLoader.getInstance().addTestWebFile(currentUrl, currentWebFile);
addedForTest = true;
}
if (currentUrl != null) {
photoImage.setImage(currentUrl, null, null, null, 0);
}
}
if (!reactionsLayoutInBubble.isSmall && !reactionsLayoutInBubble.isEmpty) {
reactionsLayoutInBubble.measure(backgroundWidth - AndroidUtilities.dp(16));
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(14);
measureTime(messageObject);
if (reactionsLayoutInBubble.lastLineX + timeWidth + AndroidUtilities.dp(24) > backgroundWidth) {
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(12);
}
additionHeight += reactionsLayoutInBubble.totalHeight;
}
} else if (messageObject.isAnyKindOfSticker()) {
drawBackground = false;
boolean isWebpSticker = messageObject.type == MessageObject.TYPE_STICKER;
for (int a = 0; a < messageObject.getDocument().attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize) {
photoWidth = attribute.w;
photoHeight = attribute.h;
break;
}
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
photoWidth = attribute.w;
photoHeight = attribute.h;
break;
}
}
if ((messageObject.isAnimatedSticker() || messageObject.isVideoSticker()) && photoWidth == 0 && photoHeight == 0) {
photoWidth = photoHeight = 512;
}
float maxHeight;
int maxWidth;
if (AndroidUtilities.isTablet()) {
maxHeight = maxWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.4f);
} else {
maxHeight = maxWidth = (int) (Math.min(getParentWidth(), AndroidUtilities.displaySize.y) * 0.5f);
}
String filter;
if (messageObject.isAnimatedEmoji() || messageObject.isDice()) {
float zoom = MessagesController.getInstance(currentAccount).animatedEmojisZoom;
photoWidth = (int) ((photoWidth / 512.0f) * maxWidth * zoom);
photoHeight = (int) ((photoHeight / 512.0f) * maxHeight * zoom);
} else {
if (photoWidth == 0) {
photoHeight = (int) maxHeight;
photoWidth = photoHeight + AndroidUtilities.dp(100);
}
photoHeight *= maxWidth / (float) photoWidth;
photoWidth = (int) maxWidth;
if (photoHeight > maxHeight) {
photoWidth *= maxHeight / photoHeight;
photoHeight = (int) maxHeight;
}
}
Object parentObject = messageObject;
int w = (int) (photoWidth / AndroidUtilities.density);
int h = (int) (photoHeight / AndroidUtilities.density);
boolean shouldRepeatSticker = delegate != null && delegate.shouldRepeatSticker(messageObject);
if (currentMessageObject.strippedThumb == null) {
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
} else {
currentPhotoObjectThumbStripped = currentMessageObject.strippedThumb;
}
photoParentObject = messageObject.photoThumbsObject;
if (messageObject.isDice()) {
filter = String.format(Locale.US, "%d_%d_dice_%s_%s", w, h, messageObject.getDiceEmoji(), messageObject.toString());
photoImage.setAutoRepeat(2);
String emoji = currentMessageObject.getDiceEmoji();
TLRPC.TL_messages_stickerSet stickerSet = MediaDataController.getInstance(currentAccount).getStickerSetByEmojiOrName(emoji);
if (stickerSet != null) {
if (stickerSet.documents.size() > 0) {
int value = currentMessageObject.getDiceValue();
if (value <= 0) {
TLRPC.Document document = stickerSet.documents.get(0);
if ("\uD83C\uDFB0".equals(emoji)) {
currentPhotoObjectThumb = null;
} else {
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(document.thumbs, 40);
}
photoParentObject = document;
}
}
}
} else if (messageObject.isAnimatedEmoji()) {
filter = String.format(Locale.US, "%d_%d_nr_%s" + messageObject.emojiAnimatedStickerColor, w, h, messageObject.toString());
photoImage.setAutoRepeat(shouldRepeatSticker ? 2 : 3);
parentObject = MessageObject.getInputStickerSet(messageObject.emojiAnimatedSticker);
} else if (SharedConfig.loopStickers || (isWebpSticker && !messageObject.isVideoSticker())) {
filter = String.format(Locale.US, "%d_%d", w, h);
photoImage.setAutoRepeat(1);
} else {
filter = String.format(Locale.US, "%d_%d_nr_%s", w, h, messageObject.toString());
photoImage.setAutoRepeat(shouldRepeatSticker ? 2 : 3);
}
documentAttachType = DOCUMENT_ATTACH_TYPE_STICKER;
availableTimeWidth = photoWidth - AndroidUtilities.dp(14);
backgroundWidth = photoWidth + AndroidUtilities.dp(12);
photoImage.setRoundRadius(0);
canChangeRadius = false;
if (messageObject.isVideoSticker()) {
// photoImage.setAspectFit(true);
photoImage.setImage(ImageLocation.getForDocument(messageObject.getDocument()), ImageLoader.AUTOPLAY_FILTER, null, null, messageObject.pathThumb, messageObject.getDocument().size, isWebpSticker ? "webp" : null, parentObject, 1);
} else if (messageObject.pathThumb != null) {
photoImage.setImage(ImageLocation.getForDocument(messageObject.getDocument()), filter, messageObject.pathThumb, messageObject.getDocument().size, isWebpSticker ? "webp" : null, parentObject, 1);
} else if (messageObject.attachPathExists) {
photoImage.setImage(ImageLocation.getForPath(messageObject.messageOwner.attachPath), filter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), "b1", currentPhotoObjectThumbStripped, messageObject.getDocument().size, isWebpSticker ? "webp" : null, parentObject, 1);
} else if (messageObject.getDocument().id != 0) {
photoImage.setImage(ImageLocation.getForDocument(messageObject.getDocument()), filter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), "b1", currentPhotoObjectThumbStripped, messageObject.getDocument().size, isWebpSticker ? "webp" : null, parentObject, 1);
} else {
photoImage.setImage(null, null, null, null, messageObject, 0);
}
if (!reactionsLayoutInBubble.isSmall) {
reactionsLayoutInBubble.measure(maxWidth);
reactionsLayoutInBubble.drawServiceShaderBackground = true;
reactionsLayoutInBubble.totalHeight = reactionsLayoutInBubble.height + AndroidUtilities.dp(8);
additionHeight += reactionsLayoutInBubble.totalHeight;
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(4);
}
} else {
currentPhotoObject = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, AndroidUtilities.getPhotoSize());
photoParentObject = messageObject.photoThumbsObject;
boolean useFullWidth = false;
if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
documentAttach = messageObject.getDocument();
documentAttachType = DOCUMENT_ATTACH_TYPE_ROUND;
} else {
if (AndroidUtilities.isTablet()) {
photoWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.7f);
} else {
if (currentPhotoObject != null && (messageObject.type == MessageObject.TYPE_PHOTO || messageObject.type == MessageObject.TYPE_VIDEO || messageObject.type == 8) && currentPhotoObject.w >= currentPhotoObject.h) {
photoWidth = Math.min(getParentWidth(), AndroidUtilities.displaySize.y) - AndroidUtilities.dp(64 + (checkNeedDrawShareButton(messageObject) ? 10 : 0));
useFullWidth = true;
} else {
photoWidth = (int) (Math.min(getParentWidth(), AndroidUtilities.displaySize.y) * 0.7f);
}
}
}
photoHeight = photoWidth + AndroidUtilities.dp(100);
if (!useFullWidth) {
if (messageObject.type != 5 && checkNeedDrawShareButton(messageObject)) {
photoWidth -= AndroidUtilities.dp(20);
}
if (photoWidth > AndroidUtilities.getPhotoSize()) {
photoWidth = AndroidUtilities.getPhotoSize();
}
if (photoHeight > AndroidUtilities.getPhotoSize()) {
photoHeight = AndroidUtilities.getPhotoSize();
}
} else if (drawAvatar) {
photoWidth -= AndroidUtilities.dp(52);
}
boolean needQualityPreview = false;
if (messageObject.type == MessageObject.TYPE_PHOTO) {
// photo
updateSecretTimeText(messageObject);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
} else if (messageObject.type == MessageObject.TYPE_VIDEO || messageObject.type == 8) {
// video, gif
createDocumentLayout(0, messageObject);
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
updateSecretTimeText(messageObject);
needQualityPreview = true;
} else if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
currentPhotoObjectThumb = FileLoader.getClosestPhotoSizeWithSize(messageObject.photoThumbs, 40);
needQualityPreview = true;
}
if (currentMessageObject.strippedThumb != null) {
currentPhotoObjectThumb = null;
currentPhotoObjectThumbStripped = currentMessageObject.strippedThumb;
}
int w;
int h;
if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
if (isPlayingRound) {
w = h = AndroidUtilities.roundPlayingMessageSize;
} else {
w = h = AndroidUtilities.roundMessageSize;
}
} else {
TLRPC.PhotoSize size = currentPhotoObject != null ? currentPhotoObject : currentPhotoObjectThumb;
int imageW = 0;
int imageH = 0;
if (size != null && !(size instanceof TLRPC.TL_photoStrippedSize)) {
imageW = size.w;
imageH = size.h;
} else if (documentAttach != null) {
for (int a = 0, N = documentAttach.attributes.size(); a < N; a++) {
TLRPC.DocumentAttribute attribute = documentAttach.attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeVideo) {
imageW = attribute.w;
imageH = attribute.h;
}
}
}
Point point = getMessageSize(imageW, imageH, photoWidth, photoHeight);
w = (int) point.x;
h = (int) point.y;
}
if (currentPhotoObject != null && "s".equals(currentPhotoObject.type)) {
currentPhotoObject = null;
}
if (currentPhotoObject != null && currentPhotoObject == currentPhotoObjectThumb) {
if (messageObject.type == MessageObject.TYPE_PHOTO) {
currentPhotoObjectThumb = null;
currentPhotoObjectThumbStripped = null;
} else {
currentPhotoObject = null;
}
}
if (needQualityPreview) {
if (!messageObject.needDrawBluredPreview() && (currentPhotoObject == null || currentPhotoObject == currentPhotoObjectThumb) && (currentPhotoObjectThumb == null || !"m".equals(currentPhotoObjectThumb.type))) {
photoImage.setNeedsQualityThumb(true);
photoImage.setShouldGenerateQualityThumb(true);
}
}
if (currentMessagesGroup == null && messageObject.caption != null) {
mediaBackground = false;
}
if ((w == 0 || h == 0) && messageObject.type == 8) {
for (int a = 0; a < messageObject.getDocument().attributes.size(); a++) {
TLRPC.DocumentAttribute attribute = messageObject.getDocument().attributes.get(a);
if (attribute instanceof TLRPC.TL_documentAttributeImageSize || attribute instanceof TLRPC.TL_documentAttributeVideo) {
float scale = (float) attribute.w / (float) photoWidth;
w = (int) (attribute.w / scale);
h = (int) (attribute.h / scale);
if (h > photoHeight) {
float scale2 = h;
h = photoHeight;
scale2 /= h;
w = (int) (w / scale2);
} else if (h < AndroidUtilities.dp(120)) {
h = AndroidUtilities.dp(120);
float hScale = (float) attribute.h / h;
if (attribute.w / hScale < photoWidth) {
w = (int) (attribute.w / hScale);
}
}
break;
}
}
}
if (w == 0 || h == 0) {
w = h = AndroidUtilities.dp(150);
}
if (messageObject.type == MessageObject.TYPE_VIDEO) {
if (w < infoWidth + AndroidUtilities.dp(16 + 24)) {
w = infoWidth + AndroidUtilities.dp(16 + 24);
}
}
if (commentLayout != null && drawSideButton != 3 && w < totalCommentWidth + AndroidUtilities.dp(10)) {
w = totalCommentWidth + AndroidUtilities.dp(10);
}
if (currentMessagesGroup != null) {
int firstLineWidth = 0;
int dWidth = getGroupPhotosWidth();
for (int a = 0; a < currentMessagesGroup.posArray.size(); a++) {
MessageObject.GroupedMessagePosition position = currentMessagesGroup.posArray.get(a);
if (position.minY == 0) {
firstLineWidth += Math.ceil((position.pw + position.leftSpanOffset) / 1000.0f * dWidth);
} else {
break;
}
}
availableTimeWidth = firstLineWidth - AndroidUtilities.dp(35);
} else {
availableTimeWidth = photoWidth - AndroidUtilities.dp(14);
}
if (messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
availableTimeWidth = (int) (AndroidUtilities.roundMessageSize - Math.ceil(Theme.chat_audioTimePaint.measureText("00:00")) - AndroidUtilities.dp(46));
}
measureTime(messageObject);
int timeWidthTotal = timeWidth + AndroidUtilities.dp((SharedConfig.bubbleRadius >= 10 ? 22 : 18) + (messageObject.isOutOwner() ? 20 : 0));
if (w < timeWidthTotal) {
w = timeWidthTotal;
}
if (messageObject.isRoundVideo()) {
w = h = Math.min(w, h);
drawBackground = false;
photoImage.setRoundRadius(w / 2);
canChangeRadius = false;
} else if (messageObject.needDrawBluredPreview()) {
if (AndroidUtilities.isTablet()) {
w = h = (int) (AndroidUtilities.getMinTabletSide() * 0.5f);
} else {
w = h = (int) (Math.min(getParentWidth(), AndroidUtilities.displaySize.y) * 0.5f);
}
}
int widthForCaption = 0;
boolean fixPhotoWidth = false;
if (currentMessagesGroup != null) {
float maxHeight = Math.max(getParentWidth(), AndroidUtilities.displaySize.y) * 0.5f;
int dWidth = getGroupPhotosWidth();
w = (int) Math.ceil(currentPosition.pw / 1000.0f * dWidth);
if (currentPosition.minY != 0 && (messageObject.isOutOwner() && (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0 || !messageObject.isOutOwner() && (currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0)) {
int firstLineWidth = 0;
int currentLineWidth = 0;
for (int a = 0; a < currentMessagesGroup.posArray.size(); a++) {
MessageObject.GroupedMessagePosition position = currentMessagesGroup.posArray.get(a);
if (position.minY == 0) {
firstLineWidth += Math.ceil(position.pw / 1000.0f * dWidth) + (position.leftSpanOffset != 0 ? Math.ceil(position.leftSpanOffset / 1000.0f * dWidth) : 0);
} else if (position.minY == currentPosition.minY) {
currentLineWidth += Math.ceil((position.pw) / 1000.0f * dWidth) + (position.leftSpanOffset != 0 ? Math.ceil(position.leftSpanOffset / 1000.0f * dWidth) : 0);
} else if (position.minY > currentPosition.minY) {
break;
}
}
w += firstLineWidth - currentLineWidth;
}
w -= AndroidUtilities.dp(9);
if (isAvatarVisible) {
w -= AndroidUtilities.dp(48);
}
if (currentPosition.siblingHeights != null) {
h = 0;
for (int a = 0; a < currentPosition.siblingHeights.length; a++) {
h += (int) Math.ceil(maxHeight * currentPosition.siblingHeights[a]);
}
// TODO fix
h += (currentPosition.maxY - currentPosition.minY) * Math.round(7 * AndroidUtilities.density);
} else {
h = (int) Math.ceil(maxHeight * currentPosition.ph);
}
backgroundWidth = w;
if ((currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0 && (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0) {
w -= AndroidUtilities.dp(8);
} else if ((currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) == 0 && (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) == 0) {
w -= AndroidUtilities.dp(11);
} else if ((currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0) {
w -= AndroidUtilities.dp(10);
} else {
w -= AndroidUtilities.dp(9);
}
photoWidth = w;
if (!currentPosition.edge) {
photoWidth += AndroidUtilities.dp(10);
}
photoHeight = h;
widthForCaption += photoWidth - AndroidUtilities.dp(10);
if ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0 || currentMessagesGroup.hasSibling && (currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0) {
widthForCaption += getAdditionalWidthForPosition(currentPosition);
int count = currentMessagesGroup.messages.size();
for (int i = 0; i < count; i++) {
MessageObject m = currentMessagesGroup.messages.get(i);
MessageObject.GroupedMessagePosition rowPosition = currentMessagesGroup.posArray.get(i);
if (rowPosition != currentPosition && (rowPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0) {
w = (int) Math.ceil(rowPosition.pw / 1000.0f * dWidth);
if (rowPosition.minY != 0 && (messageObject.isOutOwner() && (rowPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0 || !messageObject.isOutOwner() && (rowPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0)) {
int firstLineWidth = 0;
int currentLineWidth = 0;
for (int a = 0; a < currentMessagesGroup.posArray.size(); a++) {
MessageObject.GroupedMessagePosition position = currentMessagesGroup.posArray.get(a);
if (position.minY == 0) {
firstLineWidth += Math.ceil(position.pw / 1000.0f * dWidth) + (position.leftSpanOffset != 0 ? Math.ceil(position.leftSpanOffset / 1000.0f * dWidth) : 0);
} else if (position.minY == rowPosition.minY) {
currentLineWidth += Math.ceil((position.pw) / 1000.0f * dWidth) + (position.leftSpanOffset != 0 ? Math.ceil(position.leftSpanOffset / 1000.0f * dWidth) : 0);
} else if (position.minY > rowPosition.minY) {
break;
}
}
w += firstLineWidth - currentLineWidth;
}
w -= AndroidUtilities.dp(9);
if ((rowPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0 && (rowPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0) {
w -= AndroidUtilities.dp(8);
} else if ((rowPosition.flags & MessageObject.POSITION_FLAG_RIGHT) == 0 && (rowPosition.flags & MessageObject.POSITION_FLAG_LEFT) == 0) {
w -= AndroidUtilities.dp(11);
} else if ((rowPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0) {
w -= AndroidUtilities.dp(10);
} else {
w -= AndroidUtilities.dp(9);
}
if (isChat && !isThreadPost && !m.isOutOwner() && m.needDrawAvatar() && (rowPosition == null || rowPosition.edge)) {
w -= AndroidUtilities.dp(48);
}
w += getAdditionalWidthForPosition(rowPosition);
if (!rowPosition.edge) {
w += AndroidUtilities.dp(10);
}
widthForCaption += w;
if (rowPosition.minX < currentPosition.minX || currentMessagesGroup.hasSibling && rowPosition.minY != rowPosition.maxY) {
captionOffsetX -= w;
}
}
if (m.caption != null) {
if (currentCaption != null) {
currentCaption = null;
break;
} else {
currentCaption = m.caption;
}
}
}
}
} else {
photoHeight = h;
photoWidth = w;
currentCaption = messageObject.caption;
int minCaptionWidth;
if (AndroidUtilities.isTablet()) {
minCaptionWidth = (int) (AndroidUtilities.getMinTabletSide() * 0.65f);
} else {
minCaptionWidth = (int) (Math.min(getParentWidth(), AndroidUtilities.displaySize.y) * 0.65f);
}
if (!messageObject.needDrawBluredPreview() && (currentCaption != null || (!reactionsLayoutInBubble.isEmpty && !reactionsLayoutInBubble.isSmall)) && photoWidth < minCaptionWidth) {
widthForCaption = minCaptionWidth;
fixPhotoWidth = true;
} else {
widthForCaption = photoWidth - AndroidUtilities.dp(10);
}
backgroundWidth = photoWidth + AndroidUtilities.dp(8);
if (!mediaBackground) {
backgroundWidth += AndroidUtilities.dp(9);
}
}
if (currentCaption != null) {
try {
widthForCaption -= getExtraTextX() * 2;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
captionLayout = StaticLayout.Builder.obtain(currentCaption, 0, currentCaption.length(), Theme.chat_msgTextPaint, widthForCaption).setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY).setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
} else {
captionLayout = new StaticLayout(currentCaption, Theme.chat_msgTextPaint, widthForCaption, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
updateCaptionSpoilers();
int lineCount = captionLayout.getLineCount();
if (lineCount > 0) {
if (fixPhotoWidth) {
captionWidth = 0;
for (int a = 0; a < lineCount; a++) {
captionWidth = (int) Math.max(captionWidth, Math.ceil(captionLayout.getLineWidth(a)));
if (captionLayout.getLineLeft(a) != 0) {
captionWidth = widthForCaption;
break;
}
}
if (captionWidth > widthForCaption) {
captionWidth = widthForCaption;
}
} else {
captionWidth = widthForCaption;
}
captionHeight = captionLayout.getHeight();
addedCaptionHeight = captionHeight + AndroidUtilities.dp(9);
if (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0) {
additionHeight += addedCaptionHeight;
int widthToCheck = Math.max(captionWidth, photoWidth - AndroidUtilities.dp(10));
float lastLineWidth = captionLayout.getLineWidth(captionLayout.getLineCount() - 1) + captionLayout.getLineLeft(captionLayout.getLineCount() - 1);
if ((reactionsLayoutInBubble.isEmpty || reactionsLayoutInBubble.isSmall) && !shouldDrawTimeOnMedia() && widthToCheck + AndroidUtilities.dp(2) - lastLineWidth < timeWidthTotal + getExtraTimeX()) {
additionHeight += AndroidUtilities.dp(14);
addedCaptionHeight += AndroidUtilities.dp(14);
captionNewLine = 1;
}
} else {
captionLayout = null;
updateCaptionSpoilers();
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
if (!reactionsLayoutInBubble.isSmall) {
boolean useBackgroundWidth = backgroundWidth - AndroidUtilities.dp(24) > widthForCaption;
int maxWidth = Math.max(backgroundWidth - AndroidUtilities.dp(36), widthForCaption);
reactionsLayoutInBubble.measure(maxWidth);
if (!reactionsLayoutInBubble.isEmpty) {
if (shouldDrawTimeOnMedia()) {
reactionsLayoutInBubble.drawServiceShaderBackground = true;
}
int heightLocal = reactionsLayoutInBubble.height;
if (captionLayout == null) {
heightLocal += AndroidUtilities.dp(12);
heightLocal += AndroidUtilities.dp(4);
} else {
heightLocal += AndroidUtilities.dp(12);
reactionsLayoutInBubble.positionOffsetY += AndroidUtilities.dp(12);
}
reactionsLayoutInBubble.totalHeight = heightLocal;
additionHeight += reactionsLayoutInBubble.totalHeight;
if (!shouldDrawTimeOnMedia()) {
int widthToCheck = Math.min(maxWidth, reactionsLayoutInBubble.width + timeWidthTotal + getExtraTimeX() + AndroidUtilities.dp(2));
float lastLineWidth = reactionsLayoutInBubble.lastLineX;
if (!shouldDrawTimeOnMedia() && widthToCheck - lastLineWidth < timeWidthTotal + getExtraTimeX()) {
additionHeight += AndroidUtilities.dp(14);
reactionsLayoutInBubble.totalHeight += AndroidUtilities.dp(14);
reactionsLayoutInBubble.positionOffsetY -= AndroidUtilities.dp(14);
captionNewLine = 1;
if (!useBackgroundWidth && captionWidth < reactionsLayoutInBubble.width) {
captionWidth = reactionsLayoutInBubble.width;
}
} else if (!useBackgroundWidth) {
if (reactionsLayoutInBubble.lastLineX + timeWidthTotal > captionWidth) {
captionWidth = reactionsLayoutInBubble.lastLineX + timeWidthTotal;
}
if (reactionsLayoutInBubble.width > captionWidth) {
captionWidth = reactionsLayoutInBubble.width;
}
}
}
}
}
int minWidth = (int) (Theme.chat_infoPaint.measureText("100%") + AndroidUtilities.dp(100));
if (currentMessagesGroup == null && (documentAttachType == DOCUMENT_ATTACH_TYPE_VIDEO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) && photoWidth < minWidth) {
photoWidth = minWidth;
backgroundWidth = photoWidth + AndroidUtilities.dp(8);
if (!mediaBackground) {
backgroundWidth += AndroidUtilities.dp(9);
}
}
if (fixPhotoWidth && photoWidth < captionWidth + AndroidUtilities.dp(10)) {
photoWidth = captionWidth + AndroidUtilities.dp(10);
backgroundWidth = photoWidth + AndroidUtilities.dp(8);
if (!mediaBackground) {
backgroundWidth += AndroidUtilities.dp(9);
}
}
if (messageChanged || messageIdChanged || dataChanged) {
currentPhotoFilter = currentPhotoFilterThumb = String.format(Locale.US, "%d_%d", (int) (w / AndroidUtilities.density), (int) (h / AndroidUtilities.density));
if (messageObject.photoThumbs != null && messageObject.photoThumbs.size() > 1 || messageObject.type == MessageObject.TYPE_VIDEO || messageObject.type == 8 || messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
if (messageObject.needDrawBluredPreview()) {
currentPhotoFilter += "_b2";
currentPhotoFilterThumb += "_b2";
} else {
currentPhotoFilterThumb += "_b";
}
}
} else {
String filterNew = String.format(Locale.US, "%d_%d", (int) (w / AndroidUtilities.density), (int) (h / AndroidUtilities.density));
if (!messageObject.needDrawBluredPreview() && !filterNew.equals(currentPhotoFilter)) {
ImageLocation location = ImageLocation.getForObject(currentPhotoObject, photoParentObject);
if (location != null) {
String key = location.getKey(photoParentObject, null, false) + "@" + currentPhotoFilter;
if (ImageLoader.getInstance().isInMemCache(key, false)) {
currentPhotoObjectThumb = currentPhotoObject;
currentPhotoFilterThumb = currentPhotoFilter;
currentPhotoFilter = filterNew;
}
}
}
}
boolean noSize = false;
if (messageObject.type == MessageObject.TYPE_VIDEO || messageObject.type == 8 || messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
noSize = true;
}
if (currentPhotoObject != null && !noSize && currentPhotoObject.size == 0) {
currentPhotoObject.size = -1;
}
if (currentPhotoObjectThumb != null && !noSize && currentPhotoObjectThumb.size == 0) {
currentPhotoObjectThumb.size = -1;
}
if (SharedConfig.autoplayVideo && messageObject.type == MessageObject.TYPE_VIDEO && !messageObject.needDrawBluredPreview() && (currentMessageObject.mediaExists || messageObject.canStreamVideo() && DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject))) {
if (currentPosition != null) {
autoPlayingMedia = (currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) != 0 && (currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) != 0;
} else {
autoPlayingMedia = true;
}
}
if (autoPlayingMedia) {
photoImage.setAllowStartAnimation(true);
photoImage.startAnimation();
TLRPC.Document document = messageObject.getDocument();
if (currentMessageObject.videoEditedInfo != null && currentMessageObject.videoEditedInfo.canAutoPlaySourceVideo()) {
photoImage.setImage(ImageLocation.getForPath(currentMessageObject.videoEditedInfo.originalPath), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObjectThumb, document), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, messageObject.getDocument().size, null, messageObject, 0);
photoImage.setMediaStartEndTime(currentMessageObject.videoEditedInfo.startTime / 1000, currentMessageObject.videoEditedInfo.endTime / 1000);
} else {
if (!messageIdChanged && !dataChanged) {
photoImage.setCrossfadeWithOldImage(true);
}
photoImage.setImage(ImageLocation.getForDocument(document), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForDocument(currentPhotoObjectThumb, document), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, messageObject.getDocument().size, null, messageObject, 0);
}
} else if (messageObject.type == MessageObject.TYPE_PHOTO) {
if (messageObject.useCustomPhoto) {
photoImage.setImageBitmap(getResources().getDrawable(R.drawable.theme_preview_image));
} else {
if (currentPhotoObject != null) {
boolean photoExist = true;
String fileName = FileLoader.getAttachFileName(currentPhotoObject);
if (messageObject.mediaExists) {
DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
} else {
photoExist = false;
}
if (photoExist || !currentMessageObject.loadingCancelled && DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject) || FileLoader.getInstance(currentAccount).isLoadingFile(fileName)) {
photoImage.setImage(ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, currentPhotoObject.size, null, currentMessageObject, currentMessageObject.shouldEncryptPhotoOrVideo() ? 2 : 0);
} else {
photoNotSet = true;
if (currentPhotoObjectThumb != null || currentPhotoObjectThumbStripped != null) {
photoImage.setImage(null, null, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, currentMessageObject, currentMessageObject.shouldEncryptPhotoOrVideo() ? 2 : 0);
} else {
photoImage.setImageBitmap((Drawable) null);
}
}
} else {
photoImage.setImageBitmap((Drawable) null);
}
}
} else if (messageObject.type == 8 || messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
String fileName = FileLoader.getAttachFileName(messageObject.getDocument());
int localFile = 0;
if (messageObject.attachPathExists) {
DownloadController.getInstance(currentAccount).removeLoadingFileObserver(this);
localFile = 1;
} else if (messageObject.mediaExists) {
localFile = 2;
}
boolean autoDownload = false;
TLRPC.Document document = messageObject.getDocument();
if (MessageObject.isGifDocument(document, messageObject.hasValidGroupId()) || messageObject.type == MessageObject.TYPE_ROUND_VIDEO) {
autoDownload = DownloadController.getInstance(currentAccount).canDownloadMedia(currentMessageObject);
}
TLRPC.VideoSize videoSize = MessageObject.getDocumentVideoThumb(document);
if (((MessageObject.isGifDocument(document, messageObject.hasValidGroupId()) && messageObject.videoEditedInfo == null) || (!messageObject.isSending() && !messageObject.isEditing())) && (localFile != 0 || FileLoader.getInstance(currentAccount).isLoadingFile(fileName) || autoDownload)) {
if (localFile != 1 && !messageObject.needDrawBluredPreview() && (localFile != 0 || messageObject.canStreamVideo() && autoDownload)) {
autoPlayingMedia = true;
if (!messageIdChanged) {
photoImage.setCrossfadeWithOldImage(true);
photoImage.setCrossfadeDuration(250);
}
if (localFile == 0 && videoSize != null && (currentPhotoObject == null || currentPhotoObjectThumb == null)) {
photoImage.setImage(ImageLocation.getForDocument(document), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForDocument(videoSize, documentAttach), null, ImageLocation.getForDocument(currentPhotoObject != null ? currentPhotoObject : currentPhotoObjectThumb, documentAttach), currentPhotoObject != null ? currentPhotoFilter : currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
} else {
if (isRoundVideo && !messageIdChanged && photoImage.hasStaticThumb()) {
photoImage.setImage(ImageLocation.getForDocument(document), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, null, null, photoImage.getStaticThumb(), document.size, null, messageObject, 0);
} else {
photoImage.setImage(ImageLocation.getForDocument(document), ImageLoader.AUTOPLAY_FILTER, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
}
}
} else if (localFile == 1) {
photoImage.setImage(ImageLocation.getForPath(messageObject.isSendError() ? null : messageObject.messageOwner.attachPath), null, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
} else {
if (videoSize != null && (currentPhotoObject == null || currentPhotoObjectThumb == null)) {
photoImage.setImage(ImageLocation.getForDocument(document), null, ImageLocation.getForDocument(videoSize, documentAttach), null, ImageLocation.getForDocument(currentPhotoObject != null ? currentPhotoObject : currentPhotoObjectThumb, documentAttach), currentPhotoObject != null ? currentPhotoFilter : currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
} else {
photoImage.setImage(ImageLocation.getForDocument(document), null, ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, document.size, null, messageObject, 0);
}
}
} else {
if (messageObject.videoEditedInfo != null && messageObject.type == MessageObject.TYPE_ROUND_VIDEO && !currentMessageObject.needDrawBluredPreview()) {
photoImage.setImage(ImageLocation.getForPath(messageObject.videoEditedInfo.originalPath), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
photoImage.setMediaStartEndTime(currentMessageObject.videoEditedInfo.startTime / 1000, currentMessageObject.videoEditedInfo.endTime / 1000);
} else {
if (!messageIdChanged && !currentMessageObject.needDrawBluredPreview()) {
photoImage.setCrossfadeWithOldImage(true);
photoImage.setCrossfadeDuration(250);
}
photoImage.setImage(ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, 0);
}
}
} else {
if (messageObject.videoEditedInfo != null && messageObject.type == MessageObject.TYPE_ROUND_VIDEO && !currentMessageObject.needDrawBluredPreview()) {
photoImage.setImage(ImageLocation.getForPath(messageObject.videoEditedInfo.originalPath), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, currentMessageObject.shouldEncryptPhotoOrVideo() ? 2 : 0);
photoImage.setMediaStartEndTime(currentMessageObject.videoEditedInfo.startTime / 1000, currentMessageObject.videoEditedInfo.endTime / 1000);
} else {
if (!messageIdChanged && !currentMessageObject.needDrawBluredPreview()) {
photoImage.setCrossfadeWithOldImage(true);
photoImage.setCrossfadeDuration(250);
}
photoImage.setImage(ImageLocation.getForObject(currentPhotoObject, photoParentObject), currentPhotoFilter, ImageLocation.getForObject(currentPhotoObjectThumb, photoParentObject), currentPhotoFilterThumb, currentPhotoObjectThumbStripped, 0, null, messageObject, currentMessageObject.shouldEncryptPhotoOrVideo() ? 2 : 0);
}
}
}
setMessageObjectInternal(messageObject);
if (drawForwardedName && messageObject.needDrawForwarded() && (currentPosition == null || currentPosition.minY == 0)) {
if (messageObject.type != 5) {
namesOffset += AndroidUtilities.dp(5);
}
} else if (drawNameLayout && (messageObject.getReplyMsgId() == 0 || isThreadChat && messageObject.getReplyTopMsgId() == 0)) {
namesOffset += AndroidUtilities.dp(7);
}
totalHeight = photoHeight + AndroidUtilities.dp(14) + namesOffset + additionHeight;
if (currentPosition != null && (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0 && !currentMessageObject.isDocument()) {
totalHeight -= AndroidUtilities.dp(3);
}
if (currentMessageObject.isDice()) {
totalHeight += AndroidUtilities.dp(21);
additionalTimeOffsetY = AndroidUtilities.dp(21);
}
int additionalTop = 0;
if (currentPosition != null && !currentMessageObject.isDocument()) {
photoWidth += getAdditionalWidthForPosition(currentPosition);
if ((currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0) {
photoHeight += AndroidUtilities.dp(4);
additionalTop -= AndroidUtilities.dp(4);
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0) {
photoHeight += AndroidUtilities.dp(1);
}
}
if (drawPinnedTop) {
namesOffset -= AndroidUtilities.dp(1);
}
int y;
if (namesOffset > 0) {
y = AndroidUtilities.dp(7);
totalHeight -= AndroidUtilities.dp(2);
} else {
y = AndroidUtilities.dp(5);
totalHeight -= AndroidUtilities.dp(4);
}
if (currentPosition != null && currentMessagesGroup.isDocuments && currentMessagesGroup.messages.size() > 1) {
if ((currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0) {
totalHeight -= AndroidUtilities.dp(drawPhotoImage ? 3 : 6);
mediaOffsetY -= AndroidUtilities.dp(drawPhotoImage ? 3 : 6);
y -= AndroidUtilities.dp(drawPhotoImage ? 3 : 6);
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0) {
totalHeight -= AndroidUtilities.dp(drawPhotoImage ? 3 : 6);
}
}
photoImage.setImageCoords(0, y + namesOffset + additionalTop, photoWidth, photoHeight);
invalidate();
}
//
if ((currentPosition == null || currentMessageObject.isMusic() || currentMessageObject.isDocument()) && !messageObject.isAnyKindOfSticker() && addedCaptionHeight == 0) {
if (!messageObject.isRestrictedMessage && captionLayout == null && messageObject.caption != null) {
try {
currentCaption = messageObject.caption;
int width = backgroundWidth - AndroidUtilities.dp(31);
int widthForCaption = width - AndroidUtilities.dp(10) - getExtraTextX() * 2;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
captionLayout = StaticLayout.Builder.obtain(messageObject.caption, 0, messageObject.caption.length(), Theme.chat_msgTextPaint, widthForCaption).setBreakStrategy(StaticLayout.BREAK_STRATEGY_HIGH_QUALITY).setHyphenationFrequency(StaticLayout.HYPHENATION_FREQUENCY_NONE).setAlignment(Layout.Alignment.ALIGN_NORMAL).build();
} else {
captionLayout = new StaticLayout(messageObject.caption, Theme.chat_msgTextPaint, widthForCaption, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
}
updateCaptionSpoilers();
} catch (Exception e) {
FileLog.e(e);
}
}
if (captionLayout != null) {
try {
int width = backgroundWidth - AndroidUtilities.dp(31);
if (captionLayout != null && captionLayout.getLineCount() > 0) {
captionWidth = width;
captionHeight = captionLayout.getHeight();
totalHeight += captionHeight + AndroidUtilities.dp(9);
if ((reactionsLayoutInBubble.isEmpty || reactionsLayoutInBubble.isSmall) && (currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0)) {
int timeWidthTotal = timeWidth + (messageObject.isOutOwner() ? AndroidUtilities.dp(20) : 0) + getExtraTimeX();
float lastLineWidth = captionLayout.getLineWidth(captionLayout.getLineCount() - 1) + captionLayout.getLineLeft(captionLayout.getLineCount() - 1);
if (width - AndroidUtilities.dp(8) - lastLineWidth < timeWidthTotal) {
totalHeight += AndroidUtilities.dp(14);
captionHeight += AndroidUtilities.dp(14);
captionNewLine = 2;
}
}
}
} catch (Exception e) {
FileLog.e(e);
}
}
}
if ((currentPosition == null || (currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) != 0) && captionLayout == null && widthBeforeNewTimeLine != -1 && availableTimeWidth - widthBeforeNewTimeLine < timeWidth) {
totalHeight += AndroidUtilities.dp(14);
}
if (currentMessageObject.eventId != 0 && !currentMessageObject.isMediaEmpty() && currentMessageObject.messageOwner.media.webpage != null) {
int linkPreviewMaxWidth = backgroundWidth - AndroidUtilities.dp(41);
hasOldCaptionPreview = true;
linkPreviewHeight = 0;
TLRPC.WebPage webPage = currentMessageObject.messageOwner.media.webpage;
try {
int width = siteNameWidth = (int) Math.ceil(Theme.chat_replyNamePaint.measureText(webPage.site_name) + 1);
siteNameLayout = new StaticLayout(webPage.site_name, Theme.chat_replyNamePaint, Math.min(width, linkPreviewMaxWidth), Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);
siteNameRtl = siteNameLayout.getLineLeft(0) != 0;
int height = siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
} catch (Exception e) {
FileLog.e(e);
}
try {
descriptionX = 0;
if (linkPreviewHeight != 0) {
totalHeight += AndroidUtilities.dp(2);
}
descriptionLayout = StaticLayoutEx.createStaticLayout(webPage.description, Theme.chat_replyTextPaint, linkPreviewMaxWidth, Layout.Alignment.ALIGN_NORMAL, 1.0f, AndroidUtilities.dp(1), false, TextUtils.TruncateAt.END, linkPreviewMaxWidth, 6);
int height = descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
linkPreviewHeight += height;
totalHeight += height;
boolean hasNonRtl = false;
for (int a = 0; a < descriptionLayout.getLineCount(); a++) {
int lineLeft = (int) Math.ceil(descriptionLayout.getLineLeft(a));
if (lineLeft != 0) {
if (descriptionX == 0) {
descriptionX = -lineLeft;
} else {
descriptionX = Math.max(descriptionX, -lineLeft);
}
} else {
hasNonRtl = true;
}
}
if (hasNonRtl) {
descriptionX = 0;
}
} catch (Exception e) {
FileLog.e(e);
}
if (messageObject.type == MessageObject.TYPE_PHOTO || messageObject.type == MessageObject.TYPE_VIDEO) {
totalHeight += AndroidUtilities.dp(6);
}
totalHeight += AndroidUtilities.dp(17);
if (captionNewLine != 0) {
totalHeight -= AndroidUtilities.dp(14);
if (captionNewLine == 2) {
captionHeight -= AndroidUtilities.dp(14);
}
}
}
if (messageObject.isSponsored()) {
drawInstantView = true;
if (messageObject.sponsoredChannelPost != 0) {
drawInstantViewType = 12;
} else {
drawInstantViewType = 1;
}
long id = MessageObject.getPeerId(messageObject.messageOwner.from_id);
if (id > 0) {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(id);
if (user != null && user.bot) {
drawInstantViewType = 10;
}
}
createInstantViewButton();
}
botButtons.clear();
if (messageIdChanged) {
botButtonsByData.clear();
botButtonsByPosition.clear();
botButtonsLayout = null;
}
if (!messageObject.isRestrictedMessage && currentPosition == null && (messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup)) {
int rows;
if (messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup) {
rows = messageObject.messageOwner.reply_markup.rows.size();
} else {
rows = 1;
}
substractBackgroundHeight = keyboardHeight = AndroidUtilities.dp(44 + 4) * rows + AndroidUtilities.dp(1);
widthForButtons = backgroundWidth - AndroidUtilities.dp(mediaBackground ? 0 : 9);
boolean fullWidth = false;
if (messageObject.wantedBotKeyboardWidth > widthForButtons) {
int maxButtonWidth = -AndroidUtilities.dp(drawAvatar ? 62 : 10);
if (AndroidUtilities.isTablet()) {
maxButtonWidth += AndroidUtilities.getMinTabletSide();
} else {
maxButtonWidth += Math.min(getParentWidth(), AndroidUtilities.displaySize.y) - AndroidUtilities.dp(5);
}
widthForButtons = Math.max(backgroundWidth, Math.min(messageObject.wantedBotKeyboardWidth, maxButtonWidth));
}
int maxButtonsWidth = 0;
HashMap<String, BotButton> oldByData = new HashMap<>(botButtonsByData);
HashMap<String, BotButton> oldByPosition;
if (messageObject.botButtonsLayout != null && botButtonsLayout != null && botButtonsLayout.equals(messageObject.botButtonsLayout.toString())) {
oldByPosition = new HashMap<>(botButtonsByPosition);
} else {
if (messageObject.botButtonsLayout != null) {
botButtonsLayout = messageObject.botButtonsLayout.toString();
}
oldByPosition = null;
}
botButtonsByData.clear();
if (messageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyInlineMarkup) {
for (int a = 0; a < rows; a++) {
TLRPC.TL_keyboardButtonRow row = messageObject.messageOwner.reply_markup.rows.get(a);
int buttonsCount = row.buttons.size();
if (buttonsCount == 0) {
continue;
}
int buttonWidth = (widthForButtons - AndroidUtilities.dp(5) * (buttonsCount - 1) - AndroidUtilities.dp(2)) / buttonsCount;
for (int b = 0; b < row.buttons.size(); b++) {
BotButton botButton = new BotButton();
botButton.button = row.buttons.get(b);
String key = Utilities.bytesToHex(botButton.button.data);
String position = a + "" + b;
BotButton oldButton;
if (oldByPosition != null) {
oldButton = oldByPosition.get(position);
} else {
oldButton = oldByData.get(key);
}
if (oldButton != null) {
botButton.progressAlpha = oldButton.progressAlpha;
botButton.angle = oldButton.angle;
botButton.lastUpdateTime = oldButton.lastUpdateTime;
} else {
botButton.lastUpdateTime = System.currentTimeMillis();
}
botButtonsByData.put(key, botButton);
botButtonsByPosition.put(position, botButton);
botButton.x = b * (buttonWidth + AndroidUtilities.dp(5));
botButton.y = a * AndroidUtilities.dp(44 + 4) + AndroidUtilities.dp(5);
botButton.width = buttonWidth;
botButton.height = AndroidUtilities.dp(44);
CharSequence buttonText;
TextPaint botButtonPaint = (TextPaint) getThemedPaint(Theme.key_paint_chatBotButton);
if (botButton.button instanceof TLRPC.TL_keyboardButtonBuy && (messageObject.messageOwner.media.flags & 4) != 0) {
buttonText = LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt);
} else {
buttonText = Emoji.replaceEmoji(botButton.button.text, botButtonPaint.getFontMetricsInt(), AndroidUtilities.dp(15), false);
buttonText = TextUtils.ellipsize(buttonText, botButtonPaint, buttonWidth - AndroidUtilities.dp(10), TextUtils.TruncateAt.END);
}
botButton.title = new StaticLayout(buttonText, botButtonPaint, buttonWidth - AndroidUtilities.dp(10), Layout.Alignment.ALIGN_CENTER, 1.0f, 0.0f, false);
botButtons.add(botButton);
if (b == row.buttons.size() - 1) {
maxButtonsWidth = Math.max(maxButtonsWidth, botButton.x + botButton.width);
}
}
}
}
widthForButtons = maxButtonsWidth;
} else {
substractBackgroundHeight = 0;
keyboardHeight = 0;
}
if (drawCommentButton) {
totalHeight += AndroidUtilities.dp(shouldDrawTimeOnMedia() ? 41.3f : 43);
createSelectorDrawable(1);
}
if (drawPinnedBottom && drawPinnedTop) {
totalHeight -= AndroidUtilities.dp(2);
} else if (drawPinnedBottom) {
totalHeight -= AndroidUtilities.dp(1);
} else if (drawPinnedTop && pinnedBottom && currentPosition != null && currentPosition.siblingHeights == null) {
totalHeight -= AndroidUtilities.dp(1);
}
if (messageObject.isAnyKindOfSticker() && totalHeight < AndroidUtilities.dp(70)) {
additionalTimeOffsetY = AndroidUtilities.dp(70) - totalHeight;
totalHeight += additionalTimeOffsetY;
} else if (messageObject.isAnimatedEmoji()) {
additionalTimeOffsetY = AndroidUtilities.dp(16);
totalHeight += AndroidUtilities.dp(16);
}
if (!drawPhotoImage) {
photoImage.setImageBitmap((Drawable) null);
}
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
if (MessageObject.isDocumentHasThumb(documentAttach)) {
TLRPC.PhotoSize thumb = FileLoader.getClosestPhotoSizeWithSize(documentAttach.thumbs, 90);
radialProgress.setImageOverlay(thumb, documentAttach, messageObject);
} else {
String artworkUrl = messageObject.getArtworkUrl(true);
if (!TextUtils.isEmpty(artworkUrl)) {
radialProgress.setImageOverlay(artworkUrl);
} else {
radialProgress.setImageOverlay(null, null, null);
}
}
} else {
radialProgress.setImageOverlay(null, null, null);
}
if (canChangeRadius) {
int tl, tr, bl, br;
int minRad = AndroidUtilities.dp(4);
int rad;
if (SharedConfig.bubbleRadius > 2) {
rad = AndroidUtilities.dp(SharedConfig.bubbleRadius - 2);
} else {
rad = AndroidUtilities.dp(SharedConfig.bubbleRadius);
}
int nearRad = Math.min(AndroidUtilities.dp(3), rad);
tl = tr = bl = br = rad;
if (minRad > tl) {
minRad = tl;
}
if (hasLinkPreview || hasGamePreview || hasInvoicePreview) {
tl = tr = bl = br = minRad;
}
if (forwardedNameLayout[0] != null || replyNameLayout != null || drawNameLayout) {
tl = tr = minRad;
}
if (captionLayout != null || drawCommentButton) {
bl = br = minRad;
}
if (documentAttachType == DOCUMENT_ATTACH_TYPE_DOCUMENT) {
tr = br = minRad;
}
if (currentPosition != null && currentMessagesGroup != null) {
if ((currentPosition.flags & MessageObject.POSITION_FLAG_RIGHT) == 0) {
tr = br = minRad;
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_LEFT) == 0) {
tl = bl = minRad;
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_BOTTOM) == 0) {
bl = br = minRad;
}
if ((currentPosition.flags & MessageObject.POSITION_FLAG_TOP) == 0) {
tl = tr = minRad;
}
}
if (pinnedTop) {
if (currentMessageObject.isOutOwner()) {
tr = nearRad;
} else {
tl = nearRad;
}
}
if (pinnedBottom) {
if (currentMessageObject.isOutOwner()) {
br = nearRad;
} else {
bl = nearRad;
}
}
if (!mediaBackground && !currentMessageObject.isOutOwner()) {
bl = nearRad;
}
photoImage.setRoundRadius(tl, tr, br, bl);
}
}
if (messageIdChanged) {
currentUrl = null;
currentWebFile = null;
lastWebFile = null;
loadingProgressLayout = null;
animatingLoadingProgressProgress = 0;
lastLoadingSizeTotal = 0;
selectedBackgroundProgress = 0f;
if (statusDrawableAnimator != null) {
statusDrawableAnimator.removeAllListeners();
statusDrawableAnimator.cancel();
}
transitionParams.lastStatusDrawableParams = -1;
statusDrawableAnimationInProgress = false;
if (documentAttachType == DOCUMENT_ATTACH_TYPE_MUSIC) {
boolean showSeekbar = MediaController.getInstance().isPlayingMessage(currentMessageObject);
toSeekBarProgress = showSeekbar ? 1f : 0f;
}
seekBarWaveform.setProgress(0);
}
updateWaveform();
updateButtonState(false, dataChanged && !messageObject.cancelEditing, true);
if (!currentMessageObject.loadingCancelled && buttonState == 2 && documentAttachType == DOCUMENT_ATTACH_TYPE_AUDIO && DownloadController.getInstance(currentAccount).canDownloadMedia(messageObject)) {
FileLoader.getInstance(currentAccount).loadFile(documentAttach, currentMessageObject, 1, 0);
buttonState = 4;
radialProgress.setIcon(getIconForCurrentState(), false, false);
}
if (delegate != null && delegate.getTextSelectionHelper() != null && !messageIdChanged && messageChanged && messageObject != null) {
delegate.getTextSelectionHelper().checkDataChanged(messageObject);
}
accessibilityVirtualViewBounds.clear();
transitionParams.updatePhotoImageX = true;
updateFlagSecure();
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatMessageCell method drawLinkPreview.
public void drawLinkPreview(Canvas canvas, float alpha) {
if (!currentMessageObject.isSponsored() && !hasLinkPreview && !hasGamePreview && !hasInvoicePreview) {
return;
}
int startY;
int linkX;
if (hasGamePreview) {
startY = AndroidUtilities.dp(14) + namesOffset;
linkX = unmovedTextX - AndroidUtilities.dp(10);
} else if (hasInvoicePreview) {
startY = AndroidUtilities.dp(14) + namesOffset;
linkX = unmovedTextX + AndroidUtilities.dp(1);
} else if (currentMessageObject.isSponsored()) {
startY = textY + currentMessageObject.textHeight - AndroidUtilities.dp(2);
if (hasNewLineForTime) {
startY += AndroidUtilities.dp(16);
}
linkX = unmovedTextX + AndroidUtilities.dp(1);
} else {
startY = textY + currentMessageObject.textHeight + AndroidUtilities.dp(8);
linkX = unmovedTextX + AndroidUtilities.dp(1);
}
int linkPreviewY = startY;
int smallImageStartY = 0;
if (!hasInvoicePreview && !currentMessageObject.isSponsored()) {
Theme.chat_replyLinePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outPreviewLine : Theme.key_chat_inPreviewLine));
if (alpha != 1f) {
Theme.chat_replyLinePaint.setAlpha((int) (alpha * Theme.chat_replyLinePaint.getAlpha()));
}
canvas.drawRect(linkX, linkPreviewY - AndroidUtilities.dp(3), linkX + AndroidUtilities.dp(2), linkPreviewY + linkPreviewHeight + AndroidUtilities.dp(3), Theme.chat_replyLinePaint);
}
if (siteNameLayout != null) {
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
Theme.chat_replyNamePaint.setColor(getThemedColor(currentMessageObject.isOutOwner() ? Theme.key_chat_outSiteNameText : Theme.key_chat_inSiteNameText));
if (alpha != 1f) {
Theme.chat_replyNamePaint.setAlpha((int) (alpha * Theme.chat_replyLinePaint.getAlpha()));
}
canvas.save();
int x;
if (siteNameRtl) {
x = backgroundWidth - siteNameWidth - AndroidUtilities.dp(32);
if (isSmallImage) {
x -= AndroidUtilities.dp(48 + 6);
}
} else {
x = (hasInvoicePreview ? 0 : AndroidUtilities.dp(10));
}
canvas.translate(linkX + x, linkPreviewY - AndroidUtilities.dp(3));
siteNameLayout.draw(canvas);
canvas.restore();
linkPreviewY += siteNameLayout.getLineBottom(siteNameLayout.getLineCount() - 1);
}
if ((hasGamePreview || hasInvoicePreview) && currentMessageObject.textHeight != 0) {
startY += currentMessageObject.textHeight + AndroidUtilities.dp(4);
linkPreviewY += currentMessageObject.textHeight + AndroidUtilities.dp(4);
}
if (drawPhotoImage && drawInstantView && drawInstantViewType != 9 && drawInstantViewType != 13 && drawInstantViewType != 11 && drawInstantViewType != 1 || drawInstantViewType == 6 && imageBackgroundColor != 0) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (imageBackgroundSideColor != 0) {
int x = linkX + AndroidUtilities.dp(10);
photoImage.setImageCoords(x + (imageBackgroundSideWidth - photoImage.getImageWidth()) / 2, linkPreviewY, photoImage.getImageWidth(), photoImage.getImageHeight());
rect.set(x, photoImage.getImageY(), x + imageBackgroundSideWidth, photoImage.getImageY2());
Theme.chat_instantViewPaint.setColor(ColorUtils.setAlphaComponent(imageBackgroundSideColor, (int) (255 * alpha)));
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), Theme.chat_instantViewPaint);
} else {
photoImage.setImageCoords(linkX + AndroidUtilities.dp(10), linkPreviewY, photoImage.getImageWidth(), photoImage.getImageHeight());
}
if (imageBackgroundColor != 0) {
rect.set(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX2(), photoImage.getImageY2());
if (imageBackgroundGradientColor1 != 0) {
if (imageBackgroundGradientColor2 != 0) {
if (motionBackgroundDrawable == null) {
motionBackgroundDrawable = new MotionBackgroundDrawable(imageBackgroundColor, imageBackgroundGradientColor1, imageBackgroundGradientColor2, imageBackgroundGradientColor3, true);
if (imageBackgroundIntensity < 0) {
photoImage.setGradientBitmap(motionBackgroundDrawable.getBitmap());
}
if (!photoImage.hasImageSet()) {
motionBackgroundDrawable.setRoundRadius(AndroidUtilities.dp(4));
}
}
} else {
if (gradientShader == null) {
Rect r = BackgroundGradientDrawable.getGradientPoints(AndroidUtilities.getWallpaperRotation(imageBackgroundGradientRotation, false), (int) rect.width(), (int) rect.height());
gradientShader = new LinearGradient(r.left, r.top, r.right, r.bottom, new int[] { imageBackgroundColor, imageBackgroundGradientColor1 }, null, Shader.TileMode.CLAMP);
}
Theme.chat_instantViewPaint.setShader(gradientShader);
if (alpha != 1f) {
Theme.chat_instantViewPaint.setAlpha((int) (255 * alpha));
}
}
} else {
Theme.chat_instantViewPaint.setShader(null);
Theme.chat_instantViewPaint.setColor(imageBackgroundColor);
if (alpha != 1f) {
Theme.chat_instantViewPaint.setAlpha((int) (255 * alpha));
}
}
if (motionBackgroundDrawable != null) {
motionBackgroundDrawable.setBounds((int) rect.left, (int) rect.top, (int) rect.right, (int) rect.bottom);
motionBackgroundDrawable.draw(canvas);
} else if (imageBackgroundSideColor != 0) {
canvas.drawRect(photoImage.getImageX(), photoImage.getImageY(), photoImage.getImageX2(), photoImage.getImageY2(), Theme.chat_instantViewPaint);
} else {
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), Theme.chat_instantViewPaint);
}
Theme.chat_instantViewPaint.setShader(null);
Theme.chat_instantViewPaint.setAlpha(255);
}
if (drawPhotoImage && drawInstantView && drawInstantViewType != 9) {
if (drawImageButton) {
int size = AndroidUtilities.dp(48);
buttonX = this.buttonX = (int) (photoImage.getImageX() + (photoImage.getImageWidth() - size) / 2.0f);
buttonY = this.buttonY = (int) (photoImage.getImageY() + (photoImage.getImageHeight() - size) / 2.0f);
radialProgress.setProgressRect((int) buttonX, (int) buttonY, (int) buttonX + size, (int) buttonY + size);
}
if (delegate == null || delegate.getPinchToZoomHelper() == null || !delegate.getPinchToZoomHelper().isInOverlayModeFor(this)) {
if (alpha != 1f) {
photoImage.setAlpha(alpha);
imageDrawn = photoImage.draw(canvas);
photoImage.setAlpha(1f);
} else {
imageDrawn = photoImage.draw(canvas);
}
}
}
linkPreviewY += photoImage.getImageHeight() + AndroidUtilities.dp(6);
}
if (currentMessageObject.isOutOwner()) {
Theme.chat_replyNamePaint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messageTextOut), (int) (255 * alpha)));
Theme.chat_replyTextPaint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messageTextOut), (int) (255 * alpha)));
} else {
Theme.chat_replyNamePaint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messageTextIn), (int) (255 * alpha)));
Theme.chat_replyTextPaint.setColor(ColorUtils.setAlphaComponent(getThemedColor(Theme.key_chat_messageTextIn), (int) (255 * alpha)));
}
if (titleLayout != null) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (smallImageStartY == 0) {
smallImageStartY = linkPreviewY - AndroidUtilities.dp(1);
}
canvas.save();
canvas.translate(linkX + AndroidUtilities.dp(10) + titleX, linkPreviewY - AndroidUtilities.dp(3));
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);
}
canvas.save();
canvas.translate(linkX + AndroidUtilities.dp(10) + authorX, linkPreviewY - AndroidUtilities.dp(3));
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);
}
descriptionY = linkPreviewY - AndroidUtilities.dp(3);
canvas.save();
canvas.translate(linkX + (hasInvoicePreview ? 0 : AndroidUtilities.dp(10)) + descriptionX, descriptionY);
if (pressedLink != null && linkBlockNum == -10) {
for (int b = 0; b < urlPath.size(); b++) {
canvas.drawPath(urlPath.get(b), Theme.chat_urlPaint);
}
}
if (delegate != null && delegate.getTextSelectionHelper() != null && getDelegate().getTextSelectionHelper().isSelected(currentMessageObject)) {
delegate.getTextSelectionHelper().drawDescription(currentMessageObject.isOutOwner(), descriptionLayout, canvas);
}
descriptionLayout.draw(canvas);
canvas.restore();
linkPreviewY += descriptionLayout.getLineBottom(descriptionLayout.getLineCount() - 1);
}
if (drawPhotoImage && (!drawInstantView || drawInstantViewType == 9 || drawInstantViewType == 11 || drawInstantViewType == 13 || drawInstantViewType == 1)) {
if (linkPreviewY != startY) {
linkPreviewY += AndroidUtilities.dp(2);
}
if (isSmallImage) {
photoImage.setImageCoords(linkX + backgroundWidth - AndroidUtilities.dp(81), smallImageStartY, photoImage.getImageWidth(), photoImage.getImageHeight());
} else {
photoImage.setImageCoords(linkX + (hasInvoicePreview ? -AndroidUtilities.dp(6.3f) : AndroidUtilities.dp(10)), linkPreviewY, photoImage.getImageWidth(), photoImage.getImageHeight());
if (drawImageButton) {
int size = AndroidUtilities.dp(48);
buttonX = this.buttonX = (int) (photoImage.getImageX() + (photoImage.getImageWidth() - size) / 2.0f);
buttonY = this.buttonY = (int) (photoImage.getImageY() + (photoImage.getImageHeight() - size) / 2.0f);
radialProgress.setProgressRect((int) buttonX, (int) buttonY, (int) buttonX + size, (int) buttonY + size);
}
}
if (isRoundVideo && MediaController.getInstance().isPlayingMessage(currentMessageObject) && MediaController.getInstance().isVideoDrawingReady() && canvas.isHardwareAccelerated()) {
imageDrawn = true;
drawTime = true;
} else {
if (delegate == null || delegate.getPinchToZoomHelper() == null || !delegate.getPinchToZoomHelper().isInOverlayModeFor(this)) {
if (alpha != 1f) {
photoImage.setAlpha(alpha);
imageDrawn = photoImage.draw(canvas);
photoImage.setAlpha(1f);
} else {
imageDrawn = photoImage.draw(canvas);
}
}
}
}
if (documentAttachType == DOCUMENT_ATTACH_TYPE_VIDEO || documentAttachType == DOCUMENT_ATTACH_TYPE_GIF) {
videoButtonX = (int) (photoImage.getImageX() + AndroidUtilities.dp(8));
videoButtonY = (int) (photoImage.getImageY() + AndroidUtilities.dp(8));
videoRadialProgress.setProgressRect(videoButtonX, videoButtonY, videoButtonX + AndroidUtilities.dp(24), videoButtonY + AndroidUtilities.dp(24));
}
Paint timeBackgroundPaint = getThemedPaint(Theme.key_paint_chatTimeBackground);
if (photosCountLayout != null && photoImage.getVisible()) {
int x = (int) (photoImage.getImageX() + photoImage.getImageWidth() - AndroidUtilities.dp(8) - photosCountWidth);
int y = (int) (photoImage.getImageY() + photoImage.getImageHeight() - AndroidUtilities.dp(19));
rect.set(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + photosCountWidth + AndroidUtilities.dp(4), y + AndroidUtilities.dp(14.5f));
int oldAlpha = timeBackgroundPaint.getAlpha();
timeBackgroundPaint.setAlpha((int) (oldAlpha * controlsAlpha));
Theme.chat_durationPaint.setAlpha((int) (255 * controlsAlpha));
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), timeBackgroundPaint);
timeBackgroundPaint.setAlpha(oldAlpha);
canvas.save();
canvas.translate(x, y);
photosCountLayout.draw(canvas);
canvas.restore();
Theme.chat_durationPaint.setAlpha(255);
}
if (videoInfoLayout != null && (!drawPhotoImage || photoImage.getVisible()) && imageBackgroundSideColor == 0) {
int x;
int y;
if (hasGamePreview || hasInvoicePreview || documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER) {
if (drawPhotoImage) {
x = (int) (photoImage.getImageX() + AndroidUtilities.dp(8.5f));
y = (int) (photoImage.getImageY() + AndroidUtilities.dp(6));
int height = AndroidUtilities.dp(documentAttachType == DOCUMENT_ATTACH_TYPE_WALLPAPER ? 14.5f : 16.5f);
rect.set(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + durationWidth + AndroidUtilities.dp(4), y + height);
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), timeBackgroundPaint);
} else {
x = linkX;
y = linkPreviewY;
}
} else {
x = (int) (photoImage.getImageX() + photoImage.getImageWidth() - AndroidUtilities.dp(8) - durationWidth);
y = (int) (photoImage.getImageY() + photoImage.getImageHeight() - AndroidUtilities.dp(19));
rect.set(x - AndroidUtilities.dp(4), y - AndroidUtilities.dp(1.5f), x + durationWidth + AndroidUtilities.dp(4), y + AndroidUtilities.dp(14.5f));
canvas.drawRoundRect(rect, AndroidUtilities.dp(4), AndroidUtilities.dp(4), getThemedPaint(Theme.key_paint_chatTimeBackground));
}
canvas.save();
canvas.translate(x, y);
if (hasInvoicePreview) {
if (drawPhotoImage) {
Theme.chat_shipmentPaint.setColor(getThemedColor(Theme.key_chat_previewGameText));
} else {
if (currentMessageObject.isOutOwner()) {
Theme.chat_shipmentPaint.setColor(getThemedColor(Theme.key_chat_messageTextOut));
} else {
Theme.chat_shipmentPaint.setColor(getThemedColor(Theme.key_chat_messageTextIn));
}
}
}
videoInfoLayout.draw(canvas);
canvas.restore();
}
if (drawInstantView) {
Drawable instantDrawable;
int instantY = startY + linkPreviewHeight + AndroidUtilities.dp(10);
Paint backPaint = Theme.chat_instantViewRectPaint;
if (currentMessageObject.isOutOwner()) {
instantDrawable = getThemedDrawable(Theme.key_drawable_msgOutInstant);
Theme.chat_instantViewPaint.setColor(getThemedColor(Theme.key_chat_outPreviewInstantText));
backPaint.setColor(getThemedColor(Theme.key_chat_outPreviewInstantText));
} else {
instantDrawable = Theme.chat_msgInInstantDrawable;
Theme.chat_instantViewPaint.setColor(getThemedColor(Theme.key_chat_inPreviewInstantText));
backPaint.setColor(getThemedColor(Theme.key_chat_inPreviewInstantText));
}
instantButtonRect.set(linkX, instantY, linkX + instantWidth, instantY + AndroidUtilities.dp(36));
if (Build.VERSION.SDK_INT >= 21) {
selectorDrawableMaskType[0] = 0;
selectorDrawable[0].setBounds(linkX, instantY, linkX + instantWidth, instantY + AndroidUtilities.dp(36));
selectorDrawable[0].draw(canvas);
}
canvas.drawRoundRect(instantButtonRect, AndroidUtilities.dp(6), AndroidUtilities.dp(6), backPaint);
if (drawInstantViewType == 0) {
setDrawableBounds(instantDrawable, instantTextLeftX + instantTextX + linkX - AndroidUtilities.dp(15), instantY + AndroidUtilities.dp(11.5f), AndroidUtilities.dp(9), AndroidUtilities.dp(13));
instantDrawable.draw(canvas);
}
if (instantViewLayout != null) {
canvas.save();
canvas.translate(linkX + instantTextX, instantY + AndroidUtilities.dp(10.5f));
instantViewLayout.draw(canvas);
canvas.restore();
}
}
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class ThemePreviewMessagesCell method onDraw.
@Override
protected void onDraw(Canvas canvas) {
Drawable newDrawable = Theme.getCachedWallpaperNonBlocking();
if (newDrawable != backgroundDrawable && newDrawable != null) {
if (Theme.isAnimatingColor()) {
oldBackgroundDrawable = backgroundDrawable;
oldBackgroundGradientDisposable = backgroundGradientDisposable;
} else if (backgroundGradientDisposable != null) {
backgroundGradientDisposable.dispose();
backgroundGradientDisposable = null;
}
backgroundDrawable = newDrawable;
}
float themeAnimationValue = parentLayout.getThemeAnimationValue();
for (int a = 0; a < 2; a++) {
Drawable drawable = a == 0 ? oldBackgroundDrawable : backgroundDrawable;
if (drawable == null) {
continue;
}
if (a == 1 && oldBackgroundDrawable != null && parentLayout != null) {
drawable.setAlpha((int) (255 * themeAnimationValue));
} else {
drawable.setAlpha(255);
}
if (drawable instanceof ColorDrawable || drawable instanceof GradientDrawable || drawable instanceof MotionBackgroundDrawable) {
drawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
if (drawable instanceof BackgroundGradientDrawable) {
final BackgroundGradientDrawable backgroundGradientDrawable = (BackgroundGradientDrawable) drawable;
backgroundGradientDisposable = backgroundGradientDrawable.drawExactBoundsSize(canvas, this);
} else {
drawable.draw(canvas);
}
} else if (drawable instanceof BitmapDrawable) {
BitmapDrawable bitmapDrawable = (BitmapDrawable) drawable;
if (bitmapDrawable.getTileModeX() == Shader.TileMode.REPEAT) {
canvas.save();
float scale = 2.0f / AndroidUtilities.density;
canvas.scale(scale, scale);
drawable.setBounds(0, 0, (int) Math.ceil(getMeasuredWidth() / scale), (int) Math.ceil(getMeasuredHeight() / scale));
} else {
int viewHeight = getMeasuredHeight();
float scaleX = (float) getMeasuredWidth() / (float) drawable.getIntrinsicWidth();
float scaleY = (float) (viewHeight) / (float) drawable.getIntrinsicHeight();
float scale = Math.max(scaleX, scaleY);
int width = (int) Math.ceil(drawable.getIntrinsicWidth() * scale);
int height = (int) Math.ceil(drawable.getIntrinsicHeight() * scale);
int x = (getMeasuredWidth() - width) / 2;
int y = (viewHeight - height) / 2;
canvas.save();
canvas.clipRect(0, 0, width, getMeasuredHeight());
drawable.setBounds(x, y, x + width, y + height);
}
drawable.draw(canvas);
canvas.restore();
}
if (a == 0 && oldBackgroundDrawable != null && themeAnimationValue >= 1.0f) {
if (oldBackgroundGradientDisposable != null) {
oldBackgroundGradientDisposable.dispose();
oldBackgroundGradientDisposable = null;
}
oldBackgroundDrawable = null;
invalidate();
}
}
shadowDrawable.setBounds(0, 0, getMeasuredWidth(), getMeasuredHeight());
shadowDrawable.draw(canvas);
}
use of org.telegram.ui.Components.MotionBackgroundDrawable in project Telegram-FOSS by Telegram-FOSS-Team.
the class QrActivity method onItemSelected.
private void onItemSelected(EmojiThemes newTheme, int position, boolean withAnimation) {
selectedPosition = position;
final EmojiThemes prevTheme = currentTheme;
final boolean isDarkTheme = isCurrentThemeDark;
currentTheme = newTheme;
EmojiThemes.ThemeItem themeItem = currentTheme.getThemeItem(isDarkTheme ? 1 : 0);
float duration = 1f;
if (patternAlphaAnimator != null) {
// from = (float) patternAlphaAnimator.getAnimatedValue();
duration *= Math.max(.5f, 1f - (float) patternAlphaAnimator.getAnimatedValue());
patternAlphaAnimator.cancel();
}
prevMotionDrawable = currMotionDrawable;
prevMotionDrawable.setIndeterminateAnimation(false);
prevMotionDrawable.setAlpha(255);
currMotionDrawable = new MotionBackgroundDrawable();
currMotionDrawable.setCallback(backgroundView);
currMotionDrawable.setColors(themeItem.patternBgColor, themeItem.patternBgGradientColor1, themeItem.patternBgGradientColor2, themeItem.patternBgGradientColor3);
currMotionDrawable.setParentView(backgroundView);
currMotionDrawable.setPatternAlpha(1f);
currMotionDrawable.setIndeterminateAnimation(true);
if (prevMotionDrawable != null)
currMotionDrawable.posAnimationProgress = prevMotionDrawable.posAnimationProgress;
qrView.setPosAnimationProgress(currMotionDrawable.posAnimationProgress);
TLRPC.WallPaper wallPaper = currentTheme.getWallpaper(isDarkTheme ? 1 : 0);
if (wallPaper != null) {
currMotionDrawable.setPatternBitmap(wallPaper.settings.intensity);
final long startedLoading = SystemClock.elapsedRealtime();
currentTheme.loadWallpaper(isDarkTheme ? 1 : 0, pair -> {
if (pair != null && currentTheme.getTlTheme(isDarkTheme ? 1 : 0) != null) {
final long themeId = pair.first;
final Bitmap bitmap = pair.second;
if (themeId == currentTheme.getTlTheme(isDarkTheme ? 1 : 0).id && bitmap != null) {
long elapsed = SystemClock.elapsedRealtime() - startedLoading;
onPatternLoaded(bitmap, currMotionDrawable.getIntensity(), elapsed > 150);
}
}
});
} else {
currMotionDrawable.setPatternBitmap(34, SvgHelper.getBitmap(R.raw.default_pattern, backgroundView.getWidth(), backgroundView.getHeight(), Color.BLACK));
}
currMotionDrawable.setPatternColorFilter(currMotionDrawable.getPatternColor());
int[] newQrColors = qrColorsMap.get(newTheme.emoji + (isDarkTheme ? "n" : "d"));
if (withAnimation) {
currMotionDrawable.setAlpha(255);
currMotionDrawable.setBackgroundAlpha(0f);
patternAlphaAnimator = ValueAnimator.ofFloat(0f, 1f);
patternAlphaAnimator.addUpdateListener(animation -> {
float progress = (float) animation.getAnimatedValue();
if (prevMotionDrawable != null) {
prevMotionDrawable.setBackgroundAlpha(1f);
prevMotionDrawable.setPatternAlpha(1f - progress);
}
currMotionDrawable.setBackgroundAlpha(progress);
currMotionDrawable.setPatternAlpha(progress);
// currMotionDrawable.setAlpha((int) (255f * progress));
if (newQrColors != null) {
int color1 = ColorUtils.blendARGB(prevQrColors[0], newQrColors[0], progress);
int color2 = ColorUtils.blendARGB(prevQrColors[1], newQrColors[1], progress);
int color3 = ColorUtils.blendARGB(prevQrColors[2], newQrColors[2], progress);
int color4 = ColorUtils.blendARGB(prevQrColors[3], newQrColors[3], progress);
qrView.setColors(color1, color2, color3, color4);
}
backgroundView.invalidate();
});
patternAlphaAnimator.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
super.onAnimationEnd(animation);
if (newQrColors != null) {
System.arraycopy(newQrColors, 0, prevQrColors, 0, 4);
}
prevMotionDrawable = null;
patternAlphaAnimator = null;
currMotionDrawable.setBackgroundAlpha(1f);
currMotionDrawable.setPatternAlpha(1f);
}
@Override
public void onAnimationCancel(Animator animation) {
super.onAnimationCancel(animation);
float progress = (float) ((ValueAnimator) animation).getAnimatedValue();
if (newQrColors != null) {
int color1 = ColorUtils.blendARGB(prevQrColors[0], newQrColors[0], progress);
int color2 = ColorUtils.blendARGB(prevQrColors[1], newQrColors[1], progress);
int color3 = ColorUtils.blendARGB(prevQrColors[2], newQrColors[2], progress);
int color4 = ColorUtils.blendARGB(prevQrColors[3], newQrColors[3], progress);
int[] colors = new int[] { color1, color2, color3, color4 };
System.arraycopy(colors, 0, prevQrColors, 0, 4);
}
}
});
patternAlphaAnimator.setDuration((int) (250 * duration));
patternAlphaAnimator.start();
} else {
if (newQrColors != null) {
qrView.setColors(newQrColors[0], newQrColors[1], newQrColors[2], newQrColors[3]);
System.arraycopy(newQrColors, 0, prevQrColors, 0, 4);
}
prevMotionDrawable = null;
backgroundView.invalidate();
}
Theme.ThemeInfo currentThemeInfo = isCurrentThemeDark ? Theme.getCurrentNightTheme() : Theme.getCurrentTheme();
ActionBarLayout.ThemeAnimationSettings animationSettings = new ActionBarLayout.ThemeAnimationSettings(null, currentThemeInfo.currentAccentId, isCurrentThemeDark, !withAnimation);
animationSettings.applyTheme = false;
animationSettings.onlyTopFragment = true;
animationSettings.resourcesProvider = getResourceProvider();
animationSettings.duration = (int) (250 * duration);
if (withAnimation) {
resourcesProvider.initColors(prevTheme, isCurrentThemeDark);
} else {
resourcesProvider.initColors(currentTheme, isCurrentThemeDark);
}
animationSettings.afterStartDescriptionsAddedRunnable = () -> {
resourcesProvider.initColors(currentTheme, isCurrentThemeDark);
};
parentLayout.animateThemedValues(animationSettings);
}
Aggregations