Search in sources :

Example 46 with AlertDialog

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

the class DialogsActivity method createView.

@Override
public View createView(final Context context) {
    searching = false;
    searchWas = false;
    pacmanAnimation = null;
    selectedDialogs.clear();
    maximumVelocity = ViewConfiguration.get(context).getScaledMaximumFlingVelocity();
    AndroidUtilities.runOnUIThread(() -> Theme.createChatResources(context, false));
    ActionBarMenu menu = actionBar.createMenu();
    if (!onlySelect && searchString == null && folderId == 0) {
        doneItem = new ActionBarMenuItem(context, null, Theme.getColor(Theme.key_actionBarDefaultSelector), Theme.getColor(Theme.key_actionBarDefaultIcon), true);
        doneItem.setText(LocaleController.getString("Done", R.string.Done).toUpperCase());
        actionBar.addView(doneItem, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP | Gravity.RIGHT, 0, 0, 10, 0));
        doneItem.setOnClickListener(v -> {
            filterTabsView.setIsEditing(false);
            showDoneItem(false);
        });
        doneItem.setAlpha(0.0f);
        doneItem.setVisibility(View.GONE);
        proxyDrawable = new ProxyDrawable(context);
        proxyItem = menu.addItem(2, proxyDrawable);
        proxyItem.setContentDescription(LocaleController.getString("ProxySettings", R.string.ProxySettings));
        passcodeDrawable = new RLottieDrawable(R.raw.passcode_lock_close, "passcode_lock_close", AndroidUtilities.dp(28), AndroidUtilities.dp(28), true, null);
        passcodeItem = menu.addItem(1, passcodeDrawable);
        passcodeItem.setContentDescription(LocaleController.getString("AccDescrPasscodeLock", R.string.AccDescrPasscodeLock));
        updatePasscodeButton();
        updateProxyButton(false);
    }
    searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true, true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

        @Override
        public void onSearchExpand() {
            searching = true;
            if (switchItem != null) {
                switchItem.setVisibility(View.GONE);
            }
            if (proxyItem != null && proxyItemVisible) {
                proxyItem.setVisibility(View.GONE);
            }
            if (viewPages[0] != null) {
                if (searchString != null) {
                    viewPages[0].listView.hide();
                    if (searchViewPager != null) {
                        searchViewPager.searchListView.show();
                    }
                }
                if (!onlySelect) {
                    floatingButtonContainer.setVisibility(View.GONE);
                }
            }
            setScrollY(0);
            updatePasscodeButton();
            actionBar.setBackButtonContentDescription(LocaleController.getString("AccDescrGoBack", R.string.AccDescrGoBack));
        }

        @Override
        public boolean canCollapseSearch() {
            if (switchItem != null) {
                switchItem.setVisibility(View.VISIBLE);
            }
            if (proxyItem != null && proxyItemVisible) {
                proxyItem.setVisibility(View.VISIBLE);
            }
            if (searchString != null) {
                finishFragment();
                return false;
            }
            return true;
        }

        @Override
        public void onSearchCollapse() {
            searching = false;
            searchWas = false;
            if (viewPages[0] != null) {
                viewPages[0].listView.setEmptyView(folderId == 0 ? viewPages[0].progressView : null);
                if (!onlySelect) {
                    floatingButtonContainer.setVisibility(View.VISIBLE);
                    floatingHidden = true;
                    floatingButtonTranslation = AndroidUtilities.dp(100);
                    floatingButtonHideProgress = 1f;
                    updateFloatingButtonOffset();
                }
                showSearch(false, true);
            }
            updatePasscodeButton();
            if (menuDrawable != null) {
                if (actionBar.getBackButton().getDrawable() != menuDrawable) {
                    actionBar.setBackButtonDrawable(menuDrawable);
                    menuDrawable.setRotation(0, true);
                }
                actionBar.setBackButtonContentDescription(LocaleController.getString("AccDescrOpenMenu", R.string.AccDescrOpenMenu));
            }
        }

        @Override
        public void onTextChanged(EditText editText) {
            String text = editText.getText().toString();
            if (text.length() != 0 || (searchViewPager.dialogsSearchAdapter != null && searchViewPager.dialogsSearchAdapter.hasRecentSearch()) || searchFiltersWasShowed) {
                searchWas = true;
                if (!searchIsShowed) {
                    showSearch(true, true);
                }
            }
            searchViewPager.onTextChanged(text);
        }

        @Override
        public void onSearchFilterCleared(FiltersView.MediaFilterData filterData) {
            if (!searchIsShowed) {
                return;
            }
            searchViewPager.removeSearchFilter(filterData);
            searchViewPager.onTextChanged(searchItem.getSearchField().getText().toString());
            updateFiltersView(true, null, null, false, true);
        }

        @Override
        public boolean canToggleSearch() {
            return !actionBar.isActionModeShowed() && databaseMigrationHint == null;
        }
    });
    searchItem.setSearchFieldHint(LocaleController.getString("Search", R.string.Search));
    searchItem.setContentDescription(LocaleController.getString("Search", R.string.Search));
    if (onlySelect) {
        actionBar.setBackButtonImage(R.drawable.ic_ab_back);
        if (initialDialogsType == 3 && selectAlertString == null) {
            actionBar.setTitle(LocaleController.getString("ForwardTo", R.string.ForwardTo));
        } else if (initialDialogsType == 10) {
            actionBar.setTitle(LocaleController.getString("SelectChats", R.string.SelectChats));
        } else {
            actionBar.setTitle(LocaleController.getString("SelectChat", R.string.SelectChat));
        }
        actionBar.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
    } else {
        if (searchString != null || folderId != 0) {
            actionBar.setBackButtonDrawable(backDrawable = new BackDrawable(false));
        } else {
            actionBar.setBackButtonDrawable(menuDrawable = new MenuDrawable());
            actionBar.setBackButtonContentDescription(LocaleController.getString("AccDescrOpenMenu", R.string.AccDescrOpenMenu));
        }
        if (folderId != 0) {
            actionBar.setTitle(LocaleController.getString("ArchivedChats", R.string.ArchivedChats));
        } else {
            if (BuildVars.DEBUG_VERSION) {
                actionBar.setTitle("Telegram Beta");
            } else {
                actionBar.setTitle(LocaleController.getString("AppName", R.string.AppName));
            }
        }
        if (folderId == 0) {
            actionBar.setSupportsHolidayImage(true);
        }
    }
    if (!onlySelect) {
        actionBar.setAddToContainer(false);
        actionBar.setCastShadows(false);
        actionBar.setClipContent(true);
    }
    actionBar.setTitleActionRunnable(() -> {
        if (initialDialogsType != 10) {
            hideFloatingButton(false);
        }
        scrollToTop();
    });
    if (initialDialogsType == 0 && folderId == 0 && !onlySelect && TextUtils.isEmpty(searchString)) {
        scrimPaint = new Paint() {

            @Override
            public void setAlpha(int a) {
                super.setAlpha(a);
                if (fragmentView != null) {
                    fragmentView.invalidate();
                }
            }
        };
        filterTabsView = new FilterTabsView(context) {

            @Override
            public boolean onInterceptTouchEvent(MotionEvent ev) {
                getParent().requestDisallowInterceptTouchEvent(true);
                maybeStartTracking = false;
                return super.onInterceptTouchEvent(ev);
            }

            @Override
            public void setTranslationY(float translationY) {
                if (getTranslationY() != translationY) {
                    super.setTranslationY(translationY);
                    updateContextViewPosition();
                    if (fragmentView != null) {
                        fragmentView.invalidate();
                    }
                }
            }

            @Override
            protected void onLayout(boolean changed, int l, int t, int r, int b) {
                super.onLayout(changed, l, t, r, b);
                if (scrimView != null) {
                    scrimView.getLocationInWindow(scrimViewLocation);
                    fragmentView.invalidate();
                }
            }
        };
        filterTabsView.setVisibility(View.GONE);
        canShowFilterTabsView = false;
        filterTabsView.setDelegate(new FilterTabsView.FilterTabsViewDelegate() {

            private void showDeleteAlert(MessagesController.DialogFilter dialogFilter) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("FilterDelete", R.string.FilterDelete));
                builder.setMessage(LocaleController.getString("FilterDeleteAlert", R.string.FilterDeleteAlert));
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                builder.setPositiveButton(LocaleController.getString("Delete", R.string.Delete), (dialog2, which2) -> {
                    TLRPC.TL_messages_updateDialogFilter req = new TLRPC.TL_messages_updateDialogFilter();
                    req.id = dialogFilter.id;
                    getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                    }));
                    // if (getMessagesController().dialogFilters.size() > 1) {
                    // filterTabsView.beginCrossfade();
                    // }
                    getMessagesController().removeFilter(dialogFilter);
                    getMessagesStorage().deleteDialogFilter(dialogFilter);
                // filterTabsView.commitCrossfade();
                });
                AlertDialog alertDialog = builder.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            }

            @Override
            public void onSamePageSelected() {
                scrollToTop();
            }

            @Override
            public void onPageReorder(int fromId, int toId) {
                for (int a = 0; a < viewPages.length; a++) {
                    if (viewPages[a].selectedType == fromId) {
                        viewPages[a].selectedType = toId;
                    } else if (viewPages[a].selectedType == toId) {
                        viewPages[a].selectedType = fromId;
                    }
                }
            }

            @Override
            public void onPageSelected(int id, boolean forward) {
                if (viewPages[0].selectedType == id) {
                    return;
                }
                ArrayList<MessagesController.DialogFilter> dialogFilters = getMessagesController().dialogFilters;
                if (id != Integer.MAX_VALUE && (id < 0 || id >= dialogFilters.size())) {
                    return;
                }
                if (parentLayout != null) {
                    parentLayout.getDrawerLayoutContainer().setAllowOpenDrawerBySwipe(id == filterTabsView.getFirstTabId() || SharedConfig.getChatSwipeAction(currentAccount) != SwipeGestureSettingsView.SWIPE_GESTURE_FOLDERS);
                }
                viewPages[1].selectedType = id;
                viewPages[1].setVisibility(View.VISIBLE);
                viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth());
                showScrollbars(false);
                switchToCurrentSelectedMode(true);
                animatingForward = forward;
            }

            @Override
            public boolean canPerformActions() {
                return !searching;
            }

            @Override
            public void onPageScrolled(float progress) {
                if (progress == 1 && viewPages[1].getVisibility() != View.VISIBLE && !searching) {
                    return;
                }
                if (animatingForward) {
                    viewPages[0].setTranslationX(-progress * viewPages[0].getMeasuredWidth());
                    viewPages[1].setTranslationX(viewPages[0].getMeasuredWidth() - progress * viewPages[0].getMeasuredWidth());
                } else {
                    viewPages[0].setTranslationX(progress * viewPages[0].getMeasuredWidth());
                    viewPages[1].setTranslationX(progress * viewPages[0].getMeasuredWidth() - viewPages[0].getMeasuredWidth());
                }
                if (progress == 1) {
                    ViewPage tempPage = viewPages[0];
                    viewPages[0] = viewPages[1];
                    viewPages[1] = tempPage;
                    viewPages[1].setVisibility(View.GONE);
                    showScrollbars(true);
                    updateCounters(false);
                    checkListLoad(viewPages[0]);
                    viewPages[0].dialogsAdapter.resume();
                    viewPages[1].dialogsAdapter.pause();
                }
            }

            @Override
            public int getTabCounter(int tabId) {
                if (tabId == Integer.MAX_VALUE) {
                    return getMessagesStorage().getMainUnreadCount();
                }
                ArrayList<MessagesController.DialogFilter> dialogFilters = getMessagesController().dialogFilters;
                if (tabId < 0 || tabId >= dialogFilters.size()) {
                    return 0;
                }
                return getMessagesController().dialogFilters.get(tabId).unreadCount;
            }

            @Override
            public boolean didSelectTab(FilterTabsView.TabView tabView, boolean selected) {
                if (actionBar.isActionModeShowed()) {
                    return false;
                }
                if (scrimPopupWindow != null) {
                    scrimPopupWindow.dismiss();
                    scrimPopupWindow = null;
                    scrimPopupWindowItems = null;
                    return false;
                }
                Rect rect = new Rect();
                MessagesController.DialogFilter dialogFilter;
                if (tabView.getId() == Integer.MAX_VALUE) {
                    dialogFilter = null;
                } else {
                    dialogFilter = getMessagesController().dialogFilters.get(tabView.getId());
                }
                ActionBarPopupWindow.ActionBarPopupWindowLayout popupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
                popupLayout.setOnTouchListener(new View.OnTouchListener() {

                    private int[] pos = new int[2];

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                            if (scrimPopupWindow != null && scrimPopupWindow.isShowing()) {
                                View contentView = scrimPopupWindow.getContentView();
                                contentView.getLocationInWindow(pos);
                                rect.set(pos[0], pos[1], pos[0] + contentView.getMeasuredWidth(), pos[1] + contentView.getMeasuredHeight());
                                if (!rect.contains((int) event.getX(), (int) event.getY())) {
                                    scrimPopupWindow.dismiss();
                                }
                            }
                        } else if (event.getActionMasked() == MotionEvent.ACTION_OUTSIDE) {
                            if (scrimPopupWindow != null && scrimPopupWindow.isShowing()) {
                                scrimPopupWindow.dismiss();
                            }
                        }
                        return false;
                    }
                });
                popupLayout.setDispatchKeyEventListener(keyEvent -> {
                    if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && scrimPopupWindow != null && scrimPopupWindow.isShowing()) {
                        scrimPopupWindow.dismiss();
                    }
                });
                Rect backgroundPaddings = new Rect();
                Drawable shadowDrawable = getParentActivity().getResources().getDrawable(R.drawable.popup_fixed_alert).mutate();
                shadowDrawable.getPadding(backgroundPaddings);
                popupLayout.setBackgroundDrawable(shadowDrawable);
                popupLayout.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultSubmenuBackground));
                LinearLayout linearLayout = new LinearLayout(getParentActivity());
                ScrollView scrollView;
                if (Build.VERSION.SDK_INT >= 21) {
                    scrollView = new ScrollView(getParentActivity(), null, 0, R.style.scrollbarShapeStyle) {

                        @Override
                        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                            setMeasuredDimension(linearLayout.getMeasuredWidth(), getMeasuredHeight());
                        }
                    };
                } else {
                    scrollView = new ScrollView(getParentActivity());
                }
                scrollView.setClipToPadding(false);
                popupLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT));
                linearLayout.setMinimumWidth(AndroidUtilities.dp(200));
                linearLayout.setOrientation(LinearLayout.VERTICAL);
                scrimPopupWindowItems = new ActionBarMenuSubItem[3];
                for (int a = 0, N = (tabView.getId() == Integer.MAX_VALUE ? 2 : 3); a < N; a++) {
                    ActionBarMenuSubItem cell = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == N - 1);
                    if (a == 0) {
                        if (getMessagesController().dialogFilters.size() <= 1) {
                            continue;
                        }
                        cell.setTextAndIcon(LocaleController.getString("FilterReorder", R.string.FilterReorder), R.drawable.tabs_reorder);
                    } else if (a == 1) {
                        if (N == 2) {
                            cell.setTextAndIcon(LocaleController.getString("FilterEditAll", R.string.FilterEditAll), R.drawable.msg_edit);
                        } else {
                            cell.setTextAndIcon(LocaleController.getString("FilterEdit", R.string.FilterEdit), R.drawable.msg_edit);
                        }
                    } else {
                        cell.setTextAndIcon(LocaleController.getString("FilterDeleteItem", R.string.FilterDeleteItem), R.drawable.msg_delete);
                    }
                    scrimPopupWindowItems[a] = cell;
                    linearLayout.addView(cell);
                    final int i = a;
                    cell.setOnClickListener(v1 -> {
                        if (i == 0) {
                            resetScroll();
                            filterTabsView.setIsEditing(true);
                            showDoneItem(true);
                        } else if (i == 1) {
                            if (N == 2) {
                                presentFragment(new FiltersSetupActivity());
                            } else {
                                presentFragment(new FilterCreateActivity(dialogFilter));
                            }
                        } else if (i == 2) {
                            showDeleteAlert(dialogFilter);
                        }
                        if (scrimPopupWindow != null) {
                            scrimPopupWindow.dismiss();
                        }
                    });
                }
                scrollView.addView(linearLayout, LayoutHelper.createScroll(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP));
                scrimPopupWindow = new ActionBarPopupWindow(popupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT) {

                    @Override
                    public void dismiss() {
                        super.dismiss();
                        if (scrimPopupWindow != this) {
                            return;
                        }
                        scrimPopupWindow = null;
                        scrimPopupWindowItems = null;
                        if (scrimAnimatorSet != null) {
                            scrimAnimatorSet.cancel();
                            scrimAnimatorSet = null;
                        }
                        scrimAnimatorSet = new AnimatorSet();
                        ArrayList<Animator> animators = new ArrayList<>();
                        animators.add(ObjectAnimator.ofInt(scrimPaint, AnimationProperties.PAINT_ALPHA, 0));
                        scrimAnimatorSet.playTogether(animators);
                        scrimAnimatorSet.setDuration(220);
                        scrimAnimatorSet.addListener(new AnimatorListenerAdapter() {

                            @Override
                            public void onAnimationEnd(Animator animation) {
                                if (scrimView != null) {
                                    scrimView.setBackground(null);
                                    scrimView = null;
                                }
                                if (fragmentView != null) {
                                    fragmentView.invalidate();
                                }
                            }
                        });
                        scrimAnimatorSet.start();
                        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                            getParentActivity().getWindow().getDecorView().setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_AUTO);
                        }
                    }
                };
                tabView.setBackground(Theme.createRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_actionBarDefault)));
                scrimPopupWindow.setDismissAnimationDuration(220);
                scrimPopupWindow.setOutsideTouchable(true);
                scrimPopupWindow.setClippingEnabled(true);
                scrimPopupWindow.setAnimationStyle(R.style.PopupContextAnimation);
                scrimPopupWindow.setFocusable(true);
                popupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
                scrimPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
                scrimPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
                scrimPopupWindow.getContentView().setFocusableInTouchMode(true);
                tabView.getLocationInWindow(scrimViewLocation);
                int popupX = scrimViewLocation[0] + backgroundPaddings.left - AndroidUtilities.dp(16);
                if (popupX < AndroidUtilities.dp(6)) {
                    popupX = AndroidUtilities.dp(6);
                } else if (popupX > fragmentView.getMeasuredWidth() - AndroidUtilities.dp(6) - popupLayout.getMeasuredWidth()) {
                    popupX = fragmentView.getMeasuredWidth() - AndroidUtilities.dp(6) - popupLayout.getMeasuredWidth();
                }
                int popupY = scrimViewLocation[1] + tabView.getMeasuredHeight() - AndroidUtilities.dp(12);
                scrimPopupWindow.showAtLocation(fragmentView, Gravity.LEFT | Gravity.TOP, popupX, popupY);
                scrimView = tabView;
                scrimViewSelected = selected;
                fragmentView.invalidate();
                if (scrimAnimatorSet != null) {
                    scrimAnimatorSet.cancel();
                }
                scrimAnimatorSet = new AnimatorSet();
                ArrayList<Animator> animators = new ArrayList<>();
                animators.add(ObjectAnimator.ofInt(scrimPaint, AnimationProperties.PAINT_ALPHA, 0, 50));
                scrimAnimatorSet.playTogether(animators);
                scrimAnimatorSet.setDuration(150);
                scrimAnimatorSet.start();
                return true;
            }

            @Override
            public boolean isTabMenuVisible() {
                return scrimPopupWindow != null && scrimPopupWindow.isShowing();
            }

            @Override
            public void onDeletePressed(int id) {
                showDeleteAlert(getMessagesController().dialogFilters.get(id));
            }
        });
    }
    if (allowSwitchAccount && UserConfig.getActivatedAccountsCount() > 1) {
        switchItem = menu.addItemWithWidth(1, 0, AndroidUtilities.dp(56));
        AvatarDrawable avatarDrawable = new AvatarDrawable();
        avatarDrawable.setTextSize(AndroidUtilities.dp(12));
        BackupImageView imageView = new BackupImageView(context);
        imageView.setRoundRadius(AndroidUtilities.dp(18));
        switchItem.addView(imageView, LayoutHelper.createFrame(36, 36, Gravity.CENTER));
        TLRPC.User user = getUserConfig().getCurrentUser();
        avatarDrawable.setInfo(user);
        imageView.getImageReceiver().setCurrentAccount(currentAccount);
        imageView.setImage(ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_SMALL), "50_50", ImageLocation.getForUserOrChat(user, ImageLocation.TYPE_STRIPPED), "50_50", avatarDrawable, user);
        for (int a = 0; a < UserConfig.MAX_ACCOUNT_COUNT; a++) {
            TLRPC.User u = AccountInstance.getInstance(a).getUserConfig().getCurrentUser();
            if (u != null) {
                AccountSelectCell cell = new AccountSelectCell(context, false);
                cell.setAccount(a, true);
                switchItem.addSubItem(10 + a, cell, AndroidUtilities.dp(230), AndroidUtilities.dp(48));
            }
        }
    }
    actionBar.setAllowOverlayTitle(true);
    if (sideMenu != null) {
        sideMenu.setBackgroundColor(Theme.getColor(Theme.key_chats_menuBackground));
        sideMenu.setGlowColor(Theme.getColor(Theme.key_chats_menuBackground));
        sideMenu.getAdapter().notifyDataSetChanged();
    }
    createActionMode(null);
    ContentView contentView = new ContentView(context);
    fragmentView = contentView;
    int pagesCount = folderId == 0 && initialDialogsType == 0 && !onlySelect ? 2 : 1;
    viewPages = new ViewPage[pagesCount];
    for (int a = 0; a < pagesCount; a++) {
        final ViewPage viewPage = new ViewPage(context) {

            @Override
            public void setTranslationX(float translationX) {
                super.setTranslationX(translationX);
                if (tabsAnimationInProgress) {
                    if (viewPages[0] == this) {
                        float scrollProgress = Math.abs(viewPages[0].getTranslationX()) / (float) viewPages[0].getMeasuredWidth();
                        filterTabsView.selectTabWithId(viewPages[1].selectedType, scrollProgress);
                    }
                }
            }
        };
        contentView.addView(viewPage, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPage.dialogsType = initialDialogsType;
        viewPages[a] = viewPage;
        viewPage.progressView = new FlickerLoadingView(context);
        viewPage.progressView.setViewType(FlickerLoadingView.DIALOG_CELL_TYPE);
        viewPage.progressView.setVisibility(View.GONE);
        viewPage.addView(viewPage.progressView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER));
        viewPage.listView = new DialogsRecyclerView(context, viewPage);
        viewPage.listView.setAccessibilityEnabled(false);
        viewPage.listView.setAnimateEmptyView(true, 0);
        viewPage.listView.setClipToPadding(false);
        viewPage.listView.setPivotY(0);
        viewPage.dialogsItemAnimator = new DialogsItemAnimator(viewPage.listView) {

            @Override
            public void onRemoveStarting(RecyclerView.ViewHolder item) {
                super.onRemoveStarting(item);
                if (viewPage.layoutManager.findFirstVisibleItemPosition() == 0) {
                    View v = viewPage.layoutManager.findViewByPosition(0);
                    if (v != null) {
                        v.invalidate();
                    }
                    if (viewPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN) {
                        viewPage.archivePullViewState = ARCHIVE_ITEM_STATE_SHOWED;
                    }
                    if (viewPage.pullForegroundDrawable != null) {
                        viewPage.pullForegroundDrawable.doNotShow();
                    }
                }
            }

            @Override
            public void onRemoveFinished(RecyclerView.ViewHolder item) {
                if (dialogRemoveFinished == 2) {
                    dialogRemoveFinished = 1;
                }
            }

            @Override
            public void onAddFinished(RecyclerView.ViewHolder item) {
                if (dialogInsertFinished == 2) {
                    dialogInsertFinished = 1;
                }
            }

            @Override
            public void onChangeFinished(RecyclerView.ViewHolder item, boolean oldItem) {
                if (dialogChangeFinished == 2) {
                    dialogChangeFinished = 1;
                }
            }

            @Override
            protected void onAllAnimationsDone() {
                if (dialogRemoveFinished == 1 || dialogInsertFinished == 1 || dialogChangeFinished == 1) {
                    onDialogAnimationFinished();
                }
            }
        };
        // viewPage.listView.setItemAnimator(viewPage.dialogsItemAnimator);
        viewPage.listView.setVerticalScrollBarEnabled(true);
        viewPage.listView.setInstantClick(true);
        viewPage.layoutManager = new LinearLayoutManager(context) {

            private boolean fixOffset;

            @Override
            public void scrollToPositionWithOffset(int position, int offset) {
                if (fixOffset) {
                    offset -= viewPage.listView.getPaddingTop();
                }
                super.scrollToPositionWithOffset(position, offset);
            }

            @Override
            public void prepareForDrop(@NonNull View view, @NonNull View target, int x, int y) {
                fixOffset = true;
                super.prepareForDrop(view, target, x, y);
                fixOffset = false;
            }

            @Override
            public void smoothScrollToPosition(RecyclerView recyclerView, RecyclerView.State state, int position) {
                if (hasHiddenArchive() && position == 1) {
                    super.smoothScrollToPosition(recyclerView, state, position);
                } else {
                    LinearSmoothScrollerCustom linearSmoothScroller = new LinearSmoothScrollerCustom(recyclerView.getContext(), LinearSmoothScrollerCustom.POSITION_MIDDLE);
                    linearSmoothScroller.setTargetPosition(position);
                    startSmoothScroll(linearSmoothScroller);
                }
            }

            @Override
            public int scrollVerticallyBy(int dy, RecyclerView.Recycler recycler, RecyclerView.State state) {
                if (viewPage.listView.fastScrollAnimationRunning) {
                    return 0;
                }
                boolean isDragging = viewPage.listView.getScrollState() == RecyclerView.SCROLL_STATE_DRAGGING;
                int measuredDy = dy;
                int pTop = viewPage.listView.getPaddingTop();
                if (viewPage.dialogsType == 0 && !onlySelect && folderId == 0 && dy < 0 && getMessagesController().hasHiddenArchive() && viewPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN) {
                    viewPage.listView.setOverScrollMode(View.OVER_SCROLL_ALWAYS);
                    int currentPosition = viewPage.layoutManager.findFirstVisibleItemPosition();
                    if (currentPosition == 0) {
                        View view = viewPage.layoutManager.findViewByPosition(currentPosition);
                        if (view != null && (view.getBottom() - pTop) <= AndroidUtilities.dp(1)) {
                            currentPosition = 1;
                        }
                    }
                    if (!isDragging) {
                        View view = viewPage.layoutManager.findViewByPosition(currentPosition);
                        if (view != null) {
                            int dialogHeight = AndroidUtilities.dp(SharedConfig.useThreeLinesLayout ? 78 : 72) + 1;
                            int canScrollDy = -(view.getTop() - pTop) + (currentPosition - 1) * dialogHeight;
                            int positiveDy = Math.abs(dy);
                            if (canScrollDy < positiveDy) {
                                measuredDy = -canScrollDy;
                            }
                        }
                    } else if (currentPosition == 0) {
                        View v = viewPage.layoutManager.findViewByPosition(currentPosition);
                        float k = 1f + ((v.getTop() - pTop) / (float) v.getMeasuredHeight());
                        if (k > 1f) {
                            k = 1f;
                        }
                        viewPage.listView.setOverScrollMode(View.OVER_SCROLL_NEVER);
                        measuredDy *= PullForegroundDrawable.startPullParallax - PullForegroundDrawable.endPullParallax * k;
                        if (measuredDy > -1) {
                            measuredDy = -1;
                        }
                        if (undoView[0].getVisibility() == View.VISIBLE) {
                            undoView[0].hide(true, 1);
                        }
                    }
                }
                if (viewPage.dialogsType == 0 && viewPage.listView.getViewOffset() != 0 && dy > 0 && isDragging) {
                    float ty = (int) viewPage.listView.getViewOffset();
                    ty -= dy;
                    if (ty < 0) {
                        measuredDy = (int) ty;
                        ty = 0;
                    } else {
                        measuredDy = 0;
                    }
                    viewPage.listView.setViewsOffset(ty);
                }
                if (viewPage.dialogsType == 0 && viewPage.archivePullViewState != ARCHIVE_ITEM_STATE_PINNED && hasHiddenArchive()) {
                    int usedDy = super.scrollVerticallyBy(measuredDy, recycler, state);
                    if (viewPage.pullForegroundDrawable != null) {
                        viewPage.pullForegroundDrawable.scrollDy = usedDy;
                    }
                    int currentPosition = viewPage.layoutManager.findFirstVisibleItemPosition();
                    View firstView = null;
                    if (currentPosition == 0) {
                        firstView = viewPage.layoutManager.findViewByPosition(currentPosition);
                    }
                    if (currentPosition == 0 && firstView != null && (firstView.getBottom() - pTop) >= AndroidUtilities.dp(4)) {
                        if (startArchivePullingTime == 0) {
                            startArchivePullingTime = System.currentTimeMillis();
                        }
                        if (viewPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN) {
                            if (viewPage.pullForegroundDrawable != null) {
                                viewPage.pullForegroundDrawable.showHidden();
                            }
                        }
                        float k = 1f + ((firstView.getTop() - pTop) / (float) firstView.getMeasuredHeight());
                        if (k > 1f) {
                            k = 1f;
                        }
                        long pullingTime = System.currentTimeMillis() - startArchivePullingTime;
                        boolean canShowInternal = k > PullForegroundDrawable.SNAP_HEIGHT && pullingTime > PullForegroundDrawable.minPullingTime + 20;
                        if (canShowHiddenArchive != canShowInternal) {
                            canShowHiddenArchive = canShowInternal;
                            if (viewPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN) {
                                viewPage.listView.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
                                if (viewPage.pullForegroundDrawable != null) {
                                    viewPage.pullForegroundDrawable.colorize(canShowInternal);
                                }
                            }
                        }
                        if (viewPage.archivePullViewState == ARCHIVE_ITEM_STATE_HIDDEN && measuredDy - usedDy != 0 && dy < 0 && isDragging) {
                            float ty;
                            float tk = (viewPage.listView.getViewOffset() / PullForegroundDrawable.getMaxOverscroll());
                            tk = 1f - tk;
                            ty = (viewPage.listView.getViewOffset() - dy * PullForegroundDrawable.startPullOverScroll * tk);
                            viewPage.listView.setViewsOffset(ty);
                        }
                        if (viewPage.pullForegroundDrawable != null) {
                            viewPage.pullForegroundDrawable.pullProgress = k;
                            viewPage.pullForegroundDrawable.setListView(viewPage.listView);
                        }
                    } else {
                        startArchivePullingTime = 0;
                        canShowHiddenArchive = false;
                        viewPage.archivePullViewState = ARCHIVE_ITEM_STATE_HIDDEN;
                        if (viewPage.pullForegroundDrawable != null) {
                            viewPage.pullForegroundDrawable.resetText();
                            viewPage.pullForegroundDrawable.pullProgress = 0f;
                            viewPage.pullForegroundDrawable.setListView(viewPage.listView);
                        }
                    }
                    if (firstView != null) {
                        firstView.invalidate();
                    }
                    return usedDy;
                }
                return super.scrollVerticallyBy(measuredDy, recycler, state);
            }

            @Override
            public void onLayoutChildren(RecyclerView.Recycler recycler, RecyclerView.State state) {
                if (BuildVars.DEBUG_PRIVATE_VERSION) {
                    try {
                        super.onLayoutChildren(recycler, state);
                    } catch (IndexOutOfBoundsException e) {
                        throw new RuntimeException("Inconsistency detected. " + "dialogsListIsFrozen=" + dialogsListFrozen + " lastUpdateAction=" + debugLastUpdateAction);
                    }
                } else {
                    try {
                        super.onLayoutChildren(recycler, state);
                    } catch (IndexOutOfBoundsException e) {
                        FileLog.e(e);
                        AndroidUtilities.runOnUIThread(() -> viewPage.dialogsAdapter.notifyDataSetChanged());
                    }
                }
            }
        };
        viewPage.layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        viewPage.listView.setLayoutManager(viewPage.layoutManager);
        viewPage.listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
        viewPage.addView(viewPage.listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
        viewPage.listView.setOnItemClickListener((view, position) -> {
            if (initialDialogsType == 10) {
                onItemLongClick(view, position, 0, 0, viewPage.dialogsType, viewPage.dialogsAdapter);
                return;
            } else if ((initialDialogsType == 11 || initialDialogsType == 13) && position == 1) {
                Bundle args = new Bundle();
                args.putBoolean("forImport", true);
                long[] array = new long[] { getUserConfig().getClientUserId() };
                args.putLongArray("result", array);
                args.putInt("chatType", ChatObject.CHAT_TYPE_MEGAGROUP);
                String title = arguments.getString("importTitle");
                if (title != null) {
                    args.putString("title", title);
                }
                GroupCreateFinalActivity activity = new GroupCreateFinalActivity(args);
                activity.setDelegate(new GroupCreateFinalActivity.GroupCreateFinalActivityDelegate() {

                    @Override
                    public void didStartChatCreation() {
                    }

                    @Override
                    public void didFinishChatCreation(GroupCreateFinalActivity fragment, long chatId) {
                        ArrayList<Long> arrayList = new ArrayList<>();
                        arrayList.add(-chatId);
                        DialogsActivityDelegate dialogsActivityDelegate = delegate;
                        removeSelfFromStack();
                        dialogsActivityDelegate.didSelectDialogs(DialogsActivity.this, arrayList, null, true);
                    }

                    @Override
                    public void didFailChatCreation() {
                    }
                });
                presentFragment(activity);
                return;
            }
            onItemClick(view, position, viewPage.dialogsAdapter);
        });
        viewPage.listView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListenerExtended() {

            @Override
            public boolean onItemClick(View view, int position, float x, float y) {
                if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE && filterTabsView.isEditing()) {
                    return false;
                }
                return onItemLongClick(view, position, x, y, viewPage.dialogsType, viewPage.dialogsAdapter);
            }

            @Override
            public void onLongClickRelease() {
                finishPreviewFragment();
            }

            @Override
            public void onMove(float dx, float dy) {
                movePreviewFragment(dy);
            }
        });
        viewPage.swipeController = new SwipeController(viewPage);
        viewPage.recyclerItemsEnterAnimator = new RecyclerItemsEnterAnimator(viewPage.listView, false);
        viewPage.itemTouchhelper = new ItemTouchHelper(viewPage.swipeController);
        viewPage.itemTouchhelper.attachToRecyclerView(viewPage.listView);
        viewPage.listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

            private boolean wasManualScroll;

            @Override
            public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
                if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                    wasManualScroll = true;
                    scrollingManually = true;
                } else {
                    scrollingManually = false;
                }
                if (newState == RecyclerView.SCROLL_STATE_IDLE) {
                    wasManualScroll = false;
                    disableActionBarScrolling = false;
                    if (waitingForScrollFinished) {
                        waitingForScrollFinished = false;
                        if (updatePullAfterScroll) {
                            viewPage.listView.updatePullState();
                            updatePullAfterScroll = false;
                        }
                        viewPage.dialogsAdapter.notifyDataSetChanged();
                    }
                    if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE && viewPages[0].listView == recyclerView) {
                        int scrollY = (int) -actionBar.getTranslationY();
                        int actionBarHeight = ActionBar.getCurrentActionBarHeight();
                        if (scrollY != 0 && scrollY != actionBarHeight) {
                            if (scrollY < actionBarHeight / 2) {
                                recyclerView.smoothScrollBy(0, -scrollY);
                            } else if (viewPages[0].listView.canScrollVertically(1)) {
                                recyclerView.smoothScrollBy(0, actionBarHeight - scrollY);
                            }
                        }
                    }
                }
            }

            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                viewPage.dialogsItemAnimator.onListScroll(-dy);
                checkListLoad(viewPage);
                if (initialDialogsType != 10 && wasManualScroll && floatingButtonContainer.getVisibility() != View.GONE && recyclerView.getChildCount() > 0) {
                    int firstVisibleItem = viewPage.layoutManager.findFirstVisibleItemPosition();
                    if (firstVisibleItem != RecyclerView.NO_POSITION) {
                        RecyclerView.ViewHolder holder = recyclerView.findViewHolderForAdapterPosition(firstVisibleItem);
                        if (!hasHiddenArchive() || holder != null && holder.getAdapterPosition() != 0) {
                            int firstViewTop = 0;
                            if (holder != null) {
                                firstViewTop = holder.itemView.getTop();
                            }
                            boolean goingDown;
                            boolean changed = true;
                            if (prevPosition == firstVisibleItem) {
                                final int topDelta = prevTop - firstViewTop;
                                goingDown = firstViewTop < prevTop;
                                changed = Math.abs(topDelta) > 1;
                            } else {
                                goingDown = firstVisibleItem > prevPosition;
                            }
                            if (changed && scrollUpdated && (goingDown || scrollingManually)) {
                                hideFloatingButton(goingDown);
                            }
                            prevPosition = firstVisibleItem;
                            prevTop = firstViewTop;
                            scrollUpdated = true;
                        }
                    }
                }
                if (filterTabsView != null && filterTabsView.getVisibility() == View.VISIBLE && recyclerView == viewPages[0].listView && !searching && !actionBar.isActionModeShowed() && !disableActionBarScrolling && filterTabsViewIsVisible) {
                    if (dy > 0 && hasHiddenArchive() && viewPages[0].dialogsType == 0) {
                        View child = recyclerView.getChildAt(0);
                        if (child != null) {
                            RecyclerView.ViewHolder holder = recyclerView.getChildViewHolder(child);
                            if (holder.getAdapterPosition() == 0) {
                                int visiblePartAfterScroll = child.getMeasuredHeight() + (child.getTop() - recyclerView.getPaddingTop());
                                if (visiblePartAfterScroll + dy > 0) {
                                    if (visiblePartAfterScroll < 0) {
                                        dy = -visiblePartAfterScroll;
                                    } else {
                                        return;
                                    }
                                }
                            }
                        }
                    }
                    float currentTranslation = actionBar.getTranslationY();
                    float newTranslation = currentTranslation - dy;
                    if (newTranslation < -ActionBar.getCurrentActionBarHeight()) {
                        newTranslation = -ActionBar.getCurrentActionBarHeight();
                    } else if (newTranslation > 0) {
                        newTranslation = 0;
                    }
                    if (newTranslation != currentTranslation) {
                        setScrollY(newTranslation);
                    }
                }
            }
        });
        viewPage.archivePullViewState = SharedConfig.archiveHidden ? ARCHIVE_ITEM_STATE_HIDDEN : ARCHIVE_ITEM_STATE_PINNED;
        if (viewPage.pullForegroundDrawable == null && folderId == 0) {
            viewPage.pullForegroundDrawable = new PullForegroundDrawable(LocaleController.getString("AccSwipeForArchive", R.string.AccSwipeForArchive), LocaleController.getString("AccReleaseForArchive", R.string.AccReleaseForArchive)) {

                @Override
                protected float getViewOffset() {
                    return viewPage.listView.getViewOffset();
                }
            };
            if (hasHiddenArchive()) {
                viewPage.pullForegroundDrawable.showHidden();
            } else {
                viewPage.pullForegroundDrawable.doNotShow();
            }
            viewPage.pullForegroundDrawable.setWillDraw(viewPage.archivePullViewState != ARCHIVE_ITEM_STATE_PINNED);
        }
        viewPage.dialogsAdapter = new DialogsAdapter(this, context, viewPage.dialogsType, folderId, onlySelect, selectedDialogs, currentAccount) {

            @Override
            public void notifyDataSetChanged() {
                viewPage.lastItemsCount = getItemCount();
                try {
                    super.notifyDataSetChanged();
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
        };
        viewPage.dialogsAdapter.setForceShowEmptyCell(afterSignup);
        if (AndroidUtilities.isTablet() && openedDialogId != 0) {
            viewPage.dialogsAdapter.setOpenedDialogId(openedDialogId);
        }
        viewPage.dialogsAdapter.setArchivedPullDrawable(viewPage.pullForegroundDrawable);
        viewPage.listView.setAdapter(viewPage.dialogsAdapter);
        viewPage.listView.setEmptyView(folderId == 0 ? viewPage.progressView : null);
        viewPage.scrollHelper = new RecyclerAnimationScrollHelper(viewPage.listView, viewPage.layoutManager);
        if (a != 0) {
            viewPages[a].setVisibility(View.GONE);
        }
    }
    int type = 0;
    if (searchString != null) {
        type = 2;
    } else if (!onlySelect) {
        type = 1;
    }
    searchViewPager = new SearchViewPager(context, this, type, initialDialogsType, folderId, new SearchViewPager.ChatPreviewDelegate() {

        @Override
        public void startChatPreview(DialogCell cell) {
            showChatPreview(cell);
        }

        @Override
        public void move(float dy) {
            movePreviewFragment(dy);
        }

        @Override
        public void finish() {
            finishPreviewFragment();
        }
    });
    contentView.addView(searchViewPager);
    searchViewPager.dialogsSearchAdapter.setDelegate(new DialogsSearchAdapter.DialogsSearchAdapterDelegate() {

        @Override
        public void searchStateChanged(boolean search, boolean animated) {
            if (searchViewPager.emptyView.getVisibility() == View.VISIBLE) {
                animated = true;
            }
            if (searching && searchWas && searchViewPager.emptyView != null) {
                if (search || searchViewPager.dialogsSearchAdapter.getItemCount() != 0) {
                    searchViewPager.emptyView.showProgress(true, animated);
                } else {
                    searchViewPager.emptyView.showProgress(false, animated);
                }
            }
            if (search && searchViewPager.dialogsSearchAdapter.getItemCount() == 0) {
                searchViewPager.cancelEnterAnimation();
            }
        }

        @Override
        public void didPressedOnSubDialog(long did) {
            if (onlySelect) {
                if (!validateSlowModeDialog(did)) {
                    return;
                }
                if (!selectedDialogs.isEmpty()) {
                    boolean checked = addOrRemoveSelectedDialog(did, null);
                    findAndUpdateCheckBox(did, checked);
                    updateSelectedCount();
                    actionBar.closeSearchField();
                } else {
                    didSelectResult(did, true, false);
                }
            } else {
                Bundle args = new Bundle();
                if (DialogObject.isUserDialog(did)) {
                    args.putLong("user_id", did);
                } else {
                    args.putLong("chat_id", -did);
                }
                closeSearch();
                if (AndroidUtilities.isTablet() && viewPages != null) {
                    for (int a = 0; a < viewPages.length; a++) {
                        viewPages[a].dialogsAdapter.setOpenedDialogId(openedDialogId = did);
                    }
                    updateVisibleRows(MessagesController.UPDATE_MASK_SELECT_DIALOG);
                }
                if (searchString != null) {
                    if (getMessagesController().checkCanOpenChat(args, DialogsActivity.this)) {
                        getNotificationCenter().postNotificationName(NotificationCenter.closeChats);
                        presentFragment(new ChatActivity(args));
                    }
                } else {
                    if (getMessagesController().checkCanOpenChat(args, DialogsActivity.this)) {
                        presentFragment(new ChatActivity(args));
                    }
                }
            }
        }

        @Override
        public void needRemoveHint(long did) {
            if (getParentActivity() == null) {
                return;
            }
            TLRPC.User user = getMessagesController().getUser(did);
            if (user == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("ChatHintsDeleteAlertTitle", R.string.ChatHintsDeleteAlertTitle));
            builder.setMessage(AndroidUtilities.replaceTags(LocaleController.formatString("ChatHintsDeleteAlert", R.string.ChatHintsDeleteAlert, ContactsController.formatName(user.first_name, user.last_name))));
            builder.setPositiveButton(LocaleController.getString("StickersRemove", R.string.StickersRemove), (dialogInterface, i) -> getMediaDataController().removePeer(did));
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog dialog = builder.create();
            showDialog(dialog);
            TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        }

        @Override
        public void needClearList() {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("ClearSearchAlertTitle", R.string.ClearSearchAlertTitle));
            builder.setMessage(LocaleController.getString("ClearSearchAlert", R.string.ClearSearchAlert));
            builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> {
                if (searchViewPager.dialogsSearchAdapter.isRecentSearchDisplayed()) {
                    searchViewPager.dialogsSearchAdapter.clearRecentSearch();
                } else {
                    searchViewPager.dialogsSearchAdapter.clearRecentHashtags();
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog dialog = builder.create();
            showDialog(dialog);
            TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        }

        @Override
        public void runResultsEnterAnimation() {
            if (searchViewPager != null) {
                searchViewPager.runResultsEnterAnimation();
            }
        }

        @Override
        public boolean isSelected(long dialogId) {
            return selectedDialogs.contains(dialogId);
        }
    });
    searchViewPager.searchListView.setOnItemClickListener((view, position) -> {
        if (initialDialogsType == 10) {
            onItemLongClick(view, position, 0, 0, -1, searchViewPager.dialogsSearchAdapter);
            return;
        }
        onItemClick(view, position, searchViewPager.dialogsSearchAdapter);
    });
    searchViewPager.searchListView.setOnItemLongClickListener(new RecyclerListView.OnItemLongClickListenerExtended() {

        @Override
        public boolean onItemClick(View view, int position, float x, float y) {
            return onItemLongClick(view, position, x, y, -1, searchViewPager.dialogsSearchAdapter);
        }

        @Override
        public void onLongClickRelease() {
            finishPreviewFragment();
        }

        @Override
        public void onMove(float dx, float dy) {
            movePreviewFragment(dy);
        }
    });
    searchViewPager.setFilteredSearchViewDelegate((showMediaFilters, users, dates, archive) -> DialogsActivity.this.updateFiltersView(showMediaFilters, users, dates, archive, true));
    searchViewPager.setVisibility(View.GONE);
    filtersView = new FiltersView(getParentActivity(), null);
    filtersView.setOnItemClickListener((view, position) -> {
        filtersView.cancelClickRunnables(true);
        addSearchFilter(filtersView.getFilterAt(position));
    });
    contentView.addView(filtersView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.TOP));
    filtersView.setVisibility(View.GONE);
    floatingButtonContainer = new FrameLayout(context);
    floatingButtonContainer.setVisibility(onlySelect && initialDialogsType != 10 || folderId != 0 ? View.GONE : View.VISIBLE);
    contentView.addView(floatingButtonContainer, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (Build.VERSION.SDK_INT >= 21 ? 56 : 60) + 20, (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT) | Gravity.BOTTOM, LocaleController.isRTL ? 4 : 0, 0, LocaleController.isRTL ? 0 : 4, 0));
    floatingButtonContainer.setOnClickListener(v -> {
        if (initialDialogsType == 10) {
            if (delegate == null || selectedDialogs.isEmpty()) {
                return;
            }
            delegate.didSelectDialogs(DialogsActivity.this, selectedDialogs, null, false);
        } else {
            Bundle args = new Bundle();
            args.putBoolean("destroyAfterSelect", true);
            presentFragment(new ContactsActivity(args));
        }
    });
    floatingButton = new RLottieImageView(context);
    floatingButton.setScaleType(ImageView.ScaleType.CENTER);
    Drawable drawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_chats_actionBackground), Theme.getColor(Theme.key_chats_actionPressedBackground));
    if (Build.VERSION.SDK_INT < 21) {
        Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow).mutate();
        shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
        CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
        combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
        drawable = combinedDrawable;
    }
    floatingButton.setBackgroundDrawable(drawable);
    floatingButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionIcon), PorterDuff.Mode.MULTIPLY));
    if (initialDialogsType == 10) {
        floatingButton.setImageResource(R.drawable.floating_check);
        floatingButtonContainer.setContentDescription(LocaleController.getString("Done", R.string.Done));
    } else {
        floatingButton.setAnimation(R.raw.write_contacts_fab_icon, 52, 52);
        floatingButtonContainer.setContentDescription(LocaleController.getString("NewMessageTitle", R.string.NewMessageTitle));
    }
    if (Build.VERSION.SDK_INT >= 21) {
        StateListAnimator animator = new StateListAnimator();
        animator.addState(new int[] { android.R.attr.state_pressed }, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(2), AndroidUtilities.dp(4)).setDuration(200));
        animator.addState(new int[] {}, ObjectAnimator.ofFloat(floatingButton, View.TRANSLATION_Z, AndroidUtilities.dp(4), AndroidUtilities.dp(2)).setDuration(200));
        floatingButton.setStateListAnimator(animator);
        floatingButton.setOutlineProvider(new ViewOutlineProvider() {

            @SuppressLint("NewApi")
            @Override
            public void getOutline(View view, Outline outline) {
                outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            }
        });
    }
    floatingButtonContainer.addView(floatingButton, LayoutHelper.createFrame((Build.VERSION.SDK_INT >= 21 ? 56 : 60), (Build.VERSION.SDK_INT >= 21 ? 56 : 60), Gravity.LEFT | Gravity.TOP, 10, 6, 10, 0));
    searchTabsView = null;
    if (!onlySelect && initialDialogsType == 0) {
        fragmentLocationContextView = new FragmentContextView(context, this, true);
        fragmentLocationContextView.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 38, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
        contentView.addView(fragmentLocationContextView);
        fragmentContextView = new FragmentContextView(context, this, false) {

            @Override
            protected void playbackSpeedChanged(float value) {
                if (Math.abs(value - 1.0f) > 0.001f || Math.abs(value - 1.8f) > 0.001f) {
                    getUndoView().showWithAction(0, Math.abs(value - 1.0f) > 0.001f ? UndoView.ACTION_PLAYBACK_SPEED_ENABLED : UndoView.ACTION_PLAYBACK_SPEED_DISABLED, value, null, null);
                }
            }
        };
        fragmentContextView.setLayoutParams(LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 38, Gravity.TOP | Gravity.LEFT, 0, -36, 0, 0));
        contentView.addView(fragmentContextView);
        fragmentContextView.setAdditionalContextView(fragmentLocationContextView);
        fragmentLocationContextView.setAdditionalContextView(fragmentContextView);
    } else if (initialDialogsType == 3) {
        if (commentView != null) {
            commentView.onDestroy();
        }
        commentView = new ChatActivityEnterView(getParentActivity(), contentView, null, false) {

            @Override
            public boolean dispatchTouchEvent(MotionEvent ev) {
                if (ev.getAction() == MotionEvent.ACTION_DOWN) {
                    AndroidUtilities.requestAdjustResize(getParentActivity(), classGuid);
                }
                return super.dispatchTouchEvent(ev);
            }
        };
        commentView.setAllowStickersAndGifs(false, false);
        commentView.setForceShowSendButton(true, false);
        commentView.setVisibility(View.GONE);
        commentView.getSendButton().setAlpha(0);
        contentView.addView(commentView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.BOTTOM));
        commentView.setDelegate(new ChatActivityEnterView.ChatActivityEnterViewDelegate() {

            @Override
            public void onMessageSend(CharSequence message, boolean notify, int scheduleDate) {
                if (delegate == null || selectedDialogs.isEmpty()) {
                    return;
                }
                delegate.didSelectDialogs(DialogsActivity.this, selectedDialogs, message, false);
            }

            @Override
            public void onSwitchRecordMode(boolean video) {
            }

            @Override
            public void onTextSelectionChanged(int start, int end) {
            }

            @Override
            public void onStickersExpandedChange() {
            }

            @Override
            public void onPreAudioVideoRecord() {
            }

            @Override
            public void onTextChanged(final CharSequence text, boolean bigChange) {
            }

            @Override
            public void onTextSpansChanged(CharSequence text) {
            }

            @Override
            public void needSendTyping() {
            }

            @Override
            public void onAttachButtonHidden() {
            }

            @Override
            public void onAttachButtonShow() {
            }

            @Override
            public void onMessageEditEnd(boolean loading) {
            }

            @Override
            public void onWindowSizeChanged(int size) {
            }

            @Override
            public void onStickersTab(boolean opened) {
            }

            @Override
            public void didPressAttachButton() {
            }

            @Override
            public void needStartRecordVideo(int state, boolean notify, int scheduleDate) {
            }

            @Override
            public void needChangeVideoPreviewState(int state, float seekProgress) {
            }

            @Override
            public void needStartRecordAudio(int state) {
            }

            @Override
            public void needShowMediaBanHint() {
            }

            @Override
            public void onUpdateSlowModeButton(View button, boolean show, CharSequence time) {
            }

            @Override
            public void onSendLongClick() {
            }

            @Override
            public void onAudioVideoInterfaceUpdated() {
            }
        });
        writeButtonContainer = new FrameLayout(context) {

            @Override
            public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(info);
                info.setText(LocaleController.formatPluralString("AccDescrShareInChats", selectedDialogs.size()));
                info.setClassName(Button.class.getName());
                info.setLongClickable(true);
                info.setClickable(true);
            }
        };
        writeButtonContainer.setFocusable(true);
        writeButtonContainer.setFocusableInTouchMode(true);
        writeButtonContainer.setVisibility(View.INVISIBLE);
        writeButtonContainer.setScaleX(0.2f);
        writeButtonContainer.setScaleY(0.2f);
        writeButtonContainer.setAlpha(0.0f);
        contentView.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 6, 10));
        textPaint.setTextSize(AndroidUtilities.dp(12));
        textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        selectedCountView = new View(context) {

            @Override
            protected void onDraw(Canvas canvas) {
                String text = String.format("%d", Math.max(1, selectedDialogs.size()));
                int textSize = (int) Math.ceil(textPaint.measureText(text));
                int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
                int cx = getMeasuredWidth() / 2;
                int cy = getMeasuredHeight() / 2;
                textPaint.setColor(getThemedColor(Theme.key_dialogRoundCheckBoxCheck));
                paint.setColor(getThemedColor(Theme.isCurrentThemeDark() ? Theme.key_voipgroup_inviteMembersBackground : Theme.key_dialogBackground));
                rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
                canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
                paint.setColor(getThemedColor(Theme.key_dialogRoundCheckBox));
                rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
                canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
                canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
            }
        };
        selectedCountView.setAlpha(0.0f);
        selectedCountView.setScaleX(0.2f);
        selectedCountView.setScaleY(0.2f);
        contentView.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -8, 9));
        FrameLayout writeButtonBackground = new FrameLayout(context);
        Drawable writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), getThemedColor(Theme.key_dialogFloatingButton), getThemedColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
        if (Build.VERSION.SDK_INT < 21) {
            Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
            shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
            CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, drawable, 0, 0);
            combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            writeButtonDrawable = combinedDrawable;
        }
        writeButtonBackground.setBackgroundDrawable(writeButtonDrawable);
        writeButtonBackground.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            writeButtonBackground.setOutlineProvider(new ViewOutlineProvider() {

                @SuppressLint("NewApi")
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        writeButtonBackground.setOnClickListener(v -> {
            if (delegate == null || selectedDialogs.isEmpty()) {
                return;
            }
            delegate.didSelectDialogs(DialogsActivity.this, selectedDialogs, commentView.getFieldText(), false);
        });
        writeButtonBackground.setOnLongClickListener(v -> {
            if (isNextButton) {
                return false;
            }
            onSendLongClick(writeButtonBackground);
            return true;
        });
        writeButton = new ImageView[2];
        for (int a = 0; a < 2; ++a) {
            writeButton[a] = new ImageView(context);
            writeButton[a].setImageResource(a == 1 ? R.drawable.actionbtn_next : R.drawable.attach_send);
            writeButton[a].setColorFilter(new PorterDuffColorFilter(getThemedColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
            writeButton[a].setScaleType(ImageView.ScaleType.CENTER);
            writeButtonBackground.addView(writeButton[a], LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.CENTER));
        }
        AndroidUtilities.updateViewVisibilityAnimated(writeButton[0], true, 0.5f, false);
        AndroidUtilities.updateViewVisibilityAnimated(writeButton[1], false, 0.5f, false);
        writeButtonContainer.addView(writeButtonBackground, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
    }
    if (filterTabsView != null) {
        contentView.addView(filterTabsView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 44));
    }
    if (!onlySelect) {
        final FrameLayout.LayoutParams layoutParams = LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT);
        if (inPreviewMode && Build.VERSION.SDK_INT >= 21) {
            layoutParams.topMargin = AndroidUtilities.statusBarHeight;
        }
        contentView.addView(actionBar, layoutParams);
    }
    if (searchString == null && initialDialogsType == 0) {
        updateLayout = new FrameLayout(context) {

            private Paint paint = new Paint();

            private Matrix matrix = new Matrix();

            private LinearGradient updateGradient;

            private int lastGradientWidth;

            @Override
            public void draw(Canvas canvas) {
                if (updateGradient != null) {
                    paint.setColor(0xffffffff);
                    paint.setShader(updateGradient);
                    updateGradient.setLocalMatrix(matrix);
                    canvas.drawRect(0, 0, getMeasuredWidth(), getMeasuredHeight(), paint);
                    updateLayoutIcon.setBackgroundGradientDrawable(updateGradient);
                    updateLayoutIcon.draw(canvas);
                }
                super.draw(canvas);
            }

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                int width = MeasureSpec.getSize(widthMeasureSpec);
                if (lastGradientWidth != width) {
                    updateGradient = new LinearGradient(0, 0, width, 0, new int[] { 0xff69BF72, 0xff53B3AD }, new float[] { 0.0f, 1.0f }, Shader.TileMode.CLAMP);
                    lastGradientWidth = width;
                }
                int x = (getMeasuredWidth() - updateTextView.getMeasuredWidth()) / 2;
                updateLayoutIcon.setProgressRect(x, AndroidUtilities.dp(13), x + AndroidUtilities.dp(22), AndroidUtilities.dp(13 + 22));
            }

            @Override
            public void setTranslationY(float translationY) {
                super.setTranslationY(translationY);
                additionalFloatingTranslation2 = AndroidUtilities.dp(48) - translationY;
                if (additionalFloatingTranslation2 < 0) {
                    additionalFloatingTranslation2 = 0;
                }
                if (!floatingHidden) {
                    updateFloatingButtonOffset();
                }
            }
        };
        updateLayout.setWillNotDraw(false);
        updateLayout.setVisibility(View.INVISIBLE);
        updateLayout.setTranslationY(AndroidUtilities.dp(48));
        if (Build.VERSION.SDK_INT >= 21) {
            updateLayout.setBackground(Theme.getSelectorDrawable(0x40ffffff, false));
        }
        contentView.addView(updateLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
        updateLayout.setOnClickListener(v -> {
            if (!SharedConfig.isAppUpdateAvailable()) {
                return;
            }
            AndroidUtilities.openForView(SharedConfig.pendingAppUpdate.document, true, getParentActivity());
        });
        updateLayoutIcon = new RadialProgress2(updateLayout);
        updateLayoutIcon.setColors(0xffffffff, 0xffffffff, 0xffffffff, 0xffffffff);
        updateLayoutIcon.setCircleRadius(AndroidUtilities.dp(11));
        updateLayoutIcon.setAsMini();
        updateLayoutIcon.setIcon(MediaActionDrawable.ICON_UPDATE, true, false);
        updateTextView = new TextView(context);
        updateTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 15);
        updateTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        updateTextView.setText(LocaleController.getString("AppUpdateNow", R.string.AppUpdateNow).toUpperCase());
        updateTextView.setTextColor(0xffffffff);
        updateTextView.setPadding(AndroidUtilities.dp(30), 0, 0, 0);
        updateLayout.addView(updateTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER, 0, 0, 0, 0));
    }
    for (int a = 0; a < 2; a++) {
        undoView[a] = new UndoView(context) {

            @Override
            public void setTranslationY(float translationY) {
                super.setTranslationY(translationY);
                if (this == undoView[0] && undoView[1].getVisibility() != VISIBLE) {
                    additionalFloatingTranslation = getMeasuredHeight() + AndroidUtilities.dp(8) - translationY;
                    if (additionalFloatingTranslation < 0) {
                        additionalFloatingTranslation = 0;
                    }
                    if (!floatingHidden) {
                        updateFloatingButtonOffset();
                    }
                }
            }

            @Override
            protected boolean canUndo() {
                for (int a = 0; a < viewPages.length; a++) {
                    if (viewPages[a].dialogsItemAnimator.isRunning()) {
                        return false;
                    }
                }
                return true;
            }

            @Override
            protected void onRemoveDialogAction(long currentDialogId, int action) {
                if (action == UndoView.ACTION_DELETE || action == UndoView.ACTION_DELETE_FEW) {
                    debugLastUpdateAction = 1;
                    setDialogsListFrozen(true);
                    if (frozenDialogsList != null) {
                        int selectedIndex = -1;
                        for (int i = 0; i < frozenDialogsList.size(); i++) {
                            if (frozenDialogsList.get(i).id == currentDialogId) {
                                selectedIndex = i;
                                break;
                            }
                        }
                        if (selectedIndex >= 0) {
                            TLRPC.Dialog dialog = frozenDialogsList.remove(selectedIndex);
                            viewPages[0].dialogsAdapter.notifyDataSetChanged();
                            int finalSelectedIndex = selectedIndex;
                            AndroidUtilities.runOnUIThread(() -> {
                                if (frozenDialogsList != null) {
                                    frozenDialogsList.add(finalSelectedIndex, dialog);
                                    viewPages[0].dialogsAdapter.notifyItemInserted(finalSelectedIndex);
                                    dialogInsertFinished = 2;
                                }
                            });
                        } else {
                            setDialogsListFrozen(false);
                        }
                    }
                }
            }
        };
        contentView.addView(undoView[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
    }
    if (folderId != 0) {
        viewPages[0].listView.setGlowColor(Theme.getColor(Theme.key_actionBarDefaultArchived));
        actionBar.setTitleColor(Theme.getColor(Theme.key_actionBarDefaultArchivedTitle));
        actionBar.setItemsColor(Theme.getColor(Theme.key_actionBarDefaultArchivedIcon), false);
        actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_actionBarDefaultArchivedSelector), false);
        actionBar.setSearchTextColor(Theme.getColor(Theme.key_actionBarDefaultArchivedSearch), false);
        actionBar.setSearchTextColor(Theme.getColor(Theme.key_actionBarDefaultArchivedSearchPlaceholder), true);
    }
    if (!onlySelect && initialDialogsType == 0) {
        blurredView = new View(context) {

            @Override
            public void setAlpha(float alpha) {
                super.setAlpha(alpha);
                if (fragmentView != null) {
                    fragmentView.invalidate();
                }
            }
        };
        blurredView.setVisibility(View.GONE);
        contentView.addView(blurredView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    }
    actionBarDefaultPaint.setColor(Theme.getColor(folderId == 0 ? Theme.key_actionBarDefault : Theme.key_actionBarDefaultArchived));
    if (inPreviewMode) {
        final TLRPC.User currentUser = getUserConfig().getCurrentUser();
        avatarContainer = new ChatAvatarContainer(actionBar.getContext(), null, false);
        avatarContainer.setTitle(UserObject.getUserName(currentUser));
        avatarContainer.setSubtitle(LocaleController.formatUserStatus(currentAccount, currentUser));
        avatarContainer.setUserAvatar(currentUser, true);
        avatarContainer.setOccupyStatusBar(false);
        avatarContainer.setLeftPadding(AndroidUtilities.dp(10));
        actionBar.addView(avatarContainer, 0, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 40, 0));
        floatingButton.setVisibility(View.INVISIBLE);
        actionBar.setOccupyStatusBar(false);
        actionBar.setBackgroundColor(Theme.getColor(Theme.key_actionBarDefault));
        if (fragmentContextView != null) {
            contentView.removeView(fragmentContextView);
        }
        if (fragmentLocationContextView != null) {
            contentView.removeView(fragmentLocationContextView);
        }
    }
    searchIsShowed = false;
    updateFilterTabs(false, false);
    if (searchString != null) {
        showSearch(true, false);
        actionBar.openSearchField(searchString, false);
    } else if (initialSearchString != null) {
        showSearch(true, false);
        actionBar.openSearchField(initialSearchString, false);
        initialSearchString = null;
        if (filterTabsView != null) {
            filterTabsView.setTranslationY(-AndroidUtilities.dp(44));
        }
    } else {
        showSearch(false, false);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
        FilesMigrationService.checkBottomSheet(this);
    }
    updateMenuButton(false);
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) StickersAlert(org.telegram.ui.Components.StickersAlert) RecyclerAnimationScrollHelper(org.telegram.ui.Components.RecyclerAnimationScrollHelper) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) Property(android.util.Property) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) FilterTabsView(org.telegram.ui.Components.FilterTabsView) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) StateListAnimator(android.animation.StateListAnimator) DrawerProfileCell(org.telegram.ui.Cells.DrawerProfileCell) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) Shader(android.graphics.Shader) Canvas(android.graphics.Canvas) TargetApi(android.annotation.TargetApi) NotificationsController(org.telegram.messenger.NotificationsController) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) Interpolator(android.view.animation.Interpolator) UndoView(org.telegram.ui.Components.UndoView) AnimationProperties(org.telegram.ui.Components.AnimationProperties) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) MenuDrawable(org.telegram.ui.ActionBar.MenuDrawable) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) DialogsAdapter(org.telegram.ui.Adapters.DialogsAdapter) TextPaint(android.text.TextPaint) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DividerCell(org.telegram.ui.Cells.DividerCell) FileLoader(org.telegram.messenger.FileLoader) ViewParent(android.view.ViewParent) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) DialogsSearchAdapter(org.telegram.ui.Adapters.DialogsSearchAdapter) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) FragmentContextView(org.telegram.ui.Components.FragmentContextView) TLRPC(org.telegram.tgnet.TLRPC) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) DialogsEmptyCell(org.telegram.ui.Cells.DialogsEmptyCell) FilesMigrationService(org.telegram.messenger.FilesMigrationService) DialogCell(org.telegram.ui.Cells.DialogCell) ProfileSearchCell(org.telegram.ui.Cells.ProfileSearchCell) JoinGroupAlert(org.telegram.ui.Components.JoinGroupAlert) SearchViewPager(org.telegram.ui.Components.SearchViewPager) ViewPagerFixed(org.telegram.ui.Components.ViewPagerFixed) LinearGradient(android.graphics.LinearGradient) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) UserCell(org.telegram.ui.Cells.UserCell) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) DialogsItemAnimator(org.telegram.ui.Components.DialogsItemAnimator) File(java.io.File) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) DrawerAddCell(org.telegram.ui.Cells.DrawerAddCell) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) ContactsController(org.telegram.messenger.ContactsController) GraySectionCell(org.telegram.ui.Cells.GraySectionCell) Configuration(android.content.res.Configuration) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) FiltersView(org.telegram.ui.Adapters.FiltersView) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) RadialProgress2(org.telegram.ui.Components.RadialProgress2) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) Animator(android.animation.Animator) AccelerateDecelerateInterpolator(android.view.animation.AccelerateDecelerateInterpolator) ViewConfiguration(android.view.ViewConfiguration) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) PacmanAnimation(org.telegram.ui.Components.PacmanAnimation) TextCell(org.telegram.ui.Cells.TextCell) ArchiveHintInnerCell(org.telegram.ui.Cells.ArchiveHintInnerCell) View(android.view.View) Button(android.widget.Button) RecyclerView(androidx.recyclerview.widget.RecyclerView) Matrix(android.graphics.Matrix) RectF(android.graphics.RectF) ImageLoader(org.telegram.messenger.ImageLoader) DrawerUserCell(org.telegram.ui.Cells.DrawerUserCell) Utilities(org.telegram.messenger.Utilities) RLottieImageView(org.telegram.ui.Components.RLottieImageView) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ViewGroup(android.view.ViewGroup) StateSet(android.util.StateSet) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) VelocityTracker(android.view.VelocityTracker) XiaomiUtilities(org.telegram.messenger.XiaomiUtilities) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) FiltersListBottomSheet(org.telegram.ui.Components.FiltersListBottomSheet) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearSmoothScrollerCustom(androidx.recyclerview.widget.LinearSmoothScrollerCustom) TLObject(org.telegram.tgnet.TLObject) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) MediaDataController(org.telegram.messenger.MediaDataController) Build(android.os.Build) DrawerActionCell(org.telegram.ui.Cells.DrawerActionCell) DialogInterface(android.content.DialogInterface) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) DialogObject(org.telegram.messenger.DialogObject) BackupImageView(org.telegram.ui.Components.BackupImageView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) MessagesController(org.telegram.messenger.MessagesController) Color(android.graphics.Color) NumberTextView(org.telegram.ui.Components.NumberTextView) HashtagSearchCell(org.telegram.ui.Cells.HashtagSearchCell) Bitmap(android.graphics.Bitmap) ViewTreeObserver(android.view.ViewTreeObserver) Vibrator(android.os.Vibrator) ProxyDrawable(org.telegram.ui.Components.ProxyDrawable) Activity(android.app.Activity) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LoadingCell(org.telegram.ui.Cells.LoadingCell) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) ArrayList(java.util.ArrayList) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) Matrix(android.graphics.Matrix) Button(android.widget.Button) AccountSelectCell(org.telegram.ui.Cells.AccountSelectCell) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Rect(android.graphics.Rect) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) MenuDrawable(org.telegram.ui.ActionBar.MenuDrawable) Drawable(android.graphics.drawable.Drawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) MediaActionDrawable(org.telegram.ui.Components.MediaActionDrawable) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) MenuDrawable(org.telegram.ui.ActionBar.MenuDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ProxyDrawable(org.telegram.ui.Components.ProxyDrawable) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) LinearGradient(android.graphics.LinearGradient) DialogsSearchAdapter(org.telegram.ui.Adapters.DialogsSearchAdapter) MessagesController(org.telegram.messenger.MessagesController) SearchViewPager(org.telegram.ui.Components.SearchViewPager) FiltersView(org.telegram.ui.Adapters.FiltersView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ItemTouchHelper(androidx.recyclerview.widget.ItemTouchHelper) UndoView(org.telegram.ui.Components.UndoView) DialogsAdapter(org.telegram.ui.Adapters.DialogsAdapter) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) RecyclerAnimationScrollHelper(org.telegram.ui.Components.RecyclerAnimationScrollHelper) Outline(android.graphics.Outline) ViewOutlineProvider(android.view.ViewOutlineProvider) StateListAnimator(android.animation.StateListAnimator) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) DialogsItemAnimator(org.telegram.ui.Components.DialogsItemAnimator) ValueAnimator(android.animation.ValueAnimator) Animator(android.animation.Animator) ObjectAnimator(android.animation.ObjectAnimator) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) TLRPC(org.telegram.tgnet.TLRPC) RadialProgress2(org.telegram.ui.Components.RadialProgress2) BackupImageView(org.telegram.ui.Components.BackupImageView) Dialog(android.app.Dialog) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextView(android.widget.TextView) NumberTextView(org.telegram.ui.Components.NumberTextView) ImageView(android.widget.ImageView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ProxyDrawable(org.telegram.ui.Components.ProxyDrawable) Canvas(android.graphics.Canvas) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) PullForegroundDrawable(org.telegram.ui.Components.PullForegroundDrawable) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) RecyclerItemsEnterAnimator(org.telegram.ui.Components.RecyclerItemsEnterAnimator) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) AvatarDrawable(org.telegram.ui.Components.AvatarDrawable) FilterTabsView(org.telegram.ui.Components.FilterTabsView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) StateListAnimator(android.animation.StateListAnimator) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) AnimatorSet(android.animation.AnimatorSet) DialogsItemAnimator(org.telegram.ui.Components.DialogsItemAnimator) DialogCell(org.telegram.ui.Cells.DialogCell) HintDialogCell(org.telegram.ui.Cells.HintDialogCell) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) FilterTabsView(org.telegram.ui.Components.FilterTabsView) UndoView(org.telegram.ui.Components.UndoView) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) FragmentContextView(org.telegram.ui.Components.FragmentContextView) ScrollView(android.widget.ScrollView) FiltersView(org.telegram.ui.Adapters.FiltersView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RLottieImageView(org.telegram.ui.Components.RLottieImageView) TextView(android.widget.TextView) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) BackupImageView(org.telegram.ui.Components.BackupImageView) FlickerLoadingView(org.telegram.ui.Components.FlickerLoadingView) NumberTextView(org.telegram.ui.Components.NumberTextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) LinearSmoothScrollerCustom(androidx.recyclerview.widget.LinearSmoothScrollerCustom) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) FragmentContextView(org.telegram.ui.Components.FragmentContextView) LinearLayout(android.widget.LinearLayout)

Example 47 with AlertDialog

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

the class ThemeActivity method createView.

@Override
public View createView(Context context) {
    lastIsDarkTheme = !Theme.isCurrentThemeDay();
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    if (currentType == THEME_TYPE_THEMES_BROWSER) {
        actionBar.setTitle(LocaleController.getString("BrowseThemes", R.string.BrowseThemes));
        ActionBarMenu menu = actionBar.createMenu();
        sunDrawable = new RLottieDrawable(R.raw.sun, "" + R.raw.sun, AndroidUtilities.dp(28), AndroidUtilities.dp(28), true, null);
        if (lastIsDarkTheme) {
            sunDrawable.setCurrentFrame(sunDrawable.getFramesCount() - 1);
        } else {
            sunDrawable.setCurrentFrame(0);
        }
        sunDrawable.setPlayInDirectionOfCustomEndFrame(true);
        menuItem = menu.addItem(day_night_switch, sunDrawable);
    } else if (currentType == THEME_TYPE_BASIC) {
        actionBar.setTitle(LocaleController.getString("ChatSettings", R.string.ChatSettings));
        ActionBarMenu menu = actionBar.createMenu();
        menuItem = menu.addItem(0, R.drawable.ic_ab_other);
        menuItem.setContentDescription(LocaleController.getString("AccDescrMoreOptions", R.string.AccDescrMoreOptions));
        menuItem.addSubItem(share_theme, R.drawable.msg_share, LocaleController.getString("ShareTheme", R.string.ShareTheme));
        menuItem.addSubItem(edit_theme, R.drawable.msg_edit, LocaleController.getString("EditThemeColors", R.string.EditThemeColors));
        menuItem.addSubItem(create_theme, R.drawable.menu_palette, LocaleController.getString("CreateNewThemeMenu", R.string.CreateNewThemeMenu));
        menuItem.addSubItem(reset_settings, R.drawable.msg_reset, LocaleController.getString("ThemeResetToDefaults", R.string.ThemeResetToDefaults));
    } else {
        actionBar.setTitle(LocaleController.getString("AutoNightTheme", R.string.AutoNightTheme));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == create_theme) {
                createNewTheme();
            } else if (id == share_theme) {
                Theme.ThemeInfo currentTheme = Theme.getCurrentTheme();
                Theme.ThemeAccent accent = currentTheme.getAccent(false);
                if (accent.info == null) {
                    getMessagesController().saveThemeToServer(accent.parentTheme, accent);
                    NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needShareTheme, accent.parentTheme, accent);
                } else {
                    String link = "https://" + getMessagesController().linkPrefix + "/addtheme/" + accent.info.slug;
                    showDialog(new ShareAlert(getParentActivity(), null, link, false, link, false));
                }
            } else if (id == edit_theme) {
                editTheme();
            } else if (id == reset_settings) {
                if (getParentActivity() == null) {
                    return;
                }
                AlertDialog.Builder builder1 = new AlertDialog.Builder(getParentActivity());
                builder1.setTitle(LocaleController.getString("ThemeResetToDefaultsTitle", R.string.ThemeResetToDefaultsTitle));
                builder1.setMessage(LocaleController.getString("ThemeResetToDefaultsText", R.string.ThemeResetToDefaultsText));
                builder1.setPositiveButton(LocaleController.getString("Reset", R.string.Reset), (dialogInterface, i) -> {
                    boolean changed = false;
                    if (setFontSize(AndroidUtilities.isTablet() ? 18 : 16)) {
                        changed = true;
                    }
                    if (setBubbleRadius(10, true)) {
                        changed = true;
                    }
                    if (changed) {
                        listAdapter.notifyItemChanged(textSizeRow, new Object());
                        listAdapter.notifyItemChanged(bubbleRadiusRow, new Object());
                    }
                    if (themesHorizontalListCell != null) {
                        Theme.ThemeInfo themeInfo = Theme.getTheme("Blue");
                        Theme.ThemeInfo currentTheme = Theme.getCurrentTheme();
                        Theme.ThemeAccent accent = themeInfo.themeAccentsMap.get(Theme.DEFALT_THEME_ACCENT_ID);
                        if (accent != null) {
                            Theme.OverrideWallpaperInfo info = new Theme.OverrideWallpaperInfo();
                            info.slug = Theme.DEFAULT_BACKGROUND_SLUG;
                            info.fileName = "Blue_99_wp.jpg";
                            info.originalFileName = "Blue_99_wp.jpg";
                            accent.overrideWallpaper = info;
                            themeInfo.setOverrideWallpaper(info);
                        }
                        if (themeInfo != currentTheme) {
                            themeInfo.setCurrentAccentId(Theme.DEFALT_THEME_ACCENT_ID);
                            Theme.saveThemeAccents(themeInfo, true, false, true, false);
                            themesHorizontalListCell.selectTheme(themeInfo);
                            themesHorizontalListCell.smoothScrollToPosition(0);
                        } else if (themeInfo.currentAccentId != Theme.DEFALT_THEME_ACCENT_ID) {
                            NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needSetDayNightTheme, currentTheme, currentType == THEME_TYPE_NIGHT, null, Theme.DEFALT_THEME_ACCENT_ID);
                            listAdapter.notifyItemChanged(themeAccentListRow);
                        } else {
                            Theme.reloadWallpaper();
                        }
                    }
                });
                builder1.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                AlertDialog alertDialog = builder1.create();
                showDialog(alertDialog);
                TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
            } else if (id == day_night_switch) {
                SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("themeconfig", Activity.MODE_PRIVATE);
                String dayThemeName = preferences.getString("lastDayTheme", "Blue");
                if (Theme.getTheme(dayThemeName) == null || Theme.getTheme(dayThemeName).isDark()) {
                    dayThemeName = "Blue";
                }
                String nightThemeName = preferences.getString("lastDarkTheme", "Dark Blue");
                if (Theme.getTheme(nightThemeName) == null || !Theme.getTheme(nightThemeName).isDark()) {
                    nightThemeName = "Dark Blue";
                }
                Theme.ThemeInfo themeInfo = Theme.getActiveTheme();
                if (dayThemeName.equals(nightThemeName)) {
                    if (themeInfo.isDark() || dayThemeName.equals("Dark Blue") || dayThemeName.equals("Night")) {
                        dayThemeName = "Blue";
                    } else {
                        nightThemeName = "Dark Blue";
                    }
                }
                boolean toDark;
                if (toDark = dayThemeName.equals(themeInfo.getKey())) {
                    themeInfo = Theme.getTheme(nightThemeName);
                } else {
                    themeInfo = Theme.getTheme(dayThemeName);
                }
                int[] pos = new int[2];
                menuItem.getIconView().getLocationInWindow(pos);
                pos[0] += menuItem.getIconView().getMeasuredWidth() / 2;
                pos[1] += menuItem.getIconView().getMeasuredHeight() / 2;
                NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.needSetDayNightTheme, themeInfo, false, pos, -1, toDark, menuItem.getIconView());
                updateRows(true);
            // AndroidUtilities.updateVisibleRows(listView);
            }
        }
    });
    listAdapter = new ListAdapter(context);
    FrameLayout frameLayout = new FrameLayout(context);
    frameLayout.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    fragmentView = frameLayout;
    listView = new RecyclerListView(context);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setVerticalScrollBarEnabled(false);
    listView.setAdapter(listAdapter);
    ((DefaultItemAnimator) listView.getItemAnimator()).setDelayAnimations(false);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    listView.setOnItemClickListener((view, position, x, y) -> {
        if (position == enableAnimationsRow) {
            SharedPreferences preferences = MessagesController.getGlobalMainSettings();
            boolean animations = preferences.getBoolean("view_animations", true);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("view_animations", !animations);
            editor.commit();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(!animations);
            }
        } else if (position == backgroundRow) {
            presentFragment(new WallpapersListActivity(WallpapersListActivity.TYPE_ALL));
        } else if (position == sendByEnterRow) {
            SharedPreferences preferences = MessagesController.getGlobalMainSettings();
            boolean send = preferences.getBoolean("send_by_enter", false);
            SharedPreferences.Editor editor = preferences.edit();
            editor.putBoolean("send_by_enter", !send);
            editor.commit();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(!send);
            }
        } else if (position == raiseToSpeakRow) {
            SharedConfig.toogleRaiseToSpeak();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.raiseToSpeak);
            }
        } else if (position == saveToGalleryRow) {
            SharedConfig.toggleSaveToGallery();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.saveToGallery);
            }
        } else if (position == distanceRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("DistanceUnitsTitle", R.string.DistanceUnitsTitle));
            builder.setItems(new CharSequence[] { LocaleController.getString("DistanceUnitsAutomatic", R.string.DistanceUnitsAutomatic), LocaleController.getString("DistanceUnitsKilometers", R.string.DistanceUnitsKilometers), LocaleController.getString("DistanceUnitsMiles", R.string.DistanceUnitsMiles) }, (dialog, which) -> {
                SharedConfig.setDistanceSystemType(which);
                RecyclerView.ViewHolder holder = listView.findViewHolderForAdapterPosition(distanceRow);
                if (holder != null) {
                    listAdapter.onBindViewHolder(holder, distanceRow);
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == customTabsRow) {
            SharedConfig.toggleCustomTabs();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.customTabs);
            }
        } else if (position == directShareRow) {
            SharedConfig.toggleDirectShare();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.directShare);
            }
        } else if (position == contactsReimportRow) {
        // not implemented
        } else if (position == contactsSortRow) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("SortBy", R.string.SortBy));
            builder.setItems(new CharSequence[] { LocaleController.getString("Default", R.string.Default), LocaleController.getString("SortFirstName", R.string.SortFirstName), LocaleController.getString("SortLastName", R.string.SortLastName) }, (dialog, which) -> {
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                SharedPreferences.Editor editor = preferences.edit();
                editor.putInt("sortContactsBy", which);
                editor.commit();
                if (listAdapter != null) {
                    listAdapter.notifyItemChanged(position);
                }
            });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        } else if (position == stickersRow) {
            presentFragment(new StickersActivity(MediaDataController.TYPE_IMAGE));
        } else if (position == reactionsDoubleTapRow) {
            presentFragment(new ReactionsDoubleTapManageActivity());
        } else if (position == emojiRow) {
            SharedConfig.toggleBigEmoji();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.allowBigEmoji);
            }
        } else if (position == chatBlurRow) {
            SharedConfig.toggleChatBlur();
            if (view instanceof TextCheckCell) {
                ((TextCheckCell) view).setChecked(SharedConfig.chatBlurEnabled());
            }
        } else if (position == nightThemeRow) {
            if (LocaleController.isRTL && x <= AndroidUtilities.dp(76) || !LocaleController.isRTL && x >= view.getMeasuredWidth() - AndroidUtilities.dp(76)) {
                NotificationsCheckCell checkCell = (NotificationsCheckCell) view;
                if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_NONE) {
                    Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_AUTOMATIC;
                    checkCell.setChecked(true);
                } else {
                    Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_NONE;
                    checkCell.setChecked(false);
                }
                Theme.saveAutoNightThemeConfig();
                Theme.checkAutoNightThemeConditions(true);
                boolean enabled = Theme.selectedAutoNightType != Theme.AUTO_NIGHT_TYPE_NONE;
                String value = enabled ? Theme.getCurrentNightThemeName() : LocaleController.getString("AutoNightThemeOff", R.string.AutoNightThemeOff);
                if (enabled) {
                    String type;
                    if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
                        type = LocaleController.getString("AutoNightScheduled", R.string.AutoNightScheduled);
                    } else if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
                        type = LocaleController.getString("AutoNightSystemDefault", R.string.AutoNightSystemDefault);
                    } else {
                        type = LocaleController.getString("AutoNightAdaptive", R.string.AutoNightAdaptive);
                    }
                    value = type + " " + value;
                }
                checkCell.setTextAndValueAndCheck(LocaleController.getString("AutoNightTheme", R.string.AutoNightTheme), value, enabled, true);
            } else {
                presentFragment(new ThemeActivity(THEME_TYPE_NIGHT));
            }
        } else if (position == nightDisabledRow) {
            if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_NONE) {
                return;
            }
            Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_NONE;
            updateRows(true);
            Theme.checkAutoNightThemeConditions();
        } else if (position == nightScheduledRow) {
            if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SCHEDULED) {
                return;
            }
            Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_SCHEDULED;
            if (Theme.autoNightScheduleByLocation) {
                updateSunTime(null, true);
            }
            updateRows(true);
            Theme.checkAutoNightThemeConditions();
        } else if (position == nightAutomaticRow) {
            if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_AUTOMATIC) {
                return;
            }
            Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_AUTOMATIC;
            updateRows(true);
            Theme.checkAutoNightThemeConditions();
        } else if (position == nightSystemDefaultRow) {
            if (Theme.selectedAutoNightType == Theme.AUTO_NIGHT_TYPE_SYSTEM) {
                return;
            }
            Theme.selectedAutoNightType = Theme.AUTO_NIGHT_TYPE_SYSTEM;
            updateRows(true);
            Theme.checkAutoNightThemeConditions();
        } else if (position == scheduleLocationRow) {
            Theme.autoNightScheduleByLocation = !Theme.autoNightScheduleByLocation;
            TextCheckCell checkCell = (TextCheckCell) view;
            checkCell.setChecked(Theme.autoNightScheduleByLocation);
            updateRows(true);
            if (Theme.autoNightScheduleByLocation) {
                updateSunTime(null, true);
            }
            Theme.checkAutoNightThemeConditions();
        } else if (position == scheduleFromRow || position == scheduleToRow) {
            if (getParentActivity() == null) {
                return;
            }
            int currentHour;
            int currentMinute;
            if (position == scheduleFromRow) {
                currentHour = Theme.autoNightDayStartTime / 60;
                currentMinute = (Theme.autoNightDayStartTime - currentHour * 60);
            } else {
                currentHour = Theme.autoNightDayEndTime / 60;
                currentMinute = (Theme.autoNightDayEndTime - currentHour * 60);
            }
            final TextSettingsCell cell = (TextSettingsCell) view;
            TimePickerDialog dialog = new TimePickerDialog(getParentActivity(), (view1, hourOfDay, minute) -> {
                int time = hourOfDay * 60 + minute;
                if (position == scheduleFromRow) {
                    Theme.autoNightDayStartTime = time;
                    cell.setTextAndValue(LocaleController.getString("AutoNightFrom", R.string.AutoNightFrom), String.format("%02d:%02d", hourOfDay, minute), true);
                } else {
                    Theme.autoNightDayEndTime = time;
                    cell.setTextAndValue(LocaleController.getString("AutoNightTo", R.string.AutoNightTo), String.format("%02d:%02d", hourOfDay, minute), true);
                }
            }, currentHour, currentMinute, true);
            showDialog(dialog);
        } else if (position == scheduleUpdateLocationRow) {
            updateSunTime(null, true);
        } else if (position == createNewThemeRow) {
            createNewTheme();
        } else if (position == editThemeRow) {
            editTheme();
        }
    });
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Address(android.location.Address) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Bundle(android.os.Bundle) SvgHelper(org.telegram.messenger.SvgHelper) PackageManager(android.content.pm.PackageManager) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) AndroidUtilities(org.telegram.messenger.AndroidUtilities) BrightnessControlCell(org.telegram.ui.Cells.BrightnessControlCell) LocationListener(android.location.LocationListener) Drawable(android.graphics.drawable.Drawable) Manifest(android.Manifest) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) Keep(androidx.annotation.Keep) ApplicationLoader(org.telegram.messenger.ApplicationLoader) TextCell(org.telegram.ui.Cells.TextCell) Locale(java.util.Locale) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) RecyclerView(androidx.recyclerview.widget.RecyclerView) SunDate(org.telegram.messenger.time.SunDate) DocumentObject(org.telegram.messenger.DocumentObject) Utilities(org.telegram.messenger.Utilities) ObjectAnimator(android.animation.ObjectAnimator) ImageLocation(org.telegram.messenger.ImageLocation) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) Geocoder(android.location.Geocoder) ViewGroup(android.view.ViewGroup) ShareAlert(org.telegram.ui.Components.ShareAlert) NotificationCenter(org.telegram.messenger.NotificationCenter) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) ThemeTypeCell(org.telegram.ui.Cells.ThemeTypeCell) List(java.util.List) TextView(android.widget.TextView) EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) TextPaint(android.text.TextPaint) FileProvider(androidx.core.content.FileProvider) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Location(android.location.Location) LocationManager(android.location.LocationManager) FileLoader(org.telegram.messenger.FileLoader) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) TimePickerDialog(android.app.TimePickerDialog) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) HeaderCell(org.telegram.ui.Cells.HeaderCell) SwipeGestureSettingsView(org.telegram.ui.Components.SwipeGestureSettingsView) AlertsCreator(org.telegram.ui.Components.AlertsCreator) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) Calendar(java.util.Calendar) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) BuildConfig(org.telegram.messenger.BuildConfig) SharedConfig(org.telegram.messenger.SharedConfig) MediaDataController(org.telegram.messenger.MediaDataController) ChatListCell(org.telegram.ui.Cells.ChatListCell) Build(android.os.Build) SeekBarView(org.telegram.ui.Components.SeekBarView) DialogInterface(android.content.DialogInterface) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) ThemesHorizontalListCell(org.telegram.ui.Cells.ThemesHorizontalListCell) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) File(java.io.File) MessagesController(org.telegram.messenger.MessagesController) ThemePreviewMessagesCell(org.telegram.ui.Cells.ThemePreviewMessagesCell) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Activity(android.app.Activity) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) Collections(java.util.Collections) RecyclerListView(org.telegram.ui.Components.RecyclerListView) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) ShareAlert(org.telegram.ui.Components.ShareAlert) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) SharedPreferences(android.content.SharedPreferences) TimePickerDialog(android.app.TimePickerDialog) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) NotificationsCheckCell(org.telegram.ui.Cells.NotificationsCheckCell) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) FrameLayout(android.widget.FrameLayout) Theme(org.telegram.ui.ActionBar.Theme) DocumentObject(org.telegram.messenger.DocumentObject)

Example 48 with AlertDialog

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

the class PhotoPickerActivity method createView.

@SuppressWarnings("unchecked")
@Override
public View createView(Context context) {
    listSort = false;
    actionBar.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
    actionBar.setTitleColor(Theme.getColor(textKey));
    actionBar.setItemsColor(Theme.getColor(textKey), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(selectorKey), false);
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    if (selectedAlbum != null) {
        actionBar.setTitle(selectedAlbum.bucketName);
    } else if (type == 0) {
        actionBar.setTitle(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
    } else if (type == 1) {
        actionBar.setTitle(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == change_sort) {
                listSort = !listSort;
                if (listSort) {
                    listView.setPadding(0, 0, 0, AndroidUtilities.dp(48));
                } else {
                    listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
                }
                listView.stopScroll();
                layoutManager.scrollToPositionWithOffset(0, 0);
                listAdapter.notifyDataSetChanged();
            } else if (id == open_in) {
                if (delegate != null) {
                    delegate.onOpenInPressed();
                }
                finishFragment();
            }
        }
    });
    if (isDocumentsPicker) {
        ActionBarMenu menu = actionBar.createMenu();
        ActionBarMenuItem menuItem = menu.addItem(0, R.drawable.ic_ab_other);
        menuItem.setSubMenuDelegate(new ActionBarMenuItem.ActionBarSubMenuItemDelegate() {

            @Override
            public void onShowSubMenu() {
                showAsListItem.setText(listSort ? LocaleController.getString("ShowAsGrid", R.string.ShowAsGrid) : LocaleController.getString("ShowAsList", R.string.ShowAsList));
                showAsListItem.setIcon(listSort ? R.drawable.msg_media : R.drawable.msg_list);
            }

            @Override
            public void onHideSubMenu() {
            }
        });
        showAsListItem = menuItem.addSubItem(change_sort, R.drawable.msg_list, LocaleController.getString("ShowAsList", R.string.ShowAsList));
        menuItem.addSubItem(open_in, R.drawable.msg_openin, LocaleController.getString("OpenInExternalApp", R.string.OpenInExternalApp));
    }
    if (selectedAlbum == null) {
        ActionBarMenu menu = actionBar.createMenu();
        searchItem = menu.addItem(0, R.drawable.ic_ab_search).setIsSearchField(true).setActionBarMenuItemSearchListener(new ActionBarMenuItem.ActionBarMenuItemSearchListener() {

            @Override
            public void onSearchExpand() {
            }

            @Override
            public boolean canCollapseSearch() {
                finishFragment();
                return false;
            }

            @Override
            public void onTextChanged(EditText editText) {
                if (editText.getText().length() == 0) {
                    searchResult.clear();
                    searchResultKeys.clear();
                    lastSearchString = null;
                    imageSearchEndReached = true;
                    searching = false;
                    if (imageReqId != 0) {
                        ConnectionsManager.getInstance(currentAccount).cancelRequest(imageReqId, true);
                        imageReqId = 0;
                    }
                    emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
                    updateSearchInterface();
                }
            }

            @Override
            public void onSearchPressed(EditText editText) {
                processSearch(editText);
            }
        });
        EditTextBoldCursor editText = searchItem.getSearchField();
        editText.setTextColor(Theme.getColor(textKey));
        editText.setCursorColor(Theme.getColor(textKey));
        editText.setHintTextColor(Theme.getColor(Theme.key_chat_messagePanelHint));
    }
    if (selectedAlbum == null) {
        if (type == 0) {
            searchItem.setSearchFieldHint(LocaleController.getString("SearchImagesTitle", R.string.SearchImagesTitle));
        } else if (type == 1) {
            searchItem.setSearchFieldHint(LocaleController.getString("SearchGifsTitle", R.string.SearchGifsTitle));
        }
    }
    sizeNotifierFrameLayout = new SizeNotifierFrameLayout(context) {

        private int lastNotifyWidth;

        private boolean ignoreLayout;

        private int lastItemSize;

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            int totalHeight = MeasureSpec.getSize(heightMeasureSpec);
            int availableWidth = MeasureSpec.getSize(widthMeasureSpec);
            if (AndroidUtilities.isTablet()) {
                itemsPerRow = 4;
            } else if (AndroidUtilities.displaySize.x > AndroidUtilities.displaySize.y) {
                itemsPerRow = 4;
            } else {
                itemsPerRow = 3;
            }
            ignoreLayout = true;
            itemSize = (availableWidth - AndroidUtilities.dp(6 * 2) - AndroidUtilities.dp(5 * 2)) / itemsPerRow;
            if (lastItemSize != itemSize) {
                lastItemSize = itemSize;
                AndroidUtilities.runOnUIThread(() -> listAdapter.notifyDataSetChanged());
            }
            if (listSort) {
                layoutManager.setSpanCount(1);
            } else {
                layoutManager.setSpanCount(itemSize * itemsPerRow + AndroidUtilities.dp(5) * (itemsPerRow - 1));
            }
            ignoreLayout = false;
            onMeasureInternal(widthMeasureSpec, MeasureSpec.makeMeasureSpec(totalHeight, MeasureSpec.EXACTLY));
        }

        private void onMeasureInternal(int widthMeasureSpec, int heightMeasureSpec) {
            int widthSize = MeasureSpec.getSize(widthMeasureSpec);
            int heightSize = MeasureSpec.getSize(heightMeasureSpec);
            setMeasuredDimension(widthSize, heightSize);
            int kbHeight = measureKeyboardHeight();
            int keyboardSize = SharedConfig.smoothKeyboard ? 0 : kbHeight;
            if (keyboardSize <= AndroidUtilities.dp(20)) {
                if (!AndroidUtilities.isInMultiwindow && commentTextView != null && frameLayout2.getParent() == this) {
                    heightSize -= commentTextView.getEmojiPadding();
                    heightMeasureSpec = MeasureSpec.makeMeasureSpec(heightSize, MeasureSpec.EXACTLY);
                }
            }
            if (kbHeight > AndroidUtilities.dp(20) && commentTextView != null) {
                ignoreLayout = true;
                commentTextView.hideEmojiView();
                ignoreLayout = false;
            }
            if (SharedConfig.smoothKeyboard && commentTextView != null && commentTextView.isPopupShowing()) {
                fragmentView.setTranslationY(0);
                listView.setTranslationY(0);
                emptyView.setTranslationY(0);
            }
            int childCount = getChildCount();
            for (int i = 0; i < childCount; i++) {
                View child = getChildAt(i);
                if (child == null || child.getVisibility() == GONE) {
                    continue;
                }
                if (commentTextView != null && commentTextView.isPopupView(child)) {
                    if (AndroidUtilities.isInMultiwindow || AndroidUtilities.isTablet()) {
                        if (AndroidUtilities.isTablet()) {
                            child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(Math.min(AndroidUtilities.dp(AndroidUtilities.isTablet() ? 200 : 320), heightSize - AndroidUtilities.statusBarHeight + getPaddingTop()), MeasureSpec.EXACTLY));
                        } else {
                            child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(heightSize - AndroidUtilities.statusBarHeight + getPaddingTop(), MeasureSpec.EXACTLY));
                        }
                    } else {
                        child.measure(MeasureSpec.makeMeasureSpec(widthSize, MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec(child.getLayoutParams().height, MeasureSpec.EXACTLY));
                    }
                } else {
                    measureChildWithMargins(child, widthMeasureSpec, 0, heightMeasureSpec, 0);
                }
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            if (lastNotifyWidth != r - l) {
                lastNotifyWidth = r - l;
                if (listAdapter != null) {
                    listAdapter.notifyDataSetChanged();
                }
                if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                    sendPopupWindow.dismiss();
                }
            }
            final int count = getChildCount();
            int keyboardSize = SharedConfig.smoothKeyboard ? 0 : measureKeyboardHeight();
            int paddingBottom = commentTextView != null && frameLayout2.getParent() == this && keyboardSize <= AndroidUtilities.dp(20) && !AndroidUtilities.isInMultiwindow && !AndroidUtilities.isTablet() ? commentTextView.getEmojiPadding() : 0;
            setBottomClip(paddingBottom);
            for (int i = 0; i < count; i++) {
                final View child = getChildAt(i);
                if (child.getVisibility() == GONE) {
                    continue;
                }
                final LayoutParams lp = (LayoutParams) child.getLayoutParams();
                final int width = child.getMeasuredWidth();
                final int height = child.getMeasuredHeight();
                int childLeft;
                int childTop;
                int gravity = lp.gravity;
                if (gravity == -1) {
                    gravity = Gravity.TOP | Gravity.LEFT;
                }
                final int absoluteGravity = gravity & Gravity.HORIZONTAL_GRAVITY_MASK;
                final int verticalGravity = gravity & Gravity.VERTICAL_GRAVITY_MASK;
                switch(absoluteGravity & Gravity.HORIZONTAL_GRAVITY_MASK) {
                    case Gravity.CENTER_HORIZONTAL:
                        childLeft = (r - l - width) / 2 + lp.leftMargin - lp.rightMargin;
                        break;
                    case Gravity.RIGHT:
                        childLeft = (r - l) - width - lp.rightMargin - getPaddingRight();
                        break;
                    case Gravity.LEFT:
                    default:
                        childLeft = lp.leftMargin + getPaddingLeft();
                }
                switch(verticalGravity) {
                    case Gravity.TOP:
                        childTop = lp.topMargin + getPaddingTop();
                        break;
                    case Gravity.CENTER_VERTICAL:
                        childTop = ((b - paddingBottom) - t - height) / 2 + lp.topMargin - lp.bottomMargin;
                        break;
                    case Gravity.BOTTOM:
                        childTop = ((b - paddingBottom) - t) - height - lp.bottomMargin;
                        break;
                    default:
                        childTop = lp.topMargin;
                }
                if (commentTextView != null && commentTextView.isPopupView(child)) {
                    if (AndroidUtilities.isTablet()) {
                        childTop = getMeasuredHeight() - child.getMeasuredHeight();
                    } else {
                        childTop = getMeasuredHeight() + keyboardSize - child.getMeasuredHeight();
                    }
                }
                child.layout(childLeft, childTop, childLeft + width, childTop + height);
            }
            notifyHeightChanged();
        }

        @Override
        public void requestLayout() {
            if (ignoreLayout) {
                return;
            }
            super.requestLayout();
        }
    };
    sizeNotifierFrameLayout.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
    fragmentView = sizeNotifierFrameLayout;
    listView = new RecyclerListView(context);
    listView.setPadding(AndroidUtilities.dp(6), AndroidUtilities.dp(8), AndroidUtilities.dp(6), AndroidUtilities.dp(50));
    listView.setClipToPadding(false);
    listView.setHorizontalScrollBarEnabled(false);
    listView.setVerticalScrollBarEnabled(false);
    listView.setItemAnimator(null);
    listView.setLayoutAnimation(null);
    listView.setLayoutManager(layoutManager = new GridLayoutManager(context, 4) {

        @Override
        public boolean supportsPredictiveItemAnimations() {
            return false;
        }
    });
    layoutManager.setSpanSizeLookup(new GridLayoutManager.SpanSizeLookup() {

        @Override
        public int getSpanSize(int position) {
            if (listAdapter.getItemViewType(position) == 1 || listSort || selectedAlbum == null && TextUtils.isEmpty(lastSearchString)) {
                return layoutManager.getSpanCount();
            } else {
                return itemSize + (position % itemsPerRow != itemsPerRow - 1 ? AndroidUtilities.dp(5) : 0);
            }
        }
    });
    sizeNotifierFrameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP));
    listView.setAdapter(listAdapter = new ListAdapter(context));
    listView.setGlowColor(Theme.getColor(dialogBackgroundKey));
    listView.setOnItemClickListener((view, position) -> {
        if (selectedAlbum == null && searchResult.isEmpty()) {
            if (position < recentSearches.size()) {
                String text = recentSearches.get(position);
                if (searchDelegate != null) {
                    searchDelegate.shouldSearchText(text);
                } else {
                    searchItem.getSearchField().setText(text);
                    searchItem.getSearchField().setSelection(text.length());
                    processSearch(searchItem.getSearchField());
                }
            } else if (position == recentSearches.size() + 1) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("ClearSearchAlertTitle", R.string.ClearSearchAlertTitle));
                builder.setMessage(LocaleController.getString("ClearSearchAlert", R.string.ClearSearchAlert));
                builder.setPositiveButton(LocaleController.getString("ClearButton", R.string.ClearButton).toUpperCase(), (dialogInterface, i) -> {
                    if (searchDelegate != null) {
                        searchDelegate.shouldClearRecentSearch();
                    } else {
                        clearRecentSearch();
                    }
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                AlertDialog dialog = builder.create();
                showDialog(dialog);
                TextView button = (TextView) dialog.getButton(DialogInterface.BUTTON_POSITIVE);
                if (button != null) {
                    button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
                }
                return;
            }
            return;
        }
        ArrayList<Object> arrayList;
        if (selectedAlbum != null) {
            arrayList = (ArrayList) selectedAlbum.photos;
        } else {
            arrayList = (ArrayList) searchResult;
        }
        if (position < 0 || position >= arrayList.size()) {
            return;
        }
        if (searchItem != null) {
            AndroidUtilities.hideKeyboard(searchItem.getSearchField());
        }
        if (listSort) {
            onListItemClick(view, arrayList.get(position));
        } else {
            int type;
            if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR || selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_AVATAR_VIDEO) {
                type = PhotoViewer.SELECT_TYPE_AVATAR;
            } else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_WALLPAPER) {
                type = PhotoViewer.SELECT_TYPE_WALLPAPER;
            } else if (selectPhotoType == PhotoAlbumPickerActivity.SELECT_TYPE_QR) {
                type = PhotoViewer.SELECT_TYPE_QR;
            } else if (chatActivity == null) {
                type = 4;
            } else {
                type = 0;
            }
            PhotoViewer.getInstance().setParentActivity(getParentActivity());
            PhotoViewer.getInstance().setMaxSelectedPhotos(maxSelectedPhotos, allowOrder);
            PhotoViewer.getInstance().openPhotoForSelect(arrayList, position, type, isDocumentsPicker, provider, chatActivity);
        }
    });
    if (maxSelectedPhotos != 1) {
        listView.setOnItemLongClickListener((view, position) -> {
            if (listSort) {
                onListItemClick(view, selectedAlbum.photos.get(position));
                return true;
            } else {
                if (view instanceof PhotoAttachPhotoCell) {
                    PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
                    itemRangeSelector.setIsActive(view, true, position, shouldSelect = !cell.isChecked());
                }
            }
            return false;
        });
    }
    itemRangeSelector = new RecyclerViewItemRangeSelector(new RecyclerViewItemRangeSelector.RecyclerViewItemRangeSelectorDelegate() {

        @Override
        public int getItemCount() {
            return listAdapter.getItemCount();
        }

        @Override
        public void setSelected(View view, int index, boolean selected) {
            if (selected != shouldSelect || !(view instanceof PhotoAttachPhotoCell)) {
                return;
            }
            PhotoAttachPhotoCell cell = (PhotoAttachPhotoCell) view;
            cell.callDelegate();
        }

        @Override
        public boolean isSelected(int index) {
            Object key;
            if (selectedAlbum != null) {
                MediaController.PhotoEntry photoEntry = selectedAlbum.photos.get(index);
                key = photoEntry.imageId;
            } else {
                MediaController.SearchImage photoEntry = searchResult.get(index);
                key = photoEntry.id;
            }
            return selectedPhotos.containsKey(key);
        }

        @Override
        public boolean isIndexSelectable(int index) {
            return listAdapter.getItemViewType(index) == 0;
        }

        @Override
        public void onStartStopSelection(boolean start) {
            alertOnlyOnce = start ? 1 : 0;
            if (start) {
                parentLayout.requestDisallowInterceptTouchEvent(true);
            }
            listView.hideSelector(true);
        }
    });
    if (maxSelectedPhotos != 1) {
        listView.addOnItemTouchListener(itemRangeSelector);
    }
    emptyView = new EmptyTextProgressView(context);
    emptyView.setTextColor(0xff93999d);
    emptyView.setProgressBarColor(0xff527da3);
    if (selectedAlbum != null) {
        emptyView.setShowAtCenter(false);
        emptyView.setText(LocaleController.getString("NoPhotos", R.string.NoPhotos));
    } else {
        emptyView.setShowAtTop(true);
        emptyView.setPadding(0, AndroidUtilities.dp(200), 0, 0);
        emptyView.setText(LocaleController.getString("NoRecentSearches", R.string.NoRecentSearches));
    }
    sizeNotifierFrameLayout.addView(emptyView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL ? 0 : 48));
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrollStateChanged(RecyclerView recyclerView, int newState) {
            if (newState == RecyclerView.SCROLL_STATE_DRAGGING) {
                AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
            }
        }

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            if (selectedAlbum == null) {
                int firstVisibleItem = layoutManager.findFirstVisibleItemPosition();
                int visibleItemCount = firstVisibleItem == RecyclerView.NO_POSITION ? 0 : Math.abs(layoutManager.findLastVisibleItemPosition() - firstVisibleItem) + 1;
                if (visibleItemCount > 0) {
                    int totalItemCount = layoutManager.getItemCount();
                    if (firstVisibleItem + visibleItemCount > totalItemCount - 2 && !searching) {
                        if (!imageSearchEndReached) {
                            searchImages(type == 1, lastSearchString, nextImagesSearchOffset, true);
                        }
                    }
                }
            }
        }
    });
    if (selectedAlbum == null) {
        updateSearchInterface();
    }
    if (needsBottomLayout) {
        shadow = new View(context);
        shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
        shadow.setTranslationY(AndroidUtilities.dp(48));
        sizeNotifierFrameLayout.addView(shadow, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 3, Gravity.BOTTOM | Gravity.LEFT, 0, 0, 0, 48));
        frameLayout2 = new FrameLayout(context);
        frameLayout2.setBackgroundColor(Theme.getColor(dialogBackgroundKey));
        frameLayout2.setVisibility(View.INVISIBLE);
        frameLayout2.setTranslationY(AndroidUtilities.dp(48));
        sizeNotifierFrameLayout.addView(frameLayout2, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.LEFT | Gravity.BOTTOM));
        frameLayout2.setOnTouchListener((v, event) -> true);
        if (commentTextView != null) {
            commentTextView.onDestroy();
        }
        commentTextView = new EditTextEmoji(context, sizeNotifierFrameLayout, null, EditTextEmoji.STYLE_DIALOG);
        InputFilter[] inputFilters = new InputFilter[1];
        inputFilters[0] = new InputFilter.LengthFilter(MessagesController.getInstance(UserConfig.selectedAccount).maxCaptionLength);
        commentTextView.setFilters(inputFilters);
        commentTextView.setHint(LocaleController.getString("AddCaption", R.string.AddCaption));
        commentTextView.onResume();
        EditTextBoldCursor editText = commentTextView.getEditText();
        editText.setMaxLines(1);
        editText.setSingleLine(true);
        frameLayout2.addView(commentTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.TOP | Gravity.LEFT, 0, 0, 84, 0));
        if (caption != null) {
            commentTextView.setText(caption);
        }
        commentTextView.getEditText().addTextChangedListener(new TextWatcher() {

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
            }

            @Override
            public void afterTextChanged(Editable s) {
                if (delegate != null) {
                    delegate.onCaptionChanged(s);
                }
            }
        });
        writeButtonContainer = new FrameLayout(context) {

            @Override
            public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
                super.onInitializeAccessibilityNodeInfo(info);
                info.setText(LocaleController.formatPluralString("AccDescrSendPhotos", selectedPhotos.size()));
                info.setClassName(Button.class.getName());
                info.setLongClickable(true);
                info.setClickable(true);
            }
        };
        writeButtonContainer.setFocusable(true);
        writeButtonContainer.setFocusableInTouchMode(true);
        writeButtonContainer.setVisibility(View.INVISIBLE);
        writeButtonContainer.setScaleX(0.2f);
        writeButtonContainer.setScaleY(0.2f);
        writeButtonContainer.setAlpha(0.0f);
        sizeNotifierFrameLayout.addView(writeButtonContainer, LayoutHelper.createFrame(60, 60, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, 12, 10));
        writeButton = new ImageView(context);
        writeButtonDrawable = Theme.createSimpleSelectorCircleDrawable(AndroidUtilities.dp(56), Theme.getColor(Theme.key_dialogFloatingButton), Theme.getColor(Build.VERSION.SDK_INT >= 21 ? Theme.key_dialogFloatingButtonPressed : Theme.key_dialogFloatingButton));
        if (Build.VERSION.SDK_INT < 21) {
            Drawable shadowDrawable = context.getResources().getDrawable(R.drawable.floating_shadow_profile).mutate();
            shadowDrawable.setColorFilter(new PorterDuffColorFilter(0xff000000, PorterDuff.Mode.MULTIPLY));
            CombinedDrawable combinedDrawable = new CombinedDrawable(shadowDrawable, writeButtonDrawable, 0, 0);
            combinedDrawable.setIconSize(AndroidUtilities.dp(56), AndroidUtilities.dp(56));
            writeButtonDrawable = combinedDrawable;
        }
        writeButton.setBackgroundDrawable(writeButtonDrawable);
        writeButton.setImageResource(R.drawable.attach_send);
        writeButton.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO);
        writeButton.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_dialogFloatingIcon), PorterDuff.Mode.MULTIPLY));
        writeButton.setScaleType(ImageView.ScaleType.CENTER);
        if (Build.VERSION.SDK_INT >= 21) {
            writeButton.setOutlineProvider(new ViewOutlineProvider() {

                @SuppressLint("NewApi")
                @Override
                public void getOutline(View view, Outline outline) {
                    outline.setOval(0, 0, AndroidUtilities.dp(56), AndroidUtilities.dp(56));
                }
            });
        }
        writeButtonContainer.addView(writeButton, LayoutHelper.createFrame(Build.VERSION.SDK_INT >= 21 ? 56 : 60, Build.VERSION.SDK_INT >= 21 ? 56 : 60, Gravity.LEFT | Gravity.TOP, Build.VERSION.SDK_INT >= 21 ? 2 : 0, 0, 0, 0));
        writeButton.setOnClickListener(v -> {
            if (chatActivity != null && chatActivity.isInScheduleMode()) {
                AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
            } else {
                sendSelectedPhotos(true, 0);
            }
        });
        writeButton.setOnLongClickListener(view -> {
            if (chatActivity == null || maxSelectedPhotos == 1) {
                return false;
            }
            TLRPC.Chat chat = chatActivity.getCurrentChat();
            TLRPC.User user = chatActivity.getCurrentUser();
            if (sendPopupLayout == null) {
                sendPopupLayout = new ActionBarPopupWindow.ActionBarPopupWindowLayout(getParentActivity());
                sendPopupLayout.setAnimationEnabled(false);
                sendPopupLayout.setOnTouchListener(new View.OnTouchListener() {

                    private android.graphics.Rect popupRect = new android.graphics.Rect();

                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
                        if (event.getActionMasked() == MotionEvent.ACTION_DOWN) {
                            if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                                v.getHitRect(popupRect);
                                if (!popupRect.contains((int) event.getX(), (int) event.getY())) {
                                    sendPopupWindow.dismiss();
                                }
                            }
                        }
                        return false;
                    }
                });
                sendPopupLayout.setDispatchKeyEventListener(keyEvent -> {
                    if (keyEvent.getKeyCode() == KeyEvent.KEYCODE_BACK && keyEvent.getRepeatCount() == 0 && sendPopupWindow != null && sendPopupWindow.isShowing()) {
                        sendPopupWindow.dismiss();
                    }
                });
                sendPopupLayout.setShownFromBotton(false);
                itemCells = new ActionBarMenuSubItem[2];
                for (int a = 0; a < 2; a++) {
                    if (a == 0 && !chatActivity.canScheduleMessage() || a == 1 && UserObject.isUserSelf(user)) {
                        continue;
                    }
                    int num = a;
                    itemCells[a] = new ActionBarMenuSubItem(getParentActivity(), a == 0, a == 1);
                    if (num == 0) {
                        if (UserObject.isUserSelf(user)) {
                            itemCells[a].setTextAndIcon(LocaleController.getString("SetReminder", R.string.SetReminder), R.drawable.msg_schedule);
                        } else {
                            itemCells[a].setTextAndIcon(LocaleController.getString("ScheduleMessage", R.string.ScheduleMessage), R.drawable.msg_schedule);
                        }
                    } else {
                        itemCells[a].setTextAndIcon(LocaleController.getString("SendWithoutSound", R.string.SendWithoutSound), R.drawable.input_notify_off);
                    }
                    itemCells[a].setMinimumWidth(AndroidUtilities.dp(196));
                    sendPopupLayout.addView(itemCells[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 48));
                    itemCells[a].setOnClickListener(v -> {
                        if (sendPopupWindow != null && sendPopupWindow.isShowing()) {
                            sendPopupWindow.dismiss();
                        }
                        if (num == 0) {
                            AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), chatActivity.getDialogId(), this::sendSelectedPhotos);
                        } else {
                            sendSelectedPhotos(true, 0);
                        }
                    });
                }
                sendPopupLayout.setupRadialSelectors(Theme.getColor(selectorKey));
                sendPopupWindow = new ActionBarPopupWindow(sendPopupLayout, LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT);
                sendPopupWindow.setAnimationEnabled(false);
                sendPopupWindow.setAnimationStyle(R.style.PopupContextAnimation2);
                sendPopupWindow.setOutsideTouchable(true);
                sendPopupWindow.setClippingEnabled(true);
                sendPopupWindow.setInputMethodMode(ActionBarPopupWindow.INPUT_METHOD_NOT_NEEDED);
                sendPopupWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNSPECIFIED);
                sendPopupWindow.getContentView().setFocusableInTouchMode(true);
            }
            sendPopupLayout.measure(View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(1000), View.MeasureSpec.AT_MOST));
            sendPopupWindow.setFocusable(true);
            int[] location = new int[2];
            view.getLocationInWindow(location);
            sendPopupWindow.showAtLocation(view, Gravity.LEFT | Gravity.TOP, location[0] + view.getMeasuredWidth() - sendPopupLayout.getMeasuredWidth() + AndroidUtilities.dp(8), location[1] - sendPopupLayout.getMeasuredHeight() - AndroidUtilities.dp(2));
            sendPopupWindow.dimBehind();
            view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
            return false;
        });
        textPaint.setTextSize(AndroidUtilities.dp(12));
        textPaint.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        selectedCountView = new View(context) {

            @Override
            protected void onDraw(Canvas canvas) {
                String text = String.format("%d", Math.max(1, selectedPhotosOrder.size()));
                int textSize = (int) Math.ceil(textPaint.measureText(text));
                int size = Math.max(AndroidUtilities.dp(16) + textSize, AndroidUtilities.dp(24));
                int cx = getMeasuredWidth() / 2;
                int cy = getMeasuredHeight() / 2;
                textPaint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBoxCheck));
                paint.setColor(Theme.getColor(dialogBackgroundKey));
                rect.set(cx - size / 2, 0, cx + size / 2, getMeasuredHeight());
                canvas.drawRoundRect(rect, AndroidUtilities.dp(12), AndroidUtilities.dp(12), paint);
                paint.setColor(Theme.getColor(Theme.key_dialogRoundCheckBox));
                rect.set(cx - size / 2 + AndroidUtilities.dp(2), AndroidUtilities.dp(2), cx + size / 2 - AndroidUtilities.dp(2), getMeasuredHeight() - AndroidUtilities.dp(2));
                canvas.drawRoundRect(rect, AndroidUtilities.dp(10), AndroidUtilities.dp(10), paint);
                canvas.drawText(text, cx - textSize / 2, AndroidUtilities.dp(16.2f), textPaint);
            }
        };
        selectedCountView.setAlpha(0.0f);
        selectedCountView.setScaleX(0.2f);
        selectedCountView.setScaleY(0.2f);
        sizeNotifierFrameLayout.addView(selectedCountView, LayoutHelper.createFrame(42, 24, Gravity.RIGHT | Gravity.BOTTOM, 0, 0, -2, 9));
        if (selectPhotoType != PhotoAlbumPickerActivity.SELECT_TYPE_ALL) {
            commentTextView.setVisibility(View.GONE);
        }
    }
    allowIndices = (selectedAlbum != null || type == 0 || type == 1) && allowOrder;
    listView.setEmptyView(emptyView);
    updatePhotosButton(0);
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) SharedDocumentCell(org.telegram.ui.Cells.SharedDocumentCell) WindowManager(android.view.WindowManager) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) RecyclerViewItemRangeSelector(org.telegram.ui.Components.RecyclerViewItemRangeSelector) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ApplicationLoader(org.telegram.messenger.ApplicationLoader) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) TextCell(org.telegram.ui.Cells.TextCell) MediaController(org.telegram.messenger.MediaController) View(android.view.View) Button(android.widget.Button) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) RectF(android.graphics.RectF) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) ObjectAnimator(android.animation.ObjectAnimator) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) Paint(android.graphics.Paint) InputFilter(android.text.InputFilter) DividerCell(org.telegram.ui.Cells.DividerCell) DecelerateInterpolator(android.view.animation.DecelerateInterpolator) TextWatcher(android.text.TextWatcher) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) FileLoader(org.telegram.messenger.FileLoader) Context(android.content.Context) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) KeyEvent(android.view.KeyEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) Theme(org.telegram.ui.ActionBar.Theme) ViewOutlineProvider(android.view.ViewOutlineProvider) LocaleController(org.telegram.messenger.LocaleController) HashMap(java.util.HashMap) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji) AnimatorSet(android.animation.AnimatorSet) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) SharedConfig(org.telegram.messenger.SharedConfig) MessageObject(org.telegram.messenger.MessageObject) Build(android.os.Build) DialogInterface(android.content.DialogInterface) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) DialogObject(org.telegram.messenger.DialogObject) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) BackupImageView(org.telegram.ui.Components.BackupImageView) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) MessagesStorage(org.telegram.messenger.MessagesStorage) OvershootInterpolator(android.view.animation.OvershootInterpolator) Activity(android.app.Activity) ChatObject(org.telegram.messenger.ChatObject) ImageReceiver(org.telegram.messenger.ImageReceiver) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) RecyclerListView(org.telegram.ui.Components.RecyclerListView) MediaController(org.telegram.messenger.MediaController) TLRPC(org.telegram.tgnet.TLRPC) ActionBarPopupWindow(org.telegram.ui.ActionBar.ActionBarPopupWindow) TextView(android.widget.TextView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) ImageView(android.widget.ImageView) BackupImageView(org.telegram.ui.Components.BackupImageView) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) InputFilter(android.text.InputFilter) Canvas(android.graphics.Canvas) Drawable(android.graphics.drawable.Drawable) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) PhotoAttachPhotoCell(org.telegram.ui.Cells.PhotoAttachPhotoCell) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) TLObject(org.telegram.tgnet.TLObject) MessageObject(org.telegram.messenger.MessageObject) DialogObject(org.telegram.messenger.DialogObject) UserObject(org.telegram.messenger.UserObject) ChatObject(org.telegram.messenger.ChatObject) RecyclerViewItemRangeSelector(org.telegram.ui.Components.RecyclerViewItemRangeSelector) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) AccessibilityNodeInfo(android.view.accessibility.AccessibilityNodeInfo) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) Outline(android.graphics.Outline) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) TextView(android.widget.TextView) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) BackupImageView(org.telegram.ui.Components.BackupImageView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ViewOutlineProvider(android.view.ViewOutlineProvider) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) FrameLayout(android.widget.FrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) SuppressLint(android.annotation.SuppressLint) RecyclerView(androidx.recyclerview.widget.RecyclerView) EditTextEmoji(org.telegram.ui.Components.EditTextEmoji)

Example 49 with AlertDialog

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

the class PeopleNearbyActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setBackgroundDrawable(null);
    actionBar.setTitleColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    actionBar.setItemsColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), false);
    actionBar.setItemsBackgroundColor(Theme.getColor(Theme.key_listSelector), false);
    actionBar.setCastShadows(false);
    actionBar.setAddToContainer(false);
    actionBar.setOccupyStatusBar(Build.VERSION.SDK_INT >= 21 && !AndroidUtilities.isTablet());
    actionBar.setTitle(LocaleController.getString("PeopleNearby", R.string.PeopleNearby));
    actionBar.getTitleTextView().setAlpha(0.0f);
    if (!AndroidUtilities.isTablet()) {
        actionBar.showActionModeTop();
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    fragmentView = new FrameLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) actionBarBackground.getLayoutParams();
            layoutParams.height = ActionBar.getCurrentActionBarHeight() + (actionBar.getOccupyStatusBar() ? AndroidUtilities.statusBarHeight : 0) + AndroidUtilities.dp(3);
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            checkScroll(false);
        }
    };
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    fragmentView.setTag(Theme.key_windowBackgroundGray);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    listView = new RecyclerListView(context);
    listView.setGlowColor(0);
    listView.setLayoutManager(layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    listView.setAdapter(listViewAdapter = new ListAdapter(context));
    listView.setVerticalScrollbarPosition(LocaleController.isRTL ? RecyclerListView.SCROLLBAR_POSITION_LEFT : RecyclerListView.SCROLLBAR_POSITION_RIGHT);
    frameLayout.addView(listView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    itemAnimator = new DefaultItemAnimator() {

        @Override
        protected long getAddAnimationDelay(long removeDuration, long moveDuration, long changeDuration) {
            return removeDuration;
        }
    };
    listView.setOnItemClickListener((view, position) -> {
        if (getParentActivity() == null) {
            return;
        }
        if (position >= usersStartRow && position < usersEndRow) {
            if (view instanceof ManageChatUserCell) {
                ManageChatUserCell cell = (ManageChatUserCell) view;
                TLRPC.TL_peerLocated peerLocated = users.get(position - usersStartRow);
                Bundle args1 = new Bundle();
                args1.putLong("user_id", peerLocated.peer.user_id);
                if (cell.hasAvatarSet()) {
                    args1.putBoolean("expandPhoto", true);
                }
                args1.putInt("nearby_distance", peerLocated.distance);
                MessagesController.getInstance(currentAccount).ensureMessagesLoaded(peerLocated.peer.user_id, 0, null);
                presentFragment(new ProfileActivity(args1));
            }
        } else if (position >= chatsStartRow && position < chatsEndRow) {
            TLRPC.TL_peerLocated peerLocated = chats.get(position - chatsStartRow);
            Bundle args1 = new Bundle();
            long chatId;
            if (peerLocated.peer instanceof TLRPC.TL_peerChat) {
                chatId = peerLocated.peer.chat_id;
            } else {
                chatId = peerLocated.peer.channel_id;
            }
            args1.putLong("chat_id", chatId);
            ChatActivity chatActivity = new ChatActivity(args1);
            presentFragment(chatActivity);
        } else if (position == chatsCreateRow) {
            if (checkingCanCreate || currentGroupCreateAddress == null) {
                loadingDialog = new AlertDialog(getParentActivity(), 3);
                loadingDialog.setOnCancelListener(dialog -> loadingDialog = null);
                loadingDialog.show();
                return;
            }
            openGroupCreate();
        } else if (position == showMeRow) {
            UserConfig userConfig = getUserConfig();
            if (showingMe) {
                userConfig.sharingMyLocationUntil = 0;
                userConfig.saveConfig(false);
                sendRequest(false, 2);
                updateRows(null);
            } else {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("MakeMyselfVisibleTitle", R.string.MakeMyselfVisibleTitle));
                builder.setMessage(LocaleController.getString("MakeMyselfVisibleInfo", R.string.MakeMyselfVisibleInfo));
                builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), (dialog, which) -> {
                    userConfig.sharingMyLocationUntil = 0x7fffffff;
                    userConfig.saveConfig(false);
                    sendRequest(false, 1);
                    updateRows(null);
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
            }
            userConfig.saveConfig(false);
        } else if (position == showMoreRow) {
            expanded = true;
            DiffCallback diffCallback = new DiffCallback();
            diffCallback.saveCurrentState();
            updateRows(diffCallback);
        }
    });
    listView.setOnScrollListener(new RecyclerView.OnScrollListener() {

        @Override
        public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
            checkScroll(true);
        }
    });
    actionBarBackground = new View(context) {

        private Paint paint = new Paint();

        @Override
        protected void onDraw(Canvas canvas) {
            paint.setColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            int h = getMeasuredHeight() - AndroidUtilities.dp(3);
            canvas.drawRect(0, 0, getMeasuredWidth(), h, paint);
            parentLayout.drawHeaderShadow(canvas, h);
        }
    };
    actionBarBackground.setAlpha(0.0f);
    frameLayout.addView(actionBarBackground, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    frameLayout.addView(actionBar, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    undoView = new UndoView(context);
    frameLayout.addView(undoView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.BOTTOM | Gravity.LEFT, 8, 0, 8, 8));
    updateRows(null);
    return fragmentView;
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Bundle(android.os.Bundle) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Animator(android.animation.Animator) LocationController(org.telegram.messenger.LocationController) RadialProgressView(org.telegram.ui.Components.RadialProgressView) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) View(android.view.View) Canvas(android.graphics.Canvas) RecyclerView(androidx.recyclerview.widget.RecyclerView) DiffUtil(androidx.recyclerview.widget.DiffUtil) ObjectAnimator(android.animation.ObjectAnimator) UndoView(org.telegram.ui.Components.UndoView) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) UserConfig(org.telegram.messenger.UserConfig) TextView(android.widget.TextView) Paint(android.graphics.Paint) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) Location(android.location.Location) Context(android.content.Context) ManageChatTextCell(org.telegram.ui.Cells.ManageChatTextCell) SparseIntArray(android.util.SparseIntArray) Theme(org.telegram.ui.ActionBar.Theme) SystemClock(android.os.SystemClock) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) ArrayList(java.util.ArrayList) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) R(org.telegram.messenger.R) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) ManageChatUserCell(org.telegram.ui.Cells.ManageChatUserCell) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) TypedValue(android.util.TypedValue) ShareLocationDrawable(org.telegram.ui.Components.ShareLocationDrawable) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) RecyclerListView(org.telegram.ui.Components.RecyclerListView) ManageChatUserCell(org.telegram.ui.Cells.ManageChatUserCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) DefaultItemAnimator(androidx.recyclerview.widget.DefaultItemAnimator) TLRPC(org.telegram.tgnet.TLRPC) UndoView(org.telegram.ui.Components.UndoView) ActionBar(org.telegram.ui.ActionBar.ActionBar) Bundle(android.os.Bundle) Canvas(android.graphics.Canvas) Paint(android.graphics.Paint) UserConfig(org.telegram.messenger.UserConfig) ImageView(android.widget.ImageView) RadialProgressView(org.telegram.ui.Components.RadialProgressView) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) UndoView(org.telegram.ui.Components.UndoView) TextView(android.widget.TextView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Paint(android.graphics.Paint) FrameLayout(android.widget.FrameLayout) RecyclerView(androidx.recyclerview.widget.RecyclerView)

Example 50 with AlertDialog

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

the class ChatActivity method processSelectedOption.

private void processSelectedOption(int option) {
    if (selectedObject == null || getParentActivity() == null) {
        return;
    }
    boolean preserveDim = false;
    switch(option) {
        case 0:
            {
                if (selectedObjectGroup != null) {
                    boolean success = true;
                    for (int a = 0; a < selectedObjectGroup.messages.size(); a++) {
                        if (!getSendMessagesHelper().retrySendMessage(selectedObjectGroup.messages.get(a), false)) {
                            success = false;
                        }
                    }
                    if (success && chatMode == 0) {
                        moveScrollToLastMessage(false);
                    }
                } else {
                    if (getSendMessagesHelper().retrySendMessage(selectedObject, false)) {
                        updateVisibleRows();
                        if (chatMode == 0) {
                            moveScrollToLastMessage(false);
                        }
                    }
                }
                break;
            }
        case OPTION_DELETE:
            {
                if (getParentActivity() == null) {
                    selectedObject = null;
                    selectedObjectToEditCaption = null;
                    selectedObjectGroup = null;
                    return;
                }
                preserveDim = true;
                createDeleteMessagesAlert(selectedObject, selectedObjectGroup);
                break;
            }
        case 2:
            {
                forwardingMessage = selectedObject;
                forwardingMessageGroup = selectedObjectGroup;
                Bundle args = new Bundle();
                args.putBoolean("onlySelect", true);
                args.putInt("dialogsType", 3);
                args.putInt("messagesCount", forwardingMessageGroup == null ? 1 : forwardingMessageGroup.messages.size());
                args.putInt("hasPoll", forwardingMessage.isPoll() ? (forwardingMessage.isPublicPoll() ? 2 : 1) : 0);
                args.putBoolean("hasInvoice", forwardingMessage.isInvoice());
                DialogsActivity fragment = new DialogsActivity(args);
                fragment.setDelegate(this);
                presentFragment(fragment);
                break;
            }
        case 3:
            {
                if (selectedObject.isDice()) {
                    AndroidUtilities.addToClipboard(selectedObject.getDiceEmoji());
                } else {
                    CharSequence caption = getMessageCaption(selectedObject, selectedObjectGroup);
                    if (caption != null) {
                        AndroidUtilities.addToClipboard(caption);
                    } else {
                        AndroidUtilities.addToClipboard(getMessageContent(selectedObject, 0, false));
                    }
                }
                undoView.showWithAction(0, UndoView.ACTION_MESSAGE_COPIED, null);
                break;
            }
        case 4:
            {
                if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    selectedObject = null;
                    selectedObjectGroup = null;
                    selectedObjectToEditCaption = null;
                    return;
                }
                if (selectedObjectGroup != null) {
                    int filesAmount = selectedObjectGroup.messages.size();
                    boolean allPhotos = true, allVideos = true;
                    for (int a = 0; a < filesAmount; a++) {
                        MessageObject messageObject = selectedObjectGroup.messages.get(a);
                        saveMessageToGallery(messageObject);
                        allPhotos &= messageObject.isPhoto();
                        allVideos &= messageObject.isVideo();
                    }
                    final BulletinFactory.FileType fileType;
                    if (allPhotos) {
                        fileType = BulletinFactory.FileType.PHOTOS;
                    } else if (allVideos) {
                        fileType = BulletinFactory.FileType.VIDEOS;
                    } else {
                        fileType = BulletinFactory.FileType.MEDIA;
                    }
                    BulletinFactory.of(this).createDownloadBulletin(fileType, filesAmount, themeDelegate).show();
                } else {
                    saveMessageToGallery(selectedObject);
                    if (getParentActivity() != null) {
                        BulletinFactory.createSaveToGalleryBulletin(this, selectedObject.isVideo(), themeDelegate).show();
                    }
                }
                break;
            }
        case 5:
            {
                File locFile = null;
                if (!TextUtils.isEmpty(selectedObject.messageOwner.attachPath)) {
                    File f = new File(selectedObject.messageOwner.attachPath);
                    if (f.exists()) {
                        locFile = f;
                    }
                }
                if (locFile == null) {
                    File f = FileLoader.getPathToMessage(selectedObject.messageOwner);
                    if (f.exists()) {
                        locFile = f;
                    }
                }
                if (locFile != null) {
                    if (locFile.getName().toLowerCase().endsWith("attheme")) {
                        Theme.ThemeInfo themeInfo = Theme.applyThemeFile(locFile, selectedObject.getDocumentName(), null, true);
                        if (themeInfo != null) {
                            presentFragment(new ThemePreviewActivity(themeInfo));
                        } else {
                            scrollToPositionOnRecreate = -1;
                            if (getParentActivity() == null) {
                                selectedObject = null;
                                selectedObjectGroup = null;
                                selectedObjectToEditCaption = null;
                                return;
                            }
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setMessage(LocaleController.getString("IncorrectTheme", R.string.IncorrectTheme));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            preserveDim = true;
                            builder.setDimEnabled(false);
                            builder.setOnPreDismissListener(di -> dimBehindView(false));
                            showDialog(builder.create());
                        }
                    } else {
                        if (LocaleController.getInstance().applyLanguageFile(locFile, currentAccount)) {
                            presentFragment(new LanguageSelectActivity());
                        } else {
                            if (getParentActivity() == null) {
                                selectedObject = null;
                                selectedObjectGroup = null;
                                selectedObjectToEditCaption = null;
                                return;
                            }
                            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
                            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                            builder.setMessage(LocaleController.getString("IncorrectLocalization", R.string.IncorrectLocalization));
                            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                            preserveDim = true;
                            builder.setDimEnabled(false);
                            builder.setOnPreDismissListener(di -> dimBehindView(false));
                            showDialog(builder.create());
                        }
                    }
                }
                break;
            }
        case 6:
            {
                String path = selectedObject.messageOwner.attachPath;
                if (path != null && path.length() > 0) {
                    File temp = new File(path);
                    if (!temp.exists()) {
                        path = null;
                    }
                }
                if (path == null || path.length() == 0) {
                    path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
                }
                Intent intent = new Intent(Intent.ACTION_SEND);
                intent.setType(selectedObject.getDocument().mime_type);
                File f = new File(path);
                if (Build.VERSION.SDK_INT >= 24) {
                    try {
                        intent.putExtra(Intent.EXTRA_STREAM, FileProvider.getUriForFile(getParentActivity(), BuildConfig.APPLICATION_ID + ".provider", f));
                        intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
                    } catch (Exception ignore) {
                        intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
                    }
                } else {
                    intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(f));
                }
                try {
                    getParentActivity().startActivityForResult(Intent.createChooser(intent, LocaleController.getString("ShareFile", R.string.ShareFile)), 500);
                } catch (Throwable ignore) {
                }
                break;
            }
        case 7:
            {
                String path = selectedObject.messageOwner.attachPath;
                if (path != null && path.length() > 0) {
                    File temp = new File(path);
                    if (!temp.exists()) {
                        path = null;
                    }
                }
                if (path == null || path.length() == 0) {
                    path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
                }
                if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    selectedObject = null;
                    selectedObjectGroup = null;
                    selectedObjectToEditCaption = null;
                    return;
                }
                MediaController.saveFile(path, getParentActivity(), 0, null, null);
                BulletinFactory.createSaveToGalleryBulletin(this, selectedObject.isVideo(), themeDelegate).show();
                break;
            }
        case 8:
            {
                showFieldPanelForReply(selectedObject);
                break;
            }
        case 9:
            {
                StickersAlert alert = new StickersAlert(getParentActivity(), this, selectedObject.getInputStickerSet(), null, bottomOverlayChat.getVisibility() != View.VISIBLE && (currentChat == null || ChatObject.canSendStickers(currentChat)) ? chatActivityEnterView : null, themeDelegate);
                alert.setCalcMandatoryInsets(isKeyboardVisible());
                preserveDim = true;
                alert.setDimBehind(false);
                alert.setOnDismissListener(() -> dimBehindView(false));
                showDialog(alert);
                break;
            }
        case OPTION_SAVE_TO_DOWNLOADS_OR_MUSIC:
            {
                // TODO scopped storage
                if (Build.VERSION.SDK_INT >= 23 && (Build.VERSION.SDK_INT <= 28 || BuildVars.NO_SCOPED_STORAGE) && getParentActivity().checkSelfPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
                    getParentActivity().requestPermissions(new String[] { Manifest.permission.WRITE_EXTERNAL_STORAGE }, 4);
                    selectedObject = null;
                    selectedObjectGroup = null;
                    selectedObjectToEditCaption = null;
                    return;
                }
                boolean isMusic = selectedObject.isMusic();
                boolean isDocument = selectedObject.isDocument();
                if (isMusic || isDocument) {
                    ArrayList<MessageObject> messageObjects;
                    if (selectedObjectGroup != null) {
                        messageObjects = new ArrayList<>(selectedObjectGroup.messages);
                    } else {
                        messageObjects = new ArrayList<>();
                        messageObjects.add(selectedObject);
                    }
                    MediaController.saveFilesFromMessages(getParentActivity(), getAccountInstance(), messageObjects, (count) -> {
                        if (getParentActivity() == null || fragmentView == null) {
                            return;
                        }
                        if (count > 0) {
                            BulletinFactory.of(this).createDownloadBulletin(isMusic ? BulletinFactory.FileType.AUDIOS : BulletinFactory.FileType.UNKNOWNS, count, themeDelegate).show();
                        }
                    });
                } else {
                    boolean video = selectedObject.isVideo();
                    boolean photo = selectedObject.isPhoto();
                    boolean gif = selectedObject.isGif();
                    String fileName = FileLoader.getDocumentFileName(selectedObject.getDocument());
                    if (TextUtils.isEmpty(fileName)) {
                        fileName = selectedObject.getFileName();
                    }
                    String path = selectedObject.messageOwner.attachPath;
                    if (path != null && path.length() > 0) {
                        File temp = new File(path);
                        if (!temp.exists()) {
                            path = null;
                        }
                    }
                    if (path == null || path.length() == 0) {
                        path = FileLoader.getPathToMessage(selectedObject.messageOwner).toString();
                    }
                    MediaController.saveFile(path, getParentActivity(), 2, fileName, selectedObject.getDocument() != null ? selectedObject.getDocument().mime_type : "", () -> {
                        if (getParentActivity() == null) {
                            return;
                        }
                        final BulletinFactory.FileType fileType;
                        if (photo) {
                            fileType = BulletinFactory.FileType.PHOTO_TO_DOWNLOADS;
                        } else if (video) {
                            fileType = BulletinFactory.FileType.VIDEO_TO_DOWNLOADS;
                        } else if (gif) {
                            fileType = BulletinFactory.FileType.GIF_TO_DOWNLOADS;
                        } else {
                            fileType = BulletinFactory.FileType.UNKNOWN;
                        }
                        BulletinFactory.of(this).createDownloadBulletin(fileType, themeDelegate).show();
                    });
                }
                break;
            }
        case 11:
            {
                TLRPC.Document document = selectedObject.getDocument();
                getMessagesController().saveGif(selectedObject, document);
                if (!showGifHint() && getParentActivity() != null) {
                    BulletinFactory.of(this).createDownloadBulletin(BulletinFactory.FileType.GIF, themeDelegate).show();
                }
                chatActivityEnterView.addRecentGif(document);
                break;
            }
        case 12:
            {
                if (selectedObjectToEditCaption != null) {
                    startEditingMessageObject(selectedObjectToEditCaption);
                } else {
                    startEditingMessageObject(selectedObject);
                }
                selectedObject = null;
                selectedObjectGroup = null;
                selectedObjectToEditCaption = null;
                break;
            }
        case 13:
            {
                final int mid;
                if (selectedObjectGroup != null && !selectedObjectGroup.messages.isEmpty()) {
                    mid = selectedObjectGroup.messages.get(0).getId();
                } else {
                    mid = selectedObject.getId();
                }
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
                builder.setTitle(LocaleController.getString("PinMessageAlertTitle", R.string.PinMessageAlertTitle));
                preserveDim = true;
                builder.setDimEnabled(false);
                builder.setOnPreDismissListener(di -> dimBehindView(false));
                final boolean[] checks;
                if (currentUser != null) {
                    if (currentPinnedMessageId != 0 && mid < currentPinnedMessageId) {
                        builder.setMessage(LocaleController.getString("PinOldMessageAlert", R.string.PinOldMessageAlert));
                    } else {
                        builder.setMessage(LocaleController.getString("PinMessageAlertChat", R.string.PinMessageAlertChat));
                    }
                    checks = new boolean[] { false, false };
                    if (!UserObject.isUserSelf(currentUser)) {
                        FrameLayout frameLayout = new FrameLayout(getParentActivity());
                        CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1, themeDelegate);
                        cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                        cell.setText(LocaleController.formatString("PinAlsoFor", R.string.PinAlsoFor, UserObject.getFirstName(currentUser)), "", false, false);
                        cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
                        frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0));
                        cell.setOnClickListener(v -> {
                            CheckBoxCell cell1 = (CheckBoxCell) v;
                            checks[1] = !checks[1];
                            cell1.setChecked(checks[1], true);
                        });
                        builder.setView(frameLayout);
                    }
                } else if (ChatObject.isChannel(currentChat) && currentChat.megagroup || currentChat != null && !ChatObject.isChannel(currentChat)) {
                    if (!pinnedMessageIds.isEmpty() && mid < pinnedMessageIds.get(0)) {
                        builder.setMessage(LocaleController.getString("PinOldMessageAlert", R.string.PinOldMessageAlert));
                        checks = new boolean[] { false, true };
                    } else {
                        builder.setMessage(LocaleController.getString("PinMessageAlert", R.string.PinMessageAlert));
                        checks = new boolean[] { true, true };
                        FrameLayout frameLayout = new FrameLayout(getParentActivity());
                        CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1, themeDelegate);
                        cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
                        cell.setText(LocaleController.getString("PinNotify", R.string.PinNotify), "", true, false);
                        cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(8) : 0, 0, LocaleController.isRTL ? 0 : AndroidUtilities.dp(8), 0);
                        frameLayout.addView(cell, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.TOP | Gravity.LEFT, 8, 0, 8, 0));
                        cell.setOnClickListener(v -> {
                            CheckBoxCell cell1 = (CheckBoxCell) v;
                            checks[0] = !checks[0];
                            cell1.setChecked(checks[0], true);
                        });
                        builder.setView(frameLayout);
                    }
                } else {
                    if (currentPinnedMessageId != 0 && mid < currentPinnedMessageId) {
                        builder.setMessage(LocaleController.getString("PinOldMessageAlert", R.string.PinOldMessageAlert));
                    } else {
                        builder.setMessage(LocaleController.getString("PinMessageAlertChannel", R.string.PinMessageAlertChannel));
                    }
                    checks = new boolean[] { false, true };
                }
                builder.setPositiveButton(LocaleController.getString("PinMessage", R.string.PinMessage), (dialogInterface, i) -> {
                    getMessagesController().pinMessage(currentChat, currentUser, mid, false, !checks[1], checks[0]);
                    Bulletin bulletin = BulletinFactory.createPinMessageBulletin(this, themeDelegate);
                    bulletin.show();
                    View view = bulletin.getLayout();
                    view.postDelayed(() -> {
                        view.performHapticFeedback(HapticFeedbackConstants.KEYBOARD_TAP, HapticFeedbackConstants.FLAG_IGNORE_GLOBAL_SETTING);
                    }, 550);
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
                break;
            }
        case 14:
            {
                MessageObject messageObject;
                if (pinnedMessageObjects.containsKey(selectedObject.getId())) {
                    messageObject = selectedObject;
                } else if (selectedObjectGroup != null && !selectedObjectGroup.messages.isEmpty()) {
                    messageObject = selectedObjectGroup.messages.get(0);
                } else {
                    messageObject = selectedObject;
                }
                if (chatMode == MODE_PINNED && messages.size() == 2) {
                    finishFragment();
                    chatActivityDelegate.onUnpin(false, false);
                } else {
                    unpinMessage(messageObject);
                }
                break;
            }
        case 15:
            {
                Bundle args = new Bundle();
                args.putLong("user_id", selectedObject.messageOwner.media.user_id);
                args.putString("phone", selectedObject.messageOwner.media.phone_number);
                args.putBoolean("addContact", true);
                presentFragment(new ContactAddActivity(args));
                break;
            }
        case 16:
            {
                AndroidUtilities.addToClipboard(selectedObject.messageOwner.media.phone_number);
                break;
            }
        case 17:
            {
                try {
                    Intent intent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + selectedObject.messageOwner.media.phone_number));
                    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                    getParentActivity().startActivityForResult(intent, 500);
                } catch (Exception e) {
                    FileLog.e(e);
                }
                break;
            }
        case 18:
            {
                if (currentUser != null) {
                    VoIPHelper.startCall(currentUser, selectedObject.isVideoCall(), userInfo != null && userInfo.video_calls_available, getParentActivity(), getMessagesController().getUserFull(currentUser.id), getAccountInstance());
                }
                break;
            }
        case 19:
            {
                VoIPHelper.showRateAlert(getParentActivity(), (TLRPC.TL_messageActionPhoneCall) selectedObject.messageOwner.action);
                break;
            }
        case 20:
            {
                getMediaDataController().addRecentSticker(MediaDataController.TYPE_FAVE, selectedObject, selectedObject.getDocument(), (int) (System.currentTimeMillis() / 1000), false);
                break;
            }
        case 21:
            {
                getMediaDataController().addRecentSticker(MediaDataController.TYPE_FAVE, selectedObject, selectedObject.getDocument(), (int) (System.currentTimeMillis() / 1000), true);
                break;
            }
        case 22:
            {
                TLRPC.TL_channels_exportMessageLink req = new TLRPC.TL_channels_exportMessageLink();
                if (selectedObject == replyingMessageObject && isComments) {
                    req.id = replyOriginalMessageId;
                    req.channel = MessagesController.getInputChannel(replyOriginalChat);
                } else {
                    req.id = selectedObject.getId();
                    req.channel = MessagesController.getInputChannel(currentChat);
                    req.thread = isReplyChatComment();
                }
                getConnectionsManager().sendRequest(req, (response, error) -> AndroidUtilities.runOnUIThread(() -> {
                    if (response != null) {
                        TLRPC.TL_exportedMessageLink exportedMessageLink = (TLRPC.TL_exportedMessageLink) response;
                        try {
                            android.content.ClipboardManager clipboard = (android.content.ClipboardManager) ApplicationLoader.applicationContext.getSystemService(Context.CLIPBOARD_SERVICE);
                            ClipData clip = ClipData.newPlainText("label", exportedMessageLink.link);
                            clipboard.setPrimaryClip(clip);
                            if (BulletinFactory.canShowBulletin(ChatActivity.this)) {
                                BulletinFactory.of(ChatActivity.this).createCopyLinkBulletin(!isThreadChat() && exportedMessageLink.link.contains("/c/"), themeDelegate).show();
                            }
                        } catch (Exception e) {
                            FileLog.e(e);
                        }
                    }
                }));
                break;
            }
        case OPTION_REPORT_CHAT:
            {
                if (UserObject.isReplyUser(currentUser)) {
                    if (selectedObject.messageOwner.fwd_from != null) {
                        preserveDim = true;
                        AlertsCreator.showBlockReportSpamReplyAlert(ChatActivity.this, selectedObject, MessageObject.getPeerId(selectedObject.messageOwner.fwd_from.from_id), themeDelegate, () -> dimBehindView(false));
                    }
                } else {
                    preserveDim = true;
                    AlertsCreator.createReportAlert(getParentActivity(), dialog_id, selectedObject.getId(), ChatActivity.this, themeDelegate, () -> dimBehindView(false));
                }
                break;
            }
        case 24:
            {
                if (selectedObject.isEditing() || selectedObject.isSending() && selectedObjectGroup == null) {
                    getSendMessagesHelper().cancelSendingMessage(selectedObject);
                } else if (selectedObject.isSending() && selectedObjectGroup != null) {
                    for (int a = 0; a < selectedObjectGroup.messages.size(); a++) {
                        getSendMessagesHelper().cancelSendingMessage(new ArrayList<>(selectedObjectGroup.messages));
                    }
                }
                break;
            }
        case 25:
            {
                final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
                int requestId = getSendMessagesHelper().sendVote(selectedObject, null, () -> {
                    try {
                        progressDialog[0].dismiss();
                    } catch (Throwable ignore) {
                    }
                    progressDialog[0] = null;
                });
                if (requestId != 0) {
                    AndroidUtilities.runOnUIThread(() -> {
                        if (progressDialog[0] == null) {
                            return;
                        }
                        progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
                        showDialog(progressDialog[0]);
                    }, 500);
                }
                break;
            }
        case 26:
            {
                MessageObject object = selectedObject;
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity(), themeDelegate);
                preserveDim = true;
                builder.setDimEnabled(false);
                builder.setOnPreDismissListener(di -> dimBehindView(false));
                if (object.isQuiz()) {
                    builder.setTitle(LocaleController.getString("StopQuizAlertTitle", R.string.StopQuizAlertTitle));
                    builder.setMessage(LocaleController.getString("StopQuizAlertText", R.string.StopQuizAlertText));
                } else {
                    builder.setTitle(LocaleController.getString("StopPollAlertTitle", R.string.StopPollAlertTitle));
                    builder.setMessage(LocaleController.getString("StopPollAlertText", R.string.StopPollAlertText));
                }
                builder.setPositiveButton(LocaleController.getString("Stop", R.string.Stop), (dialogInterface, i) -> {
                    final AlertDialog[] progressDialog = new AlertDialog[] { new AlertDialog(getParentActivity(), 3, themeDelegate) };
                    TLRPC.TL_messages_editMessage req = new TLRPC.TL_messages_editMessage();
                    TLRPC.TL_messageMediaPoll mediaPoll = (TLRPC.TL_messageMediaPoll) object.messageOwner.media;
                    TLRPC.TL_inputMediaPoll poll = new TLRPC.TL_inputMediaPoll();
                    poll.poll = new TLRPC.TL_poll();
                    poll.poll.id = mediaPoll.poll.id;
                    poll.poll.question = mediaPoll.poll.question;
                    poll.poll.answers = mediaPoll.poll.answers;
                    poll.poll.closed = true;
                    req.media = poll;
                    req.peer = getMessagesController().getInputPeer(dialog_id);
                    req.id = object.getId();
                    req.flags |= 16384;
                    int requestId = getConnectionsManager().sendRequest(req, (response, error) -> {
                        AndroidUtilities.runOnUIThread(() -> {
                            try {
                                progressDialog[0].dismiss();
                            } catch (Throwable ignore) {
                            }
                            progressDialog[0] = null;
                        });
                        if (error == null) {
                            getMessagesController().processUpdates((TLRPC.Updates) response, false);
                        } else {
                            AndroidUtilities.runOnUIThread(() -> AlertsCreator.processError(currentAccount, error, ChatActivity.this, req));
                        }
                    });
                    AndroidUtilities.runOnUIThread(() -> {
                        if (progressDialog[0] == null) {
                            return;
                        }
                        progressDialog[0].setOnCancelListener(dialog -> getConnectionsManager().cancelRequest(requestId, true));
                        showDialog(progressDialog[0]);
                    }, 500);
                });
                builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                showDialog(builder.create());
                break;
            }
        case 27:
            {
                openDiscussionMessageChat(currentChat.id, null, selectedObject.getId(), 0, -1, 0, null);
                break;
            }
        case 28:
            {
                presentFragment(new MessageStatisticActivity(selectedObject));
                break;
            }
        case 100:
            {
                if (!checkSlowMode(chatActivityEnterView.getSendButton())) {
                    if (getMediaController().isPlayingMessage(selectedObject)) {
                        getMediaController().cleanupPlayer(true, true);
                    }
                    TLRPC.TL_messages_sendScheduledMessages req = new TLRPC.TL_messages_sendScheduledMessages();
                    req.peer = getMessagesController().getInputPeer(dialog_id);
                    if (selectedObjectGroup != null) {
                        for (int a = 0; a < selectedObjectGroup.messages.size(); a++) {
                            req.id.add(selectedObjectGroup.messages.get(a).getId());
                        }
                    } else {
                        req.id.add(selectedObject.getId());
                    }
                    ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
                        if (error == null) {
                            TLRPC.Updates updates = (TLRPC.Updates) response;
                            getMessagesController().processUpdates(updates, false);
                            AndroidUtilities.runOnUIThread(() -> NotificationCenter.getInstance(currentAccount).postNotificationName(NotificationCenter.messagesDeleted, req.id, -dialog_id, true, dialog_id));
                        } else if (error.text != null) {
                            AndroidUtilities.runOnUIThread(() -> {
                                if (error.text.startsWith("SLOWMODE_WAIT_")) {
                                    AlertsCreator.showSimpleToast(ChatActivity.this, LocaleController.getString("SlowmodeSendError", R.string.SlowmodeSendError));
                                } else if (error.text.equals("CHAT_SEND_MEDIA_FORBIDDEN")) {
                                    AlertsCreator.showSimpleToast(ChatActivity.this, LocaleController.getString("AttachMediaRestrictedForever", R.string.AttachMediaRestrictedForever));
                                } else {
                                    AlertsCreator.showSimpleToast(ChatActivity.this, error.text);
                                }
                            });
                        }
                    });
                    break;
                }
            }
        case 102:
            {
                MessageObject message = selectedObject;
                MessageObject.GroupedMessages group = selectedObjectGroup;
                AlertsCreator.createScheduleDatePickerDialog(getParentActivity(), dialog_id, message.messageOwner.date, (notify, scheduleDate) -> {
                    if (group != null && !group.messages.isEmpty()) {
                        SendMessagesHelper.getInstance(currentAccount).editMessage(group.messages.get(0), null, false, ChatActivity.this, null, scheduleDate);
                    } else {
                        SendMessagesHelper.getInstance(currentAccount).editMessage(message, null, false, ChatActivity.this, null, scheduleDate);
                    }
                }, null, themeDelegate).setOnPreDismissListener(di -> dimBehindView(false)).setDimBehind(false);
                preserveDim = true;
                break;
            }
    }
    selectedObject = null;
    selectedObjectGroup = null;
    selectedObjectToEditCaption = null;
    closeMenu(!preserveDim);
}
Also used : AlertDialog(org.telegram.ui.ActionBar.AlertDialog) ViewHelper(org.telegram.ui.Components.ViewHelper) Bundle(android.os.Bundle) BotHelpCell(org.telegram.ui.Cells.BotHelpCell) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) StickersAlert(org.telegram.ui.Components.StickersAlert) RecyclerAnimationScrollHelper(org.telegram.ui.Components.RecyclerAnimationScrollHelper) URLSpanUserMention(org.telegram.ui.Components.URLSpanUserMention) Property(android.util.Property) HorizontalScrollView(android.widget.HorizontalScrollView) ChatThemeController(org.telegram.messenger.ChatThemeController) MediaStore(android.provider.MediaStore) Map(java.util.Map) Shader(android.graphics.Shader) ContextCompat(androidx.core.content.ContextCompat) NotificationCenter(org.telegram.messenger.NotificationCenter) PinnedLineView(org.telegram.ui.Components.PinnedLineView) CountDownLatch(java.util.concurrent.CountDownLatch) Layout(android.text.Layout) EmojiData(org.telegram.messenger.EmojiData) ForwardingMessagesParams(org.telegram.messenger.ForwardingMessagesParams) BotCommandsMenuView(org.telegram.ui.Components.BotCommandsMenuView) Paint(android.graphics.Paint) Path(android.graphics.Path) ReactedHeaderView(org.telegram.ui.Components.ReactedHeaderView) PipRoundVideoView(org.telegram.ui.Components.PipRoundVideoView) SystemClock(android.os.SystemClock) ChatBlurredFrameLayout(org.telegram.ui.Components.ChatBlurredFrameLayout) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) Toast(android.widget.Toast) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) Menu(android.view.Menu) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) JoinGroupAlert(org.telegram.ui.Components.JoinGroupAlert) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) LongSparseIntArray(org.telegram.messenger.support.LongSparseIntArray) SimpleTextView(org.telegram.ui.ActionBar.SimpleTextView) URLSpan(android.text.style.URLSpan) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) ChatActivityMemberRequestsDelegate(org.telegram.ui.Delegates.ChatActivityMemberRequestsDelegate) UserObject(org.telegram.messenger.UserObject) SharedPreferences(android.content.SharedPreferences) ContactsController(org.telegram.messenger.ContactsController) MessagesStorage(org.telegram.messenger.MessagesStorage) EditText(android.widget.EditText) Rect(android.graphics.Rect) LinearLayout(android.widget.LinearLayout) URLDecoder(java.net.URLDecoder) PackageManager(android.content.pm.PackageManager) WindowManager(android.view.WindowManager) Animator(android.animation.Animator) TypefaceSpan(org.telegram.ui.Components.TypefaceSpan) ChatAttachAlertDocumentLayout(org.telegram.ui.Components.ChatAttachAlertDocumentLayout) DatePickerDialog(android.app.DatePickerDialog) ChatMessageCell(org.telegram.ui.Cells.ChatMessageCell) RecyclerView(androidx.recyclerview.widget.RecyclerView) StickersAdapter(org.telegram.ui.Adapters.StickersAdapter) RectF(android.graphics.RectF) ReportAlert(org.telegram.ui.Components.ReportAlert) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ChatActionCell(org.telegram.ui.Cells.ChatActionCell) ChatThemeBottomSheet(org.telegram.ui.Components.ChatThemeBottomSheet) PorterDuff(android.graphics.PorterDuff) SendMessagesHelper(org.telegram.messenger.SendMessagesHelper) BackDrawable(org.telegram.ui.ActionBar.BackDrawable) ShareAlert(org.telegram.ui.Components.ShareAlert) BluredView(org.telegram.ui.Components.BluredView) UserConfig(org.telegram.messenger.UserConfig) TextStyleSpan(org.telegram.ui.Components.TextStyleSpan) EmojiThemes(org.telegram.ui.ActionBar.EmojiThemes) InstantCameraView(org.telegram.ui.Components.InstantCameraView) PhonebookShareAlert(org.telegram.ui.Components.PhonebookShareAlert) ChatActivityEnterView(org.telegram.ui.Components.ChatActivityEnterView) ImportingAlert(org.telegram.ui.Components.ImportingAlert) Spanned(android.text.Spanned) GridLayoutManager(androidx.recyclerview.widget.GridLayoutManager) SparseIntArray(android.util.SparseIntArray) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LocaleController(org.telegram.messenger.LocaleController) ChatActivityEnterTopView(org.telegram.ui.Components.ChatActivityEnterTopView) ExtendedGridLayoutManager(org.telegram.ui.Components.ExtendedGridLayoutManager) ChatBigEmptyView(org.telegram.ui.Components.ChatBigEmptyView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearSmoothScrollerCustom(androidx.recyclerview.widget.LinearSmoothScrollerCustom) TLObject(org.telegram.tgnet.TLObject) Size(org.telegram.ui.Components.Size) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) ChatAvatarContainer(org.telegram.ui.Components.ChatAvatarContainer) PollVotesAlert(org.telegram.ui.Components.PollVotesAlert) EmbedBottomSheet(org.telegram.ui.Components.EmbedBottomSheet) DialogObject(org.telegram.messenger.DialogObject) BackupImageView(org.telegram.ui.Components.BackupImageView) LayoutHelper(org.telegram.ui.Components.LayoutHelper) TextureView(android.view.TextureView) Color(android.graphics.Color) Bitmap(android.graphics.Bitmap) CharacterStyle(android.text.style.CharacterStyle) ViewTreeObserver(android.view.ViewTreeObserver) Vibrator(android.os.Vibrator) Comparator(java.util.Comparator) Activity(android.app.Activity) ImageReceiver(org.telegram.messenger.ImageReceiver) RecyclerListView(org.telegram.ui.Components.RecyclerListView) Arrays(java.util.Arrays) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AnimatedFileDrawable(org.telegram.ui.Components.AnimatedFileDrawable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) Drawable(android.graphics.drawable.Drawable) Bulletin(org.telegram.ui.Components.Bulletin) RadialProgressView(org.telegram.ui.Components.RadialProgressView) Manifest(android.Manifest) ActionBarMenuSubItem(org.telegram.ui.ActionBar.ActionBarMenuSubItem) Matcher(java.util.regex.Matcher) ChatGreetingsView(org.telegram.ui.Components.ChatGreetingsView) Canvas(android.graphics.Canvas) AccessibilityEvent(android.view.accessibility.AccessibilityEvent) Emoji(org.telegram.messenger.Emoji) MessagesSearchAdapter(org.telegram.ui.Adapters.MessagesSearchAdapter) ColorMatrix(android.graphics.ColorMatrix) ForegroundColorSpan(android.text.style.ForegroundColorSpan) TargetApi(android.annotation.TargetApi) CombinedDrawable(org.telegram.ui.Components.CombinedDrawable) BackButtonMenu(org.telegram.ui.Components.BackButtonMenu) ChatListItemAnimator(androidx.recyclerview.widget.ChatListItemAnimator) MentionsAdapter(org.telegram.ui.Adapters.MentionsAdapter) UndoView(org.telegram.ui.Components.UndoView) AnimationProperties(org.telegram.ui.Components.AnimationProperties) ColorMatrixColorFilter(android.graphics.ColorMatrixColorFilter) CounterView(org.telegram.ui.Components.CounterView) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) Outline(android.graphics.Outline) HapticFeedbackConstants(android.view.HapticFeedbackConstants) TextPaint(android.text.TextPaint) BotSwitchCell(org.telegram.ui.Cells.BotSwitchCell) HintView(org.telegram.ui.Components.HintView) MessageBackgroundDrawable(org.telegram.ui.Components.MessageBackgroundDrawable) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) URLSpanBotCommand(org.telegram.ui.Components.URLSpanBotCommand) ReactionsLayoutInBubble(org.telegram.ui.Components.Reactions.ReactionsLayoutInBubble) ExifInterface(androidx.exifinterface.media.ExifInterface) FileLoader(org.telegram.messenger.FileLoader) ContextLinkCell(org.telegram.ui.Cells.ContextLinkCell) ClearHistoryAlert(org.telegram.ui.Components.ClearHistoryAlert) Space(android.widget.Space) ViewPager(androidx.viewpager.widget.ViewPager) Dialog(android.app.Dialog) BitmapFactory(android.graphics.BitmapFactory) GigagroupConvertAlert(org.telegram.ui.Components.GigagroupConvertAlert) URLSpanMono(org.telegram.ui.Components.URLSpanMono) URLSpanNoUnderline(org.telegram.ui.Components.URLSpanNoUnderline) AlertsCreator(org.telegram.ui.Components.AlertsCreator) BlurBehindDrawable(org.telegram.ui.Components.BlurBehindDrawable) ArrayList(java.util.ArrayList) SharedMediaLayout(org.telegram.ui.Components.SharedMediaLayout) FragmentContextView(org.telegram.ui.Components.FragmentContextView) TLRPC(org.telegram.tgnet.TLRPC) EditTextCaption(org.telegram.ui.Components.EditTextCaption) BuildConfig(org.telegram.messenger.BuildConfig) DialogCell(org.telegram.ui.Cells.DialogCell) SpannableString(android.text.SpannableString) BufferedWriter(java.io.BufferedWriter) FileOutputStream(java.io.FileOutputStream) TextUtils(android.text.TextUtils) ChatUnreadCell(org.telegram.ui.Cells.ChatUnreadCell) ChatLoadingCell(org.telegram.ui.Cells.ChatLoadingCell) ClippingImageView(org.telegram.ui.Components.ClippingImageView) File(java.io.File) ReactionsEffectOverlay(org.telegram.ui.Components.Reactions.ReactionsEffectOverlay) Gravity(android.view.Gravity) PorterDuffXfermode(android.graphics.PorterDuffXfermode) TypedValue(android.util.TypedValue) Configuration(android.content.res.Configuration) StickerCell(org.telegram.ui.Cells.StickerCell) ReactionsContainerLayout(org.telegram.ui.Components.ReactionsContainerLayout) ColorUtils(androidx.core.graphics.ColorUtils) ChatObject(org.telegram.messenger.ChatObject) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) VoIPHelper(org.telegram.ui.Components.voip.VoIPHelper) EmojiView(org.telegram.ui.Components.EmojiView) ValueAnimator(android.animation.ValueAnimator) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) ChatScrimPopupContainerLayout(org.telegram.ui.Components.ChatScrimPopupContainerLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) Spannable(android.text.Spannable) AccountInstance(org.telegram.messenger.AccountInstance) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) ApplicationLoader(org.telegram.messenger.ApplicationLoader) ChecksHintView(org.telegram.ui.Components.ChecksHintView) MediaController(org.telegram.messenger.MediaController) ThemeEditorView(org.telegram.ui.Components.ThemeEditorView) View(android.view.View) Matrix(android.graphics.Matrix) SearchCounterView(org.telegram.ui.Components.SearchCounterView) ForwardingPreviewView(org.telegram.ui.Components.ForwardingPreviewView) BitmapShader(android.graphics.BitmapShader) Utilities(org.telegram.messenger.Utilities) HideViewAfterAnimation(org.telegram.ui.Components.HideViewAfterAnimation) ObjectAnimator(android.animation.ObjectAnimator) GridLayoutManagerFixed(androidx.recyclerview.widget.GridLayoutManagerFixed) ImageLocation(org.telegram.messenger.ImageLocation) MentionCell(org.telegram.ui.Cells.MentionCell) ReactionTabHolderView(org.telegram.ui.Components.ReactionTabHolderView) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) SparseArray(android.util.SparseArray) List(java.util.List) TextView(android.widget.TextView) MotionBackgroundDrawable(org.telegram.ui.Components.MotionBackgroundDrawable) SecretChatHelper(org.telegram.messenger.SecretChatHelper) FileProvider(androidx.core.content.FileProvider) Pattern(java.util.regex.Pattern) 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) TextSelectionHelper(org.telegram.ui.Cells.TextSelectionHelper) ReactedUsersListView(org.telegram.ui.Components.ReactedUsersListView) KeyEvent(android.view.KeyEvent) VoIPService(org.telegram.messenger.voip.VoIPService) Theme(org.telegram.ui.ActionBar.Theme) PagerAdapter(androidx.viewpager.widget.PagerAdapter) ViewOutlineProvider(android.view.ViewOutlineProvider) BulletinFactory(org.telegram.ui.Components.BulletinFactory) Intent(android.content.Intent) HashMap(java.util.HashMap) ActionBarLayout(org.telegram.ui.ActionBar.ActionBarLayout) TranslateAlert(org.telegram.ui.Components.TranslateAlert) AtomicReference(java.util.concurrent.atomic.AtomicReference) ClipData(android.content.ClipData) SuppressLint(android.annotation.SuppressLint) VideoEditedInfo(org.telegram.messenger.VideoEditedInfo) MotionEvent(android.view.MotionEvent) AnimatorSet(android.animation.AnimatorSet) MediaDataController(org.telegram.messenger.MediaDataController) DialogInterface(android.content.DialogInterface) Browser(org.telegram.messenger.browser.Browser) FireworksOverlay(org.telegram.ui.Components.FireworksOverlay) LongSparseArray(androidx.collection.LongSparseArray) FileWriter(java.io.FileWriter) FileLog(org.telegram.messenger.FileLog) URLSpanReplacement(org.telegram.ui.Components.URLSpanReplacement) MessagesController(org.telegram.messenger.MessagesController) NumberTextView(org.telegram.ui.Components.NumberTextView) ChatAttachAlert(org.telegram.ui.Components.ChatAttachAlert) InviteMembersBottomSheet(org.telegram.ui.Components.InviteMembersBottomSheet) Collections(java.util.Collections) RLottieDrawable(org.telegram.ui.Components.RLottieDrawable) InputStream(java.io.InputStream) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) SpannableString(android.text.SpannableString) TLRPC(org.telegram.tgnet.TLRPC) StickersAlert(org.telegram.ui.Components.StickersAlert) TrendingStickersAlert(org.telegram.ui.Components.TrendingStickersAlert) CheckBoxCell(org.telegram.ui.Cells.CheckBoxCell) File(java.io.File) ClipData(android.content.ClipData) Bundle(android.os.Bundle) Intent(android.content.Intent) 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) Paint(android.graphics.Paint) TextSelectionHint(org.telegram.ui.Components.TextSelectionHint) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) Bulletin(org.telegram.ui.Components.Bulletin) ChatBlurredFrameLayout(org.telegram.ui.Components.ChatBlurredFrameLayout) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) AspectRatioFrameLayout(com.google.android.exoplayer2.ui.AspectRatioFrameLayout) FrameLayout(android.widget.FrameLayout) MessageObject(org.telegram.messenger.MessageObject)

Aggregations

AlertDialog (org.telegram.ui.ActionBar.AlertDialog)101 TLRPC (org.telegram.tgnet.TLRPC)71 TextView (android.widget.TextView)63 FrameLayout (android.widget.FrameLayout)47 ArrayList (java.util.ArrayList)47 Context (android.content.Context)45 View (android.view.View)44 AndroidUtilities (org.telegram.messenger.AndroidUtilities)41 LocaleController (org.telegram.messenger.LocaleController)41 Theme (org.telegram.ui.ActionBar.Theme)41 R (org.telegram.messenger.R)40 BaseFragment (org.telegram.ui.ActionBar.BaseFragment)40 LinearLayout (android.widget.LinearLayout)38 Paint (android.graphics.Paint)37 MessagesController (org.telegram.messenger.MessagesController)37 SuppressLint (android.annotation.SuppressLint)36 TextUtils (android.text.TextUtils)36 FileLog (org.telegram.messenger.FileLog)36 Build (android.os.Build)34 Gravity (android.view.Gravity)34