Search in sources :

Example 11 with TextSettingsCell

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

the class LinkEditActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    if (type == CREATE_TYPE) {
        actionBar.setTitle(LocaleController.getString("NewLink", R.string.NewLink));
    } else if (type == EDIT_TYPE) {
        actionBar.setTitle(LocaleController.getString("EditLink", R.string.EditLink));
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
                AndroidUtilities.hideKeyboard(usesEditText);
            }
        }
    });
    createTextView = new TextView(context);
    createTextView.setEllipsize(TextUtils.TruncateAt.END);
    createTextView.setGravity(Gravity.CENTER_VERTICAL);
    createTextView.setOnClickListener(this::onCreateClicked);
    createTextView.setSingleLine();
    if (type == CREATE_TYPE) {
        createTextView.setText(LocaleController.getString("CreateLinkHeader", R.string.CreateLinkHeader));
    } else if (type == EDIT_TYPE) {
        createTextView.setText(LocaleController.getString("SaveLinkHeader", R.string.SaveLinkHeader));
    }
    createTextView.setTextColor(Theme.getColor(Theme.key_actionBarDefaultTitle));
    createTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14f);
    createTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    createTextView.setPadding(AndroidUtilities.dp(18), AndroidUtilities.dp(8), AndroidUtilities.dp(18), AndroidUtilities.dp(8));
    int topSpace = actionBar.getOccupyStatusBar() ? (AndroidUtilities.statusBarHeight / AndroidUtilities.dp(2)) : 0;
    actionBar.addView(createTextView, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.END | Gravity.CENTER_VERTICAL, 0, topSpace, 0, 0));
    scrollView = new ScrollView(context);
    SizeNotifierFrameLayout contentView = new SizeNotifierFrameLayout(context) {

        int oldKeyboardHeight;

        @Override
        protected AdjustPanLayoutHelper createAdjustPanLayoutHelper() {
            AdjustPanLayoutHelper panLayoutHelper = new AdjustPanLayoutHelper(this) {

                @Override
                protected void onTransitionStart(boolean keyboardVisible, int contentHeight) {
                    super.onTransitionStart(keyboardVisible, contentHeight);
                    scrollView.getLayoutParams().height = contentHeight;
                }

                @Override
                protected void onTransitionEnd() {
                    super.onTransitionEnd();
                    scrollView.getLayoutParams().height = LinearLayout.LayoutParams.MATCH_PARENT;
                    scrollView.requestLayout();
                }

                @Override
                protected void onPanTranslationUpdate(float y, float progress, boolean keyboardVisible) {
                    super.onPanTranslationUpdate(y, progress, keyboardVisible);
                    setTranslationY(0);
                }

                @Override
                protected boolean heightAnimationEnabled() {
                    return !finished;
                }
            };
            panLayoutHelper.setCheckHierarchyHeight(true);
            return panLayoutHelper;
        }

        @Override
        protected void onAttachedToWindow() {
            super.onAttachedToWindow();
            adjustPanLayoutHelper.onAttach();
        }

        @Override
        protected void onDetachedFromWindow() {
            super.onDetachedFromWindow();
            adjustPanLayoutHelper.onDetach();
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            measureKeyboardHeight();
            boolean isNeedScrollToEnd = usesEditText.isCursorVisible() || nameEditText.isCursorVisible();
            if (oldKeyboardHeight != keyboardHeight && keyboardHeight > AndroidUtilities.dp(20) && isNeedScrollToEnd) {
                scrollToEnd = true;
                invalidate();
            } else if (scrollView.getScrollY() == 0 && !isNeedScrollToEnd) {
                scrollToStart = true;
                invalidate();
            }
            if (keyboardHeight != 0 && keyboardHeight < AndroidUtilities.dp(20)) {
                usesEditText.clearFocus();
                nameEditText.clearFocus();
            }
            oldKeyboardHeight = keyboardHeight;
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int scrollY = scrollView.getScrollY();
            super.onLayout(changed, l, t, r, b);
            if (scrollY != scrollView.getScrollY() && !scrollToEnd) {
                scrollView.setTranslationY(scrollView.getScrollY() - scrollY);
                scrollView.animate().cancel();
                scrollView.animate().translationY(0).setDuration(AdjustPanLayoutHelper.keyboardDuration).setInterpolator(AdjustPanLayoutHelper.keyboardInterpolator).start();
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            if (scrollToEnd) {
                scrollToEnd = false;
                scrollView.smoothScrollTo(0, Math.max(0, scrollView.getChildAt(0).getMeasuredHeight() - scrollView.getMeasuredHeight()));
            } else if (scrollToStart) {
                scrollToStart = false;
                scrollView.smoothScrollTo(0, 0);
            }
        }
    };
    fragmentView = contentView;
    LinearLayout linearLayout = new LinearLayout(context) {

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            int elementsHeight = 0;
            int h = MeasureSpec.getSize(heightMeasureSpec);
            for (int i = 0; i < getChildCount(); i++) {
                View child = getChildAt(i);
                if (child != buttonTextView && child.getVisibility() != View.GONE) {
                    elementsHeight += child.getMeasuredHeight();
                }
            }
            int topMargin;
            int buttonH = AndroidUtilities.dp(48) + AndroidUtilities.dp(24) + AndroidUtilities.dp(16);
            if (elementsHeight >= h - buttonH) {
                topMargin = AndroidUtilities.dp(24);
            } else {
                topMargin = AndroidUtilities.dp(24) + (h - buttonH) - elementsHeight;
            }
            if (((LayoutParams) buttonTextView.getLayoutParams()).topMargin != topMargin) {
                int oldMargin = ((LayoutParams) buttonTextView.getLayoutParams()).topMargin;
                ((LayoutParams) buttonTextView.getLayoutParams()).topMargin = topMargin;
                if (!firstLayout) {
                    buttonTextView.setTranslationY(oldMargin - topMargin);
                    buttonTextView.animate().translationY(0).setDuration(AdjustPanLayoutHelper.keyboardDuration).setInterpolator(AdjustPanLayoutHelper.keyboardInterpolator).start();
                }
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }
        }

        @Override
        protected void dispatchDraw(Canvas canvas) {
            super.dispatchDraw(canvas);
            firstLayout = false;
        }
    };
    LayoutTransition transition = new LayoutTransition();
    transition.setDuration(100);
    linearLayout.setLayoutTransition(transition);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(linearLayout);
    buttonTextView = new TextView(context);
    buttonTextView.setPadding(AndroidUtilities.dp(34), 0, AndroidUtilities.dp(34), 0);
    buttonTextView.setGravity(Gravity.CENTER);
    buttonTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
    buttonTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    if (type == CREATE_TYPE) {
        buttonTextView.setText(LocaleController.getString("CreateLink", R.string.CreateLink));
    } else if (type == EDIT_TYPE) {
        buttonTextView.setText(LocaleController.getString("SaveLink", R.string.SaveLink));
    }
    approveCell = new TextCheckCell(context) {

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.save();
            canvas.clipRect(0, 0, getWidth(), getHeight());
            super.onDraw(canvas);
            canvas.restore();
        }
    };
    approveCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundUnchecked));
    approveCell.setColors(Theme.key_windowBackgroundCheckText, Theme.key_switchTrackBlue, Theme.key_switchTrackBlueChecked, Theme.key_switchTrackBlueThumb, Theme.key_switchTrackBlueThumbChecked);
    approveCell.setDrawCheckRipple(true);
    approveCell.setHeight(56);
    approveCell.setTag(Theme.key_windowBackgroundUnchecked);
    approveCell.setTextAndCheck(LocaleController.getString("ApproveNewMembers", R.string.ApproveNewMembers), false, false);
    approveCell.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    approveCell.setOnClickListener(view -> {
        TextCheckCell cell = (TextCheckCell) view;
        boolean newIsChecked = !cell.isChecked();
        cell.setBackgroundColorAnimated(newIsChecked, Theme.getColor(newIsChecked ? Theme.key_windowBackgroundChecked : Theme.key_windowBackgroundUnchecked));
        cell.setChecked(newIsChecked);
        setUsesVisible(!newIsChecked);
        firstLayout = true;
    });
    linearLayout.addView(approveCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 56));
    TextInfoPrivacyCell hintCell = new TextInfoPrivacyCell(context);
    hintCell.setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
    hintCell.setText(LocaleController.getString("ApproveNewMembersDescription", R.string.ApproveNewMembersDescription));
    linearLayout.addView(hintCell);
    timeHeaderCell = new HeaderCell(context);
    timeHeaderCell.setText(LocaleController.getString("LimitByPeriod", R.string.LimitByPeriod));
    linearLayout.addView(timeHeaderCell);
    timeChooseView = new SlideChooseView(context);
    linearLayout.addView(timeChooseView);
    timeEditText = new TextView(context);
    timeEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
    timeEditText.setGravity(Gravity.CENTER_VERTICAL);
    timeEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    timeEditText.setHint(LocaleController.getString("TimeLimitHint", R.string.TimeLimitHint));
    timeEditText.setOnClickListener(view -> AlertsCreator.createDatePickerDialog(context, -1, (notify, scheduleDate) -> chooseDate(scheduleDate)));
    timeChooseView.setCallback(index -> {
        if (index < dispalyedDates.size()) {
            long date = dispalyedDates.get(index) + getConnectionsManager().getCurrentTime();
            timeEditText.setText(LocaleController.formatDateAudio(date, false));
        } else {
            timeEditText.setText("");
        }
    });
    resetDates();
    linearLayout.addView(timeEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
    divider = new TextInfoPrivacyCell(context);
    divider.setText(LocaleController.getString("TimeLimitHelp", R.string.TimeLimitHelp));
    linearLayout.addView(divider);
    usesHeaderCell = new HeaderCell(context);
    usesHeaderCell.setText(LocaleController.getString("LimitNumberOfUses", R.string.LimitNumberOfUses));
    linearLayout.addView(usesHeaderCell);
    usesChooseView = new SlideChooseView(context);
    usesChooseView.setCallback(index -> {
        usesEditText.clearFocus();
        ignoreSet = true;
        if (index < dispalyedUses.size()) {
            usesEditText.setText(dispalyedUses.get(index).toString());
        } else {
            usesEditText.setText("");
        }
        ignoreSet = false;
    });
    resetUses();
    linearLayout.addView(usesChooseView);
    usesEditText = new EditText(context) {

        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                setCursorVisible(true);
            }
            return super.onTouchEvent(event);
        }
    };
    usesEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
    usesEditText.setGravity(Gravity.CENTER_VERTICAL);
    usesEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    usesEditText.setHint(LocaleController.getString("UsesLimitHint", R.string.UsesLimitHint));
    usesEditText.setKeyListener(DigitsKeyListener.getInstance("0123456789."));
    usesEditText.setInputType(InputType.TYPE_CLASS_NUMBER);
    usesEditText.addTextChangedListener(new TextWatcher() {

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

        @Override
        public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
        }

        @Override
        public void afterTextChanged(Editable editable) {
            if (ignoreSet) {
                return;
            }
            if (editable.toString().equals("0")) {
                usesEditText.setText("");
                return;
            }
            int customUses;
            try {
                customUses = Integer.parseInt(editable.toString());
            } catch (NumberFormatException exception) {
                resetUses();
                return;
            }
            if (customUses > 100000) {
                resetUses();
            } else {
                chooseUses(customUses);
            }
        }
    });
    linearLayout.addView(usesEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
    dividerUses = new TextInfoPrivacyCell(context);
    dividerUses.setText(LocaleController.getString("UsesLimitHelp", R.string.UsesLimitHelp));
    linearLayout.addView(dividerUses);
    nameEditText = new EditText(context) {

        @SuppressLint("ClickableViewAccessibility")
        @Override
        public boolean onTouchEvent(MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_UP) {
                setCursorVisible(true);
            }
            return super.onTouchEvent(event);
        }
    };
    nameEditText.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) {
            SpannableStringBuilder builder = new SpannableStringBuilder(s);
            Emoji.replaceEmoji(builder, nameEditText.getPaint().getFontMetricsInt(), (int) nameEditText.getPaint().getTextSize(), false);
            int selection = nameEditText.getSelectionStart();
            nameEditText.removeTextChangedListener(this);
            nameEditText.setText(builder);
            if (selection >= 0) {
                nameEditText.setSelection(selection);
            }
            nameEditText.addTextChangedListener(this);
        }
    });
    nameEditText.setCursorVisible(false);
    nameEditText.setFilters(new InputFilter[] { new InputFilter.LengthFilter(32) });
    nameEditText.setGravity(Gravity.CENTER_VERTICAL);
    nameEditText.setHint(LocaleController.getString("LinkNameHint", R.string.LinkNameHint));
    nameEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
    nameEditText.setLines(1);
    nameEditText.setPadding(AndroidUtilities.dp(22), 0, AndroidUtilities.dp(22), 0);
    nameEditText.setSingleLine();
    nameEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    nameEditText.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    linearLayout.addView(nameEditText, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
    dividerName = new TextInfoPrivacyCell(context);
    dividerName.setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    dividerName.setText(LocaleController.getString("LinkNameHelp", R.string.LinkNameHelp));
    linearLayout.addView(dividerName);
    if (type == EDIT_TYPE) {
        revokeLink = new TextSettingsCell(context);
        revokeLink.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        revokeLink.setText(LocaleController.getString("RevokeLink", R.string.RevokeLink), false);
        revokeLink.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText5));
        revokeLink.setOnClickListener(view -> {
            AlertDialog.Builder builder2 = new AlertDialog.Builder(getParentActivity());
            builder2.setMessage(LocaleController.getString("RevokeAlert", R.string.RevokeAlert));
            builder2.setTitle(LocaleController.getString("RevokeLink", R.string.RevokeLink));
            builder2.setPositiveButton(LocaleController.getString("RevokeButton", R.string.RevokeButton), (dialogInterface2, i2) -> {
                callback.revokeLink(inviteToEdit);
                finishFragment();
            });
            builder2.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder2.create());
        });
        linearLayout.addView(revokeLink);
    }
    contentView.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    linearLayout.addView(buttonTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM, 16, 15, 16, 16));
    timeHeaderCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    timeChooseView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    timeEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    usesHeaderCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    usesChooseView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    usesEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    nameEditText.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    contentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    buttonTextView.setOnClickListener(this::onCreateClicked);
    buttonTextView.setTextColor(Theme.getColor(Theme.key_featuredStickers_buttonText));
    dividerUses.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    divider.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
    buttonTextView.setBackgroundDrawable(Theme.createSimpleSelectorRoundRectDrawable(AndroidUtilities.dp(6), Theme.getColor(Theme.key_featuredStickers_addButton), Theme.getColor(Theme.key_featuredStickers_addButtonPressed)));
    usesEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    usesEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
    timeEditText.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
    timeEditText.setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText));
    usesEditText.setCursorVisible(false);
    setInviteToEdit(inviteToEdit);
    contentView.setClipChildren(false);
    scrollView.setClipChildren(false);
    linearLayout.setClipChildren(false);
    return contentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) Context(android.content.Context) LinearLayout(android.widget.LinearLayout) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) Theme(org.telegram.ui.ActionBar.Theme) AndroidUtilities(org.telegram.messenger.AndroidUtilities) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) LayoutTransition(android.animation.LayoutTransition) SuppressLint(android.annotation.SuppressLint) SpannableStringBuilder(android.text.SpannableStringBuilder) MotionEvent(android.view.MotionEvent) TLRPC(org.telegram.tgnet.TLRPC) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) View(android.view.View) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Canvas(android.graphics.Canvas) Emoji(org.telegram.messenger.Emoji) SlideChooseView(org.telegram.ui.Components.SlideChooseView) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) InputType(android.text.InputType) TextUtils(android.text.TextUtils) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) LayoutHelper(org.telegram.ui.Components.LayoutHelper) Gravity(android.view.Gravity) TextView(android.widget.TextView) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Vibrator(android.os.Vibrator) InputFilter(android.text.InputFilter) DigitsKeyListener(android.text.method.DigitsKeyListener) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) TextWatcher(android.text.TextWatcher) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) HeaderCell(org.telegram.ui.Cells.HeaderCell) SpannableStringBuilder(android.text.SpannableStringBuilder) LayoutTransition(android.animation.LayoutTransition) SlideChooseView(org.telegram.ui.Components.SlideChooseView) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) SizeNotifierFrameLayout(org.telegram.ui.Components.SizeNotifierFrameLayout) Canvas(android.graphics.Canvas) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) View(android.view.View) SlideChooseView(org.telegram.ui.Components.SlideChooseView) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) ScrollView(android.widget.ScrollView) SuppressLint(android.annotation.SuppressLint) AdjustPanLayoutHelper(org.telegram.ui.ActionBar.AdjustPanLayoutHelper) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 12 with TextSettingsCell

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

the class PaymentFormActivity method createView.

@SuppressLint({ "SetJavaScriptEnabled", "AddJavascriptInterface" })
@Override
public View createView(Context context) {
    if (currentStep == 0) {
        actionBar.setTitle(LocaleController.getString("PaymentShippingInfo", R.string.PaymentShippingInfo));
    } else if (currentStep == 1) {
        actionBar.setTitle(LocaleController.getString("PaymentShippingMethod", R.string.PaymentShippingMethod));
    } else if (currentStep == 2) {
        actionBar.setTitle(LocaleController.getString("PaymentCardInfo", R.string.PaymentCardInfo));
    } else if (currentStep == 3) {
        actionBar.setTitle(LocaleController.getString("PaymentCardInfo", R.string.PaymentCardInfo));
    } else if (currentStep == 4) {
        if (paymentForm.invoice.test) {
            actionBar.setTitle("Test " + LocaleController.getString("PaymentCheckout", R.string.PaymentCheckout));
        } else {
            actionBar.setTitle(LocaleController.getString("PaymentCheckout", R.string.PaymentCheckout));
        }
    } else if (currentStep == 5) {
        if (paymentForm.invoice.test) {
            actionBar.setTitle("Test " + LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt));
        } else {
            actionBar.setTitle(LocaleController.getString("PaymentReceipt", R.string.PaymentReceipt));
        }
    } else if (currentStep == 6) {
        actionBar.setTitle(LocaleController.getString("PaymentPassword", R.string.PaymentPassword));
    }
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                if (donePressed) {
                    return;
                }
                finishFragment();
            } else if (id == done_button) {
                if (donePressed) {
                    return;
                }
                if (currentStep != 3) {
                    AndroidUtilities.hideKeyboard(getParentActivity().getCurrentFocus());
                }
                if (currentStep == 0) {
                    setDonePressed(true);
                    sendForm();
                } else if (currentStep == 1) {
                    for (int a = 0; a < radioCells.length; a++) {
                        if (radioCells[a].isChecked()) {
                            shippingOption = requestedInfo.shipping_options.get(a);
                            break;
                        }
                    }
                    goToNextStep();
                } else if (currentStep == 2) {
                    sendCardData();
                } else if (currentStep == 3) {
                    checkPassword();
                } else if (currentStep == 6) {
                    sendSavePassword(false);
                }
            }
        }
    });
    ActionBarMenu menu = actionBar.createMenu();
    if (currentStep == 0 || currentStep == 1 || currentStep == 2 || currentStep == 3 || currentStep == 4 || currentStep == 6) {
        doneItem = menu.addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56), LocaleController.getString("Done", R.string.Done));
        progressView = new ContextProgressView(context, 1);
        progressView.setAlpha(0.0f);
        progressView.setScaleX(0.1f);
        progressView.setScaleY(0.1f);
        progressView.setVisibility(View.INVISIBLE);
        doneItem.addView(progressView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    }
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    scrollView = new ScrollView(context);
    scrollView.setFillViewport(true);
    AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault));
    frameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 0, 0, 0, currentStep == 4 ? 48 : 0));
    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    linearLayout2.setClipChildren(false);
    scrollView.addView(linearLayout2, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    if (currentStep == 0) {
        HashMap<String, String> languageMap = new HashMap<>();
        HashMap<String, String> countryMap = new HashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
            String line;
            while ((line = reader.readLine()) != null) {
                String[] args = line.split(";");
                countriesArray.add(0, args[2]);
                countriesMap.put(args[2], args[0]);
                codesMap.put(args[0], args[2]);
                countryMap.put(args[1], args[2]);
                if (args.length > 3) {
                    phoneFormatMap.put(args[0], args[3]);
                }
                languageMap.put(args[1], args[2]);
            }
            reader.close();
        } catch (Exception e) {
            FileLog.e(e);
        }
        Collections.sort(countriesArray, String::compareTo);
        inputFields = new EditTextBoldCursor[FIELDS_COUNT_ADDRESS];
        for (int a = 0; a < FIELDS_COUNT_ADDRESS; a++) {
            if (a == FIELD_STREET1) {
                headerCell[0] = new HeaderCell(context);
                headerCell[0].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                headerCell[0].setText(LocaleController.getString("PaymentShippingAddress", R.string.PaymentShippingAddress));
                linearLayout2.addView(headerCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            } else if (a == FIELD_NAME) {
                sectionCell[0] = new ShadowSectionCell(context);
                linearLayout2.addView(sectionCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                headerCell[1] = new HeaderCell(context);
                headerCell[1].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                headerCell[1].setText(LocaleController.getString("PaymentShippingReceiver", R.string.PaymentShippingReceiver));
                linearLayout2.addView(headerCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
            ViewGroup container;
            if (a == FIELD_PHONECODE) {
                container = new LinearLayout(context);
                container.setClipChildren(false);
                ((LinearLayout) container).setOrientation(LinearLayout.HORIZONTAL);
                linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            } else if (a == FIELD_PHONE) {
                container = (ViewGroup) inputFields[FIELD_PHONECODE].getParent();
            } else {
                container = new FrameLayout(context);
                container.setClipChildren(false);
                linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                boolean allowDivider = a != FIELD_POSTCODE;
                if (allowDivider) {
                    if (a == FIELD_EMAIL && !paymentForm.invoice.phone_requested) {
                        allowDivider = false;
                    } else if (a == FIELD_NAME && !paymentForm.invoice.phone_requested && !paymentForm.invoice.email_requested) {
                        allowDivider = false;
                    }
                }
                if (allowDivider) {
                    View 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);
                        }
                    };
                    divider.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    dividers.add(divider);
                    container.addView(divider, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.LEFT | Gravity.BOTTOM));
                }
            }
            if (a == FIELD_PHONE) {
                inputFields[a] = new HintEditText(context);
            } else {
                inputFields[a] = new EditTextBoldCursor(context);
            }
            inputFields[a].setTag(a);
            inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setBackgroundDrawable(null);
            inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setCursorSize(AndroidUtilities.dp(20));
            inputFields[a].setCursorWidth(1.5f);
            if (a == FIELD_COUNTRY) {
                inputFields[a].setOnTouchListener((v, event) -> {
                    if (getParentActivity() == null) {
                        return false;
                    }
                    if (event.getAction() == MotionEvent.ACTION_UP) {
                        CountrySelectActivity fragment = new CountrySelectActivity(false);
                        fragment.setCountrySelectActivityDelegate((country) -> {
                            inputFields[FIELD_COUNTRY].setText(country.name);
                            countryName = country.shortname;
                        });
                        presentFragment(fragment);
                    }
                    return true;
                });
                inputFields[a].setInputType(0);
            }
            if (a == FIELD_PHONE || a == FIELD_PHONECODE) {
                inputFields[a].setInputType(InputType.TYPE_CLASS_PHONE);
            } else if (a == FIELD_EMAIL) {
                inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT);
            } else {
                inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            }
            inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            switch(a) {
                case FIELD_NAME:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingName", R.string.PaymentShippingName));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.name != null) {
                        inputFields[a].setText(paymentForm.saved_info.name);
                    }
                    break;
                case FIELD_EMAIL:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingEmailPlaceholder", R.string.PaymentShippingEmailPlaceholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.email != null) {
                        inputFields[a].setText(paymentForm.saved_info.email);
                    }
                    break;
                case FIELD_STREET1:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingAddress1Placeholder", R.string.PaymentShippingAddress1Placeholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        inputFields[a].setText(paymentForm.saved_info.shipping_address.street_line1);
                    }
                    break;
                case FIELD_STREET2:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingAddress2Placeholder", R.string.PaymentShippingAddress2Placeholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        inputFields[a].setText(paymentForm.saved_info.shipping_address.street_line2);
                    }
                    break;
                case FIELD_CITY:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingCityPlaceholder", R.string.PaymentShippingCityPlaceholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        inputFields[a].setText(paymentForm.saved_info.shipping_address.city);
                    }
                    break;
                case FIELD_STATE:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingStatePlaceholder", R.string.PaymentShippingStatePlaceholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        inputFields[a].setText(paymentForm.saved_info.shipping_address.state);
                    }
                    break;
                case FIELD_COUNTRY:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingCountry", R.string.PaymentShippingCountry));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        String value = countryMap.get(paymentForm.saved_info.shipping_address.country_iso2);
                        countryName = paymentForm.saved_info.shipping_address.country_iso2;
                        inputFields[a].setText(value != null ? value : countryName);
                    }
                    break;
                case FIELD_POSTCODE:
                    inputFields[a].setHint(LocaleController.getString("PaymentShippingZipPlaceholder", R.string.PaymentShippingZipPlaceholder));
                    if (paymentForm.saved_info != null && paymentForm.saved_info.shipping_address != null) {
                        inputFields[a].setText(paymentForm.saved_info.shipping_address.post_code);
                    }
                    break;
            }
            inputFields[a].setSelection(inputFields[a].length());
            if (a == FIELD_PHONECODE) {
                textView = new TextView(context);
                textView.setText("+");
                textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                container.addView(textView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 21, 12, 0, 6));
                inputFields[a].setPadding(AndroidUtilities.dp(10), 0, 0, 0);
                inputFields[a].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
                InputFilter[] inputFilters = new InputFilter[1];
                inputFilters[0] = new InputFilter.LengthFilter(5);
                inputFields[a].setFilters(inputFilters);
                container.addView(inputFields[a], LayoutHelper.createLinear(55, LayoutHelper.WRAP_CONTENT, 0, 12, 21, 6));
                inputFields[a].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) {
                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        if (ignoreOnTextChange) {
                            return;
                        }
                        ignoreOnTextChange = true;
                        String text = PhoneFormat.stripExceptNumbers(inputFields[FIELD_PHONECODE].getText().toString());
                        inputFields[FIELD_PHONECODE].setText(text);
                        HintEditText phoneField = (HintEditText) inputFields[FIELD_PHONE];
                        if (text.length() == 0) {
                            phoneField.setHintText(null);
                            phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                        } else {
                            String country;
                            boolean ok = false;
                            String textToSet = null;
                            if (text.length() > 4) {
                                for (int a = 4; a >= 1; a--) {
                                    String sub = text.substring(0, a);
                                    country = codesMap.get(sub);
                                    if (country != null) {
                                        ok = true;
                                        textToSet = text.substring(a) + inputFields[FIELD_PHONE].getText().toString();
                                        inputFields[FIELD_PHONECODE].setText(text = sub);
                                        break;
                                    }
                                }
                                if (!ok) {
                                    textToSet = text.substring(1) + inputFields[FIELD_PHONE].getText().toString();
                                    inputFields[FIELD_PHONECODE].setText(text = text.substring(0, 1));
                                }
                            }
                            country = codesMap.get(text);
                            boolean set = false;
                            if (country != null) {
                                int index = countriesArray.indexOf(country);
                                if (index != -1) {
                                    String hint = phoneFormatMap.get(text);
                                    if (hint != null) {
                                        set = true;
                                        phoneField.setHintText(hint.replace('X', '–'));
                                        phoneField.setHint(null);
                                    }
                                }
                            }
                            if (!set) {
                                phoneField.setHintText(null);
                                phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                            }
                            if (!ok) {
                                inputFields[FIELD_PHONECODE].setSelection(inputFields[FIELD_PHONECODE].getText().length());
                            }
                            if (textToSet != null) {
                                phoneField.requestFocus();
                                phoneField.setText(textToSet);
                                phoneField.setSelection(phoneField.length());
                            }
                        }
                        ignoreOnTextChange = false;
                    }
                });
            } else if (a == FIELD_PHONE) {
                inputFields[a].setPadding(0, 0, 0, 0);
                inputFields[a].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
                container.addView(inputFields[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 12, 21, 6));
                inputFields[a].addTextChangedListener(new TextWatcher() {

                    private int characterAction = -1;

                    private int actionPosition;

                    @Override
                    public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                        if (count == 0 && after == 1) {
                            characterAction = 1;
                        } else if (count == 1 && after == 0) {
                            if (s.charAt(start) == ' ' && start > 0) {
                                characterAction = 3;
                                actionPosition = start - 1;
                            } else {
                                characterAction = 2;
                            }
                        } else {
                            characterAction = -1;
                        }
                    }

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

                    @Override
                    public void afterTextChanged(Editable s) {
                        if (ignoreOnPhoneChange) {
                            return;
                        }
                        HintEditText phoneField = (HintEditText) inputFields[FIELD_PHONE];
                        int start = phoneField.getSelectionStart();
                        String phoneChars = "0123456789";
                        String str = phoneField.getText().toString();
                        if (characterAction == 3) {
                            str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
                            start--;
                        }
                        StringBuilder builder = new StringBuilder(str.length());
                        for (int a = 0; a < str.length(); a++) {
                            String ch = str.substring(a, a + 1);
                            if (phoneChars.contains(ch)) {
                                builder.append(ch);
                            }
                        }
                        ignoreOnPhoneChange = true;
                        String hint = phoneField.getHintText();
                        if (hint != null) {
                            for (int a = 0; a < builder.length(); a++) {
                                if (a < hint.length()) {
                                    if (hint.charAt(a) == ' ') {
                                        builder.insert(a, ' ');
                                        a++;
                                        if (start == a && characterAction != 2 && characterAction != 3) {
                                            start++;
                                        }
                                    }
                                } else {
                                    builder.insert(a, ' ');
                                    if (start == a + 1 && characterAction != 2 && characterAction != 3) {
                                        start++;
                                    }
                                    break;
                                }
                            }
                        }
                        phoneField.setText(builder);
                        if (start >= 0) {
                            phoneField.setSelection(Math.min(start, phoneField.length()));
                        }
                        phoneField.onTextChange();
                        ignoreOnPhoneChange = false;
                    }
                });
            } else {
                inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
                inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
                container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));
            }
            inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
                if (i == EditorInfo.IME_ACTION_NEXT) {
                    int num = (Integer) textView.getTag();
                    while (num + 1 < inputFields.length) {
                        num++;
                        if (num != FIELD_COUNTRY && ((View) inputFields[num].getParent()).getVisibility() == View.VISIBLE) {
                            inputFields[num].requestFocus();
                            break;
                        }
                    }
                    return true;
                } else if (i == EditorInfo.IME_ACTION_DONE) {
                    doneItem.performClick();
                    return true;
                }
                return false;
            });
            if (a == FIELD_PHONE) {
                if (paymentForm.invoice.email_to_provider || paymentForm.invoice.phone_to_provider) {
                    TLRPC.User providerUser = null;
                    for (int b = 0; b < paymentForm.users.size(); b++) {
                        TLRPC.User user = paymentForm.users.get(b);
                        if (user.id == paymentForm.provider_id) {
                            providerUser = user;
                        }
                    }
                    final String providerName;
                    if (providerUser != null) {
                        providerName = ContactsController.formatName(providerUser.first_name, providerUser.last_name);
                    } else {
                        providerName = "";
                    }
                    bottomCell[1] = new TextInfoPrivacyCell(context);
                    bottomCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                    linearLayout2.addView(bottomCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    if (paymentForm.invoice.email_to_provider && paymentForm.invoice.phone_to_provider) {
                        bottomCell[1].setText(LocaleController.formatString("PaymentPhoneEmailToProvider", R.string.PaymentPhoneEmailToProvider, providerName));
                    } else if (paymentForm.invoice.email_to_provider) {
                        bottomCell[1].setText(LocaleController.formatString("PaymentEmailToProvider", R.string.PaymentEmailToProvider, providerName));
                    } else {
                        bottomCell[1].setText(LocaleController.formatString("PaymentPhoneToProvider", R.string.PaymentPhoneToProvider, providerName));
                    }
                } else {
                    sectionCell[1] = new ShadowSectionCell(context);
                    linearLayout2.addView(sectionCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                }
                checkCell1 = new TextCheckCell(context);
                checkCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                checkCell1.setTextAndCheck(LocaleController.getString("PaymentShippingSave", R.string.PaymentShippingSave), saveShippingInfo, false);
                linearLayout2.addView(checkCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                checkCell1.setOnClickListener(v -> {
                    saveShippingInfo = !saveShippingInfo;
                    checkCell1.setChecked(saveShippingInfo);
                });
                bottomCell[0] = new TextInfoPrivacyCell(context);
                bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                bottomCell[0].setText(LocaleController.getString("PaymentShippingSaveInfo", R.string.PaymentShippingSaveInfo));
                linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
        }
        if (!paymentForm.invoice.name_requested) {
            ((ViewGroup) inputFields[FIELD_NAME].getParent()).setVisibility(View.GONE);
        }
        if (!paymentForm.invoice.phone_requested) {
            ((ViewGroup) inputFields[FIELD_PHONECODE].getParent()).setVisibility(View.GONE);
        }
        if (!paymentForm.invoice.email_requested) {
            ((ViewGroup) inputFields[FIELD_EMAIL].getParent()).setVisibility(View.GONE);
        }
        if (paymentForm.invoice.phone_requested) {
            inputFields[FIELD_PHONE].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        } else if (paymentForm.invoice.email_requested) {
            inputFields[FIELD_EMAIL].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        } else if (paymentForm.invoice.name_requested) {
            inputFields[FIELD_NAME].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        } else {
            inputFields[FIELD_POSTCODE].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        }
        if (sectionCell[1] != null) {
            sectionCell[1].setVisibility(paymentForm.invoice.name_requested || paymentForm.invoice.phone_requested || paymentForm.invoice.email_requested ? View.VISIBLE : View.GONE);
        } else if (bottomCell[1] != null) {
            bottomCell[1].setVisibility(paymentForm.invoice.name_requested || paymentForm.invoice.phone_requested || paymentForm.invoice.email_requested ? View.VISIBLE : View.GONE);
        }
        headerCell[1].setVisibility(paymentForm.invoice.name_requested || paymentForm.invoice.phone_requested || paymentForm.invoice.email_requested ? View.VISIBLE : View.GONE);
        if (!paymentForm.invoice.shipping_address_requested) {
            headerCell[0].setVisibility(View.GONE);
            sectionCell[0].setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_STREET1].getParent()).setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_STREET2].getParent()).setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_CITY].getParent()).setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_STATE].getParent()).setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_COUNTRY].getParent()).setVisibility(View.GONE);
            ((ViewGroup) inputFields[FIELD_POSTCODE].getParent()).setVisibility(View.GONE);
        }
        if (paymentForm.saved_info != null && !TextUtils.isEmpty(paymentForm.saved_info.phone)) {
            fillNumber(paymentForm.saved_info.phone);
        } else {
            fillNumber(null);
        }
        if (inputFields[FIELD_PHONECODE].length() == 0 && (paymentForm.invoice.phone_requested && (paymentForm.saved_info == null || TextUtils.isEmpty(paymentForm.saved_info.phone)))) {
            String country = null;
            try {
                TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
                if (telephonyManager != null) {
                    country = telephonyManager.getSimCountryIso().toUpperCase();
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
            if (country != null) {
                String countryName = languageMap.get(country);
                if (countryName != null) {
                    int index = countriesArray.indexOf(countryName);
                    if (index != -1) {
                        inputFields[FIELD_PHONECODE].setText(countriesMap.get(countryName));
                    }
                }
            }
        }
    } else if (currentStep == 2) {
        if (paymentForm.native_params != null) {
            try {
                JSONObject jsonObject = new JSONObject(paymentForm.native_params.data);
                String googlePayKey = jsonObject.optString("google_pay_public_key");
                if (!TextUtils.isEmpty(googlePayKey)) {
                    googlePayPublicKey = googlePayKey;
                }
                googlePayCountryCode = jsonObject.optString("acquirer_bank_country");
                googlePayParameters = jsonObject.optJSONObject("gpay_parameters");
            } catch (Exception e) {
                FileLog.e(e);
            }
        }
        if (isWebView) {
            if (googlePayPublicKey != null || googlePayParameters != null) {
                initGooglePay(context);
            }
            createGooglePayButton(context);
            linearLayout2.addView(googlePayContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            webviewLoading = true;
            showEditDoneProgress(true, true);
            progressView.setVisibility(View.VISIBLE);
            doneItem.setEnabled(false);
            doneItem.getContentView().setVisibility(View.INVISIBLE);
            webView = new WebView(context) {

                @Override
                public boolean onTouchEvent(MotionEvent event) {
                    ((ViewGroup) fragmentView).requestDisallowInterceptTouchEvent(true);
                    return super.onTouchEvent(event);
                }

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            };
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setDomStorageEnabled(true);
            if (Build.VERSION.SDK_INT >= 21) {
                webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptThirdPartyCookies(webView, true);
            }
            if (Build.VERSION.SDK_INT >= 17) {
                webView.addJavascriptInterface(new TelegramWebviewProxy(), "TelegramWebviewProxy");
            }
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onLoadResource(WebView view, String url) {
                    super.onLoadResource(view, url);
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    shouldNavigateBack = !url.equals(webViewUrl);
                    return super.shouldOverrideUrlLoading(view, url);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    webviewLoading = false;
                    showEditDoneProgress(true, false);
                    updateSavePaymentField();
                }
            });
            linearLayout2.addView(webView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            sectionCell[2] = new ShadowSectionCell(context);
            linearLayout2.addView(sectionCell[2], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            checkCell1 = new TextCheckCell(context);
            checkCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            checkCell1.setTextAndCheck(LocaleController.getString("PaymentCardSavePaymentInformation", R.string.PaymentCardSavePaymentInformation), saveCardInfo, false);
            linearLayout2.addView(checkCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            checkCell1.setOnClickListener(v -> {
                saveCardInfo = !saveCardInfo;
                checkCell1.setChecked(saveCardInfo);
            });
            bottomCell[0] = new TextInfoPrivacyCell(context);
            bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            updateSavePaymentField();
            linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        } else {
            if (paymentForm.native_params != null) {
                try {
                    JSONObject jsonObject = new JSONObject(paymentForm.native_params.data);
                    try {
                        need_card_country = jsonObject.getBoolean("need_country");
                    } catch (Exception e) {
                        need_card_country = false;
                    }
                    try {
                        need_card_postcode = jsonObject.getBoolean("need_zip");
                    } catch (Exception e) {
                        need_card_postcode = false;
                    }
                    try {
                        need_card_name = jsonObject.getBoolean("need_cardholder_name");
                    } catch (Exception e) {
                        need_card_name = false;
                    }
                    if (jsonObject.has("public_token")) {
                        providerApiKey = jsonObject.getString("public_token");
                    } else {
                        try {
                            providerApiKey = jsonObject.getString("publishable_key");
                        } catch (Exception e) {
                            providerApiKey = "";
                        }
                    }
                    initGooglePay = !jsonObject.optBoolean("google_pay_hidden", false);
                } catch (Exception e) {
                    FileLog.e(e);
                }
            }
            if (initGooglePay && (!TextUtils.isEmpty(providerApiKey) && "stripe".equals(paymentForm.native_provider) || googlePayParameters != null)) {
                initGooglePay(context);
            }
            inputFields = new EditTextBoldCursor[FIELDS_COUNT_CARD];
            for (int a = 0; a < FIELDS_COUNT_CARD; a++) {
                if (a == FIELD_CARD) {
                    headerCell[0] = new HeaderCell(context);
                    headerCell[0].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    headerCell[0].setText(LocaleController.getString("PaymentCardTitle", R.string.PaymentCardTitle));
                    linearLayout2.addView(headerCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                } else if (a == FIELD_CARD_COUNTRY) {
                    headerCell[1] = new HeaderCell(context);
                    headerCell[1].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    headerCell[1].setText(LocaleController.getString("PaymentBillingAddress", R.string.PaymentBillingAddress));
                    linearLayout2.addView(headerCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                }
                boolean allowDivider = a != FIELD_CVV && a != FIELD_CARD_POSTCODE && !(a == FIELD_CARD_COUNTRY && !need_card_postcode);
                ViewGroup container = new FrameLayout(context);
                container.setClipChildren(false);
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
                View.OnTouchListener onTouchListener = null;
                inputFields[a] = new EditTextBoldCursor(context);
                inputFields[a].setTag(a);
                inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
                inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                inputFields[a].setBackgroundDrawable(null);
                inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                inputFields[a].setCursorSize(AndroidUtilities.dp(20));
                inputFields[a].setCursorWidth(1.5f);
                if (a == FIELD_CVV) {
                    InputFilter[] inputFilters = new InputFilter[1];
                    inputFilters[0] = new InputFilter.LengthFilter(3);
                    inputFields[a].setFilters(inputFilters);
                    inputFields[a].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                    inputFields[a].setTypeface(Typeface.DEFAULT);
                    inputFields[a].setTransformationMethod(PasswordTransformationMethod.getInstance());
                } else if (a == FIELD_CARD) {
                    inputFields[a].setInputType(InputType.TYPE_CLASS_PHONE);
                } else if (a == FIELD_CARD_COUNTRY) {
                    inputFields[a].setOnTouchListener((v, event) -> {
                        if (getParentActivity() == null) {
                            return false;
                        }
                        if (event.getAction() == MotionEvent.ACTION_UP) {
                            CountrySelectActivity fragment = new CountrySelectActivity(false);
                            fragment.setCountrySelectActivityDelegate((country) -> inputFields[FIELD_CARD_COUNTRY].setText(country.name));
                            presentFragment(fragment);
                        }
                        return true;
                    });
                    inputFields[a].setInputType(0);
                } else if (a == FIELD_EXPIRE_DATE) {
                    inputFields[a].setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
                } else if (a == FIELD_CARDNAME) {
                    inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_CHARACTERS);
                } else {
                    inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
                }
                inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
                switch(a) {
                    case FIELD_CARD:
                        inputFields[a].setHint(LocaleController.getString("PaymentCardNumber", R.string.PaymentCardNumber));
                        break;
                    case FIELD_CVV:
                        inputFields[a].setHint(LocaleController.getString("PaymentCardCvv", R.string.PaymentCardCvv));
                        break;
                    case FIELD_EXPIRE_DATE:
                        inputFields[a].setHint(LocaleController.getString("PaymentCardExpireDate", R.string.PaymentCardExpireDate));
                        break;
                    case FIELD_CARDNAME:
                        inputFields[a].setHint(LocaleController.getString("PaymentCardName", R.string.PaymentCardName));
                        break;
                    case FIELD_CARD_POSTCODE:
                        inputFields[a].setHint(LocaleController.getString("PaymentShippingZipPlaceholder", R.string.PaymentShippingZipPlaceholder));
                        break;
                    case FIELD_CARD_COUNTRY:
                        inputFields[a].setHint(LocaleController.getString("PaymentShippingCountry", R.string.PaymentShippingCountry));
                        break;
                }
                if (a == FIELD_CARD) {
                    inputFields[a].addTextChangedListener(new TextWatcher() {

                        public final String[] PREFIXES_15 = { "34", "37" };

                        public final String[] PREFIXES_14 = { "300", "301", "302", "303", "304", "305", "309", "36", "38", "39" };

                        public final String[] PREFIXES_16 = { "2221", "2222", "2223", "2224", "2225", "2226", "2227", "2228", "2229", "223", "224", "225", "226", "227", "228", "229", "23", "24", "25", "26", "270", "271", "2720", "50", "51", "52", "53", "54", "55", "4", "60", "62", "64", "65", "35" };

                        public static final int MAX_LENGTH_STANDARD = 16;

                        public static final int MAX_LENGTH_AMERICAN_EXPRESS = 15;

                        public static final int MAX_LENGTH_DINERS_CLUB = 14;

                        private int characterAction = -1;

                        private int actionPosition;

                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                            if (count == 0 && after == 1) {
                                characterAction = 1;
                            } else if (count == 1 && after == 0) {
                                if (s.charAt(start) == ' ' && start > 0) {
                                    characterAction = 3;
                                    actionPosition = start - 1;
                                } else {
                                    characterAction = 2;
                                }
                            } else {
                                characterAction = -1;
                            }
                        }

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

                        @Override
                        public void afterTextChanged(Editable editable) {
                            if (ignoreOnCardChange) {
                                return;
                            }
                            EditText phoneField = inputFields[FIELD_CARD];
                            int start = phoneField.getSelectionStart();
                            String phoneChars = "0123456789";
                            String str = phoneField.getText().toString();
                            if (characterAction == 3) {
                                str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
                                start--;
                            }
                            StringBuilder builder = new StringBuilder(str.length());
                            for (int a = 0; a < str.length(); a++) {
                                String ch = str.substring(a, a + 1);
                                if (phoneChars.contains(ch)) {
                                    builder.append(ch);
                                }
                            }
                            ignoreOnCardChange = true;
                            String hint = null;
                            int maxLength = 100;
                            if (builder.length() > 0) {
                                String currentString = builder.toString();
                                for (int a = 0; a < 3; a++) {
                                    String[] checkArr;
                                    String resultHint;
                                    int resultMaxLength;
                                    switch(a) {
                                        case 0:
                                            checkArr = PREFIXES_16;
                                            resultMaxLength = 16;
                                            resultHint = "xxxx xxxx xxxx xxxx";
                                            break;
                                        case 1:
                                            checkArr = PREFIXES_15;
                                            resultMaxLength = 15;
                                            resultHint = "xxxx xxxx xxxx xxx";
                                            break;
                                        case 2:
                                        default:
                                            checkArr = PREFIXES_14;
                                            resultMaxLength = 14;
                                            resultHint = "xxxx xxxx xxxx xx";
                                            break;
                                    }
                                    for (int b = 0; b < checkArr.length; b++) {
                                        String prefix = checkArr[b];
                                        if (currentString.length() <= prefix.length()) {
                                            if (prefix.startsWith(currentString)) {
                                                hint = resultHint;
                                                maxLength = resultMaxLength;
                                                break;
                                            }
                                        } else {
                                            if (currentString.startsWith(prefix)) {
                                                hint = resultHint;
                                                maxLength = resultMaxLength;
                                                break;
                                            }
                                        }
                                    }
                                    if (hint != null) {
                                        break;
                                    }
                                }
                                if (builder.length() > maxLength) {
                                    builder.setLength(maxLength);
                                }
                            }
                            if (hint != null) {
                                if (builder.length() == maxLength) {
                                    inputFields[FIELD_EXPIRE_DATE].requestFocus();
                                }
                                phoneField.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                                for (int a = 0; a < builder.length(); a++) {
                                    if (a < hint.length()) {
                                        if (hint.charAt(a) == ' ') {
                                            builder.insert(a, ' ');
                                            a++;
                                            if (start == a && characterAction != 2 && characterAction != 3) {
                                                start++;
                                            }
                                        }
                                    } else {
                                        builder.insert(a, ' ');
                                        if (start == a + 1 && characterAction != 2 && characterAction != 3) {
                                            start++;
                                        }
                                        break;
                                    }
                                }
                            } else {
                                phoneField.setTextColor(builder.length() > 0 ? Theme.getColor(Theme.key_windowBackgroundWhiteRedText4) : Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                            }
                            if (!builder.toString().equals(editable.toString())) {
                                editable.replace(0, editable.length(), builder);
                            }
                            if (start >= 0) {
                                phoneField.setSelection(Math.min(start, phoneField.length()));
                            }
                            ignoreOnCardChange = false;
                        }
                    });
                } else if (a == FIELD_EXPIRE_DATE) {
                    inputFields[a].addTextChangedListener(new TextWatcher() {

                        private int characterAction = -1;

                        private boolean isYear;

                        private int actionPosition;

                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                            if (count == 0 && after == 1) {
                                isYear = TextUtils.indexOf(inputFields[FIELD_EXPIRE_DATE].getText(), '/') != -1;
                                characterAction = 1;
                            } else if (count == 1 && after == 0) {
                                if (s.charAt(start) == '/' && start > 0) {
                                    isYear = false;
                                    characterAction = 3;
                                    actionPosition = start - 1;
                                } else {
                                    characterAction = 2;
                                }
                            } else {
                                characterAction = -1;
                            }
                        }

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

                        @Override
                        public void afterTextChanged(Editable s) {
                            if (ignoreOnCardChange) {
                                return;
                            }
                            EditText phoneField = inputFields[FIELD_EXPIRE_DATE];
                            int start = phoneField.getSelectionStart();
                            String phoneChars = "0123456789";
                            String str = phoneField.getText().toString();
                            if (characterAction == 3) {
                                str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
                                start--;
                            }
                            StringBuilder builder = new StringBuilder(str.length());
                            for (int a = 0; a < str.length(); a++) {
                                String ch = str.substring(a, a + 1);
                                if (phoneChars.contains(ch)) {
                                    builder.append(ch);
                                }
                            }
                            ignoreOnCardChange = true;
                            inputFields[FIELD_EXPIRE_DATE].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                            if (builder.length() > 4) {
                                builder.setLength(4);
                            }
                            if (builder.length() < 2) {
                                isYear = false;
                            }
                            boolean isError = false;
                            if (isYear) {
                                String[] args = new String[builder.length() > 2 ? 2 : 1];
                                args[0] = builder.substring(0, 2);
                                if (args.length == 2) {
                                    args[1] = builder.substring(2);
                                }
                                if (builder.length() == 4 && args.length == 2) {
                                    int month = Utilities.parseInt(args[0]);
                                    int year = Utilities.parseInt(args[1]) + 2000;
                                    Calendar rightNow = Calendar.getInstance();
                                    int currentYear = rightNow.get(Calendar.YEAR);
                                    int currentMonth = rightNow.get(Calendar.MONTH) + 1;
                                    if (year < currentYear || year == currentYear && month < currentMonth) {
                                        inputFields[FIELD_EXPIRE_DATE].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                                        isError = true;
                                    }
                                } else {
                                    int value = Utilities.parseInt(args[0]);
                                    if (value > 12 || value == 0) {
                                        inputFields[FIELD_EXPIRE_DATE].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                                        isError = true;
                                    }
                                }
                            } else {
                                if (builder.length() == 1) {
                                    int value = Utilities.parseInt(builder.toString());
                                    if (value != 1 && value != 0) {
                                        builder.insert(0, "0");
                                        start++;
                                    }
                                } else if (builder.length() == 2) {
                                    int value = Utilities.parseInt(builder.toString());
                                    if (value > 12 || value == 0) {
                                        inputFields[FIELD_EXPIRE_DATE].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText4));
                                        isError = true;
                                    }
                                    start++;
                                }
                            }
                            if (!isError && builder.length() == 4) {
                                inputFields[need_card_name ? FIELD_CARDNAME : FIELD_CVV].requestFocus();
                            }
                            if (builder.length() == 2) {
                                builder.append('/');
                                start++;
                            } else if (builder.length() > 2 && builder.charAt(2) != '/') {
                                builder.insert(2, '/');
                                start++;
                            }
                            phoneField.setText(builder);
                            if (start >= 0) {
                                phoneField.setSelection(Math.min(start, phoneField.length()));
                            }
                            ignoreOnCardChange = false;
                        }
                    });
                }
                inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
                inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
                container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));
                inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
                    if (i == EditorInfo.IME_ACTION_NEXT) {
                        int num = (Integer) textView.getTag();
                        while (num + 1 < inputFields.length) {
                            num++;
                            if (num == FIELD_CARD_COUNTRY) {
                                num++;
                            }
                            if (((View) inputFields[num].getParent()).getVisibility() == View.VISIBLE) {
                                inputFields[num].requestFocus();
                                break;
                            }
                        }
                        return true;
                    } else if (i == EditorInfo.IME_ACTION_DONE) {
                        doneItem.performClick();
                        return true;
                    }
                    return false;
                });
                if (a == FIELD_CVV) {
                    sectionCell[0] = new ShadowSectionCell(context);
                    linearLayout2.addView(sectionCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                } else if (a == FIELD_CARD_POSTCODE) {
                    sectionCell[2] = new ShadowSectionCell(context);
                    linearLayout2.addView(sectionCell[2], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    checkCell1 = new TextCheckCell(context);
                    checkCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    checkCell1.setTextAndCheck(LocaleController.getString("PaymentCardSavePaymentInformation", R.string.PaymentCardSavePaymentInformation), saveCardInfo, false);
                    linearLayout2.addView(checkCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                    checkCell1.setOnClickListener(v -> {
                        saveCardInfo = !saveCardInfo;
                        checkCell1.setChecked(saveCardInfo);
                    });
                    bottomCell[0] = new TextInfoPrivacyCell(context);
                    bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                    updateSavePaymentField();
                    linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                } else if (a == FIELD_CARD) {
                    createGooglePayButton(context);
                    container.addView(googlePayContainer, LayoutHelper.createFrame(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, Gravity.CENTER_VERTICAL | (LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT), 0, 0, 4, 0));
                }
                if (allowDivider) {
                    View 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);
                        }
                    };
                    divider.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    dividers.add(divider);
                    container.addView(divider, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.LEFT | Gravity.BOTTOM));
                }
                if (a == FIELD_CARD_COUNTRY && !need_card_country || a == FIELD_CARD_POSTCODE && !need_card_postcode || a == FIELD_CARDNAME && !need_card_name) {
                    container.setVisibility(View.GONE);
                }
            }
            if (!need_card_country && !need_card_postcode) {
                headerCell[1].setVisibility(View.GONE);
                sectionCell[0].setVisibility(View.GONE);
            }
            if (need_card_postcode) {
                inputFields[FIELD_CARD_POSTCODE].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            } else {
                inputFields[FIELD_CVV].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
        }
    } else if (currentStep == 1) {
        int count = requestedInfo.shipping_options.size();
        radioCells = new RadioCell[count];
        for (int a = 0; a < count; a++) {
            TLRPC.TL_shippingOption shippingOption = requestedInfo.shipping_options.get(a);
            radioCells[a] = new RadioCell(context);
            radioCells[a].setTag(a);
            radioCells[a].setBackgroundDrawable(Theme.getSelectorDrawable(true));
            radioCells[a].setText(String.format("%s - %s", getTotalPriceString(shippingOption.prices), shippingOption.title), a == 0, a != count - 1);
            radioCells[a].setOnClickListener(v -> {
                int num = (Integer) v.getTag();
                for (int a1 = 0; a1 < radioCells.length; a1++) {
                    radioCells[a1].setChecked(num == a1, true);
                }
            });
            linearLayout2.addView(radioCells[a]);
        }
        bottomCell[0] = new TextInfoPrivacyCell(context);
        bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    } else if (currentStep == 3) {
        inputFields = new EditTextBoldCursor[FIELDS_COUNT_SAVEDCARD];
        for (int a = 0; a < FIELDS_COUNT_SAVEDCARD; a++) {
            if (a == FIELD_SAVEDCARD) {
                headerCell[0] = new HeaderCell(context);
                headerCell[0].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                headerCell[0].setText(LocaleController.getString("PaymentCardTitle", R.string.PaymentCardTitle));
                linearLayout2.addView(headerCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
            ViewGroup container = new FrameLayout(context);
            container.setClipChildren(false);
            linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            boolean allowDivider = a != FIELD_SAVEDPASSWORD;
            if (allowDivider) {
                if (a == FIELD_EMAIL && !paymentForm.invoice.phone_requested) {
                    allowDivider = false;
                } else if (a == FIELD_NAME && !paymentForm.invoice.phone_requested && !paymentForm.invoice.email_requested) {
                    allowDivider = false;
                }
            }
            if (allowDivider) {
                View 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);
                    }
                };
                divider.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                dividers.add(divider);
                container.addView(divider, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.LEFT | Gravity.BOTTOM));
            }
            inputFields[a] = new EditTextBoldCursor(context);
            inputFields[a].setTag(a);
            inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setBackgroundDrawable(null);
            inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setCursorSize(AndroidUtilities.dp(20));
            inputFields[a].setCursorWidth(1.5f);
            if (a == FIELD_SAVEDCARD) {
                inputFields[a].setOnTouchListener((v, event) -> true);
                inputFields[a].setInputType(0);
            } else {
                inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                inputFields[a].setTypeface(Typeface.DEFAULT);
            }
            inputFields[a].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            switch(a) {
                case FIELD_SAVEDCARD:
                    inputFields[a].setText(paymentForm.saved_credentials.title);
                    break;
                case FIELD_SAVEDPASSWORD:
                    inputFields[a].setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
                    inputFields[a].requestFocus();
                    break;
            }
            inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
            inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
            container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));
            inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
                if (i == EditorInfo.IME_ACTION_DONE) {
                    doneItem.performClick();
                    return true;
                }
                return false;
            });
            if (a == FIELD_SAVEDPASSWORD) {
                bottomCell[0] = new TextInfoPrivacyCell(context);
                bottomCell[0].setText(LocaleController.formatString("PaymentConfirmationMessage", R.string.PaymentConfirmationMessage, paymentForm.saved_credentials.title));
                bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                settingsCell[0] = new TextSettingsCell(context);
                settingsCell[0].setBackgroundDrawable(Theme.getSelectorDrawable(true));
                settingsCell[0].setText(LocaleController.getString("PaymentConfirmationNewCard", R.string.PaymentConfirmationNewCard), false);
                linearLayout2.addView(settingsCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
                settingsCell[0].setOnClickListener(v -> {
                    passwordOk = false;
                    goToNextStep();
                });
                bottomCell[1] = new TextInfoPrivacyCell(context);
                bottomCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                linearLayout2.addView(bottomCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
        }
    } else if (currentStep == 4 || currentStep == 5) {
        paymentInfoCell = new PaymentInfoCell(context);
        paymentInfoCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        if (messageObject != null) {
            paymentInfoCell.setInvoice((TLRPC.TL_messageMediaInvoice) messageObject.messageOwner.media, currentBotName);
        } else if (paymentReceipt != null) {
            paymentInfoCell.setReceipt(paymentReceipt, currentBotName);
        }
        linearLayout2.addView(paymentInfoCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        sectionCell[0] = new ShadowSectionCell(context);
        linearLayout2.addView(sectionCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        prices = new ArrayList<>(paymentForm.invoice.prices);
        if (shippingOption != null) {
            prices.addAll(shippingOption.prices);
        }
        totalPrice = new String[1];
        for (int a = 0; a < prices.size(); a++) {
            TLRPC.TL_labeledPrice price = prices.get(a);
            TextPriceCell priceCell = new TextPriceCell(context);
            priceCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            priceCell.setTextAndValue(price.label, LocaleController.getInstance().formatCurrencyString(price.amount, paymentForm.invoice.currency), false);
            linearLayout2.addView(priceCell);
        }
        if (currentStep == 5 && tipAmount != null) {
            TextPriceCell priceCell = new TextPriceCell(context);
            priceCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            priceCell.setTextAndValue(LocaleController.getString("PaymentTip", R.string.PaymentTip), LocaleController.getInstance().formatCurrencyString(tipAmount, paymentForm.invoice.currency), false);
            linearLayout2.addView(priceCell);
        }
        totalCell = new TextPriceCell(context);
        totalCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        totalPrice[0] = getTotalPriceString(prices);
        totalCell.setTextAndValue(LocaleController.getString("PaymentTransactionTotal", R.string.PaymentTransactionTotal), totalPrice[0], true);
        if (currentStep == 4 && (paymentForm.invoice.flags & 256) != 0) {
            ViewGroup container = new FrameLayout(context);
            container.setClipChildren(false);
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, paymentForm.invoice.suggested_tip_amounts.isEmpty() ? 40 : 78));
            container.setOnClickListener(v -> {
                inputFields[0].requestFocus();
                AndroidUtilities.showKeyboard(inputFields[0]);
            });
            TextPriceCell cell = new TextPriceCell(context);
            cell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            cell.setTextAndValue(LocaleController.getString("PaymentTipOptional", R.string.PaymentTipOptional), "", false);
            container.addView(cell);
            inputFields = new EditTextBoldCursor[1];
            inputFields[0] = new EditTextBoldCursor(context);
            inputFields[0].setTag(0);
            inputFields[0].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            inputFields[0].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
            inputFields[0].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
            inputFields[0].setBackgroundDrawable(null);
            inputFields[0].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[0].setCursorSize(AndroidUtilities.dp(20));
            inputFields[0].setCursorWidth(1.5f);
            inputFields[0].setInputType(InputType.TYPE_CLASS_PHONE);
            inputFields[0].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            inputFields[0].setHint(LocaleController.getInstance().formatCurrencyString(0, paymentForm.invoice.currency));
            inputFields[0].setPadding(0, 0, 0, AndroidUtilities.dp(6));
            inputFields[0].setGravity(LocaleController.isRTL ? Gravity.LEFT : Gravity.RIGHT);
            container.addView(inputFields[0], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 9, 21, 1));
            inputFields[0].addTextChangedListener(new TextWatcher() {

                private boolean anyBefore;

                private String overrideText;

                private boolean isDeletedChar;

                private int beforeTextLength;

                private int enteredCharacterStart;

                private boolean lastDotEntered;

                char[] commas = new char[] { ',', '.', '٫', '、', '\u2E41', '︐', '︑', '﹐', '﹑', ',', '、', 'ʻ' };

                private int indexOfComma(String text) {
                    for (int a = 0; a < commas.length; a++) {
                        int idx = text.indexOf(commas[a]);
                        if (idx >= 0) {
                            return idx;
                        }
                    }
                    return -1;
                }

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    if (ignoreOnTextChange) {
                        return;
                    }
                    anyBefore = !TextUtils.isEmpty(s);
                    overrideText = null;
                    beforeTextLength = s == null ? 0 : s.length();
                    enteredCharacterStart = start;
                    if (isDeletedChar = (count == 1 && after == 0)) {
                        String fixed = LocaleController.fixNumbers(s);
                        char actionCh = fixed.charAt(start);
                        int idx = indexOfComma(fixed);
                        String reminderStr = idx >= 0 ? fixed.substring(idx + 1) : "";
                        long reminder = Utilities.parseLong(PhoneFormat.stripExceptNumbers(reminderStr));
                        if ((actionCh < '0' || actionCh > '9') && (reminderStr.length() == 0 || reminder != 0)) {
                            while (--start >= 0) {
                                actionCh = fixed.charAt(start);
                                if (actionCh >= '0' && actionCh <= '9') {
                                    overrideText = fixed.substring(0, start) + fixed.substring(start + 1);
                                    break;
                                }
                            }
                        } else if (idx > 0 && start > idx && reminder == 0) {
                            overrideText = fixed.substring(0, idx - 1);
                        }
                    }
                }

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

                @Override
                public void afterTextChanged(Editable s) {
                    if (ignoreOnTextChange) {
                        return;
                    }
                    long oldAmount = tipAmount != null ? tipAmount : 0;
                    String text;
                    if (overrideText != null) {
                        text = overrideText;
                    } else {
                        text = LocaleController.fixNumbers(s.toString());
                    }
                    int idx = indexOfComma(text);
                    boolean dotEntered = idx >= 0;
                    int exp = LocaleController.getCurrencyExpDivider(paymentForm.invoice.currency);
                    String wholeStr = idx >= 0 ? text.substring(0, idx) : text;
                    String reminderStr = idx >= 0 ? text.substring(idx + 1) : "";
                    long whole = Utilities.parseLong(PhoneFormat.stripExceptNumbers(wholeStr)) * exp;
                    long reminder = Utilities.parseLong(PhoneFormat.stripExceptNumbers(reminderStr));
                    reminderStr = "" + reminder;
                    String expStr = "" + (exp - 1);
                    if (idx > 0 && reminderStr.length() > expStr.length()) {
                        if (enteredCharacterStart - idx < reminderStr.length()) {
                            reminderStr = reminderStr.substring(0, expStr.length());
                        } else {
                            reminderStr = reminderStr.substring(reminderStr.length() - expStr.length());
                        }
                        reminder = Utilities.parseLong(reminderStr);
                    }
                    tipAmount = whole + reminder;
                    if (paymentForm.invoice.max_tip_amount != 0 && tipAmount > paymentForm.invoice.max_tip_amount) {
                        tipAmount = paymentForm.invoice.max_tip_amount;
                    }
                    int start = inputFields[0].getSelectionStart();
                    ignoreOnTextChange = true;
                    String newText;
                    if (tipAmount == 0) {
                        inputFields[0].setText(newText = "");
                    } else {
                        inputFields[0].setText(newText = LocaleController.getInstance().formatCurrencyString(tipAmount, false, dotEntered, true, paymentForm.invoice.currency));
                    }
                    if (oldAmount < tipAmount && oldAmount != 0 && anyBefore && start >= 0) {
                        inputFields[0].setSelection(Math.min(start, inputFields[0].length()));
                    } else if (!isDeletedChar || beforeTextLength == inputFields[0].length()) {
                        if (!lastDotEntered && dotEntered && idx >= 0) {
                            idx = indexOfComma(newText);
                            if (idx > 0) {
                                inputFields[0].setSelection(idx + 1);
                            } else {
                                inputFields[0].setSelection(inputFields[0].length());
                            }
                        } else {
                            inputFields[0].setSelection(inputFields[0].length());
                        }
                    } else {
                        inputFields[0].setSelection(Math.max(0, Math.min(start, inputFields[0].length())));
                    }
                    lastDotEntered = dotEntered;
                    updateTotalPrice();
                    overrideText = null;
                    ignoreOnTextChange = false;
                }
            });
            inputFields[0].setOnEditorActionListener((textView, i, keyEvent) -> {
                if (i == EditorInfo.IME_ACTION_DONE) {
                    AndroidUtilities.hideKeyboard(textView);
                    return true;
                }
                return false;
            });
            inputFields[0].requestFocus();
            if (!paymentForm.invoice.suggested_tip_amounts.isEmpty()) {
                HorizontalScrollView scrollView = new HorizontalScrollView(context);
                scrollView.setHorizontalScrollBarEnabled(false);
                scrollView.setVerticalScrollBarEnabled(false);
                scrollView.setClipToPadding(false);
                scrollView.setPadding(AndroidUtilities.dp(21), 0, AndroidUtilities.dp(21), 0);
                scrollView.setFillViewport(true);
                container.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 30, Gravity.LEFT | Gravity.TOP, 0, 44, 0, 0));
                int[] maxTextWidth = new int[1];
                int[] textWidths = new int[1];
                int N = paymentForm.invoice.suggested_tip_amounts.size();
                tipLayout = new LinearLayout(context) {

                    boolean ignoreLayout;

                    @Override
                    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                        int availableSize = MeasureSpec.getSize(widthMeasureSpec);
                        ignoreLayout = true;
                        int gaps = AndroidUtilities.dp(9) * (N - 1);
                        if (maxTextWidth[0] * N + gaps <= availableSize) {
                            setWeightSum(1.0f);
                            for (int a = 0, N2 = getChildCount(); a < N2; a++) {
                                getChildAt(a).getLayoutParams().width = 0;
                                ((LayoutParams) getChildAt(a).getLayoutParams()).weight = 1.0f / N2;
                            }
                        } else if (textWidths[0] + gaps <= availableSize) {
                            setWeightSum(1.0f);
                            availableSize -= gaps;
                            float extraWeight = 1.0f;
                            for (int a = 0, N2 = getChildCount(); a < N2; a++) {
                                View child = getChildAt(a);
                                LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
                                layoutParams.width = 0;
                                int width = (Integer) child.getTag(R.id.width_tag);
                                layoutParams.weight = width / (float) availableSize;
                                extraWeight -= layoutParams.weight;
                            }
                            extraWeight /= (N - 1);
                            if (extraWeight > 0) {
                                for (int a = 0, N2 = getChildCount(); a < N2; a++) {
                                    View child = getChildAt(a);
                                    LayoutParams layoutParams = (LayoutParams) child.getLayoutParams();
                                    int width = (Integer) child.getTag(R.id.width_tag);
                                    if (width != maxTextWidth[0]) {
                                        layoutParams.weight += extraWeight;
                                    }
                                }
                            }
                        } else {
                            setWeightSum(0.0f);
                            for (int a = 0, N2 = getChildCount(); a < N2; a++) {
                                getChildAt(a).getLayoutParams().width = LayoutHelper.WRAP_CONTENT;
                                ((LayoutParams) getChildAt(a).getLayoutParams()).weight = 0.0f;
                            }
                        }
                        ignoreLayout = false;
                        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                    }

                    @Override
                    public void requestLayout() {
                        if (ignoreLayout) {
                            return;
                        }
                        super.requestLayout();
                    }
                };
                tipLayout.setOrientation(LinearLayout.HORIZONTAL);
                scrollView.addView(tipLayout, LayoutHelper.createScroll(LayoutHelper.MATCH_PARENT, 30, Gravity.LEFT | Gravity.TOP));
                int color = Theme.getColor(Theme.key_contacts_inviteBackground);
                for (int a = 0; a < N; a++) {
                    long amount;
                    if (LocaleController.isRTL) {
                        amount = paymentForm.invoice.suggested_tip_amounts.get(N - a - 1);
                    } else {
                        amount = paymentForm.invoice.suggested_tip_amounts.get(a);
                    }
                    String text = LocaleController.getInstance().formatCurrencyString(amount, paymentForm.invoice.currency);
                    TextView valueTextView = new TextView(context);
                    valueTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
                    valueTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                    valueTextView.setLines(1);
                    valueTextView.setTag(amount);
                    valueTextView.setMaxLines(1);
                    valueTextView.setText(text);
                    valueTextView.setPadding(AndroidUtilities.dp(15), 0, AndroidUtilities.dp(15), 0);
                    valueTextView.setTextColor(Theme.getColor(Theme.key_chats_secretName));
                    valueTextView.setBackground(Theme.createRoundRectDrawable(AndroidUtilities.dp(15), color & 0x1fffffff));
                    valueTextView.setSingleLine(true);
                    valueTextView.setGravity(Gravity.CENTER);
                    tipLayout.addView(valueTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.MATCH_PARENT, Gravity.CENTER_VERTICAL | Gravity.LEFT, 0, 0, a != N - 1 ? 9 : 0, 0));
                    valueTextView.setOnClickListener(v -> {
                        long amoumt = (Long) valueTextView.getTag();
                        if (tipAmount != null && amoumt == tipAmount) {
                            ignoreOnTextChange = true;
                            inputFields[0].setText("");
                            ignoreOnTextChange = false;
                            tipAmount = 0L;
                            updateTotalPrice();
                        } else {
                            inputFields[0].setText(LocaleController.getInstance().formatCurrencyString(amount, false, true, true, paymentForm.invoice.currency));
                        }
                        inputFields[0].setSelection(inputFields[0].length());
                    });
                    int width = (int) Math.ceil(valueTextView.getPaint().measureText(text)) + AndroidUtilities.dp(30);
                    valueTextView.setTag(R.id.width_tag, width);
                    maxTextWidth[0] = Math.max(maxTextWidth[0], width);
                    textWidths[0] += width;
                }
            }
        }
        linearLayout2.addView(totalCell);
        sectionCell[2] = new ShadowSectionCell(context);
        sectionCell[2].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout2.addView(sectionCell[2], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        detailSettingsCell[0] = new TextDetailSettingsCell(context);
        detailSettingsCell[0].setBackgroundDrawable(Theme.getSelectorDrawable(true));
        detailSettingsCell[0].setTextAndValueAndIcon(cardName != null && cardName.length() > 1 ? cardName.substring(0, 1).toUpperCase() + cardName.substring(1) : cardName, LocaleController.getString("PaymentCheckoutMethod", R.string.PaymentCheckoutMethod), R.drawable.payment_card, true);
        linearLayout2.addView(detailSettingsCell[0]);
        if (currentStep == 4) {
            detailSettingsCell[0].setOnClickListener(v -> {
                if (getParentActivity() == null) {
                    return;
                }
                BottomSheet.Builder builder = new BottomSheet.Builder(getParentActivity());
                builder.setTitle(LocaleController.getString("PaymentCheckoutMethod", R.string.PaymentCheckoutMethod), true);
                builder.setItems(new CharSequence[] { cardName, LocaleController.getString("PaymentCheckoutMethodNewCard", R.string.PaymentCheckoutMethodNewCard) }, new int[] { R.drawable.payment_card, R.drawable.msg_addbot }, (dialog, which) -> {
                    if (which == 1) {
                        PaymentFormActivity activity = new PaymentFormActivity(paymentForm, messageObject, 2, requestedInfo, shippingOption, tipAmount, null, cardName, validateRequest, saveCardInfo, null, parentFragment);
                        activity.setDelegate(new PaymentFormActivityDelegate() {

                            @Override
                            public boolean didSelectNewCard(String tokenJson, String card, boolean saveCard, TLRPC.TL_inputPaymentCredentialsGooglePay googlePay) {
                                paymentForm.saved_credentials = null;
                                paymentJson = tokenJson;
                                saveCardInfo = saveCard;
                                cardName = card;
                                googlePayCredentials = googlePay;
                                detailSettingsCell[0].setTextAndValue(cardName, LocaleController.getString("PaymentCheckoutMethod", R.string.PaymentCheckoutMethod), true);
                                return false;
                            }
                        });
                        presentFragment(activity);
                    }
                });
                showDialog(builder.create());
            });
        }
        TLRPC.User providerUser = null;
        for (int a = 0; a < paymentForm.users.size(); a++) {
            TLRPC.User user = paymentForm.users.get(a);
            if (user.id == paymentForm.provider_id) {
                providerUser = user;
            }
        }
        final String providerName;
        if (providerUser != null) {
            detailSettingsCell[1] = new TextDetailSettingsCell(context);
            detailSettingsCell[1].setBackgroundDrawable(Theme.getSelectorDrawable(true));
            detailSettingsCell[1].setTextAndValueAndIcon(providerName = ContactsController.formatName(providerUser.first_name, providerUser.last_name), LocaleController.getString("PaymentCheckoutProvider", R.string.PaymentCheckoutProvider), R.drawable.payment_provider, validateRequest != null && (validateRequest.info.shipping_address != null || shippingOption != null));
            linearLayout2.addView(detailSettingsCell[1]);
        } else {
            providerName = "";
        }
        if (validateRequest != null) {
            if (validateRequest.info.shipping_address != null) {
                detailSettingsCell[2] = new TextDetailSettingsCell(context);
                linearLayout2.addView(detailSettingsCell[2]);
                if (currentStep == 4) {
                    detailSettingsCell[2].setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    detailSettingsCell[2].setOnClickListener(v -> {
                        PaymentFormActivity activity = new PaymentFormActivity(paymentForm, messageObject, 0, requestedInfo, shippingOption, tipAmount, null, cardName, validateRequest, saveCardInfo, null, parentFragment);
                        activity.setDelegate(new PaymentFormActivityDelegate() {

                            @Override
                            public void didSelectNewAddress(TLRPC.TL_payments_validateRequestedInfo validateRequested) {
                                validateRequest = validateRequested;
                                setAddressFields();
                            }
                        });
                        presentFragment(activity);
                    });
                } else {
                    detailSettingsCell[2].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                }
            }
            if (validateRequest.info.name != null) {
                detailSettingsCell[3] = new TextDetailSettingsCell(context);
                linearLayout2.addView(detailSettingsCell[3]);
                if (currentStep == 4) {
                    detailSettingsCell[3].setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    detailSettingsCell[3].setOnClickListener(v -> {
                        PaymentFormActivity activity = new PaymentFormActivity(paymentForm, messageObject, 0, requestedInfo, shippingOption, tipAmount, null, cardName, validateRequest, saveCardInfo, null, parentFragment);
                        activity.setDelegate(new PaymentFormActivityDelegate() {

                            @Override
                            public void didSelectNewAddress(TLRPC.TL_payments_validateRequestedInfo validateRequested) {
                                validateRequest = validateRequested;
                                setAddressFields();
                            }
                        });
                        presentFragment(activity);
                    });
                } else {
                    detailSettingsCell[3].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                }
            }
            if (validateRequest.info.phone != null) {
                detailSettingsCell[4] = new TextDetailSettingsCell(context);
                linearLayout2.addView(detailSettingsCell[4]);
                if (currentStep == 4) {
                    detailSettingsCell[4].setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    detailSettingsCell[4].setOnClickListener(v -> {
                        PaymentFormActivity activity = new PaymentFormActivity(paymentForm, messageObject, 0, requestedInfo, shippingOption, tipAmount, null, cardName, validateRequest, saveCardInfo, null, parentFragment);
                        activity.setDelegate(new PaymentFormActivityDelegate() {

                            @Override
                            public void didSelectNewAddress(TLRPC.TL_payments_validateRequestedInfo validateRequested) {
                                validateRequest = validateRequested;
                                setAddressFields();
                            }
                        });
                        presentFragment(activity);
                    });
                } else {
                    detailSettingsCell[4].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                }
            }
            if (validateRequest.info.email != null) {
                detailSettingsCell[5] = new TextDetailSettingsCell(context);
                linearLayout2.addView(detailSettingsCell[5]);
                if (currentStep == 4) {
                    detailSettingsCell[5].setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    detailSettingsCell[5].setOnClickListener(v -> {
                        PaymentFormActivity activity = new PaymentFormActivity(paymentForm, messageObject, 0, requestedInfo, shippingOption, tipAmount, null, cardName, validateRequest, saveCardInfo, null, parentFragment);
                        activity.setDelegate(new PaymentFormActivityDelegate() {

                            @Override
                            public void didSelectNewAddress(TLRPC.TL_payments_validateRequestedInfo validateRequested) {
                                validateRequest = validateRequested;
                                setAddressFields();
                            }
                        });
                        presentFragment(activity);
                    });
                } else {
                    detailSettingsCell[5].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                }
            }
            if (shippingOption != null) {
                detailSettingsCell[6] = new TextDetailSettingsCell(context);
                detailSettingsCell[6].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                detailSettingsCell[6].setTextAndValueAndIcon(shippingOption.title, LocaleController.getString("PaymentCheckoutShippingMethod", R.string.PaymentCheckoutShippingMethod), R.drawable.payment_delivery, false);
                linearLayout2.addView(detailSettingsCell[6]);
            }
            setAddressFields();
        }
        if (currentStep == 4) {
            bottomLayout = new FrameLayout(context);
            if (Build.VERSION.SDK_INT >= 21) {
                bottomLayout.setBackgroundDrawable(Theme.getSelectorDrawable(Theme.getColor(Theme.key_listSelector), Theme.key_contacts_inviteBackground));
            } else {
                bottomLayout.setBackgroundColor(Theme.getColor(Theme.key_contacts_inviteBackground));
            }
            frameLayout.addView(bottomLayout, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 48, Gravity.BOTTOM));
            bottomLayout.setOnClickListener(v -> {
                if (botUser != null && !botUser.verified) {
                    String botKey = "payment_warning_" + botUser.id;
                    SharedPreferences preferences = MessagesController.getNotificationsSettings(currentAccount);
                    if (!preferences.getBoolean(botKey, false)) {
                        preferences.edit().putBoolean(botKey, true).commit();
                        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                        builder.setTitle(LocaleController.getString("PaymentWarning", R.string.PaymentWarning));
                        builder.setMessage(LocaleController.formatString("PaymentWarningText", R.string.PaymentWarningText, currentBotName, providerName));
                        builder.setPositiveButton(LocaleController.getString("Continue", R.string.Continue), (dialogInterface, i) -> showPayAlert(totalPrice[0]));
                        showDialog(builder.create());
                    } else {
                        showPayAlert(totalPrice[0]);
                    }
                } else {
                    showPayAlert(totalPrice[0]);
                }
            });
            payTextView = new TextView(context);
            payTextView.setTextColor(Theme.getColor(Theme.key_contacts_inviteText));
            payTextView.setText(LocaleController.formatString("PaymentCheckoutPay", R.string.PaymentCheckoutPay, totalPrice[0]));
            payTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 14);
            payTextView.setGravity(Gravity.CENTER);
            payTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            bottomLayout.addView(payTextView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            progressViewButton = new ContextProgressView(context, 0);
            progressViewButton.setVisibility(View.INVISIBLE);
            int color = Theme.getColor(Theme.key_contacts_inviteText);
            progressViewButton.setColors(color & 0x2fffffff, color);
            bottomLayout.addView(progressViewButton, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            doneItem.setEnabled(false);
            doneItem.getContentView().setVisibility(View.INVISIBLE);
            webView = new WebView(context) {

                @Override
                public boolean onTouchEvent(MotionEvent event) {
                    getParent().requestDisallowInterceptTouchEvent(true);
                    return super.onTouchEvent(event);
                }
            };
            webView.setBackgroundColor(0xffffffff);
            webView.getSettings().setJavaScriptEnabled(true);
            webView.getSettings().setDomStorageEnabled(true);
            if (Build.VERSION.SDK_INT >= 21) {
                webView.getSettings().setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptThirdPartyCookies(webView, true);
            }
            webView.setWebViewClient(new WebViewClient() {

                @Override
                public void onLoadResource(WebView view, String url) {
                    try {
                        Uri uri = Uri.parse(url);
                        if ("t.me".equals(uri.getHost())) {
                            goToNextStep();
                            return;
                        }
                    } catch (Exception ignore) {
                    }
                    super.onLoadResource(view, url);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    super.onPageFinished(view, url);
                    webviewLoading = false;
                    showEditDoneProgress(true, false);
                    updateSavePaymentField();
                }

                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    try {
                        Uri uri = Uri.parse(url);
                        if ("t.me".equals(uri.getHost())) {
                            goToNextStep();
                            return true;
                        }
                    } catch (Exception ignore) {
                    }
                    return false;
                }
            });
            frameLayout.addView(webView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
            webView.setVisibility(View.GONE);
        }
        sectionCell[1] = new ShadowSectionCell(context);
        sectionCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout2.addView(sectionCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    } else if (currentStep == 6) {
        codeFieldCell = new EditTextSettingsCell(context);
        codeFieldCell.setTextAndHint("", LocaleController.getString("PasswordCode", R.string.PasswordCode), false);
        codeFieldCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        EditTextBoldCursor editText = codeFieldCell.getTextView();
        editText.setInputType(InputType.TYPE_CLASS_PHONE);
        editText.setImeOptions(EditorInfo.IME_ACTION_DONE);
        editText.setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_DONE) {
                sendSavePassword(false);
                return true;
            }
            return false;
        });
        editText.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 (emailCodeLength != 0 && s.length() == emailCodeLength) {
                    sendSavePassword(false);
                }
            }
        });
        linearLayout2.addView(codeFieldCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        bottomCell[2] = new TextInfoPrivacyCell(context);
        bottomCell[2].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        linearLayout2.addView(bottomCell[2], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        settingsCell[1] = new TextSettingsCell(context);
        settingsCell[1].setBackgroundDrawable(Theme.getSelectorDrawable(true));
        settingsCell[1].setTag(Theme.key_windowBackgroundWhiteBlackText);
        settingsCell[1].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        settingsCell[1].setText(LocaleController.getString("ResendCode", R.string.ResendCode), true);
        linearLayout2.addView(settingsCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        settingsCell[1].setOnClickListener(v -> {
            TLRPC.TL_account_resendPasswordEmail req = new TLRPC.TL_account_resendPasswordEmail();
            ConnectionsManager.getInstance(currentAccount).sendRequest(req, (response, error) -> {
            });
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(LocaleController.getString("ResendCodeInfo", R.string.ResendCodeInfo));
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
            showDialog(builder.create());
        });
        settingsCell[0] = new TextSettingsCell(context);
        settingsCell[0].setBackgroundDrawable(Theme.getSelectorDrawable(true));
        settingsCell[0].setTag(Theme.key_windowBackgroundWhiteRedText3);
        settingsCell[0].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
        settingsCell[0].setText(LocaleController.getString("AbortPassword", R.string.AbortPassword), false);
        linearLayout2.addView(settingsCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        settingsCell[0].setOnClickListener(v -> {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            String text = LocaleController.getString("TurnPasswordOffQuestion", R.string.TurnPasswordOffQuestion);
            if (currentPassword.has_secure_values) {
                text += "\n\n" + LocaleController.getString("TurnPasswordOffPassport", R.string.TurnPasswordOffPassport);
            }
            builder.setMessage(text);
            builder.setTitle(LocaleController.getString("TurnPasswordOffQuestionTitle", R.string.TurnPasswordOffQuestionTitle));
            builder.setPositiveButton(LocaleController.getString("Disable", R.string.Disable), (dialogInterface, i) -> sendSavePassword(true));
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            AlertDialog alertDialog = builder.create();
            showDialog(alertDialog);
            TextView button = (TextView) alertDialog.getButton(DialogInterface.BUTTON_POSITIVE);
            if (button != null) {
                button.setTextColor(Theme.getColor(Theme.key_dialogTextRed2));
            }
        });
        inputFields = new EditTextBoldCursor[FIELDS_COUNT_PASSWORD];
        for (int a = 0; a < FIELDS_COUNT_PASSWORD; a++) {
            if (a == FIELD_ENTERPASSWORD) {
                headerCell[0] = new HeaderCell(context);
                headerCell[0].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                headerCell[0].setText(LocaleController.getString("PaymentPasswordTitle", R.string.PaymentPasswordTitle));
                linearLayout2.addView(headerCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            } else if (a == FIELD_ENTERPASSWORDEMAIL) {
                headerCell[1] = new HeaderCell(context);
                headerCell[1].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                headerCell[1].setText(LocaleController.getString("PaymentPasswordEmailTitle", R.string.PaymentPasswordEmailTitle));
                linearLayout2.addView(headerCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
            ViewGroup container = new FrameLayout(context);
            container.setClipChildren(false);
            linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            if (a == FIELD_ENTERPASSWORD) {
                View 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);
                    }
                };
                divider.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                dividers.add(divider);
                container.addView(divider, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.LEFT | Gravity.BOTTOM));
            }
            inputFields[a] = new EditTextBoldCursor(context);
            inputFields[a].setTag(a);
            inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setBackgroundDrawable(null);
            inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            inputFields[a].setCursorSize(AndroidUtilities.dp(20));
            inputFields[a].setCursorWidth(1.5f);
            if (a == FIELD_ENTERPASSWORD || a == FIELD_REENTERPASSWORD) {
                inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
                inputFields[a].setTypeface(Typeface.DEFAULT);
                inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            } else {
                inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_EMAIL_ADDRESS);
                inputFields[a].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
            switch(a) {
                case FIELD_ENTERPASSWORD:
                    inputFields[a].setHint(LocaleController.getString("PaymentPasswordEnter", R.string.PaymentPasswordEnter));
                    inputFields[a].requestFocus();
                    break;
                case FIELD_REENTERPASSWORD:
                    inputFields[a].setHint(LocaleController.getString("PaymentPasswordReEnter", R.string.PaymentPasswordReEnter));
                    break;
                case FIELD_ENTERPASSWORDEMAIL:
                    inputFields[a].setHint(LocaleController.getString("PaymentPasswordEmail", R.string.PaymentPasswordEmail));
                    break;
            }
            inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
            inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
            container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));
            inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
                if (i == EditorInfo.IME_ACTION_DONE) {
                    doneItem.performClick();
                    return true;
                } else if (i == EditorInfo.IME_ACTION_NEXT) {
                    int num = (Integer) textView.getTag();
                    if (num == FIELD_ENTERPASSWORD) {
                        inputFields[FIELD_REENTERPASSWORD].requestFocus();
                    } else if (num == FIELD_REENTERPASSWORD) {
                        inputFields[FIELD_ENTERPASSWORDEMAIL].requestFocus();
                    }
                }
                return false;
            });
            if (a == FIELD_REENTERPASSWORD) {
                bottomCell[0] = new TextInfoPrivacyCell(context);
                bottomCell[0].setText(LocaleController.getString("PaymentPasswordInfo", R.string.PaymentPasswordInfo));
                bottomCell[0].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                linearLayout2.addView(bottomCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            } else if (a == FIELD_ENTERPASSWORDEMAIL) {
                bottomCell[1] = new TextInfoPrivacyCell(context);
                bottomCell[1].setText(LocaleController.getString("PaymentPasswordEmailInfo", R.string.PaymentPasswordEmailInfo));
                bottomCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                linearLayout2.addView(bottomCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            }
        }
        updatePasswordFields();
    }
    return fragmentView;
}
Also used : JavascriptInterface(android.webkit.JavascriptInterface) TokenParser(com.stripe.android.net.TokenParser) HttpURLConnection(java.net.HttpURLConnection) Arrays(java.util.Arrays) Uri(android.net.Uri) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) PaymentInfoCell(org.telegram.ui.Cells.PaymentInfoCell) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) HorizontalScrollView(android.widget.HorizontalScrollView) Manifest(android.Manifest) Card(com.stripe.android.model.Card) JSONException(org.json.JSONException) CookieManager(android.webkit.CookieManager) Canvas(android.graphics.Canvas) APIException(com.stripe.android.exception.APIException) UndoView(org.telegram.ui.Components.UndoView) AnimatorListenerAdapter(android.animation.AnimatorListenerAdapter) NotificationCenter(org.telegram.messenger.NotificationCenter) TextPaint(android.text.TextPaint) TextPriceCell(org.telegram.ui.Cells.TextPriceCell) Token(com.stripe.android.model.Token) RadioCell(org.telegram.ui.Cells.RadioCell) InputFilter(android.text.InputFilter) TextWatcher(android.text.TextWatcher) ViewParent(android.view.ViewParent) RequestDelegate(org.telegram.tgnet.RequestDelegate) Dialog(android.app.Dialog) AlertsCreator(org.telegram.ui.Components.AlertsCreator) Editable(android.text.Editable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) SpannableStringBuilder(android.text.SpannableStringBuilder) Calendar(java.util.Calendar) WebSettings(android.webkit.WebSettings) TextDetailSettingsCell(org.telegram.ui.Cells.TextDetailSettingsCell) TLRPC(org.telegram.tgnet.TLRPC) Toast(android.widget.Toast) PhoneFormat(org.telegram.PhoneFormat.PhoneFormat) EditTextSettingsCell(org.telegram.ui.Cells.EditTextSettingsCell) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) HintEditText(org.telegram.ui.Components.HintEditText) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) R(org.telegram.messenger.R) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) TextUtils(android.text.TextUtils) IOException(java.io.IOException) InputStreamReader(java.io.InputStreamReader) Gravity(android.view.Gravity) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) ContactsController(org.telegram.messenger.ContactsController) Stripe(com.stripe.android.Stripe) BufferedReader(java.io.BufferedReader) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) EditText(android.widget.EditText) ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) PackageManager(android.content.pm.PackageManager) URL(java.net.URL) WindowManager(android.view.WindowManager) AndroidUtilities(org.telegram.messenger.AndroidUtilities) Scanner(java.util.Scanner) ClickableSpan(android.text.style.ClickableSpan) Animator(android.animation.Animator) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) JSONObject(org.json.JSONObject) ApplicationLoader(org.telegram.messenger.ApplicationLoader) Locale(java.util.Locale) WebViewClient(android.webkit.WebViewClient) View(android.view.View) WebView(android.webkit.WebView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) Utilities(org.telegram.messenger.Utilities) StripeApiHandler(com.stripe.android.net.StripeApiHandler) AsyncTask(android.os.AsyncTask) APIConnectionException(com.stripe.android.exception.APIConnectionException) ObjectAnimator(android.animation.ObjectAnimator) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) UserConfig(org.telegram.messenger.UserConfig) List(java.util.List) TextView(android.widget.TextView) Optional(java.util.Optional) EditorInfo(android.view.inputmethod.EditorInfo) Typeface(android.graphics.Typeface) Context(android.content.Context) Spanned(android.text.Spanned) 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) SuppressLint(android.annotation.SuppressLint) MotionEvent(android.view.MotionEvent) SRPHelper(org.telegram.messenger.SRPHelper) TelephonyManager(android.telephony.TelephonyManager) ActionBar(org.telegram.ui.ActionBar.ActionBar) TLObject(org.telegram.tgnet.TLObject) AnimatorSet(android.animation.AnimatorSet) MessageObject(org.telegram.messenger.MessageObject) SharedConfig(org.telegram.messenger.SharedConfig) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) BuildVars(org.telegram.messenger.BuildVars) Build(android.os.Build) DialogInterface(android.content.DialogInterface) OutputStream(java.io.OutputStream) LayoutHelper(org.telegram.ui.Components.LayoutHelper) FileLog(org.telegram.messenger.FileLog) MessagesController(org.telegram.messenger.MessagesController) TokenCallback(com.stripe.android.TokenCallback) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) Vibrator(android.os.Vibrator) Activity(android.app.Activity) Collections(java.util.Collections) JSONArray(org.json.JSONArray) InputStream(java.io.InputStream) AlertDialog(org.telegram.ui.ActionBar.AlertDialog) HashMap(java.util.HashMap) TextCheckCell(org.telegram.ui.Cells.TextCheckCell) HeaderCell(org.telegram.ui.Cells.HeaderCell) SpannableStringBuilder(android.text.SpannableStringBuilder) TLRPC(org.telegram.tgnet.TLRPC) TelephonyManager(android.telephony.TelephonyManager) TextView(android.widget.TextView) HorizontalScrollView(android.widget.HorizontalScrollView) ActionBar(org.telegram.ui.ActionBar.ActionBar) CookieManager(android.webkit.CookieManager) WebViewClient(android.webkit.WebViewClient) HintEditText(org.telegram.ui.Components.HintEditText) EditText(android.widget.EditText) InputFilter(android.text.InputFilter) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) Canvas(android.graphics.Canvas) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ActionBarMenu(org.telegram.ui.ActionBar.ActionBarMenu) HintEditText(org.telegram.ui.Components.HintEditText) JSONObject(org.json.JSONObject) TextPriceCell(org.telegram.ui.Cells.TextPriceCell) BottomSheet(org.telegram.ui.ActionBar.BottomSheet) SpannableStringBuilder(android.text.SpannableStringBuilder) ContextProgressView(org.telegram.ui.Components.ContextProgressView) RadioCell(org.telegram.ui.Cells.RadioCell) Uri(android.net.Uri) PaymentInfoCell(org.telegram.ui.Cells.PaymentInfoCell) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) WebView(android.webkit.WebView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) InputStreamReader(java.io.InputStreamReader) TextDetailSettingsCell(org.telegram.ui.Cells.TextDetailSettingsCell) SharedPreferences(android.content.SharedPreferences) ViewGroup(android.view.ViewGroup) Calendar(java.util.Calendar) EditTextSettingsCell(org.telegram.ui.Cells.EditTextSettingsCell) ImageView(android.widget.ImageView) HorizontalScrollView(android.widget.HorizontalScrollView) UndoView(org.telegram.ui.Components.UndoView) ScrollView(android.widget.ScrollView) View(android.view.View) WebView(android.webkit.WebView) ContextProgressView(org.telegram.ui.Components.ContextProgressView) TextView(android.widget.TextView) TextPaint(android.text.TextPaint) SuppressLint(android.annotation.SuppressLint) JSONException(org.json.JSONException) APIException(com.stripe.android.exception.APIException) IOException(java.io.IOException) APIConnectionException(com.stripe.android.exception.APIConnectionException) MotionEvent(android.view.MotionEvent) EditTextSettingsCell(org.telegram.ui.Cells.EditTextSettingsCell) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) HorizontalScrollView(android.widget.HorizontalScrollView) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) BufferedReader(java.io.BufferedReader) LinearLayout(android.widget.LinearLayout) SuppressLint(android.annotation.SuppressLint)

Example 13 with TextSettingsCell

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

the class PassportActivity method createAddressInterface.

private void createAddressInterface(Context context) {
    languageMap = new HashMap<>();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
        String line;
        while ((line = reader.readLine()) != null) {
            String[] args = line.split(";");
            languageMap.put(args[1], args[2]);
        }
        reader.close();
    } catch (Exception e) {
        FileLog.e(e);
    }
    topErrorCell = new TextInfoPrivacyCell(context);
    topErrorCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow));
    topErrorCell.setPadding(0, AndroidUtilities.dp(7), 0, 0);
    linearLayout2.addView(topErrorCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    checkTopErrorCell(true);
    if (currentDocumentsType != null) {
        if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
            actionBar.setTitle(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
        } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
            actionBar.setTitle(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
        } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
            actionBar.setTitle(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
        } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
            actionBar.setTitle(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
        } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
            actionBar.setTitle(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
        }
        headerCell = new HeaderCell(context);
        headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments));
        headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        documentsLayout = new LinearLayout(context);
        documentsLayout.setOrientation(LinearLayout.VERTICAL);
        linearLayout2.addView(documentsLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        uploadDocumentCell = new TextSettingsCell(context);
        uploadDocumentCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        linearLayout2.addView(uploadDocumentCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        uploadDocumentCell.setOnClickListener(v -> {
            uploadingFileType = UPLOADING_TYPE_DOCUMENTS;
            openAttachMenu();
        });
        bottomCell = new TextInfoPrivacyCell(context);
        bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        if (currentBotId != 0) {
            noAllDocumentsErrorText = LocaleController.getString("PassportAddAddressUploadInfo", R.string.PassportAddAddressUploadInfo);
        } else {
            if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                noAllDocumentsErrorText = LocaleController.getString("PassportAddAgreementInfo", R.string.PassportAddAgreementInfo);
            } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                noAllDocumentsErrorText = LocaleController.getString("PassportAddBillInfo", R.string.PassportAddBillInfo);
            } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                noAllDocumentsErrorText = LocaleController.getString("PassportAddPassportRegistrationInfo", R.string.PassportAddPassportRegistrationInfo);
            } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                noAllDocumentsErrorText = LocaleController.getString("PassportAddTemporaryRegistrationInfo", R.string.PassportAddTemporaryRegistrationInfo);
            } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                noAllDocumentsErrorText = LocaleController.getString("PassportAddBankInfo", R.string.PassportAddBankInfo);
            } else {
                noAllDocumentsErrorText = "";
            }
        }
        CharSequence text = noAllDocumentsErrorText;
        if (documentsErrors != null) {
            String errorText;
            if ((errorText = documentsErrors.get("files_all")) != null) {
                SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText);
                stringBuilder.append("\n\n");
                stringBuilder.append(noAllDocumentsErrorText);
                text = stringBuilder;
                stringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                errorsValues.put("files_all", "");
            }
        }
        bottomCell.setText(text);
        linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        if (currentDocumentsType.translation_required) {
            headerCell = new HeaderCell(context);
            headerCell.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation));
            headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            translationLayout = new LinearLayout(context);
            translationLayout.setOrientation(LinearLayout.VERTICAL);
            linearLayout2.addView(translationLayout, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            uploadTranslationCell = new TextSettingsCell(context);
            uploadTranslationCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            linearLayout2.addView(uploadTranslationCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
            uploadTranslationCell.setOnClickListener(v -> {
                uploadingFileType = UPLOADING_TYPE_TRANSLATION;
                openAttachMenu();
            });
            bottomCellTranslation = new TextInfoPrivacyCell(context);
            bottomCellTranslation.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            if (currentBotId != 0) {
                noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo);
            } else {
                if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                    noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationAgreementInfo", R.string.PassportAddTranslationAgreementInfo);
                } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                    noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBillInfo", R.string.PassportAddTranslationBillInfo);
                } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                    noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationPassportRegistrationInfo", R.string.PassportAddTranslationPassportRegistrationInfo);
                } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                    noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationTemporaryRegistrationInfo", R.string.PassportAddTranslationTemporaryRegistrationInfo);
                } else if (currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                    noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBankInfo", R.string.PassportAddTranslationBankInfo);
                } else {
                    noAllTranslationErrorText = "";
                }
            }
            text = noAllTranslationErrorText;
            if (documentsErrors != null) {
                String errorText;
                if ((errorText = documentsErrors.get("translation_all")) != null) {
                    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText);
                    stringBuilder.append("\n\n");
                    stringBuilder.append(noAllTranslationErrorText);
                    text = stringBuilder;
                    stringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
                    errorsValues.put("translation_all", "");
                }
            }
            bottomCellTranslation.setText(text);
            linearLayout2.addView(bottomCellTranslation, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        }
    } else {
        actionBar.setTitle(LocaleController.getString("PassportAddress", R.string.PassportAddress));
    }
    headerCell = new HeaderCell(context);
    headerCell.setText(LocaleController.getString("PassportAddressHeader", R.string.PassportAddressHeader));
    headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    inputFields = new EditTextBoldCursor[FIELD_ADDRESS_COUNT];
    for (int a = 0; a < FIELD_ADDRESS_COUNT; a++) {
        final EditTextBoldCursor field = new EditTextBoldCursor(context);
        inputFields[a] = field;
        ViewGroup container = new FrameLayout(context) {

            private StaticLayout errorLayout;

            float offsetX;

            @Override
            protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                int width = MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34);
                errorLayout = field.getErrorLayout(width);
                if (errorLayout != null) {
                    int lineCount = errorLayout.getLineCount();
                    if (lineCount > 1) {
                        int height = AndroidUtilities.dp(64) + (errorLayout.getLineBottom(lineCount - 1) - errorLayout.getLineBottom(0));
                        heightMeasureSpec = MeasureSpec.makeMeasureSpec(height, MeasureSpec.EXACTLY);
                    }
                    if (LocaleController.isRTL) {
                        float maxW = 0;
                        for (int a = 0; a < lineCount; a++) {
                            float l = errorLayout.getLineLeft(a);
                            if (l != 0) {
                                offsetX = 0;
                                break;
                            }
                            maxW = Math.max(maxW, errorLayout.getLineWidth(a));
                            if (a == lineCount - 1) {
                                offsetX = width - maxW;
                            }
                        }
                    }
                }
                super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            }

            @Override
            protected void onDraw(Canvas canvas) {
                if (errorLayout != null) {
                    canvas.save();
                    canvas.translate(AndroidUtilities.dp(21) + offsetX, field.getLineY() + AndroidUtilities.dp(3));
                    errorLayout.draw(canvas);
                    canvas.restore();
                }
            }
        };
        container.setWillNotDraw(false);
        linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        if (a == FIELD_ADDRESS_COUNT - 1) {
            extraBackgroundView = new View(context);
            extraBackgroundView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            linearLayout2.addView(extraBackgroundView, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 6));
        }
        if (documentOnly && currentDocumentsType != null) {
            container.setVisibility(View.GONE);
            if (extraBackgroundView != null) {
                extraBackgroundView.setVisibility(View.GONE);
            }
        }
        inputFields[a].setTag(a);
        inputFields[a].setSupportRtlHint(true);
        inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
        inputFields[a].setTransformHintToHeader(true);
        inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setBackgroundDrawable(null);
        inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setCursorSize(AndroidUtilities.dp(20));
        inputFields[a].setCursorWidth(1.5f);
        inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
        if (a == FIELD_COUNTRY) {
            inputFields[a].setOnTouchListener((v, event) -> {
                if (getParentActivity() == null) {
                    return false;
                }
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    CountrySelectActivity fragment = new CountrySelectActivity(false);
                    fragment.setCountrySelectActivityDelegate((country) -> {
                        inputFields[FIELD_COUNTRY].setText(country.name);
                        currentCitizeship = country.shortname;
                    });
                    presentFragment(fragment);
                }
                return true;
            });
            inputFields[a].setInputType(0);
            inputFields[a].setFocusable(false);
        } else {
            inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_CAP_SENTENCES);
            inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        }
        String value;
        final String key;
        switch(a) {
            case FIELD_STREET1:
                inputFields[a].setHintText(LocaleController.getString("PassportStreet1", R.string.PassportStreet1));
                key = "street_line1";
                break;
            case FIELD_STREET2:
                inputFields[a].setHintText(LocaleController.getString("PassportStreet2", R.string.PassportStreet2));
                key = "street_line2";
                break;
            case FIELD_CITY:
                inputFields[a].setHintText(LocaleController.getString("PassportCity", R.string.PassportCity));
                key = "city";
                break;
            case FIELD_STATE:
                inputFields[a].setHintText(LocaleController.getString("PassportState", R.string.PassportState));
                key = "state";
                break;
            case FIELD_COUNTRY:
                inputFields[a].setHintText(LocaleController.getString("PassportCountry", R.string.PassportCountry));
                key = "country_code";
                break;
            case FIELD_POSTCODE:
                inputFields[a].setHintText(LocaleController.getString("PassportPostcode", R.string.PassportPostcode));
                key = "post_code";
                break;
            default:
                continue;
        }
        setFieldValues(currentValues, inputFields[a], key);
        if (a == FIELD_POSTCODE) {
            inputFields[a].addTextChangedListener(new TextWatcher() {

                private boolean ignore;

                @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 (ignore) {
                        return;
                    }
                    ignore = true;
                    boolean error = false;
                    for (int a = 0; a < s.length(); a++) {
                        char ch = s.charAt(a);
                        if (!(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z' || ch >= '0' && ch <= '9' || ch == '-' || ch == ' ')) {
                            error = true;
                            break;
                        }
                    }
                    ignore = false;
                    if (error) {
                        field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly));
                    } else {
                        checkFieldForError(field, key, s, false);
                    }
                }
            });
            InputFilter[] inputFilters = new InputFilter[1];
            inputFilters[0] = new InputFilter.LengthFilter(10);
            inputFields[a].setFilters(inputFilters);
        } else {
            inputFields[a].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) {
                    checkFieldForError(field, key, s, false);
                }
            });
        }
        inputFields[a].setSelection(inputFields[a].length());
        inputFields[a].setPadding(0, 0, 0, 0);
        inputFields[a].setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
        container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, 64, Gravity.LEFT | Gravity.TOP, 21, 0, 21, 0));
        inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_NEXT) {
                int num = (Integer) textView.getTag();
                num++;
                if (num < inputFields.length) {
                    if (inputFields[num].isFocusable()) {
                        inputFields[num].requestFocus();
                    } else {
                        inputFields[num].dispatchTouchEvent(MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 0, 0, 0));
                        textView.clearFocus();
                        AndroidUtilities.hideKeyboard(textView);
                    }
                }
                return true;
            }
            return false;
        });
    }
    sectionCell = new ShadowSectionCell(context);
    linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    if (documentOnly && currentDocumentsType != null) {
        headerCell.setVisibility(View.GONE);
        sectionCell.setVisibility(View.GONE);
    }
    if ((currentBotId != 0 || currentDocumentsType == null) && currentTypeValue != null && !documentOnly || currentDocumentsTypeValue != null) {
        if (currentDocumentsTypeValue != null) {
            addDocumentViews(currentDocumentsTypeValue.files);
            addTranslationDocumentViews(currentDocumentsTypeValue.translation);
        }
        sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        TextSettingsCell settingsCell1 = new TextSettingsCell(context);
        settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
        settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        if (currentDocumentsType == null) {
            settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false);
        } else {
            settingsCell1.setText(LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false);
        }
        linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
        settingsCell1.setOnClickListener(v -> createDocumentDeleteAlert());
        sectionCell = new ShadowSectionCell(context);
        sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        linearLayout2.addView(sectionCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    } else {
        sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        if (documentOnly && currentDocumentsType != null) {
            bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        }
    }
    updateUploadText(UPLOADING_TYPE_DOCUMENTS);
    updateUploadText(UPLOADING_TYPE_TRANSLATION);
}
Also used : HeaderCell(org.telegram.ui.Cells.HeaderCell) TLRPC(org.telegram.tgnet.TLRPC) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) InputFilter(android.text.InputFilter) InputStreamReader(java.io.InputStreamReader) ForegroundColorSpan(android.text.style.ForegroundColorSpan) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ViewGroup(android.view.ViewGroup) Canvas(android.graphics.Canvas) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) StaticLayout(android.text.StaticLayout) ImageView(android.widget.ImageView) SlideView(org.telegram.ui.Components.SlideView) ScrollView(android.widget.ScrollView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) FrameLayout(android.widget.FrameLayout) BufferedReader(java.io.BufferedReader) LinearLayout(android.widget.LinearLayout) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 14 with TextSettingsCell

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

the class PassportActivity method createPhoneInterface.

private void createPhoneInterface(Context context) {
    actionBar.setTitle(LocaleController.getString("PassportPhone", R.string.PassportPhone));
    languageMap = new HashMap<>();
    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
        String line;
        while ((line = reader.readLine()) != null) {
            String[] args = line.split(";");
            countriesArray.add(0, args[2]);
            countriesMap.put(args[2], args[0]);
            codesMap.put(args[0], args[2]);
            if (args.length > 3) {
                phoneFormatMap.put(args[0], args[3]);
            }
            languageMap.put(args[1], args[2]);
        }
        reader.close();
    } catch (Exception e) {
        FileLog.e(e);
    }
    Collections.sort(countriesArray, String::compareTo);
    String currentPhone = UserConfig.getInstance(currentAccount).getCurrentUser().phone;
    TextSettingsCell settingsCell1 = new TextSettingsCell(context);
    settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
    settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
    settingsCell1.setText(LocaleController.formatString("PassportPhoneUseSame", R.string.PassportPhoneUseSame, PhoneFormat.getInstance().format("+" + currentPhone)), false);
    linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    settingsCell1.setOnClickListener(v -> {
        useCurrentValue = true;
        doneItem.callOnClick();
        useCurrentValue = false;
    });
    bottomCell = new TextInfoPrivacyCell(context);
    bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    bottomCell.setText(LocaleController.getString("PassportPhoneUseSameInfo", R.string.PassportPhoneUseSameInfo));
    linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    headerCell = new HeaderCell(context);
    headerCell.setText(LocaleController.getString("PassportPhoneUseOther", R.string.PassportPhoneUseOther));
    headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    linearLayout2.addView(headerCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    inputFields = new EditTextBoldCursor[3];
    for (int a = 0; a < 3; a++) {
        if (a == FIELD_PHONE) {
            inputFields[a] = new HintEditText(context);
        } else {
            inputFields[a] = new EditTextBoldCursor(context);
        }
        ViewGroup container;
        if (a == FIELD_PHONECODE) {
            container = new LinearLayout(context);
            ((LinearLayout) container).setOrientation(LinearLayout.HORIZONTAL);
            linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        } else if (a == FIELD_PHONE) {
            container = (ViewGroup) inputFields[FIELD_PHONECODE].getParent();
        } else {
            container = new FrameLayout(context);
            linearLayout2.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        }
        inputFields[a].setTag(a);
        inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setBackgroundDrawable(null);
        inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setCursorSize(AndroidUtilities.dp(20));
        inputFields[a].setCursorWidth(1.5f);
        if (a == FIELD_PHONECOUNTRY) {
            inputFields[a].setOnTouchListener((v, event) -> {
                if (getParentActivity() == null) {
                    return false;
                }
                if (event.getAction() == MotionEvent.ACTION_UP) {
                    CountrySelectActivity fragment = new CountrySelectActivity(false);
                    fragment.setCountrySelectActivityDelegate(country -> {
                        inputFields[FIELD_PHONECOUNTRY].setText(country.name);
                        int index = countriesArray.indexOf(country.name);
                        if (index != -1) {
                            ignoreOnTextChange = true;
                            String code = countriesMap.get(country.name);
                            inputFields[FIELD_PHONECODE].setText(code);
                            String hint = phoneFormatMap.get(code);
                            inputFields[FIELD_PHONE].setHintText(hint != null ? hint.replace('X', '–') : null);
                            ignoreOnTextChange = false;
                        }
                        AndroidUtilities.runOnUIThread(() -> AndroidUtilities.showKeyboard(inputFields[FIELD_PHONE]), 300);
                        inputFields[FIELD_PHONE].requestFocus();
                        inputFields[FIELD_PHONE].setSelection(inputFields[FIELD_PHONE].length());
                    });
                    presentFragment(fragment);
                }
                return true;
            });
            inputFields[a].setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
            inputFields[a].setInputType(0);
            inputFields[a].setFocusable(false);
        } else {
            inputFields[a].setInputType(InputType.TYPE_CLASS_PHONE);
            if (a == FIELD_PHONE) {
                inputFields[a].setImeOptions(EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            } else {
                inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
            }
        }
        inputFields[a].setSelection(inputFields[a].length());
        if (a == FIELD_PHONECODE) {
            plusTextView = new TextView(context);
            plusTextView.setText("+");
            plusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            plusTextView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
            container.addView(plusTextView, LayoutHelper.createLinear(LayoutHelper.WRAP_CONTENT, LayoutHelper.WRAP_CONTENT, 21, 12, 0, 6));
            inputFields[a].setPadding(AndroidUtilities.dp(10), 0, 0, 0);
            InputFilter[] inputFilters = new InputFilter[1];
            inputFilters[0] = new InputFilter.LengthFilter(5);
            inputFields[a].setFilters(inputFilters);
            inputFields[a].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
            container.addView(inputFields[a], LayoutHelper.createLinear(55, LayoutHelper.WRAP_CONTENT, 0, 12, 16, 6));
            inputFields[a].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) {
                }

                @Override
                public void afterTextChanged(Editable editable) {
                    if (ignoreOnTextChange) {
                        return;
                    }
                    ignoreOnTextChange = true;
                    String text = PhoneFormat.stripExceptNumbers(inputFields[FIELD_PHONECODE].getText().toString());
                    inputFields[FIELD_PHONECODE].setText(text);
                    HintEditText phoneField = (HintEditText) inputFields[FIELD_PHONE];
                    if (text.length() == 0) {
                        phoneField.setHintText(null);
                        phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                        inputFields[FIELD_PHONECOUNTRY].setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
                    } else {
                        String country;
                        boolean ok = false;
                        String textToSet = null;
                        if (text.length() > 4) {
                            for (int a = 4; a >= 1; a--) {
                                String sub = text.substring(0, a);
                                country = codesMap.get(sub);
                                if (country != null) {
                                    ok = true;
                                    textToSet = text.substring(a) + inputFields[FIELD_PHONE].getText().toString();
                                    inputFields[FIELD_PHONECODE].setText(text = sub);
                                    break;
                                }
                            }
                            if (!ok) {
                                textToSet = text.substring(1) + inputFields[FIELD_PHONE].getText().toString();
                                inputFields[FIELD_PHONECODE].setText(text = text.substring(0, 1));
                            }
                        }
                        country = codesMap.get(text);
                        boolean set = false;
                        if (country != null) {
                            int index = countriesArray.indexOf(country);
                            if (index != -1) {
                                inputFields[FIELD_PHONECOUNTRY].setText(countriesArray.get(index));
                                String hint = phoneFormatMap.get(text);
                                set = true;
                                if (hint != null) {
                                    phoneField.setHintText(hint.replace('X', '–'));
                                    phoneField.setHint(null);
                                }
                            }
                        }
                        if (!set) {
                            phoneField.setHintText(null);
                            phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                            inputFields[FIELD_PHONECOUNTRY].setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
                        }
                        if (!ok) {
                            inputFields[FIELD_PHONECODE].setSelection(inputFields[FIELD_PHONECODE].getText().length());
                        }
                        if (textToSet != null) {
                            phoneField.requestFocus();
                            phoneField.setText(textToSet);
                            phoneField.setSelection(phoneField.length());
                        }
                    }
                    ignoreOnTextChange = false;
                }
            });
        } else if (a == FIELD_PHONE) {
            inputFields[a].setPadding(0, 0, 0, 0);
            inputFields[a].setGravity(Gravity.LEFT | Gravity.CENTER_VERTICAL);
            inputFields[a].setHintText(null);
            inputFields[a].setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
            container.addView(inputFields[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, 0, 12, 21, 6));
            inputFields[a].addTextChangedListener(new TextWatcher() {

                private int characterAction = -1;

                private int actionPosition;

                @Override
                public void beforeTextChanged(CharSequence s, int start, int count, int after) {
                    if (count == 0 && after == 1) {
                        characterAction = 1;
                    } else if (count == 1 && after == 0) {
                        if (s.charAt(start) == ' ' && start > 0) {
                            characterAction = 3;
                            actionPosition = start - 1;
                        } else {
                            characterAction = 2;
                        }
                    } else {
                        characterAction = -1;
                    }
                }

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

                @Override
                public void afterTextChanged(Editable s) {
                    if (ignoreOnPhoneChange) {
                        return;
                    }
                    HintEditText phoneField = (HintEditText) inputFields[FIELD_PHONE];
                    int start = phoneField.getSelectionStart();
                    String phoneChars = "0123456789";
                    String str = phoneField.getText().toString();
                    if (characterAction == 3) {
                        str = str.substring(0, actionPosition) + str.substring(actionPosition + 1);
                        start--;
                    }
                    StringBuilder builder = new StringBuilder(str.length());
                    for (int a = 0; a < str.length(); a++) {
                        String ch = str.substring(a, a + 1);
                        if (phoneChars.contains(ch)) {
                            builder.append(ch);
                        }
                    }
                    ignoreOnPhoneChange = true;
                    String hint = phoneField.getHintText();
                    if (hint != null) {
                        for (int a = 0; a < builder.length(); a++) {
                            if (a < hint.length()) {
                                if (hint.charAt(a) == ' ') {
                                    builder.insert(a, ' ');
                                    a++;
                                    if (start == a && characterAction != 2 && characterAction != 3) {
                                        start++;
                                    }
                                }
                            } else {
                                builder.insert(a, ' ');
                                if (start == a + 1 && characterAction != 2 && characterAction != 3) {
                                    start++;
                                }
                                break;
                            }
                        }
                    }
                    phoneField.setText(builder);
                    if (start >= 0) {
                        phoneField.setSelection(Math.min(start, phoneField.length()));
                    }
                    phoneField.onTextChange();
                    ignoreOnPhoneChange = false;
                }
            });
        } else {
            inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6));
            inputFields[a].setGravity(LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT);
            container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT, Gravity.LEFT | Gravity.TOP, 21, 12, 21, 6));
        }
        inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_NEXT) {
                inputFields[FIELD_PHONE].requestFocus();
                return true;
            } else if (i == EditorInfo.IME_ACTION_DONE) {
                doneItem.callOnClick();
                return true;
            }
            return false;
        });
        if (a == FIELD_PHONE) {
            inputFields[a].setOnKeyListener((v, keyCode, event) -> {
                if (keyCode == KeyEvent.KEYCODE_DEL && inputFields[FIELD_PHONE].length() == 0) {
                    inputFields[FIELD_PHONECODE].requestFocus();
                    inputFields[FIELD_PHONECODE].setSelection(inputFields[FIELD_PHONECODE].length());
                    inputFields[FIELD_PHONECODE].dispatchKeyEvent(event);
                    return true;
                }
                return false;
            });
        }
        if (a == FIELD_PHONECOUNTRY) {
            View divider = new View(context);
            dividers.add(divider);
            divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
            container.addView(divider, new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 1, Gravity.LEFT | Gravity.BOTTOM));
        }
    }
    String country = null;
    try {
        TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService(Context.TELEPHONY_SERVICE);
        if (telephonyManager != null) {
            country = telephonyManager.getSimCountryIso().toUpperCase();
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    if (country != null) {
        String countryName = languageMap.get(country);
        if (countryName != null) {
            int index = countriesArray.indexOf(countryName);
            if (index != -1) {
                inputFields[FIELD_PHONECODE].setText(countriesMap.get(countryName));
            }
        }
    }
    bottomCell = new TextInfoPrivacyCell(context);
    bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    bottomCell.setText(LocaleController.getString("PassportPhoneUploadInfo", R.string.PassportPhoneUploadInfo));
    linearLayout2.addView(bottomCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
}
Also used : SpannableStringBuilder(android.text.SpannableStringBuilder) HeaderCell(org.telegram.ui.Cells.HeaderCell) TelephonyManager(android.telephony.TelephonyManager) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) TextView(android.widget.TextView) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) InputFilter(android.text.InputFilter) InputStreamReader(java.io.InputStreamReader) ViewGroup(android.view.ViewGroup) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ImageView(android.widget.ImageView) SlideView(org.telegram.ui.Components.SlideView) ScrollView(android.widget.ScrollView) View(android.view.View) ContextProgressView(org.telegram.ui.Components.ContextProgressView) EmptyTextProgressView(org.telegram.ui.Components.EmptyTextProgressView) TextView(android.widget.TextView) BackupImageView(org.telegram.ui.Components.BackupImageView) TextPaint(android.text.TextPaint) Paint(android.graphics.Paint) SuppressLint(android.annotation.SuppressLint) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) HintEditText(org.telegram.ui.Components.HintEditText) FrameLayout(android.widget.FrameLayout) BufferedReader(java.io.BufferedReader) LinearLayout(android.widget.LinearLayout)

Example 15 with TextSettingsCell

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

the class ProxySettingsActivity method createView.

@Override
public View createView(Context context) {
    actionBar.setTitle(LocaleController.getString("ProxyDetails", R.string.ProxyDetails));
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(false);
    if (AndroidUtilities.isTablet()) {
        actionBar.setOccupyStatusBar(false);
    }
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {

        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            } else if (id == done_button) {
                if (getParentActivity() == null) {
                    return;
                }
                currentProxyInfo.address = inputFields[FIELD_IP].getText().toString();
                currentProxyInfo.port = Utilities.parseInt(inputFields[FIELD_PORT].getText().toString());
                if (currentType == 0) {
                    currentProxyInfo.secret = "";
                    currentProxyInfo.username = inputFields[FIELD_USER].getText().toString();
                    currentProxyInfo.password = inputFields[FIELD_PASSWORD].getText().toString();
                } else {
                    currentProxyInfo.secret = inputFields[FIELD_SECRET].getText().toString();
                    currentProxyInfo.username = "";
                    currentProxyInfo.password = "";
                }
                SharedPreferences preferences = MessagesController.getGlobalMainSettings();
                SharedPreferences.Editor editor = preferences.edit();
                boolean enabled;
                if (addingNewProxy) {
                    SharedConfig.addProxy(currentProxyInfo);
                    SharedConfig.currentProxy = currentProxyInfo;
                    editor.putBoolean("proxy_enabled", true);
                    enabled = true;
                } else {
                    enabled = preferences.getBoolean("proxy_enabled", false);
                    SharedConfig.saveProxyList();
                }
                if (addingNewProxy || SharedConfig.currentProxy == currentProxyInfo) {
                    editor.putString("proxy_ip", currentProxyInfo.address);
                    editor.putString("proxy_pass", currentProxyInfo.password);
                    editor.putString("proxy_user", currentProxyInfo.username);
                    editor.putInt("proxy_port", currentProxyInfo.port);
                    editor.putString("proxy_secret", currentProxyInfo.secret);
                    ConnectionsManager.setProxySettings(enabled, currentProxyInfo.address, currentProxyInfo.port, currentProxyInfo.username, currentProxyInfo.password, currentProxyInfo.secret);
                }
                editor.commit();
                NotificationCenter.getGlobalInstance().postNotificationName(NotificationCenter.proxySettingsChanged);
                finishFragment();
            }
        }
    });
    doneItem = actionBar.createMenu().addItemWithWidth(done_button, R.drawable.ic_done, AndroidUtilities.dp(56));
    doneItem.setContentDescription(LocaleController.getString("Done", R.string.Done));
    fragmentView = new FrameLayout(context);
    FrameLayout frameLayout = (FrameLayout) fragmentView;
    fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
    scrollView = new ScrollView(context);
    scrollView.setFillViewport(true);
    AndroidUtilities.setScrollViewEdgeEffectColor(scrollView, Theme.getColor(Theme.key_actionBarDefault));
    frameLayout.addView(scrollView, LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT));
    linearLayout2 = new LinearLayout(context);
    linearLayout2.setOrientation(LinearLayout.VERTICAL);
    scrollView.addView(linearLayout2, new ScrollView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
    final View.OnClickListener typeCellClickListener = view -> setProxyType((Integer) view.getTag(), true);
    for (int a = 0; a < 2; a++) {
        typeCell[a] = new RadioCell(context);
        typeCell[a].setBackground(Theme.getSelectorDrawable(true));
        typeCell[a].setTag(a);
        if (a == 0) {
            typeCell[a].setText(LocaleController.getString("UseProxySocks5", R.string.UseProxySocks5), a == currentType, true);
        } else {
            typeCell[a].setText(LocaleController.getString("UseProxyTelegram", R.string.UseProxyTelegram), a == currentType, false);
        }
        linearLayout2.addView(typeCell[a], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 50));
        typeCell[a].setOnClickListener(typeCellClickListener);
    }
    sectionCell[0] = new ShadowSectionCell(context);
    linearLayout2.addView(sectionCell[0], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    inputFieldsContainer = new LinearLayout(context);
    inputFieldsContainer.setOrientation(LinearLayout.VERTICAL);
    inputFieldsContainer.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        // bring to front for transitions
        inputFieldsContainer.setElevation(AndroidUtilities.dp(1f));
        inputFieldsContainer.setOutlineProvider(null);
    }
    linearLayout2.addView(inputFieldsContainer, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    inputFields = new EditTextBoldCursor[5];
    for (int a = 0; a < 5; a++) {
        FrameLayout container = new FrameLayout(context);
        inputFieldsContainer.addView(container, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, 64));
        inputFields[a] = new EditTextBoldCursor(context);
        inputFields[a].setTag(a);
        inputFields[a].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
        inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
        inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setBackground(null);
        inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
        inputFields[a].setCursorSize(AndroidUtilities.dp(20));
        inputFields[a].setCursorWidth(1.5f);
        inputFields[a].setSingleLine(true);
        inputFields[a].setGravity((LocaleController.isRTL ? Gravity.RIGHT : Gravity.LEFT) | Gravity.CENTER_VERTICAL);
        inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
        inputFields[a].setTransformHintToHeader(true);
        inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
        if (a == FIELD_IP) {
            inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS | InputType.TYPE_TEXT_VARIATION_URI);
            inputFields[a].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) {
                    checkShareDone(true);
                }
            });
        } else if (a == FIELD_PORT) {
            inputFields[a].setInputType(InputType.TYPE_CLASS_NUMBER);
            inputFields[a].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 (ignoreOnTextChange) {
                        return;
                    }
                    EditText phoneField = inputFields[FIELD_PORT];
                    int start = phoneField.getSelectionStart();
                    String chars = "0123456789";
                    String str = phoneField.getText().toString();
                    StringBuilder builder = new StringBuilder(str.length());
                    for (int a = 0; a < str.length(); a++) {
                        String ch = str.substring(a, a + 1);
                        if (chars.contains(ch)) {
                            builder.append(ch);
                        }
                    }
                    ignoreOnTextChange = true;
                    boolean changed;
                    int port = Utilities.parseInt(builder.toString());
                    if (port < 0 || port > 65535 || !str.equals(builder.toString())) {
                        if (port < 0) {
                            phoneField.setText("0");
                        } else if (port > 65535) {
                            phoneField.setText("65535");
                        } else {
                            phoneField.setText(builder.toString());
                        }
                    } else {
                        if (start >= 0) {
                            phoneField.setSelection(Math.min(start, phoneField.length()));
                        }
                    }
                    ignoreOnTextChange = false;
                    checkShareDone(true);
                }
            });
        } else if (a == FIELD_PASSWORD) {
            inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_VARIATION_PASSWORD);
            inputFields[a].setTypeface(Typeface.DEFAULT);
            inputFields[a].setTransformationMethod(PasswordTransformationMethod.getInstance());
        } else {
            inputFields[a].setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS);
        }
        inputFields[a].setImeOptions(EditorInfo.IME_ACTION_NEXT | EditorInfo.IME_FLAG_NO_EXTRACT_UI);
        switch(a) {
            case FIELD_IP:
                inputFields[a].setHintText(LocaleController.getString("UseProxyAddress", R.string.UseProxyAddress));
                inputFields[a].setText(currentProxyInfo.address);
                break;
            case FIELD_PASSWORD:
                inputFields[a].setHintText(LocaleController.getString("UseProxyPassword", R.string.UseProxyPassword));
                inputFields[a].setText(currentProxyInfo.password);
                break;
            case FIELD_PORT:
                inputFields[a].setHintText(LocaleController.getString("UseProxyPort", R.string.UseProxyPort));
                inputFields[a].setText("" + currentProxyInfo.port);
                break;
            case FIELD_USER:
                inputFields[a].setHintText(LocaleController.getString("UseProxyUsername", R.string.UseProxyUsername));
                inputFields[a].setText(currentProxyInfo.username);
                break;
            case FIELD_SECRET:
                inputFields[a].setHintText(LocaleController.getString("UseProxySecret", R.string.UseProxySecret));
                inputFields[a].setText(currentProxyInfo.secret);
                break;
        }
        inputFields[a].setSelection(inputFields[a].length());
        inputFields[a].setPadding(0, 0, 0, 0);
        container.addView(inputFields[a], LayoutHelper.createFrame(LayoutHelper.MATCH_PARENT, LayoutHelper.MATCH_PARENT, Gravity.LEFT | Gravity.TOP, 17, a == FIELD_IP ? 12 : 0, 17, 0));
        inputFields[a].setOnEditorActionListener((textView, i, keyEvent) -> {
            if (i == EditorInfo.IME_ACTION_NEXT) {
                int num = (Integer) textView.getTag();
                if (num + 1 < inputFields.length) {
                    num++;
                    inputFields[num].requestFocus();
                }
                return true;
            } else if (i == EditorInfo.IME_ACTION_DONE) {
                finishFragment();
                return true;
            }
            return false;
        });
    }
    for (int i = 0; i < 2; i++) {
        bottomCells[i] = new TextInfoPrivacyCell(context);
        bottomCells[i].setBackground(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        if (i == 0) {
            bottomCells[i].setText(LocaleController.getString("UseProxyInfo", R.string.UseProxyInfo));
        } else {
            bottomCells[i].setText(LocaleController.getString("UseProxyTelegramInfo", R.string.UseProxyTelegramInfo) + "\n\n" + LocaleController.getString("UseProxyTelegramInfo2", R.string.UseProxyTelegramInfo2));
            bottomCells[i].setVisibility(View.GONE);
        }
        linearLayout2.addView(bottomCells[i], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    }
    pasteCell = new TextSettingsCell(fragmentView.getContext());
    pasteCell.setBackground(Theme.getSelectorDrawable(true));
    pasteCell.setText(LocaleController.getString("PasteFromClipboard", R.string.PasteFromClipboard), false);
    pasteCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
    pasteCell.setOnClickListener(v -> {
        if (pasteType != -1) {
            for (int i = 0; i < pasteFields.length; i++) {
                if (pasteType == TYPE_SOCKS5 && i == FIELD_SECRET) {
                    continue;
                }
                if (pasteType == TYPE_MTPROTO && (i == FIELD_USER || i == FIELD_PASSWORD)) {
                    continue;
                }
                if (pasteFields[i] != null) {
                    try {
                        inputFields[i].setText(URLDecoder.decode(pasteFields[i], "UTF-8"));
                    } catch (UnsupportedEncodingException e) {
                        inputFields[i].setText(pasteFields[i]);
                    }
                } else {
                    inputFields[i].setText(null);
                }
            }
            inputFields[0].setSelection(inputFields[0].length());
            setProxyType(pasteType, true, () -> {
                AndroidUtilities.hideKeyboard(inputFieldsContainer.findFocus());
                for (int i = 0; i < pasteFields.length; i++) {
                    if (pasteType == TYPE_SOCKS5 && i != FIELD_SECRET) {
                        continue;
                    }
                    if (pasteType == TYPE_MTPROTO && i != FIELD_USER && i != FIELD_PASSWORD) {
                        continue;
                    }
                    inputFields[i].setText(null);
                }
            });
        }
    });
    linearLayout2.addView(pasteCell, 0, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    pasteCell.setVisibility(View.GONE);
    sectionCell[2] = new ShadowSectionCell(fragmentView.getContext());
    sectionCell[2].setBackground(Theme.getThemedDrawable(fragmentView.getContext(), R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    linearLayout2.addView(sectionCell[2], 1, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    sectionCell[2].setVisibility(View.GONE);
    shareCell = new TextSettingsCell(context);
    shareCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
    shareCell.setText(LocaleController.getString("ShareFile", R.string.ShareFile), false);
    shareCell.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
    linearLayout2.addView(shareCell, LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    shareCell.setOnClickListener(v -> {
        StringBuilder params = new StringBuilder();
        String address = inputFields[FIELD_IP].getText().toString();
        String password = inputFields[FIELD_PASSWORD].getText().toString();
        String user = inputFields[FIELD_USER].getText().toString();
        String port = inputFields[FIELD_PORT].getText().toString();
        String secret = inputFields[FIELD_SECRET].getText().toString();
        String url;
        try {
            if (!TextUtils.isEmpty(address)) {
                params.append("server=").append(URLEncoder.encode(address, "UTF-8"));
            }
            if (!TextUtils.isEmpty(port)) {
                if (params.length() != 0) {
                    params.append("&");
                }
                params.append("port=").append(URLEncoder.encode(port, "UTF-8"));
            }
            if (currentType == 1) {
                url = "https://t.me/proxy?";
                if (params.length() != 0) {
                    params.append("&");
                }
                params.append("secret=").append(URLEncoder.encode(secret, "UTF-8"));
            } else {
                url = "https://t.me/socks?";
                if (!TextUtils.isEmpty(user)) {
                    if (params.length() != 0) {
                        params.append("&");
                    }
                    params.append("user=").append(URLEncoder.encode(user, "UTF-8"));
                }
                if (!TextUtils.isEmpty(password)) {
                    if (params.length() != 0) {
                        params.append("&");
                    }
                    params.append("pass=").append(URLEncoder.encode(password, "UTF-8"));
                }
            }
        } catch (Exception ignore) {
            return;
        }
        if (params.length() == 0) {
            return;
        }
        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");
        shareIntent.putExtra(Intent.EXTRA_TEXT, url + params.toString());
        Intent chooserIntent = Intent.createChooser(shareIntent, LocaleController.getString("ShareLink", R.string.ShareLink));
        chooserIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        getParentActivity().startActivity(chooserIntent);
    });
    sectionCell[1] = new ShadowSectionCell(context);
    sectionCell[1].setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
    linearLayout2.addView(sectionCell[1], LayoutHelper.createLinear(LayoutHelper.MATCH_PARENT, LayoutHelper.WRAP_CONTENT));
    clipboardManager = (ClipboardManager) context.getSystemService(Context.CLIPBOARD_SERVICE);
    shareDoneEnabled = true;
    shareDoneProgress = 1f;
    checkShareDone(false);
    currentType = -1;
    setProxyType(TextUtils.isEmpty(currentProxyInfo.secret) ? 0 : 1, false);
    pasteType = -1;
    pasteString = null;
    updatePasteCell();
    return fragmentView;
}
Also used : ThemeDescription(org.telegram.ui.ActionBar.ThemeDescription) LinearLayout(android.widget.LinearLayout) ActionBarMenuItem(org.telegram.ui.ActionBar.ActionBarMenuItem) URLDecoder(java.net.URLDecoder) FrameLayout(android.widget.FrameLayout) ImageView(android.widget.ImageView) AndroidUtilities(org.telegram.messenger.AndroidUtilities) CubicBezierInterpolator(org.telegram.ui.Components.CubicBezierInterpolator) TransitionManager(android.transition.TransitionManager) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) ClipboardManager(android.content.ClipboardManager) View(android.view.View) Canvas(android.graphics.Canvas) Transition(android.transition.Transition) TransitionSet(android.transition.TransitionSet) Utilities(org.telegram.messenger.Utilities) InputType(android.text.InputType) BaseFragment(org.telegram.ui.ActionBar.BaseFragment) PorterDuff(android.graphics.PorterDuff) ConnectionsManager(org.telegram.tgnet.ConnectionsManager) ViewGroup(android.view.ViewGroup) NotificationCenter(org.telegram.messenger.NotificationCenter) TextView(android.widget.TextView) PorterDuffColorFilter(android.graphics.PorterDuffColorFilter) RadioCell(org.telegram.ui.Cells.RadioCell) EditorInfo(android.view.inputmethod.EditorInfo) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TextWatcher(android.text.TextWatcher) Typeface(android.graphics.Typeface) Context(android.content.Context) Theme(org.telegram.ui.ActionBar.Theme) Intent(android.content.Intent) LocaleController(org.telegram.messenger.LocaleController) HeaderCell(org.telegram.ui.Cells.HeaderCell) Editable(android.text.Editable) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) ArrayList(java.util.ArrayList) ClipData(android.content.ClipData) ChangeBounds(android.transition.ChangeBounds) ActionBar(org.telegram.ui.ActionBar.ActionBar) SharedConfig(org.telegram.messenger.SharedConfig) PasswordTransformationMethod(android.text.method.PasswordTransformationMethod) Build(android.os.Build) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) R(org.telegram.messenger.R) TextUtils(android.text.TextUtils) LayoutHelper(org.telegram.ui.Components.LayoutHelper) MessagesController(org.telegram.messenger.MessagesController) Gravity(android.view.Gravity) URLEncoder(java.net.URLEncoder) SharedPreferences(android.content.SharedPreferences) TypedValue(android.util.TypedValue) ScrollView(android.widget.ScrollView) Fade(android.transition.Fade) ColorUtils(androidx.core.graphics.ColorUtils) EditText(android.widget.EditText) ValueAnimator(android.animation.ValueAnimator) RadioCell(org.telegram.ui.Cells.RadioCell) TextWatcher(android.text.TextWatcher) Editable(android.text.Editable) EditTextBoldCursor(org.telegram.ui.Components.EditTextBoldCursor) ActionBar(org.telegram.ui.ActionBar.ActionBar) EditText(android.widget.EditText) ShadowSectionCell(org.telegram.ui.Cells.ShadowSectionCell) SharedPreferences(android.content.SharedPreferences) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TextInfoPrivacyCell(org.telegram.ui.Cells.TextInfoPrivacyCell) Intent(android.content.Intent) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) ScrollView(android.widget.ScrollView) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TextSettingsCell(org.telegram.ui.Cells.TextSettingsCell) ScrollView(android.widget.ScrollView) FrameLayout(android.widget.FrameLayout) LinearLayout(android.widget.LinearLayout)

Aggregations

TextSettingsCell (org.telegram.ui.Cells.TextSettingsCell)16 View (android.view.View)14 TextView (android.widget.TextView)12 TextInfoPrivacyCell (org.telegram.ui.Cells.TextInfoPrivacyCell)12 FrameLayout (android.widget.FrameLayout)11 HeaderCell (org.telegram.ui.Cells.HeaderCell)11 LinearLayout (android.widget.LinearLayout)10 ArrayList (java.util.ArrayList)10 Canvas (android.graphics.Canvas)9 Editable (android.text.Editable)9 TextWatcher (android.text.TextWatcher)9 ViewGroup (android.view.ViewGroup)9 ActionBar (org.telegram.ui.ActionBar.ActionBar)9 EditTextBoldCursor (org.telegram.ui.Components.EditTextBoldCursor)9 SuppressLint (android.annotation.SuppressLint)8 Paint (android.graphics.Paint)8 InputFilter (android.text.InputFilter)8 SpannableStringBuilder (android.text.SpannableStringBuilder)8 TextPaint (android.text.TextPaint)8 ScrollView (android.widget.ScrollView)8