Search in sources :

Example 1 with ThemesHorizontalListCell

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

the class ThemeSetUrlActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (creatingNewTheme) {
        actionBar.setTitle(LocaleController.getString("NewThemeTitle", R.string.NewThemeTitle));
    } else {
        actionBar.setTitle(LocaleController.getString("EditThemeTitle", R.string.EditThemeTitle));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                saveTheme();
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    doneButton = menu.addItem(done_button, LocaleController.getString("Done", R.string.Done).toUpperCase());
    fragmentView = new LinearLayout(context);
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    LinearLayout linearLayout = (LinearLayout) fragmentView;
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    fragmentView.setOnTouchListener((v, event) -> true);
    linearLayoutTypeContainer = new LinearLayout(context);
    linearLayoutTypeContainer.setOrientation(LinearLayout.VERTICAL);
    linearLayoutTypeContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout.addView(linearLayoutTypeContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    headerCell = new HeaderCell(context, 23);
    headerCell.setText(LocaleController.getString("Info", R.string.Info));
    linearLayoutTypeContainer.addView(headerCell);
    nameField = new EditTextBoldCursor(context);
    nameField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    nameField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    nameField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameField.setMaxLines(1);
    nameField.setLines(1);
    nameField.setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
    nameField.setBackgroundDrawable(null);
    nameField.setPadding(0, 0, 0, 0);
    nameField.setSingleLine(true);
    InputFilter[] inputFilters = new InputFilter[1];
    inputFilters[0] = new InputFilter.LengthFilter(128);
    nameField.setFilters(inputFilters);
    nameField.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    nameField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    nameField.setHint(LocaleController.getString("ThemeNamePlaceholder", R.string.ThemeNamePlaceholder));
    nameField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameField.setCursorSize(AndroidUtilities.dp(20));
    nameField.setCursorWidth(1.5f);
    linearLayoutTypeContainer.addView(nameField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50, 23, 0, 23, 0));
    nameField.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_DONE) {
            AndroidUtilities.hideKeyboard(nameField);
            return true;
        }
        return false;
    });
    divider = new View(context) {

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawLine(LocaleController.isRTL ? 0 : AndroidUtilities.dp(20), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
        }
    };
    linearLayoutTypeContainer.addView(divider, new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1));
    LinearLayout linkContainer = new LinearLayout(context);
    linkContainer.setOrientation(LinearLayout.HORIZONTAL);
    linearLayoutTypeContainer.addView(linkContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50, 23, 0, 23, 0));
    editText = new EditTextBoldCursor(context);
    editText.setText(getMessagesController().linkPrefix + "/addtheme/");
    editText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    editText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    editText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    editText.setMaxLines(1);
    editText.setLines(1);
    editText.setEnabled(false);
    editText.setBackgroundDrawable(null);
    editText.setPadding(0, 0, 0, 0);
    editText.setSingleLine(true);
    editText.setInputType(InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
    linkContainer.addView(editText, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, 50));
    linkField = new EditTextBoldCursor(context);
    linkField.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    linkField.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
    linkField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    linkField.setMaxLines(1);
    linkField.setLines(1);
    linkField.setBackgroundDrawable(null);
    linkField.setPadding(0, 0, 0, 0);
    linkField.setSingleLine(true);
    linkField.setInputType(InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS | InputType.TYPE_TEXT_FLAG_MULTI_LINE | InputType.TYPE_TEXT_FLAG_AUTO_CORRECT);
    linkField.setImeOptions(EditorInfo.IME_ACTION_DONE);
    linkField.setHint(LocaleController.getString("SetUrlPlaceholder", R.string.SetUrlPlaceholder));
    linkField.setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    linkField.setCursorSize(AndroidUtilities.dp(20));
    linkField.setCursorWidth(1.5f);
    linkContainer.addView(linkField, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
    linkField.setOnEditorActionListener((textView, i, keyEvent) -> {
        if (i == EditorInfo.IME_ACTION_DONE && doneButton != null) {
            doneButton.performClick();
            return true;
        }
        return false;
    });
    linkField.addTextChangedListener(new TextWatcher() {

        @Override
        public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) {
        }

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) {
            if (ignoreCheck) {
                return;
            }
            checkUrl(linkField.getText().toString(), false);
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (creatingNewTheme) {
                return;
            }
            if (linkField.length() > 0) {
                String url = "https://" + getMessagesController().linkPrefix + "/addtheme/" + linkField.getText();
                String text = LocaleController.formatString("ThemeHelpLink", R.string.ThemeHelpLink, url);
                int index = text.indexOf(url);
                SpannableStringBuilder textSpan = new SpannableStringBuilder(text);
                if (index >= 0) {
                    textSpan.setSpan(new LinkSpan(url), index, index + url.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
                }
                helpInfoCell.setText(TextUtils.concat(infoText, "\n\n", textSpan));
            } else {
                helpInfoCell.setText(infoText);
            }
        }
    });
    if (creatingNewTheme) {
        linkField.setOnFocusChangeListener((v, hasFocus) -> {
            if (hasFocus) {
                helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp2", R.string.ThemeCreateHelp2)));
            } else {
                helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp", R.string.ThemeCreateHelp)));
            }
        });
    }
    checkInfoCell = new TextInfoPrivacyCell(context);
    checkInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    checkInfoCell.setVisibility(View.GONE);
    checkInfoCell.setBottomPadding(0);
    linearLayout.addView(checkInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    helpInfoCell = new TextInfoPrivacyCell(context);
    helpInfoCell.getTextView().setMovementMethod(new LinkMovementMethodMy());
    helpInfoCell.getTextView().setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteLinkSelection));
    if (creatingNewTheme) {
        helpInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("ThemeCreateHelp", R.string.ThemeCreateHelp)));
    } else {
        helpInfoCell.setText(infoText = AndroidUtilities.replaceTags(LocaleController.getString("ThemeSetUrlHelp", R.string.ThemeSetUrlHelp)));
    }
    linearLayout.addView(helpInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    if (creatingNewTheme) {
        helpInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        messagesCell = new ThemePreviewMessagesCell(context, parentLayout, 1);
        linearLayout.addView(messagesCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        createCell = new TextSettingsCell(context);
        createCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        createCell.setText(LocaleController.getString("UseDifferentTheme", R.string.UseDifferentTheme), false);
        linearLayout.addView(createCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        createCell.setOnClickListener(v -> {
            if (getParentActivity() == null) {
                return;
            }
            BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity(), false);
            builder.setApplyBottomPadding(false);
            LinearLayout container = new LinearLayout(context);
            container.setOrientation(LinearLayout.VERTICAL);
            TextView titleView = new TextView(context);
            titleView.setText(LocaleController.getString("ChooseTheme", R.string.ChooseTheme));
            titleView.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
            titleView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 20);
            titleView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            container.addView(titleView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 22, 12, 22, 4));
            titleView.setOnTouchListener((v2, event) -> true);
            builder.setCustomView(container);
            ArrayList<Theme.ThemeInfo> themes = new ArrayList<>();
            for (int a = 0, N = Theme.themes.size(); a < N; a++) {
                Theme.ThemeInfo themeInfo = Theme.themes.get(a);
                if (themeInfo.info != null && themeInfo.info.document == null) {
                    continue;
                }
                themes.add(themeInfo);
            }
            ThemesHorizontalListCell cell = new ThemesHorizontalListCell(context, ThemeActivity.THEME_TYPE_OTHER, themes, new ArrayList<>()) {

                @Override
                protected void updateRows() {
                    builder.getDismissRunnable().run();
                }
            };
            container.addView(cell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 148, 0, 7, 0, 1));
            cell.scrollToCurrentTheme(fragmentView.getMeasuredWidth(), false);
            showDialog(builder.create());
        });
        createInfoCell = new TextInfoPrivacyCell(context);
        createInfoCell.setText(AndroidUtilities.replaceTags(LocaleController.getString("UseDifferentThemeInfo", R.string.UseDifferentThemeInfo)));
        createInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout.addView(createInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    } else {
        helpInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    }
    if (info != null) {
        ignoreCheck = true;
        nameField.setText(info.title);
        nameField.setSelection(nameField.length());
        linkField.setText(info.slug);
        linkField.setSelection(linkField.length());
        ignoreCheck = false;
    }
    return fragmentView;
}
Also used : HeaderCell(org.telegram.ui.Cells.HeaderCell) SpannableStringBuilder(android.text.SpannableStringBuilder) ArrayList(java.util.ArrayList) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) InputFilter(android.text.InputFilter) ThemePreviewMessagesCell(org.telegram.ui.Cells.ThemePreviewMessagesCell) Canvas(android.graphics.Canvas) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ThemesHorizontalListCell(org.telegram.ui.Cells.ThemesHorizontalListCell) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) View(android.view.View) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) Theme(org.telegram.ui.ActionBar.Theme) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 2 with ThemesHorizontalListCell

use of org.telegram.ui.Cells.ThemesHorizontalListCell 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)

Aggregations

Canvas (android.graphics.Canvas)2 TextPaint (android.text.TextPaint)2 View (android.view.View)2 TextView (android.widget.TextView)2 ArrayList (java.util.ArrayList)2 ActionBar (org.telegram.ui.ActionBar.ActionBar)2 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)2 Theme (org.telegram.ui.ActionBar.Theme)2 HeaderCell (org.telegram.ui.Cells.HeaderCell)2 TextInfoPrivacyCell (org.telegram.ui.Cells.TextInfoPrivacyCell)2 TextSettingsCell (org.telegram.ui.Cells.TextSettingsCell)2 ThemePreviewMessagesCell (org.telegram.ui.Cells.ThemePreviewMessagesCell)2 ThemesHorizontalListCell (org.telegram.ui.Cells.ThemesHorizontalListCell)2 Manifest (android.Manifest)1 ObjectAnimator (android.animation.ObjectAnimator)1 Activity (android.app.Activity)1 TimePickerDialog (android.app.TimePickerDialog)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1