Search in sources :

Example 1 with ChatMessageCell

use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChannelAdminLogActivity method createMenu.

private void createMenu(View v) {
    MessageObject message = null;
    if (v instanceof ChatMessageCell) {
        message = ((ChatMessageCell) v).getMessageObject();
    } else if (v instanceof ChatActionCell) {
        message = ((ChatActionCell) v).getMessageObject();
    }
    if (message == null) {
        return;
    }
    final int type = getMessageType(message);
    selectedObject = message;
    if (getParentActivity() == null) {
        return;
    }
    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
    ArrayList<CharSequence> items = new ArrayList<>();
    final ArrayList<Integer> options = new ArrayList<>();
    if (selectedObject.type == 0 || selectedObject.caption != null) {
        items.add(LocaleController.getString("Copy", R.string.Copy));
        options.add(3);
    }
    if (type == 1) {
        if (selectedObject.currentEvent != null && selectedObject.currentEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeStickerSet) {
            TLRPC.TL_channelAdminLogEventActionChangeStickerSet action = (TLRPC.TL_channelAdminLogEventActionChangeStickerSet) selectedObject.currentEvent.action;
            TLRPC.InputStickerSet stickerSet = action.new_stickerset;
            if (stickerSet == null || stickerSet instanceof TLRPC.TL_inputStickerSetEmpty) {
                stickerSet = action.prev_stickerset;
            }
            if (stickerSet != null) {
                showDialog(new StickersAlert(getParentActivity(), ChannelAdminLogActivity.this, stickerSet, null, null));
                return;
            }
        } else if (selectedObject.currentEvent != null && selectedObject.currentEvent.action instanceof TLRPC.TL_channelAdminLogEventActionChangeHistoryTTL) {
            if (ChatObject.canUserDoAdminAction(currentChat, ChatObject.ACTION_DELETE_MESSAGES)) {
                ClearHistoryAlert alert = new ClearHistoryAlert(getParentActivity(), null, currentChat, false, null);
                alert.setDelegate(new ClearHistoryAlert.ClearHistoryAlertDelegate() {

                    @Override
                    public void onAutoDeleteHistory(int ttl, int action) {
                        getMessagesController().setDialogHistoryTTL(-currentChat.id, ttl);
                        TLRPC.ChatFull chatInfo = getMessagesController().getChatFull(currentChat.id);
                        if (chatInfo != null) {
                            undoView.showWithAction(-currentChat.id, action, null, chatInfo.ttl_period, null, null);
                        }
                    }
                });
                showDialog(alert);
            }
        }
    } else if (type == 3) {
        if (selectedObject.messageOwner.media instanceof TLRPC.TL_messageMediaWebPage && MessageObject.isNewGifDocument(selectedObject.messageOwner.media.webpage.document)) {
            items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
            options.add(11);
        }
    } else if (type == 4) {
        if (selectedObject.isVideo()) {
            items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
            options.add(4);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else if (selectedObject.isMusic()) {
            items.add(LocaleController.getString("SaveToMusic", R.string.SaveToMusic));
            options.add(10);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else if (selectedObject.getDocument() != null) {
            if (MessageObject.isNewGifDocument(selectedObject.getDocument())) {
                items.add(LocaleController.getString("SaveToGIFs", R.string.SaveToGIFs));
                options.add(11);
            }
            items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
            options.add(10);
            items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
            options.add(6);
        } else {
            items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
            options.add(4);
        }
    } else if (type == 5) {
        items.add(LocaleController.getString("ApplyLocalizationFile", R.string.ApplyLocalizationFile));
        options.add(5);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 10) {
        items.add(LocaleController.getString("ApplyThemeFile", R.string.ApplyThemeFile));
        options.add(5);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 6) {
        items.add(LocaleController.getString("SaveToGallery", R.string.SaveToGallery));
        options.add(7);
        items.add(LocaleController.getString("SaveToDownloads", R.string.SaveToDownloads));
        options.add(10);
        items.add(LocaleController.getString("ShareFile", R.string.ShareFile));
        options.add(6);
    } else if (type == 7) {
        if (selectedObject.isMask()) {
            items.add(LocaleController.getString("AddToMasks", R.string.AddToMasks));
        } else {
            items.add(LocaleController.getString("AddToStickers", R.string.AddToStickers));
        }
        options.add(9);
    } else if (type == 8) {
        long uid = selectedObject.messageOwner.media.user_id;
        TLRPC.User user = null;
        if (uid != 0) {
            user = MessagesController.getInstance(currentAccount).getUser(uid);
        }
        if (user != null && user.id != UserConfig.getInstance(currentAccount).getClientUserId() && ContactsController.getInstance(currentAccount).contactsDict.get(user.id) == null) {
            items.add(LocaleController.getString("AddContactTitle", R.string.AddContactTitle));
            options.add(15);
        }
        if (!TextUtils.isEmpty(selectedObject.messageOwner.media.phone_number)) {
            items.add(LocaleController.getString("Copy", R.string.Copy));
            options.add(16);
            items.add(LocaleController.getString("Call", R.string.Call));
            options.add(17);
        }
    }
    if (options.isEmpty()) {
        return;
    }
    final CharSequence[] finalItems = items.toArray(new CharSequence[0]);
    builder.setItems(finalItems, (dialogInterface, i) -> {
        if (selectedObject == null || i < 0 || i >= options.size()) {
            return;
        }
        processSelectedOption(options.get(i));
    });
    builder.setTitle(LocaleController.getString("Message", R.string.Message));
    showDialog(builder.create());
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) ClearHistoryAlert(org.telegram.ui.Components.ClearHistoryAlert) Paint(android.graphics.Paint) StickersAlert(org.telegram.ui.Components.StickersAlert) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) MessageObject(org.telegram.messenger.MessageObject)

Example 2 with ChatMessageCell

use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChannelAdminLogActivity method updateTextureViewPosition.

private void updateTextureViewPosition() {
    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 (roundVideoContainer != null && messageObject.isRoundVideo() && MediaController.getInstance().isPlayingMessage(messageObject)) {
                ImageReceiver imageReceiver = messageCell.getPhotoImage();
                roundVideoContainer.setTranslationX(imageReceiver.getImageX());
                roundVideoContainer.setTranslationY(fragmentView.getPaddingTop() + messageCell.getTop() + imageReceiver.getImageY());
                fragmentView.invalidate();
                roundVideoContainer.invalidate();
                foundTextureViewMessage = true;
                break;
            }
        }
    }
    if (roundVideoContainer != null) {
        MessageObject messageObject = MediaController.getInstance().getPlayingMessageObject();
        if (!foundTextureViewMessage) {
            roundVideoContainer.setTranslationY(-AndroidUtilities.roundMessageSize - 100);
            fragmentView.invalidate();
            if (messageObject != null && messageObject.isRoundVideo()) {
                if (checkTextureViewPosition || PipRoundVideoView.getInstance() != null) {
                    MediaController.getInstance().setCurrentVideoVisible(false);
                }
            }
        } else {
            MediaController.getInstance().setCurrentVideoVisible(true);
        }
    }
}
Also used : ImageReceiver(org.telegram.messenger.ImageReceiver) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) UndoView(org.telegram.ui.Components.UndoView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextureView(android.view.TextureView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) MessageObject(org.telegram.messenger.MessageObject) Paint(android.graphics.Paint)

Example 3 with ChatMessageCell

use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatListItemAnimator method animateAddImpl.

public void animateAddImpl(final RecyclerView.ViewHolder holder, int addedItemsHeight) {
    final View view = holder.itemView;
    final ViewPropertyAnimator animation = view.animate();
    mAddAnimations.add(holder);
    view.setTranslationY(addedItemsHeight);
    holder.itemView.setScaleX(1);
    holder.itemView.setScaleY(1);
    ChatMessageCell chatMessageCell = holder.itemView instanceof ChatMessageCell ? (ChatMessageCell) holder.itemView : null;
    if (!(chatMessageCell != null && chatMessageCell.getTransitionParams().ignoreAlpha)) {
        holder.itemView.setAlpha(1);
    }
    if (chatMessageCell != null && activity.animatingMessageObjects.contains(chatMessageCell.getMessageObject())) {
        activity.animatingMessageObjects.remove(chatMessageCell.getMessageObject());
        if (activity.getChatActivityEnterView().canShowMessageTransition()) {
            if (chatMessageCell.getMessageObject().isVoice()) {
                if (Math.abs(view.getTranslationY()) < view.getMeasuredHeight() * 3f) {
                    VoiceMessageEnterTransition transition = new VoiceMessageEnterTransition(chatMessageCell, activity.getChatActivityEnterView(), recyclerListView, activity.messageEnterTransitionContainer, resourcesProvider);
                    transition.start();
                }
            } else {
                if (SharedConfig.getDevicePerformanceClass() != SharedConfig.PERFORMANCE_CLASS_LOW && Math.abs(view.getTranslationY()) < recyclerListView.getMeasuredHeight()) {
                    TextMessageEnterTransition transition = new TextMessageEnterTransition(chatMessageCell, activity, recyclerListView, activity.messageEnterTransitionContainer, resourcesProvider);
                    transition.start();
                }
            }
            activity.getChatActivityEnterView().startMessageTransition();
        }
    }
    animation.translationY(0).setDuration(getMoveDuration()).setInterpolator(translationInterpolator).setListener(new AnimatorListenerAdapter() {

        @Override
        public void onAnimationStart(Animator animator) {
            dispatchAddStarting(holder);
        }

        @Override
        public void onAnimationCancel(Animator animator) {
            view.setTranslationY(0);
            if (view instanceof ChatMessageCell) {
                ((ChatMessageCell) view).getTransitionParams().messageEntering = false;
            }
        }

        @Override
        public void onAnimationEnd(Animator animator) {
            if (view instanceof ChatMessageCell) {
                ((ChatMessageCell) view).getTransitionParams().messageEntering = false;
            }
            animation.setListener(null);
            if (mAddAnimations.remove(holder)) {
                dispatchAddFinished(holder);
                dispatchFinishedWhenDone();
            }
        }
    }).start();
}
Also used : ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) ViewPropertyAnimator(android.view.ViewPropertyAnimator) ValueAnimator(android.animation.ValueAnimator) TextMessageEnterTransition(org.telegram.ui.TextMessageEnterTransition) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) View(android.view.View) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewPropertyAnimator(android.view.ViewPropertyAnimator) VoiceMessageEnterTransition(org.telegram.ui.VoiceMessageEnterTransition)

Example 4 with ChatMessageCell

use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatListItemAnimator method recordPreLayoutInformation.

@NonNull
@Override
public ItemHolderInfo recordPreLayoutInformation(@NonNull RecyclerView.State state, @NonNull RecyclerView.ViewHolder viewHolder, int changeFlags, @NonNull List<Object> payloads) {
    ItemHolderInfo info = super.recordPreLayoutInformation(state, viewHolder, changeFlags, payloads);
    if (viewHolder.itemView instanceof ChatMessageCell) {
        ChatMessageCell chatMessageCell = (ChatMessageCell) viewHolder.itemView;
        ItemHolderInfoExtended extended = new ItemHolderInfoExtended();
        extended.left = info.left;
        extended.top = info.top;
        extended.right = info.right;
        extended.bottom = info.bottom;
        ChatMessageCell.TransitionParams params = chatMessageCell.getTransitionParams();
        extended.imageX = params.lastDrawingImageX;
        extended.imageY = params.lastDrawingImageY;
        extended.imageWidth = params.lastDrawingImageW;
        extended.imageHeight = params.lastDrawingImageH;
        return extended;
    }
    return info;
}
Also used : ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) NonNull(androidx.annotation.NonNull)

Example 5 with ChatMessageCell

use of org.telegram.ui.Cells.ChatMessageCell in project Telegram-FOSS by Telegram-FOSS-Team.

the class ChatListItemAnimator method restoreTransitionParams.

private void restoreTransitionParams(View view) {
    view.setAlpha(1f);
    view.setScaleX(1f);
    view.setScaleY(1f);
    view.setTranslationY(0f);
    if (view instanceof BotHelpCell) {
        BotHelpCell botCell = (BotHelpCell) view;
        int top = recyclerListView.getMeasuredHeight() / 2 - view.getMeasuredHeight() / 2;
        botCell.setAnimating(false);
        if (view.getTop() > top) {
            view.setTranslationY(top - view.getTop());
        } else {
            view.setTranslationY(0);
        }
    } else if (view instanceof ChatMessageCell) {
        ((ChatMessageCell) view).getTransitionParams().resetAnimation();
        ((ChatMessageCell) view).setAnimationOffsetX(0f);
    } else {
        view.setTranslationX(0f);
    }
}
Also used : ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) BotHelpCell(org.telegram.ui.Cells.BotHelpCell)

Aggregations

ChatMessageCell (org.telegram.ui.Cells.ChatMessageCell)50 View (android.view.View)36 RecyclerListView (org.telegram.ui.Components.RecyclerListView)36 MessageObject (org.telegram.messenger.MessageObject)33 Paint (android.graphics.Paint)32 RecyclerView (androidx.recyclerview.widget.RecyclerView)29 TextPaint (android.text.TextPaint)27 ChatGreetingsView (org.telegram.ui.Components.ChatGreetingsView)27 SuppressLint (android.annotation.SuppressLint)25 ImageView (android.widget.ImageView)25 TextView (android.widget.TextView)25 UndoView (org.telegram.ui.Components.UndoView)25 TextureView (android.view.TextureView)24 SimpleTextView (org.telegram.ui.ActionBar.SimpleTextView)24 PipRoundVideoView (org.telegram.ui.Components.PipRoundVideoView)24 RadialProgressView (org.telegram.ui.Components.RadialProgressView)24 TextSelectionHint (org.telegram.ui.Components.TextSelectionHint)24 BackupImageView (org.telegram.ui.Components.BackupImageView)21 HintView (org.telegram.ui.Components.HintView)21 HorizontalScrollView (android.widget.HorizontalScrollView)20