use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method fixLayoutInternal.
private boolean fixLayoutInternal() {
if (!AndroidUtilities.isTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
selectedMessagesCountTextView.setTextSize(18);
} else {
selectedMessagesCountTextView.setTextSize(20);
}
HashMap<Long, MessageObject.GroupedMessages> newGroups = null;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View child = chatListView.getChildAt(a);
if (child instanceof ChatMessageCell) {
MessageObject.GroupedMessages groupedMessages = ((ChatMessageCell) child).getCurrentMessagesGroup();
if (groupedMessages != null && groupedMessages.hasSibling && !groupedMessages.messages.isEmpty()) {
if (newGroups == null) {
newGroups = new HashMap<>();
}
if (!newGroups.containsKey(groupedMessages.groupId)) {
newGroups.put(groupedMessages.groupId, groupedMessages);
MessageObject messageObject = groupedMessages.messages.get(groupedMessages.messages.size() - 1);
int idx = messages.indexOf(messageObject);
if (idx >= 0) {
chatAdapter.notifyItemRangeChanged(idx + chatAdapter.messagesStartRow, groupedMessages.messages.size());
chatListView.setItemAnimator(null);
}
}
}
}
}
if (AndroidUtilities.isTablet()) {
if (AndroidUtilities.isSmallTablet() && ApplicationLoader.applicationContext.getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) {
actionBar.setBackButtonDrawable(new BackDrawable(false));
} else {
actionBar.setBackButtonDrawable(new BackDrawable(parentLayout == null || parentLayout.fragmentsStack.isEmpty() || parentLayout.fragmentsStack.get(0) == ChatActivity.this || parentLayout.fragmentsStack.size() == 1));
}
return false;
}
return true;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method didPressMessageUrl.
private void didPressMessageUrl(CharacterStyle url, boolean longPress, MessageObject messageObject, ChatMessageCell cell) {
if (url == null || getParentActivity() == null) {
return;
}
boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || (messageObject != null && messageObject.messageOwner != null && messageObject.messageOwner.noforwards);
if (url instanceof URLSpanMono) {
if (!noforwards) {
((URLSpanMono) url).copyToClipboard();
getUndoView().showWithAction(0, UndoView.ACTION_TEXT_COPIED, null);
}
} else if (url instanceof URLSpanUserMention) {
TLRPC.User user = getMessagesController().getUser(Utilities.parseLong(((URLSpanUserMention) url).getURL()));
if (user != null) {
MessagesController.openChatOrProfileWith(user, null, ChatActivity.this, 0, false);
}
} else if (url instanceof URLSpanNoUnderline) {
String str = ((URLSpanNoUnderline) url).getURL();
if (messageObject != null && str.startsWith("/")) {
if (URLSpanBotCommand.enabled) {
chatActivityEnterView.setCommand(messageObject, str, longPress, currentChat != null && currentChat.megagroup);
if (!longPress && chatActivityEnterView.getFieldText() == null) {
hideFieldPanel(false);
}
}
} else if (messageObject != null && str.startsWith("video") && !longPress) {
int seekTime = Utilities.parseInt(str);
TLRPC.WebPage webPage;
if (messageObject.isYouTubeVideo()) {
webPage = messageObject.messageOwner.media.webpage;
} else if (messageObject.replyMessageObject != null && messageObject.replyMessageObject.isYouTubeVideo()) {
webPage = messageObject.replyMessageObject.messageOwner.media.webpage;
messageObject = messageObject.replyMessageObject;
} else {
webPage = null;
}
if (webPage != null) {
EmbedBottomSheet.show(getParentActivity(), messageObject, photoViewerProvider, webPage.site_name, webPage.title, webPage.url, webPage.embed_url, webPage.embed_width, webPage.embed_height, seekTime, isKeyboardVisible());
} else {
if (!messageObject.isVideo() && messageObject.replyMessageObject != null) {
MessageObject obj = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
cell = null;
if (obj == null) {
messageObject = messageObject.replyMessageObject;
} else {
messageObject = obj;
}
}
messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
openPhotoViewerForMessage(cell, messageObject);
}
} else if (messageObject != null && str.startsWith("audio")) {
int seekTime = Utilities.parseInt(str);
if (!messageObject.isMusic() && messageObject.replyMessageObject != null) {
messageObject = messagesDict[messageObject.replyMessageObject.getDialogId() == dialog_id ? 0 : 1].get(messageObject.replyMessageObject.getId());
}
float progress = seekTime / (float) messageObject.getDuration();
MediaController mediaController = getMediaController();
if (mediaController.isPlayingMessage(messageObject)) {
messageObject.audioProgress = progress;
mediaController.seekToProgress(messageObject, progress);
if (mediaController.isMessagePaused()) {
mediaController.playMessage(messageObject);
}
} else {
messageObject.forceSeekTo = seekTime / (float) messageObject.getDuration();
mediaController.playMessage(messageObject);
}
} else if (str.startsWith("card:")) {
String number = str.substring(5);
final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
TLRPC.TL_payments_getBankCardData req = new TLRPC.TL_payments_getBankCardData();
req.number = number;
int requestId = getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
try {
progressDialog[0].dismiss();
} catch (Throwable ignore) {
}
progressDialog[0] = null;
if (response instanceof TLRPC.TL_payments_bankCardData) {
if (getParentActivity() == null) {
return;
}
TLRPC.TL_payments_bankCardData data = (TLRPC.TL_payments_bankCardData) response;
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
ArrayList<CharSequence> arrayList = new ArrayList<>();
for (int a = 0, N = data.open_urls.size(); a < N; a++) {
arrayList.add(data.open_urls.get(a).name);
}
arrayList.add(LocaleController.getString("CopyCardNumber", R.string.CopyCardNumber));
builder.setTitle(data.title);
builder.setItems(arrayList.toArray(new CharSequence[0]), (dialog, which) -> {
if (which < data.open_urls.size()) {
Browser.openUrl(getParentActivity(), data.open_urls.get(which).url, inlineReturn == 0, false);
} else {
AndroidUtilities.addToClipboard(number);
Toast.makeText(ApplicationLoader.applicationContext, LocaleController.getString("CardNumberCopied", R.string.CardNumberCopied), Toast.LENGTH_SHORT).show();
}
});
showDialog(builder.create());
}
}), null, null, 0, getMessagesController().webFileDatacenterId, ConnectionsManager.ConnectionTypeGeneric, true);
AndroidUtilities.runOnUIThread(() -> {
if (progressDialog[0] == null) {
return;
}
progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
showDialog(progressDialog[0]);
}, 500);
} else {
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
int timestamp = -1;
if (str.startsWith("video?")) {
timestamp = Utilities.parseInt(str);
}
if (timestamp >= 0) {
builder.setTitle(AndroidUtilities.formatDuration(timestamp, false));
} else {
builder.setTitle(str);
}
final int finalTimestamp = timestamp;
ChatMessageCell finalCell = cell;
MessageObject finalMessageObject = messageObject;
builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
if (which == 0) {
if (str.startsWith("video?")) {
didPressMessageUrl(url, false, finalMessageObject, finalCell);
} else {
openClickableLink(str);
}
} else if (which == 1) {
if (str.startsWith("video?") && finalMessageObject != null && !finalMessageObject.scheduled) {
MessageObject messageObject1 = finalMessageObject;
boolean isMedia = finalMessageObject.isVideo() || finalMessageObject.isRoundVideo() || finalMessageObject.isVoice() || finalMessageObject.isMusic();
if (!isMedia && finalMessageObject.replyMessageObject != null) {
messageObject1 = finalMessageObject.replyMessageObject;
}
long dialogId = messageObject1.getDialogId();
int messageId = messageObject1.getId();
String link = null;
if (messageObject1.messageOwner.fwd_from != null) {
if (messageObject1.messageOwner.fwd_from.saved_from_peer != null) {
dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.saved_from_peer);
messageId = messageObject1.messageOwner.fwd_from.saved_from_msg_id;
} else if (messageObject1.messageOwner.fwd_from.from_id != null) {
dialogId = MessageObject.getPeerId(messageObject1.messageOwner.fwd_from.from_id);
messageId = messageObject1.messageOwner.fwd_from.channel_post;
}
}
if (DialogObject.isChatDialog(dialogId)) {
TLRPC.Chat currentChat = MessagesController.getInstance(currentAccount).getChat(-dialogId);
if (currentChat != null && currentChat.username != null) {
link = "https://t.me/" + currentChat.username + "/" + messageId + "?t=" + finalTimestamp;
}
} else {
TLRPC.User user = MessagesController.getInstance(currentAccount).getUser(dialogId);
if (user != null && user.username != null) {
link = "https://t.me/" + user.username + "/" + messageId + "?t=" + finalTimestamp;
}
}
if (link == null) {
return;
}
AndroidUtilities.addToClipboard(link);
} else {
AndroidUtilities.addToClipboard(str);
}
if (str.startsWith("@")) {
undoView.showWithAction(0, UndoView.ACTION_USERNAME_COPIED, null);
} else if (str.startsWith("#") || str.startsWith("$")) {
undoView.showWithAction(0, UndoView.ACTION_HASHTAG_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
}
});
showDialog(builder.create());
} else {
openClickableLink(str);
}
}
} else {
final String urlFinal = ((URLSpan) url).getURL();
if (longPress) {
BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false, themeDelegate);
builder.setTitle(urlFinal);
builder.setItems(noforwards ? new CharSequence[] { LocaleController.getString("Open", R.string.Open) } : new CharSequence[] { LocaleController.getString("Open", R.string.Open), LocaleController.getString("Copy", R.string.Copy) }, (dialog, which) -> {
if (which == 0) {
processExternalUrl(1, urlFinal, false);
} else if (which == 1) {
String url1 = urlFinal;
boolean tel = false;
boolean mail = false;
if (url1.startsWith("mailto:")) {
url1 = url1.substring(7);
mail = true;
} else if (url1.startsWith("tel:")) {
url1 = url1.substring(4);
tel = true;
}
AndroidUtilities.addToClipboard(url1);
if (mail) {
undoView.showWithAction(0, UndoView.ACTION_EMAIL_COPIED, null);
} else if (tel) {
undoView.showWithAction(0, UndoView.ACTION_PHONE_COPIED, null);
} else {
undoView.showWithAction(0, UndoView.ACTION_LINK_COPIED, null);
}
}
});
showDialog(builder.create());
} else {
boolean forceAlert = url instanceof URLSpanReplacement;
if (url instanceof URLSpanReplacement && (urlFinal == null || !urlFinal.startsWith("mailto:")) || AndroidUtilities.shouldShowUrlInAlert(urlFinal)) {
if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
return;
}
forceAlert = true;
} else {
if (messageObject != null && messageObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && messageObject.messageOwner.media.webpage != null && messageObject.messageOwner.media.webpage.cached_page != null) {
String lowerUrl = urlFinal.toLowerCase();
String lowerUrl2 = messageObject.messageOwner.media.webpage.url.toLowerCase();
if ((lowerUrl.contains("telegram.org/blog") || Browser.isTelegraphUrl(lowerUrl, false) || lowerUrl.contains("t.me/iv")) && (lowerUrl.contains(lowerUrl2) || lowerUrl2.contains(lowerUrl))) {
ArticleViewer.getInstance().setParentActivity(getParentActivity(), ChatActivity.this);
ArticleViewer.getInstance().open(messageObject);
return;
}
}
if (openLinkInternally(urlFinal, messageObject != null ? messageObject.getId() : 0)) {
return;
}
}
if (Browser.urlMustNotHaveConfirmation(urlFinal)) {
forceAlert = false;
}
processExternalUrl(2, urlFinal, forceAlert);
}
}
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method scrollToMessageId.
public void scrollToMessageId(int id, int fromMessageId, boolean select, int loadIndex, boolean forceScroll, int forcePinnedMessageId) {
if (id == 0 || NotificationCenter.getInstance(currentAccount).isAnimationInProgress() || getParentActivity() == null) {
if (NotificationCenter.getInstance(currentAccount).isAnimationInProgress()) {
nextScrollToMessageId = id;
nextScrollFromMessageId = fromMessageId;
nextScrollSelect = select;
nextScrollLoadIndex = loadIndex;
nextScrollForce = forceScroll;
nextScrollForcePinnedMessageId = forcePinnedMessageId;
NotificationCenter.getInstance(currentAccount).doOnIdle(() -> {
if (nextScrollToMessageId != 0) {
scrollToMessageId(nextScrollToMessageId, nextScrollFromMessageId, nextScrollSelect, nextScrollLoadIndex, nextScrollForce, nextScrollForcePinnedMessageId);
nextScrollToMessageId = 0;
}
});
}
return;
}
forceNextPinnedMessageId = Math.abs(forcePinnedMessageId);
forceScrollToFirst = forcePinnedMessageId > 0;
wasManualScroll = true;
MessageObject object = messagesDict[loadIndex].get(id);
boolean query = false;
int scrollDirection = RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UNSET;
int scrollFromIndex = 0;
if (fromMessageId != 0) {
boolean scrollDown = fromMessageId < id;
if (isSecretChat()) {
scrollDown = !scrollDown;
}
scrollDirection = scrollDown ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
} else if (messages.size() > 0) {
if (isThreadChat() && id == threadMessageId) {
scrollDirection = RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
} else {
int end = chatLayoutManager.findLastVisibleItemPosition();
for (int i = chatLayoutManager.findFirstVisibleItemPosition(); i <= end; i++) {
if (i >= chatAdapter.messagesStartRow && i <= chatAdapter.messagesEndRow) {
MessageObject messageObject = messages.get(i - chatAdapter.messagesStartRow);
if (messageObject.getId() == 0) {
continue;
}
scrollFromIndex = i - chatAdapter.messagesStartRow;
boolean scrollDown = messageObject.getId() < id;
if (isSecretChat()) {
scrollDown = !scrollDown;
}
scrollDirection = scrollDown ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
break;
}
}
}
}
chatScrollHelper.setScrollDirection(scrollDirection);
if (object != null) {
MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(object.getGroupId());
if (object.getGroupId() != 0 && groupedMessages != null) {
MessageObject primary = groupedMessages.findPrimaryMessageObject();
if (primary != null) {
object = primary;
}
}
int index = messages.indexOf(object);
if (index != -1) {
if (scrollFromIndex > 0) {
scrollDirection = scrollFromIndex > index ? RecyclerAnimationScrollHelper.SCROLL_DIRECTION_DOWN : RecyclerAnimationScrollHelper.SCROLL_DIRECTION_UP;
chatScrollHelper.setScrollDirection(scrollDirection);
}
removeSelectedMessageHighlight();
if (select) {
highlightMessageId = id;
}
chatAdapter.updateRowsSafe();
int position = chatAdapter.messagesStartRow + messages.indexOf(object);
updateVisibleRows();
boolean found = false;
int count = chatListView.getChildCount();
for (int a = 0; a < count; a++) {
View view = chatListView.getChildAt(a);
if (view instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
found = true;
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
} else if (view instanceof ChatActionCell) {
ChatActionCell cell = (ChatActionCell) view;
MessageObject messageObject = cell.getMessageObject();
if (messageObject != null && messageObject.getId() == object.getId()) {
found = true;
view.sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_FOCUSED);
}
}
if (found) {
int yOffset = getScrollOffsetForMessage(object);
int scrollY = (int) (view.getTop() - chatListViewPaddingTop - yOffset);
int maxScrollOffset = chatListView.computeVerticalScrollRange() - chatListView.computeVerticalScrollOffset() - chatListView.computeVerticalScrollExtent();
if (maxScrollOffset < 0)
maxScrollOffset = 0;
if (scrollY > maxScrollOffset) {
scrollY = maxScrollOffset;
}
if (scrollY != 0) {
scrollByTouch = false;
chatListView.smoothScrollBy(0, scrollY);
chatListView.setOverScrollMode(RecyclerListView.OVER_SCROLL_NEVER);
}
break;
}
}
if (!found) {
int yOffset = getScrollOffsetForMessage(object);
chatScrollHelperCallback.scrollTo = object;
chatScrollHelperCallback.lastBottom = false;
chatScrollHelperCallback.lastItemOffset = yOffset;
chatScrollHelperCallback.lastPadding = (int) chatListViewPaddingTop;
chatScrollHelper.setScrollDirection(scrollDirection);
chatScrollHelper.scrollToPosition(position, yOffset, false, true);
canShowPagedownButton = true;
updatePagedownButtonVisibility(true);
}
} else {
query = true;
}
} else {
query = true;
}
if (query) {
if (isThreadChat() && id == threadMessageId) {
scrollToThreadMessage = true;
id = 1;
}
if (progressDialog != null) {
progressDialog.dismiss();
}
showPinnedProgress(forceNextPinnedMessageId != 0);
progressDialog = new AlertDialog(getParentActivity(), 3, themeDelegate);
progressDialog.setOnShowListener(dialogInterface -> showPinnedProgress(false));
progressDialog.setOnCancelListener(postponedScrollCancelListener);
progressDialog.showDelayed(400);
waitingForLoad.clear();
removeSelectedMessageHighlight();
scrollToMessagePosition = -10000;
startLoadFromMessageId = id;
showScrollToMessageError = !forceScroll;
if (id == createUnreadMessageAfterId) {
createUnreadMessageAfterIdLoading = true;
}
postponedScrollIsCanceled = false;
waitingForLoad.add(lastLoadIndex);
postponedScrollToLastMessageQueryIndex = lastLoadIndex;
postponedScrollMinMessageId = minMessageId[0];
postponedScrollMessageId = id;
getMessagesController().loadMessages(loadIndex == 0 ? dialog_id : mergeDialogId, 0, false, isThreadChat() || AndroidUtilities.isTablet() ? 30 : 20, startLoadFromMessageId, 0, true, 0, classGuid, 3, 0, chatMode, threadMessageId, replyMaxReadId, lastLoadIndex++);
} else {
View child = chatListView.getChildAt(0);
if (child != null && child.getTop() <= 0) {
showFloatingDateView(false);
}
}
returnToMessageId = fromMessageId;
returnToLoadIndex = loadIndex;
needSelectFromMessageId = select;
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method playReactionAnimation.
private void playReactionAnimation(Integer messageId) {
if (fragmentView == null) {
return;
}
ChatMessageCell cell = findMessageCell(messageId, false);
if (cell != null) {
TLRPC.TL_messagePeerReaction reaction = cell.getMessageObject().getRandomUnreadReaction();
if (reaction != null && cell.reactionsLayoutInBubble.hasUnreadReactions) {
ReactionsEffectOverlay.show(ChatActivity.this, null, cell, 0, 0, reaction.reaction, currentAccount, reaction.big ? ReactionsEffectOverlay.LONG_ANIMATION : ReactionsEffectOverlay.SHORT_ANIMATION);
ReactionsEffectOverlay.startAnimation();
}
cell.markReactionsAsRead();
}
}
use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.
the class ChatActivity method dimBehindView.
private void dimBehindView(float value, boolean hidePagedownButtons) {
boolean enable = value > 0;
if (scrimView instanceof ChatMessageCell) {
ChatMessageCell cell = (ChatMessageCell) scrimView;
cell.setInvalidatesParent(enable);
if (enable) {
restartSticker(cell);
}
}
contentView.invalidate();
chatListView.invalidate();
if (scrimAnimatorSet != null) {
scrimAnimatorSet.removeAllListeners();
scrimAnimatorSet.cancel();
}
scrimAnimatorSet = new AnimatorSet();
ArrayList<Animator> animators = new ArrayList<>();
ValueAnimator scrimPaintAlphaAnimator;
if (enable) {
scrimViewAlpha = 1f;
if (scrimViewAlphaAnimator != null) {
scrimViewAlphaAnimator.cancel();
}
animators.add(scrimPaintAlphaAnimator = ValueAnimator.ofFloat(0, value));
} else {
animators.add(scrimPaintAlphaAnimator = ValueAnimator.ofFloat(scrimPaintAlpha, 0));
}
scrimPaintAlphaAnimator.addUpdateListener(a -> {
scrimPaintAlpha = (float) a.getAnimatedValue();
if (fragmentView != null) {
fragmentView.invalidate();
}
});
if (!enable || hidePagedownButtons) {
if (pagedownButton != null) {
animators.add(ObjectAnimator.ofFloat(pagedownButton, View.ALPHA, enable ? 0 : 1));
}
if (mentiondownButton != null) {
animators.add(ObjectAnimator.ofFloat(mentiondownButton, View.ALPHA, enable ? 0 : 1));
}
if (reactionsMentiondownButton != null) {
animators.add(ObjectAnimator.ofFloat(reactionsMentiondownButton, View.ALPHA, enable ? 0 : 1));
}
}
scrimAnimatorSet.playTogether(animators);
scrimAnimatorSet.setDuration(enable ? 150 : 220);
if (!enable) {
scrimAnimatorSet.addListener(new AnimatorListenerAdapter() {
@Override
public void onAnimationEnd(Animator animation) {
scrimView = null;
scrimViewReaction = null;
contentView.invalidate();
chatListView.invalidate();
}
});
}
if (scrimView != null && scrimViewAlpha <= 0f) {
scrimView = null;
}
scrimAnimatorSet.start();
}
Aggregations