Search in sources :

Example 56 with MessageObject

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

the class ChatActivity method setCellSelectionBackground.

private void setCellSelectionBackground(MessageObject message, ChatMessageCell messageCell, int idx, boolean animated) {
    MessageObject.GroupedMessages groupedMessages = getValidGroupedMessage(message);
    if (groupedMessages != null) {
        boolean hasUnselected = false;
        for (int a = 0; a < groupedMessages.messages.size(); a++) {
            if (selectedMessagesIds[idx].indexOfKey(groupedMessages.messages.get(a).getId()) < 0) {
                hasUnselected = true;
                break;
            }
        }
        if (!hasUnselected) {
            groupedMessages = null;
        }
    }
    messageCell.setDrawSelectionBackground(groupedMessages == null);
    messageCell.setChecked(true, groupedMessages == null, animated);
}
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 57 with MessageObject

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

the class ChatActivity method onConfigurationChanged.

@Override
public void onConfigurationChanged(android.content.res.Configuration newConfig) {
    fixLayout();
    if (visibleDialog instanceof DatePickerDialog) {
        visibleDialog.dismiss();
    }
    closeMenu();
    if (!AndroidUtilities.isTablet()) {
        if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
            if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isVisible()) {
                return;
            }
            MessageObject message = MediaController.getInstance().getPlayingMessageObject();
            if (message != null && message.isVideo()) {
                PhotoViewer.getInstance().setParentActivity(getParentActivity(), themeDelegate);
                getFileLoader().setLoadingVideoForPlayer(message.getDocument(), false);
                MediaController.getInstance().cleanupPlayer(true, true, false, true);
                if (PhotoViewer.getInstance().openPhoto(message, message.type != 0 ? dialog_id : 0, message.type != 0 ? mergeDialogId : 0, photoViewerProvider, false)) {
                    PhotoViewer.getInstance().setParentChatActivity(ChatActivity.this);
                }
                hideHints(false);
                MediaController.getInstance().resetGoingToShowMessageObject();
            }
        } else if (PhotoViewer.hasInstance() && PhotoViewer.getInstance().isOpenedFullScreenVideo()) {
            PhotoViewer.getInstance().injectVideoPlayerToMediaController();
            PhotoViewer.getInstance().closePhoto(false, true);
        }
    }
}
Also used : DatePickerDialog(android.app.DatePickerDialog) MessageObject(org.telegram.messenger.MessageObject)

Example 58 with MessageObject

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

the class ChatActivity method getPlaceForPhoto.

private PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, boolean needPreview, boolean onlyIfVisible) {
    int count = chatListView.getChildCount();
    for (int a = 0; a < count; a++) {
        ImageReceiver imageReceiver = null;
        View view = chatListView.getChildAt(a);
        if (view instanceof ChatMessageCell) {
            if (messageObject != null) {
                ChatMessageCell cell = (ChatMessageCell) view;
                MessageObject message = cell.getMessageObject();
                if (message != null && message.getId() == messageObject.getId()) {
                    imageReceiver = cell.getPhotoImage();
                }
            }
        } else if (view instanceof ChatActionCell) {
            ChatActionCell cell = (ChatActionCell) view;
            MessageObject message = cell.getMessageObject();
            if (message != null) {
                if (messageObject != null) {
                    if (message.getId() == messageObject.getId()) {
                        imageReceiver = cell.getPhotoImage();
                    }
                } else if (fileLocation != null && message.photoThumbs != null) {
                    for (int b = 0; b < message.photoThumbs.size(); b++) {
                        TLRPC.PhotoSize photoSize = message.photoThumbs.get(b);
                        if (photoSize.location != null && photoSize.location.volume_id == fileLocation.volume_id && photoSize.location.local_id == fileLocation.local_id) {
                            imageReceiver = cell.getPhotoImage();
                            break;
                        }
                    }
                }
            }
        }
        if (imageReceiver != null) {
            if (onlyIfVisible && view.getY() + imageReceiver.getImageY2() < chatListViewPaddingTop - AndroidUtilities.dp(4)) {
                return null;
            }
            int[] coords = new int[2];
            view.getLocationInWindow(coords);
            PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
            object.viewX = coords[0];
            object.viewY = coords[1] - (Build.VERSION.SDK_INT >= 21 ? 0 : AndroidUtilities.statusBarHeight);
            object.parentView = chatListView;
            object.animatingImageView = !SharedConfig.smoothKeyboard && pagedownButton != null && pagedownButton.getTag() != null && view instanceof ChatMessageCell ? animatingImageView : null;
            object.imageReceiver = imageReceiver;
            if (needPreview) {
                object.thumb = imageReceiver.getBitmapSafe();
            }
            object.radius = imageReceiver.getRoundRadius();
            if (view instanceof ChatActionCell && currentChat != null) {
                object.dialogId = -currentChat.id;
            }
            object.clipTopAddition = (int) (chatListViewPaddingTop - chatListViewPaddingVisibleOffset - AndroidUtilities.dp(4));
            return object;
        }
    }
    return null;
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) 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) TLRPC(org.telegram.tgnet.TLRPC)

Example 59 with MessageObject

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

the class ChatActivity method addToSelectedMessages.

private void addToSelectedMessages(MessageObject messageObject, boolean outside, boolean last) {
    int prevCantForwardCount = cantForwardMessagesCount;
    if (messageObject != null) {
        if (threadMessageObjects != null && threadMessageObjects.contains(messageObject)) {
            return;
        }
        int index = messageObject.getDialogId() == dialog_id ? 0 : 1;
        if (outside && messageObject.getGroupId() != 0) {
            boolean hasUnselected = false;
            MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId());
            if (groupedMessages != null) {
                int lastNum = 0;
                for (int a = 0; a < groupedMessages.messages.size(); a++) {
                    MessageObject message = groupedMessages.messages.get(a);
                    if (selectedMessagesIds[index].indexOfKey(message.getId()) < 0) {
                        hasUnselected = true;
                        lastNum = a;
                    }
                }
                for (int a = 0; a < groupedMessages.messages.size(); a++) {
                    MessageObject message = groupedMessages.messages.get(a);
                    if (hasUnselected) {
                        if (selectedMessagesIds[index].indexOfKey(message.getId()) < 0) {
                            addToSelectedMessages(message, false, a == lastNum);
                        }
                    } else {
                        addToSelectedMessages(message, false, a == groupedMessages.messages.size() - 1);
                    }
                    if (!TextUtils.isEmpty(message.caption)) {
                        showTextSelectionHint(messageObject);
                    }
                }
            }
            return;
        }
        if (selectedMessagesIds[index].indexOfKey(messageObject.getId()) >= 0) {
            selectedMessagesIds[index].remove(messageObject.getId());
            if (reportType < 0) {
                if ((messageObject.type == 0 || messageObject.isAnimatedEmoji() || messageObject.caption != null) && !(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) {
                    selectedMessagesCanCopyIds[index].remove(messageObject.getId());
                }
                if (!messageObject.isAnimatedEmoji() && (messageObject.isSticker() || messageObject.isAnimatedSticker()) && MessageObject.isStickerHasSet(messageObject.getDocument())) {
                    selectedMessagesCanStarIds[index].remove(messageObject.getId());
                }
                if (messageObject.canEditMessage(currentChat)) {
                    canEditMessagesCount--;
                }
                if (!messageObject.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat)) {
                    cantDeleteMessagesCount--;
                }
                boolean noforwards = getMessagesController().isChatNoForwards(currentChat);
                if (chatMode == MODE_SCHEDULED || !messageObject.canForwardMessage() || noforwards) {
                    cantForwardMessagesCount--;
                } else {
                    canForwardMessagesCount--;
                }
                if (messageObject.isMusic() && !noforwards) {
                    canSaveMusicCount--;
                } else if (messageObject.isDocument() && !noforwards) {
                    canSaveDocumentsCount--;
                } else {
                    cantSaveMessagesCount--;
                }
            }
        } else {
            if (selectedMessagesIds[0].size() + selectedMessagesIds[1].size() >= 100) {
                AndroidUtilities.shakeView(selectedMessagesCountTextView, 2, 0);
                Vibrator vibrator = (Vibrator) ApplicationLoader.applicationContext.getSystemService(Context.VIBRATOR_SERVICE);
                if (vibrator != null) {
                    vibrator.vibrate(200);
                }
                return;
            }
            selectedMessagesIds[index].put(messageObject.getId(), messageObject);
            if (reportType < 0) {
                if ((messageObject.type == 0 || messageObject.isAnimatedEmoji() || messageObject.caption != null) && !(messageObject.messageOwner != null && messageObject.messageOwner.noforwards)) {
                    selectedMessagesCanCopyIds[index].put(messageObject.getId(), messageObject);
                }
                if (!messageObject.isAnimatedEmoji() && (messageObject.isSticker() || messageObject.isAnimatedSticker()) && MessageObject.isStickerHasSet(messageObject.getDocument())) {
                    selectedMessagesCanStarIds[index].put(messageObject.getId(), messageObject);
                }
                if (messageObject.canEditMessage(currentChat)) {
                    canEditMessagesCount++;
                }
                if (!messageObject.canDeleteMessage(chatMode == MODE_SCHEDULED, currentChat)) {
                    cantDeleteMessagesCount++;
                }
                boolean noforwards = getMessagesController().isChatNoForwards(currentChat);
                if (chatMode == MODE_SCHEDULED || !messageObject.canForwardMessage() || noforwards) {
                    cantForwardMessagesCount++;
                } else {
                    canForwardMessagesCount++;
                }
                if (messageObject.isMusic() && !noforwards) {
                    canSaveMusicCount++;
                } else if (messageObject.isDocument() && !noforwards) {
                    canSaveDocumentsCount++;
                } else {
                    cantSaveMessagesCount++;
                }
                if (outside) {
                    showTextSelectionHint(messageObject);
                }
            }
        }
    }
    if (forwardButtonAnimation != null) {
        forwardButtonAnimation.cancel();
        forwardButtonAnimation = null;
    }
    if (last && actionBar.isActionModeShowed() && reportType < 0) {
        int selectedCount = selectedMessagesIds[0].size() + selectedMessagesIds[1].size();
        if (selectedCount == 0) {
            hideActionMode();
            updatePinnedMessageView(true);
        } else {
            ActionBarMenuItem saveItem = actionBar.createActionMode().getItem(save_to);
            ActionBarMenuItem copyItem = actionBar.createActionMode().getItem(copy);
            ActionBarMenuItem starItem = actionBar.createActionMode().getItem(star);
            ActionBarMenuItem editItem = actionBar.createActionMode().getItem(edit);
            ActionBarMenuItem forwardItem = actionBar.createActionMode().getItem(forward);
            boolean noforwards = getMessagesController().isChatNoForwards(currentChat) || hasSelectedNoforwardsMessage();
            if (prevCantForwardCount == 0 && cantForwardMessagesCount != 0 || prevCantForwardCount != 0 && cantForwardMessagesCount == 0) {
                forwardButtonAnimation = new AnimatorSet();
                ArrayList<Animator> animators = new ArrayList<>();
                if (forwardItem != null) {
                    forwardItem.setEnabled(cantForwardMessagesCount == 0 || noforwards);
                    animators.add(ObjectAnimator.ofFloat(forwardItem, View.ALPHA, cantForwardMessagesCount == 0 ? 1.0f : 0.5f));
                    if (noforwards && forwardItem.getBackground() != null) {
                        forwardItem.setBackground(null);
                    } else if (forwardItem.getBackground() == null) {
                        forwardItem.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 5));
                    }
                }
                if (forwardButton != null) {
                    forwardButton.setEnabled(cantForwardMessagesCount == 0 || noforwards);
                    if (noforwards && forwardButton.getBackground() != null) {
                        forwardButton.setBackground(null);
                    } else if (forwardButton.getBackground() == null) {
                        forwardButton.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
                    }
                    animators.add(ObjectAnimator.ofFloat(forwardButton, View.ALPHA, cantForwardMessagesCount == 0 ? 1.0f : 0.5f));
                }
                forwardButtonAnimation.playTogether(animators);
                forwardButtonAnimation.setDuration(100);
                forwardButtonAnimation.addListener(new AnimatorListenerAdapter() {

                    @Override
                    public void onAnimationEnd(Animator animation) {
                        forwardButtonAnimation = null;
                    }
                });
                forwardButtonAnimation.start();
            } else {
                if (forwardItem != null) {
                    forwardItem.setEnabled(cantForwardMessagesCount == 0 || noforwards);
                    forwardItem.setAlpha(cantForwardMessagesCount == 0 ? 1.0f : 0.5f);
                    if (noforwards) {
                        if (forwardItem.getBackground() != null)
                            forwardButton.setBackground(null);
                    } else if (forwardItem.getBackground() == null) {
                        forwardItem.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
                    }
                }
                if (forwardButton != null) {
                    forwardButton.setEnabled(cantForwardMessagesCount == 0 || noforwards);
                    if (noforwards) {
                        if (forwardButton.getBackground() != null)
                            forwardButton.setBackground(null);
                    } else if (forwardButton.getBackground() == null) {
                        forwardButton.setBackground(Theme.createSelectorDrawable(getThemedColor(Theme.key_actionBarActionModeDefaultSelector), 3));
                    }
                    forwardButton.setAlpha(cantForwardMessagesCount == 0 ? 1.0f : 0.5f);
                }
            }
            if (saveItem != null) {
                saveItem.setVisibility(((canSaveMusicCount > 0 && canSaveDocumentsCount == 0) || (canSaveMusicCount == 0 && canSaveDocumentsCount > 0)) && cantSaveMessagesCount == 0 ? View.VISIBLE : View.GONE);
                saveItem.setContentDescription(canSaveMusicCount > 0 ? LocaleController.getString("SaveToMusic", R.string.SaveToMusic) : LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
            }
            int copyVisible = copyItem.getVisibility();
            int starVisible = starItem.getVisibility();
            copyItem.setVisibility(!noforwards && selectedMessagesCanCopyIds[0].size() + selectedMessagesCanCopyIds[1].size() != 0 ? View.VISIBLE : View.GONE);
            starItem.setVisibility(getMediaDataController().canAddStickerToFavorites() && (selectedMessagesCanStarIds[0].size() + selectedMessagesCanStarIds[1].size()) == selectedCount ? View.VISIBLE : View.GONE);
            int newCopyVisible = copyItem.getVisibility();
            int newStarVisible = starItem.getVisibility();
            actionBar.createActionMode().getItem(delete).setVisibility(cantDeleteMessagesCount == 0 ? View.VISIBLE : View.GONE);
            hasUnfavedSelected = false;
            for (int a = 0; a < 2; a++) {
                for (int b = 0; b < selectedMessagesCanStarIds[a].size(); b++) {
                    MessageObject msg = selectedMessagesCanStarIds[a].valueAt(b);
                    if (!getMediaDataController().isStickerInFavorites(msg.getDocument())) {
                        hasUnfavedSelected = true;
                        break;
                    }
                }
                if (hasUnfavedSelected) {
                    break;
                }
            }
            starItem.setIcon(hasUnfavedSelected ? R.drawable.msg_fave : R.drawable.msg_unfave);
            final int newEditVisibility = canEditMessagesCount == 1 && selectedCount == 1 ? View.VISIBLE : View.GONE;
            if (replyButton != null) {
                boolean allowChatActions = true;
                if (bottomOverlayChat != null && bottomOverlayChat.getVisibility() == View.VISIBLE || currentChat != null && (ChatObject.isNotInChat(currentChat) && !isThreadChat() || ChatObject.isChannel(currentChat) && !ChatObject.canPost(currentChat) && !currentChat.megagroup || !ChatObject.canSendMessages(currentChat))) {
                    allowChatActions = false;
                }
                int newVisibility;
                if (chatMode == MODE_SCHEDULED || !allowChatActions || selectedMessagesIds[0].size() != 0 && selectedMessagesIds[1].size() != 0) {
                    newVisibility = View.GONE;
                } else if (selectedCount == 1) {
                    newVisibility = View.VISIBLE;
                } else {
                    newVisibility = View.VISIBLE;
                    long lastGroupId = 0;
                    for (int a = 0; a < 2; a++) {
                        for (int b = 0, N = selectedMessagesIds[a].size(); b < N; b++) {
                            MessageObject message = selectedMessagesIds[a].valueAt(b);
                            long groupId = message.getGroupId();
                            if (groupId == 0 || lastGroupId != 0 && lastGroupId != groupId) {
                                newVisibility = View.GONE;
                                break;
                            }
                            lastGroupId = groupId;
                        }
                        if (newVisibility == View.GONE) {
                            break;
                        }
                    }
                }
                if (threadMessageObjects != null && newVisibility == View.VISIBLE) {
                    for (int b = 0, N = selectedMessagesIds[0].size(); b < N; b++) {
                        MessageObject message = selectedMessagesIds[0].valueAt(b);
                        if (threadMessageObjects.contains(message)) {
                            newVisibility = View.GONE;
                        }
                    }
                }
                if (replyButton.getVisibility() != newVisibility) {
                    if (replyButtonAnimation != null) {
                        replyButtonAnimation.cancel();
                    }
                    replyButtonAnimation = new AnimatorSet();
                    if (newVisibility == View.VISIBLE) {
                        replyButton.setVisibility(newVisibility);
                        replyButtonAnimation.playTogether(ObjectAnimator.ofFloat(replyButton, View.ALPHA, 1.0f), ObjectAnimator.ofFloat(replyButton, View.SCALE_Y, 1.0f));
                    } else {
                        replyButtonAnimation.playTogether(ObjectAnimator.ofFloat(replyButton, View.ALPHA, 0.0f), ObjectAnimator.ofFloat(replyButton, View.SCALE_Y, 0.0f));
                    }
                    replyButtonAnimation.setDuration(100);
                    int newVisibilityFinal = newVisibility;
                    replyButtonAnimation.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
                                if (newVisibilityFinal == View.GONE) {
                                    replyButton.setVisibility(View.GONE);
                                }
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            if (replyButtonAnimation != null && replyButtonAnimation.equals(animation)) {
                                replyButtonAnimation = null;
                            }
                        }
                    });
                    replyButtonAnimation.start();
                }
            }
            if (editItem != null) {
                if (copyVisible != newCopyVisible || starVisible != newStarVisible) {
                    if (newEditVisibility == View.VISIBLE) {
                        editItem.setAlpha(1.0f);
                        editItem.setScaleX(1.0f);
                    } else {
                        editItem.setAlpha(0.0f);
                        editItem.setScaleX(0.0f);
                    }
                    editItem.setVisibility(newEditVisibility);
                } else if (editItem.getVisibility() != newEditVisibility) {
                    if (editButtonAnimation != null) {
                        editButtonAnimation.cancel();
                    }
                    editButtonAnimation = new AnimatorSet();
                    editItem.setPivotX(AndroidUtilities.dp(54));
                    editItem.setPivotX(AndroidUtilities.dp(54));
                    if (newEditVisibility == View.VISIBLE) {
                        editItem.setVisibility(newEditVisibility);
                        editButtonAnimation.playTogether(ObjectAnimator.ofFloat(editItem, View.ALPHA, 1.0f), ObjectAnimator.ofFloat(editItem, View.SCALE_X, 1.0f));
                    } else {
                        editButtonAnimation.playTogether(ObjectAnimator.ofFloat(editItem, View.ALPHA, 0.0f), ObjectAnimator.ofFloat(editItem, View.SCALE_X, 0.0f));
                    }
                    editButtonAnimation.setDuration(100);
                    editButtonAnimation.addListener(new AnimatorListenerAdapter() {

                        @Override
                        public void onAnimationEnd(Animator animation) {
                            if (editButtonAnimation != null && editButtonAnimation.equals(animation)) {
                                if (newEditVisibility == View.GONE) {
                                    editItem.setVisibility(View.GONE);
                                }
                            }
                        }

                        @Override
                        public void onAnimationCancel(Animator animation) {
                            if (editButtonAnimation != null && editButtonAnimation.equals(animation)) {
                                editButtonAnimation = null;
                            }
                        }
                    });
                    editButtonAnimation.start();
                }
            }
        }
    }
}
Also used : ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Animator(android.animation.Animator) ChatListItemAnimator(androidx.recyclerview.widget.ChatListItemAnimator) ValueAnimator(android.animation.ValueAnimator) ObjectAnimator(android.animation.ObjectAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ArrayList(java.util.ArrayList) AnimatorSet(android.animation.AnimatorSet) Vibrator(android.os.Vibrator) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint)

Example 60 with MessageObject

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

the class ChatActivity method startMultiselect.

private void startMultiselect(int position) {
    int indexOfMessage = position - chatAdapter.messagesStartRow;
    if (indexOfMessage < 0 || indexOfMessage >= messages.size()) {
        return;
    }
    MessageObject messageObject = messages.get(indexOfMessage);
    final boolean unselect = selectedMessagesIds[0].get(messageObject.getId(), null) == null && selectedMessagesIds[1].get(messageObject.getId(), null) == null;
    SparseArray<MessageObject> alreadySelectedMessagesIds = new SparseArray<>();
    for (int i = 0; i < selectedMessagesIds[0].size(); i++) {
        alreadySelectedMessagesIds.put(selectedMessagesIds[0].keyAt(i), selectedMessagesIds[0].valueAt(i));
    }
    for (int i = 0; i < selectedMessagesIds[1].size(); i++) {
        alreadySelectedMessagesIds.put(selectedMessagesIds[1].keyAt(i), selectedMessagesIds[1].valueAt(i));
    }
    chatListView.startMultiselect(position, false, new RecyclerListView.onMultiSelectionChanged() {

        boolean limitReached;

        @Override
        public void onSelectionChanged(int position, boolean selected, float x, float y) {
            int i = position - chatAdapter.messagesStartRow;
            if (unselect) {
                selected = !selected;
            }
            if (i >= 0 && i < messages.size()) {
                MessageObject messageObject = messages.get(i);
                if (selected && (selectedMessagesIds[0].indexOfKey(messageObject.getId()) >= 0 || selectedMessagesIds[1].indexOfKey(messageObject.getId()) >= 0)) {
                    return;
                }
                if (!selected && selectedMessagesIds[0].indexOfKey(messageObject.getId()) < 0 && selectedMessagesIds[1].indexOfKey(messageObject.getId()) < 0) {
                    return;
                }
                if (messageObject.contentType == 0) {
                    if (selected && selectedMessagesIds[0].size() + selectedMessagesIds[1].size() >= 100) {
                        limitReached = true;
                    } else {
                        limitReached = false;
                    }
                    RecyclerView.ViewHolder holder = chatListView.findViewHolderForAdapterPosition(position);
                    if (holder != null && holder.itemView instanceof ChatMessageCell) {
                        processRowSelect(holder.itemView, false, x, y);
                    } else {
                        addToSelectedMessages(messageObject, false);
                        updateActionModeTitle();
                        updateVisibleRows();
                    }
                }
            }
        }

        @Override
        public boolean canSelect(int position) {
            int i = position - chatAdapter.messagesStartRow;
            if (i >= 0 && i < messages.size()) {
                MessageObject messageObject = messages.get(i);
                if (messageObject.contentType == 0) {
                    if (!unselect && alreadySelectedMessagesIds.get(messageObject.getId(), null) == null) {
                        return true;
                    }
                    if (unselect && alreadySelectedMessagesIds.get(messageObject.getId(), null) != null) {
                        return true;
                    }
                }
            }
            return false;
        }

        @Override
        public int checkPosition(int position, boolean selectionTop) {
            int i = position - chatAdapter.messagesStartRow;
            if (i >= 0 && i < messages.size()) {
                MessageObject messageObject = messages.get(i);
                if (messageObject.contentType == 0 && messageObject.hasValidGroupId()) {
                    MessageObject.GroupedMessages groupedMessages = groupedMessagesMap.get(messageObject.getGroupId());
                    if (groupedMessages != null) {
                        MessageObject messageObject1 = groupedMessages.messages.get(selectionTop ? 0 : groupedMessages.messages.size() - 1);
                        return chatAdapter.messagesStartRow + messages.indexOf(messageObject1);
                    }
                }
            }
            return position;
        }

        @Override
        public boolean limitReached() {
            return limitReached;
        }

        @Override
        public void getPaddings(int[] paddings) {
            paddings[0] = (int) chatListViewPaddingTop;
            paddings[1] = 0;
        }

        @Override
        public void scrollBy(int dy) {
            chatListView.scrollBy(0, dy);
        }
    });
}
Also used : RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) SparseArray(android.util.SparseArray) LongSparseArray(androidx.collection.LongSparseArray) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) MessageObject(org.telegram.messenger.MessageObject)

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