Search in sources :

Example 51 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method updateTextureViewPosition.

public void updateTextureViewPosition(boolean needScroll) {
    if (fragmentView == null || paused) {
        return;
    }
    boolean foundTextureViewMessage = false;
    int count = chatListView.getChildCount();
    for (int a = 0; a < count; a++) {
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            ChatMessageCell messageCell = (ChatMessageCell) view;
            MessageObject messageObject = messageCell.getMessageObject();
            if (videoPlayerContainer != null && (messageObject.isRoundVideo() || messageObject.isVideo()) && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                videoPlayerContainer.setTranslationX(imageReceiver.getImageX() + messageCell.getX());
                float translationY = messageCell.getY() + imageReceiver.getImageY() + chatListView.getY() - videoPlayerContainer.getTop();
                videoPlayerContainer.setTranslationY(translationY);
                FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) videoPlayerContainer.getLayoutParams();
                if (messageObject.isRoundVideo()) {
                    videoPlayerContainer.setTag(R.id.parent_tag, null);
                    if (layoutParams.width != AndroidUtilities.roundPlayingMessageSize || layoutParams.height != AndroidUtilities.roundPlayingMessageSize) {
                        layoutParams.width = layoutParams.height = AndroidUtilities.roundPlayingMessageSize;
                        aspectRatioFrameLayout.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FIT);
                        videoPlayerContainer.setLayoutParams(layoutParams);
                    }
                    float scale = (AndroidUtilities.roundPlayingMessageSize + AndroidUtilities.roundMessageInset * 2) / (float) AndroidUtilities.roundPlayingMessageSize;
                    float transitionScale = messageCell.getPhotoImage().getImageWidth() / AndroidUtilities.roundPlayingMessageSize;
                    if (videoPlayerContainer.getScaleX() != transitionScale) {
                        videoPlayerContainer.invalidate();
                        fragmentView.invalidate();
                    }
                    videoPlayerContainer.setPivotX(0);
                    videoPlayerContainer.setPivotY(0);
                    videoPlayerContainer.setScaleX(transitionScale);
                    videoPlayerContainer.setScaleY(transitionScale);
                    videoTextureView.setScaleX(scale);
                    videoTextureView.setScaleY(scale);
                } else {
                    videoPlayerContainer.setTag(R.id.parent_tag, imageReceiver);
                    if (layoutParams.width != imageReceiver.getImageWidth() || layoutParams.height != imageReceiver.getImageHeight()) {
                        aspectRatioFrameLayout.setResizeMode(AspectRatioFrameLayout.RESIZE_MODE_FILL);
                        layoutParams.width = (int) imageReceiver.getImageWidth();
                        layoutParams.height = (int) imageReceiver.getImageHeight();
                        videoPlayerContainer.setLayoutParams(layoutParams);
                    }
                    videoTextureView.setScaleX(1f);
                    videoTextureView.setScaleY(1f);
                }
                fragmentView.invalidate();
                videoPlayerContainer.invalidate();
                foundTextureViewMessage = true;
                break;
            }
        }
    }
    if (needScroll && videoPlayerContainer != null) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (messageObject != null && messageObject.eventId == 0) {
            if (!foundTextureViewMessage) {
                if (checkTextureViewPosition && messageObject.isVideo()) {
                    MediaController.getInstance().cleanupPlayer(true, true);
                } else {
                    videoPlayerContainer.setTranslationY(-AndroidUtilities.roundPlayingMessageSize - 100);
                    fragmentView.invalidate();
                    if (messageObject.isRoundVideo() || messageObject.isVideo()) {
                        if (checkTextureViewPosition || PipRoundVideoView.getInstance() != null) {
                            MediaController.getInstance().setCurrentVideoVisible(false);
                        } else {
                            scrollToMessageId(messageObject.getId(), 0, false, 0, true, 0);
                        }
                    }
                }
            } else {
                MediaController.getInstance().setCurrentVideoVisible(true);
                if (messageObject.isRoundVideo() || scrollToVideo) {
                // scrollToMessageId(messageObject.getId(), 0, false, 0, true, 0);
                } else {
                    chatListView.invalidate();
                }
            }
        }
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) ChatBlurredFrameLayout(org.telegram.ui.Components.ChatBlurredFrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) FrameLayout(android.widget.FrameLayout) HorizontalScrollView(android.widget.HorizontalScrollView) PinnedLineView(org.telegram.ui.Components.PinnedLineView) BotCommandsMenuView(org.telegram.ui.Components.BotCommandsMenuView) ReactedHeaderView(org.telegram.ui.Components.ReactedHeaderView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) BluredView(org.telegram.ui.Components.BluredView) InstantCameraView(org.telegram.ui.Components.InstantCameraView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) ChatActivityEnterTopView(org.telegram.ui.Components.ChatActivityEnterTopView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) BackupImageView(org.telegram.ui.Components.BackupImageView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) UndoView(org.telegram.ui.Components.UndoView) CounterView(org.telegram.ui.Components.CounterView) HintView(org.telegram.ui.Components.HintView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ClippingImageView(org.telegram.ui.Components.ClippingImageView) EmojiView(org.telegram.ui.Components.EmojiView) ChecksHintView(org.telegram.ui.Components.ChecksHintView) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) SearchCounterView(org.telegram.ui.Components.SearchCounterView) ForwardingPreviewView(org.telegram.ui.Components.ForwardingPreviewView) ReactionTabHolderView(org.telegram.ui.Components.ReactionTabHolderView) TextView(android.widget.TextView) ReactedUsersListView(org.telegram.ui.Components.ReactedUsersListView) NumberTextView(org.telegram.ui.Components.NumberTextView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 52 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method addSponsoredMessages.

private void addSponsoredMessages(boolean animated) {
    if (sponsoredMessagesAdded || chatMode != 0 || !ChatObject.isChannel(currentChat) || !forwardEndReached[0]) {
        return;
    }
    ArrayList<MessageObject> arrayList = getMessagesController().getSponsoredMessages(dialog_id);
    if (arrayList == null) {
        return;
    }
    for (int i = 0; i < arrayList.size(); i++) {
        MessageObject messageObject = arrayList.get(i);
        messageObject.resetLayout();
        long dialogId = MessageObject.getPeerId(messageObject.messageOwner.from_id);
        int messageId = 0;
        if (messageObject.sponsoredChannelPost != 0) {
            messageId = messageObject.sponsoredChannelPost;
        }
        getMessagesController().ensureMessagesLoaded(dialogId, messageId, null);
    }
    sponsoredMessagesAdded = true;
    processNewMessages(arrayList);
}
Also used : MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 53 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method getMessageCaption.

private CharSequence getMessageCaption(MessageObject messageObject, MessageObject.GroupedMessages group) {
    String restrictionReason = MessagesController.getRestrictionReason(messageObject.messageOwner.restriction_reason);
    if (!TextUtils.isEmpty(restrictionReason)) {
        return restrictionReason;
    }
    if (messageObject.caption != null) {
        return messageObject.caption;
    }
    if (group == null) {
        return null;
    }
    CharSequence caption = null;
    for (int a = 0, N = group.messages.size(); a < N; a++) {
        MessageObject message = group.messages.get(a);
        if (message.caption != null) {
            if (caption != null) {
                return null;
            }
            caption = message.caption;
        }
    }
    return caption;
}
Also used : SpannableString(android.text.SpannableString) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 54 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method updateChatListViewTopPadding.

private void updateChatListViewTopPadding() {
    if (!invalidateChatListViewTopPadding || chatListView == null || fixedKeyboardHeight > 0) {
        return;
    }
    float topPanelViewH = Math.max(0, AndroidUtilities.dp(48) + topChatPanelViewOffset);
    float pinnedViewH = 0;
    if (pinnedMessageView != null && pinnedMessageView.getVisibility() == View.VISIBLE) {
        pinnedViewH = Math.max(0, AndroidUtilities.dp(48) + pinnedMessageEnterOffset);
    }
    float pendingViewH = 0;
    View pendingRequestsView = pendingRequestsDelegate != null ? pendingRequestsDelegate.getView() : null;
    if (pendingRequestsView != null && pendingRequestsView.getVisibility() == View.VISIBLE) {
        pendingViewH = Math.max(0, pendingRequestsView.getHeight() + pendingRequestsDelegate.getViewEnterOffset());
    }
    float oldPadding = chatListViewPaddingTop;
    chatListViewPaddingTopOnlyTopViews = topPanelViewH + pinnedViewH;
    chatListViewPaddingTop = AndroidUtilities.dp(4) + contentPaddingTop + topPanelViewH + pinnedViewH + pendingViewH;
    chatListViewPaddingTop += blurredViewTopOffset;
    chatListViewPaddingVisibleOffset = 0;
    chatListViewPaddingTop += contentPanTranslation + bottomPanelTranslationY;
    if (bottomPanelTranslationY == 0 && !chatActivityEnterView.pannelAniamationInProgress() && (contentView.getLayoutParams().height < 0 || (contentView.getKeyboardHeight() <= AndroidUtilities.dp(20) && chatActivityEnterView.isPopupShowing()))) {
        chatListViewPaddingTop += contentView.getKeyboardHeight() <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !inBubbleMode ? chatActivityEnterView.getEmojiPadding() : contentView.getKeyboardHeight();
    }
    if (!inPreviewMode && chatActivityEnterView != null) {
        if (chatActivityEnterView.getAnimatedTop() != 0) {
            chatListViewPaddingTop += chatActivityEnterView.getHeightWithTopView() - AndroidUtilities.dp(51) - chatActivityEnterView.getAnimatedTop();
        } else if (!chatActivityEnterView.pannelAniamationInProgress()) {
            chatListViewPaddingTop += chatActivityEnterView.getHeightWithTopView() - AndroidUtilities.dp(51);
            if (chatActivityEnterView.currentTopViewAnimation == null) {
                chatListViewPaddingTop -= chatListView.getTranslationY();
            }
        }
    }
    if (infoTopView != null) {
        infoTopView.setTranslationY(chatListViewPaddingTop - AndroidUtilities.dp(30) + topViewOffset);
        chatListViewPaddingTop += topViewOffset;
        chatListViewPaddingVisibleOffset += topViewOffset;
    }
    if (floatingDateView != null) {
        floatingDateView.setTranslationY(chatListView.getTranslationY() + chatListViewPaddingTop + floatingDateViewOffset - AndroidUtilities.dp(4));
    }
    int p = chatListView.getMeasuredHeight() * 2 / 3;
    if (chatListView != null && chatLayoutManager != null && chatAdapter != null) {
        if (chatListView.getPaddingTop() != p) {
            int firstVisPos = chatLayoutManager.findFirstVisibleItemPosition();
            int lastVisPos = chatLayoutManager.findLastVisibleItemPosition();
            int top = 0;
            MessageObject scrollToMessageObject = null;
            if (firstVisPos != RecyclerView.NO_POSITION) {
                for (int i = firstVisPos; i <= lastVisPos; i++) {
                    View v = chatLayoutManager.findViewByPosition(i);
                    if (v instanceof ChatMessageCell) {
                        scrollToMessageObject = ((ChatMessageCell) v).getMessageObject();
                        top = chatListView.getMeasuredHeight() - v.getBottom() - chatListView.getPaddingBottom();
                        break;
                    } else if (v instanceof ChatActionCell) {
                        scrollToMessageObject = ((ChatActionCell) v).getMessageObject();
                        top = chatListView.getMeasuredHeight() - v.getBottom() - chatListView.getPaddingBottom();
                        break;
                    }
                }
            }
            chatListView.setPadding(0, p, 0, AndroidUtilities.dp(3) + blurredViewBottomOffset);
            if (firstVisPos != RecyclerView.NO_POSITION && scrollToMessageObject != null) {
                chatAdapter.updateRowsSafe();
                int index = messages.indexOf(scrollToMessageObject);
                if (index >= 0) {
                    chatLayoutManager.scrollToPositionWithOffset(chatAdapter.messagesStartRow + index, top);
                }
            }
            invalidateMessagesVisiblePart();
        }
        chatListView.setTopGlowOffset((int) (chatListViewPaddingTop - chatListViewPaddingVisibleOffset - AndroidUtilities.dp(4)));
        if (oldPadding != chatListViewPaddingTop) {
            int n = chatListView.getChildCount();
            for (int i = 0; i < n; i++) {
                View child = chatListView.getChildAt(i);
                int adapterPosition = chatListView.getChildAdapterPosition(child);
                if (adapterPosition == chatAdapter.getItemCount() - 1) {
                    float padding = chatListViewPaddingTop;
                    if (isThreadChat() && pinnedMessageView != null && pinnedMessageView.getVisibility() == View.VISIBLE) {
                        padding -= Math.max(0, AndroidUtilities.dp(48) + pinnedMessageEnterOffset);
                    }
                    if (child.getTop() > padding) {
                        chatListView.scrollBy(0, (int) (child.getTop() - padding));
                    }
                    break;
                }
            }
        }
        if (!isThreadChat() && !wasManualScroll && unreadMessageObject != null && chatListView != null) {
            chatListView.scrollBy(0, (int) (oldPadding - chatListViewPaddingTop));
        }
    }
    invalidateChatListViewTopPadding = false;
}
Also used : ChatActionCell(org.telegram.ui.Cells.ChatActionCell) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) HorizontalScrollView(android.widget.HorizontalScrollView) PinnedLineView(org.telegram.ui.Components.PinnedLineView) BotCommandsMenuView(org.telegram.ui.Components.BotCommandsMenuView) ReactedHeaderView(org.telegram.ui.Components.ReactedHeaderView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) RecyclerView(androidx.recyclerview.widget.RecyclerView) BluredView(org.telegram.ui.Components.BluredView) InstantCameraView(org.telegram.ui.Components.InstantCameraView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) ChatActivityEnterTopView(org.telegram.ui.Components.ChatActivityEnterTopView) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) BackupImageView(org.telegram.ui.Components.BackupImageView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) UndoView(org.telegram.ui.Components.UndoView) CounterView(org.telegram.ui.Components.CounterView) HintView(org.telegram.ui.Components.HintView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ClippingImageView(org.telegram.ui.Components.ClippingImageView) EmojiView(org.telegram.ui.Components.EmojiView) ChecksHintView(org.telegram.ui.Components.ChecksHintView) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) SearchCounterView(org.telegram.ui.Components.SearchCounterView) ForwardingPreviewView(org.telegram.ui.Components.ForwardingPreviewView) ReactionTabHolderView(org.telegram.ui.Components.ReactionTabHolderView) TextView(android.widget.TextView) ReactedUsersListView(org.telegram.ui.Components.ReactedUsersListView) NumberTextView(org.telegram.ui.Components.NumberTextView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 55 with MessageObject

use of org.telegram.messenger.MessageObject in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatActivity method deleteHistory.

public void deleteHistory(int dateSelectedStart, int dateSelectedEnd, boolean forAll) {
    chatAdapter.frozenMessages.clear();
    for (int i = 0; i < messages.size(); i++) {
        MessageObject messageObject = messages.get(i);
        if (messageObject.messageOwner.date <= dateSelectedStart || messageObject.messageOwner.date >= dateSelectedEnd) {
            chatAdapter.frozenMessages.add(messageObject);
        }
    }
    if (chatListView != null) {
        chatListView.setEmptyView(null);
    }
    if (chatAdapter.frozenMessages.isEmpty()) {
        showProgressView(true);
    }
    chatAdapter.isFrozen = true;
    chatAdapter.notifyDataSetChanged(true);
    getUndoView().showWithAction(dialog_id, UndoView.ACTION_CLEAR_DATES, () -> {
        getMessagesController().deleteMessagesRange(dialog_id, ChatObject.isChannel(currentChat) ? dialog_id : 0, dateSelectedStart, dateSelectedEnd, forAll, () -> {
            chatAdapter.frozenMessages.clear();
            chatAdapter.isFrozen = false;
            chatAdapter.notifyDataSetChanged(true);
            showProgressView(false);
        });
    }, () -> {
        chatAdapter.frozenMessages.clear();
        chatAdapter.isFrozen = false;
        chatAdapter.notifyDataSetChanged(true);
        showProgressView(false);
    });
}
Also used : MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Aggregations

MessageObject (org.telegram.messenger.MessageObject)156 Paint (android.graphics.Paint)107 TLRPC (org.telegram.tgnet.TLRPC)88 SuppressLint (android.annotation.SuppressLint)87 TextPaint (android.text.TextPaint)80 View (android.view.View)59 ArrayList (java.util.ArrayList)59 TextView (android.widget.TextView)53 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)52 RecyclerView (androidx.recyclerview.widget.RecyclerView)50 ImageView (android.widget.ImageView)48 RecyclerListView (org.telegram.ui.Components.RecyclerListView)46 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)39 UndoView (org.telegram.ui.Components.UndoView)36 TextureView (android.view.TextureView)34 File (java.io.File)33 ChatObject (org.telegram.messenger.ChatObject)32 DialogObject (org.telegram.messenger.DialogObject)30 MediaController (org.telegram.messenger.MediaController)30 TLObject (org.telegram.tgnet.TLObject)30