use of org.telegram.messenger.ForwardingMessagesParams in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method showFieldPanel.
public void showFieldPanel(boolean show, MessageObject messageObjectToReply, MessageObject messageObjectToEdit, ArrayList<MessageObject> messageObjectsToForward, TLRPC.WebPage webPage, boolean notify, int scheduleDate, boolean cancel, boolean animated) {
if (chatActivityEnterView == null) {
return;
}
boolean showHint = false;
if (show) {
if (messageObjectToReply == null && messageObjectsToForward == null && messageObjectToEdit == null && webPage == null) {
return;
}
hideHints(false);
if (searchItem != null && actionBar.isSearchFieldVisible()) {
actionBar.closeSearchField(false);
chatActivityEnterView.setFieldFocused();
AndroidUtilities.runOnUIThread(() -> {
if (chatActivityEnterView != null) {
chatActivityEnterView.openKeyboard();
}
}, 100);
}
boolean openKeyboard = false;
if (messageObjectToReply != null && messageObjectToReply.getDialogId() != dialog_id) {
messageObjectsToForward = new ArrayList<>();
messageObjectsToForward.add(messageObjectToReply);
messageObjectToReply = null;
openKeyboard = true;
}
chatActivityEnterTopView.setEditMode(false);
if (messageObjectToEdit != null) {
forwardingMessages = null;
if (threadMessageId == 0) {
replyingMessageObject = null;
chatActivityEnterView.setReplyingMessageObject(null);
}
editingMessageObject = messageObjectToEdit;
final boolean mediaEmpty = messageObjectToEdit.isMediaEmpty();
chatActivityEnterView.setEditingMessageObject(messageObjectToEdit, !mediaEmpty);
if (foundWebPage != null) {
return;
}
chatActivityEnterView.setForceShowSendButton(false, false);
final boolean canEditMedia = messageObjectToEdit.canEditMedia();
if (!mediaEmpty && canEditMedia) {
String editButtonText = null;
String replaceButtonText;
if (messageObjectToEdit.isPhoto()) {
editButtonText = LocaleController.getString("EditMessageEditPhoto", R.string.EditMessageEditPhoto);
replaceButtonText = LocaleController.getString("EditMessageReplacePhoto", R.string.EditMessageReplacePhoto);
} else if (messageObjectToEdit.isVideo()) {
editButtonText = LocaleController.getString("EditMessageEditVideo", R.string.EditMessageEditVideo);
replaceButtonText = LocaleController.getString("EditMessageReplaceVideo", R.string.EditMessageReplaceVideo);
} else if (messageObjectToEdit.isGif()) {
replaceButtonText = LocaleController.getString("EditMessageReplaceGif", R.string.EditMessageReplaceGif);
} else if (messageObjectToEdit.isMusic()) {
replaceButtonText = LocaleController.getString("EditMessageReplaceAudio", R.string.EditMessageReplaceAudio);
} else {
replaceButtonText = LocaleController.getString("EditMessageReplaceFile", R.string.EditMessageReplaceFile);
}
final ChatActivityEnterTopView.EditViewButton[] buttons = chatActivityEnterTopView.getEditView().getButtons();
buttons[0].setEditButton(editButtonText != null);
buttons[0].getTextView().setText(editButtonText != null ? editButtonText : replaceButtonText);
buttons[0].getImageView().setImageResource(editButtonText != null ? R.drawable.msg_photoeditor : R.drawable.msg_replace);
buttons[1].setVisibility(editButtonText != null ? View.VISIBLE : View.GONE);
if (editButtonText != null) {
buttons[1].getTextView().setText(replaceButtonText);
}
chatActivityEnterTopView.setEditMode(true);
} else {
replyIconImageView.setImageResource(R.drawable.group_edit);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrEditing", R.string.AccDescrEditing));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelEdit", R.string.AccDescrCancelEdit));
if (mediaEmpty) {
replyNameTextView.setText(LocaleController.getString("EditMessage", R.string.EditMessage));
} else {
replyNameTextView.setText(LocaleController.getString("EditCaption", R.string.EditCaption));
}
if (canEditMedia) {
replyObjectTextView.setText(LocaleController.getString("EditMessageMedia", R.string.EditMessageMedia));
} else if (messageObjectToEdit.messageText != null || messageObjectToEdit.caption != null) {
String mess = messageObjectToEdit.caption != null ? messageObjectToEdit.caption.toString() : messageObjectToEdit.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
Spannable cs = new SpannableStringBuilder(Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
MediaDataController.addTextStyleRuns(messageObjectToEdit, cs);
replyObjectTextView.setText(cs);
}
}
} else if (messageObjectToReply != null) {
forwardingMessages = null;
editingMessageObject = null;
replyingMessageObject = messageObjectToReply;
chatActivityEnterView.setReplyingMessageObject(messageObjectToReply);
chatActivityEnterView.setEditingMessageObject(null, false);
if (foundWebPage != null) {
return;
}
String restrictionReason = MessagesController.getRestrictionReason(messageObjectToReply.messageOwner.restriction_reason);
chatActivityEnterView.setForceShowSendButton(false, false);
String name;
if (messageObjectToReply.isFromUser()) {
if (messageObjectToReply.messageOwner.from_id.channel_id != 0) {
TLRPC.Chat chat = getMessagesController().getChat(messageObjectToReply.messageOwner.from_id.channel_id);
if (chat == null) {
return;
}
name = chat.title;
} else {
TLRPC.User user = getMessagesController().getUser(messageObjectToReply.messageOwner.from_id.user_id);
if (user == null) {
return;
}
name = UserObject.getUserName(user);
}
} else {
TLRPC.Chat chat;
if (ChatObject.isChannel(currentChat) && currentChat.megagroup && messageObjectToReply.isForwardedChannelPost()) {
chat = getMessagesController().getChat(messageObjectToReply.messageOwner.fwd_from.from_id.channel_id);
} else {
chat = getMessagesController().getChat(-messageObjectToReply.getSenderId());
}
if (chat == null) {
return;
}
name = chat.title;
}
replyIconImageView.setImageResource(R.drawable.msg_panel_reply);
replyNameTextView.setText(name);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrReplying", R.string.AccDescrReplying));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelReply", R.string.AccDescrCancelReply));
CharSequence replyObjectText = null;
if (!TextUtils.isEmpty(restrictionReason)) {
replyObjectText = restrictionReason;
} else if (messageObjectToReply.messageOwner.media instanceof TLRPC.TL_messageMediaGame) {
replyObjectText = Emoji.replaceEmoji(messageObjectToReply.messageOwner.media.game.title, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
} else if (messageObjectToReply.messageText != null || messageObjectToReply.caption != null) {
String mess = messageObjectToReply.caption != null ? messageObjectToReply.caption.toString() : messageObjectToReply.messageText.toString();
if (mess.length() > 150) {
mess = mess.substring(0, 150);
}
mess = mess.replace('\n', ' ');
replyObjectText = Emoji.replaceEmoji(mess, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false);
}
if (replyObjectText != null) {
if (replyObjectText instanceof Spannable)
MediaDataController.addTextStyleRuns(messageObjectToReply.messageOwner.entities, messageObjectToReply.caption != null ? messageObjectToReply.caption : messageObjectToReply.messageText, (Spannable) replyObjectText);
replyObjectTextView.setText(replyObjectText);
}
} else if (messageObjectsToForward != null) {
if (messageObjectsToForward.isEmpty()) {
return;
}
if (threadMessageId == 0) {
replyingMessageObject = null;
chatActivityEnterView.setReplyingMessageObject(null);
}
editingMessageObject = null;
chatActivityEnterView.setEditingMessageObject(null, false);
if (forwardingMessages == null) {
forwardingMessages = new ForwardingMessagesParams(messageObjectsToForward, dialog_id);
}
if (foundWebPage != null) {
return;
}
chatActivityEnterView.setForceShowSendButton(true, false);
ArrayList<Long> uids = new ArrayList<>();
replyIconImageView.setImageResource(R.drawable.msg_panel_forward);
replyIconImageView.setContentDescription(LocaleController.getString("AccDescrForwarding", R.string.AccDescrForwarding));
replyCloseImageView.setContentDescription(LocaleController.getString("AccDescrCancelForward", R.string.AccDescrCancelForward));
MessageObject object = messageObjectsToForward.get(0);
if (object.isFromUser()) {
uids.add(object.messageOwner.from_id.user_id);
} else {
TLRPC.Chat chat = getMessagesController().getChat(object.messageOwner.peer_id.channel_id);
if (ChatObject.isChannel(chat) && chat.megagroup && object.isForwardedChannelPost()) {
uids.add(-object.messageOwner.fwd_from.from_id.channel_id);
} else {
uids.add(-object.messageOwner.peer_id.channel_id);
}
}
int type = object.isAnimatedEmoji() || object.isDice() ? 0 : object.type;
for (int a = 1; a < messageObjectsToForward.size(); a++) {
object = messageObjectsToForward.get(a);
long uid;
if (object.isFromUser()) {
uid = object.messageOwner.from_id.user_id;
} else {
TLRPC.Chat chat = getMessagesController().getChat(object.messageOwner.peer_id.channel_id);
if (ChatObject.isChannel(chat) && chat.megagroup && object.isForwardedChannelPost()) {
uid = -object.messageOwner.fwd_from.from_id.channel_id;
} else {
uid = -object.messageOwner.peer_id.channel_id;
}
}
if (!uids.contains(uid)) {
uids.add(uid);
}
if (messageObjectsToForward.get(a).type != type) {
type = -1;
}
}
StringBuilder userNames = new StringBuilder();
for (int a = 0; a < uids.size(); a++) {
Long uid = uids.get(a);
TLRPC.Chat chat = null;
TLRPC.User user = null;
if (uid > 0) {
user = getMessagesController().getUser(uid);
} else {
chat = getMessagesController().getChat(-uid);
}
if (user == null && chat == null) {
continue;
}
if (uids.size() == 1) {
if (user != null) {
userNames.append(UserObject.getUserName(user));
} else {
userNames.append(chat.title);
}
} else if (uids.size() == 2 || userNames.length() == 0) {
if (userNames.length() > 0) {
userNames.append(", ");
}
if (user != null) {
if (!TextUtils.isEmpty(user.first_name)) {
userNames.append(user.first_name);
} else if (!TextUtils.isEmpty(user.last_name)) {
userNames.append(user.last_name);
} else {
userNames.append(" ");
}
} else {
userNames.append(chat.title);
}
} else {
userNames.append(" ");
userNames.append(LocaleController.formatPluralString("AndOther", uids.size() - 1));
break;
}
}
formwardingNameText = userNames;
if (type == -1 || type == 0 || type == 10 || type == 11) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardMessagesCount", messageObjectsToForward.size()));
} else if (type == 1) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardPhoto", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 4) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardLocation", messageObjectsToForward.size()));
} else if (type == 3) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardVideo", messageObjectsToForward.size()));
if (messageObjectsToForward.size() == 1) {
messageObjectToReply = messageObjectsToForward.get(0);
}
} else if (type == 12) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardContact", messageObjectsToForward.size()));
} else if (type == 2) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardAudio", messageObjectsToForward.size()));
} else if (type == MessageObject.TYPE_ROUND_VIDEO) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardRound", messageObjectsToForward.size()));
} else if (type == 14) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardMusic", messageObjectsToForward.size()));
} else if (type == MessageObject.TYPE_STICKER || type == MessageObject.TYPE_ANIMATED_STICKER) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardSticker", messageObjectsToForward.size()));
} else if (type == 17) {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardPoll", messageObjectsToForward.size()));
} else if (type == 8 || type == 9) {
if (messageObjectsToForward.size() == 1 & type == 9) {
messageObjectToReply = messageObjectsToForward.get(0);
}
if (messageObjectsToForward.size() == 1 && type == 8) {
replyNameTextView.setText(LocaleController.getString("AttachGif", R.string.AttachGif));
} else {
replyNameTextView.setText(LocaleController.formatPluralString("PreviewForwardFile", messageObjectsToForward.size()));
}
}
if (forwardingMessages.hideForwardSendersName) {
replyObjectTextView.setText(LocaleController.getString("HiddenSendersNameDescription", R.string.HiddenSendersNameDescription));
} else {
if ((type == -1 || type == 0 || type == 10 || type == 11) && (messageObjectsToForward.size() == 1 && messageObjectsToForward.get(0).messageText != null)) {
MessageObject messageObject = messageObjectsToForward.get(0);
CharSequence mess = SpannableStringBuilder.valueOf(messageObject.messageText);
MediaDataController.addTextStyleRuns(messageObjectsToForward.get(0), (Spannable) mess);
if (mess.length() > 150) {
mess = mess.subSequence(0, 150);
}
mess = AndroidUtilities.replaceNewLines(mess);
Spannable formatted = AndroidUtilities.formatSpannableSimple(LocaleController.getString("ForwardingFromNameAndMessage", R.string.ForwardingFromNameAndMessage), userNames, mess);
replyObjectTextView.setText(Emoji.replaceEmoji(formatted, replyObjectTextView.getPaint().getFontMetricsInt(), AndroidUtilities.dp(14), false));
} else {
replyObjectTextView.setText(LocaleController.formatString("ForwardingFromNames", R.string.ForwardingFromNames, userNames));
}
}
if (!SharedConfig.forwardingOptionsHintShown) {
showHint = true;
}
} else {
replyIconImageView.setImageResource(R.drawable.msg_link);
if (webPage instanceof TLRPC.TL_webPagePending) {
replyNameTextView.setText(LocaleController.getString("GettingLinkInfo", R.string.GettingLinkInfo));
replyObjectTextView.setText(pendingLinkSearchString);
} else {
if (webPage.site_name != null) {
replyNameTextView.setText(webPage.site_name);
} else if (webPage.title != null) {
replyNameTextView.setText(webPage.title);
} else {
replyNameTextView.setText(LocaleController.getString("LinkPreview", R.string.LinkPreview));
}
if (webPage.title != null) {
replyObjectTextView.setText(webPage.title);
} else if (webPage.description != null) {
replyObjectTextView.setText(webPage.description);
} else if (webPage.author != null) {
replyObjectTextView.setText(webPage.author);
} else {
replyObjectTextView.setText(webPage.display_url);
}
chatActivityEnterView.setWebPage(webPage, true);
}
}
MessageObject thumbMediaMessageObject;
if (messageObjectToReply != null) {
thumbMediaMessageObject = messageObjectToReply;
} else if (messageObjectToEdit != null) {
if (!chatActivityEnterTopView.isEditMode()) {
thumbMediaMessageObject = messageObjectToEdit;
} else {
thumbMediaMessageObject = null;
}
} else {
thumbMediaMessageObject = null;
}
FrameLayout.LayoutParams layoutParams1 = (FrameLayout.LayoutParams) replyNameTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams2 = (FrameLayout.LayoutParams) replyObjectTextView.getLayoutParams();
FrameLayout.LayoutParams layoutParams3 = (FrameLayout.LayoutParams) replyObjectHintTextView.getLayoutParams();
int cacheType = 1;
int size = 0;
TLRPC.PhotoSize photoSize = null;
TLRPC.PhotoSize thumbPhotoSize = null;
TLObject photoSizeObject = null;
if (thumbMediaMessageObject != null && TextUtils.isEmpty(MessagesController.getRestrictionReason(thumbMediaMessageObject.messageOwner.restriction_reason))) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs2, 320);
thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs2, AndroidUtilities.dp(40));
photoSizeObject = thumbMediaMessageObject.photoThumbsObject2;
if (photoSize == null) {
if (thumbMediaMessageObject.mediaExists) {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, AndroidUtilities.getPhotoSize());
if (photoSize != null) {
size = photoSize.size;
}
cacheType = 0;
} else {
photoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, 320);
}
thumbPhotoSize = FileLoader.getClosestPhotoSizeWithSize(thumbMediaMessageObject.photoThumbs, AndroidUtilities.dp(40));
photoSizeObject = thumbMediaMessageObject.photoThumbsObject;
}
}
if (photoSize == thumbPhotoSize) {
thumbPhotoSize = null;
}
if (photoSize == null || photoSize instanceof TLRPC.TL_photoSizeEmpty || photoSize.location instanceof TLRPC.TL_fileLocationUnavailable || thumbMediaMessageObject.isAnyKindOfSticker() || thumbMediaMessageObject.isSecretMedia() || thumbMediaMessageObject.isWebpageDocument()) {
replyImageView.setImageBitmap(null);
replyImageLocation = null;
replyImageLocationObject = null;
replyImageView.setVisibility(View.INVISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = AndroidUtilities.dp(52);
} else {
if (thumbMediaMessageObject.isRoundVideo()) {
replyImageView.setRoundRadius(AndroidUtilities.dp(17));
} else {
replyImageView.setRoundRadius(AndroidUtilities.dp(2));
}
replyImageSize = size;
replyImageCacheType = cacheType;
replyImageLocation = photoSize;
replyImageThumbLocation = thumbPhotoSize;
replyImageLocationObject = photoSizeObject;
replyImageView.setImage(ImageLocation.getForObject(replyImageLocation, photoSizeObject), "50_50", ImageLocation.getForObject(thumbPhotoSize, photoSizeObject), "50_50_b", null, size, cacheType, thumbMediaMessageObject);
replyImageView.setVisibility(View.VISIBLE);
layoutParams1.leftMargin = layoutParams2.leftMargin = layoutParams3.leftMargin = AndroidUtilities.dp(96);
}
replyNameTextView.setLayoutParams(layoutParams1);
replyObjectTextView.setLayoutParams(layoutParams2);
replyObjectTextView.setLayoutParams(layoutParams3);
chatActivityEnterView.showTopView(true, openKeyboard);
} else {
if (replyingMessageObject == null && forwardingMessages == null && foundWebPage == null && editingMessageObject == null && !chatActivityEnterView.isTopViewVisible()) {
return;
}
if (replyingMessageObject != null && replyingMessageObject.messageOwner.reply_markup instanceof TLRPC.TL_replyKeyboardForceReply) {
SharedPreferences preferences = MessagesController.getMainSettings(currentAccount);
preferences.edit().putInt("answered_" + dialog_id, replyingMessageObject.getId()).commit();
}
if (foundWebPage != null) {
foundWebPage = null;
chatActivityEnterView.setWebPage(null, !cancel);
if (webPage != null && (replyingMessageObject != null || forwardingMessages != null || editingMessageObject != null)) {
showFieldPanel(true, replyingMessageObject, editingMessageObject, forwardingMessages != null ? forwardingMessages.messages : null, null, notify, scheduleDate, false, true);
return;
}
}
if (forwardingMessages != null) {
ArrayList<MessageObject> messagesToForward = new ArrayList<>();
forwardingMessages.getSelectedMessages(messagesToForward);
forwardMessages(messagesToForward, forwardingMessages.hideForwardSendersName, forwardingMessages.hideCaption, notify, scheduleDate != 0 && scheduleDate != 0x7ffffffe ? scheduleDate + 1 : scheduleDate);
forwardingMessages = null;
}
chatActivityEnterView.setForceShowSendButton(false, animated);
if (!waitingForSendingMessageLoad) {
chatActivityEnterView.hideTopView(animated);
}
chatActivityEnterView.setReplyingMessageObject(threadMessageObject);
chatActivityEnterView.setEditingMessageObject(null, false);
topViewWasVisible = 0;
replyingMessageObject = threadMessageObject;
editingMessageObject = null;
replyImageLocation = null;
replyImageLocationObject = null;
}
if (showHint) {
if (tapForForwardingOptionsHitRunnable == null) {
AndroidUtilities.runOnUIThread(tapForForwardingOptionsHitRunnable = () -> {
showTapForForwardingOptionsHit = !showTapForForwardingOptionsHit;
replyObjectTextView.setPivotX(0);
replyObjectHintTextView.setPivotX(0);
if (showTapForForwardingOptionsHit) {
replyObjectTextView.animate().alpha(0f).scaleX(0.98f).scaleY(0.98f).setDuration(150).start();
replyObjectHintTextView.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(150).start();
} else {
replyObjectTextView.animate().alpha(1f).scaleX(1f).scaleY(1f).setDuration(150).start();
replyObjectHintTextView.animate().alpha(0f).scaleX(0.98f).scaleY(0.98f).setDuration(150).start();
}
AndroidUtilities.runOnUIThread(tapForForwardingOptionsHitRunnable, 6000);
}, 6000);
}
} else {
if (tapForForwardingOptionsHitRunnable != null) {
AndroidUtilities.cancelRunOnUIThread(tapForForwardingOptionsHitRunnable);
tapForForwardingOptionsHitRunnable = null;
}
replyObjectTextView.setAlpha(1f);
replyObjectHintTextView.setAlpha(0);
}
}
Aggregations