Search in sources :

Example 1 with GroupStickersActivity

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

the class ChatActivityEnterView method createEmojiView.

private void createEmojiView() {
    if (emojiView != null) {
        return;
    }
    emojiView = new EmojiView(allowStickers, allowGifs, getContext(), true, info, sizeNotifierLayout, resourcesProvider) {

        @Override
        public void setTranslationY(float translationY) {
            super.setTranslationY(translationY);
            if (panelAnimation != null && animatingContentType == 0) {
                delegate.bottomPanelTranslationYChanged(translationY);
            }
        }
    };
    emojiView.setVisibility(GONE);
    emojiView.setShowing(false);
    emojiView.setDelegate(new EmojiView.EmojiViewDelegate() {

        @Override
        public boolean onBackspace() {
            if (messageEditText.length() == 0) {
                return false;
            }
            messageEditText.dispatchKeyEvent(new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_DEL));
            return true;
        }

        @Override
        public void onEmojiSelected(String symbol) {
            int i = messageEditText.getSelectionEnd();
            if (i < 0) {
                i = 0;
            }
            try {
                innerTextChange = 2;
                CharSequence localCharSequence = Emoji.replaceEmoji(symbol, messageEditText.getPaint().getFontMetricsInt(), AndroidUtilities.dp(20), false);
                messageEditText.setText(messageEditText.getText().insert(i, localCharSequence));
                int j = i + localCharSequence.length();
                messageEditText.setSelection(j, j);
            } catch (Exception e) {
                FileLog.e(e);
            } finally {
                innerTextChange = 0;
            }
        }

        @Override
        public void onStickerSelected(View view, TLRPC.Document sticker, String query, Object parent, MessageObject.SendAnimationData sendAnimationData, boolean notify, int scheduleDate) {
            if (trendingStickersAlert != null) {
                trendingStickersAlert.dismiss();
                trendingStickersAlert = null;
            }
            if (slowModeTimer > 0 && !isInScheduleMode()) {
                if (delegate != null) {
                    delegate.onUpdateSlowModeButton(view != null ? view : slowModeButton, true, slowModeButton.getText());
                }
                return;
            }
            if (stickersExpanded) {
                if (searchingType != 0) {
                    setSearchingTypeInternal(0, true);
                    emojiView.closeSearch(true, MessageObject.getStickerSetId(sticker));
                    emojiView.hideSearchKeyboard();
                }
                setStickersExpanded(false, true, false);
            }
            ChatActivityEnterView.this.onStickerSelected(sticker, query, parent, sendAnimationData, false, notify, scheduleDate);
            if (DialogObject.isEncryptedDialog(dialog_id) && MessageObject.isGifDocument(sticker)) {
                accountInstance.getMessagesController().saveGif(parent, sticker);
            }
        }

        @Override
        public void onStickersSettingsClick() {
            if (parentFragment != null) {
                parentFragment.presentFragment(new StickersActivity(MediaDataController.TYPE_IMAGE));
            }
        }

        @Override
        public void onGifSelected(View view, Object gif, String query, Object parent, boolean notify, int scheduleDate) {
            if (isInScheduleMode() && scheduleDate == 0) {
                AlertsCreator.createScheduleDatePickerDialog(parentActivity, parentFragment.getDialogId(), (n, s) -> onGifSelected(view, gif, query, parent, n, s), resourcesProvider);
            } else {
                if (slowModeTimer > 0 && !isInScheduleMode()) {
                    if (delegate != null) {
                        delegate.onUpdateSlowModeButton(view != null ? view : slowModeButton, true, slowModeButton.getText());
                    }
                    return;
                }
                if (stickersExpanded) {
                    if (searchingType != 0) {
                        emojiView.hideSearchKeyboard();
                    }
                    setStickersExpanded(false, true, false);
                }
                if (gif instanceof TLRPC.Document) {
                    TLRPC.Document document = (TLRPC.Document) gif;
                    SendMessagesHelper.getInstance(currentAccount).sendSticker(document, query, dialog_id, replyingMessageObject, getThreadMessage(), parent, null, notify, scheduleDate);
                    MediaDataController.getInstance(currentAccount).addRecentGif(document, (int) (System.currentTimeMillis() / 1000));
                    if (DialogObject.isEncryptedDialog(dialog_id)) {
                        accountInstance.getMessagesController().saveGif(parent, document);
                    }
                } else if (gif instanceof TLRPC.BotInlineResult) {
                    TLRPC.BotInlineResult result = (TLRPC.BotInlineResult) gif;
                    if (result.document != null) {
                        MediaDataController.getInstance(currentAccount).addRecentGif(result.document, (int) (System.currentTimeMillis() / 1000));
                        if (DialogObject.isEncryptedDialog(dialog_id)) {
                            accountInstance.getMessagesController().saveGif(parent, result.document);
                        }
                    }
                    TLRPC.User bot = (TLRPC.User) parent;
                    HashMap<String, String> params = new HashMap<>();
                    params.put("id", result.id);
                    params.put("query_id", "" + result.query_id);
                    params.put("force_gif", "1");
                    SendMessagesHelper.prepareSendingBotContextResult(accountInstance, result, params, dialog_id, replyingMessageObject, getThreadMessage(), notify, scheduleDate);
                    if (searchingType != 0) {
                        setSearchingTypeInternal(0, true);
                        emojiView.closeSearch(true);
                        emojiView.hideSearchKeyboard();
                    }
                }
                if (delegate != null) {
                    delegate.onMessageSend(null, notify, scheduleDate);
                }
            }
        }

        @Override
        public void onTabOpened(int type) {
            delegate.onStickersTab(type == 3);
            post(updateExpandabilityRunnable);
        }

        @Override
        public void onClearEmojiRecent() {
            if (parentFragment == null || parentActivity == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(parentActivity, resourcesProvider);
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("ClearRecentEmoji", R.string.ClearRecentEmoji));
            builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> emojiView.clearRecentEmoji());
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            parentFragment.showDialog(builder.create());
        }

        @Override
        public void onShowStickerSet(TLRPC.StickerSet stickerSet, TLRPC.InputStickerSet inputStickerSet) {
            if (trendingStickersAlert != null && !trendingStickersAlert.isDismissed()) {
                trendingStickersAlert.getLayout().showStickerSet(stickerSet, inputStickerSet);
                return;
            }
            if (parentFragment == null || parentActivity == null) {
                return;
            }
            if (stickerSet != null) {
                inputStickerSet = new TLRPC.TL_inputStickerSetID();
                inputStickerSet.access_hash = stickerSet.access_hash;
                inputStickerSet.id = stickerSet.id;
            }
            parentFragment.showDialog(new StickersAlert(parentActivity, parentFragment, inputStickerSet, null, ChatActivityEnterView.this, resourcesProvider));
        }

        @Override
        public void onStickerSetAdd(TLRPC.StickerSetCovered stickerSet) {
            MediaDataController.getInstance(currentAccount).toggleStickerSet(parentActivity, stickerSet, 2, parentFragment, false, false);
        }

        @Override
        public void onStickerSetRemove(TLRPC.StickerSetCovered stickerSet) {
            MediaDataController.getInstance(currentAccount).toggleStickerSet(parentActivity, stickerSet, 0, parentFragment, false, false);
        }

        @Override
        public void onStickersGroupClick(long chatId) {
            if (parentFragment != null) {
                if (AndroidUtilities.isTablet()) {
                    hidePopup(false);
                }
                GroupStickersActivity fragment = new GroupStickersActivity(chatId);
                fragment.setInfo(info);
                parentFragment.presentFragment(fragment);
            }
        }

        @Override
        public void onSearchOpenClose(int type) {
            setSearchingTypeInternal(type, true);
            if (type != 0) {
                setStickersExpanded(true, true, false);
            }
            if (emojiTabOpen && searchingType == 2) {
                checkStickresExpandHeight();
            }
        }

        @Override
        public boolean isSearchOpened() {
            return searchingType != 0;
        }

        @Override
        public boolean isExpanded() {
            return stickersExpanded;
        }

        @Override
        public boolean canSchedule() {
            return parentFragment != null && parentFragment.canScheduleMessage();
        }

        @Override
        public boolean isInScheduleMode() {
            return parentFragment != null && parentFragment.isInScheduleMode();
        }

        @Override
        public long getDialogId() {
            return dialog_id;
        }

        @Override
        public int getThreadId() {
            return getThreadMessageId();
        }

        @Override
        public void showTrendingStickersAlert(TrendingStickersLayout layout) {
            if (parentActivity != null && parentFragment != null) {
                trendingStickersAlert = new TrendingStickersAlert(parentActivity, parentFragment, layout, resourcesProvider) {

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        if (trendingStickersAlert == this) {
                            trendingStickersAlert = null;
                        }
                        if (delegate != null) {
                            delegate.onTrendingStickersShowed(false);
                        }
                    }
                };
                if (delegate != null) {
                    delegate.onTrendingStickersShowed(true);
                }
                trendingStickersAlert.show();
            }
        }

        @Override
        public void invalidateEnterView() {
            invalidate();
        }

        @Override
        public float getProgressToSearchOpened() {
            return searchToOpenProgress;
        }
    });
    emojiView.setDragListener(new EmojiView.DragListener() {

        boolean wasExpanded;

        int initialOffset;

        @Override
        public void onDragStart() {
            if (!allowDragging()) {
                return;
            }
            if (stickersExpansionAnim != null) {
                stickersExpansionAnim.cancel();
            }
            stickersDragging = true;
            wasExpanded = stickersExpanded;
            stickersExpanded = true;
            NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.stopAllHeavyOperations, 1);
            stickersExpandedHeight = sizeNotifierLayout.getHeight() - (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? AndroidUtilities.statusBarHeight : 0) - ActionBar.getCurrentActionBarHeight() - getHeight() + Theme.chat_composeShadowDrawable.getIntrinsicHeight();
            if (searchingType == 2) {
                stickersExpandedHeight = Math.min(stickersExpandedHeight, AndroidUtilities.dp(120) + (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight));
            }
            emojiView.getLayoutParams().height = stickersExpandedHeight;
            emojiView.setLayerType(LAYER_TYPE_HARDWARE, null);
            sizeNotifierLayout.requestLayout();
            sizeNotifierLayout.setForeground(new ScrimDrawable());
            initialOffset = (int) getTranslationY();
            if (delegate != null) {
                delegate.onStickersExpandedChange();
            }
        }

        @Override
        public void onDragEnd(float velocity) {
            if (!allowDragging()) {
                return;
            }
            stickersDragging = false;
            if ((wasExpanded && velocity >= AndroidUtilities.dp(200)) || (!wasExpanded && velocity <= AndroidUtilities.dp(-200)) || (wasExpanded && stickersExpansionProgress <= 0.6f) || (!wasExpanded && stickersExpansionProgress >= 0.4f)) {
                setStickersExpanded(!wasExpanded, true, true);
            } else {
                setStickersExpanded(wasExpanded, true, true);
            }
        }

        @Override
        public void onDragCancel() {
            if (!stickersTabOpen) {
                return;
            }
            stickersDragging = false;
            setStickersExpanded(wasExpanded, true, false);
        }

        @Override
        public void onDrag(int offset) {
            if (!allowDragging()) {
                return;
            }
            int origHeight = AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y ? keyboardHeightLand : keyboardHeight;
            offset += initialOffset;
            offset = Math.max(Math.min(offset, 0), -(stickersExpandedHeight - origHeight));
            emojiView.setTranslationY(offset);
            setTranslationY(offset);
            stickersExpansionProgress = (float) offset / (-(stickersExpandedHeight - origHeight));
            sizeNotifierLayout.invalidate();
        }

        private boolean allowDragging() {
            return stickersTabOpen && !(!stickersExpanded && messageEditText.length() > 0) && emojiView.areThereAnyStickers() && !waitingForKeyboardOpen;
        }
    });
    sizeNotifierLayout.addView(emojiView, sizeNotifierLayout.getChildCount() - 5);
    checkChannelRights();
}
Also used : Bundle(android.os.Bundle) ProfileActivity(org.telegram.ui.ProfileActivity) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) Drawable(android.graphics.drawable.Drawable) Property(android.util.Property) Manifest(android.Manifest) Keep(androidx.annotation.Keep) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) DialogsActivity(org.telegram.ui.DialogsActivity) ClipboardManager(android.content.ClipboardManager) Canvas(android.graphics.Canvas) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Emoji(org.telegram.messenger.Emoji) ContextCompat(androidx.core.content.ContextCompat) NotificationsController(org.telegram.messenger.NotificationsController) ViewCompat(androidx.core.view.ViewCompat) ChatListItemAnimator(androidx.recyclerview.widget.ChatListItemAnimator) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) HapticFeedbackConstants(android.view.HapticFeedbackConstants) Nullable(androidx.annotation.Nullable) Layout(android.text.Layout) TextPaint(android.text.TextPaint) LaunchActivity(org.telegram.ui.LaunchActivity) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TextWatcher(android.text.TextWatcher) ChatActivity(org.telegram.ui.ChatActivity) Path(android.graphics.Path) ImageSpan(android.text.style.ImageSpan) BuildCompat(androidx.core.os.BuildCompat) Dialog(android.app.Dialog) SystemClock(android.os.SystemClock) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) Menu(android.view.Menu) ColorFilter(android.graphics.ColorFilter) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) R(org.telegram.messenger.R) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) File(java.io.File) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) Configuration(android.content.res.Configuration) AccessibilityNodeInfoCompat(androidx.core.view.accessibility.AccessibilityNodeInfoCompat) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) CameraController(org.telegram.messenger.camera.CameraController) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ValueAnimator(android.animation.ValueAnimator) Rect(android.graphics.Rect) ActionMode(android.view.ActionMode) LinearLayout(android.widget.LinearLayout) StickersActivity(org.telegram.ui.StickersActivity) PackageManager(android.content.pm.PackageManager) Spannable(android.text.Spannable) WindowManager(android.view.WindowManager) InputConnectionCompat(androidx.core.view.inputmethod.InputConnectionCompat) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) ViewConfiguration(android.view.ViewConfiguration) PowerManager(android.os.PowerManager) ApplicationLoader(org.telegram.messenger.ApplicationLoader) GroupStickersActivity(org.telegram.ui.GroupStickersActivity) Locale(java.util.Locale) MediaController(org.telegram.messenger.MediaController) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) Matrix(android.graphics.Matrix) RectF(android.graphics.RectF) Utilities(org.telegram.messenger.Utilities) ExploreByTouchHelper(androidx.customview.widget.ExploreByTouchHelper) ObjectAnimator(android.animation.ObjectAnimator) PorterDuff(android.graphics.PorterDuff) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) WindowInsets(android.view.WindowInsets) EditorInfo(android.view.inputmethod.EditorInfo) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Typeface(android.graphics.Typeface) Context(android.content.Context) StaticLayout(android.text.StaticLayout) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) Spanned(android.text.Spanned) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) InputConnection(android.view.inputmethod.InputConnection) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) PixelFormat(android.graphics.PixelFormat) AudioManager(android.media.AudioManager) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) AccessibilityManager(android.view.accessibility.AccessibilityManager) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) PhotoViewer(org.telegram.ui.PhotoViewer) MotionEvent(android.view.MotionEvent) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) LongSparseArray(androidx.collection.LongSparseArray) DialogObject(org.telegram.messenger.DialogObject) InputContentInfoCompat(androidx.core.view.inputmethod.InputContentInfoCompat) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) EditorInfoCompat(androidx.core.view.inputmethod.EditorInfoCompat) Bitmap(android.graphics.Bitmap) ClipDescription(android.content.ClipDescription) ViewTreeObserver(android.view.ViewTreeObserver) Vibrator(android.os.Vibrator) Activity(android.app.Activity) MimeTypeMap(android.webkit.MimeTypeMap) InputStream(java.io.InputStream) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) HashMap(java.util.HashMap) SpannableStringBuilder(android.text.SpannableStringBuilder) StickersActivity(org.telegram.ui.StickersActivity) GroupStickersActivity(org.telegram.ui.GroupStickersActivity) GroupStickersActivity(org.telegram.ui.GroupStickersActivity) TLRPC(org.telegram.tgnet.TLRPC) KeyEvent(android.view.KeyEvent) ImageView(android.widget.ImageView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

Manifest (android.Manifest)1 Animator (android.animation.Animator)1 AnimatorListenerAdapter (android.animation.AnimatorListenerAdapter)1 AnimatorSet (android.animation.AnimatorSet)1 ObjectAnimator (android.animation.ObjectAnimator)1 ValueAnimator (android.animation.ValueAnimator)1 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 Dialog (android.app.Dialog)1 ClipData (android.content.ClipData)1 ClipDescription (android.content.ClipDescription)1 ClipboardManager (android.content.ClipboardManager)1 Context (android.content.Context)1 SharedPreferences (android.content.SharedPreferences)1 PackageManager (android.content.pm.PackageManager)1 Configuration (android.content.res.Configuration)1 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 Color (android.graphics.Color)1 ColorFilter (android.graphics.ColorFilter)1