Search in sources :

Example 1 with ThemePreviewMessagesCell

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

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

the class ReactionsDoubleTapManageActivity method createView.

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

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });
    LinearLayout linaerLayout = new LinearLayout(context);
    linaerLayout.setOrientation(LinearLayout.VERTICAL);
    listView = new RecyclerListView(context);
    listView.setLayoutManager(new LinearLayoutManager(context));
    listView.setAdapter(listAdapter = new RecyclerView.Adapter() {

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            View view;
            switch(viewType) {
                case 0:
                    ThemePreviewMessagesCell messagesCell = new ThemePreviewMessagesCell(context, parentLayout, ThemePreviewMessagesCell.TYPE_REACTIONS_DOUBLE_TAP);
                    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
                        messagesCell.setImportantForAccessibility(View.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
                    }
                    messagesCell.fragment = ReactionsDoubleTapManageActivity.this;
                    view = messagesCell;
                    break;
                case 2:
                    TextInfoPrivacyCell cell = new TextInfoPrivacyCell(context);
                    cell.setText(LocaleController.getString("DoubleTapPreviewRational", R.string.DoubleTapPreviewRational));
                    view = cell;
                    break;
                default:
                case 1:
                    {
                        view = new AvailableReactionCell(context, true);
                    }
                    break;
            }
            return new RecyclerListView.Holder(view);
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            switch(getItemViewType(position)) {
                case 1:
                    AvailableReactionCell reactionCell = (AvailableReactionCell) holder.itemView;
                    TLRPC.TL_availableReaction react = getAvailableReactions().get(position - reactionsStartRow);
                    reactionCell.bind(react, react.reaction.contains(MediaDataController.getInstance(currentAccount).getDoubleTapReaction()));
                    break;
            }
        }

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

        @Override
        public int getItemViewType(int position) {
            if (position == previewRow) {
                return 0;
            }
            if (position == infoRow) {
                return 2;
            }
            return 1;
        }
    });
    listView.setOnItemClickListener((view, position) -> {
        if (view instanceof AvailableReactionCell) {
            MediaDataController.getInstance(currentAccount).setDoubleTapReaction(((AvailableReactionCell) view).react.reaction);
            AndroidUtilities.updateVisibleRows(listView);
        }
    });
    linaerLayout.addView(listView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    fragmentView = contentView = linaerLayout;
    updateColors();
    updateRows();
    return contentView;
}
Also used : ThemePreviewMessagesCell(org.telegram.ui.Cells.ThemePreviewMessagesCell) ViewGroup(android.view.ViewGroup) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) AvailableReactionCell(org.telegram.ui.Cells.AvailableReactionCell) RecyclerListView(org.telegram.ui.Components.RecyclerListView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) View(android.view.View) RecyclerView(androidx.recyclerview.widget.RecyclerView) RecyclerListView(org.telegram.ui.Components.RecyclerListView) SuppressLint(android.annotation.SuppressLint) TLRPC(org.telegram.tgnet.TLRPC) NonNull(androidx.annotation.NonNull) RecyclerView(androidx.recyclerview.widget.RecyclerView) ActionBar(org.telegram.ui.ActionBar.ActionBar) LinearLayout(android.widget.LinearLayout)

Aggregations

View (android.view.View)2 LinearLayout (android.widget.LinearLayout)2 ActionBar (org.telegram.ui.ActionBar.ActionBar)2 TextInfoPrivacyCell (org.telegram.ui.Cells.TextInfoPrivacyCell)2 ThemePreviewMessagesCell (org.telegram.ui.Cells.ThemePreviewMessagesCell)2 SuppressLint (android.annotation.SuppressLint)1 Canvas (android.graphics.Canvas)1 Editable (android.text.Editable)1 InputFilter (android.text.InputFilter)1 SpannableStringBuilder (android.text.SpannableStringBuilder)1 TextPaint (android.text.TextPaint)1 TextWatcher (android.text.TextWatcher)1 ViewGroup (android.view.ViewGroup)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 ArrayList (java.util.ArrayList)1 TLRPC (org.telegram.tgnet.TLRPC)1 ActionBarMenu (org.telegram.ui.ActionBar.ActionBarMenu)1