❤️ v1.8.0版本的 MD5 值为:13813da8dfbbee8cc971a6875a6e3027

以下内容为反编译后的 PassportActivity.java 源代码,内容仅作参考


package im.giitqbkwzt.ui;

import android.animation.Animator;
import android.animation.AnimatorListenerAdapter;
import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageInfo;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.Rect;
import android.graphics.Typeface;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Vibrator;
import android.telephony.TelephonyManager;
import android.text.Editable;
import android.text.InputFilter;
import android.text.SpannableStringBuilder;
import android.text.StaticLayout;
import android.text.TextPaint;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.text.method.PasswordTransformationMethod;
import android.text.style.ClickableSpan;
import android.text.style.ForegroundColorSpan;
import android.util.Base64;
import android.util.Property;
import android.view.ActionMode;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ScrollView;
import android.widget.TextView;
import androidx.core.content.FileProvider;
import com.blankj.utilcode.constant.TimeConstants;
import com.google.android.exoplayer2.extractor.ts.TsExtractor;
import com.google.firebase.remoteconfig.RemoteConfigConstants;
import im.giitqbkwzt.messenger.AndroidUtilities;
import im.giitqbkwzt.messenger.ApplicationLoader;
import im.giitqbkwzt.messenger.BuildVars;
import im.giitqbkwzt.messenger.DispatchQueue;
import im.giitqbkwzt.messenger.DownloadController;
import im.giitqbkwzt.messenger.FileLoader;
import im.giitqbkwzt.messenger.FileLog;
import im.giitqbkwzt.messenger.ImageLoader;
import im.giitqbkwzt.messenger.ImageLocation;
import im.giitqbkwzt.messenger.LocaleController;
import im.giitqbkwzt.messenger.MediaController;
import im.giitqbkwzt.messenger.MessageObject;
import im.giitqbkwzt.messenger.MrzRecognizer;
import im.giitqbkwzt.messenger.NotificationCenter;
import im.giitqbkwzt.messenger.R;
import im.giitqbkwzt.messenger.SRPHelper;
import im.giitqbkwzt.messenger.SecureDocument;
import im.giitqbkwzt.messenger.SecureDocumentKey;
import im.giitqbkwzt.messenger.SendMessagesHelper;
import im.giitqbkwzt.messenger.SharedConfig;
import im.giitqbkwzt.messenger.UserConfig;
import im.giitqbkwzt.messenger.UserObject;
import im.giitqbkwzt.messenger.Utilities;
import im.giitqbkwzt.messenger.browser.Browser;
import im.giitqbkwzt.phoneformat.PhoneFormat;
import im.giitqbkwzt.tgnet.ConnectionsManager;
import im.giitqbkwzt.tgnet.RequestDelegate;
import im.giitqbkwzt.tgnet.TLObject;
import im.giitqbkwzt.tgnet.TLRPC;
import im.giitqbkwzt.ui.CountrySelectActivity;
import im.giitqbkwzt.ui.DocumentSelectActivity;
import im.giitqbkwzt.ui.MrzCameraActivity;
import im.giitqbkwzt.ui.PassportActivity;
import im.giitqbkwzt.ui.PhotoAlbumPickerActivity;
import im.giitqbkwzt.ui.PhotoViewer;
import im.giitqbkwzt.ui.actionbar.ActionBar;
import im.giitqbkwzt.ui.actionbar.ActionBarMenu;
import im.giitqbkwzt.ui.actionbar.ActionBarMenuItem;
import im.giitqbkwzt.ui.actionbar.AlertDialog;
import im.giitqbkwzt.ui.actionbar.BaseFragment;
import im.giitqbkwzt.ui.actionbar.Theme;
import im.giitqbkwzt.ui.actionbar.ThemeDescription;
import im.giitqbkwzt.ui.cells.CheckBoxCell;
import im.giitqbkwzt.ui.cells.HeaderCell;
import im.giitqbkwzt.ui.cells.ShadowSectionCell;
import im.giitqbkwzt.ui.cells.TextDetailSettingsCell;
import im.giitqbkwzt.ui.cells.TextInfoPrivacyCell;
import im.giitqbkwzt.ui.cells.TextSettingsCell;
import im.giitqbkwzt.ui.components.AlertsCreator;
import im.giitqbkwzt.ui.components.AvatarDrawable;
import im.giitqbkwzt.ui.components.BackupImageView;
import im.giitqbkwzt.ui.components.ChatAttachAlert;
import im.giitqbkwzt.ui.components.ContextProgressView;
import im.giitqbkwzt.ui.components.EditTextBoldCursor;
import im.giitqbkwzt.ui.components.EmptyTextProgressView;
import im.giitqbkwzt.ui.components.HintEditText;
import im.giitqbkwzt.ui.components.LayoutHelper;
import im.giitqbkwzt.ui.components.RadialProgress;
import im.giitqbkwzt.ui.components.SlideView;
import im.giitqbkwzt.ui.components.URLSpanNoUnderline;
import im.giitqbkwzt.ui.components.toast.ToastUtils;
import im.giitqbkwzt.ui.hui.visualcall.PermissionUtils;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.io.RandomAccessFile;
import java.security.KeyFactory;
import java.security.interfaces.RSAPublicKey;
import java.security.spec.X509EncodedKeySpec;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Timer;
import java.util.TimerTask;
import javax.crypto.Cipher;
import kotlin.UByte;
import kotlin.text.Typography;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Marker;

public class PassportActivity extends BaseFragment implements NotificationCenter.NotificationCenterDelegate {
    private static final int FIELD_ADDRESS_COUNT = 6;
    private static final int FIELD_BIRTHDAY = 3;
    private static final int FIELD_CARDNUMBER = 7;
    private static final int FIELD_CITIZENSHIP = 5;
    private static final int FIELD_CITY = 3;
    private static final int FIELD_COUNTRY = 5;
    private static final int FIELD_EMAIL = 0;
    private static final int FIELD_EXPIRE = 8;
    private static final int FIELD_GENDER = 4;
    private static final int FIELD_IDENTITY_COUNT = 9;
    private static final int FIELD_IDENTITY_NODOC_COUNT = 7;
    private static final int FIELD_MIDNAME = 1;
    private static final int FIELD_NAME = 0;
    private static final int FIELD_NATIVE_COUNT = 3;
    private static final int FIELD_NATIVE_MIDNAME = 1;
    private static final int FIELD_NATIVE_NAME = 0;
    private static final int FIELD_NATIVE_SURNAME = 2;
    private static final int FIELD_PASSWORD = 0;
    private static final int FIELD_PHONE = 2;
    private static final int FIELD_PHONECODE = 1;
    private static final int FIELD_PHONECOUNTRY = 0;
    private static final int FIELD_POSTCODE = 2;
    private static final int FIELD_RESIDENCE = 6;
    private static final int FIELD_STATE = 4;
    private static final int FIELD_STREET1 = 0;
    private static final int FIELD_STREET2 = 1;
    private static final int FIELD_SURNAME = 2;
    public static final int TYPE_ADDRESS = 2;
    public static final int TYPE_EMAIL = 4;
    public static final int TYPE_EMAIL_VERIFICATION = 6;
    public static final int TYPE_IDENTITY = 1;
    public static final int TYPE_MANAGE = 8;
    public static final int TYPE_PASSWORD = 5;
    public static final int TYPE_PHONE = 3;
    public static final int TYPE_PHONE_VERIFICATION = 7;
    public static final int TYPE_REQUEST = 0;
    private static final int UPLOADING_TYPE_DOCUMENTS = 0;
    private static final int UPLOADING_TYPE_FRONT = 2;
    private static final int UPLOADING_TYPE_REVERSE = 3;
    private static final int UPLOADING_TYPE_SELFIE = 1;
    private static final int UPLOADING_TYPE_TRANSLATION = 4;
    private static final int attach_document = 4;
    private static final int attach_gallery = 1;
    private static final int attach_photo = 0;
    private static final int done_button = 2;
    private static final int info_item = 1;
    private TextView acceptTextView;
    private TextSettingsCell addDocumentCell;
    private ShadowSectionCell addDocumentSectionCell;
    private boolean allowNonLatinName;
    private ArrayList<TLRPC.TL_secureRequiredType> availableDocumentTypes;
    private TextInfoPrivacyCell bottomCell;
    private TextInfoPrivacyCell bottomCellTranslation;
    private FrameLayout bottomLayout;
    private boolean callbackCalled;
    private ChatAttachAlert chatAttachAlert;
    private HashMap<String, String> codesMap;
    private ArrayList<String> countriesArray;
    private HashMap<String, String> countriesMap;
    private int currentActivityType;
    private int currentBotId;
    private String currentCallbackUrl;
    private String currentCitizeship;
    private HashMap<String, String> currentDocumentValues;
    private TLRPC.TL_secureRequiredType currentDocumentsType;
    private TLRPC.TL_secureValue currentDocumentsTypeValue;
    private String currentEmail;
    private int[] currentExpireDate;
    private TLRPC.TL_account_authorizationForm currentForm;
    private String currentGender;
    private String currentNonce;
    private TLRPC.TL_account_password currentPassword;
    private String currentPayload;
    private TLRPC.TL_auth_sentCode currentPhoneVerification;
    private LinearLayout currentPhotoViewerLayout;
    private String currentPicturePath;
    private String currentPublicKey;
    private String currentResidence;
    private String currentScope;
    private TLRPC.TL_secureRequiredType currentType;
    private TLRPC.TL_secureValue currentTypeValue;
    private HashMap<String, String> currentValues;
    private int currentViewNum;
    private PassportActivityDelegate delegate;
    private TextSettingsCell deletePassportCell;
    private ArrayList<View> dividers;
    private boolean documentOnly;
    private ArrayList<SecureDocument> documents;
    private HashMap<SecureDocument, SecureDocumentCell> documentsCells;
    private HashMap<String, String> documentsErrors;
    private LinearLayout documentsLayout;
    private HashMap<TLRPC.TL_secureRequiredType, TLRPC.TL_secureRequiredType> documentsToTypesLink;
    private ActionBarMenuItem doneItem;
    private AnimatorSet doneItemAnimation;
    private int emailCodeLength;
    private ImageView emptyImageView;
    private LinearLayout emptyLayout;
    private TextView emptyTextView1;
    private TextView emptyTextView2;
    private TextView emptyTextView3;
    private EmptyTextProgressView emptyView;
    private HashMap<String, HashMap<String, String>> errorsMap;
    private HashMap<String, String> errorsValues;
    private View extraBackgroundView;
    private View extraBackgroundView2;
    private HashMap<String, String> fieldsErrors;
    private SecureDocument frontDocument;
    private LinearLayout frontLayout;
    private HeaderCell headerCell;
    private boolean ignoreOnFailure;
    private boolean ignoreOnPhoneChange;
    private boolean ignoreOnTextChange;
    private String initialValues;
    private EditTextBoldCursor[] inputExtraFields;
    private ViewGroup[] inputFieldContainers;
    private EditTextBoldCursor[] inputFields;
    private HashMap<String, String> languageMap;
    private LinearLayout linearLayout2;
    private HashMap<String, String> mainErrorsMap;
    private TextInfoPrivacyCell nativeInfoCell;
    private boolean needActivityResult;
    private CharSequence noAllDocumentsErrorText;
    private CharSequence noAllTranslationErrorText;
    private ImageView noPasswordImageView;
    private TextView noPasswordSetTextView;
    private TextView noPasswordTextView;
    private boolean[] nonLatinNames;
    private FrameLayout passwordAvatarContainer;
    private TextView passwordForgotButton;
    private TextInfoPrivacyCell passwordInfoRequestTextView;
    private TextInfoPrivacyCell passwordRequestTextView;
    private PassportActivityDelegate pendingDelegate;
    private ErrorRunnable pendingErrorRunnable;
    private Runnable pendingFinishRunnable;
    private String pendingPhone;
    private Dialog permissionsDialog;
    private ArrayList<String> permissionsItems;
    private HashMap<String, String> phoneFormatMap;
    private TextView plusTextView;
    private PassportActivity presentAfterAnimation;
    private AlertDialog progressDialog;
    private ContextProgressView progressView;
    private ContextProgressView progressViewButton;
    private PhotoViewer.PhotoViewerProvider provider;
    private SecureDocument reverseDocument;
    private LinearLayout reverseLayout;
    private byte[] saltedPassword;
    private byte[] savedPasswordHash;
    private byte[] savedSaltedPassword;
    private TextSettingsCell scanDocumentCell;
    private int scrollHeight;
    private ScrollView scrollView;
    private ShadowSectionCell sectionCell;
    private ShadowSectionCell sectionCell2;
    private byte[] secureSecret;
    private long secureSecretId;
    private SecureDocument selfieDocument;
    private LinearLayout selfieLayout;
    private TextInfoPrivacyCell topErrorCell;
    private ArrayList<SecureDocument> translationDocuments;
    private LinearLayout translationLayout;
    private HashMap<TLRPC.TL_secureRequiredType, HashMap<String, String>> typesValues;
    private HashMap<TLRPC.TL_secureRequiredType, TextDetailSecureCell> typesViews;
    private TextSettingsCell uploadDocumentCell;
    private TextDetailSettingsCell uploadFrontCell;
    private TextDetailSettingsCell uploadReverseCell;
    private TextDetailSettingsCell uploadSelfieCell;
    private TextSettingsCell uploadTranslationCell;
    private HashMap<String, SecureDocument> uploadingDocuments;
    private int uploadingFileType;
    private boolean useCurrentValue;
    private int usingSavedPassword;
    private SlideView[] views;

    public interface ErrorRunnable {
        void onError(String str, String str2);
    }

    public interface PassportActivityDelegate {
        void deleteValue(TLRPC.TL_secureRequiredType tL_secureRequiredType, TLRPC.TL_secureRequiredType tL_secureRequiredType2, ArrayList<TLRPC.TL_secureRequiredType> arrayList, boolean z, Runnable runnable, ErrorRunnable errorRunnable);

        SecureDocument saveFile(TLRPC.TL_secureFile tL_secureFile);

        void saveValue(TLRPC.TL_secureRequiredType tL_secureRequiredType, String str, String str2, TLRPC.TL_secureRequiredType tL_secureRequiredType2, String str3, ArrayList<SecureDocument> arrayList, SecureDocument secureDocument, ArrayList<SecureDocument> arrayList2, SecureDocument secureDocument2, SecureDocument secureDocument3, Runnable runnable, ErrorRunnable errorRunnable);
    }

    public class LinkSpan extends ClickableSpan {
        public LinkSpan() {
        }

        @Override
        public void updateDrawState(TextPaint ds) {
            super.updateDrawState(ds);
            ds.setUnderlineText(true);
            ds.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        }

        @Override
        public void onClick(View widget) {
            Browser.openUrl(PassportActivity.this.getParentActivity(), PassportActivity.this.currentForm.privacy_policy_url);
        }
    }

    public class TextDetailSecureCell extends FrameLayout {
        private ImageView checkImageView;
        private boolean needDivider;
        private TextView textView;
        private TextView valueTextView;

        public TextDetailSecureCell(Context context) {
            super(context);
            int padding = PassportActivity.this.currentActivityType == 8 ? 21 : 51;
            TextView textView = new TextView(context);
            this.textView = textView;
            textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.textView.setTextSize(1, 16.0f);
            this.textView.setLines(1);
            this.textView.setMaxLines(1);
            this.textView.setSingleLine(true);
            this.textView.setEllipsize(TextUtils.TruncateAt.END);
            this.textView.setGravity((LocaleController.isRTL ? 5 : 3) | 16);
            addView(this.textView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, LocaleController.isRTL ? padding : 21, 10.0f, LocaleController.isRTL ? 21 : padding, 0.0f));
            TextView textView2 = new TextView(context);
            this.valueTextView = textView2;
            textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
            this.valueTextView.setTextSize(1, 13.0f);
            this.valueTextView.setGravity(LocaleController.isRTL ? 5 : 3);
            this.valueTextView.setLines(1);
            this.valueTextView.setMaxLines(1);
            this.valueTextView.setSingleLine(true);
            this.valueTextView.setEllipsize(TextUtils.TruncateAt.END);
            this.valueTextView.setPadding(0, 0, 0, 0);
            addView(this.valueTextView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, LocaleController.isRTL ? padding : 21, 35.0f, LocaleController.isRTL ? 21 : padding, 0.0f));
            ImageView imageView = new ImageView(context);
            this.checkImageView = imageView;
            imageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_featuredStickers_addedIcon), PorterDuff.Mode.SRC_IN));
            this.checkImageView.setImageResource(R.mipmap.ic_selected);
            addView(this.checkImageView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 3 : 5) | 48, 21.0f, 25.0f, 21.0f, 0.0f));
        }

        @Override
        protected void onMeasure(int i, int i2) {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(i), 1073741824), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64.0f) + (this.needDivider ? 1 : 0), 1073741824));
        }

        public void setTextAndValue(String text, CharSequence value, boolean divider) {
            this.textView.setText(text);
            this.valueTextView.setText(value);
            this.needDivider = divider;
            setWillNotDraw(!divider);
        }

        public void setChecked(boolean checked) {
            this.checkImageView.setVisibility(checked ? 0 : 4);
        }

        public void setValue(CharSequence value) {
            this.valueTextView.setText(value);
        }

        public void setNeedDivider(boolean value) {
            this.needDivider = value;
            setWillNotDraw(!value);
            invalidate();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            if (this.needDivider) {
                canvas.drawLine(LocaleController.isRTL ? 0.0f : AndroidUtilities.dp(20.0f), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20.0f) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
            }
        }
    }

    public class SecureDocumentCell extends FrameLayout implements DownloadController.FileDownloadProgressListener {
        private int TAG;
        private int buttonState;
        private SecureDocument currentSecureDocument;
        private BackupImageView imageView;
        private RadialProgress radialProgress;
        private TextView textView;
        private TextView valueTextView;

        public SecureDocumentCell(Context context) {
            super(context);
            this.TAG = DownloadController.getInstance(PassportActivity.this.currentAccount).generateObserverTag();
            this.radialProgress = new RadialProgress(this);
            BackupImageView backupImageView = new BackupImageView(context);
            this.imageView = backupImageView;
            addView(backupImageView, LayoutHelper.createFrame(48.0f, 48.0f, (LocaleController.isRTL ? 5 : 3) | 48, 21.0f, 8.0f, 21.0f, 0.0f));
            TextView textView = new TextView(context);
            this.textView = textView;
            textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.textView.setTextSize(1, 16.0f);
            this.textView.setLines(1);
            this.textView.setMaxLines(1);
            this.textView.setSingleLine(true);
            this.textView.setEllipsize(TextUtils.TruncateAt.END);
            this.textView.setGravity((LocaleController.isRTL ? 5 : 3) | 16);
            addView(this.textView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, LocaleController.isRTL ? 21 : 81, 10.0f, LocaleController.isRTL ? 81 : 21, 0.0f));
            TextView textView2 = new TextView(context);
            this.valueTextView = textView2;
            textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
            this.valueTextView.setTextSize(1, 13.0f);
            this.valueTextView.setGravity(LocaleController.isRTL ? 5 : 3);
            this.valueTextView.setLines(1);
            this.valueTextView.setMaxLines(1);
            this.valueTextView.setSingleLine(true);
            this.valueTextView.setPadding(0, 0, 0, 0);
            addView(this.valueTextView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, LocaleController.isRTL ? 21 : 81, 35.0f, LocaleController.isRTL ? 81 : 21, 0.0f));
            setWillNotDraw(false);
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            super.onMeasure(View.MeasureSpec.makeMeasureSpec(View.MeasureSpec.getSize(widthMeasureSpec), 1073741824), View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(64.0f) + 1, 1073741824));
        }

        @Override
        protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
            super.onLayout(changed, left, top, right, bottom);
            int x = this.imageView.getLeft() + ((this.imageView.getMeasuredWidth() - AndroidUtilities.dp(24.0f)) / 2);
            int y = this.imageView.getTop() + ((this.imageView.getMeasuredHeight() - AndroidUtilities.dp(24.0f)) / 2);
            this.radialProgress.setProgressRect(x, y, AndroidUtilities.dp(24.0f) + x, AndroidUtilities.dp(24.0f) + y);
        }

        @Override
        protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
            boolean result = super.drawChild(canvas, child, drawingTime);
            if (child == this.imageView) {
                this.radialProgress.draw(canvas);
            }
            return result;
        }

        public void setTextAndValueAndImage(String text, CharSequence value, SecureDocument document) {
            this.textView.setText(text);
            this.valueTextView.setText(value);
            this.imageView.setImage(document, "48_48");
            this.currentSecureDocument = document;
            updateButtonState(false);
        }

        public void setValue(CharSequence value) {
            this.valueTextView.setText(value);
        }

        public void updateButtonState(boolean animated) {
            String fileName = FileLoader.getAttachFileName(this.currentSecureDocument);
            File path = FileLoader.getPathToAttach(this.currentSecureDocument);
            boolean fileExists = path.exists();
            if (TextUtils.isEmpty(fileName)) {
                this.radialProgress.setBackground(null, false, false);
                return;
            }
            if (this.currentSecureDocument.path != null) {
                if (this.currentSecureDocument.inputFile != null) {
                    DownloadController.getInstance(PassportActivity.this.currentAccount).removeLoadingFileObserver(this);
                    this.radialProgress.setBackground(null, false, animated);
                    this.buttonState = -1;
                    return;
                } else {
                    DownloadController.getInstance(PassportActivity.this.currentAccount).addLoadingFileObserver(this.currentSecureDocument.path, this);
                    this.buttonState = 1;
                    Float progress = ImageLoader.getInstance().getFileProgress(this.currentSecureDocument.path);
                    this.radialProgress.setBackground(Theme.chat_photoStatesDrawables[5][0], true, animated);
                    this.radialProgress.setProgress(progress != null ? progress.floatValue() : 0.0f, false);
                    invalidate();
                    return;
                }
            }
            if (fileExists) {
                DownloadController.getInstance(PassportActivity.this.currentAccount).removeLoadingFileObserver(this);
                this.buttonState = -1;
                this.radialProgress.setBackground(null, false, animated);
                invalidate();
                return;
            }
            DownloadController.getInstance(PassportActivity.this.currentAccount).addLoadingFileObserver(fileName, this);
            this.buttonState = 1;
            Float progress2 = ImageLoader.getInstance().getFileProgress(fileName);
            this.radialProgress.setBackground(Theme.chat_photoStatesDrawables[5][0], true, animated);
            this.radialProgress.setProgress(progress2 != null ? progress2.floatValue() : 0.0f, animated);
            invalidate();
        }

        @Override
        public void invalidate() {
            super.invalidate();
            this.textView.invalidate();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            canvas.drawLine(LocaleController.isRTL ? 0.0f : AndroidUtilities.dp(20.0f), getMeasuredHeight() - 1, getMeasuredWidth() - (LocaleController.isRTL ? AndroidUtilities.dp(20.0f) : 0), getMeasuredHeight() - 1, Theme.dividerPaint);
        }

        @Override
        public void onFailedDownload(String fileName, boolean canceled) {
            updateButtonState(false);
        }

        @Override
        public void onSuccessDownload(String fileName) {
            this.radialProgress.setProgress(1.0f, true);
            updateButtonState(true);
        }

        @Override
        public void onProgressDownload(String fileName, float progress) {
            this.radialProgress.setProgress(progress, true);
            if (this.buttonState != 1) {
                updateButtonState(false);
            }
        }

        @Override
        public void onProgressUpload(String fileName, float progress, boolean isEncrypted) {
            this.radialProgress.setProgress(progress, true);
        }

        @Override
        public int getObserverTag() {
            return this.TAG;
        }
    }

    public PassportActivity(int type, int botId, String scope, String publicKey, String payload, String nonce, String callbackUrl, TLRPC.TL_account_authorizationForm form, TLRPC.TL_account_password accountPassword) {
        this(type, form, accountPassword, (TLRPC.TL_secureRequiredType) null, (TLRPC.TL_secureValue) null, (TLRPC.TL_secureRequiredType) null, (TLRPC.TL_secureValue) null, (HashMap<String, String>) null, (HashMap<String, String>) null);
        int size;
        boolean found;
        String description;
        String target;
        String target2;
        String hash;
        char c;
        TLRPC.TL_account_authorizationForm tL_account_authorizationForm = form;
        this.currentBotId = botId;
        this.currentPayload = payload;
        this.currentNonce = nonce;
        this.currentScope = scope;
        this.currentPublicKey = publicKey;
        this.currentCallbackUrl = callbackUrl;
        if (type == 0 && !tL_account_authorizationForm.errors.isEmpty()) {
            try {
                Collections.sort(tL_account_authorizationForm.errors, new Comparator<TLRPC.SecureValueError>() {
                    int getErrorValue(TLRPC.SecureValueError error) {
                        if (error instanceof TLRPC.TL_secureValueError) {
                            return 0;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorFrontSide) {
                            return 1;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorReverseSide) {
                            return 2;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorSelfie) {
                            return 3;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorTranslationFile) {
                            return 4;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorTranslationFiles) {
                            return 5;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorFile) {
                            return 6;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorFiles) {
                            return 7;
                        }
                        if (error instanceof TLRPC.TL_secureValueErrorData) {
                            TLRPC.TL_secureValueErrorData errorData = (TLRPC.TL_secureValueErrorData) error;
                            return PassportActivity.this.getFieldCost(errorData.field);
                        }
                        return 100;
                    }

                    @Override
                    public int compare(TLRPC.SecureValueError e1, TLRPC.SecureValueError e2) {
                        int val1 = getErrorValue(e1);
                        int val2 = getErrorValue(e2);
                        if (val1 < val2) {
                            return -1;
                        }
                        if (val1 > val2) {
                            return 1;
                        }
                        return 0;
                    }
                });
                int a = 0;
                int size2 = tL_account_authorizationForm.errors.size();
                while (a < size2) {
                    TLRPC.SecureValueError secureValueError = tL_account_authorizationForm.errors.get(a);
                    String field = null;
                    byte[] file_hash = null;
                    if (secureValueError instanceof TLRPC.TL_secureValueErrorFrontSide) {
                        TLRPC.TL_secureValueErrorFrontSide secureValueErrorFrontSide = (TLRPC.TL_secureValueErrorFrontSide) secureValueError;
                        String key = getNameForType(secureValueErrorFrontSide.type);
                        String key2 = secureValueErrorFrontSide.text;
                        file_hash = secureValueErrorFrontSide.file_hash;
                        description = key2;
                        int i = size2;
                        target = "front";
                        target2 = key;
                        size = i;
                    } else if (secureValueError instanceof TLRPC.TL_secureValueErrorReverseSide) {
                        TLRPC.TL_secureValueErrorReverseSide secureValueErrorReverseSide = (TLRPC.TL_secureValueErrorReverseSide) secureValueError;
                        String key3 = getNameForType(secureValueErrorReverseSide.type);
                        size = size2;
                        String description2 = secureValueErrorReverseSide.text;
                        file_hash = secureValueErrorReverseSide.file_hash;
                        target = "reverse";
                        target2 = key3;
                        description = description2;
                    } else {
                        size = size2;
                        if (secureValueError instanceof TLRPC.TL_secureValueErrorSelfie) {
                            TLRPC.TL_secureValueErrorSelfie secureValueErrorSelfie = (TLRPC.TL_secureValueErrorSelfie) secureValueError;
                            String key4 = getNameForType(secureValueErrorSelfie.type);
                            description = secureValueErrorSelfie.text;
                            file_hash = secureValueErrorSelfie.file_hash;
                            target = "selfie";
                            target2 = key4;
                        } else if (secureValueError instanceof TLRPC.TL_secureValueErrorTranslationFile) {
                            TLRPC.TL_secureValueErrorTranslationFile secureValueErrorTranslationFile = (TLRPC.TL_secureValueErrorTranslationFile) secureValueError;
                            String key5 = getNameForType(secureValueErrorTranslationFile.type);
                            description = secureValueErrorTranslationFile.text;
                            file_hash = secureValueErrorTranslationFile.file_hash;
                            target = "translation";
                            target2 = key5;
                        } else if (secureValueError instanceof TLRPC.TL_secureValueErrorTranslationFiles) {
                            TLRPC.TL_secureValueErrorTranslationFiles secureValueErrorTranslationFiles = (TLRPC.TL_secureValueErrorTranslationFiles) secureValueError;
                            String key6 = getNameForType(secureValueErrorTranslationFiles.type);
                            description = secureValueErrorTranslationFiles.text;
                            target = "translation";
                            target2 = key6;
                        } else if (secureValueError instanceof TLRPC.TL_secureValueErrorFile) {
                            TLRPC.TL_secureValueErrorFile secureValueErrorFile = (TLRPC.TL_secureValueErrorFile) secureValueError;
                            String key7 = getNameForType(secureValueErrorFile.type);
                            description = secureValueErrorFile.text;
                            file_hash = secureValueErrorFile.file_hash;
                            target = "files";
                            target2 = key7;
                        } else if (secureValueError instanceof TLRPC.TL_secureValueErrorFiles) {
                            TLRPC.TL_secureValueErrorFiles secureValueErrorFiles = (TLRPC.TL_secureValueErrorFiles) secureValueError;
                            String key8 = getNameForType(secureValueErrorFiles.type);
                            description = secureValueErrorFiles.text;
                            target = "files";
                            target2 = key8;
                        } else if (!(secureValueError instanceof TLRPC.TL_secureValueError)) {
                            if (secureValueError instanceof TLRPC.TL_secureValueErrorData) {
                                TLRPC.TL_secureValueErrorData secureValueErrorData = (TLRPC.TL_secureValueErrorData) secureValueError;
                                boolean found2 = false;
                                int b = 0;
                                while (true) {
                                    boolean found3 = found2;
                                    if (b < tL_account_authorizationForm.values.size()) {
                                        TLRPC.TL_secureValue value = tL_account_authorizationForm.values.get(b);
                                        TLRPC.SecureValueError secureValueError2 = secureValueError;
                                        found = (value.data != null && Arrays.equals(value.data.data_hash, secureValueErrorData.data_hash)) ? true : found;
                                        b++;
                                        found2 = found3;
                                        secureValueError = secureValueError2;
                                    } else {
                                        found = found3;
                                    }
                                }
                                if (found) {
                                    String key9 = getNameForType(secureValueErrorData.type);
                                    description = secureValueErrorData.text;
                                    field = secureValueErrorData.field;
                                    file_hash = secureValueErrorData.data_hash;
                                    target = "data";
                                    target2 = key9;
                                }
                            }
                            a++;
                            tL_account_authorizationForm = form;
                            size2 = size;
                        } else {
                            TLRPC.TL_secureValueError secureValueErrorAll = (TLRPC.TL_secureValueError) secureValueError;
                            String key10 = getNameForType(secureValueErrorAll.type);
                            description = secureValueErrorAll.text;
                            file_hash = secureValueErrorAll.hash;
                            target = "error_all";
                            target2 = key10;
                        }
                    }
                    HashMap<String, String> vals = this.errorsMap.get(target2);
                    if (vals == null) {
                        vals = new HashMap<>();
                        this.errorsMap.put(target2, vals);
                        this.mainErrorsMap.put(target2, description);
                    }
                    if (file_hash != null) {
                        hash = Base64.encodeToString(file_hash, 2);
                    } else {
                        hash = "";
                    }
                    switch (target.hashCode()) {
                        case -1840647503:
                            if (target.equals("translation")) {
                                c = 3;
                                break;
                            }
                            break;
                        case -906020504:
                            if (target.equals("selfie")) {
                                c = 2;
                                break;
                            }
                            break;
                        case 3076010:
                            if (target.equals("data")) {
                                c = 0;
                                break;
                            }
                            break;
                        case 97434231:
                            if (target.equals("files")) {
                                c = 1;
                                break;
                            }
                            break;
                        case 97705513:
                            if (target.equals("front")) {
                                c = 4;
                                break;
                            }
                            break;
                        case 329856746:
                            if (target.equals("error_all")) {
                                c = 6;
                                break;
                            }
                            break;
                        case 1099846370:
                            if (target.equals("reverse")) {
                                c = 5;
                                break;
                            }
                            break;
                    }
                    c = 65535;
                    switch (c) {
                        case 0:
                            if (field == null) {
                                break;
                            } else {
                                vals.put(field, description);
                                break;
                            }
                        case 1:
                            if (file_hash != null) {
                                vals.put("files" + hash, description);
                                break;
                            } else {
                                vals.put("files_all", description);
                                break;
                            }
                        case 2:
                            vals.put("selfie" + hash, description);
                            break;
                        case 3:
                            if (file_hash != null) {
                                vals.put("translation" + hash, description);
                                break;
                            } else {
                                vals.put("translation_all", description);
                                break;
                            }
                        case 4:
                            vals.put("front" + hash, description);
                            break;
                        case 5:
                            vals.put("reverse" + hash, description);
                            break;
                        case 6:
                            vals.put("error_all", description);
                            break;
                    }
                    a++;
                    tL_account_authorizationForm = form;
                    size2 = size;
                }
            } catch (Exception e) {
            }
        }
    }

    public PassportActivity(int type, TLRPC.TL_account_authorizationForm form, TLRPC.TL_account_password accountPassword, TLRPC.TL_secureRequiredType secureType, TLRPC.TL_secureValue secureValue, TLRPC.TL_secureRequiredType secureDocumentsType, TLRPC.TL_secureValue secureDocumentsValue, HashMap<String, String> values, HashMap<String, String> documentValues) {
        this.currentCitizeship = "";
        this.currentResidence = "";
        this.currentExpireDate = new int[3];
        this.dividers = new ArrayList<>();
        this.nonLatinNames = new boolean[3];
        this.allowNonLatinName = true;
        this.countriesArray = new ArrayList<>();
        this.countriesMap = new HashMap<>();
        this.codesMap = new HashMap<>();
        this.phoneFormatMap = new HashMap<>();
        this.documents = new ArrayList<>();
        this.translationDocuments = new ArrayList<>();
        this.documentsCells = new HashMap<>();
        this.uploadingDocuments = new HashMap<>();
        this.typesValues = new HashMap<>();
        this.typesViews = new HashMap<>();
        this.documentsToTypesLink = new HashMap<>();
        this.errorsMap = new HashMap<>();
        this.mainErrorsMap = new HashMap<>();
        this.errorsValues = new HashMap<>();
        this.provider = new PhotoViewer.EmptyPhotoViewerProvider() {
            @Override
            public PhotoViewer.PlaceProviderObject getPlaceForPhoto(MessageObject messageObject, TLRPC.FileLocation fileLocation, int index, boolean needPreview) {
                if (index >= 0 && index < PassportActivity.this.currentPhotoViewerLayout.getChildCount()) {
                    SecureDocumentCell cell = (SecureDocumentCell) PassportActivity.this.currentPhotoViewerLayout.getChildAt(index);
                    int[] coords = new int[2];
                    cell.imageView.getLocationInWindow(coords);
                    PhotoViewer.PlaceProviderObject object = new PhotoViewer.PlaceProviderObject();
                    object.viewX = coords[0];
                    object.viewY = coords[1] - (Build.VERSION.SDK_INT < 21 ? AndroidUtilities.statusBarHeight : 0);
                    object.parentView = PassportActivity.this.currentPhotoViewerLayout;
                    object.imageReceiver = cell.imageView.getImageReceiver();
                    object.thumb = object.imageReceiver.getBitmapSafe();
                    return object;
                }
                return null;
            }

            @Override
            public void deleteImageAtIndex(int index) {
                SecureDocument document = PassportActivity.this.uploadingFileType == 1 ? PassportActivity.this.selfieDocument : PassportActivity.this.uploadingFileType == 4 ? (SecureDocument) PassportActivity.this.translationDocuments.get(index) : PassportActivity.this.uploadingFileType == 2 ? PassportActivity.this.frontDocument : PassportActivity.this.uploadingFileType == 3 ? PassportActivity.this.reverseDocument : (SecureDocument) PassportActivity.this.documents.get(index);
                SecureDocumentCell cell = (SecureDocumentCell) PassportActivity.this.documentsCells.remove(document);
                if (cell == null) {
                    return;
                }
                String key = null;
                String hash = PassportActivity.this.getDocumentHash(document);
                if (PassportActivity.this.uploadingFileType == 1) {
                    PassportActivity.this.selfieDocument = null;
                    key = "selfie" + hash;
                } else if (PassportActivity.this.uploadingFileType != 4) {
                    if (PassportActivity.this.uploadingFileType == 2) {
                        PassportActivity.this.frontDocument = null;
                        key = "front" + hash;
                    } else if (PassportActivity.this.uploadingFileType == 3) {
                        PassportActivity.this.reverseDocument = null;
                        key = "reverse" + hash;
                    } else if (PassportActivity.this.uploadingFileType == 0) {
                        key = "files" + hash;
                    }
                } else {
                    key = "translation" + hash;
                }
                if (key != null) {
                    if (PassportActivity.this.documentsErrors != null) {
                        PassportActivity.this.documentsErrors.remove(key);
                    }
                    if (PassportActivity.this.errorsValues != null) {
                        PassportActivity.this.errorsValues.remove(key);
                    }
                }
                PassportActivity passportActivity = PassportActivity.this;
                passportActivity.updateUploadText(passportActivity.uploadingFileType);
                PassportActivity.this.currentPhotoViewerLayout.removeView(cell);
            }

            @Override
            public String getDeleteMessageString() {
                if (PassportActivity.this.uploadingFileType == 1) {
                    return LocaleController.formatString("PassportDeleteSelfieAlert", R.string.PassportDeleteSelfieAlert, new Object[0]);
                }
                return LocaleController.formatString("PassportDeleteScanAlert", R.string.PassportDeleteScanAlert, new Object[0]);
            }
        };
        this.currentActivityType = type;
        this.currentForm = form;
        this.currentType = secureType;
        if (secureType != null) {
            this.allowNonLatinName = secureType.native_names;
        }
        this.currentTypeValue = secureValue;
        this.currentDocumentsType = secureDocumentsType;
        this.currentDocumentsTypeValue = secureDocumentsValue;
        this.currentPassword = accountPassword;
        this.currentValues = values;
        this.currentDocumentValues = documentValues;
        int i = this.currentActivityType;
        if (i == 3) {
            this.permissionsItems = new ArrayList<>();
        } else if (i == 7) {
            this.views = new SlideView[3];
        }
        if (this.currentValues == null) {
            this.currentValues = new HashMap<>();
        }
        if (this.currentDocumentValues == null) {
            this.currentDocumentValues = new HashMap<>();
        }
        if (type == 5) {
            if (UserConfig.getInstance(this.currentAccount).savedPasswordHash != null && UserConfig.getInstance(this.currentAccount).savedSaltedPassword != null) {
                this.usingSavedPassword = 1;
                this.savedPasswordHash = UserConfig.getInstance(this.currentAccount).savedPasswordHash;
                this.savedSaltedPassword = UserConfig.getInstance(this.currentAccount).savedSaltedPassword;
            }
            TLRPC.TL_account_password tL_account_password = this.currentPassword;
            if (tL_account_password == null) {
                loadPasswordInfo();
            } else {
                TwoStepVerificationActivity.initPasswordNewAlgo(tL_account_password);
                if (this.usingSavedPassword == 1) {
                    onPasswordDone(true);
                }
            }
            if (!SharedConfig.isPassportConfigLoaded()) {
                TLRPC.TL_help_getPassportConfig req = new TLRPC.TL_help_getPassportConfig();
                req.hash = SharedConfig.passportConfigHash;
                ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                PassportActivity.lambda$null$0(TLObject.this);
                            }
                        });
                    }
                });
            }
        }
    }

    public static void lambda$null$0(TLObject response) {
        if (response instanceof TLRPC.TL_help_passportConfig) {
            TLRPC.TL_help_passportConfig res = (TLRPC.TL_help_passportConfig) response;
            SharedConfig.setPassportConfig(res.countries_langs.data, res.hash);
        } else {
            SharedConfig.getCountryLangs();
        }
    }

    @Override
    public void onResume() {
        ViewGroup[] viewGroupArr;
        super.onResume();
        ChatAttachAlert chatAttachAlert = this.chatAttachAlert;
        if (chatAttachAlert != null) {
            chatAttachAlert.onResume();
        }
        if (this.currentActivityType == 5 && (viewGroupArr = this.inputFieldContainers) != null && viewGroupArr[0] != null && viewGroupArr[0].getVisibility() == 0) {
            this.inputFields[0].requestFocus();
            AndroidUtilities.showKeyboard(this.inputFields[0]);
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.this.lambda$onResume$2$PassportActivity();
                }
            }, 200L);
        }
        AndroidUtilities.requestAdjustResize(getParentActivity(), this.classGuid);
    }

    public void lambda$onResume$2$PassportActivity() {
        ViewGroup[] viewGroupArr = this.inputFieldContainers;
        if (viewGroupArr != null && viewGroupArr[0] != null && viewGroupArr[0].getVisibility() == 0) {
            this.inputFields[0].requestFocus();
            AndroidUtilities.showKeyboard(this.inputFields[0]);
        }
    }

    @Override
    public void onPause() {
        super.onPause();
        ChatAttachAlert chatAttachAlert = this.chatAttachAlert;
        if (chatAttachAlert != null) {
            chatAttachAlert.onPause();
        }
    }

    @Override
    public boolean onFragmentCreate() {
        NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.FileDidUpload);
        NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.FileDidFailUpload);
        NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.didSetTwoStepPassword);
        NotificationCenter.getInstance(this.currentAccount).addObserver(this, NotificationCenter.didRemoveTwoStepPassword);
        return super.onFragmentCreate();
    }

    @Override
    public void onFragmentDestroy() {
        super.onFragmentDestroy();
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.FileDidUpload);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.FileDidFailUpload);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.didSetTwoStepPassword);
        NotificationCenter.getInstance(this.currentAccount).removeObserver(this, NotificationCenter.didRemoveTwoStepPassword);
        callCallback(false);
        ChatAttachAlert chatAttachAlert = this.chatAttachAlert;
        if (chatAttachAlert != null) {
            chatAttachAlert.dismissInternal();
            this.chatAttachAlert.onDestroy();
        }
        if (this.currentActivityType == 7) {
            int a = 0;
            while (true) {
                SlideView[] slideViewArr = this.views;
                if (a >= slideViewArr.length) {
                    break;
                }
                if (slideViewArr[a] != null) {
                    slideViewArr[a].onDestroyActivity();
                }
                a++;
            }
            AlertDialog alertDialog = this.progressDialog;
            if (alertDialog != null) {
                try {
                    alertDialog.dismiss();
                } catch (Exception e) {
                    FileLog.e(e);
                }
                this.progressDialog = null;
            }
        }
    }

    @Override
    public View createView(Context context) {
        ChatAttachAlert chatAttachAlert;
        this.actionBar.setBackButtonImage(R.mipmap.ic_back);
        this.actionBar.setAllowOverlayTitle(true);
        this.actionBar.setActionBarMenuOnItemClick(new AnonymousClass3());
        if (this.currentActivityType == 7) {
            ScrollView scrollView = new ScrollView(context) {
                @Override
                protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
                    return false;
                }

                @Override
                public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
                    if (PassportActivity.this.currentViewNum == 1 || PassportActivity.this.currentViewNum == 2 || PassportActivity.this.currentViewNum == 4) {
                        rectangle.bottom += AndroidUtilities.dp(40.0f);
                    }
                    return super.requestChildRectangleOnScreen(child, rectangle, immediate);
                }

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    PassportActivity.this.scrollHeight = View.MeasureSpec.getSize(heightMeasureSpec) - AndroidUtilities.dp(30.0f);
                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                }
            };
            this.scrollView = scrollView;
            this.fragmentView = scrollView;
            this.scrollView.setFillViewport(true);
            AndroidUtilities.setScrollViewEdgeEffectColor(this.scrollView, Theme.getColor(Theme.key_actionBarDefault));
        } else {
            this.fragmentView = new FrameLayout(context);
            FrameLayout frameLayout = (FrameLayout) this.fragmentView;
            this.fragmentView.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundGray));
            ScrollView scrollView2 = new ScrollView(context) {
                @Override
                protected boolean onRequestFocusInDescendants(int direction, Rect previouslyFocusedRect) {
                    return false;
                }

                @Override
                public boolean requestChildRectangleOnScreen(View child, Rect rectangle, boolean immediate) {
                    rectangle.offset(child.getLeft() - child.getScrollX(), child.getTop() - child.getScrollY());
                    rectangle.top += AndroidUtilities.dp(20.0f);
                    rectangle.bottom += AndroidUtilities.dp(50.0f);
                    return super.requestChildRectangleOnScreen(child, rectangle, immediate);
                }
            };
            this.scrollView = scrollView2;
            scrollView2.setFillViewport(true);
            AndroidUtilities.setScrollViewEdgeEffectColor(this.scrollView, Theme.getColor(Theme.key_actionBarDefault));
            frameLayout.addView(this.scrollView, LayoutHelper.createFrame(-1.0f, -1.0f, 51, 0.0f, 0.0f, 0.0f, this.currentActivityType == 0 ? 48.0f : 0.0f));
            LinearLayout linearLayout = new LinearLayout(context);
            this.linearLayout2 = linearLayout;
            linearLayout.setOrientation(1);
            this.scrollView.addView(this.linearLayout2, new FrameLayout.LayoutParams(-1, -2));
        }
        int i = this.currentActivityType;
        if (i != 0 && i != 8) {
            ActionBarMenu menu = this.actionBar.createMenu();
            this.doneItem = menu.addItemWithWidth(2, R.drawable.ic_done, AndroidUtilities.dp(56.0f));
            ContextProgressView contextProgressView = new ContextProgressView(context, 1);
            this.progressView = contextProgressView;
            contextProgressView.setAlpha(0.0f);
            this.progressView.setScaleX(0.1f);
            this.progressView.setScaleY(0.1f);
            this.progressView.setVisibility(4);
            this.doneItem.addView(this.progressView, LayoutHelper.createFrame(-1, -1.0f));
            int i2 = this.currentActivityType;
            if ((i2 == 1 || i2 == 2) && (chatAttachAlert = this.chatAttachAlert) != null) {
                try {
                    if (chatAttachAlert.isShowing()) {
                        this.chatAttachAlert.dismiss();
                    }
                } catch (Exception e) {
                }
                this.chatAttachAlert.onDestroy();
                this.chatAttachAlert = null;
            }
        }
        int i3 = this.currentActivityType;
        if (i3 == 5) {
            createPasswordInterface(context);
        } else if (i3 == 0) {
            createRequestInterface(context);
        } else if (i3 == 1) {
            createIdentityInterface(context);
            fillInitialValues();
        } else if (i3 == 2) {
            createAddressInterface(context);
            fillInitialValues();
        } else if (i3 == 3) {
            createPhoneInterface(context);
        } else if (i3 == 4) {
            createEmailInterface(context);
        } else if (i3 == 6) {
            createEmailVerificationInterface(context);
        } else if (i3 == 7) {
            createPhoneVerificationInterface(context);
        } else if (i3 == 8) {
            createManageInterface(context);
        }
        return this.fragmentView;
    }

    public class AnonymousClass3 extends ActionBar.ActionBarMenuOnItemClick {
        AnonymousClass3() {
        }

        private boolean onIdentityDone(final Runnable finishRunnable, final ErrorRunnable errorRunnable) {
            String obj;
            String obj2;
            String obj3;
            char c = 0;
            if (PassportActivity.this.uploadingDocuments.isEmpty() && !PassportActivity.this.checkFieldsForError()) {
                int i = 3;
                char c2 = 2;
                char c3 = 1;
                if (PassportActivity.this.allowNonLatinName) {
                    PassportActivity.this.allowNonLatinName = false;
                    boolean error = false;
                    int a = 0;
                    while (a < PassportActivity.this.nonLatinNames.length) {
                        if (PassportActivity.this.nonLatinNames[a]) {
                            PassportActivity.this.inputFields[a].setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly));
                            if (!error) {
                                error = true;
                                if (!PassportActivity.this.nonLatinNames[c]) {
                                    obj = PassportActivity.this.inputFields[c].getText().toString();
                                } else {
                                    PassportActivity passportActivity = PassportActivity.this;
                                    obj = passportActivity.getTranslitString(passportActivity.inputExtraFields[c].getText().toString());
                                }
                                final String firstName = obj;
                                if (!PassportActivity.this.nonLatinNames[c3]) {
                                    obj2 = PassportActivity.this.inputFields[c3].getText().toString();
                                } else {
                                    PassportActivity passportActivity2 = PassportActivity.this;
                                    obj2 = passportActivity2.getTranslitString(passportActivity2.inputExtraFields[c3].getText().toString());
                                }
                                final String middleName = obj2;
                                if (!PassportActivity.this.nonLatinNames[c2]) {
                                    obj3 = PassportActivity.this.inputFields[c2].getText().toString();
                                } else {
                                    PassportActivity passportActivity3 = PassportActivity.this;
                                    obj3 = passportActivity3.getTranslitString(passportActivity3.inputExtraFields[c2].getText().toString());
                                }
                                final String lastName = obj3;
                                if (!TextUtils.isEmpty(firstName) && !TextUtils.isEmpty(middleName) && !TextUtils.isEmpty(lastName)) {
                                    final int num = a;
                                    AlertDialog.Builder builder = new AlertDialog.Builder(PassportActivity.this.getParentActivity());
                                    Object[] objArr = new Object[i];
                                    objArr[c] = firstName;
                                    objArr[c3] = middleName;
                                    objArr[c2] = lastName;
                                    builder.setMessage(LocaleController.formatString("PassportNameCheckAlert", R.string.PassportNameCheckAlert, objArr));
                                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                                    builder.setPositiveButton(LocaleController.getString("Done", R.string.Done), new DialogInterface.OnClickListener() {
                                        @Override
                                        public final void onClick(DialogInterface dialogInterface, int i2) {
                                            PassportActivity.AnonymousClass3.this.lambda$onIdentityDone$0$PassportActivity$3(firstName, middleName, lastName, finishRunnable, errorRunnable, dialogInterface, i2);
                                        }
                                    });
                                    builder.setNegativeButton(LocaleController.getString("Edit", R.string.Edit), new DialogInterface.OnClickListener() {
                                        @Override
                                        public final void onClick(DialogInterface dialogInterface, int i2) {
                                            PassportActivity.AnonymousClass3.this.lambda$onIdentityDone$1$PassportActivity$3(num, dialogInterface, i2);
                                        }
                                    });
                                    PassportActivity.this.showDialog(builder.create());
                                } else {
                                    PassportActivity passportActivity4 = PassportActivity.this;
                                    passportActivity4.onFieldError(passportActivity4.inputFields[a]);
                                }
                            }
                        }
                        a++;
                        c = 0;
                        i = 3;
                        c2 = 2;
                        c3 = 1;
                    }
                    if (error) {
                        return false;
                    }
                }
                if (PassportActivity.this.isHasNotAnyChanges()) {
                    PassportActivity.this.finishFragment();
                    return false;
                }
                JSONObject json = null;
                JSONObject documentsJson = null;
                try {
                    if (!PassportActivity.this.documentOnly) {
                        HashMap<String, String> valuesToSave = new HashMap<>(PassportActivity.this.currentValues);
                        if (PassportActivity.this.currentType.native_names) {
                            if (PassportActivity.this.nativeInfoCell.getVisibility() == 0) {
                                valuesToSave.put("first_name_native", PassportActivity.this.inputExtraFields[0].getText().toString());
                                valuesToSave.put("middle_name_native", PassportActivity.this.inputExtraFields[1].getText().toString());
                                valuesToSave.put("last_name_native", PassportActivity.this.inputExtraFields[2].getText().toString());
                            } else {
                                valuesToSave.put("first_name_native", PassportActivity.this.inputFields[0].getText().toString());
                                valuesToSave.put("middle_name_native", PassportActivity.this.inputFields[1].getText().toString());
                                valuesToSave.put("last_name_native", PassportActivity.this.inputFields[2].getText().toString());
                            }
                        }
                        valuesToSave.put("first_name", PassportActivity.this.inputFields[0].getText().toString());
                        valuesToSave.put("middle_name", PassportActivity.this.inputFields[1].getText().toString());
                        valuesToSave.put("last_name", PassportActivity.this.inputFields[2].getText().toString());
                        valuesToSave.put("birth_date", PassportActivity.this.inputFields[3].getText().toString());
                        valuesToSave.put("gender", PassportActivity.this.currentGender);
                        valuesToSave.put("country_code", PassportActivity.this.currentCitizeship);
                        valuesToSave.put("residence_country_code", PassportActivity.this.currentResidence);
                        json = new JSONObject();
                        ArrayList<String> keys = new ArrayList<>(valuesToSave.keySet());
                        Collections.sort(keys, new Comparator() {
                            @Override
                            public final int compare(Object obj4, Object obj5) {
                                return PassportActivity.AnonymousClass3.this.lambda$onIdentityDone$2$PassportActivity$3((String) obj4, (String) obj5);
                            }
                        });
                        int size = keys.size();
                        for (int a2 = 0; a2 < size; a2++) {
                            String key = keys.get(a2);
                            json.put(key, valuesToSave.get(key));
                        }
                    }
                    if (PassportActivity.this.currentDocumentsType != null) {
                        HashMap<String, String> valuesToSave2 = new HashMap<>(PassportActivity.this.currentDocumentValues);
                        valuesToSave2.put("document_no", PassportActivity.this.inputFields[7].getText().toString());
                        if (PassportActivity.this.currentExpireDate[0] != 0) {
                            valuesToSave2.put("expiry_date", String.format(Locale.US, "%02d.%02d.%d", Integer.valueOf(PassportActivity.this.currentExpireDate[2]), Integer.valueOf(PassportActivity.this.currentExpireDate[1]), Integer.valueOf(PassportActivity.this.currentExpireDate[0])));
                        } else {
                            valuesToSave2.put("expiry_date", "");
                        }
                        documentsJson = new JSONObject();
                        ArrayList<String> keys2 = new ArrayList<>(valuesToSave2.keySet());
                        Collections.sort(keys2, new Comparator() {
                            @Override
                            public final int compare(Object obj4, Object obj5) {
                                return PassportActivity.AnonymousClass3.this.lambda$onIdentityDone$3$PassportActivity$3((String) obj4, (String) obj5);
                            }
                        });
                        int size2 = keys2.size();
                        for (int a3 = 0; a3 < size2; a3++) {
                            String key2 = keys2.get(a3);
                            documentsJson.put(key2, valuesToSave2.get(key2));
                        }
                    }
                } catch (Exception e) {
                }
                if (PassportActivity.this.fieldsErrors != null) {
                    PassportActivity.this.fieldsErrors.clear();
                }
                if (PassportActivity.this.documentsErrors != null) {
                    PassportActivity.this.documentsErrors.clear();
                }
                PassportActivityDelegate passportActivityDelegate = PassportActivity.this.delegate;
                TLRPC.TL_secureRequiredType tL_secureRequiredType = PassportActivity.this.currentType;
                SecureDocument secureDocument = null;
                String jSONObject = json != null ? json.toString() : null;
                TLRPC.TL_secureRequiredType tL_secureRequiredType2 = PassportActivity.this.currentDocumentsType;
                String jSONObject2 = documentsJson != null ? documentsJson.toString() : null;
                SecureDocument secureDocument2 = PassportActivity.this.selfieDocument;
                ArrayList<SecureDocument> arrayList = PassportActivity.this.translationDocuments;
                SecureDocument secureDocument3 = PassportActivity.this.frontDocument;
                if (PassportActivity.this.reverseLayout != null && PassportActivity.this.reverseLayout.getVisibility() == 0) {
                    secureDocument = PassportActivity.this.reverseDocument;
                }
                passportActivityDelegate.saveValue(tL_secureRequiredType, null, jSONObject, tL_secureRequiredType2, jSONObject2, null, secureDocument2, arrayList, secureDocument3, secureDocument, finishRunnable, errorRunnable);
                return true;
            }
            return false;
        }

        public void lambda$onIdentityDone$0$PassportActivity$3(String firstName, String middleName, String lastName, Runnable finishRunnable, ErrorRunnable errorRunnable, DialogInterface dialogInterface, int i) {
            PassportActivity.this.inputFields[0].setText(firstName);
            PassportActivity.this.inputFields[1].setText(middleName);
            PassportActivity.this.inputFields[2].setText(lastName);
            PassportActivity.this.showEditDoneProgress(true, true);
            onIdentityDone(finishRunnable, errorRunnable);
        }

        public void lambda$onIdentityDone$1$PassportActivity$3(int num, DialogInterface dialogInterface, int i) {
            PassportActivity passportActivity = PassportActivity.this;
            passportActivity.onFieldError(passportActivity.inputFields[num]);
        }

        public int lambda$onIdentityDone$2$PassportActivity$3(String key1, String key2) {
            int val1 = PassportActivity.this.getFieldCost(key1);
            int val2 = PassportActivity.this.getFieldCost(key2);
            if (val1 < val2) {
                return -1;
            }
            if (val1 > val2) {
                return 1;
            }
            return 0;
        }

        public int lambda$onIdentityDone$3$PassportActivity$3(String key1, String key2) {
            int val1 = PassportActivity.this.getFieldCost(key1);
            int val2 = PassportActivity.this.getFieldCost(key2);
            if (val1 < val2) {
                return -1;
            }
            if (val1 > val2) {
                return 1;
            }
            return 0;
        }

        @Override
        public void onItemClick(int id) {
            JSONObject json;
            String value;
            String value2;
            if (id == -1) {
                if (!PassportActivity.this.checkDiscard()) {
                    if (PassportActivity.this.currentActivityType == 0 || PassportActivity.this.currentActivityType == 5) {
                        PassportActivity.this.callCallback(false);
                    }
                    PassportActivity.this.finishFragment();
                    return;
                }
                return;
            }
            if (id == 1) {
                if (PassportActivity.this.getParentActivity() == null) {
                    return;
                }
                TextView message = new TextView(PassportActivity.this.getParentActivity());
                String str2 = LocaleController.getString("PassportInfo2", R.string.PassportInfo2);
                SpannableStringBuilder spanned = new SpannableStringBuilder(str2);
                int index1 = str2.indexOf(42);
                int index2 = str2.lastIndexOf(42);
                if (index1 != -1 && index2 != -1) {
                    spanned.replace(index2, index2 + 1, (CharSequence) "");
                    spanned.replace(index1, index1 + 1, (CharSequence) "");
                    spanned.setSpan(new URLSpanNoUnderline(LocaleController.getString("PassportInfoUrl", R.string.PassportInfoUrl)) {
                        @Override
                        public void onClick(View widget) {
                            PassportActivity.this.dismissCurrentDialog();
                            super.onClick(widget);
                        }
                    }, index1, index2 - 1, 33);
                }
                message.setText(spanned);
                message.setTextSize(1, 16.0f);
                message.setLinkTextColor(Theme.getColor(Theme.key_dialogTextLink));
                message.setHighlightColor(Theme.getColor(Theme.key_dialogLinkSelection));
                message.setPadding(AndroidUtilities.dp(23.0f), 0, AndroidUtilities.dp(23.0f), 0);
                message.setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
                message.setTextColor(Theme.getColor(Theme.key_dialogTextBlack));
                AlertDialog.Builder builder = new AlertDialog.Builder(PassportActivity.this.getParentActivity());
                builder.setView(message);
                builder.setTitle(LocaleController.getString("PassportInfoTitle", R.string.PassportInfoTitle));
                builder.setNegativeButton(LocaleController.getString("Close", R.string.Close), null);
                PassportActivity.this.showDialog(builder.create());
                return;
            }
            if (id == 2) {
                if (PassportActivity.this.currentActivityType == 5) {
                    PassportActivity.this.onPasswordDone(false);
                    return;
                }
                if (PassportActivity.this.currentActivityType == 7) {
                    PassportActivity.this.views[PassportActivity.this.currentViewNum].onNextPressed();
                    return;
                }
                final Runnable finishRunnable = new Runnable() {
                    @Override
                    public final void run() {
                        PassportActivity.AnonymousClass3.this.lambda$onItemClick$4$PassportActivity$3();
                    }
                };
                final ErrorRunnable errorRunnable = new ErrorRunnable() {
                    @Override
                    public void onError(String error, String text) {
                        if ("PHONE_VERIFICATION_NEEDED".equals(error)) {
                            PassportActivity.this.startPhoneVerification(true, text, finishRunnable, this, PassportActivity.this.delegate);
                        } else {
                            PassportActivity.this.showEditDoneProgress(true, false);
                        }
                    }
                };
                if (PassportActivity.this.currentActivityType == 4) {
                    if (PassportActivity.this.useCurrentValue) {
                        value2 = PassportActivity.this.currentEmail;
                    } else if (!PassportActivity.this.checkFieldsForError()) {
                        value2 = PassportActivity.this.inputFields[0].getText().toString();
                    } else {
                        return;
                    }
                    PassportActivity.this.delegate.saveValue(PassportActivity.this.currentType, value2, null, null, null, null, null, null, null, null, finishRunnable, errorRunnable);
                } else if (PassportActivity.this.currentActivityType == 3) {
                    if (PassportActivity.this.useCurrentValue) {
                        value = UserConfig.getInstance(PassportActivity.this.currentAccount).getCurrentUser().phone;
                    } else {
                        if (PassportActivity.this.checkFieldsForError()) {
                            return;
                        }
                        value = PassportActivity.this.inputFields[1].getText().toString() + PassportActivity.this.inputFields[2].getText().toString();
                    }
                    PassportActivity.this.delegate.saveValue(PassportActivity.this.currentType, value, null, null, null, null, null, null, null, null, finishRunnable, errorRunnable);
                } else {
                    if (PassportActivity.this.currentActivityType == 2) {
                        if (PassportActivity.this.uploadingDocuments.isEmpty() && !PassportActivity.this.checkFieldsForError()) {
                            if (PassportActivity.this.isHasNotAnyChanges()) {
                                PassportActivity.this.finishFragment();
                                return;
                            }
                            JSONObject json2 = null;
                            try {
                                if (!PassportActivity.this.documentOnly) {
                                    json2 = new JSONObject();
                                    json2.put("street_line1", PassportActivity.this.inputFields[0].getText().toString());
                                    json2.put("street_line2", PassportActivity.this.inputFields[1].getText().toString());
                                    json2.put("post_code", PassportActivity.this.inputFields[2].getText().toString());
                                    json2.put("city", PassportActivity.this.inputFields[3].getText().toString());
                                    json2.put(RemoteConfigConstants.ResponseFieldKey.STATE, PassportActivity.this.inputFields[4].getText().toString());
                                    json2.put("country_code", PassportActivity.this.currentCitizeship);
                                }
                                json = json2;
                            } catch (Exception e) {
                                json = json2;
                            }
                            if (PassportActivity.this.fieldsErrors != null) {
                                PassportActivity.this.fieldsErrors.clear();
                            }
                            if (PassportActivity.this.documentsErrors != null) {
                                PassportActivity.this.documentsErrors.clear();
                            }
                            PassportActivity.this.delegate.saveValue(PassportActivity.this.currentType, null, json != null ? json.toString() : null, PassportActivity.this.currentDocumentsType, null, PassportActivity.this.documents, PassportActivity.this.selfieDocument, PassportActivity.this.translationDocuments, null, null, finishRunnable, errorRunnable);
                        }
                        return;
                    }
                    if (PassportActivity.this.currentActivityType != 1) {
                        if (PassportActivity.this.currentActivityType == 6) {
                            final TLRPC.TL_account_verifyEmail req = new TLRPC.TL_account_verifyEmail();
                            req.email = (String) PassportActivity.this.currentValues.get("email");
                            req.code = PassportActivity.this.inputFields[0].getText().toString();
                            int reqId = ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req, new RequestDelegate() {
                                @Override
                                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                    PassportActivity.AnonymousClass3.this.lambda$onItemClick$6$PassportActivity$3(finishRunnable, errorRunnable, req, tLObject, tL_error);
                                }
                            });
                            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).bindRequestToGuid(reqId, PassportActivity.this.classGuid);
                        }
                    } else if (!onIdentityDone(finishRunnable, errorRunnable)) {
                        return;
                    }
                }
                PassportActivity.this.showEditDoneProgress(true, true);
            }
        }

        public void lambda$onItemClick$4$PassportActivity$3() {
            PassportActivity.this.finishFragment();
        }

        public void lambda$onItemClick$6$PassportActivity$3(final Runnable finishRunnable, final ErrorRunnable errorRunnable, final TLRPC.TL_account_verifyEmail req, TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass3.this.lambda$null$5$PassportActivity$3(error, finishRunnable, errorRunnable, req);
                }
            });
        }

        public void lambda$null$5$PassportActivity$3(TLRPC.TL_error error, Runnable finishRunnable, ErrorRunnable errorRunnable, TLRPC.TL_account_verifyEmail req) {
            if (error == null) {
                PassportActivity.this.delegate.saveValue(PassportActivity.this.currentType, (String) PassportActivity.this.currentValues.get("email"), null, null, null, null, null, null, null, null, finishRunnable, errorRunnable);
            } else {
                AlertsCreator.processError(PassportActivity.this.currentAccount, error, PassportActivity.this, req, new Object[0]);
                errorRunnable.onError(null, null);
            }
        }
    }

    @Override
    public boolean dismissDialogOnPause(Dialog dialog) {
        return dialog != this.chatAttachAlert && super.dismissDialogOnPause(dialog);
    }

    @Override
    public void dismissCurrentDialog() {
        if (this.chatAttachAlert != null) {
            Dialog dialog = this.visibleDialog;
            ChatAttachAlert chatAttachAlert = this.chatAttachAlert;
            if (dialog == chatAttachAlert) {
                chatAttachAlert.closeCamera(false);
                this.chatAttachAlert.dismissInternal();
                this.chatAttachAlert.hideCamera(true);
                return;
            }
        }
        super.dismissCurrentDialog();
    }

    public String getTranslitString(String value) {
        return LocaleController.getInstance().getTranslitString(value, true);
    }

    public int getFieldCost(String key) {
        char c;
        switch (key.hashCode()) {
            case -2006252145:
                if (key.equals("residence_country_code")) {
                    c = '\t';
                    break;
                }
                c = 65535;
                break;
            case -1537298398:
                if (key.equals("last_name_native")) {
                    c = 5;
                    break;
                }
                c = 65535;
                break;
            case -1249512767:
                if (key.equals("gender")) {
                    c = 7;
                    break;
                }
                c = 65535;
                break;
            case -796150911:
                if (key.equals("street_line1")) {
                    c = '\f';
                    break;
                }
                c = 65535;
                break;
            case -796150910:
                if (key.equals("street_line2")) {
                    c = '\r';
                    break;
                }
                c = 65535;
                break;
            case -160985414:
                if (key.equals("first_name")) {
                    c = 0;
                    break;
                }
                c = 65535;
                break;
            case 3053931:
                if (key.equals("city")) {
                    c = 15;
                    break;
                }
                c = 65535;
                break;
            case 109757585:
                if (key.equals(RemoteConfigConstants.ResponseFieldKey.STATE)) {
                    c = 16;
                    break;
                }
                c = 65535;
                break;
            case 421072629:
                if (key.equals("middle_name")) {
                    c = 2;
                    break;
                }
                c = 65535;
                break;
            case 451516732:
                if (key.equals("first_name_native")) {
                    c = 1;
                    break;
                }
                c = 65535;
                break;
            case 475919162:
                if (key.equals("expiry_date")) {
                    c = 11;
                    break;
                }
                c = 65535;
                break;
            case 506677093:
                if (key.equals("document_no")) {
                    c = '\n';
                    break;
                }
                c = 65535;
                break;
            case 1168724782:
                if (key.equals("birth_date")) {
                    c = 6;
                    break;
                }
                c = 65535;
                break;
            case 1181577377:
                if (key.equals("middle_name_native")) {
                    c = 3;
                    break;
                }
                c = 65535;
                break;
            case 1481071862:
                if (key.equals("country_code")) {
                    c = '\b';
                    break;
                }
                c = 65535;
                break;
            case 2002465324:
                if (key.equals("post_code")) {
                    c = 14;
                    break;
                }
                c = 65535;
                break;
            case 2013122196:
                if (key.equals("last_name")) {
                    c = 4;
                    break;
                }
                c = 65535;
                break;
            default:
                c = 65535;
                break;
        }
        switch (c) {
            case 0:
            case 1:
                return 20;
            case 2:
            case 3:
                return 21;
            case 4:
            case 5:
                return 22;
            case 6:
                return 23;
            case 7:
                return 24;
            case '\b':
                return 25;
            case '\t':
                return 26;
            case '\n':
                return 27;
            case 11:
                return 28;
            case '\f':
                return 29;
            case '\r':
                return 30;
            case 14:
                return 31;
            case 15:
                return 32;
            case 16:
                return 33;
            default:
                return 100;
        }
    }

    private void createPhoneVerificationInterface(Context context) {
        this.actionBar.setTitle(LocaleController.getString("PassportPhone", R.string.PassportPhone));
        FrameLayout frameLayout = new FrameLayout(context);
        this.scrollView.addView(frameLayout, LayoutHelper.createScroll(-1, -2, 51));
        for (int a = 0; a < 3; a++) {
            this.views[a] = new PhoneConfirmationView(context, a + 2);
            this.views[a].setVisibility(8);
            SlideView slideView = this.views[a];
            float f = 18.0f;
            float f2 = AndroidUtilities.isTablet() ? 26.0f : 18.0f;
            if (AndroidUtilities.isTablet()) {
                f = 26.0f;
            }
            frameLayout.addView(slideView, LayoutHelper.createFrame(-1.0f, -1.0f, 51, f2, 30.0f, f, 0.0f));
        }
        Bundle params = new Bundle();
        params.putString("phone", this.currentValues.get("phone"));
        fillNextCodeParams(params, this.currentPhoneVerification, false);
    }

    private void loadPasswordInfo() {
        TLRPC.TL_account_getPassword req = new TLRPC.TL_account_getPassword();
        int reqId = ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                PassportActivity.this.lambda$loadPasswordInfo$4$PassportActivity(tLObject, tL_error);
            }
        });
        ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(reqId, this.classGuid);
    }

    public void lambda$loadPasswordInfo$4$PassportActivity(final TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$3$PassportActivity(response);
            }
        });
    }

    public void lambda$null$3$PassportActivity(TLObject response) {
        if (response != null) {
            TLRPC.TL_account_password tL_account_password = (TLRPC.TL_account_password) response;
            this.currentPassword = tL_account_password;
            if (!TwoStepVerificationActivity.canHandleCurrentPassword(tL_account_password, false)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
                return;
            }
            TwoStepVerificationActivity.initPasswordNewAlgo(this.currentPassword);
            updatePasswordInterface();
            if (this.inputFieldContainers[0].getVisibility() == 0) {
                this.inputFields[0].requestFocus();
                AndroidUtilities.showKeyboard(this.inputFields[0]);
            }
            if (this.usingSavedPassword == 1) {
                onPasswordDone(true);
            }
        }
    }

    private void createEmailVerificationInterface(Context context) {
        this.actionBar.setTitle(LocaleController.getString("PassportEmail", R.string.PassportEmail));
        this.inputFields = new EditTextBoldCursor[1];
        for (int a = 0; a < 1; a++) {
            ViewGroup container = new FrameLayout(context);
            this.linearLayout2.addView(container, LayoutHelper.createLinear(-1, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            this.inputFields[a] = new EditTextBoldCursor(context);
            this.inputFields[a].setTag(Integer.valueOf(a));
            this.inputFields[a].setTextSize(1, 16.0f);
            this.inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            this.inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setBackgroundDrawable(null);
            this.inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setCursorSize(AndroidUtilities.dp(20.0f));
            this.inputFields[a].setCursorWidth(1.5f);
            int i = 3;
            this.inputFields[a].setInputType(3);
            this.inputFields[a].setImeOptions(268435462);
            this.inputFields[a].setHint(LocaleController.getString("PassportEmailCode", R.string.PassportEmailCode));
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
            this.inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6.0f));
            EditTextBoldCursor editTextBoldCursor = this.inputFields[a];
            if (LocaleController.isRTL) {
                i = 5;
            }
            editTextBoldCursor.setGravity(i);
            container.addView(this.inputFields[a], LayoutHelper.createFrame(-1.0f, -2.0f, 51, 21.0f, 12.0f, 21.0f, 6.0f));
            this.inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public final boolean onEditorAction(TextView textView, int i2, KeyEvent keyEvent) {
                    return PassportActivity.this.lambda$createEmailVerificationInterface$5$PassportActivity(textView, i2, keyEvent);
                }
            });
            this.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 (!PassportActivity.this.ignoreOnTextChange && PassportActivity.this.emailCodeLength != 0 && PassportActivity.this.inputFields[0].length() == PassportActivity.this.emailCodeLength) {
                        PassportActivity.this.doneItem.callOnClick();
                    }
                }
            });
        }
        TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
        this.bottomCell = textInfoPrivacyCell;
        textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.bottomCell.setText(LocaleController.formatString("PassportEmailVerifyInfo", R.string.PassportEmailVerifyInfo, this.currentValues.get("email")));
        this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
    }

    public boolean lambda$createEmailVerificationInterface$5$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 6 || i == 5) {
            this.doneItem.callOnClick();
            return true;
        }
        return false;
    }

    private void createPasswordInterface(Context context) {
        TLRPC.User botUser = null;
        if (this.currentForm != null) {
            int a = 0;
            while (true) {
                if (a >= this.currentForm.users.size()) {
                    break;
                }
                TLRPC.User user = this.currentForm.users.get(a);
                if (user.id != this.currentBotId) {
                    a++;
                } else {
                    botUser = user;
                    break;
                }
            }
        } else {
            botUser = UserConfig.getInstance(this.currentAccount).getCurrentUser();
        }
        FrameLayout frameLayout = (FrameLayout) this.fragmentView;
        this.actionBar.setTitle(LocaleController.getString("AppPassport", R.string.AppPassport));
        EmptyTextProgressView emptyTextProgressView = new EmptyTextProgressView(context);
        this.emptyView = emptyTextProgressView;
        emptyTextProgressView.showProgress();
        frameLayout.addView(this.emptyView, LayoutHelper.createFrame(-1, -1.0f));
        FrameLayout frameLayout2 = new FrameLayout(context);
        this.passwordAvatarContainer = frameLayout2;
        this.linearLayout2.addView(frameLayout2, LayoutHelper.createLinear(-1, 100));
        BackupImageView avatarImageView = new BackupImageView(context);
        avatarImageView.setRoundRadius(AndroidUtilities.dp(32.0f));
        this.passwordAvatarContainer.addView(avatarImageView, LayoutHelper.createFrame(64.0f, 64.0f, 17, 0.0f, 8.0f, 0.0f, 0.0f));
        AvatarDrawable avatarDrawable = new AvatarDrawable(botUser);
        avatarImageView.setImage(ImageLocation.getForUser(botUser, false), "50_50", avatarDrawable, botUser);
        TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
        this.passwordRequestTextView = textInfoPrivacyCell;
        textInfoPrivacyCell.getTextView().setGravity(1);
        if (this.currentBotId == 0) {
            this.passwordRequestTextView.setText(LocaleController.getString("PassportSelfRequest", R.string.PassportSelfRequest));
        } else {
            this.passwordRequestTextView.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PassportRequest", R.string.PassportRequest, UserObject.getFirstName(botUser))));
        }
        ((FrameLayout.LayoutParams) this.passwordRequestTextView.getTextView().getLayoutParams()).gravity = 1;
        this.linearLayout2.addView(this.passwordRequestTextView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, 21.0f, 0.0f, 21.0f, 0.0f));
        ImageView imageView = new ImageView(context);
        this.noPasswordImageView = imageView;
        imageView.setImageResource(R.drawable.no_password);
        this.noPasswordImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chat_messagePanelIcons), PorterDuff.Mode.MULTIPLY));
        this.linearLayout2.addView(this.noPasswordImageView, LayoutHelper.createLinear(-2, -2, 49, 0, 13, 0, 0));
        TextView textView = new TextView(context);
        this.noPasswordTextView = textView;
        textView.setTextSize(1, 14.0f);
        this.noPasswordTextView.setGravity(1);
        this.noPasswordTextView.setPadding(AndroidUtilities.dp(21.0f), AndroidUtilities.dp(10.0f), AndroidUtilities.dp(21.0f), AndroidUtilities.dp(17.0f));
        this.noPasswordTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
        this.noPasswordTextView.setText(LocaleController.getString("AppPassportCreatePasswordInfo", R.string.AppPassportCreatePasswordInfo));
        this.linearLayout2.addView(this.noPasswordTextView, LayoutHelper.createFrame(-2.0f, -2.0f, (LocaleController.isRTL ? 5 : 3) | 48, 21.0f, 10.0f, 21.0f, 0.0f));
        TextView textView2 = new TextView(context);
        this.noPasswordSetTextView = textView2;
        textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText5));
        this.noPasswordSetTextView.setGravity(17);
        this.noPasswordSetTextView.setTextSize(1, 16.0f);
        this.noPasswordSetTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        this.noPasswordSetTextView.setText(LocaleController.getString("AppPassportCreatePassword", R.string.AppPassportCreatePassword));
        this.linearLayout2.addView(this.noPasswordSetTextView, LayoutHelper.createFrame(-1.0f, 24.0f, (LocaleController.isRTL ? 5 : 3) | 48, 21.0f, 9.0f, 21.0f, 0.0f));
        this.noPasswordSetTextView.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createPasswordInterface$6$PassportActivity(view);
            }
        });
        this.inputFields = new EditTextBoldCursor[1];
        this.inputFieldContainers = new ViewGroup[1];
        for (int a2 = 0; a2 < 1; a2++) {
            this.inputFieldContainers[a2] = new FrameLayout(context);
            this.linearLayout2.addView(this.inputFieldContainers[a2], LayoutHelper.createLinear(-1, 50));
            this.inputFieldContainers[a2].setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            this.inputFields[a2] = new EditTextBoldCursor(context);
            this.inputFields[a2].setTag(Integer.valueOf(a2));
            this.inputFields[a2].setTextSize(1, 16.0f);
            this.inputFields[a2].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            this.inputFields[a2].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a2].setBackgroundDrawable(null);
            this.inputFields[a2].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a2].setCursorSize(AndroidUtilities.dp(20.0f));
            this.inputFields[a2].setCursorWidth(1.5f);
            this.inputFields[a2].setInputType(TsExtractor.TS_STREAM_TYPE_AC3);
            this.inputFields[a2].setMaxLines(1);
            this.inputFields[a2].setLines(1);
            this.inputFields[a2].setSingleLine(true);
            this.inputFields[a2].setTransformationMethod(PasswordTransformationMethod.getInstance());
            this.inputFields[a2].setTypeface(Typeface.DEFAULT);
            this.inputFields[a2].setImeOptions(268435462);
            this.inputFields[a2].setPadding(0, 0, 0, AndroidUtilities.dp(6.0f));
            this.inputFields[a2].setGravity(LocaleController.isRTL ? 5 : 3);
            this.inputFieldContainers[a2].addView(this.inputFields[a2], LayoutHelper.createFrame(-1.0f, -2.0f, 51, 21.0f, 12.0f, 21.0f, 6.0f));
            this.inputFields[a2].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public final boolean onEditorAction(TextView textView3, int i, KeyEvent keyEvent) {
                    return PassportActivity.this.lambda$createPasswordInterface$7$PassportActivity(textView3, i, keyEvent);
                }
            });
            this.inputFields[a2].setCustomSelectionActionModeCallback(new ActionMode.Callback() {
                @Override
                public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public void onDestroyActionMode(ActionMode mode) {
                }

                @Override
                public boolean onCreateActionMode(ActionMode mode, Menu menu) {
                    return false;
                }

                @Override
                public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
                    return false;
                }
            });
        }
        TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
        this.passwordInfoRequestTextView = textInfoPrivacyCell2;
        textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.passwordInfoRequestTextView.setText(LocaleController.formatString("PassportRequestPasswordInfo", R.string.PassportRequestPasswordInfo, new Object[0]));
        this.linearLayout2.addView(this.passwordInfoRequestTextView, LayoutHelper.createLinear(-1, -2));
        TextView textView3 = new TextView(context);
        this.passwordForgotButton = textView3;
        textView3.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
        this.passwordForgotButton.setTextSize(1, 14.0f);
        this.passwordForgotButton.setText(LocaleController.getString("ForgotPassword", R.string.ForgotPassword));
        this.passwordForgotButton.setPadding(0, 0, 0, 0);
        this.linearLayout2.addView(this.passwordForgotButton, LayoutHelper.createLinear(-2, 30, (LocaleController.isRTL ? 5 : 3) | 48, 21, 0, 21, 0));
        this.passwordForgotButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createPasswordInterface$12$PassportActivity(view);
            }
        });
        updatePasswordInterface();
    }

    public void lambda$createPasswordInterface$6$PassportActivity(View v) {
        TwoStepVerificationActivity activity = new TwoStepVerificationActivity(this.currentAccount, 1);
        activity.setCloseAfterSet(true);
        activity.setCurrentPasswordInfo(new byte[0], this.currentPassword);
        presentFragment(activity);
    }

    public boolean lambda$createPasswordInterface$7$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 5 || i == 6) {
            this.doneItem.callOnClick();
            return true;
        }
        return false;
    }

    public void lambda$createPasswordInterface$12$PassportActivity(View v) {
        if (this.currentPassword.has_recovery) {
            needShowProgress();
            TLRPC.TL_auth_requestPasswordRecovery req = new TLRPC.TL_auth_requestPasswordRecovery();
            int reqId = ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.this.lambda$null$10$PassportActivity(tLObject, tL_error);
                }
            }, 10);
            ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(reqId, this.classGuid);
            return;
        }
        if (getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setNegativeButton(LocaleController.getString("RestorePasswordResetAccount", R.string.RestorePasswordResetAccount), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$null$11$PassportActivity(dialogInterface, i);
            }
        });
        builder.setTitle(LocaleController.getString("RestorePasswordNoEmailTitle", R.string.RestorePasswordNoEmailTitle));
        builder.setMessage(LocaleController.getString("RestorePasswordNoEmailText", R.string.RestorePasswordNoEmailText));
        showDialog(builder.create());
    }

    public void lambda$null$10$PassportActivity(final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$9$PassportActivity(error, response);
            }
        });
    }

    public void lambda$null$9$PassportActivity(TLRPC.TL_error error, TLObject response) {
        String timeString;
        needHideProgress();
        if (error == null) {
            final TLRPC.TL_auth_passwordRecovery res = (TLRPC.TL_auth_passwordRecovery) response;
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setMessage(LocaleController.formatString("RestoreEmailSent", R.string.RestoreEmailSent, res.email_pattern));
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                @Override
                public final void onClick(DialogInterface dialogInterface, int i) {
                    PassportActivity.this.lambda$null$8$PassportActivity(res, dialogInterface, i);
                }
            });
            Dialog dialog = showDialog(builder.create());
            if (dialog != null) {
                dialog.setCanceledOnTouchOutside(false);
                dialog.setCancelable(false);
                return;
            }
            return;
        }
        if (error.text.startsWith("FLOOD_WAIT")) {
            int time = Utilities.parseInt(error.text).intValue();
            if (time < 60) {
                timeString = LocaleController.formatPluralString("Seconds", time);
            } else {
                timeString = LocaleController.formatPluralString("Minutes", time / 60);
            }
            showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
            return;
        }
        showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
    }

    public void lambda$null$8$PassportActivity(TLRPC.TL_auth_passwordRecovery res, DialogInterface dialogInterface, int i) {
        TwoStepVerificationActivity fragment = new TwoStepVerificationActivity(this.currentAccount, 1);
        fragment.setRecoveryParams(this.currentPassword);
        this.currentPassword.email_unconfirmed_pattern = res.email_pattern;
        presentFragment(fragment);
    }

    public void lambda$null$11$PassportActivity(DialogInterface dialog, int which) {
        Browser.openUrl(getParentActivity(), "https://lovechat323.com/deactivate?phone=" + UserConfig.getInstance(this.currentAccount).getClientPhone());
    }

    public void onPasswordDone(final boolean saved) {
        final String textPassword;
        if (saved) {
            textPassword = null;
        } else {
            textPassword = this.inputFields[0].getText().toString();
            if (TextUtils.isEmpty(textPassword)) {
                onPasscodeError(false);
                return;
            }
            showEditDoneProgress(true, true);
        }
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$onPasswordDone$13$PassportActivity(saved, textPassword);
            }
        });
    }

    public void lambda$onPasswordDone$13$PassportActivity(boolean saved, String textPassword) {
        byte[] x_bytes;
        TLRPC.TL_account_getPasswordSettings req = new TLRPC.TL_account_getPasswordSettings();
        if (saved) {
            x_bytes = this.savedPasswordHash;
        } else if (this.currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
            byte[] passwordBytes = AndroidUtilities.getStringBytes(textPassword);
            TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) this.currentPassword.current_algo;
            x_bytes = SRPHelper.getX(passwordBytes, algo);
        } else {
            x_bytes = null;
        }
        RequestDelegate requestDelegate = new AnonymousClass8(saved, x_bytes, req, textPassword);
        if (this.currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
            TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo2 = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) this.currentPassword.current_algo;
            req.password = SRPHelper.startCheck(x_bytes, this.currentPassword.srp_id, this.currentPassword.srp_B, algo2);
            if (req.password == null) {
                TLRPC.TL_error error = new TLRPC.TL_error();
                error.text = "ALGO_INVALID";
                requestDelegate.run(null, error);
                return;
            } else {
                int reqId = ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, requestDelegate, 10);
                ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(reqId, this.classGuid);
                return;
            }
        }
        TLRPC.TL_error error2 = new TLRPC.TL_error();
        error2.text = "PASSWORD_HASH_INVALID";
        requestDelegate.run(null, error2);
    }

    public class AnonymousClass8 implements RequestDelegate {
        final TLRPC.TL_account_getPasswordSettings val$req;
        final boolean val$saved;
        final String val$textPassword;
        final byte[] val$x_bytes;

        AnonymousClass8(boolean z, byte[] bArr, TLRPC.TL_account_getPasswordSettings tL_account_getPasswordSettings, String str) {
            this.val$saved = z;
            this.val$x_bytes = bArr;
            this.val$req = tL_account_getPasswordSettings;
            this.val$textPassword = str;
        }

        private void openRequestInterface() {
            int type;
            if (PassportActivity.this.inputFields == null) {
                return;
            }
            if (!this.val$saved) {
                UserConfig.getInstance(PassportActivity.this.currentAccount).savePassword(this.val$x_bytes, PassportActivity.this.saltedPassword);
            }
            AndroidUtilities.hideKeyboard(PassportActivity.this.inputFields[0]);
            PassportActivity.this.ignoreOnFailure = true;
            if (PassportActivity.this.currentBotId == 0) {
                type = 8;
            } else {
                type = 0;
            }
            PassportActivity activity = new PassportActivity(type, PassportActivity.this.currentBotId, PassportActivity.this.currentScope, PassportActivity.this.currentPublicKey, PassportActivity.this.currentPayload, PassportActivity.this.currentNonce, PassportActivity.this.currentCallbackUrl, PassportActivity.this.currentForm, PassportActivity.this.currentPassword);
            activity.currentEmail = PassportActivity.this.currentEmail;
            activity.currentAccount = PassportActivity.this.currentAccount;
            activity.saltedPassword = PassportActivity.this.saltedPassword;
            activity.secureSecret = PassportActivity.this.secureSecret;
            activity.secureSecretId = PassportActivity.this.secureSecretId;
            activity.needActivityResult = PassportActivity.this.needActivityResult;
            if (PassportActivity.this.parentLayout != null && PassportActivity.this.parentLayout.checkTransitionAnimation()) {
                PassportActivity.this.presentAfterAnimation = activity;
            } else {
                PassportActivity.this.presentFragment(activity, true);
            }
        }

        private void resetSecret() {
            TLRPC.TL_account_updatePasswordSettings req2 = new TLRPC.TL_account_updatePasswordSettings();
            if (PassportActivity.this.currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
                TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) PassportActivity.this.currentPassword.current_algo;
                req2.password = SRPHelper.startCheck(this.val$x_bytes, PassportActivity.this.currentPassword.srp_id, PassportActivity.this.currentPassword.srp_B, algo);
            }
            req2.new_settings = new TLRPC.TL_account_passwordInputSettings();
            req2.new_settings.new_secure_settings = new TLRPC.TL_secureSecretSettings();
            req2.new_settings.new_secure_settings.secure_secret = new byte[0];
            req2.new_settings.new_secure_settings.secure_algo = new TLRPC.TL_securePasswordKdfAlgoUnknown();
            req2.new_settings.new_secure_settings.secure_secret_id = 0L;
            req2.new_settings.flags |= 4;
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(this.val$req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.AnonymousClass8.this.lambda$resetSecret$3$PassportActivity$8(tLObject, tL_error);
                }
            });
        }

        public void lambda$resetSecret$3$PassportActivity$8(TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$2$PassportActivity$8(error);
                }
            });
        }

        public void lambda$null$2$PassportActivity$8(TLRPC.TL_error error) {
            if (error != null && "SRP_ID_INVALID".equals(error.text)) {
                TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
                ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(getPasswordReq, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        PassportActivity.AnonymousClass8.this.lambda$null$1$PassportActivity$8(tLObject, tL_error);
                    }
                }, 8);
            } else {
                generateNewSecret();
            }
        }

        public void lambda$null$1$PassportActivity$8(final TLObject response2, final TLRPC.TL_error error2) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$0$PassportActivity$8(error2, response2);
                }
            });
        }

        public void lambda$null$0$PassportActivity$8(TLRPC.TL_error error2, TLObject response2) {
            if (error2 == null) {
                PassportActivity.this.currentPassword = (TLRPC.TL_account_password) response2;
                TwoStepVerificationActivity.initPasswordNewAlgo(PassportActivity.this.currentPassword);
                resetSecret();
            }
        }

        private void generateNewSecret() {
            DispatchQueue dispatchQueue = Utilities.globalQueue;
            final byte[] bArr = this.val$x_bytes;
            final String str = this.val$textPassword;
            dispatchQueue.postRunnable(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$generateNewSecret$8$PassportActivity$8(bArr, str);
                }
            });
        }

        public void lambda$generateNewSecret$8$PassportActivity$8(byte[] x_bytes, String textPassword) {
            Utilities.random.setSeed(PassportActivity.this.currentPassword.secure_random);
            TLRPC.TL_account_updatePasswordSettings req1 = new TLRPC.TL_account_updatePasswordSettings();
            if (PassportActivity.this.currentPassword.current_algo instanceof TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) {
                TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow algo = (TLRPC.TL_passwordKdfAlgoSHA256SHA256PBKDF2HMACSHA512iter100000SHA256ModPow) PassportActivity.this.currentPassword.current_algo;
                req1.password = SRPHelper.startCheck(x_bytes, PassportActivity.this.currentPassword.srp_id, PassportActivity.this.currentPassword.srp_B, algo);
            }
            req1.new_settings = new TLRPC.TL_account_passwordInputSettings();
            PassportActivity passportActivity = PassportActivity.this;
            passportActivity.secureSecret = passportActivity.getRandomSecret();
            PassportActivity passportActivity2 = PassportActivity.this;
            passportActivity2.secureSecretId = Utilities.bytesToLong(Utilities.computeSHA256(passportActivity2.secureSecret));
            if (PassportActivity.this.currentPassword.new_secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) {
                TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000 newAlgo = (TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) PassportActivity.this.currentPassword.new_secure_algo;
                PassportActivity.this.saltedPassword = Utilities.computePBKDF2(AndroidUtilities.getStringBytes(textPassword), newAlgo.salt);
                byte[] key = new byte[32];
                System.arraycopy(PassportActivity.this.saltedPassword, 0, key, 0, 32);
                byte[] iv = new byte[16];
                System.arraycopy(PassportActivity.this.saltedPassword, 32, iv, 0, 16);
                Utilities.aesCbcEncryptionByteArraySafe(PassportActivity.this.secureSecret, key, iv, 0, PassportActivity.this.secureSecret.length, 0, 1);
                req1.new_settings.new_secure_settings = new TLRPC.TL_secureSecretSettings();
                req1.new_settings.new_secure_settings.secure_algo = newAlgo;
                req1.new_settings.new_secure_settings.secure_secret = PassportActivity.this.secureSecret;
                req1.new_settings.new_secure_settings.secure_secret_id = PassportActivity.this.secureSecretId;
                req1.new_settings.flags |= 4;
            }
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req1, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.AnonymousClass8.this.lambda$null$7$PassportActivity$8(tLObject, tL_error);
                }
            });
        }

        public void lambda$null$7$PassportActivity$8(TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$6$PassportActivity$8(error);
                }
            });
        }

        public void lambda$null$6$PassportActivity$8(TLRPC.TL_error error) {
            if (error == null || !"SRP_ID_INVALID".equals(error.text)) {
                if (PassportActivity.this.currentForm == null) {
                    PassportActivity.this.currentForm = new TLRPC.TL_account_authorizationForm();
                }
                openRequestInterface();
                return;
            }
            TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(getPasswordReq, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.AnonymousClass8.this.lambda$null$5$PassportActivity$8(tLObject, tL_error);
                }
            }, 8);
        }

        public void lambda$null$5$PassportActivity$8(final TLObject response2, final TLRPC.TL_error error2) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$4$PassportActivity$8(error2, response2);
                }
            });
        }

        public void lambda$null$4$PassportActivity$8(TLRPC.TL_error error2, TLObject response2) {
            if (error2 == null) {
                PassportActivity.this.currentPassword = (TLRPC.TL_account_password) response2;
                TwoStepVerificationActivity.initPasswordNewAlgo(PassportActivity.this.currentPassword);
                generateNewSecret();
            }
        }

        @Override
        public void run(final TLObject response, final TLRPC.TL_error error) {
            if (error != null && "SRP_ID_INVALID".equals(error.text)) {
                TLRPC.TL_account_getPassword getPasswordReq = new TLRPC.TL_account_getPassword();
                ConnectionsManager connectionsManager = ConnectionsManager.getInstance(PassportActivity.this.currentAccount);
                final boolean z = this.val$saved;
                connectionsManager.sendRequest(getPasswordReq, new RequestDelegate() {
                    @Override
                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                        PassportActivity.AnonymousClass8.this.lambda$run$10$PassportActivity$8(z, tLObject, tL_error);
                    }
                }, 8);
                return;
            }
            if (error == null) {
                DispatchQueue dispatchQueue = Utilities.globalQueue;
                final String str = this.val$textPassword;
                final boolean z2 = this.val$saved;
                dispatchQueue.postRunnable(new Runnable() {
                    @Override
                    public final void run() {
                        PassportActivity.AnonymousClass8.this.lambda$run$15$PassportActivity$8(response, str, z2);
                    }
                });
                return;
            }
            final boolean z3 = this.val$saved;
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$run$16$PassportActivity$8(z3, error);
                }
            });
        }

        public void lambda$run$10$PassportActivity$8(final boolean saved, final TLObject response2, final TLRPC.TL_error error2) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$9$PassportActivity$8(error2, response2, saved);
                }
            });
        }

        public void lambda$null$9$PassportActivity$8(TLRPC.TL_error error2, TLObject response2, boolean saved) {
            if (error2 == null) {
                PassportActivity.this.currentPassword = (TLRPC.TL_account_password) response2;
                TwoStepVerificationActivity.initPasswordNewAlgo(PassportActivity.this.currentPassword);
                PassportActivity.this.onPasswordDone(saved);
            }
        }

        public void lambda$run$15$PassportActivity$8(TLObject response, String textPassword, final boolean saved) {
            final byte[] secure_salt;
            final TLRPC.TL_account_passwordSettings settings = (TLRPC.TL_account_passwordSettings) response;
            if (settings.secure_settings == null) {
                if (PassportActivity.this.currentPassword.new_secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) {
                    TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000 algo = (TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) PassportActivity.this.currentPassword.new_secure_algo;
                    secure_salt = algo.salt;
                    PassportActivity.this.saltedPassword = Utilities.computePBKDF2(AndroidUtilities.getStringBytes(textPassword), algo.salt);
                } else {
                    secure_salt = new byte[0];
                }
                PassportActivity.this.secureSecret = null;
                PassportActivity.this.secureSecretId = 0L;
            } else {
                PassportActivity.this.secureSecret = settings.secure_settings.secure_secret;
                PassportActivity.this.secureSecretId = settings.secure_settings.secure_secret_id;
                if (settings.secure_settings.secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoSHA512) {
                    secure_salt = ((TLRPC.TL_securePasswordKdfAlgoSHA512) settings.secure_settings.secure_algo).salt;
                    PassportActivity.this.saltedPassword = Utilities.computeSHA512(secure_salt, AndroidUtilities.getStringBytes(textPassword), secure_salt);
                } else if (settings.secure_settings.secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) {
                    TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000 algo2 = (TLRPC.TL_securePasswordKdfAlgoPBKDF2HMACSHA512iter100000) settings.secure_settings.secure_algo;
                    secure_salt = algo2.salt;
                    PassportActivity.this.saltedPassword = Utilities.computePBKDF2(AndroidUtilities.getStringBytes(textPassword), algo2.salt);
                } else {
                    if (settings.secure_settings.secure_algo instanceof TLRPC.TL_securePasswordKdfAlgoUnknown) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                PassportActivity.AnonymousClass8.this.lambda$null$11$PassportActivity$8();
                            }
                        });
                        return;
                    }
                    secure_salt = new byte[0];
                }
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$14$PassportActivity$8(settings, saved, secure_salt);
                }
            });
        }

        public void lambda$null$11$PassportActivity$8() {
            AlertsCreator.showUpdateAppAlert(PassportActivity.this.getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
        }

        public void lambda$null$14$PassportActivity$8(TLRPC.TL_account_passwordSettings settings, boolean saved, byte[] secure_salt) {
            PassportActivity.this.currentEmail = settings.email;
            if (saved) {
                PassportActivity passportActivity = PassportActivity.this;
                passportActivity.saltedPassword = passportActivity.savedSaltedPassword;
            }
            PassportActivity passportActivity2 = PassportActivity.this;
            if (PassportActivity.checkSecret(passportActivity2.decryptSecret(passportActivity2.secureSecret, PassportActivity.this.saltedPassword), Long.valueOf(PassportActivity.this.secureSecretId)) && secure_salt.length != 0 && PassportActivity.this.secureSecretId != 0) {
                if (PassportActivity.this.currentBotId == 0) {
                    TLRPC.TL_account_getAllSecureValues req12 = new TLRPC.TL_account_getAllSecureValues();
                    ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req12, new RequestDelegate() {
                        @Override
                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                            PassportActivity.AnonymousClass8.this.lambda$null$13$PassportActivity$8(tLObject, tL_error);
                        }
                    });
                    return;
                } else {
                    openRequestInterface();
                    return;
                }
            }
            if (saved) {
                UserConfig.getInstance(PassportActivity.this.currentAccount).resetSavedPassword();
                PassportActivity.this.usingSavedPassword = 0;
                PassportActivity.this.updatePasswordInterface();
                return;
            }
            if (PassportActivity.this.currentForm != null) {
                PassportActivity.this.currentForm.values.clear();
                PassportActivity.this.currentForm.errors.clear();
            }
            if (PassportActivity.this.secureSecret == null || PassportActivity.this.secureSecret.length == 0) {
                generateNewSecret();
            } else {
                resetSecret();
            }
        }

        public void lambda$null$13$PassportActivity$8(final TLObject response1, final TLRPC.TL_error error1) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.AnonymousClass8.this.lambda$null$12$PassportActivity$8(response1, error1);
                }
            });
        }

        public void lambda$null$12$PassportActivity$8(TLObject response1, TLRPC.TL_error error1) {
            if (response1 != null) {
                PassportActivity.this.currentForm = new TLRPC.TL_account_authorizationForm();
                TLRPC.Vector vector = (TLRPC.Vector) response1;
                int size = vector.objects.size();
                for (int a = 0; a < size; a++) {
                    PassportActivity.this.currentForm.values.add((TLRPC.TL_secureValue) vector.objects.get(a));
                }
                openRequestInterface();
                return;
            }
            if (!"APP_VERSION_OUTDATED".equals(error1.text)) {
                PassportActivity.this.showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error1.text);
            } else {
                AlertsCreator.showUpdateAppAlert(PassportActivity.this.getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
            }
            PassportActivity.this.showEditDoneProgress(true, false);
        }

        public void lambda$run$16$PassportActivity$8(boolean saved, TLRPC.TL_error error) {
            String timeString;
            if (saved) {
                UserConfig.getInstance(PassportActivity.this.currentAccount).resetSavedPassword();
                PassportActivity.this.usingSavedPassword = 0;
                PassportActivity.this.updatePasswordInterface();
                if (PassportActivity.this.inputFieldContainers != null && PassportActivity.this.inputFieldContainers[0].getVisibility() == 0) {
                    PassportActivity.this.inputFields[0].requestFocus();
                    AndroidUtilities.showKeyboard(PassportActivity.this.inputFields[0]);
                    return;
                }
                return;
            }
            PassportActivity.this.showEditDoneProgress(true, false);
            if (error.text.equals("PASSWORD_HASH_INVALID")) {
                PassportActivity.this.onPasscodeError(true);
                return;
            }
            if (!error.text.startsWith("FLOOD_WAIT")) {
                PassportActivity.this.showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
                return;
            }
            int time = Utilities.parseInt(error.text).intValue();
            if (time < 60) {
                timeString = LocaleController.formatPluralString("Seconds", time);
            } else {
                timeString = LocaleController.formatPluralString("Minutes", time / 60);
            }
            PassportActivity.this.showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("FloodWaitTime", R.string.FloodWaitTime, timeString));
        }
    }

    private boolean isPersonalDocument(TLRPC.SecureValueType type) {
        return (type instanceof TLRPC.TL_secureValueTypeDriverLicense) || (type instanceof TLRPC.TL_secureValueTypePassport) || (type instanceof TLRPC.TL_secureValueTypeInternalPassport) || (type instanceof TLRPC.TL_secureValueTypeIdentityCard);
    }

    private boolean isAddressDocument(TLRPC.SecureValueType type) {
        return (type instanceof TLRPC.TL_secureValueTypeUtilityBill) || (type instanceof TLRPC.TL_secureValueTypeBankStatement) || (type instanceof TLRPC.TL_secureValueTypePassportRegistration) || (type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) || (type instanceof TLRPC.TL_secureValueTypeRentalAgreement);
    }

    private void createRequestInterface(Context context) {
        TLRPC.User botUser;
        int addressCount;
        int personalCount;
        ArrayList<TLRPC.TL_secureRequiredType> addressDocuments;
        ArrayList<TLRPC.TL_secureRequiredType> personalDocuments;
        TLRPC.TL_secureRequiredType requiredType;
        TLRPC.TL_secureRequiredType requiredType2;
        ArrayList<TLRPC.TL_secureRequiredType> documentTypes;
        boolean documentOnly;
        ArrayList<TLRPC.TL_secureRequiredType> documentTypes2;
        ArrayList<TLRPC.TL_secureRequiredType> documentTypes3;
        if (this.currentForm != null) {
            for (int a = 0; a < this.currentForm.users.size(); a++) {
                TLRPC.User user = this.currentForm.users.get(a);
                if (user.id == this.currentBotId) {
                    botUser = user;
                    break;
                }
            }
        }
        botUser = null;
        FrameLayout frameLayout = (FrameLayout) this.fragmentView;
        this.actionBar.setTitle(LocaleController.getString("AppPassport", R.string.AppPassport));
        this.actionBar.createMenu().addItem(1, R.drawable.profile_info);
        int i = 0;
        if (botUser != null) {
            FrameLayout avatarContainer = new FrameLayout(context);
            this.linearLayout2.addView(avatarContainer, LayoutHelper.createLinear(-1, 100));
            BackupImageView avatarImageView = new BackupImageView(context);
            avatarImageView.setRoundRadius(AndroidUtilities.dp(32.0f));
            avatarContainer.addView(avatarImageView, LayoutHelper.createFrame(64.0f, 64.0f, 17, 0.0f, 8.0f, 0.0f, 0.0f));
            AvatarDrawable avatarDrawable = new AvatarDrawable(botUser);
            avatarImageView.setImage(ImageLocation.getForUser(botUser, false), "50_50", avatarDrawable, botUser);
            TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell;
            textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow));
            this.bottomCell.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PassportRequest", R.string.PassportRequest, UserObject.getFirstName(botUser))));
            this.bottomCell.getTextView().setGravity(1);
            ((FrameLayout.LayoutParams) this.bottomCell.getTextView().getLayoutParams()).gravity = 1;
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
        }
        HeaderCell headerCell = new HeaderCell(context);
        this.headerCell = headerCell;
        headerCell.setText(LocaleController.getString("PassportRequestedInformation", R.string.PassportRequestedInformation));
        this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
        TLRPC.TL_account_authorizationForm tL_account_authorizationForm = this.currentForm;
        if (tL_account_authorizationForm != null) {
            int size = tL_account_authorizationForm.required_types.size();
            ArrayList<TLRPC.TL_secureRequiredType> personalDocuments2 = new ArrayList<>();
            ArrayList<TLRPC.TL_secureRequiredType> addressDocuments2 = new ArrayList<>();
            boolean hasAddressInfo = false;
            int personalCount2 = 0;
            int personalCount3 = 0;
            boolean hasPersonalInfo = false;
            int addressCount2 = 0;
            while (personalCount3 < size) {
                TLRPC.SecureRequiredType secureRequiredType = this.currentForm.required_types.get(personalCount3);
                if (secureRequiredType instanceof TLRPC.TL_secureRequiredType) {
                    TLRPC.TL_secureRequiredType requiredType3 = (TLRPC.TL_secureRequiredType) secureRequiredType;
                    if (!isPersonalDocument(requiredType3.type)) {
                        if (isAddressDocument(requiredType3.type)) {
                            addressDocuments2.add(requiredType3);
                            addressCount2++;
                        } else if (requiredType3.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                            hasPersonalInfo = true;
                        } else if (requiredType3.type instanceof TLRPC.TL_secureValueTypeAddress) {
                            hasAddressInfo = true;
                        }
                    } else {
                        personalDocuments2.add(requiredType3);
                        personalCount2++;
                    }
                } else if (secureRequiredType instanceof TLRPC.TL_secureRequiredTypeOneOf) {
                    TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType;
                    if (!requiredTypeOneOf.types.isEmpty()) {
                        TLRPC.SecureRequiredType innerType = requiredTypeOneOf.types.get(i);
                        if (innerType instanceof TLRPC.TL_secureRequiredType) {
                            TLRPC.TL_secureRequiredType requiredType4 = (TLRPC.TL_secureRequiredType) innerType;
                            if (!isPersonalDocument(requiredType4.type)) {
                                if (isAddressDocument(requiredType4.type)) {
                                    int b = 0;
                                    int size2 = requiredTypeOneOf.types.size();
                                    while (b < size2) {
                                        int size22 = size2;
                                        TLRPC.SecureRequiredType innerType2 = requiredTypeOneOf.types.get(b);
                                        if (innerType2 instanceof TLRPC.TL_secureRequiredType) {
                                            addressDocuments2.add((TLRPC.TL_secureRequiredType) innerType2);
                                        }
                                        b++;
                                        size2 = size22;
                                    }
                                    addressCount2++;
                                }
                            } else {
                                int b2 = 0;
                                int size23 = requiredTypeOneOf.types.size();
                                while (b2 < size23) {
                                    int size24 = size23;
                                    TLRPC.SecureRequiredType innerType3 = requiredTypeOneOf.types.get(b2);
                                    if (innerType3 instanceof TLRPC.TL_secureRequiredType) {
                                        personalDocuments2.add((TLRPC.TL_secureRequiredType) innerType3);
                                    }
                                    b2++;
                                    size23 = size24;
                                }
                                personalCount2++;
                            }
                        }
                    }
                }
                personalCount3++;
                i = 0;
            }
            boolean separatePersonal = !hasPersonalInfo || personalCount2 > 1;
            boolean separateAddress = !hasAddressInfo || addressCount2 > 1;
            int a2 = 0;
            while (a2 < size) {
                TLRPC.SecureRequiredType secureRequiredType2 = this.currentForm.required_types.get(a2);
                if (secureRequiredType2 instanceof TLRPC.TL_secureRequiredType) {
                    TLRPC.TL_secureRequiredType requiredType5 = (TLRPC.TL_secureRequiredType) secureRequiredType2;
                    if ((requiredType5.type instanceof TLRPC.TL_secureValueTypePhone) || (requiredType5.type instanceof TLRPC.TL_secureValueTypeEmail)) {
                        requiredType2 = requiredType5;
                        documentTypes = null;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        documentOnly = false;
                        addressCount = addressCount2;
                    } else if (requiredType5.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                        if (separatePersonal) {
                            documentTypes3 = null;
                        } else {
                            documentTypes3 = personalDocuments2;
                        }
                        requiredType2 = requiredType5;
                        documentTypes = documentTypes3;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        documentOnly = false;
                        addressCount = addressCount2;
                    } else if (requiredType5.type instanceof TLRPC.TL_secureValueTypeAddress) {
                        if (separateAddress) {
                            documentTypes2 = null;
                        } else {
                            documentTypes2 = addressDocuments2;
                        }
                        requiredType2 = requiredType5;
                        documentTypes = documentTypes2;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        documentOnly = false;
                        addressCount = addressCount2;
                    } else if (separatePersonal && isPersonalDocument(requiredType5.type)) {
                        ArrayList<TLRPC.TL_secureRequiredType> documentTypes4 = new ArrayList<>();
                        documentTypes4.add(requiredType5);
                        TLRPC.TL_secureRequiredType requiredType6 = new TLRPC.TL_secureRequiredType();
                        requiredType6.type = new TLRPC.TL_secureValueTypePersonalDetails();
                        requiredType2 = requiredType6;
                        documentOnly = true;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        documentTypes = documentTypes4;
                        addressCount = addressCount2;
                    } else if (!separateAddress || !isAddressDocument(requiredType5.type)) {
                        addressCount = addressCount2;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        personalDocuments = personalDocuments2;
                        a2++;
                        addressCount2 = addressCount;
                        addressDocuments2 = addressDocuments;
                        personalCount2 = personalCount;
                        personalDocuments2 = personalDocuments;
                    } else {
                        ArrayList<TLRPC.TL_secureRequiredType> documentTypes5 = new ArrayList<>();
                        documentTypes5.add(requiredType5);
                        TLRPC.TL_secureRequiredType requiredType7 = new TLRPC.TL_secureRequiredType();
                        requiredType7.type = new TLRPC.TL_secureValueTypeAddress();
                        requiredType2 = requiredType7;
                        documentOnly = true;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        documentTypes = documentTypes5;
                        addressCount = addressCount2;
                    }
                    personalDocuments = personalDocuments2;
                    addField(context, requiredType2, documentTypes, documentOnly, a2 != size + (-1));
                    a2++;
                    addressCount2 = addressCount;
                    addressDocuments2 = addressDocuments;
                    personalCount2 = personalCount;
                    personalDocuments2 = personalDocuments;
                } else {
                    if (!(secureRequiredType2 instanceof TLRPC.TL_secureRequiredTypeOneOf)) {
                        addressCount = addressCount2;
                        personalCount = personalCount2;
                        addressDocuments = addressDocuments2;
                        personalDocuments = personalDocuments2;
                    } else {
                        TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf2 = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType2;
                        if (requiredTypeOneOf2.types.isEmpty()) {
                            addressCount = addressCount2;
                            personalCount = personalCount2;
                            addressDocuments = addressDocuments2;
                            personalDocuments = personalDocuments2;
                        } else {
                            addressCount = addressCount2;
                            TLRPC.SecureRequiredType innerType4 = requiredTypeOneOf2.types.get(0);
                            if (!(innerType4 instanceof TLRPC.TL_secureRequiredType)) {
                                personalCount = personalCount2;
                                addressDocuments = addressDocuments2;
                                personalDocuments = personalDocuments2;
                            } else {
                                TLRPC.TL_secureRequiredType requiredType8 = (TLRPC.TL_secureRequiredType) innerType4;
                                if (!separatePersonal) {
                                }
                                if (!separateAddress || !isAddressDocument(requiredType8.type)) {
                                    personalCount = personalCount2;
                                    addressDocuments = addressDocuments2;
                                    personalDocuments = personalDocuments2;
                                }
                                ArrayList<TLRPC.TL_secureRequiredType> documentTypes6 = new ArrayList<>();
                                personalCount = personalCount2;
                                int size25 = requiredTypeOneOf2.types.size();
                                addressDocuments = addressDocuments2;
                                int b3 = 0;
                                while (b3 < size25) {
                                    int size26 = size25;
                                    TLRPC.SecureRequiredType innerType5 = requiredTypeOneOf2.types.get(b3);
                                    TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf3 = requiredTypeOneOf2;
                                    if (innerType5 instanceof TLRPC.TL_secureRequiredType) {
                                        documentTypes6.add((TLRPC.TL_secureRequiredType) innerType5);
                                    }
                                    b3++;
                                    size25 = size26;
                                    requiredTypeOneOf2 = requiredTypeOneOf3;
                                }
                                if (isPersonalDocument(requiredType8.type)) {
                                    requiredType = new TLRPC.TL_secureRequiredType();
                                    requiredType.type = new TLRPC.TL_secureValueTypePersonalDetails();
                                } else {
                                    requiredType = new TLRPC.TL_secureRequiredType();
                                    requiredType.type = new TLRPC.TL_secureValueTypeAddress();
                                }
                                requiredType2 = requiredType;
                                documentTypes = documentTypes6;
                                documentOnly = true;
                                personalDocuments = personalDocuments2;
                                addField(context, requiredType2, documentTypes, documentOnly, a2 != size + (-1));
                            }
                        }
                    }
                    a2++;
                    addressCount2 = addressCount;
                    addressDocuments2 = addressDocuments;
                    personalCount2 = personalCount;
                    personalDocuments2 = personalDocuments;
                }
            }
        }
        if (botUser != null) {
            TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell2;
            textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            this.bottomCell.setLinkTextColorKey(Theme.key_windowBackgroundWhiteGrayText4);
            if (!TextUtils.isEmpty(this.currentForm.privacy_policy_url)) {
                String str2 = LocaleController.formatString("PassportPolicy", R.string.PassportPolicy, UserObject.getFirstName(botUser), botUser.username);
                SpannableStringBuilder text = new SpannableStringBuilder(str2);
                int index1 = str2.indexOf(42);
                int index2 = str2.lastIndexOf(42);
                if (index1 != -1 && index2 != -1) {
                    this.bottomCell.getTextView().setMovementMethod(new AndroidUtilities.LinkMovementMethodMy());
                    text.replace(index2, index2 + 1, (CharSequence) "");
                    text.replace(index1, index1 + 1, (CharSequence) "");
                    text.setSpan(new LinkSpan(), index1, index2 - 1, 33);
                }
                this.bottomCell.setText(text);
            } else {
                this.bottomCell.setText(AndroidUtilities.replaceTags(LocaleController.formatString("PassportNoPolicy", R.string.PassportNoPolicy, UserObject.getFirstName(botUser), botUser.username)));
            }
            this.bottomCell.getTextView().setHighlightColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText4));
            this.bottomCell.getTextView().setGravity(1);
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
        }
        FrameLayout frameLayout2 = new FrameLayout(context);
        this.bottomLayout = frameLayout2;
        frameLayout2.setBackgroundDrawable(Theme.createSelectorWithBackgroundDrawable(Theme.getColor(Theme.key_passport_authorizeBackground), Theme.getColor(Theme.key_passport_authorizeBackgroundSelected)));
        frameLayout.addView(this.bottomLayout, LayoutHelper.createFrame(-1, 48, 80));
        this.bottomLayout.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createRequestInterface$16$PassportActivity(view);
            }
        });
        TextView textView = new TextView(context);
        this.acceptTextView = textView;
        textView.setCompoundDrawablePadding(AndroidUtilities.dp(8.0f));
        this.acceptTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.authorize, 0, 0, 0);
        this.acceptTextView.setTextColor(Theme.getColor(Theme.key_passport_authorizeText));
        this.acceptTextView.setText(LocaleController.getString("PassportAuthorize", R.string.PassportAuthorize));
        this.acceptTextView.setTextSize(1, 14.0f);
        this.acceptTextView.setGravity(17);
        this.acceptTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        this.bottomLayout.addView(this.acceptTextView, LayoutHelper.createFrame(-2, -1, 17));
        ContextProgressView contextProgressView = new ContextProgressView(context, 0);
        this.progressViewButton = contextProgressView;
        contextProgressView.setVisibility(4);
        this.bottomLayout.addView(this.progressViewButton, LayoutHelper.createFrame(-1, -1.0f));
        View shadow = new View(context);
        shadow.setBackgroundResource(R.drawable.header_shadow_reverse);
        frameLayout.addView(shadow, LayoutHelper.createFrame(-1.0f, 3.0f, 83, 0.0f, 0.0f, 0.0f, 48.0f));
    }

    class C1ValueToSend {
        boolean selfie_required;
        boolean translation_required;
        TLRPC.TL_secureValue value;

        public C1ValueToSend(TLRPC.TL_secureValue v, boolean s, boolean t) {
            this.value = v;
            this.selfie_required = s;
            this.translation_required = t;
        }
    }

    public void lambda$createRequestInterface$16$PassportActivity(View view) {
        ArrayList<C1ValueToSend> valuesToSend;
        int size;
        TLRPC.TL_secureRequiredType requiredType;
        ArrayList<C1ValueToSend> valuesToSend2 = new ArrayList<>();
        int size2 = this.currentForm.required_types.size();
        for (int a = 0; a < size2; a++) {
            TLRPC.SecureRequiredType secureRequiredType = this.currentForm.required_types.get(a);
            if (secureRequiredType instanceof TLRPC.TL_secureRequiredType) {
                requiredType = (TLRPC.TL_secureRequiredType) secureRequiredType;
            } else {
                if (secureRequiredType instanceof TLRPC.TL_secureRequiredTypeOneOf) {
                    TLRPC.TL_secureRequiredTypeOneOf requiredTypeOneOf = (TLRPC.TL_secureRequiredTypeOneOf) secureRequiredType;
                    if (!requiredTypeOneOf.types.isEmpty()) {
                        TLRPC.SecureRequiredType secureRequiredType2 = requiredTypeOneOf.types.get(0);
                        if (secureRequiredType2 instanceof TLRPC.TL_secureRequiredType) {
                            TLRPC.TL_secureRequiredType requiredType2 = (TLRPC.TL_secureRequiredType) secureRequiredType2;
                            int b = 0;
                            int size22 = requiredTypeOneOf.types.size();
                            while (true) {
                                if (b >= size22) {
                                    requiredType = requiredType2;
                                    break;
                                }
                                TLRPC.SecureRequiredType secureRequiredType3 = requiredTypeOneOf.types.get(b);
                                if (secureRequiredType3 instanceof TLRPC.TL_secureRequiredType) {
                                    TLRPC.TL_secureRequiredType innerType = (TLRPC.TL_secureRequiredType) secureRequiredType3;
                                    if (getValueByType(innerType, true) != null) {
                                        requiredType = innerType;
                                        break;
                                    }
                                }
                                b++;
                            }
                        } else {
                            continue;
                        }
                    } else {
                        continue;
                    }
                } else {
                    continue;
                }
            }
            TLRPC.TL_secureValue value = getValueByType(requiredType, true);
            if (value == null) {
                Vibrator v = (Vibrator) getParentActivity().getSystemService("vibrator");
                if (v != null) {
                    v.vibrate(200L);
                }
                AndroidUtilities.shakeView(getViewByType(requiredType), 2.0f, 0);
                return;
            }
            String key = getNameForType(requiredType.type);
            HashMap<String, String> errors = this.errorsMap.get(key);
            if (errors != null && !errors.isEmpty()) {
                Vibrator v2 = (Vibrator) getParentActivity().getSystemService("vibrator");
                if (v2 != null) {
                    v2.vibrate(200L);
                }
                AndroidUtilities.shakeView(getViewByType(requiredType), 2.0f, 0);
                return;
            }
            valuesToSend2.add(new C1ValueToSend(value, requiredType.selfie_required, requiredType.translation_required));
        }
        showEditDoneProgress(false, true);
        TLRPC.TL_account_acceptAuthorization req = new TLRPC.TL_account_acceptAuthorization();
        req.bot_id = this.currentBotId;
        req.scope = this.currentScope;
        req.public_key = this.currentPublicKey;
        JSONObject jSONObject = new JSONObject();
        int size3 = valuesToSend2.size();
        int a2 = 0;
        while (a2 < size3) {
            C1ValueToSend valueToSend = valuesToSend2.get(a2);
            TLRPC.TL_secureValue secureValue = valueToSend.value;
            JSONObject data = new JSONObject();
            if (secureValue.plain_data != null) {
                if (secureValue.plain_data instanceof TLRPC.TL_securePlainEmail) {
                } else if (secureValue.plain_data instanceof TLRPC.TL_securePlainPhone) {
                    valuesToSend = valuesToSend2;
                    size = size3;
                }
                valuesToSend = valuesToSend2;
                size = size3;
            } else {
                try {
                    JSONObject jSONObject2 = new JSONObject();
                    if (secureValue.data != null) {
                        try {
                            byte[] decryptedSecret = decryptValueSecret(secureValue.data.secret, secureValue.data.data_hash);
                            data.put("data_hash", Base64.encodeToString(secureValue.data.data_hash, 2));
                            data.put("secret", Base64.encodeToString(decryptedSecret, 2));
                            jSONObject2.put("data", data);
                        } catch (Exception e) {
                            valuesToSend = valuesToSend2;
                            size = size3;
                        }
                    }
                    if (secureValue.files.isEmpty()) {
                        valuesToSend = valuesToSend2;
                        size = size3;
                    } else {
                        try {
                            JSONArray files = new JSONArray();
                            int b2 = 0;
                            for (int size23 = secureValue.files.size(); b2 < size23; size23 = size23) {
                                valuesToSend = valuesToSend2;
                                try {
                                    TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) secureValue.files.get(b2);
                                    size = size3;
                                    try {
                                        JSONObject data2 = data;
                                        try {
                                            byte[] decryptedSecret2 = decryptValueSecret(secureFile.secret, secureFile.file_hash);
                                            JSONObject file = new JSONObject();
                                            file.put("file_hash", Base64.encodeToString(secureFile.file_hash, 2));
                                            file.put("secret", Base64.encodeToString(decryptedSecret2, 2));
                                            files.put(file);
                                            b2++;
                                            valuesToSend2 = valuesToSend;
                                            size3 = size;
                                            data = data2;
                                        } catch (Exception e2) {
                                        }
                                    } catch (Exception e3) {
                                    }
                                } catch (Exception e4) {
                                    size = size3;
                                }
                            }
                            valuesToSend = valuesToSend2;
                            size = size3;
                            jSONObject2.put("files", files);
                        } catch (Exception e5) {
                            valuesToSend = valuesToSend2;
                            size = size3;
                        }
                    }
                    try {
                        if (secureValue.front_side instanceof TLRPC.TL_secureFile) {
                            TLRPC.TL_secureFile secureFile2 = (TLRPC.TL_secureFile) secureValue.front_side;
                            byte[] decryptedSecret3 = decryptValueSecret(secureFile2.secret, secureFile2.file_hash);
                            JSONObject front = new JSONObject();
                            front.put("file_hash", Base64.encodeToString(secureFile2.file_hash, 2));
                            front.put("secret", Base64.encodeToString(decryptedSecret3, 2));
                            jSONObject2.put("front_side", front);
                        }
                        if (secureValue.reverse_side instanceof TLRPC.TL_secureFile) {
                            TLRPC.TL_secureFile secureFile3 = (TLRPC.TL_secureFile) secureValue.reverse_side;
                            byte[] decryptedSecret4 = decryptValueSecret(secureFile3.secret, secureFile3.file_hash);
                            JSONObject reverse = new JSONObject();
                            reverse.put("file_hash", Base64.encodeToString(secureFile3.file_hash, 2));
                            reverse.put("secret", Base64.encodeToString(decryptedSecret4, 2));
                            jSONObject2.put("reverse_side", reverse);
                        }
                        if (valueToSend.selfie_required && (secureValue.selfie instanceof TLRPC.TL_secureFile)) {
                            TLRPC.TL_secureFile secureFile4 = (TLRPC.TL_secureFile) secureValue.selfie;
                            byte[] decryptedSecret5 = decryptValueSecret(secureFile4.secret, secureFile4.file_hash);
                            JSONObject selfie = new JSONObject();
                            selfie.put("file_hash", Base64.encodeToString(secureFile4.file_hash, 2));
                            selfie.put("secret", Base64.encodeToString(decryptedSecret5, 2));
                            jSONObject2.put("selfie", selfie);
                        }
                        if (valueToSend.translation_required && !secureValue.translation.isEmpty()) {
                            JSONArray translation = new JSONArray();
                            int b3 = 0;
                            int size24 = secureValue.translation.size();
                            while (b3 < size24) {
                                TLRPC.TL_secureFile secureFile5 = (TLRPC.TL_secureFile) secureValue.translation.get(b3);
                                byte[] decryptedSecret6 = decryptValueSecret(secureFile5.secret, secureFile5.file_hash);
                                JSONObject file2 = new JSONObject();
                                int size25 = size24;
                                C1ValueToSend valueToSend2 = valueToSend;
                                try {
                                    file2.put("file_hash", Base64.encodeToString(secureFile5.file_hash, 2));
                                    file2.put("secret", Base64.encodeToString(decryptedSecret6, 2));
                                    translation.put(file2);
                                    b3++;
                                    size24 = size25;
                                    valueToSend = valueToSend2;
                                } catch (Exception e6) {
                                }
                            }
                            jSONObject2.put("translation", translation);
                        }
                        jSONObject.put(getNameForType(secureValue.type), jSONObject2);
                    } catch (Exception e7) {
                    }
                } catch (Exception e8) {
                    valuesToSend = valuesToSend2;
                    size = size3;
                }
            }
            TLRPC.TL_secureValueHash hash = new TLRPC.TL_secureValueHash();
            hash.type = secureValue.type;
            hash.hash = secureValue.hash;
            req.value_hashes.add(hash);
            a2++;
            valuesToSend2 = valuesToSend;
            size3 = size;
        }
        JSONObject jSONObject3 = new JSONObject();
        try {
            jSONObject3.put("secure_data", jSONObject);
        } catch (Exception e9) {
        }
        Object obj = this.currentPayload;
        if (obj != null) {
            try {
                jSONObject3.put("payload", obj);
            } catch (Exception e10) {
            }
        }
        Object obj2 = this.currentNonce;
        if (obj2 != null) {
            try {
                jSONObject3.put("nonce", obj2);
            } catch (Exception e11) {
            }
        }
        String json = jSONObject3.toString();
        EncryptionResult encryptionResult = encryptData(AndroidUtilities.getStringBytes(json));
        req.credentials = new TLRPC.TL_secureCredentialsEncrypted();
        req.credentials.hash = encryptionResult.fileHash;
        req.credentials.data = encryptionResult.encryptedData;
        try {
            String key2 = this.currentPublicKey.replaceAll("\\n", "").replace("-----BEGIN PUBLIC KEY-----", "").replace("-----END PUBLIC KEY-----", "");
            KeyFactory kf = KeyFactory.getInstance("RSA");
            X509EncodedKeySpec keySpecX509 = new X509EncodedKeySpec(Base64.decode(key2, 0));
            RSAPublicKey pubKey = (RSAPublicKey) kf.generatePublic(keySpecX509);
            Cipher c = Cipher.getInstance("RSA/NONE/OAEPWithSHA1AndMGF1Padding", "BC");
            c.init(1, pubKey);
            req.credentials.secret = c.doFinal(encryptionResult.decrypyedFileSecret);
        } catch (Exception e12) {
            FileLog.e(e12);
        }
        int reqId = ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                PassportActivity.this.lambda$null$15$PassportActivity(tLObject, tL_error);
            }
        });
        ConnectionsManager.getInstance(this.currentAccount).bindRequestToGuid(reqId, this.classGuid);
    }

    public void lambda$null$15$PassportActivity(TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$14$PassportActivity(error);
            }
        });
    }

    public void lambda$null$14$PassportActivity(TLRPC.TL_error error) {
        if (error == null) {
            this.ignoreOnFailure = true;
            callCallback(true);
            finishFragment();
        } else {
            showEditDoneProgress(false, false);
            if ("APP_VERSION_OUTDATED".equals(error.text)) {
                AlertsCreator.showUpdateAppAlert(getParentActivity(), LocaleController.getString("UpdateAppAlert", R.string.UpdateAppAlert), true);
            } else {
                showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
            }
        }
    }

    private void createManageInterface(Context context) {
        ArrayList<TLRPC.TL_secureRequiredType> documentTypes;
        TLRPC.TL_secureRequiredType requiredType;
        boolean documentOnly;
        this.actionBar.setTitle(LocaleController.getString("AppPassport", R.string.AppPassport));
        this.actionBar.createMenu().addItem(1, R.drawable.profile_info);
        HeaderCell headerCell = new HeaderCell(context);
        this.headerCell = headerCell;
        headerCell.setText(LocaleController.getString("PassportProvidedInformation", R.string.PassportProvidedInformation));
        this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
        ShadowSectionCell shadowSectionCell = new ShadowSectionCell(context);
        this.sectionCell = shadowSectionCell;
        shadowSectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        this.linearLayout2.addView(this.sectionCell, LayoutHelper.createLinear(-1, -2));
        TextSettingsCell textSettingsCell = new TextSettingsCell(context);
        this.addDocumentCell = textSettingsCell;
        textSettingsCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        this.addDocumentCell.setText(LocaleController.getString("PassportNoDocumentsAdd", R.string.PassportNoDocumentsAdd), true);
        this.linearLayout2.addView(this.addDocumentCell, LayoutHelper.createLinear(-1, -2));
        this.addDocumentCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createManageInterface$17$PassportActivity(view);
            }
        });
        TextSettingsCell textSettingsCell2 = new TextSettingsCell(context);
        this.deletePassportCell = textSettingsCell2;
        textSettingsCell2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
        this.deletePassportCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        this.deletePassportCell.setText(LocaleController.getString("AppPassportDelete", R.string.AppPassportDelete), false);
        this.linearLayout2.addView(this.deletePassportCell, LayoutHelper.createLinear(-1, -2));
        this.deletePassportCell.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createManageInterface$21$PassportActivity(view);
            }
        });
        ShadowSectionCell shadowSectionCell2 = new ShadowSectionCell(context);
        this.addDocumentSectionCell = shadowSectionCell2;
        shadowSectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.linearLayout2.addView(this.addDocumentSectionCell, LayoutHelper.createLinear(-1, -2));
        LinearLayout linearLayout = new LinearLayout(context);
        this.emptyLayout = linearLayout;
        linearLayout.setOrientation(1);
        this.emptyLayout.setGravity(17);
        this.emptyLayout.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        if (AndroidUtilities.isTablet()) {
            this.linearLayout2.addView(this.emptyLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.dp(528.0f) - ActionBar.getCurrentActionBarHeight()));
        } else {
            this.linearLayout2.addView(this.emptyLayout, new LinearLayout.LayoutParams(-1, AndroidUtilities.displaySize.y - ActionBar.getCurrentActionBarHeight()));
        }
        ImageView imageView = new ImageView(context);
        this.emptyImageView = imageView;
        imageView.setImageResource(R.drawable.no_passport);
        this.emptyImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_sessions_devicesImage), PorterDuff.Mode.MULTIPLY));
        this.emptyLayout.addView(this.emptyImageView, LayoutHelper.createLinear(-2, -2));
        TextView textView = new TextView(context);
        this.emptyTextView1 = textView;
        textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
        this.emptyTextView1.setGravity(17);
        this.emptyTextView1.setTextSize(1, 15.0f);
        this.emptyTextView1.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        this.emptyTextView1.setText(LocaleController.getString("PassportNoDocuments", R.string.PassportNoDocuments));
        this.emptyLayout.addView(this.emptyTextView1, LayoutHelper.createLinear(-2, -2, 17, 0, 16, 0, 0));
        TextView textView2 = new TextView(context);
        this.emptyTextView2 = textView2;
        textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText2));
        this.emptyTextView2.setGravity(17);
        this.emptyTextView2.setTextSize(1, 14.0f);
        this.emptyTextView2.setPadding(AndroidUtilities.dp(20.0f), 0, AndroidUtilities.dp(20.0f), 0);
        this.emptyTextView2.setText(LocaleController.getString("PassportNoDocumentsInfo", R.string.PassportNoDocumentsInfo));
        this.emptyLayout.addView(this.emptyTextView2, LayoutHelper.createLinear(-2, -2, 17, 0, 14, 0, 0));
        TextView textView3 = new TextView(context);
        this.emptyTextView3 = textView3;
        textView3.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
        this.emptyTextView3.setGravity(17);
        this.emptyTextView3.setTextSize(1, 15.0f);
        this.emptyTextView3.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
        this.emptyTextView3.setGravity(17);
        this.emptyTextView3.setText(LocaleController.getString("PassportNoDocumentsAdd", R.string.PassportNoDocumentsAdd).toUpperCase());
        this.emptyLayout.addView(this.emptyTextView3, LayoutHelper.createLinear(-2, 30, 17, 0, 16, 0, 0));
        this.emptyTextView3.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createManageInterface$22$PassportActivity(view);
            }
        });
        int size = this.currentForm.values.size();
        int a = 0;
        while (a < size) {
            TLRPC.TL_secureValue value = this.currentForm.values.get(a);
            if (!isPersonalDocument(value.type)) {
                if (isAddressDocument(value.type)) {
                    ArrayList<TLRPC.TL_secureRequiredType> documentTypes2 = new ArrayList<>();
                    TLRPC.TL_secureRequiredType requiredType2 = new TLRPC.TL_secureRequiredType();
                    requiredType2.type = value.type;
                    requiredType2.translation_required = true;
                    documentTypes2.add(requiredType2);
                    TLRPC.TL_secureRequiredType requiredType3 = new TLRPC.TL_secureRequiredType();
                    requiredType3.type = new TLRPC.TL_secureValueTypeAddress();
                    documentTypes = documentTypes2;
                    requiredType = requiredType3;
                    documentOnly = true;
                } else {
                    TLRPC.TL_secureRequiredType requiredType4 = new TLRPC.TL_secureRequiredType();
                    requiredType4.type = value.type;
                    documentTypes = null;
                    requiredType = requiredType4;
                    documentOnly = false;
                }
            } else {
                ArrayList<TLRPC.TL_secureRequiredType> documentTypes3 = new ArrayList<>();
                TLRPC.TL_secureRequiredType requiredType5 = new TLRPC.TL_secureRequiredType();
                requiredType5.type = value.type;
                requiredType5.selfie_required = true;
                requiredType5.translation_required = true;
                documentTypes3.add(requiredType5);
                TLRPC.TL_secureRequiredType requiredType6 = new TLRPC.TL_secureRequiredType();
                requiredType6.type = new TLRPC.TL_secureValueTypePersonalDetails();
                documentTypes = documentTypes3;
                requiredType = requiredType6;
                documentOnly = true;
            }
            addField(context, requiredType, documentTypes, documentOnly, a == size + (-1));
            a++;
        }
        updateManageVisibility();
    }

    public void lambda$createManageInterface$17$PassportActivity(View v) {
        openAddDocumentAlert();
    }

    public void lambda$createManageInterface$21$PassportActivity(View v) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$null$20$PassportActivity(dialogInterface, i);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setMessage(LocaleController.getString("AppPassportDeleteAlert", R.string.AppPassportDeleteAlert));
        showDialog(builder.create());
    }

    public void lambda$null$20$PassportActivity(DialogInterface dialog, int which) {
        TLRPC.TL_account_deleteSecureValue req = new TLRPC.TL_account_deleteSecureValue();
        for (int a = 0; a < this.currentForm.values.size(); a++) {
            req.types.add(this.currentForm.values.get(a).type);
        }
        needShowProgress();
        ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                PassportActivity.this.lambda$null$19$PassportActivity(tLObject, tL_error);
            }
        });
    }

    public void lambda$null$19$PassportActivity(TLObject response, TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$18$PassportActivity();
            }
        });
    }

    public void lambda$null$18$PassportActivity() {
        int a = 0;
        while (a < this.linearLayout2.getChildCount()) {
            View child = this.linearLayout2.getChildAt(a);
            if (child instanceof TextDetailSecureCell) {
                this.linearLayout2.removeView(child);
                a--;
            }
            a++;
        }
        needHideProgress();
        this.typesViews.clear();
        this.typesValues.clear();
        this.currentForm.values.clear();
        updateManageVisibility();
    }

    public void lambda$createManageInterface$22$PassportActivity(View v) {
        openAddDocumentAlert();
    }

    private boolean hasNotValueForType(Class<? extends TLRPC.SecureValueType> type) {
        int count = this.currentForm.values.size();
        for (int a = 0; a < count; a++) {
            if (this.currentForm.values.get(a).type.getClass() == type) {
                return false;
            }
        }
        return true;
    }

    private boolean hasUnfilledValues() {
        return hasNotValueForType(TLRPC.TL_secureValueTypePhone.class) || hasNotValueForType(TLRPC.TL_secureValueTypeEmail.class) || hasNotValueForType(TLRPC.TL_secureValueTypePersonalDetails.class) || hasNotValueForType(TLRPC.TL_secureValueTypePassport.class) || hasNotValueForType(TLRPC.TL_secureValueTypeInternalPassport.class) || hasNotValueForType(TLRPC.TL_secureValueTypeIdentityCard.class) || hasNotValueForType(TLRPC.TL_secureValueTypeDriverLicense.class) || hasNotValueForType(TLRPC.TL_secureValueTypeAddress.class) || hasNotValueForType(TLRPC.TL_secureValueTypeUtilityBill.class) || hasNotValueForType(TLRPC.TL_secureValueTypePassportRegistration.class) || hasNotValueForType(TLRPC.TL_secureValueTypeTemporaryRegistration.class) || hasNotValueForType(TLRPC.TL_secureValueTypeBankStatement.class) || hasNotValueForType(TLRPC.TL_secureValueTypeRentalAgreement.class);
    }

    private void openAddDocumentAlert() {
        ArrayList<CharSequence> values = new ArrayList<>();
        final ArrayList<Class<? extends TLRPC.SecureValueType>> types = new ArrayList<>();
        if (hasNotValueForType(TLRPC.TL_secureValueTypePhone.class)) {
            values.add(LocaleController.getString("ActionBotDocumentPhone", R.string.ActionBotDocumentPhone));
            types.add(TLRPC.TL_secureValueTypePhone.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeEmail.class)) {
            values.add(LocaleController.getString("ActionBotDocumentEmail", R.string.ActionBotDocumentEmail));
            types.add(TLRPC.TL_secureValueTypeEmail.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypePersonalDetails.class)) {
            values.add(LocaleController.getString("ActionBotDocumentIdentity", R.string.ActionBotDocumentIdentity));
            types.add(TLRPC.TL_secureValueTypePersonalDetails.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypePassport.class)) {
            values.add(LocaleController.getString("ActionBotDocumentPassport", R.string.ActionBotDocumentPassport));
            types.add(TLRPC.TL_secureValueTypePassport.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeInternalPassport.class)) {
            values.add(LocaleController.getString("ActionBotDocumentInternalPassport", R.string.ActionBotDocumentInternalPassport));
            types.add(TLRPC.TL_secureValueTypeInternalPassport.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypePassportRegistration.class)) {
            values.add(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
            types.add(TLRPC.TL_secureValueTypePassportRegistration.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeTemporaryRegistration.class)) {
            values.add(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
            types.add(TLRPC.TL_secureValueTypeTemporaryRegistration.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeIdentityCard.class)) {
            values.add(LocaleController.getString("ActionBotDocumentIdentityCard", R.string.ActionBotDocumentIdentityCard));
            types.add(TLRPC.TL_secureValueTypeIdentityCard.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeDriverLicense.class)) {
            values.add(LocaleController.getString("ActionBotDocumentDriverLicence", R.string.ActionBotDocumentDriverLicence));
            types.add(TLRPC.TL_secureValueTypeDriverLicense.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeAddress.class)) {
            values.add(LocaleController.getString("ActionBotDocumentAddress", R.string.ActionBotDocumentAddress));
            types.add(TLRPC.TL_secureValueTypeAddress.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeUtilityBill.class)) {
            values.add(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
            types.add(TLRPC.TL_secureValueTypeUtilityBill.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeBankStatement.class)) {
            values.add(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
            types.add(TLRPC.TL_secureValueTypeBankStatement.class);
        }
        if (hasNotValueForType(TLRPC.TL_secureValueTypeRentalAgreement.class)) {
            values.add(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
            types.add(TLRPC.TL_secureValueTypeRentalAgreement.class);
        }
        if (getParentActivity() == null || values.isEmpty()) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setTitle(LocaleController.getString("PassportNoDocumentsAdd", R.string.PassportNoDocumentsAdd));
        builder.setItems((CharSequence[]) values.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$openAddDocumentAlert$23$PassportActivity(types, dialogInterface, i);
            }
        });
        showDialog(builder.create());
    }

    public void lambda$openAddDocumentAlert$23$PassportActivity(ArrayList types, DialogInterface dialog, int which) {
        TLRPC.TL_secureRequiredType requiredType = null;
        TLRPC.TL_secureRequiredType documentRequiredType = null;
        try {
            requiredType = new TLRPC.TL_secureRequiredType();
            requiredType.type = (TLRPC.SecureValueType) ((Class) types.get(which)).newInstance();
        } catch (Exception e) {
        }
        if (isPersonalDocument(requiredType.type)) {
            documentRequiredType = requiredType;
            documentRequiredType.selfie_required = true;
            documentRequiredType.translation_required = true;
            requiredType = new TLRPC.TL_secureRequiredType();
            requiredType.type = new TLRPC.TL_secureValueTypePersonalDetails();
        } else if (isAddressDocument(requiredType.type)) {
            documentRequiredType = requiredType;
            requiredType = new TLRPC.TL_secureRequiredType();
            requiredType.type = new TLRPC.TL_secureValueTypeAddress();
        }
        openTypeActivity(requiredType, documentRequiredType, new ArrayList<>(), documentRequiredType != null);
    }

    private void updateManageVisibility() {
        if (this.currentForm.values.isEmpty()) {
            this.emptyLayout.setVisibility(0);
            this.sectionCell.setVisibility(8);
            this.headerCell.setVisibility(8);
            this.addDocumentCell.setVisibility(8);
            this.deletePassportCell.setVisibility(8);
            this.addDocumentSectionCell.setVisibility(8);
            return;
        }
        this.emptyLayout.setVisibility(8);
        this.sectionCell.setVisibility(0);
        this.headerCell.setVisibility(0);
        this.deletePassportCell.setVisibility(0);
        this.addDocumentSectionCell.setVisibility(0);
        if (hasUnfilledValues()) {
            this.addDocumentCell.setVisibility(0);
        } else {
            this.addDocumentCell.setVisibility(8);
        }
    }

    public void callCallback(boolean success) {
        int i;
        int i2;
        if (!this.callbackCalled) {
            if (!TextUtils.isEmpty(this.currentCallbackUrl)) {
                if (success) {
                    Browser.openUrl(getParentActivity(), Uri.parse(this.currentCallbackUrl + "&tg_passport=success"));
                } else if (!this.ignoreOnFailure && ((i2 = this.currentActivityType) == 5 || i2 == 0)) {
                    Browser.openUrl(getParentActivity(), Uri.parse(this.currentCallbackUrl + "&tg_passport=cancel"));
                }
                this.callbackCalled = true;
                return;
            }
            if (this.needActivityResult) {
                if (success || (!this.ignoreOnFailure && ((i = this.currentActivityType) == 5 || i == 0))) {
                    getParentActivity().setResult(success ? -1 : 0);
                }
                this.callbackCalled = true;
            }
        }
    }

    private void createEmailInterface(Context context) {
        this.actionBar.setTitle(LocaleController.getString("PassportEmail", R.string.PassportEmail));
        if (!TextUtils.isEmpty(this.currentEmail)) {
            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, this.currentEmail), false);
            this.linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(-1, -2));
            settingsCell1.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.this.lambda$createEmailInterface$24$PassportActivity(view);
                }
            });
            TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell;
            textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            this.bottomCell.setText(LocaleController.getString("PassportPhoneUseSameEmailInfo", R.string.PassportPhoneUseSameEmailInfo));
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
        }
        this.inputFields = new EditTextBoldCursor[1];
        for (int a = 0; a < 1; a++) {
            ViewGroup container = new FrameLayout(context);
            this.linearLayout2.addView(container, LayoutHelper.createLinear(-1, 50));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            this.inputFields[a] = new EditTextBoldCursor(context);
            this.inputFields[a].setTag(Integer.valueOf(a));
            this.inputFields[a].setTextSize(1, 16.0f);
            this.inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            this.inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setBackgroundDrawable(null);
            this.inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setCursorSize(AndroidUtilities.dp(20.0f));
            this.inputFields[a].setCursorWidth(1.5f);
            this.inputFields[a].setInputType(33);
            this.inputFields[a].setImeOptions(268435462);
            this.inputFields[a].setHint(LocaleController.getString("PaymentShippingEmailPlaceholder", R.string.PaymentShippingEmailPlaceholder));
            TLRPC.TL_secureValue tL_secureValue = this.currentTypeValue;
            if (tL_secureValue != null && (tL_secureValue.plain_data instanceof TLRPC.TL_securePlainEmail)) {
                TLRPC.TL_securePlainEmail securePlainEmail = (TLRPC.TL_securePlainEmail) this.currentTypeValue.plain_data;
                if (!TextUtils.isEmpty(securePlainEmail.email)) {
                    this.inputFields[a].setText(securePlainEmail.email);
                }
            }
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
            this.inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6.0f));
            this.inputFields[a].setGravity(LocaleController.isRTL ? 5 : 3);
            container.addView(this.inputFields[a], LayoutHelper.createFrame(-1.0f, -2.0f, 51, 21.0f, 12.0f, 21.0f, 6.0f));
            this.inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public final boolean onEditorAction(TextView textView, int i, KeyEvent keyEvent) {
                    return PassportActivity.this.lambda$createEmailInterface$25$PassportActivity(textView, i, keyEvent);
                }
            });
        }
        TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
        this.bottomCell = textInfoPrivacyCell2;
        textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.bottomCell.setText(LocaleController.getString("PassportEmailUploadInfo", R.string.PassportEmailUploadInfo));
        this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
    }

    public void lambda$createEmailInterface$24$PassportActivity(View v) {
        this.useCurrentValue = true;
        this.doneItem.callOnClick();
        this.useCurrentValue = false;
    }

    public boolean lambda$createEmailInterface$25$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 6 || i == 5) {
            this.doneItem.callOnClick();
            return true;
        }
        return false;
    }

    private void createPhoneInterface(Context context) {
        String countryName;
        ViewGroup container;
        this.actionBar.setTitle(LocaleController.getString("PassportPhone", R.string.PassportPhone));
        this.languageMap = new HashMap<>();
        int i = 3;
        int i2 = 1;
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                String[] args = line.split(";");
                this.countriesArray.add(0, args[2]);
                this.countriesMap.put(args[2], args[0]);
                this.codesMap.put(args[0], args[2]);
                if (args.length > 3) {
                    this.phoneFormatMap.put(args[0], args[3]);
                }
                this.languageMap.put(args[1], args[2]);
            }
            reader.close();
        } catch (Exception e) {
            FileLog.e(e);
        }
        Collections.sort(this.countriesArray, $$Lambda$TEfSBt3hRUlBSSARfPEHsJesTtE.INSTANCE);
        String currentPhone = UserConfig.getInstance(this.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(Marker.ANY_NON_NULL_MARKER + currentPhone)), false);
        int i3 = -1;
        this.linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(-1, -2));
        settingsCell1.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$createPhoneInterface$26$PassportActivity(view);
            }
        });
        TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
        this.bottomCell = textInfoPrivacyCell;
        textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.bottomCell.setText(LocaleController.getString("PassportPhoneUseSameInfo", R.string.PassportPhoneUseSameInfo));
        this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
        HeaderCell headerCell = new HeaderCell(context);
        this.headerCell = headerCell;
        headerCell.setText(LocaleController.getString("PassportPhoneUseOther", R.string.PassportPhoneUseOther));
        this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
        this.inputFields = new EditTextBoldCursor[3];
        int a = 0;
        while (a < i) {
            if (a == 2) {
                this.inputFields[a] = new HintEditText(context);
            } else {
                this.inputFields[a] = new EditTextBoldCursor(context);
            }
            if (a == i2) {
                container = new LinearLayout(context);
                ((LinearLayout) container).setOrientation(0);
                this.linearLayout2.addView(container, LayoutHelper.createLinear(i3, 50));
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            } else if (a == 2) {
                container = (ViewGroup) this.inputFields[i2].getParent();
            } else {
                container = new FrameLayout(context);
                this.linearLayout2.addView(container, LayoutHelper.createLinear(i3, 50));
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            }
            this.inputFields[a].setTag(Integer.valueOf(a));
            this.inputFields[a].setTextSize(i2, 16.0f);
            this.inputFields[a].setHintTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            this.inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setBackgroundDrawable(null);
            this.inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setCursorSize(AndroidUtilities.dp(20.0f));
            this.inputFields[a].setCursorWidth(1.5f);
            if (a == 0) {
                this.inputFields[a].setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public final boolean onTouch(View view, MotionEvent motionEvent) {
                        return PassportActivity.this.lambda$createPhoneInterface$29$PassportActivity(view, motionEvent);
                    }
                });
                this.inputFields[a].setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
                this.inputFields[a].setInputType(0);
                this.inputFields[a].setFocusable(false);
            } else {
                this.inputFields[a].setInputType(i);
                if (a == 2) {
                    this.inputFields[a].setImeOptions(268435462);
                } else {
                    this.inputFields[a].setImeOptions(268435461);
                }
            }
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
            if (a == 1) {
                TextView textView = new TextView(context);
                this.plusTextView = textView;
                textView.setText(Marker.ANY_NON_NULL_MARKER);
                this.plusTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                this.plusTextView.setTextSize(1, 16.0f);
                container.addView(this.plusTextView, LayoutHelper.createLinear(-2, -2, 21.0f, 12.0f, 0.0f, 6.0f));
                this.inputFields[a].setPadding(AndroidUtilities.dp(10.0f), 0, 0, 0);
                InputFilter[] inputFilters = {new InputFilter.LengthFilter(5)};
                this.inputFields[a].setFilters(inputFilters);
                this.inputFields[a].setGravity(19);
                container.addView(this.inputFields[a], LayoutHelper.createLinear(55, -2, 0.0f, 12.0f, 16.0f, 6.0f));
                this.inputFields[a].addTextChangedListener(new TextWatcher() {
                    @Override
                    public void beforeTextChanged(CharSequence charSequence, int i4, int i22, int i32) {
                    }

                    @Override
                    public void onTextChanged(CharSequence charSequence, int i4, int i22, int i32) {
                    }

                    @Override
                    public void afterTextChanged(Editable editable) {
                        int index;
                        if (!PassportActivity.this.ignoreOnTextChange) {
                            PassportActivity.this.ignoreOnTextChange = true;
                            String text = PhoneFormat.stripExceptNumbers(PassportActivity.this.inputFields[1].getText().toString());
                            PassportActivity.this.inputFields[1].setText(text);
                            HintEditText phoneField = (HintEditText) PassportActivity.this.inputFields[2];
                            if (text.length() == 0) {
                                phoneField.setHintText((String) null);
                                phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                                PassportActivity.this.inputFields[0].setText(LocaleController.getString("ChooseCountry", R.string.ChooseCountry));
                            } else {
                                boolean ok = false;
                                String textToSet = null;
                                if (text.length() > 4) {
                                    int a2 = 4;
                                    while (true) {
                                        if (a2 < 1) {
                                            break;
                                        }
                                        String sub = text.substring(0, a2);
                                        if (((String) PassportActivity.this.codesMap.get(sub)) == null) {
                                            a2--;
                                        } else {
                                            ok = true;
                                            textToSet = text.substring(a2) + PassportActivity.this.inputFields[2].getText().toString();
                                            text = sub;
                                            PassportActivity.this.inputFields[1].setText(sub);
                                            break;
                                        }
                                    }
                                    if (!ok) {
                                        textToSet = text.substring(1) + PassportActivity.this.inputFields[2].getText().toString();
                                        EditTextBoldCursor editTextBoldCursor = PassportActivity.this.inputFields[1];
                                        String substring = text.substring(0, 1);
                                        text = substring;
                                        editTextBoldCursor.setText(substring);
                                    }
                                }
                                String country = (String) PassportActivity.this.codesMap.get(text);
                                boolean set = false;
                                if (country != null && (index = PassportActivity.this.countriesArray.indexOf(country)) != -1) {
                                    PassportActivity.this.inputFields[0].setText((CharSequence) PassportActivity.this.countriesArray.get(index));
                                    String hint = (String) PassportActivity.this.phoneFormatMap.get(text);
                                    set = true;
                                    if (hint != null) {
                                        phoneField.setHintText(hint.replace('X', Typography.ndash));
                                        phoneField.setHint((CharSequence) null);
                                    }
                                }
                                if (!set) {
                                    phoneField.setHintText((String) null);
                                    phoneField.setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                                    PassportActivity.this.inputFields[0].setText(LocaleController.getString("WrongCountry", R.string.WrongCountry));
                                }
                                if (!ok) {
                                    PassportActivity.this.inputFields[1].setSelection(PassportActivity.this.inputFields[1].getText().length());
                                }
                                if (textToSet != null) {
                                    phoneField.requestFocus();
                                    phoneField.setText(textToSet);
                                    phoneField.setSelection(phoneField.length());
                                }
                            }
                            PassportActivity.this.ignoreOnTextChange = false;
                        }
                    }
                });
            } else if (a == 2) {
                this.inputFields[a].setPadding(0, 0, 0, 0);
                this.inputFields[a].setGravity(19);
                this.inputFields[a].setHintText(null);
                this.inputFields[a].setHint(LocaleController.getString("PaymentShippingPhoneNumber", R.string.PaymentShippingPhoneNumber));
                container.addView(this.inputFields[a], LayoutHelper.createLinear(-1, -2, 0.0f, 12.0f, 21.0f, 6.0f));
                this.inputFields[a].addTextChangedListener(new TextWatcher() {
                    private int actionPosition;
                    private int characterAction = -1;

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

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

                    @Override
                    public void afterTextChanged(Editable s) {
                        int i4;
                        int i5;
                        if (!PassportActivity.this.ignoreOnPhoneChange) {
                            HintEditText phoneField = (HintEditText) PassportActivity.this.inputFields[2];
                            int start = phoneField.getSelectionStart();
                            String str = phoneField.getText().toString();
                            if (this.characterAction == 3) {
                                str = str.substring(0, this.actionPosition) + str.substring(this.actionPosition + 1);
                                start--;
                            }
                            StringBuilder builder = new StringBuilder(str.length());
                            for (int a2 = 0; a2 < str.length(); a2++) {
                                String ch = str.substring(a2, a2 + 1);
                                if ("0123456789".contains(ch)) {
                                    builder.append(ch);
                                }
                            }
                            PassportActivity.this.ignoreOnPhoneChange = true;
                            String hint = phoneField.getHintText();
                            if (hint != null) {
                                int a3 = 0;
                                while (true) {
                                    if (a3 >= builder.length()) {
                                        break;
                                    }
                                    if (a3 < hint.length()) {
                                        if (hint.charAt(a3) == ' ') {
                                            builder.insert(a3, ' ');
                                            a3++;
                                            if (start == a3 && (i5 = this.characterAction) != 2 && i5 != 3) {
                                                start++;
                                            }
                                        }
                                        a3++;
                                    } else {
                                        builder.insert(a3, ' ');
                                        if (start == a3 + 1 && (i4 = this.characterAction) != 2 && i4 != 3) {
                                            start++;
                                        }
                                    }
                                }
                            }
                            phoneField.setText(builder);
                            if (start >= 0) {
                                phoneField.setSelection(start <= phoneField.length() ? start : phoneField.length());
                            }
                            phoneField.onTextChange();
                            PassportActivity.this.ignoreOnPhoneChange = false;
                        }
                    }
                });
            } else {
                this.inputFields[a].setPadding(0, 0, 0, AndroidUtilities.dp(6.0f));
                this.inputFields[a].setGravity(LocaleController.isRTL ? 5 : 3);
                container.addView(this.inputFields[a], LayoutHelper.createFrame(-1.0f, -2.0f, 51, 21.0f, 12.0f, 21.0f, 6.0f));
            }
            this.inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public final boolean onEditorAction(TextView textView2, int i4, KeyEvent keyEvent) {
                    return PassportActivity.this.lambda$createPhoneInterface$30$PassportActivity(textView2, i4, keyEvent);
                }
            });
            if (a == 2) {
                this.inputFields[a].setOnKeyListener(new View.OnKeyListener() {
                    @Override
                    public final boolean onKey(View view, int i4, KeyEvent keyEvent) {
                        return PassportActivity.this.lambda$createPhoneInterface$31$PassportActivity(view, i4, keyEvent);
                    }
                });
            }
            if (a == 0) {
                View divider = new View(context);
                this.dividers.add(divider);
                divider.setBackgroundColor(Theme.getColor(Theme.key_divider));
                container.addView(divider, new FrameLayout.LayoutParams(-1, 1, 83));
            }
            a++;
            i = 3;
            i2 = 1;
            i3 = -1;
        }
        String country = null;
        try {
            TelephonyManager telephonyManager = (TelephonyManager) ApplicationLoader.applicationContext.getSystemService("phone");
            if (telephonyManager != null) {
                country = telephonyManager.getSimCountryIso().toUpperCase();
            }
        } catch (Exception e2) {
            FileLog.e(e2);
        }
        if (country != null && (countryName = this.languageMap.get(country)) != null) {
            int index = this.countriesArray.indexOf(countryName);
            if (index != -1) {
                this.inputFields[1].setText(this.countriesMap.get(countryName));
            }
        }
        TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
        this.bottomCell = textInfoPrivacyCell2;
        textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
        this.bottomCell.setText(LocaleController.getString("PassportPhoneUploadInfo", R.string.PassportPhoneUploadInfo));
        this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
    }

    public void lambda$createPhoneInterface$26$PassportActivity(View v) {
        this.useCurrentValue = true;
        this.doneItem.callOnClick();
        this.useCurrentValue = false;
    }

    public boolean lambda$createPhoneInterface$29$PassportActivity(View v, MotionEvent event) {
        if (getParentActivity() == null) {
            return false;
        }
        if (event.getAction() == 1) {
            CountrySelectActivity fragment = new CountrySelectActivity(false);
            fragment.setCountrySelectActivityDelegate(new CountrySelectActivity.CountrySelectActivityDelegate() {
                @Override
                public final void didSelectCountry(CountrySelectActivity.Country country) {
                    PassportActivity.this.lambda$null$28$PassportActivity(country);
                }
            });
            presentFragment(fragment);
        }
        return true;
    }

    public void lambda$null$28$PassportActivity(CountrySelectActivity.Country country) {
        if (country != null) {
            this.inputFields[0].setText(country.name);
            int index = this.countriesArray.indexOf(country.name);
            if (index != -1) {
                this.ignoreOnTextChange = true;
                String code = this.countriesMap.get(country.name);
                this.inputFields[1].setText(code);
                String hint = this.phoneFormatMap.get(code);
                this.inputFields[2].setHintText(hint != null ? hint.replace('X', Typography.ndash) : null);
                this.ignoreOnTextChange = false;
            }
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.this.lambda$null$27$PassportActivity();
                }
            }, 300L);
            this.inputFields[2].requestFocus();
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[2].setSelection(editTextBoldCursorArr[2].length());
        }
    }

    public void lambda$null$27$PassportActivity() {
        AndroidUtilities.showKeyboard(this.inputFields[2]);
    }

    public boolean lambda$createPhoneInterface$30$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 5) {
            this.inputFields[2].requestFocus();
            return true;
        }
        if (i == 6) {
            this.doneItem.callOnClick();
            return true;
        }
        return false;
    }

    public boolean lambda$createPhoneInterface$31$PassportActivity(View v, int keyCode, KeyEvent event) {
        if (keyCode == 67 && this.inputFields[2].length() == 0) {
            this.inputFields[1].requestFocus();
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[1].setSelection(editTextBoldCursorArr[1].length());
            this.inputFields[1].dispatchKeyEvent(event);
            return true;
        }
        return false;
    }

    private void createAddressInterface(Context context) {
        final String key;
        String errorText;
        String errorText2;
        this.languageMap = new HashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                String[] args = line.split(";");
                this.languageMap.put(args[1], args[2]);
            }
            reader.close();
        } catch (Exception e) {
            FileLog.e(e);
        }
        TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
        this.topErrorCell = textInfoPrivacyCell;
        textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow));
        this.topErrorCell.setPadding(0, AndroidUtilities.dp(7.0f), 0, 0);
        this.linearLayout2.addView(this.topErrorCell, LayoutHelper.createLinear(-1, -2));
        checkTopErrorCell(true);
        TLRPC.TL_secureRequiredType tL_secureRequiredType = this.currentDocumentsType;
        if (tL_secureRequiredType != null) {
            if (tL_secureRequiredType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                this.actionBar.setTitle(LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement));
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                this.actionBar.setTitle(LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement));
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                this.actionBar.setTitle(LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill));
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                this.actionBar.setTitle(LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration));
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                this.actionBar.setTitle(LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration));
            }
            HeaderCell headerCell = new HeaderCell(context);
            this.headerCell = headerCell;
            headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments));
            this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
            LinearLayout linearLayout = new LinearLayout(context);
            this.documentsLayout = linearLayout;
            linearLayout.setOrientation(1);
            this.linearLayout2.addView(this.documentsLayout, LayoutHelper.createLinear(-1, -2));
            TextSettingsCell textSettingsCell = new TextSettingsCell(context);
            this.uploadDocumentCell = textSettingsCell;
            textSettingsCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            this.linearLayout2.addView(this.uploadDocumentCell, LayoutHelper.createLinear(-1, -2));
            this.uploadDocumentCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.this.lambda$createAddressInterface$32$PassportActivity(view);
                }
            });
            TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell2;
            textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            if (this.currentBotId != 0) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddAddressUploadInfo", R.string.PassportAddAddressUploadInfo);
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddAgreementInfo", R.string.PassportAddAgreementInfo);
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddBillInfo", R.string.PassportAddBillInfo);
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddPassportRegistrationInfo", R.string.PassportAddPassportRegistrationInfo);
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddTemporaryRegistrationInfo", R.string.PassportAddTemporaryRegistrationInfo);
            } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                this.noAllDocumentsErrorText = LocaleController.getString("PassportAddBankInfo", R.string.PassportAddBankInfo);
            } else {
                this.noAllDocumentsErrorText = "";
            }
            CharSequence text = this.noAllDocumentsErrorText;
            HashMap<String, String> hashMap = this.documentsErrors;
            if (hashMap != null && (errorText2 = hashMap.get("files_all")) != null) {
                SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText2);
                stringBuilder.append((CharSequence) "\n\n");
                stringBuilder.append(this.noAllDocumentsErrorText);
                text = stringBuilder;
                stringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText2.length(), 33);
                this.errorsValues.put("files_all", "");
            }
            this.bottomCell.setText(text);
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
            if (this.currentDocumentsType.translation_required) {
                HeaderCell headerCell2 = new HeaderCell(context);
                this.headerCell = headerCell2;
                headerCell2.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation));
                this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
                LinearLayout linearLayout2 = new LinearLayout(context);
                this.translationLayout = linearLayout2;
                linearLayout2.setOrientation(1);
                this.linearLayout2.addView(this.translationLayout, LayoutHelper.createLinear(-1, -2));
                TextSettingsCell textSettingsCell2 = new TextSettingsCell(context);
                this.uploadTranslationCell = textSettingsCell2;
                textSettingsCell2.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                this.linearLayout2.addView(this.uploadTranslationCell, LayoutHelper.createLinear(-1, -2));
                this.uploadTranslationCell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        PassportActivity.this.lambda$createAddressInterface$33$PassportActivity(view);
                    }
                });
                TextInfoPrivacyCell textInfoPrivacyCell3 = new TextInfoPrivacyCell(context);
                this.bottomCellTranslation = textInfoPrivacyCell3;
                textInfoPrivacyCell3.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                if (this.currentBotId != 0) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationAgreementInfo", R.string.PassportAddTranslationAgreementInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBillInfo", R.string.PassportAddTranslationBillInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationPassportRegistrationInfo", R.string.PassportAddTranslationPassportRegistrationInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationTemporaryRegistrationInfo", R.string.PassportAddTranslationTemporaryRegistrationInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationBankInfo", R.string.PassportAddTranslationBankInfo);
                } else {
                    this.noAllTranslationErrorText = "";
                }
                CharSequence text2 = this.noAllTranslationErrorText;
                HashMap<String, String> hashMap2 = this.documentsErrors;
                if (hashMap2 != null && (errorText = hashMap2.get("translation_all")) != null) {
                    SpannableStringBuilder stringBuilder2 = new SpannableStringBuilder(errorText);
                    stringBuilder2.append((CharSequence) "\n\n");
                    stringBuilder2.append(this.noAllTranslationErrorText);
                    text2 = stringBuilder2;
                    stringBuilder2.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), 33);
                    this.errorsValues.put("translation_all", "");
                }
                this.bottomCellTranslation.setText(text2);
                this.linearLayout2.addView(this.bottomCellTranslation, LayoutHelper.createLinear(-1, -2));
            }
        } else {
            this.actionBar.setTitle(LocaleController.getString("PassportAddress", R.string.PassportAddress));
        }
        HeaderCell headerCell3 = new HeaderCell(context);
        this.headerCell = headerCell3;
        headerCell3.setText(LocaleController.getString("PassportAddressHeader", R.string.PassportAddressHeader));
        this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
        this.inputFields = new EditTextBoldCursor[6];
        int a = 0;
        for (int i = 6; a < i; i = 6) {
            final EditTextBoldCursor field = new EditTextBoldCursor(context);
            this.inputFields[a] = field;
            ViewGroup container = new FrameLayout(context) {
                private StaticLayout errorLayout;
                float offsetX;

                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    int width = View.MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34.0f);
                    StaticLayout errorLayout = field.getErrorLayout(width);
                    this.errorLayout = errorLayout;
                    if (errorLayout != null) {
                        int lineCount = errorLayout.getLineCount();
                        if (lineCount > 1) {
                            int height = AndroidUtilities.dp(64.0f) + (this.errorLayout.getLineBottom(lineCount - 1) - this.errorLayout.getLineBottom(0));
                            heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, 1073741824);
                        }
                        if (LocaleController.isRTL) {
                            float maxW = 0.0f;
                            int a2 = 0;
                            while (true) {
                                if (a2 >= lineCount) {
                                    break;
                                }
                                float l = this.errorLayout.getLineLeft(a2);
                                if (l != 0.0f) {
                                    this.offsetX = 0.0f;
                                    break;
                                }
                                maxW = Math.max(maxW, this.errorLayout.getLineWidth(a2));
                                if (a2 == lineCount - 1) {
                                    this.offsetX = width - maxW;
                                }
                                a2++;
                            }
                        }
                    }
                    super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                }

                @Override
                protected void onDraw(Canvas canvas) {
                    if (this.errorLayout != null) {
                        canvas.save();
                        canvas.translate(AndroidUtilities.dp(21.0f) + this.offsetX, field.getLineY() + AndroidUtilities.dp(3.0f));
                        this.errorLayout.draw(canvas);
                        canvas.restore();
                    }
                }
            };
            container.setWillNotDraw(false);
            this.linearLayout2.addView(container, LayoutHelper.createLinear(-1, -2));
            container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            if (a == 5) {
                View view = new View(context);
                this.extraBackgroundView = view;
                view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                this.linearLayout2.addView(this.extraBackgroundView, LayoutHelper.createLinear(-1, i));
            }
            if (this.documentOnly && this.currentDocumentsType != null) {
                container.setVisibility(8);
                View view2 = this.extraBackgroundView;
                if (view2 != null) {
                    view2.setVisibility(8);
                }
            }
            this.inputFields[a].setTag(Integer.valueOf(a));
            this.inputFields[a].setSupportRtlHint(true);
            this.inputFields[a].setTextSize(1, 16.0f);
            this.inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
            this.inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
            this.inputFields[a].setTransformHintToHeader(true);
            this.inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setBackgroundDrawable(null);
            this.inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.inputFields[a].setCursorSize(AndroidUtilities.dp(20.0f));
            this.inputFields[a].setCursorWidth(1.5f);
            this.inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
            if (a == 5) {
                this.inputFields[a].setOnTouchListener(new View.OnTouchListener() {
                    @Override
                    public final boolean onTouch(View view3, MotionEvent motionEvent) {
                        return PassportActivity.this.lambda$createAddressInterface$35$PassportActivity(view3, motionEvent);
                    }
                });
                this.inputFields[a].setInputType(0);
                this.inputFields[a].setFocusable(false);
            } else {
                this.inputFields[a].setInputType(16385);
                this.inputFields[a].setImeOptions(268435461);
            }
            if (a == 0) {
                this.inputFields[a].setHintText(LocaleController.getString("PassportStreet1", R.string.PassportStreet1));
                key = "street_line1";
            } else if (a == 1) {
                this.inputFields[a].setHintText(LocaleController.getString("PassportStreet2", R.string.PassportStreet2));
                key = "street_line2";
            } else if (a != 2) {
                if (a == 3) {
                    this.inputFields[a].setHintText(LocaleController.getString("PassportCity", R.string.PassportCity));
                    key = "city";
                } else if (a != 4) {
                    if (a != 5) {
                        a++;
                    } else {
                        this.inputFields[a].setHintText(LocaleController.getString("PassportCountry", R.string.PassportCountry));
                        key = "country_code";
                    }
                } else {
                    this.inputFields[a].setHintText(LocaleController.getString("PassportState", R.string.PassportState));
                    key = RemoteConfigConstants.ResponseFieldKey.STATE;
                }
            } else {
                this.inputFields[a].setHintText(LocaleController.getString("PassportPostcode", R.string.PassportPostcode));
                key = "post_code";
            }
            setFieldValues(this.currentValues, this.inputFields[a], key);
            if (a == 2) {
                this.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 (this.ignore) {
                            return;
                        }
                        this.ignore = true;
                        boolean error = false;
                        int a2 = 0;
                        while (true) {
                            if (a2 >= s.length()) {
                                break;
                            }
                            char ch = s.charAt(a2);
                            if ((ch >= 'a' && ch <= 'z') || ((ch >= 'A' && ch <= 'Z') || ((ch >= '0' && ch <= '9') || ch == '-' || ch == ' '))) {
                                a2++;
                            } else {
                                error = true;
                                break;
                            }
                        }
                        this.ignore = false;
                        if (!error) {
                            PassportActivity.this.checkFieldForError(field, key, s, false);
                        } else {
                            field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly));
                        }
                    }
                });
                InputFilter[] inputFilters = {new InputFilter.LengthFilter(10)};
                this.inputFields[a].setFilters(inputFilters);
            } else {
                this.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) {
                        PassportActivity.this.checkFieldForError(field, key, s, false);
                    }
                });
            }
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
            this.inputFields[a].setPadding(0, 0, 0, 0);
            this.inputFields[a].setGravity((LocaleController.isRTL ? 5 : 3) | 16);
            container.addView(this.inputFields[a], LayoutHelper.createFrame(-1.0f, 64.0f, 51, 21.0f, 0.0f, 21.0f, 0.0f));
            this.inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                @Override
                public final boolean onEditorAction(TextView textView, int i2, KeyEvent keyEvent) {
                    return PassportActivity.this.lambda$createAddressInterface$36$PassportActivity(textView, i2, keyEvent);
                }
            });
            a++;
        }
        ShadowSectionCell shadowSectionCell = new ShadowSectionCell(context);
        this.sectionCell = shadowSectionCell;
        this.linearLayout2.addView(shadowSectionCell, LayoutHelper.createLinear(-1, -2));
        if (this.documentOnly && this.currentDocumentsType != null) {
            this.headerCell.setVisibility(8);
            this.sectionCell.setVisibility(8);
        }
        if (((this.currentBotId != 0 || this.currentDocumentsType == null) && this.currentTypeValue != null && !this.documentOnly) || this.currentDocumentsTypeValue != null) {
            TLRPC.TL_secureValue tL_secureValue = this.currentDocumentsTypeValue;
            if (tL_secureValue != null) {
                addDocumentViews(tL_secureValue.files);
                addTranslationDocumentViews(this.currentDocumentsTypeValue.translation);
            }
            this.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 (this.currentDocumentsType == null) {
                settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false);
            } else {
                settingsCell1.setText(LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false);
            }
            this.linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(-1, -2));
            settingsCell1.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view3) {
                    PassportActivity.this.lambda$createAddressInterface$37$PassportActivity(view3);
                }
            });
            ShadowSectionCell shadowSectionCell2 = new ShadowSectionCell(context);
            this.sectionCell = shadowSectionCell2;
            shadowSectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            this.linearLayout2.addView(this.sectionCell, LayoutHelper.createLinear(-1, -2));
        } else {
            this.sectionCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            if (this.documentOnly && this.currentDocumentsType != null) {
                this.bottomCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
            }
        }
        updateUploadText(0);
        updateUploadText(4);
    }

    public void lambda$createAddressInterface$32$PassportActivity(View v) {
        this.uploadingFileType = 0;
        openAttachMenu();
    }

    public void lambda$createAddressInterface$33$PassportActivity(View v) {
        this.uploadingFileType = 4;
        openAttachMenu();
    }

    public boolean lambda$createAddressInterface$35$PassportActivity(View v, MotionEvent event) {
        if (getParentActivity() == null) {
            return false;
        }
        if (event.getAction() == 1) {
            CountrySelectActivity fragment = new CountrySelectActivity(false);
            fragment.setCountrySelectActivityDelegate(new CountrySelectActivity.CountrySelectActivityDelegate() {
                @Override
                public final void didSelectCountry(CountrySelectActivity.Country country) {
                    PassportActivity.this.lambda$null$34$PassportActivity(country);
                }
            });
            presentFragment(fragment);
        }
        return true;
    }

    public void lambda$null$34$PassportActivity(CountrySelectActivity.Country country) {
        if (country != null) {
            this.inputFields[5].setText(country.name);
            this.currentCitizeship = country.shortname;
        }
    }

    public boolean lambda$createAddressInterface$36$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 5) {
            int num = ((Integer) textView.getTag()).intValue() + 1;
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            if (num < editTextBoldCursorArr.length) {
                if (editTextBoldCursorArr[num].isFocusable()) {
                    this.inputFields[num].requestFocus();
                } else {
                    this.inputFields[num].dispatchTouchEvent(MotionEvent.obtain(0L, 0L, 1, 0.0f, 0.0f, 0));
                    textView.clearFocus();
                    AndroidUtilities.hideKeyboard(textView);
                }
            }
            return true;
        }
        return false;
    }

    public void lambda$createAddressInterface$37$PassportActivity(View v) {
        createDocumentDeleteAlert();
    }

    private void createDocumentDeleteAlert() {
        final boolean[] checks = {true};
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$createDocumentDeleteAlert$38$PassportActivity(checks, dialogInterface, i);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        if (this.documentOnly && this.currentDocumentsType == null && (this.currentType.type instanceof TLRPC.TL_secureValueTypeAddress)) {
            builder.setMessage(LocaleController.getString("PassportDeleteAddressAlert", R.string.PassportDeleteAddressAlert));
        } else if (this.documentOnly && this.currentDocumentsType == null && (this.currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails)) {
            builder.setMessage(LocaleController.getString("PassportDeletePersonalAlert", R.string.PassportDeletePersonalAlert));
        } else {
            builder.setMessage(LocaleController.getString("PassportDeleteDocumentAlert", R.string.PassportDeleteDocumentAlert));
        }
        if (!this.documentOnly && this.currentDocumentsType != null) {
            FrameLayout frameLayout = new FrameLayout(getParentActivity());
            CheckBoxCell cell = new CheckBoxCell(getParentActivity(), 1);
            cell.setBackgroundDrawable(Theme.getSelectorDrawable(false));
            if (this.currentType.type instanceof TLRPC.TL_secureValueTypeAddress) {
                cell.setText(LocaleController.getString("PassportDeleteDocumentAddress", R.string.PassportDeleteDocumentAddress), "", true, false);
            } else if (this.currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                cell.setText(LocaleController.getString("PassportDeleteDocumentPersonal", R.string.PassportDeleteDocumentPersonal), "", true, false);
            }
            cell.setPadding(LocaleController.isRTL ? AndroidUtilities.dp(16.0f) : AndroidUtilities.dp(8.0f), 0, LocaleController.isRTL ? AndroidUtilities.dp(8.0f) : AndroidUtilities.dp(16.0f), 0);
            frameLayout.addView(cell, LayoutHelper.createFrame(-1, 48, 51));
            cell.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.lambda$createDocumentDeleteAlert$39(checks, view);
                }
            });
            builder.setView(frameLayout);
        }
        showDialog(builder.create());
    }

    public void lambda$createDocumentDeleteAlert$38$PassportActivity(boolean[] checks, DialogInterface dialog, int which) {
        if (!this.documentOnly) {
            this.currentValues.clear();
        }
        this.currentDocumentValues.clear();
        this.delegate.deleteValue(this.currentType, this.currentDocumentsType, this.availableDocumentTypes, checks[0], null, null);
        finishFragment();
    }

    public static void lambda$createDocumentDeleteAlert$39(boolean[] checks, View v) {
        if (!v.isEnabled()) {
            return;
        }
        CheckBoxCell cell1 = (CheckBoxCell) v;
        checks[0] = !checks[0];
        cell1.setChecked(checks[0], true);
    }

    public void onFieldError(View field) {
        if (field == null) {
            return;
        }
        Vibrator v = (Vibrator) getParentActivity().getSystemService("vibrator");
        if (v != null) {
            v.vibrate(200L);
        }
        AndroidUtilities.shakeView(field, 2.0f, 0);
        scrollToField(field);
    }

    private void scrollToField(View field) {
        while (field != null && this.linearLayout2.indexOfChild(field) < 0) {
            field = (View) field.getParent();
        }
        if (field != null) {
            this.scrollView.smoothScrollTo(0, field.getTop() - ((this.scrollView.getMeasuredHeight() - field.getMeasuredHeight()) / 2));
        }
    }

    public String getDocumentHash(SecureDocument document) {
        if (document != null) {
            if (document.secureFile != null && document.secureFile.file_hash != null) {
                return Base64.encodeToString(document.secureFile.file_hash, 2);
            }
            if (document.fileHash != null) {
                return Base64.encodeToString(document.fileHash, 2);
            }
            return "";
        }
        return "";
    }

    public void checkFieldForError(EditTextBoldCursor field, String key, Editable s, boolean document) {
        String value;
        String value2;
        String value3;
        HashMap<String, String> hashMap = this.errorsValues;
        if (hashMap != null && (value = hashMap.get(key)) != null) {
            if (TextUtils.equals(value, s)) {
                HashMap<String, String> hashMap2 = this.fieldsErrors;
                if (hashMap2 != null && (value3 = hashMap2.get(key)) != null) {
                    field.setErrorText(value3);
                } else {
                    HashMap<String, String> hashMap3 = this.documentsErrors;
                    if (hashMap3 != null && (value2 = hashMap3.get(key)) != null) {
                        field.setErrorText(value2);
                    }
                }
            } else {
                field.setErrorText(null);
            }
        } else {
            field.setErrorText(null);
        }
        String errorKey = document ? "error_document_all" : "error_all";
        HashMap<String, String> hashMap4 = this.errorsValues;
        if (hashMap4 != null && hashMap4.containsKey(errorKey)) {
            this.errorsValues.remove(errorKey);
            checkTopErrorCell(false);
        }
    }

    public boolean checkFieldsForError() {
        EditTextBoldCursor[] fields;
        String key;
        View view;
        if (this.currentDocumentsType != null) {
            if (this.errorsValues.containsKey("error_all") || this.errorsValues.containsKey("error_document_all")) {
                onFieldError(this.topErrorCell);
                return true;
            }
            if (this.uploadDocumentCell != null) {
                if (this.documents.isEmpty()) {
                    onFieldError(this.uploadDocumentCell);
                    return true;
                }
                int size = this.documents.size();
                for (int a = 0; a < size; a++) {
                    SecureDocument document = this.documents.get(a);
                    String key2 = "files" + getDocumentHash(document);
                    if (key2 != null && this.errorsValues.containsKey(key2)) {
                        onFieldError(this.documentsCells.get(document));
                        return true;
                    }
                }
            }
            if (this.errorsValues.containsKey("files_all") || this.errorsValues.containsKey("translation_all")) {
                onFieldError(this.bottomCell);
                return true;
            }
            View view2 = this.uploadFrontCell;
            if (view2 != null) {
                if (this.frontDocument == null) {
                    onFieldError(view2);
                    return true;
                }
                String key3 = "front" + getDocumentHash(this.frontDocument);
                if (this.errorsValues.containsKey(key3)) {
                    onFieldError(this.documentsCells.get(this.frontDocument));
                    return true;
                }
            }
            if (((this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) || (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense)) && (view = this.uploadReverseCell) != null) {
                if (this.reverseDocument == null) {
                    onFieldError(view);
                    return true;
                }
                String key4 = "reverse" + getDocumentHash(this.reverseDocument);
                if (this.errorsValues.containsKey(key4)) {
                    onFieldError(this.documentsCells.get(this.reverseDocument));
                    return true;
                }
            }
            View view3 = this.uploadSelfieCell;
            if (view3 != null && this.currentBotId != 0) {
                if (this.selfieDocument == null) {
                    onFieldError(view3);
                    return true;
                }
                String key5 = "selfie" + getDocumentHash(this.selfieDocument);
                if (this.errorsValues.containsKey(key5)) {
                    onFieldError(this.documentsCells.get(this.selfieDocument));
                    return true;
                }
            }
            if (this.uploadTranslationCell != null && this.currentBotId != 0) {
                if (this.translationDocuments.isEmpty()) {
                    onFieldError(this.uploadTranslationCell);
                    return true;
                }
                int size2 = this.translationDocuments.size();
                for (int a2 = 0; a2 < size2; a2++) {
                    SecureDocument document2 = this.translationDocuments.get(a2);
                    String key6 = "translation" + getDocumentHash(document2);
                    if (key6 != null && this.errorsValues.containsKey(key6)) {
                        onFieldError(this.documentsCells.get(document2));
                        return true;
                    }
                }
            }
        }
        for (int i = 0; i < 2; i++) {
            if (i == 0) {
                fields = this.inputFields;
            } else {
                TextInfoPrivacyCell textInfoPrivacyCell = this.nativeInfoCell;
                fields = (textInfoPrivacyCell == null || textInfoPrivacyCell.getVisibility() != 0) ? null : this.inputExtraFields;
            }
            if (fields != null) {
                for (int a3 = 0; a3 < fields.length; a3++) {
                    boolean error = false;
                    if (fields[a3].hasErrorText()) {
                        error = true;
                    }
                    if (!this.errorsValues.isEmpty()) {
                        if (this.currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                            if (i == 0) {
                                switch (a3) {
                                    case 0:
                                        key = "first_name";
                                        break;
                                    case 1:
                                        key = "middle_name";
                                        break;
                                    case 2:
                                        key = "last_name";
                                        break;
                                    case 3:
                                        key = "birth_date";
                                        break;
                                    case 4:
                                        key = "gender";
                                        break;
                                    case 5:
                                        key = "country_code";
                                        break;
                                    case 6:
                                        key = "residence_country_code";
                                        break;
                                    case 7:
                                        key = "document_no";
                                        break;
                                    case 8:
                                        key = "expiry_date";
                                        break;
                                    default:
                                        key = null;
                                        break;
                                }
                            } else if (a3 == 0) {
                                key = "first_name_native";
                            } else if (a3 == 1) {
                                key = "middle_name_native";
                            } else if (a3 == 2) {
                                key = "last_name_native";
                            } else {
                                key = null;
                            }
                        } else if (this.currentType.type instanceof TLRPC.TL_secureValueTypeAddress) {
                            if (a3 == 0) {
                                key = "street_line1";
                            } else if (a3 == 1) {
                                key = "street_line2";
                            } else if (a3 == 2) {
                                key = "post_code";
                            } else if (a3 == 3) {
                                key = "city";
                            } else if (a3 == 4) {
                                key = RemoteConfigConstants.ResponseFieldKey.STATE;
                            } else if (a3 == 5) {
                                key = "country_code";
                            } else {
                                key = null;
                            }
                        } else {
                            key = null;
                        }
                        if (key != null) {
                            String value = this.errorsValues.get(key);
                            if (!TextUtils.isEmpty(value) && value.equals(fields[a3].getText().toString())) {
                                error = true;
                            }
                        }
                    }
                    if (!this.documentOnly || this.currentDocumentsType == null || a3 >= 7) {
                        if (!error) {
                            int len = fields[a3].length();
                            boolean allowZeroLength = false;
                            int i2 = this.currentActivityType;
                            if (i2 == 1) {
                                if (a3 != 8) {
                                    if ((i == 0 && (a3 == 0 || a3 == 2 || a3 == 1)) || (i == 1 && (a3 == 0 || a3 == 1 || a3 == 2))) {
                                        if (len > 255) {
                                            error = true;
                                        }
                                        if ((i == 0 && a3 == 1) || (i == 1 && a3 == 1)) {
                                            allowZeroLength = true;
                                        }
                                    } else if (a3 == 7 && len > 24) {
                                        error = true;
                                    }
                                    if (!error && !allowZeroLength && len == 0) {
                                        error = true;
                                    }
                                } else {
                                    continue;
                                }
                            } else {
                                if (i2 == 2) {
                                    if (a3 == 1) {
                                        continue;
                                    } else if (a3 == 3) {
                                        if (len < 2) {
                                            error = true;
                                        }
                                    } else if (a3 == 4) {
                                        if (!"US".equals(this.currentCitizeship)) {
                                            continue;
                                        } else if (len < 2) {
                                            error = true;
                                        }
                                    } else if (a3 == 2 && (len < 2 || len > 10)) {
                                        error = true;
                                    }
                                }
                                if (!error) {
                                    error = true;
                                }
                            }
                        }
                        if (error) {
                            onFieldError(fields[a3]);
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }

    private void createIdentityInterface(final Context context) {
        final String key;
        HashMap<String, String> values;
        final String key2;
        final HashMap<String, String> values2;
        String errorText;
        this.languageMap = new HashMap<>();
        try {
            BufferedReader reader = new BufferedReader(new InputStreamReader(context.getResources().getAssets().open("countries.txt")));
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                String[] args = line.split(";");
                this.languageMap.put(args[1], args[2]);
            }
            reader.close();
        } catch (Exception e) {
            FileLog.e(e);
        }
        TextInfoPrivacyCell textInfoPrivacyCell = new TextInfoPrivacyCell(context);
        this.topErrorCell = textInfoPrivacyCell;
        textInfoPrivacyCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_top, Theme.key_windowBackgroundGrayShadow));
        boolean z = false;
        this.topErrorCell.setPadding(0, AndroidUtilities.dp(7.0f), 0, 0);
        int i = -1;
        this.linearLayout2.addView(this.topErrorCell, LayoutHelper.createLinear(-1, -2));
        checkTopErrorCell(true);
        if (this.currentDocumentsType != null) {
            HeaderCell headerCell = new HeaderCell(context);
            this.headerCell = headerCell;
            if (this.documentOnly) {
                headerCell.setText(LocaleController.getString("PassportDocuments", R.string.PassportDocuments));
            } else {
                headerCell.setText(LocaleController.getString("PassportRequiredDocuments", R.string.PassportRequiredDocuments));
            }
            this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
            this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
            LinearLayout linearLayout = new LinearLayout(context);
            this.frontLayout = linearLayout;
            linearLayout.setOrientation(1);
            this.linearLayout2.addView(this.frontLayout, LayoutHelper.createLinear(-1, -2));
            TextDetailSettingsCell textDetailSettingsCell = new TextDetailSettingsCell(context);
            this.uploadFrontCell = textDetailSettingsCell;
            textDetailSettingsCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            this.linearLayout2.addView(this.uploadFrontCell, LayoutHelper.createLinear(-1, -2));
            this.uploadFrontCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.this.lambda$createIdentityInterface$40$PassportActivity(view);
                }
            });
            LinearLayout linearLayout2 = new LinearLayout(context);
            this.reverseLayout = linearLayout2;
            linearLayout2.setOrientation(1);
            this.linearLayout2.addView(this.reverseLayout, LayoutHelper.createLinear(-1, -2));
            boolean divider = this.currentDocumentsType.selfie_required;
            TextDetailSettingsCell textDetailSettingsCell2 = new TextDetailSettingsCell(context);
            this.uploadReverseCell = textDetailSettingsCell2;
            textDetailSettingsCell2.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            this.uploadReverseCell.setTextAndValue(LocaleController.getString("PassportReverseSide", R.string.PassportReverseSide), LocaleController.getString("PassportReverseSideInfo", R.string.PassportReverseSideInfo), divider);
            this.linearLayout2.addView(this.uploadReverseCell, LayoutHelper.createLinear(-1, -2));
            this.uploadReverseCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.this.lambda$createIdentityInterface$41$PassportActivity(view);
                }
            });
            if (this.currentDocumentsType.selfie_required) {
                LinearLayout linearLayout3 = new LinearLayout(context);
                this.selfieLayout = linearLayout3;
                linearLayout3.setOrientation(1);
                this.linearLayout2.addView(this.selfieLayout, LayoutHelper.createLinear(-1, -2));
                TextDetailSettingsCell textDetailSettingsCell3 = new TextDetailSettingsCell(context);
                this.uploadSelfieCell = textDetailSettingsCell3;
                textDetailSettingsCell3.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                this.uploadSelfieCell.setTextAndValue(LocaleController.getString("PassportSelfie", R.string.PassportSelfie), LocaleController.getString("PassportSelfieInfo", R.string.PassportSelfieInfo), this.currentType.translation_required);
                this.linearLayout2.addView(this.uploadSelfieCell, LayoutHelper.createLinear(-1, -2));
                this.uploadSelfieCell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        PassportActivity.this.lambda$createIdentityInterface$42$PassportActivity(view);
                    }
                });
            }
            TextInfoPrivacyCell textInfoPrivacyCell2 = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell2;
            textInfoPrivacyCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            this.bottomCell.setText(LocaleController.getString("PassportPersonalUploadInfo", R.string.PassportPersonalUploadInfo));
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
            if (this.currentDocumentsType.translation_required) {
                HeaderCell headerCell2 = new HeaderCell(context);
                this.headerCell = headerCell2;
                headerCell2.setText(LocaleController.getString("PassportTranslation", R.string.PassportTranslation));
                this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
                LinearLayout linearLayout4 = new LinearLayout(context);
                this.translationLayout = linearLayout4;
                linearLayout4.setOrientation(1);
                this.linearLayout2.addView(this.translationLayout, LayoutHelper.createLinear(-1, -2));
                TextSettingsCell textSettingsCell = new TextSettingsCell(context);
                this.uploadTranslationCell = textSettingsCell;
                textSettingsCell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                this.linearLayout2.addView(this.uploadTranslationCell, LayoutHelper.createLinear(-1, -2));
                this.uploadTranslationCell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        PassportActivity.this.lambda$createIdentityInterface$43$PassportActivity(view);
                    }
                });
                TextInfoPrivacyCell textInfoPrivacyCell3 = new TextInfoPrivacyCell(context);
                this.bottomCellTranslation = textInfoPrivacyCell3;
                textInfoPrivacyCell3.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                if (this.currentBotId != 0) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddTranslationUploadInfo", R.string.PassportAddTranslationUploadInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassport) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddPassportInfo", R.string.PassportAddPassportInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddInternalPassportInfo", R.string.PassportAddInternalPassportInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddIdentityCardInfo", R.string.PassportAddIdentityCardInfo);
                } else if (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                    this.noAllTranslationErrorText = LocaleController.getString("PassportAddDriverLicenceInfo", R.string.PassportAddDriverLicenceInfo);
                } else {
                    this.noAllTranslationErrorText = "";
                }
                CharSequence text = this.noAllTranslationErrorText;
                HashMap<String, String> hashMap = this.documentsErrors;
                if (hashMap != null && (errorText = hashMap.get("translation_all")) != null) {
                    SpannableStringBuilder stringBuilder = new SpannableStringBuilder(errorText);
                    stringBuilder.append((CharSequence) "\n\n");
                    stringBuilder.append(this.noAllTranslationErrorText);
                    text = stringBuilder;
                    stringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, errorText.length(), 33);
                    this.errorsValues.put("translation_all", "");
                }
                this.bottomCellTranslation.setText(text);
                this.linearLayout2.addView(this.bottomCellTranslation, LayoutHelper.createLinear(-1, -2));
            }
        } else if (Build.VERSION.SDK_INT >= 18) {
            TextSettingsCell textSettingsCell2 = new TextSettingsCell(context);
            this.scanDocumentCell = textSettingsCell2;
            textSettingsCell2.setBackgroundDrawable(Theme.getSelectorDrawable(true));
            this.scanDocumentCell.setText(LocaleController.getString("PassportScanPassport", R.string.PassportScanPassport), false);
            this.linearLayout2.addView(this.scanDocumentCell, LayoutHelper.createLinear(-1, -2));
            this.scanDocumentCell.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.this.lambda$createIdentityInterface$45$PassportActivity(view);
                }
            });
            TextInfoPrivacyCell textInfoPrivacyCell4 = new TextInfoPrivacyCell(context);
            this.bottomCell = textInfoPrivacyCell4;
            textInfoPrivacyCell4.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
            this.bottomCell.setText(LocaleController.getString("PassportScanPassportInfo", R.string.PassportScanPassportInfo));
            this.linearLayout2.addView(this.bottomCell, LayoutHelper.createLinear(-1, -2));
        }
        HeaderCell headerCell3 = new HeaderCell(context);
        this.headerCell = headerCell3;
        if (this.documentOnly) {
            headerCell3.setText(LocaleController.getString("PassportDocument", R.string.PassportDocument));
        } else {
            headerCell3.setText(LocaleController.getString("PassportPersonal", R.string.PassportPersonal));
        }
        this.headerCell.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
        this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
        int count = this.currentDocumentsType != null ? 9 : 7;
        this.inputFields = new EditTextBoldCursor[count];
        int a = 0;
        while (true) {
            int i2 = 64;
            if (a < count) {
                final EditTextBoldCursor field = new EditTextBoldCursor(context);
                this.inputFields[a] = field;
                ViewGroup container = new FrameLayout(context) {
                    private StaticLayout errorLayout;
                    private float offsetX;

                    @Override
                    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                        int width = View.MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34.0f);
                        StaticLayout errorLayout = field.getErrorLayout(width);
                        this.errorLayout = errorLayout;
                        if (errorLayout != null) {
                            int lineCount = errorLayout.getLineCount();
                            if (lineCount > 1) {
                                int height = AndroidUtilities.dp(64.0f) + (this.errorLayout.getLineBottom(lineCount - 1) - this.errorLayout.getLineBottom(0));
                                heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, 1073741824);
                            }
                            if (LocaleController.isRTL) {
                                float maxW = 0.0f;
                                int a2 = 0;
                                while (true) {
                                    if (a2 >= lineCount) {
                                        break;
                                    }
                                    float l = this.errorLayout.getLineLeft(a2);
                                    if (l != 0.0f) {
                                        this.offsetX = 0.0f;
                                        break;
                                    }
                                    maxW = Math.max(maxW, this.errorLayout.getLineWidth(a2));
                                    if (a2 == lineCount - 1) {
                                        this.offsetX = width - maxW;
                                    }
                                    a2++;
                                }
                            }
                        }
                        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                    }

                    @Override
                    protected void onDraw(Canvas canvas) {
                        if (this.errorLayout != null) {
                            canvas.save();
                            canvas.translate(AndroidUtilities.dp(21.0f) + this.offsetX, field.getLineY() + AndroidUtilities.dp(3.0f));
                            this.errorLayout.draw(canvas);
                            canvas.restore();
                        }
                    }
                };
                container.setWillNotDraw(z);
                this.linearLayout2.addView(container, LayoutHelper.createLinear(i, 64));
                container.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                if (a == count - 1) {
                    View view = new View(context);
                    this.extraBackgroundView = view;
                    view.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    this.linearLayout2.addView(this.extraBackgroundView, LayoutHelper.createLinear(i, 6));
                }
                if (this.documentOnly && this.currentDocumentsType != null) {
                    if (a < 7) {
                        container.setVisibility(8);
                        View view2 = this.extraBackgroundView;
                        if (view2 != null) {
                            view2.setVisibility(8);
                        }
                    }
                }
                this.inputFields[a].setTag(Integer.valueOf(a));
                this.inputFields[a].setSupportRtlHint(true);
                this.inputFields[a].setTextSize(1, 16.0f);
                this.inputFields[a].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                this.inputFields[a].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                this.inputFields[a].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
                this.inputFields[a].setTransformHintToHeader(true);
                this.inputFields[a].setBackgroundDrawable(null);
                this.inputFields[a].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                this.inputFields[a].setCursorSize(AndroidUtilities.dp(20.0f));
                this.inputFields[a].setCursorWidth(1.5f);
                this.inputFields[a].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
                if (a == 5 || a == 6) {
                    this.inputFields[a].setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public final boolean onTouch(View view3, MotionEvent motionEvent) {
                            return PassportActivity.this.lambda$createIdentityInterface$47$PassportActivity(view3, motionEvent);
                        }
                    });
                    this.inputFields[a].setInputType(0);
                } else if (a == 3 || a == 8) {
                    this.inputFields[a].setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public final boolean onTouch(View view3, MotionEvent motionEvent) {
                            return PassportActivity.this.lambda$createIdentityInterface$50$PassportActivity(context, view3, motionEvent);
                        }
                    });
                    this.inputFields[a].setInputType(0);
                    this.inputFields[a].setFocusable(false);
                } else if (a == 4) {
                    this.inputFields[a].setOnTouchListener(new View.OnTouchListener() {
                        @Override
                        public final boolean onTouch(View view3, MotionEvent motionEvent) {
                            return PassportActivity.this.lambda$createIdentityInterface$52$PassportActivity(view3, motionEvent);
                        }
                    });
                    this.inputFields[a].setInputType(0);
                    this.inputFields[a].setFocusable(false);
                } else {
                    this.inputFields[a].setInputType(16385);
                    this.inputFields[a].setImeOptions(268435461);
                }
                switch (a) {
                    case 0:
                        if (this.currentType.native_names) {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportNameLatin", R.string.PassportNameLatin));
                        } else {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportName", R.string.PassportName));
                        }
                        key2 = "first_name";
                        values2 = this.currentValues;
                        break;
                    case 1:
                        if (this.currentType.native_names) {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportMidnameLatin", R.string.PassportMidnameLatin));
                        } else {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportMidname", R.string.PassportMidname));
                        }
                        key2 = "middle_name";
                        values2 = this.currentValues;
                        break;
                    case 2:
                        if (this.currentType.native_names) {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportSurnameLatin", R.string.PassportSurnameLatin));
                        } else {
                            this.inputFields[a].setHintText(LocaleController.getString("PassportSurname", R.string.PassportSurname));
                        }
                        key2 = "last_name";
                        values2 = this.currentValues;
                        break;
                    case 3:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportBirthdate", R.string.PassportBirthdate));
                        key2 = "birth_date";
                        values2 = this.currentValues;
                        break;
                    case 4:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportGender", R.string.PassportGender));
                        key2 = "gender";
                        values2 = this.currentValues;
                        break;
                    case 5:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportCitizenship", R.string.PassportCitizenship));
                        key2 = "country_code";
                        values2 = this.currentValues;
                        break;
                    case 6:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportResidence", R.string.PassportResidence));
                        key2 = "residence_country_code";
                        values2 = this.currentValues;
                        break;
                    case 7:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportDocumentNumber", R.string.PassportDocumentNumber));
                        key2 = "document_no";
                        values2 = this.currentDocumentValues;
                        break;
                    case 8:
                        this.inputFields[a].setHintText(LocaleController.getString("PassportExpired", R.string.PassportExpired));
                        key2 = "expiry_date";
                        values2 = this.currentDocumentValues;
                        break;
                }
                setFieldValues(values2, this.inputFields[a], key2);
                EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
                editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
                if (a == 0 || a == 2 || a == 1) {
                    this.inputFields[a].addTextChangedListener(new TextWatcher() {
                        private boolean ignore;

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

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

                        @Override
                        public void afterTextChanged(Editable s) {
                            if (this.ignore) {
                                return;
                            }
                            int num = ((Integer) field.getTag()).intValue();
                            boolean error = false;
                            int a2 = 0;
                            while (true) {
                                if (a2 >= s.length()) {
                                    break;
                                }
                                char ch = s.charAt(a2);
                                if ((ch >= '0' && ch <= '9') || ((ch >= 'a' && ch <= 'z') || ((ch >= 'A' && ch <= 'Z') || ch == ' ' || ch == '\'' || ch == ',' || ch == '.' || ch == '&' || ch == '-' || ch == '/'))) {
                                    a2++;
                                } else {
                                    error = true;
                                    break;
                                }
                            }
                            if (!error || PassportActivity.this.allowNonLatinName) {
                                PassportActivity.this.nonLatinNames[num] = error;
                                PassportActivity.this.checkFieldForError(field, key2, s, false);
                            } else {
                                field.setErrorText(LocaleController.getString("PassportUseLatinOnly", R.string.PassportUseLatinOnly));
                            }
                        }
                    });
                } else {
                    this.inputFields[a].addTextChangedListener(new TextWatcher() {
                        @Override
                        public void beforeTextChanged(CharSequence s, int start, int count2, int after) {
                        }

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

                        @Override
                        public void afterTextChanged(Editable s) {
                            PassportActivity passportActivity = PassportActivity.this;
                            passportActivity.checkFieldForError(field, key2, s, values2 == passportActivity.currentDocumentValues);
                            int field12 = ((Integer) field.getTag()).intValue();
                            EditTextBoldCursor editTextBoldCursor = PassportActivity.this.inputFields[field12];
                            if (field12 == 6) {
                                PassportActivity.this.checkNativeFields(true);
                            }
                        }
                    });
                }
                this.inputFields[a].setPadding(0, 0, 0, 0);
                this.inputFields[a].setGravity((LocaleController.isRTL ? 5 : 3) | 16);
                container.addView(this.inputFields[a], LayoutHelper.createFrame(-1.0f, -1.0f, 51, 21.0f, 0.0f, 21.0f, 0.0f));
                this.inputFields[a].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public final boolean onEditorAction(TextView textView, int i3, KeyEvent keyEvent) {
                        return PassportActivity.this.lambda$createIdentityInterface$53$PassportActivity(textView, i3, keyEvent);
                    }
                });
                a++;
                z = false;
                i = -1;
            } else {
                ShadowSectionCell shadowSectionCell = new ShadowSectionCell(context);
                this.sectionCell2 = shadowSectionCell;
                this.linearLayout2.addView(shadowSectionCell, LayoutHelper.createLinear(-1, -2));
                HeaderCell headerCell4 = new HeaderCell(context);
                this.headerCell = headerCell4;
                headerCell4.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                this.linearLayout2.addView(this.headerCell, LayoutHelper.createLinear(-1, -2));
                int i3 = 3;
                this.inputExtraFields = new EditTextBoldCursor[3];
                int a2 = 0;
                while (a2 < i3) {
                    final EditTextBoldCursor field2 = new EditTextBoldCursor(context);
                    this.inputExtraFields[a2] = field2;
                    ViewGroup container2 = new FrameLayout(context) {
                        private StaticLayout errorLayout;
                        private float offsetX;

                        @Override
                        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                            int width = View.MeasureSpec.getSize(widthMeasureSpec) - AndroidUtilities.dp(34.0f);
                            StaticLayout errorLayout = field2.getErrorLayout(width);
                            this.errorLayout = errorLayout;
                            if (errorLayout != null) {
                                int lineCount = errorLayout.getLineCount();
                                if (lineCount > 1) {
                                    int height = AndroidUtilities.dp(64.0f) + (this.errorLayout.getLineBottom(lineCount - 1) - this.errorLayout.getLineBottom(0));
                                    heightMeasureSpec = View.MeasureSpec.makeMeasureSpec(height, 1073741824);
                                }
                                if (LocaleController.isRTL) {
                                    float maxW = 0.0f;
                                    int a3 = 0;
                                    while (true) {
                                        if (a3 >= lineCount) {
                                            break;
                                        }
                                        float l = this.errorLayout.getLineLeft(a3);
                                        if (l != 0.0f) {
                                            this.offsetX = 0.0f;
                                            break;
                                        }
                                        maxW = Math.max(maxW, this.errorLayout.getLineWidth(a3));
                                        if (a3 == lineCount - 1) {
                                            this.offsetX = width - maxW;
                                        }
                                        a3++;
                                    }
                                }
                            }
                            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
                        }

                        @Override
                        protected void onDraw(Canvas canvas) {
                            if (this.errorLayout != null) {
                                canvas.save();
                                canvas.translate(AndroidUtilities.dp(21.0f) + this.offsetX, field2.getLineY() + AndroidUtilities.dp(3.0f));
                                this.errorLayout.draw(canvas);
                                canvas.restore();
                            }
                        }
                    };
                    container2.setWillNotDraw(false);
                    this.linearLayout2.addView(container2, LayoutHelper.createLinear(-1, i2));
                    container2.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                    if (a2 == 2) {
                        View view3 = new View(context);
                        this.extraBackgroundView2 = view3;
                        view3.setBackgroundColor(Theme.getColor(Theme.key_windowBackgroundWhite));
                        this.linearLayout2.addView(this.extraBackgroundView2, LayoutHelper.createLinear(-1, 6));
                    }
                    this.inputExtraFields[a2].setTag(Integer.valueOf(a2));
                    this.inputExtraFields[a2].setSupportRtlHint(true);
                    this.inputExtraFields[a2].setTextSize(1, 16.0f);
                    this.inputExtraFields[a2].setHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteHintText));
                    this.inputExtraFields[a2].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                    this.inputExtraFields[a2].setHeaderHintColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueHeader));
                    this.inputExtraFields[a2].setTransformHintToHeader(true);
                    this.inputExtraFields[a2].setBackgroundDrawable(null);
                    this.inputExtraFields[a2].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                    this.inputExtraFields[a2].setCursorSize(AndroidUtilities.dp(20.0f));
                    this.inputExtraFields[a2].setCursorWidth(1.5f);
                    this.inputExtraFields[a2].setLineColors(Theme.getColor(Theme.key_windowBackgroundWhiteInputField), Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
                    this.inputExtraFields[a2].setInputType(16385);
                    this.inputExtraFields[a2].setImeOptions(268435461);
                    if (a2 == 0) {
                        key = "first_name_native";
                        values = this.currentValues;
                    } else if (a2 == 1) {
                        key = "middle_name_native";
                        values = this.currentValues;
                    } else if (a2 != 2) {
                        a2++;
                        i3 = 3;
                        i2 = 64;
                    } else {
                        key = "last_name_native";
                        values = this.currentValues;
                    }
                    setFieldValues(values, this.inputExtraFields[a2], key);
                    EditTextBoldCursor[] editTextBoldCursorArr2 = this.inputExtraFields;
                    editTextBoldCursorArr2[a2].setSelection(editTextBoldCursorArr2[a2].length());
                    if (a2 == 0 || a2 == 2 || a2 == 1) {
                        this.inputExtraFields[a2].addTextChangedListener(new TextWatcher() {
                            private boolean ignore;

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

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

                            @Override
                            public void afterTextChanged(Editable s) {
                                if (!this.ignore) {
                                    PassportActivity.this.checkFieldForError(field2, key, s, false);
                                }
                            }
                        });
                    }
                    this.inputExtraFields[a2].setPadding(0, 0, 0, 0);
                    this.inputExtraFields[a2].setGravity((LocaleController.isRTL ? 5 : 3) | 16);
                    container2.addView(this.inputExtraFields[a2], LayoutHelper.createFrame(-1.0f, -1.0f, 51, 21.0f, 0.0f, 21.0f, 0.0f));
                    this.inputExtraFields[a2].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                        @Override
                        public final boolean onEditorAction(TextView textView, int i4, KeyEvent keyEvent) {
                            return PassportActivity.this.lambda$createIdentityInterface$54$PassportActivity(textView, i4, keyEvent);
                        }
                    });
                    a2++;
                    i3 = 3;
                    i2 = 64;
                }
                TextInfoPrivacyCell textInfoPrivacyCell5 = new TextInfoPrivacyCell(context);
                this.nativeInfoCell = textInfoPrivacyCell5;
                this.linearLayout2.addView(textInfoPrivacyCell5, LayoutHelper.createLinear(-1, -2));
                if (((this.currentBotId != 0 || this.currentDocumentsType == null) && this.currentTypeValue != null && !this.documentOnly) || this.currentDocumentsTypeValue != null) {
                    TLRPC.TL_secureValue tL_secureValue = this.currentDocumentsTypeValue;
                    if (tL_secureValue != null) {
                        addDocumentViews(tL_secureValue.files);
                        if (this.currentDocumentsTypeValue.front_side instanceof TLRPC.TL_secureFile) {
                            addDocumentViewInternal((TLRPC.TL_secureFile) this.currentDocumentsTypeValue.front_side, 2);
                        }
                        if (this.currentDocumentsTypeValue.reverse_side instanceof TLRPC.TL_secureFile) {
                            addDocumentViewInternal((TLRPC.TL_secureFile) this.currentDocumentsTypeValue.reverse_side, 3);
                        }
                        if (this.currentDocumentsTypeValue.selfie instanceof TLRPC.TL_secureFile) {
                            addDocumentViewInternal((TLRPC.TL_secureFile) this.currentDocumentsTypeValue.selfie, 1);
                        }
                        addTranslationDocumentViews(this.currentDocumentsTypeValue.translation);
                    }
                    TextSettingsCell settingsCell1 = new TextSettingsCell(context);
                    settingsCell1.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
                    settingsCell1.setBackgroundDrawable(Theme.getSelectorDrawable(true));
                    if (this.currentDocumentsType == null) {
                        settingsCell1.setText(LocaleController.getString("PassportDeleteInfo", R.string.PassportDeleteInfo), false);
                    } else {
                        settingsCell1.setText(LocaleController.getString("PassportDeleteDocument", R.string.PassportDeleteDocument), false);
                    }
                    this.linearLayout2.addView(settingsCell1, LayoutHelper.createLinear(-1, -2));
                    settingsCell1.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public final void onClick(View view4) {
                            PassportActivity.this.lambda$createIdentityInterface$55$PassportActivity(view4);
                        }
                    });
                    this.nativeInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                    ShadowSectionCell shadowSectionCell2 = new ShadowSectionCell(context);
                    this.sectionCell = shadowSectionCell2;
                    shadowSectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                    this.linearLayout2.addView(this.sectionCell, LayoutHelper.createLinear(-1, -2));
                } else {
                    this.nativeInfoCell.setBackgroundDrawable(Theme.getThemedDrawable(context, R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                }
                updateInterfaceStringsForDocumentType();
                checkNativeFields(false);
                return;
            }
        }
    }

    public void lambda$createIdentityInterface$40$PassportActivity(View v) {
        this.uploadingFileType = 2;
        openAttachMenu();
    }

    public void lambda$createIdentityInterface$41$PassportActivity(View v) {
        this.uploadingFileType = 3;
        openAttachMenu();
    }

    public void lambda$createIdentityInterface$42$PassportActivity(View v) {
        this.uploadingFileType = 1;
        openAttachMenu();
    }

    public void lambda$createIdentityInterface$43$PassportActivity(View v) {
        this.uploadingFileType = 4;
        openAttachMenu();
    }

    public void lambda$createIdentityInterface$45$PassportActivity(View v) {
        if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission("android.permission.CAMERA") != 0) {
            getParentActivity().requestPermissions(new String[]{"android.permission.CAMERA"}, 22);
            return;
        }
        MrzCameraActivity fragment = new MrzCameraActivity();
        fragment.setDelegate(new MrzCameraActivity.MrzCameraActivityDelegate() {
            @Override
            public final void didFindMrzInfo(MrzRecognizer.Result result) {
                PassportActivity.this.lambda$null$44$PassportActivity(result);
            }
        });
        presentFragment(fragment);
    }

    public void lambda$null$44$PassportActivity(MrzRecognizer.Result result) {
        if (!TextUtils.isEmpty(result.firstName)) {
            this.inputFields[0].setText(result.firstName);
        }
        if (!TextUtils.isEmpty(result.middleName)) {
            this.inputFields[1].setText(result.middleName);
        }
        if (!TextUtils.isEmpty(result.lastName)) {
            this.inputFields[2].setText(result.lastName);
        }
        if (result.gender != 0) {
            int i = result.gender;
            if (i == 1) {
                this.currentGender = "male";
                this.inputFields[4].setText(LocaleController.getString("PassportMale", R.string.PassportMale));
            } else if (i == 2) {
                this.currentGender = "female";
                this.inputFields[4].setText(LocaleController.getString("PassportFemale", R.string.PassportFemale));
            }
        }
        if (!TextUtils.isEmpty(result.nationality)) {
            String str = result.nationality;
            this.currentCitizeship = str;
            String country = this.languageMap.get(str);
            if (country != null) {
                this.inputFields[5].setText(country);
            }
        }
        if (!TextUtils.isEmpty(result.issuingCountry)) {
            String str2 = result.issuingCountry;
            this.currentResidence = str2;
            String country2 = this.languageMap.get(str2);
            if (country2 != null) {
                this.inputFields[6].setText(country2);
            }
        }
        if (result.birthDay > 0 && result.birthMonth > 0 && result.birthYear > 0) {
            this.inputFields[3].setText(String.format(Locale.US, "%02d.%02d.%d", Integer.valueOf(result.birthDay), Integer.valueOf(result.birthMonth), Integer.valueOf(result.birthYear)));
        }
    }

    public boolean lambda$createIdentityInterface$47$PassportActivity(final View v, MotionEvent event) {
        if (getParentActivity() == null) {
            return false;
        }
        if (event.getAction() == 1) {
            CountrySelectActivity fragment = new CountrySelectActivity(false);
            fragment.setCountrySelectActivityDelegate(new CountrySelectActivity.CountrySelectActivityDelegate() {
                @Override
                public final void didSelectCountry(CountrySelectActivity.Country country) {
                    PassportActivity.this.lambda$null$46$PassportActivity(v, country);
                }
            });
            presentFragment(fragment);
        }
        return true;
    }

    public void lambda$null$46$PassportActivity(View v, CountrySelectActivity.Country country) {
        if (country != null) {
            int field12 = ((Integer) v.getTag()).intValue();
            EditTextBoldCursor editText = this.inputFields[field12];
            if (field12 == 5) {
                this.currentCitizeship = country.shortname;
            } else {
                this.currentResidence = country.shortname;
            }
            editText.setText(country.name + "");
        }
    }

    public boolean lambda$createIdentityInterface$50$PassportActivity(Context context, View v, MotionEvent event) {
        String title;
        int minYear;
        int maxYear;
        int currentYearDiff;
        int selectedDay;
        int selectedMonth;
        int selectedYear;
        if (getParentActivity() == null) {
            return false;
        }
        if (event.getAction() == 1) {
            Calendar calendar = Calendar.getInstance();
            calendar.get(1);
            calendar.get(2);
            calendar.get(5);
            try {
                final EditTextBoldCursor field1 = (EditTextBoldCursor) v;
                final int num = ((Integer) field1.getTag()).intValue();
                if (num == 8) {
                    title = LocaleController.getString("PassportSelectExpiredDate", R.string.PassportSelectExpiredDate);
                    minYear = 0;
                    maxYear = 20;
                    currentYearDiff = 0;
                } else {
                    title = LocaleController.getString("PassportSelectBithdayDate", R.string.PassportSelectBithdayDate);
                    minYear = -120;
                    maxYear = 0;
                    currentYearDiff = -18;
                }
                String[] args = field1.getText().toString().split("\\.");
                if (args.length != 3) {
                    selectedDay = -1;
                    selectedMonth = -1;
                    selectedYear = -1;
                } else {
                    int selectedDay2 = Utilities.parseInt(args[0]).intValue();
                    int selectedMonth2 = Utilities.parseInt(args[1]).intValue();
                    int selectedYear2 = Utilities.parseInt(args[2]).intValue();
                    selectedDay = selectedDay2;
                    selectedMonth = selectedMonth2;
                    selectedYear = selectedYear2;
                }
                AlertDialog.Builder builder = AlertsCreator.createDatePickerDialog(context, minYear, maxYear, currentYearDiff, selectedDay, selectedMonth, selectedYear, title, num == 8, new AlertsCreator.DatePickerDelegate() {
                    @Override
                    public final void didSelectDate(int i, int i2, int i3) {
                        PassportActivity.this.lambda$null$48$PassportActivity(num, field1, i, i2, i3);
                    }
                });
                if (num == 8) {
                    builder.setNegativeButton(LocaleController.getString("PassportSelectNotExpire", R.string.PassportSelectNotExpire), new DialogInterface.OnClickListener() {
                        @Override
                        public final void onClick(DialogInterface dialogInterface, int i) {
                            PassportActivity.this.lambda$null$49$PassportActivity(field1, dialogInterface, i);
                        }
                    });
                }
                showDialog(builder.create());
                return true;
            } catch (Exception e) {
                FileLog.e(e);
                return true;
            }
        }
        return true;
    }

    public void lambda$null$48$PassportActivity(int num, EditTextBoldCursor field1, int year1, int month, int dayOfMonth1) {
        if (num == 8) {
            int[] iArr = this.currentExpireDate;
            iArr[0] = year1;
            iArr[1] = month + 1;
            iArr[2] = dayOfMonth1;
        }
        field1.setText(String.format(Locale.US, "%02d.%02d.%d", Integer.valueOf(dayOfMonth1), Integer.valueOf(month + 1), Integer.valueOf(year1)));
    }

    public void lambda$null$49$PassportActivity(EditTextBoldCursor field1, DialogInterface dialog, int which) {
        int[] iArr = this.currentExpireDate;
        iArr[2] = 0;
        iArr[1] = 0;
        iArr[0] = 0;
        field1.setText(LocaleController.getString("PassportNoExpireDate", R.string.PassportNoExpireDate));
    }

    public boolean lambda$createIdentityInterface$52$PassportActivity(View v, MotionEvent event) {
        if (getParentActivity() == null) {
            return false;
        }
        if (event.getAction() == 1) {
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("PassportSelectGender", R.string.PassportSelectGender));
            builder.setItems(new CharSequence[]{LocaleController.getString("PassportMale", R.string.PassportMale), LocaleController.getString("PassportFemale", R.string.PassportFemale)}, new DialogInterface.OnClickListener() {
                @Override
                public final void onClick(DialogInterface dialogInterface, int i) {
                    PassportActivity.this.lambda$null$51$PassportActivity(dialogInterface, i);
                }
            });
            builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
        return true;
    }

    public void lambda$null$51$PassportActivity(DialogInterface dialogInterface, int i) {
        if (i == 0) {
            this.currentGender = "male";
            this.inputFields[4].setText(LocaleController.getString("PassportMale", R.string.PassportMale));
        } else if (i == 1) {
            this.currentGender = "female";
            this.inputFields[4].setText(LocaleController.getString("PassportFemale", R.string.PassportFemale));
        }
    }

    public boolean lambda$createIdentityInterface$53$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 5) {
            int num = ((Integer) textView.getTag()).intValue() + 1;
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            if (num < editTextBoldCursorArr.length) {
                if (editTextBoldCursorArr[num].isFocusable()) {
                    this.inputFields[num].requestFocus();
                } else {
                    this.inputFields[num].dispatchTouchEvent(MotionEvent.obtain(0L, 0L, 1, 0.0f, 0.0f, 0));
                    textView.clearFocus();
                    AndroidUtilities.hideKeyboard(textView);
                }
            }
            return true;
        }
        return false;
    }

    public boolean lambda$createIdentityInterface$54$PassportActivity(TextView textView, int i, KeyEvent keyEvent) {
        if (i == 5) {
            int num = ((Integer) textView.getTag()).intValue() + 1;
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputExtraFields;
            if (num < editTextBoldCursorArr.length) {
                if (editTextBoldCursorArr[num].isFocusable()) {
                    this.inputExtraFields[num].requestFocus();
                } else {
                    this.inputExtraFields[num].dispatchTouchEvent(MotionEvent.obtain(0L, 0L, 1, 0.0f, 0.0f, 0));
                    textView.clearFocus();
                    AndroidUtilities.hideKeyboard(textView);
                }
            }
            return true;
        }
        return false;
    }

    public void lambda$createIdentityInterface$55$PassportActivity(View v) {
        createDocumentDeleteAlert();
    }

    private void updateInterfaceStringsForDocumentType() {
        if (this.currentDocumentsType != null) {
            this.actionBar.setTitle(getTextForType(this.currentDocumentsType.type));
        } else {
            this.actionBar.setTitle(LocaleController.getString("PassportPersonal", R.string.PassportPersonal));
        }
        updateUploadText(2);
        updateUploadText(3);
        updateUploadText(1);
        updateUploadText(4);
    }

    public void updateUploadText(int type) {
        boolean z = true;
        if (type == 0) {
            if (this.uploadDocumentCell == null) {
                return;
            }
            if (this.documents.size() >= 1) {
                this.uploadDocumentCell.setText(LocaleController.getString("PassportUploadAdditinalDocument", R.string.PassportUploadAdditinalDocument), false);
                return;
            } else {
                this.uploadDocumentCell.setText(LocaleController.getString("PassportUploadDocument", R.string.PassportUploadDocument), false);
                return;
            }
        }
        if (type == 1) {
            TextDetailSettingsCell textDetailSettingsCell = this.uploadSelfieCell;
            if (textDetailSettingsCell == null) {
                return;
            }
            textDetailSettingsCell.setVisibility(this.selfieDocument != null ? 8 : 0);
            return;
        }
        if (type == 4) {
            if (this.uploadTranslationCell == null) {
                return;
            }
            if (this.translationDocuments.size() >= 1) {
                this.uploadTranslationCell.setText(LocaleController.getString("PassportUploadAdditinalDocument", R.string.PassportUploadAdditinalDocument), false);
                return;
            } else {
                this.uploadTranslationCell.setText(LocaleController.getString("PassportUploadDocument", R.string.PassportUploadDocument), false);
                return;
            }
        }
        if (type == 2) {
            if (this.uploadFrontCell == null) {
                return;
            }
            TLRPC.TL_secureRequiredType tL_secureRequiredType = this.currentDocumentsType;
            if (tL_secureRequiredType == null || (!tL_secureRequiredType.selfie_required && !(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) && !(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense))) {
                z = false;
            }
            boolean divider = z;
            if ((this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassport) || (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport)) {
                this.uploadFrontCell.setTextAndValue(LocaleController.getString("PassportMainPage", R.string.PassportMainPage), LocaleController.getString("PassportMainPageInfo", R.string.PassportMainPageInfo), divider);
            } else {
                this.uploadFrontCell.setTextAndValue(LocaleController.getString("PassportFrontSide", R.string.PassportFrontSide), LocaleController.getString("PassportFrontSideInfo", R.string.PassportFrontSideInfo), divider);
            }
            this.uploadFrontCell.setVisibility(this.frontDocument != null ? 8 : 0);
            return;
        }
        if (type != 3 || this.uploadReverseCell == null) {
            return;
        }
        if (!(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) && !(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense)) {
            this.reverseLayout.setVisibility(8);
            this.uploadReverseCell.setVisibility(8);
        } else {
            this.reverseLayout.setVisibility(0);
            this.uploadReverseCell.setVisibility(this.reverseDocument != null ? 8 : 0);
        }
    }

    private void checkTopErrorCell(boolean init) {
        String errorText;
        String errorText2;
        if (this.topErrorCell == null) {
            return;
        }
        SpannableStringBuilder stringBuilder = null;
        if (this.fieldsErrors != null && ((init || this.errorsValues.containsKey("error_all")) && (errorText2 = this.fieldsErrors.get("error_all")) != null)) {
            stringBuilder = new SpannableStringBuilder(errorText2);
            if (init) {
                this.errorsValues.put("error_all", "");
            }
        }
        if (this.documentsErrors != null && ((init || this.errorsValues.containsKey("error_document_all")) && (errorText = this.documentsErrors.get("error_all")) != null)) {
            if (stringBuilder == null) {
                stringBuilder = new SpannableStringBuilder(errorText);
            } else {
                stringBuilder.append((CharSequence) "\n\n").append((CharSequence) errorText);
            }
            if (init) {
                this.errorsValues.put("error_document_all", "");
            }
        }
        if (stringBuilder != null) {
            stringBuilder.setSpan(new ForegroundColorSpan(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3)), 0, stringBuilder.length(), 33);
            this.topErrorCell.setText(stringBuilder);
            this.topErrorCell.setVisibility(0);
        } else if (this.topErrorCell.getVisibility() != 8) {
            this.topErrorCell.setVisibility(8);
        }
    }

    private void addDocumentViewInternal(TLRPC.TL_secureFile f, int uploadingType) {
        SecureDocumentKey secureDocumentKey = getSecureDocumentKey(f.secret, f.file_hash);
        SecureDocument secureDocument = new SecureDocument(secureDocumentKey, f, null, null, null);
        addDocumentView(secureDocument, uploadingType);
    }

    private void addDocumentViews(ArrayList<TLRPC.SecureFile> files) {
        this.documents.clear();
        int size = files.size();
        for (int a = 0; a < size; a++) {
            TLRPC.SecureFile secureFile = files.get(a);
            if (secureFile instanceof TLRPC.TL_secureFile) {
                addDocumentViewInternal((TLRPC.TL_secureFile) secureFile, 0);
            }
        }
    }

    private void addTranslationDocumentViews(ArrayList<TLRPC.SecureFile> files) {
        this.translationDocuments.clear();
        int size = files.size();
        for (int a = 0; a < size; a++) {
            TLRPC.SecureFile secureFile = files.get(a);
            if (secureFile instanceof TLRPC.TL_secureFile) {
                addDocumentViewInternal((TLRPC.TL_secureFile) secureFile, 4);
            }
        }
    }

    private void setFieldValues(HashMap<String, String> values, EditTextBoldCursor editText, String key) {
        String value;
        String value2;
        String value3 = values.get(key);
        if (value3 != null) {
            char c = 65535;
            switch (key.hashCode()) {
                case -2006252145:
                    if (key.equals("residence_country_code")) {
                        c = 1;
                        break;
                    }
                    break;
                case -1249512767:
                    if (key.equals("gender")) {
                        c = 2;
                        break;
                    }
                    break;
                case 475919162:
                    if (key.equals("expiry_date")) {
                        c = 3;
                        break;
                    }
                    break;
                case 1481071862:
                    if (key.equals("country_code")) {
                        c = 0;
                        break;
                    }
                    break;
            }
            if (c == 0) {
                this.currentCitizeship = value3;
                String country = this.languageMap.get(value3);
                if (country != null) {
                    editText.setText(country);
                }
            } else if (c == 1) {
                this.currentResidence = value3;
                String country2 = this.languageMap.get(value3);
                if (country2 != null) {
                    editText.setText(country2);
                }
            } else if (c != 2) {
                if (c == 3) {
                    boolean ok = false;
                    if (!TextUtils.isEmpty(value3)) {
                        String[] args = value3.split("\\.");
                        if (args.length == 3) {
                            this.currentExpireDate[0] = Utilities.parseInt(args[2]).intValue();
                            this.currentExpireDate[1] = Utilities.parseInt(args[1]).intValue();
                            this.currentExpireDate[2] = Utilities.parseInt(args[0]).intValue();
                            editText.setText(value3);
                            ok = true;
                        }
                    }
                    if (!ok) {
                        int[] iArr = this.currentExpireDate;
                        iArr[2] = 0;
                        iArr[1] = 0;
                        iArr[0] = 0;
                        editText.setText(LocaleController.getString("PassportNoExpireDate", R.string.PassportNoExpireDate));
                    }
                } else {
                    editText.setText(value3);
                }
            } else if ("male".equals(value3)) {
                this.currentGender = value3;
                editText.setText(LocaleController.getString("PassportMale", R.string.PassportMale));
            } else if ("female".equals(value3)) {
                this.currentGender = value3;
                editText.setText(LocaleController.getString("PassportFemale", R.string.PassportFemale));
            }
        }
        HashMap<String, String> hashMap = this.fieldsErrors;
        if (hashMap != null && (value2 = hashMap.get(key)) != null) {
            editText.setErrorText(value2);
            this.errorsValues.put(key, editText.getText().toString());
            return;
        }
        HashMap<String, String> hashMap2 = this.documentsErrors;
        if (hashMap2 != null && (value = hashMap2.get(key)) != null) {
            editText.setErrorText(value);
            this.errorsValues.put(key, editText.getText().toString());
        }
    }

    private void addDocumentView(final SecureDocument document, final int type) {
        String text;
        String key;
        String value;
        HashMap<String, String> hashMap;
        if (type == 1) {
            this.selfieDocument = document;
            if (this.selfieLayout == null) {
                return;
            }
        } else if (type == 4) {
            this.translationDocuments.add(document);
            if (this.translationLayout == null) {
                return;
            }
        } else if (type == 2) {
            this.frontDocument = document;
            if (this.frontLayout == null) {
                return;
            }
        } else if (type == 3) {
            this.reverseDocument = document;
            if (this.reverseLayout == null) {
                return;
            }
        } else {
            this.documents.add(document);
            if (this.documentsLayout == null) {
                return;
            }
        }
        if (getParentActivity() == null) {
            return;
        }
        final SecureDocumentCell cell = new SecureDocumentCell(getParentActivity());
        cell.setTag(document);
        cell.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        this.documentsCells.put(document, cell);
        String hash = getDocumentHash(document);
        if (type == 1) {
            text = LocaleController.getString("PassportSelfie", R.string.PassportSelfie);
            this.selfieLayout.addView(cell, LayoutHelper.createLinear(-1, -2));
            key = "selfie" + hash;
        } else if (type == 4) {
            text = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
            this.translationLayout.addView(cell, LayoutHelper.createLinear(-1, -2));
            key = "translation" + hash;
        } else if (type == 2) {
            if ((this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassport) || (this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport)) {
                text = LocaleController.getString("PassportMainPage", R.string.PassportMainPage);
            } else {
                text = LocaleController.getString("PassportFrontSide", R.string.PassportFrontSide);
            }
            this.frontLayout.addView(cell, LayoutHelper.createLinear(-1, -2));
            key = "front" + hash;
        } else if (type == 3) {
            text = LocaleController.getString("PassportReverseSide", R.string.PassportReverseSide);
            this.reverseLayout.addView(cell, LayoutHelper.createLinear(-1, -2));
            key = "reverse" + hash;
        } else {
            text = LocaleController.getString("AttachPhoto", R.string.AttachPhoto);
            this.documentsLayout.addView(cell, LayoutHelper.createLinear(-1, -2));
            key = "files" + hash;
        }
        if (key != null && (hashMap = this.documentsErrors) != null) {
            String str = hashMap.get(key);
            value = str;
            if (str != null) {
                cell.valueTextView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteRedText3));
                this.errorsValues.put(key, "");
                cell.setTextAndValueAndImage(text, value, document);
                cell.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public final void onClick(View view) {
                        PassportActivity.this.lambda$addDocumentView$56$PassportActivity(type, view);
                    }
                });
                final String str2 = key;
                cell.setOnLongClickListener(new View.OnLongClickListener() {
                    @Override
                    public final boolean onLongClick(View view) {
                        return PassportActivity.this.lambda$addDocumentView$58$PassportActivity(type, document, cell, str2, view);
                    }
                });
            }
        }
        value = LocaleController.formatDateForBan(document.secureFile.date);
        cell.setTextAndValueAndImage(text, value, document);
        cell.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view) {
                PassportActivity.this.lambda$addDocumentView$56$PassportActivity(type, view);
            }
        });
        final String str22 = key;
        cell.setOnLongClickListener(new View.OnLongClickListener() {
            @Override
            public final boolean onLongClick(View view) {
                return PassportActivity.this.lambda$addDocumentView$58$PassportActivity(type, document, cell, str22, view);
            }
        });
    }

    public void lambda$addDocumentView$56$PassportActivity(int type, View v) {
        this.uploadingFileType = type;
        if (type == 1) {
            this.currentPhotoViewerLayout = this.selfieLayout;
        } else if (type == 4) {
            this.currentPhotoViewerLayout = this.translationLayout;
        } else if (type == 2) {
            this.currentPhotoViewerLayout = this.frontLayout;
        } else if (type == 3) {
            this.currentPhotoViewerLayout = this.reverseLayout;
        } else {
            this.currentPhotoViewerLayout = this.documentsLayout;
        }
        SecureDocument document1 = (SecureDocument) v.getTag();
        PhotoViewer.getInstance().setParentActivity(getParentActivity());
        if (type == 0) {
            PhotoViewer photoViewer = PhotoViewer.getInstance();
            ArrayList<SecureDocument> arrayList = this.documents;
            photoViewer.openPhoto(arrayList, arrayList.indexOf(document1), this.provider);
        } else {
            PhotoViewer photoViewer2 = PhotoViewer.getInstance();
            ArrayList<SecureDocument> arrayList2 = this.translationDocuments;
            photoViewer2.openPhoto(arrayList2, arrayList2.indexOf(document1), this.provider);
        }
    }

    public boolean lambda$addDocumentView$58$PassportActivity(final int type, final SecureDocument document, final SecureDocumentCell cell, final String key, View v) {
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        if (type == 1) {
            builder.setMessage(LocaleController.getString("PassportDeleteSelfie", R.string.PassportDeleteSelfie));
        } else {
            builder.setMessage(LocaleController.getString("PassportDeleteScan", R.string.PassportDeleteScan));
        }
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$null$57$PassportActivity(document, type, cell, key, dialogInterface, i);
            }
        });
        showDialog(builder.create());
        return true;
    }

    public void lambda$null$57$PassportActivity(SecureDocument document, int type, SecureDocumentCell cell, String key, DialogInterface dialog, int which) {
        this.documentsCells.remove(document);
        if (type == 1) {
            this.selfieDocument = null;
            this.selfieLayout.removeView(cell);
        } else if (type == 4) {
            this.translationDocuments.remove(document);
            this.translationLayout.removeView(cell);
        } else if (type == 2) {
            this.frontDocument = null;
            this.frontLayout.removeView(cell);
        } else if (type == 3) {
            this.reverseDocument = null;
            this.reverseLayout.removeView(cell);
        } else {
            this.documents.remove(document);
            this.documentsLayout.removeView(cell);
        }
        if (key != null) {
            HashMap<String, String> hashMap = this.documentsErrors;
            if (hashMap != null) {
                hashMap.remove(key);
            }
            HashMap<String, String> hashMap2 = this.errorsValues;
            if (hashMap2 != null) {
                hashMap2.remove(key);
            }
        }
        updateUploadText(type);
        if (document.path != null && this.uploadingDocuments.remove(document.path) != null) {
            if (this.uploadingDocuments.isEmpty()) {
                this.doneItem.setEnabled(true);
                this.doneItem.setAlpha(1.0f);
            }
            FileLoader.getInstance(this.currentAccount).cancelUploadFile(document.path, false);
        }
    }

    private String getNameForType(TLRPC.SecureValueType type) {
        if (type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
            return "personal_details";
        }
        if (type instanceof TLRPC.TL_secureValueTypePassport) {
            return "passport";
        }
        if (type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
            return "internal_passport";
        }
        if (type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
            return "driver_license";
        }
        if (type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
            return "identity_card";
        }
        if (type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
            return "utility_bill";
        }
        if (type instanceof TLRPC.TL_secureValueTypeAddress) {
            return "address";
        }
        if (type instanceof TLRPC.TL_secureValueTypeBankStatement) {
            return "bank_statement";
        }
        if (type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
            return "rental_agreement";
        }
        if (type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
            return "temporary_registration";
        }
        if (type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
            return "passport_registration";
        }
        if (type instanceof TLRPC.TL_secureValueTypeEmail) {
            return "email";
        }
        if (type instanceof TLRPC.TL_secureValueTypePhone) {
            return "phone";
        }
        return "";
    }

    private TextDetailSecureCell getViewByType(TLRPC.TL_secureRequiredType requiredType) {
        TLRPC.TL_secureRequiredType requiredType2;
        TextDetailSecureCell view = this.typesViews.get(requiredType);
        if (view == null && (requiredType2 = this.documentsToTypesLink.get(requiredType)) != null) {
            return this.typesViews.get(requiredType2);
        }
        return view;
    }

    private String getTextForType(TLRPC.SecureValueType type) {
        if (type instanceof TLRPC.TL_secureValueTypePassport) {
            return LocaleController.getString("ActionBotDocumentPassport", R.string.ActionBotDocumentPassport);
        }
        if (type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
            return LocaleController.getString("ActionBotDocumentDriverLicence", R.string.ActionBotDocumentDriverLicence);
        }
        if (type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
            return LocaleController.getString("ActionBotDocumentIdentityCard", R.string.ActionBotDocumentIdentityCard);
        }
        if (type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
            return LocaleController.getString("ActionBotDocumentUtilityBill", R.string.ActionBotDocumentUtilityBill);
        }
        if (type instanceof TLRPC.TL_secureValueTypeBankStatement) {
            return LocaleController.getString("ActionBotDocumentBankStatement", R.string.ActionBotDocumentBankStatement);
        }
        if (type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
            return LocaleController.getString("ActionBotDocumentRentalAgreement", R.string.ActionBotDocumentRentalAgreement);
        }
        if (type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
            return LocaleController.getString("ActionBotDocumentInternalPassport", R.string.ActionBotDocumentInternalPassport);
        }
        if (type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
            return LocaleController.getString("ActionBotDocumentPassportRegistration", R.string.ActionBotDocumentPassportRegistration);
        }
        if (type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
            return LocaleController.getString("ActionBotDocumentTemporaryRegistration", R.string.ActionBotDocumentTemporaryRegistration);
        }
        if (type instanceof TLRPC.TL_secureValueTypePhone) {
            return LocaleController.getString("ActionBotDocumentPhone", R.string.ActionBotDocumentPhone);
        }
        if (type instanceof TLRPC.TL_secureValueTypeEmail) {
            return LocaleController.getString("ActionBotDocumentEmail", R.string.ActionBotDocumentEmail);
        }
        return "";
    }

    public void setTypeValue(TLRPC.TL_secureRequiredType requiredType, String text, String json, TLRPC.TL_secureRequiredType documentRequiredType, String documentsJson, boolean documentOnly, int availableDocumentTypesCount) {
        String str;
        boolean z;
        TextDetailSecureCell view;
        TextDetailSecureCell view2;
        TLRPC.TL_secureValue requiredTypeValue;
        StringBuilder stringBuilder;
        String value;
        StringBuilder stringBuilder2;
        String[] keys;
        JSONObject jsonObject;
        HashMap<String, String> values;
        HashMap<String, String> documentValues;
        String str2;
        String[] currentKeys;
        JSONObject jsonObject2;
        HashMap<String, String> values2;
        HashMap<String, String> documentValues2;
        String[] currentKeys2;
        JSONObject jsonObject3;
        String str3;
        StringBuilder stringBuilder3;
        char c;
        String country;
        Iterator<String> iter;
        int i;
        String value2;
        boolean z2;
        BufferedReader reader;
        String str4 = json;
        String str5 = documentsJson;
        TextDetailSecureCell view3 = this.typesViews.get(requiredType);
        if (view3 != null) {
            str = "last_name_native";
            z = true;
            view = view3;
        } else {
            if (this.currentActivityType != 8) {
                return;
            }
            ArrayList<TLRPC.TL_secureRequiredType> documentTypes = new ArrayList<>();
            if (documentRequiredType != null) {
                documentTypes.add(documentRequiredType);
            }
            View prev = this.linearLayout2.getChildAt(r1.getChildCount() - 6);
            if (prev instanceof TextDetailSecureCell) {
                ((TextDetailSecureCell) prev).setNeedDivider(true);
            }
            str = "last_name_native";
            z = true;
            TextDetailSecureCell view4 = addField(getParentActivity(), requiredType, documentTypes, true, true);
            updateManageVisibility();
            view = view4;
        }
        HashMap<String, String> values3 = this.typesValues.get(requiredType);
        HashMap<String, String> documentValues3 = documentRequiredType != null ? this.typesValues.get(documentRequiredType) : null;
        TLRPC.TL_secureValue requiredTypeValue2 = getValueByType(requiredType, z);
        TLRPC.TL_secureValue documentRequiredTypeValue = getValueByType(documentRequiredType, z);
        if (str4 == null || this.languageMap != null) {
            view2 = view;
            requiredTypeValue = requiredTypeValue2;
            this.languageMap = null;
        } else {
            this.languageMap = new HashMap<>();
            try {
                requiredTypeValue = requiredTypeValue2;
                try {
                    reader = new BufferedReader(new InputStreamReader(ApplicationLoader.applicationContext.getResources().getAssets().open("countries.txt")));
                } catch (Exception e) {
                    e = e;
                    view2 = view;
                }
            } catch (Exception e2) {
                e = e2;
                view2 = view;
                requiredTypeValue = requiredTypeValue2;
            }
            while (true) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                String[] args = line.split(";");
                view2 = view;
                try {
                    this.languageMap.put(args[1], args[2]);
                    view = view2;
                } catch (Exception e3) {
                    e = e3;
                }
                e = e3;
                FileLog.e(e);
            }
            view2 = view;
            reader.close();
        }
        if (text == null) {
            if (this.currentActivityType != 8 && documentRequiredType != null && (!TextUtils.isEmpty(documentsJson) || documentRequiredTypeValue != null)) {
                stringBuilder = 0 == 0 ? new StringBuilder() : null;
                if (availableDocumentTypesCount > 1) {
                    stringBuilder.append(getTextForType(documentRequiredType.type));
                } else if (TextUtils.isEmpty(documentsJson)) {
                    stringBuilder.append(LocaleController.getString("PassportDocuments", R.string.PassportDocuments));
                }
            }
            if (str4 == null && str5 == null) {
                stringBuilder = stringBuilder;
                value = null;
            } else {
                if (values3 == null) {
                    return;
                }
                values3.clear();
                String[] keys2 = null;
                String[] documentKeys = null;
                stringBuilder = stringBuilder;
                if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                    if (this.currentActivityType != 0 || documentOnly) {
                        value = null;
                        if (this.currentActivityType == 8) {
                        }
                        i = this.currentActivityType;
                        if (i != 0 || (i == 8 && documentRequiredType != null)) {
                            documentKeys = new String[]{"document_no", "expiry_date"};
                        }
                    } else {
                        value = null;
                    }
                    keys2 = new String[]{"first_name", "middle_name", "last_name", "first_name_native", "middle_name_native", "last_name_native", "birth_date", "gender", "country_code", "residence_country_code"};
                    i = this.currentActivityType;
                    if (i != 0) {
                    }
                    documentKeys = new String[]{"document_no", "expiry_date"};
                } else {
                    value = null;
                    if ((requiredType.type instanceof TLRPC.TL_secureValueTypeAddress) && ((this.currentActivityType == 0 && !documentOnly) || (this.currentActivityType == 8 && documentRequiredType == null))) {
                        keys2 = new String[]{"street_line1", "street_line2", "post_code", "city", RemoteConfigConstants.ResponseFieldKey.STATE, "country_code"};
                    }
                }
                if (keys2 != null || documentKeys != null) {
                    JSONObject jsonObject4 = null;
                    String[] currentKeys3 = null;
                    int b = 0;
                    while (b < 2) {
                        if (b == 0) {
                            if (str4 != null) {
                                try {
                                    JSONObject jsonObject5 = new JSONObject(str4);
                                    keys = keys2;
                                    jsonObject = jsonObject5;
                                    if (keys2 != null) {
                                        values = values3;
                                        documentValues = documentValues3;
                                        currentKeys = keys2;
                                        jsonObject2 = jsonObject;
                                        str2 = str;
                                    } else if (jsonObject == null) {
                                        values = values3;
                                        documentValues = documentValues3;
                                        currentKeys = keys2;
                                        jsonObject2 = jsonObject;
                                        str2 = str;
                                    } else {
                                        try {
                                            Iterator<String> iter2 = jsonObject.keys();
                                            while (iter2.hasNext()) {
                                                String key = iter2.next();
                                                if (b == 0) {
                                                    iter = iter2;
                                                    values3.put(key, jsonObject.getString(key));
                                                } else {
                                                    iter = iter2;
                                                    documentValues3.put(key, jsonObject.getString(key));
                                                }
                                                iter2 = iter;
                                            }
                                        } catch (Throwable e4) {
                                            FileLog.e(e4);
                                        }
                                        int a = 0;
                                        while (a < keys2.length) {
                                            try {
                                                if (jsonObject.has(keys2[a])) {
                                                    if (stringBuilder == null) {
                                                        try {
                                                            stringBuilder3 = new StringBuilder();
                                                        } catch (Exception e5) {
                                                            stringBuilder2 = stringBuilder;
                                                        }
                                                    } else {
                                                        stringBuilder3 = stringBuilder;
                                                    }
                                                    values2 = values3;
                                                    try {
                                                        String jsonValue = jsonObject.getString(keys2[a]);
                                                        if (jsonValue == null) {
                                                            documentValues2 = documentValues3;
                                                            currentKeys2 = keys2;
                                                            jsonObject3 = jsonObject;
                                                            str3 = str;
                                                        } else if (TextUtils.isEmpty(jsonValue)) {
                                                            documentValues2 = documentValues3;
                                                            currentKeys2 = keys2;
                                                            jsonObject3 = jsonObject;
                                                            str3 = str;
                                                        } else {
                                                            documentValues2 = documentValues3;
                                                            try {
                                                                jsonObject3 = jsonObject;
                                                                if ("first_name_native".equals(keys2[a])) {
                                                                    currentKeys2 = keys2;
                                                                    str3 = str;
                                                                } else if ("middle_name_native".equals(keys2[a])) {
                                                                    currentKeys2 = keys2;
                                                                    str3 = str;
                                                                } else {
                                                                    str3 = str;
                                                                    if (str3.equals(keys2[a])) {
                                                                        currentKeys2 = keys2;
                                                                    } else {
                                                                        if (stringBuilder3.length() > 0) {
                                                                            if (!"last_name".equals(keys2[a]) && !str3.equals(keys2[a]) && !"middle_name".equals(keys2[a]) && !"middle_name_native".equals(keys2[a])) {
                                                                                stringBuilder3.append(", ");
                                                                            }
                                                                            stringBuilder3.append(" ");
                                                                        }
                                                                        String str6 = keys2[a];
                                                                        int hashCode = str6.hashCode();
                                                                        currentKeys2 = keys2;
                                                                        if (hashCode == -2006252145) {
                                                                            if (str6.equals("residence_country_code")) {
                                                                                c = 1;
                                                                                if (c != 0) {
                                                                                }
                                                                                country = this.languageMap.get(jsonValue);
                                                                                if (country != null) {
                                                                                }
                                                                            }
                                                                            c = 65535;
                                                                            if (c != 0) {
                                                                            }
                                                                            country = this.languageMap.get(jsonValue);
                                                                            if (country != null) {
                                                                            }
                                                                        } else if (hashCode != -1249512767) {
                                                                            if (hashCode == 1481071862 && str6.equals("country_code")) {
                                                                                c = 0;
                                                                                if (c != 0 || c == 1) {
                                                                                    country = this.languageMap.get(jsonValue);
                                                                                    if (country != null) {
                                                                                        stringBuilder3.append(country);
                                                                                    }
                                                                                } else if (c != 2) {
                                                                                    stringBuilder3.append(jsonValue);
                                                                                } else if ("male".equals(jsonValue)) {
                                                                                    stringBuilder3.append(LocaleController.getString("PassportMale", R.string.PassportMale));
                                                                                } else if ("female".equals(jsonValue)) {
                                                                                    stringBuilder3.append(LocaleController.getString("PassportFemale", R.string.PassportFemale));
                                                                                }
                                                                            }
                                                                            c = 65535;
                                                                            if (c != 0) {
                                                                            }
                                                                            country = this.languageMap.get(jsonValue);
                                                                            if (country != null) {
                                                                            }
                                                                        } else {
                                                                            if (str6.equals("gender")) {
                                                                                c = 2;
                                                                                if (c != 0) {
                                                                                }
                                                                                country = this.languageMap.get(jsonValue);
                                                                                if (country != null) {
                                                                                }
                                                                            }
                                                                            c = 65535;
                                                                            if (c != 0) {
                                                                            }
                                                                            country = this.languageMap.get(jsonValue);
                                                                            if (country != null) {
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            } catch (Exception e6) {
                                                                stringBuilder2 = stringBuilder3;
                                                            }
                                                        }
                                                        stringBuilder = stringBuilder3;
                                                    } catch (Exception e7) {
                                                        stringBuilder2 = stringBuilder3;
                                                    }
                                                } else {
                                                    values2 = values3;
                                                    documentValues2 = documentValues3;
                                                    currentKeys2 = keys2;
                                                    jsonObject3 = jsonObject;
                                                    str3 = str;
                                                }
                                                a++;
                                                str = str3;
                                                jsonObject = jsonObject3;
                                                values3 = values2;
                                                documentValues3 = documentValues2;
                                                keys2 = currentKeys2;
                                            } catch (Exception e8) {
                                                stringBuilder2 = stringBuilder;
                                            }
                                        }
                                        values = values3;
                                        documentValues = documentValues3;
                                        String[] currentKeys4 = keys2;
                                        JSONObject jsonObject6 = jsonObject;
                                        str2 = str;
                                        jsonObject4 = jsonObject6;
                                        currentKeys3 = currentKeys4;
                                    }
                                    jsonObject4 = jsonObject2;
                                    currentKeys3 = currentKeys;
                                } catch (Exception e9) {
                                    stringBuilder2 = stringBuilder;
                                }
                            }
                            jsonObject = jsonObject4;
                            keys = keys2;
                            keys2 = currentKeys3;
                            if (keys2 != null) {
                            }
                            jsonObject4 = jsonObject2;
                            currentKeys3 = currentKeys;
                        } else if (documentValues3 == null) {
                            values = values3;
                            documentValues = documentValues3;
                            keys = keys2;
                            str2 = str;
                        } else {
                            if (str5 != null) {
                                JSONObject jsonObject7 = new JSONObject(str5);
                                keys = keys2;
                                keys2 = documentKeys;
                                jsonObject = jsonObject7;
                                if (keys2 != null) {
                                }
                                jsonObject4 = jsonObject2;
                                currentKeys3 = currentKeys;
                            }
                            jsonObject = jsonObject4;
                            keys = keys2;
                            keys2 = currentKeys3;
                            if (keys2 != null) {
                            }
                            jsonObject4 = jsonObject2;
                            currentKeys3 = currentKeys;
                        }
                        b++;
                        str4 = json;
                        str5 = documentsJson;
                        str = str2;
                        keys2 = keys;
                        values3 = values;
                        documentValues3 = documentValues;
                    }
                    stringBuilder2 = stringBuilder;
                    if (stringBuilder2 != null) {
                        value2 = stringBuilder2.toString();
                    }
                    value2 = value;
                }
            }
            stringBuilder2 = stringBuilder;
            if (stringBuilder2 != null) {
            }
            value2 = value;
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypePhone) {
            value2 = PhoneFormat.getInstance().format(Marker.ANY_NON_NULL_MARKER + text);
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeEmail) {
            value2 = text;
        } else {
            value = null;
            value2 = value;
        }
        boolean isError = false;
        HashMap<String, String> errors = !documentOnly ? this.errorsMap.get(getNameForType(requiredType.type)) : null;
        HashMap<String, String> documentsErrors = documentRequiredType != null ? this.errorsMap.get(getNameForType(documentRequiredType.type)) : null;
        if ((errors != null && errors.size() > 0) || (documentsErrors != null && documentsErrors.size() > 0)) {
            String value3 = documentOnly ? null : this.mainErrorsMap.get(getNameForType(requiredType.type));
            value2 = value3 == null ? this.mainErrorsMap.get(getNameForType(documentRequiredType.type)) : value3;
            isError = true;
            z2 = true;
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
            if (!TextUtils.isEmpty(value2)) {
                z2 = true;
            } else if (documentRequiredType == null) {
                value2 = LocaleController.getString("PassportPersonalDetailsInfo", R.string.PassportPersonalDetailsInfo);
                z2 = true;
            } else if (this.currentActivityType == 8) {
                value2 = LocaleController.getString("PassportDocuments", R.string.PassportDocuments);
                z2 = true;
            } else if (availableDocumentTypesCount != 1) {
                value2 = LocaleController.getString("PassportIdentityDocumentInfo", R.string.PassportIdentityDocumentInfo);
                z2 = true;
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypePassport) {
                value2 = LocaleController.getString("PassportIdentityPassport", R.string.PassportIdentityPassport);
                z2 = true;
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                value2 = LocaleController.getString("PassportIdentityInternalPassport", R.string.PassportIdentityInternalPassport);
                z2 = true;
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                value2 = LocaleController.getString("PassportIdentityDriverLicence", R.string.PassportIdentityDriverLicence);
                z2 = true;
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                value2 = LocaleController.getString("PassportIdentityID", R.string.PassportIdentityID);
                z2 = true;
            } else {
                z2 = true;
            }
        } else if (!(requiredType.type instanceof TLRPC.TL_secureValueTypeAddress)) {
            z2 = true;
            if (requiredType.type instanceof TLRPC.TL_secureValueTypePhone) {
                if (TextUtils.isEmpty(value2)) {
                    value2 = LocaleController.getString("PassportPhoneInfo", R.string.PassportPhoneInfo);
                }
            } else if ((requiredType.type instanceof TLRPC.TL_secureValueTypeEmail) && TextUtils.isEmpty(value2)) {
                value2 = LocaleController.getString("PassportEmailInfo", R.string.PassportEmailInfo);
            }
        } else if (!TextUtils.isEmpty(value2)) {
            z2 = true;
        } else if (documentRequiredType == null) {
            value2 = LocaleController.getString("PassportAddressNoUploadInfo", R.string.PassportAddressNoUploadInfo);
            z2 = true;
        } else if (this.currentActivityType == 8) {
            value2 = LocaleController.getString("PassportDocuments", R.string.PassportDocuments);
            z2 = true;
        } else {
            z2 = true;
            if (availableDocumentTypesCount != 1) {
                value2 = LocaleController.getString("PassportAddressInfo", R.string.PassportAddressInfo);
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                value2 = LocaleController.getString("PassportAddAgreementInfo", R.string.PassportAddAgreementInfo);
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                value2 = LocaleController.getString("PassportAddBillInfo", R.string.PassportAddBillInfo);
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                value2 = LocaleController.getString("PassportAddPassportRegistrationInfo", R.string.PassportAddPassportRegistrationInfo);
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                value2 = LocaleController.getString("PassportAddTemporaryRegistrationInfo", R.string.PassportAddTemporaryRegistrationInfo);
            } else if (documentRequiredType.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                value2 = LocaleController.getString("PassportAddBankInfo", R.string.PassportAddBankInfo);
            }
        }
        TextDetailSecureCell view5 = view2;
        view5.setValue(value2);
        view5.valueTextView.setTextColor(Theme.getColor(isError ? Theme.key_windowBackgroundWhiteRedText3 : Theme.key_windowBackgroundWhiteGrayText2));
        if (isError || this.currentActivityType == 8 || (((!documentOnly || documentRequiredType == null) && (documentOnly || requiredTypeValue == null)) || (documentRequiredType != null && documentRequiredTypeValue == null))) {
            z2 = false;
        }
        view5.setChecked(z2);
    }

    public void checkNativeFields(boolean byEdit) {
        EditTextBoldCursor[] editTextBoldCursorArr;
        if (this.inputExtraFields == null) {
            return;
        }
        String country = this.languageMap.get(this.currentResidence);
        HashMap<String, String> map = SharedConfig.getCountryLangs();
        String lang = map.get(this.currentResidence);
        if (!this.currentType.native_names || TextUtils.isEmpty(this.currentResidence) || "EN".equals(lang)) {
            if (this.nativeInfoCell.getVisibility() != 8) {
                this.nativeInfoCell.setVisibility(8);
                this.headerCell.setVisibility(8);
                this.extraBackgroundView2.setVisibility(8);
                int a = 0;
                while (true) {
                    EditTextBoldCursor[] editTextBoldCursorArr2 = this.inputExtraFields;
                    if (a >= editTextBoldCursorArr2.length) {
                        break;
                    }
                    ((View) editTextBoldCursorArr2[a].getParent()).setVisibility(8);
                    a++;
                }
                int a2 = this.currentBotId;
                if (((a2 != 0 || this.currentDocumentsType == null) && this.currentTypeValue != null && !this.documentOnly) || this.currentDocumentsTypeValue != null) {
                    this.sectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(getParentActivity(), R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
                    return;
                } else {
                    this.sectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(getParentActivity(), R.drawable.greydivider_bottom, Theme.key_windowBackgroundGrayShadow));
                    return;
                }
            }
            return;
        }
        if (this.nativeInfoCell.getVisibility() != 0) {
            this.nativeInfoCell.setVisibility(0);
            this.headerCell.setVisibility(0);
            this.extraBackgroundView2.setVisibility(0);
            int a3 = 0;
            while (true) {
                editTextBoldCursorArr = this.inputExtraFields;
                if (a3 >= editTextBoldCursorArr.length) {
                    break;
                }
                ((View) editTextBoldCursorArr[a3].getParent()).setVisibility(0);
                a3++;
            }
            if (editTextBoldCursorArr[0].length() == 0 && this.inputExtraFields[1].length() == 0 && this.inputExtraFields[2].length() == 0) {
                int a4 = 0;
                while (true) {
                    boolean[] zArr = this.nonLatinNames;
                    if (a4 >= zArr.length) {
                        break;
                    }
                    if (!zArr[a4]) {
                        a4++;
                    } else {
                        this.inputExtraFields[0].setText(this.inputFields[0].getText());
                        this.inputExtraFields[1].setText(this.inputFields[1].getText());
                        this.inputExtraFields[2].setText(this.inputFields[2].getText());
                        break;
                    }
                }
            }
            this.sectionCell2.setBackgroundDrawable(Theme.getThemedDrawable(getParentActivity(), R.drawable.greydivider, Theme.key_windowBackgroundGrayShadow));
        }
        this.nativeInfoCell.setText(LocaleController.formatString("PassportNativeInfo", R.string.PassportNativeInfo, country));
        String header = lang != null ? LocaleController.getServerString("PassportLanguage_" + lang) : null;
        if (header != null) {
            this.headerCell.setText(LocaleController.formatString("PassportNativeHeaderLang", R.string.PassportNativeHeaderLang, header));
        } else {
            this.headerCell.setText(LocaleController.getString("PassportNativeHeader", R.string.PassportNativeHeader));
        }
        for (int a5 = 0; a5 < 3; a5++) {
            if (a5 != 0) {
                if (a5 != 1) {
                    if (a5 == 2) {
                        if (header != null) {
                            this.inputExtraFields[a5].setHintText(LocaleController.getString("PassportSurname", R.string.PassportSurname));
                        } else {
                            this.inputExtraFields[a5].setHintText(LocaleController.formatString("PassportSurnameCountry", R.string.PassportSurnameCountry, country));
                        }
                    }
                } else if (header != null) {
                    this.inputExtraFields[a5].setHintText(LocaleController.getString("PassportMidname", R.string.PassportMidname));
                } else {
                    this.inputExtraFields[a5].setHintText(LocaleController.formatString("PassportMidnameCountry", R.string.PassportMidnameCountry, country));
                }
            } else if (header != null) {
                this.inputExtraFields[a5].setHintText(LocaleController.getString("PassportName", R.string.PassportName));
            } else {
                this.inputExtraFields[a5].setHintText(LocaleController.formatString("PassportNameCountry", R.string.PassportNameCountry, country));
            }
        }
        if (byEdit) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.this.lambda$checkNativeFields$59$PassportActivity();
                }
            });
        }
    }

    public void lambda$checkNativeFields$59$PassportActivity() {
        EditTextBoldCursor[] editTextBoldCursorArr = this.inputExtraFields;
        if (editTextBoldCursorArr != null) {
            scrollToField(editTextBoldCursorArr[0]);
        }
    }

    private String getErrorsString(HashMap<String, String> errors, HashMap<String, String> documentErrors) {
        HashMap<String, String> hashMap;
        StringBuilder stringBuilder = new StringBuilder();
        for (int a = 0; a < 2; a++) {
            if (a == 0) {
                hashMap = errors;
            } else {
                hashMap = documentErrors;
            }
            if (hashMap != null) {
                for (Map.Entry<String, String> entry : hashMap.entrySet()) {
                    String value = entry.getValue();
                    if (stringBuilder.length() > 0) {
                        stringBuilder.append(", ");
                        value = value.toLowerCase();
                    }
                    if (value.endsWith(".")) {
                        value = value.substring(0, value.length() - 1);
                    }
                    stringBuilder.append(value);
                }
            }
        }
        int a2 = stringBuilder.length();
        if (a2 > 0) {
            stringBuilder.append('.');
        }
        return stringBuilder.toString();
    }

    private TLRPC.TL_secureValue getValueByType(TLRPC.TL_secureRequiredType requiredType, boolean check) {
        String[] keys;
        if (requiredType == null) {
            return null;
        }
        int size = this.currentForm.values.size();
        for (int a = 0; a < size; a++) {
            TLRPC.TL_secureValue secureValue = this.currentForm.values.get(a);
            if (requiredType.type.getClass() == secureValue.type.getClass()) {
                if (check) {
                    if (requiredType.selfie_required && !(secureValue.selfie instanceof TLRPC.TL_secureFile)) {
                        return null;
                    }
                    if (requiredType.translation_required && secureValue.translation.isEmpty()) {
                        return null;
                    }
                    if (isAddressDocument(requiredType.type) && secureValue.files.isEmpty()) {
                        return null;
                    }
                    if (isPersonalDocument(requiredType.type) && !(secureValue.front_side instanceof TLRPC.TL_secureFile)) {
                        return null;
                    }
                    if (((requiredType.type instanceof TLRPC.TL_secureValueTypeDriverLicense) || (requiredType.type instanceof TLRPC.TL_secureValueTypeIdentityCard)) && !(secureValue.reverse_side instanceof TLRPC.TL_secureFile)) {
                        return null;
                    }
                    if ((requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) || (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress)) {
                        if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                            if (requiredType.native_names) {
                                keys = new String[]{"first_name_native", "last_name_native", "birth_date", "gender", "country_code", "residence_country_code"};
                            } else {
                                keys = new String[]{"first_name", "last_name", "birth_date", "gender", "country_code", "residence_country_code"};
                            }
                        } else {
                            keys = new String[]{"street_line1", "street_line2", "post_code", "city", RemoteConfigConstants.ResponseFieldKey.STATE, "country_code"};
                        }
                        try {
                            JSONObject jsonObject = new JSONObject(decryptData(secureValue.data.data, decryptValueSecret(secureValue.data.secret, secureValue.data.data_hash), secureValue.data.data_hash));
                            for (int b = 0; b < keys.length; b++) {
                                if (!jsonObject.has(keys[b]) || TextUtils.isEmpty(jsonObject.getString(keys[b]))) {
                                    return null;
                                }
                            }
                        } catch (Throwable th) {
                            return null;
                        }
                    }
                }
                return secureValue;
            }
        }
        return null;
    }

    private void openTypeActivity(TLRPC.TL_secureRequiredType requiredType, TLRPC.TL_secureRequiredType documentRequiredType, ArrayList<TLRPC.TL_secureRequiredType> availableDocumentTypes, final boolean documentOnly) {
        int activityType;
        HashMap<String, String> hashMap;
        HashMap<String, String> hashMap2;
        final int availableDocumentTypesCount = availableDocumentTypes != null ? availableDocumentTypes.size() : 0;
        final TLRPC.SecureValueType type = requiredType.type;
        TLRPC.SecureValueType documentType = documentRequiredType != null ? documentRequiredType.type : null;
        if (type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
            activityType = 1;
        } else if (type instanceof TLRPC.TL_secureValueTypeAddress) {
            activityType = 2;
        } else if (type instanceof TLRPC.TL_secureValueTypePhone) {
            activityType = 3;
        } else if (!(type instanceof TLRPC.TL_secureValueTypeEmail)) {
            activityType = -1;
        } else {
            activityType = 4;
        }
        if (activityType != -1) {
            if (!documentOnly) {
                hashMap = this.errorsMap.get(getNameForType(type));
            } else {
                hashMap = null;
            }
            HashMap<String, String> errors = hashMap;
            HashMap<String, String> documentsErrors = this.errorsMap.get(getNameForType(documentType));
            TLRPC.TL_secureValue value = getValueByType(requiredType, false);
            TLRPC.TL_secureValue documentsValue = getValueByType(documentRequiredType, false);
            TLRPC.TL_account_authorizationForm tL_account_authorizationForm = this.currentForm;
            TLRPC.TL_account_password tL_account_password = this.currentPassword;
            HashMap<String, String> hashMap3 = this.typesValues.get(requiredType);
            if (documentRequiredType != null) {
                hashMap2 = this.typesValues.get(documentRequiredType);
            } else {
                hashMap2 = null;
            }
            int activityType2 = activityType;
            PassportActivity activity = new PassportActivity(activityType, tL_account_authorizationForm, tL_account_password, requiredType, value, documentRequiredType, documentsValue, hashMap3, hashMap2);
            activity.delegate = new PassportActivityDelegate() {
                private TLRPC.InputSecureFile getInputSecureFile(SecureDocument document) {
                    if (document.inputFile != null) {
                        TLRPC.TL_inputSecureFileUploaded inputSecureFileUploaded = new TLRPC.TL_inputSecureFileUploaded();
                        inputSecureFileUploaded.id = document.inputFile.id;
                        inputSecureFileUploaded.parts = document.inputFile.parts;
                        inputSecureFileUploaded.md5_checksum = document.inputFile.md5_checksum;
                        inputSecureFileUploaded.file_hash = document.fileHash;
                        inputSecureFileUploaded.secret = document.fileSecret;
                        return inputSecureFileUploaded;
                    }
                    TLRPC.TL_inputSecureFile inputSecureFile = new TLRPC.TL_inputSecureFile();
                    inputSecureFile.id = document.secureFile.id;
                    inputSecureFile.access_hash = document.secureFile.access_hash;
                    return inputSecureFile;
                }

                public void renameFile(SecureDocument oldDocument, TLRPC.TL_secureFile newSecureFile) {
                    File oldFile = FileLoader.getPathToAttach(oldDocument);
                    String oldKey = oldDocument.secureFile.dc_id + "_" + oldDocument.secureFile.id;
                    File newFile = FileLoader.getPathToAttach(newSecureFile);
                    String newKey = newSecureFile.dc_id + "_" + newSecureFile.id;
                    oldFile.renameTo(newFile);
                    ImageLoader.getInstance().replaceImageInCache(oldKey, newKey, null, false);
                }

                @Override
                public void saveValue(TLRPC.TL_secureRequiredType tL_secureRequiredType, String str, String str2, TLRPC.TL_secureRequiredType tL_secureRequiredType2, String str3, ArrayList<SecureDocument> arrayList, SecureDocument secureDocument, ArrayList<SecureDocument> arrayList2, SecureDocument secureDocument2, SecureDocument secureDocument3, Runnable runnable, ErrorRunnable errorRunnable) {
                    TLRPC.TL_securePlainPhone tL_securePlainPhone;
                    TLRPC.TL_inputSecureValue tL_inputSecureValue;
                    TLRPC.TL_inputSecureValue tL_inputSecureValue2;
                    TLRPC.TL_inputSecureValue tL_inputSecureValue3 = null;
                    if (!TextUtils.isEmpty(str2)) {
                        tL_inputSecureValue3 = new TLRPC.TL_inputSecureValue();
                        tL_inputSecureValue3.type = tL_secureRequiredType.type;
                        tL_inputSecureValue3.flags |= 1;
                        EncryptionResult encryptData = PassportActivity.this.encryptData(AndroidUtilities.getStringBytes(str2));
                        tL_inputSecureValue3.data = new TLRPC.TL_secureData();
                        tL_inputSecureValue3.data.data = encryptData.encryptedData;
                        tL_inputSecureValue3.data.data_hash = encryptData.fileHash;
                        tL_inputSecureValue3.data.secret = encryptData.fileSecret;
                    } else if (!TextUtils.isEmpty(str)) {
                        TLRPC.SecureValueType secureValueType = type;
                        if (secureValueType instanceof TLRPC.TL_secureValueTypeEmail) {
                            TLRPC.TL_securePlainEmail tL_securePlainEmail = new TLRPC.TL_securePlainEmail();
                            tL_securePlainEmail.email = str;
                            tL_securePlainPhone = tL_securePlainEmail;
                        } else if (secureValueType instanceof TLRPC.TL_secureValueTypePhone) {
                            TLRPC.TL_securePlainPhone tL_securePlainPhone2 = new TLRPC.TL_securePlainPhone();
                            tL_securePlainPhone2.phone = str;
                            tL_securePlainPhone = tL_securePlainPhone2;
                        } else {
                            return;
                        }
                        tL_inputSecureValue3 = new TLRPC.TL_inputSecureValue();
                        tL_inputSecureValue3.type = tL_secureRequiredType.type;
                        tL_inputSecureValue3.flags |= 32;
                        tL_inputSecureValue3.plain_data = tL_securePlainPhone;
                    }
                    if (!documentOnly && tL_inputSecureValue3 == null) {
                        if (errorRunnable != null) {
                            errorRunnable.onError(null, null);
                            return;
                        }
                        return;
                    }
                    if (tL_secureRequiredType2 != null) {
                        TLRPC.TL_inputSecureValue tL_inputSecureValue4 = new TLRPC.TL_inputSecureValue();
                        tL_inputSecureValue4.type = tL_secureRequiredType2.type;
                        if (!TextUtils.isEmpty(str3)) {
                            tL_inputSecureValue4.flags |= 1;
                            EncryptionResult encryptData2 = PassportActivity.this.encryptData(AndroidUtilities.getStringBytes(str3));
                            tL_inputSecureValue4.data = new TLRPC.TL_secureData();
                            tL_inputSecureValue4.data.data = encryptData2.encryptedData;
                            tL_inputSecureValue4.data.data_hash = encryptData2.fileHash;
                            tL_inputSecureValue4.data.secret = encryptData2.fileSecret;
                        }
                        if (secureDocument2 != null) {
                            tL_inputSecureValue4.front_side = getInputSecureFile(secureDocument2);
                            tL_inputSecureValue4.flags |= 2;
                        }
                        if (secureDocument3 != null) {
                            tL_inputSecureValue4.reverse_side = getInputSecureFile(secureDocument3);
                            tL_inputSecureValue4.flags |= 4;
                        }
                        if (secureDocument != null) {
                            tL_inputSecureValue4.selfie = getInputSecureFile(secureDocument);
                            tL_inputSecureValue4.flags |= 8;
                        }
                        if (arrayList2 != null && !arrayList2.isEmpty()) {
                            tL_inputSecureValue4.flags |= 64;
                            int size = arrayList2.size();
                            for (int i = 0; i < size; i++) {
                                tL_inputSecureValue4.translation.add(getInputSecureFile(arrayList2.get(i)));
                            }
                        }
                        if (arrayList != null && !arrayList.isEmpty()) {
                            tL_inputSecureValue4.flags |= 16;
                            int size2 = arrayList.size();
                            for (int i2 = 0; i2 < size2; i2++) {
                                tL_inputSecureValue4.files.add(getInputSecureFile(arrayList.get(i2)));
                            }
                        }
                        if (!documentOnly) {
                            tL_inputSecureValue = tL_inputSecureValue3;
                            tL_inputSecureValue2 = tL_inputSecureValue4;
                        } else {
                            tL_inputSecureValue = tL_inputSecureValue4;
                            tL_inputSecureValue2 = null;
                        }
                    } else {
                        tL_inputSecureValue = tL_inputSecureValue3;
                        tL_inputSecureValue2 = null;
                    }
                    TLRPC.TL_account_saveSecureValue tL_account_saveSecureValue = new TLRPC.TL_account_saveSecureValue();
                    tL_account_saveSecureValue.value = tL_inputSecureValue;
                    tL_account_saveSecureValue.secure_secret_id = PassportActivity.this.secureSecretId;
                    ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(tL_account_saveSecureValue, new AnonymousClass1(errorRunnable, str, tL_account_saveSecureValue, tL_secureRequiredType2, tL_secureRequiredType, arrayList, secureDocument, secureDocument2, secureDocument3, arrayList2, str2, str3, runnable, this, tL_inputSecureValue2));
                }

                public class AnonymousClass1 implements RequestDelegate {
                    final PassportActivityDelegate val$currentDelegate;
                    final TLRPC.TL_secureRequiredType val$documentRequiredType;
                    final ArrayList val$documents;
                    final String val$documentsJson;
                    final ErrorRunnable val$errorRunnable;
                    final TLRPC.TL_inputSecureValue val$finalFileInputSecureValue;
                    final Runnable val$finishRunnable;
                    final SecureDocument val$front;
                    final String val$json;
                    final TLRPC.TL_account_saveSecureValue val$req;
                    final TLRPC.TL_secureRequiredType val$requiredType;
                    final SecureDocument val$reverse;
                    final SecureDocument val$selfie;
                    final String val$text;
                    final ArrayList val$translationDocuments;

                    AnonymousClass1(ErrorRunnable errorRunnable, String str, TLRPC.TL_account_saveSecureValue tL_account_saveSecureValue, TLRPC.TL_secureRequiredType tL_secureRequiredType, TLRPC.TL_secureRequiredType tL_secureRequiredType2, ArrayList arrayList, SecureDocument secureDocument, SecureDocument secureDocument2, SecureDocument secureDocument3, ArrayList arrayList2, String str2, String str3, Runnable runnable, PassportActivityDelegate passportActivityDelegate, TLRPC.TL_inputSecureValue tL_inputSecureValue) {
                        this.val$errorRunnable = errorRunnable;
                        this.val$text = str;
                        this.val$req = tL_account_saveSecureValue;
                        this.val$documentRequiredType = tL_secureRequiredType;
                        this.val$requiredType = tL_secureRequiredType2;
                        this.val$documents = arrayList;
                        this.val$selfie = secureDocument;
                        this.val$front = secureDocument2;
                        this.val$reverse = secureDocument3;
                        this.val$translationDocuments = arrayList2;
                        this.val$json = str2;
                        this.val$documentsJson = str3;
                        this.val$finishRunnable = runnable;
                        this.val$currentDelegate = passportActivityDelegate;
                        this.val$finalFileInputSecureValue = tL_inputSecureValue;
                    }

                    public void lambda$run$4$PassportActivity$19$1(final TLRPC.TL_error error, final TLRPC.TL_secureValue newValue, final TLRPC.TL_secureValue newPendingValue) {
                        final ErrorRunnable errorRunnable = this.val$errorRunnable;
                        final String str = this.val$text;
                        final TLRPC.TL_account_saveSecureValue tL_account_saveSecureValue = this.val$req;
                        final boolean z = documentOnly;
                        final TLRPC.TL_secureRequiredType tL_secureRequiredType = this.val$documentRequiredType;
                        final TLRPC.TL_secureRequiredType tL_secureRequiredType2 = this.val$requiredType;
                        final ArrayList arrayList = this.val$documents;
                        final SecureDocument secureDocument = this.val$selfie;
                        final SecureDocument secureDocument2 = this.val$front;
                        final SecureDocument secureDocument3 = this.val$reverse;
                        final ArrayList arrayList2 = this.val$translationDocuments;
                        final String str2 = this.val$json;
                        final String str3 = this.val$documentsJson;
                        final int i = availableDocumentTypesCount;
                        final Runnable runnable = this.val$finishRunnable;
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                PassportActivity.AnonymousClass19.AnonymousClass1.this.lambda$onResult$0$PassportActivity$19$1(error, errorRunnable, str, tL_account_saveSecureValue, z, tL_secureRequiredType, tL_secureRequiredType2, newValue, newPendingValue, arrayList, secureDocument, secureDocument2, secureDocument3, arrayList2, str2, str3, i, runnable);
                            }
                        });
                    }

                    public void lambda$onResult$0$PassportActivity$19$1(TLRPC.TL_error error, ErrorRunnable errorRunnable, String text, TLRPC.TL_account_saveSecureValue req, boolean documentOnly, TLRPC.TL_secureRequiredType documentRequiredType, TLRPC.TL_secureRequiredType requiredType, TLRPC.TL_secureValue newValue, TLRPC.TL_secureValue newPendingValue, ArrayList documents, SecureDocument selfie, SecureDocument front, SecureDocument reverse, ArrayList translationDocuments, String json, String documentsJson, int availableDocumentTypesCount, Runnable finishRunnable) {
                        int size;
                        int size2;
                        int size3;
                        ArrayList arrayList = documents;
                        ArrayList arrayList2 = translationDocuments;
                        if (error != null) {
                            if (errorRunnable != null) {
                                errorRunnable.onError(error.text, text);
                            }
                            AlertsCreator.processError(PassportActivity.this.currentAccount, error, PassportActivity.this, req, text);
                            return;
                        }
                        if (!documentOnly) {
                            PassportActivity.this.removeValue(requiredType);
                            PassportActivity.this.removeValue(documentRequiredType);
                        } else if (documentRequiredType != null) {
                            PassportActivity.this.removeValue(documentRequiredType);
                        } else {
                            PassportActivity.this.removeValue(requiredType);
                        }
                        if (newValue != null) {
                            PassportActivity.this.currentForm.values.add(newValue);
                        }
                        if (newPendingValue != null) {
                            PassportActivity.this.currentForm.values.add(newPendingValue);
                        }
                        if (arrayList != null && !documents.isEmpty()) {
                            int a = 0;
                            int size4 = documents.size();
                            while (a < size4) {
                                SecureDocument document = (SecureDocument) arrayList.get(a);
                                if (document.inputFile == null) {
                                    size3 = size4;
                                } else {
                                    int b = 0;
                                    int size22 = newValue.files.size();
                                    while (true) {
                                        if (b >= size22) {
                                            size3 = size4;
                                            break;
                                        }
                                        int size23 = size22;
                                        TLRPC.SecureFile file = newValue.files.get(b);
                                        size3 = size4;
                                        if (file instanceof TLRPC.TL_secureFile) {
                                            TLRPC.TL_secureFile secureFile = (TLRPC.TL_secureFile) file;
                                            if (Utilities.arraysEquals(document.fileSecret, 0, secureFile.secret, 0)) {
                                                renameFile(document, secureFile);
                                                break;
                                            }
                                        }
                                        b++;
                                        size22 = size23;
                                        size4 = size3;
                                    }
                                }
                                a++;
                                arrayList = documents;
                                size4 = size3;
                            }
                        }
                        if (selfie != null && selfie.inputFile != null && (newValue.selfie instanceof TLRPC.TL_secureFile)) {
                            TLRPC.TL_secureFile secureFile2 = (TLRPC.TL_secureFile) newValue.selfie;
                            if (Utilities.arraysEquals(selfie.fileSecret, 0, secureFile2.secret, 0)) {
                                renameFile(selfie, secureFile2);
                            }
                        }
                        if (front != null && front.inputFile != null && (newValue.front_side instanceof TLRPC.TL_secureFile)) {
                            TLRPC.TL_secureFile secureFile3 = (TLRPC.TL_secureFile) newValue.front_side;
                            if (Utilities.arraysEquals(front.fileSecret, 0, secureFile3.secret, 0)) {
                                renameFile(front, secureFile3);
                            }
                        }
                        if (reverse != null && reverse.inputFile != null && (newValue.reverse_side instanceof TLRPC.TL_secureFile)) {
                            TLRPC.TL_secureFile secureFile4 = (TLRPC.TL_secureFile) newValue.reverse_side;
                            if (Utilities.arraysEquals(reverse.fileSecret, 0, secureFile4.secret, 0)) {
                                renameFile(reverse, secureFile4);
                            }
                        }
                        if (arrayList2 != null && !translationDocuments.isEmpty()) {
                            int a2 = 0;
                            int size5 = translationDocuments.size();
                            while (a2 < size5) {
                                SecureDocument document2 = (SecureDocument) arrayList2.get(a2);
                                if (document2.inputFile == null) {
                                    size = size5;
                                } else {
                                    int b2 = 0;
                                    int size24 = newValue.translation.size();
                                    while (true) {
                                        if (b2 >= size24) {
                                            size = size5;
                                            break;
                                        }
                                        TLRPC.SecureFile file2 = newValue.translation.get(b2);
                                        if (!(file2 instanceof TLRPC.TL_secureFile)) {
                                            size = size5;
                                            size2 = size24;
                                        } else {
                                            TLRPC.TL_secureFile secureFile5 = (TLRPC.TL_secureFile) file2;
                                            size = size5;
                                            size2 = size24;
                                            if (Utilities.arraysEquals(document2.fileSecret, 0, secureFile5.secret, 0)) {
                                                renameFile(document2, secureFile5);
                                                break;
                                            }
                                        }
                                        b2++;
                                        size5 = size;
                                        size24 = size2;
                                    }
                                }
                                a2++;
                                arrayList2 = translationDocuments;
                                size5 = size;
                            }
                        }
                        PassportActivity.this.setTypeValue(requiredType, text, json, documentRequiredType, documentsJson, documentOnly, availableDocumentTypesCount);
                        if (finishRunnable != null) {
                            finishRunnable.run();
                        }
                    }

                    @Override
                    public void run(TLObject response, final TLRPC.TL_error error) {
                        if (error != null) {
                            if (error.text.equals("EMAIL_VERIFICATION_NEEDED")) {
                                TLRPC.TL_account_sendVerifyEmailCode req = new TLRPC.TL_account_sendVerifyEmailCode();
                                req.email = this.val$text;
                                ConnectionsManager connectionsManager = ConnectionsManager.getInstance(PassportActivity.this.currentAccount);
                                final String str = this.val$text;
                                final TLRPC.TL_secureRequiredType tL_secureRequiredType = this.val$requiredType;
                                final PassportActivityDelegate passportActivityDelegate = this.val$currentDelegate;
                                final ErrorRunnable errorRunnable = this.val$errorRunnable;
                                connectionsManager.sendRequest(req, new RequestDelegate() {
                                    @Override
                                    public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                        PassportActivity.AnonymousClass19.AnonymousClass1.this.lambda$run$2$PassportActivity$19$1(str, tL_secureRequiredType, passportActivityDelegate, errorRunnable, tLObject, tL_error);
                                    }
                                });
                                return;
                            }
                            if (error.text.equals("PHONE_VERIFICATION_NEEDED")) {
                                final ErrorRunnable errorRunnable2 = this.val$errorRunnable;
                                final String str2 = this.val$text;
                                AndroidUtilities.runOnUIThread(new Runnable() {
                                    @Override
                                    public final void run() {
                                        PassportActivity.ErrorRunnable.this.onError(error.text, str2);
                                    }
                                });
                                return;
                            }
                        }
                        if (error == null && this.val$finalFileInputSecureValue != null) {
                            final TLRPC.TL_secureValue pendingValue = (TLRPC.TL_secureValue) response;
                            TLRPC.TL_account_saveSecureValue req2 = new TLRPC.TL_account_saveSecureValue();
                            req2.value = this.val$finalFileInputSecureValue;
                            req2.secure_secret_id = PassportActivity.this.secureSecretId;
                            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req2, new RequestDelegate() {
                                @Override
                                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                    PassportActivity.AnonymousClass19.AnonymousClass1.this.lambda$run$4$PassportActivity$19$1(pendingValue, tLObject, tL_error);
                                }
                            });
                            return;
                        }
                        lambda$run$4$PassportActivity$19$1(error, (TLRPC.TL_secureValue) response, null);
                    }

                    public void lambda$run$2$PassportActivity$19$1(final String text, final TLRPC.TL_secureRequiredType requiredType, final PassportActivityDelegate currentDelegate, final ErrorRunnable errorRunnable, final TLObject response1, final TLRPC.TL_error error1) {
                        AndroidUtilities.runOnUIThread(new Runnable() {
                            @Override
                            public final void run() {
                                PassportActivity.AnonymousClass19.AnonymousClass1.this.lambda$null$1$PassportActivity$19$1(response1, text, requiredType, currentDelegate, error1, errorRunnable);
                            }
                        });
                    }

                    public void lambda$null$1$PassportActivity$19$1(TLObject response1, String text, TLRPC.TL_secureRequiredType requiredType, PassportActivityDelegate currentDelegate, TLRPC.TL_error error1, ErrorRunnable errorRunnable) {
                        if (response1 == null) {
                            PassportActivity.this.showAlertWithText(LocaleController.getString("PassportEmail", R.string.PassportEmail), error1.text);
                            if (errorRunnable != null) {
                                errorRunnable.onError(error1.text, text);
                                return;
                            }
                            return;
                        }
                        TLRPC.TL_account_sentEmailCode res = (TLRPC.TL_account_sentEmailCode) response1;
                        HashMap<String, String> values = new HashMap<>();
                        values.put("email", text);
                        values.put("pattern", res.email_pattern);
                        PassportActivity activity1 = new PassportActivity(6, PassportActivity.this.currentForm, PassportActivity.this.currentPassword, requiredType, (TLRPC.TL_secureValue) null, (TLRPC.TL_secureRequiredType) null, (TLRPC.TL_secureValue) null, values, (HashMap<String, String>) null);
                        activity1.currentAccount = PassportActivity.this.currentAccount;
                        activity1.emailCodeLength = res.length;
                        activity1.saltedPassword = PassportActivity.this.saltedPassword;
                        activity1.secureSecret = PassportActivity.this.secureSecret;
                        activity1.delegate = currentDelegate;
                        PassportActivity.this.presentFragment(activity1, true);
                    }
                }

                @Override
                public SecureDocument saveFile(TLRPC.TL_secureFile secureFile) {
                    String path = FileLoader.getDirectory(4) + "/" + secureFile.dc_id + "_" + secureFile.id + ".jpg";
                    EncryptionResult result = PassportActivity.this.createSecureDocument(path);
                    return new SecureDocument(result.secureDocumentKey, secureFile, path, result.fileHash, result.fileSecret);
                }

                @Override
                public void deleteValue(TLRPC.TL_secureRequiredType requiredType2, TLRPC.TL_secureRequiredType documentRequiredType2, ArrayList<TLRPC.TL_secureRequiredType> documentRequiredTypes, boolean deleteType, Runnable finishRunnable, ErrorRunnable errorRunnable) {
                    PassportActivity.this.deleteValueInternal(requiredType2, documentRequiredType2, documentRequiredTypes, deleteType, finishRunnable, errorRunnable, documentOnly);
                }
            };
            activity.currentAccount = this.currentAccount;
            activity.saltedPassword = this.saltedPassword;
            activity.secureSecret = this.secureSecret;
            activity.currentBotId = this.currentBotId;
            activity.fieldsErrors = errors;
            activity.documentOnly = documentOnly;
            activity.documentsErrors = documentsErrors;
            activity.availableDocumentTypes = availableDocumentTypes;
            if (activityType2 == 4) {
                activity.currentEmail = this.currentEmail;
            }
            presentFragment(activity);
        }
    }

    public TLRPC.TL_secureValue removeValue(TLRPC.TL_secureRequiredType requiredType) {
        if (requiredType == null) {
            return null;
        }
        int size = this.currentForm.values.size();
        for (int a = 0; a < size; a++) {
            TLRPC.TL_secureValue secureValue = this.currentForm.values.get(a);
            if (requiredType.type.getClass() == secureValue.type.getClass()) {
                return this.currentForm.values.remove(a);
            }
        }
        return null;
    }

    public void deleteValueInternal(final TLRPC.TL_secureRequiredType requiredType, final TLRPC.TL_secureRequiredType documentRequiredType, final ArrayList<TLRPC.TL_secureRequiredType> documentRequiredTypes, final boolean deleteType, final Runnable finishRunnable, final ErrorRunnable errorRunnable, final boolean documentOnly) {
        if (requiredType == null) {
            return;
        }
        TLRPC.TL_account_deleteSecureValue req = new TLRPC.TL_account_deleteSecureValue();
        if (documentOnly && documentRequiredType != null) {
            req.types.add(documentRequiredType.type);
        } else {
            if (deleteType) {
                req.types.add(requiredType.type);
            }
            if (documentRequiredType != null) {
                req.types.add(documentRequiredType.type);
            }
        }
        ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                PassportActivity.this.lambda$deleteValueInternal$61$PassportActivity(errorRunnable, documentOnly, documentRequiredType, requiredType, deleteType, documentRequiredTypes, finishRunnable, tLObject, tL_error);
            }
        });
    }

    public void lambda$deleteValueInternal$61$PassportActivity(final ErrorRunnable errorRunnable, final boolean documentOnly, final TLRPC.TL_secureRequiredType documentRequiredType, final TLRPC.TL_secureRequiredType requiredType, final boolean deleteType, final ArrayList documentRequiredTypes, final Runnable finishRunnable, TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$60$PassportActivity(error, errorRunnable, documentOnly, documentRequiredType, requiredType, deleteType, documentRequiredTypes, finishRunnable);
            }
        });
    }

    public void lambda$null$60$PassportActivity(TLRPC.TL_error error, ErrorRunnable errorRunnable, boolean documentOnly, TLRPC.TL_secureRequiredType documentRequiredType, TLRPC.TL_secureRequiredType requiredType, boolean deleteType, ArrayList documentRequiredTypes, Runnable finishRunnable) {
        String documentJson;
        TLRPC.TL_secureRequiredType documentsType;
        String json;
        if (error != null) {
            if (errorRunnable != null) {
                errorRunnable.onError(error.text, null);
            }
            showAlertWithText(LocaleController.getString("AppName", R.string.AppName), error.text);
            return;
        }
        if (documentOnly) {
            if (documentRequiredType != null) {
                removeValue(documentRequiredType);
            } else {
                removeValue(requiredType);
            }
        } else {
            if (deleteType) {
                removeValue(requiredType);
            }
            removeValue(documentRequiredType);
        }
        if (this.currentActivityType == 8) {
            TextDetailSecureCell view = this.typesViews.remove(requiredType);
            if (view != null) {
                this.linearLayout2.removeView(view);
                View child = this.linearLayout2.getChildAt(r1.getChildCount() - 6);
                if (child instanceof TextDetailSecureCell) {
                    ((TextDetailSecureCell) child).setNeedDivider(false);
                }
            }
            updateManageVisibility();
        } else {
            String documentJson2 = null;
            TLRPC.TL_secureRequiredType documentsType2 = documentRequiredType;
            if (documentsType2 != null && documentRequiredTypes != null && documentRequiredTypes.size() > 1) {
                int a = 0;
                int count = documentRequiredTypes.size();
                while (true) {
                    if (a >= count) {
                        break;
                    }
                    TLRPC.TL_secureRequiredType documentType = (TLRPC.TL_secureRequiredType) documentRequiredTypes.get(a);
                    TLRPC.TL_secureValue documentValue = getValueByType(documentType, false);
                    if (documentValue == null) {
                        a++;
                    } else {
                        if (documentValue.data != null) {
                            documentJson2 = decryptData(documentValue.data.data, decryptValueSecret(documentValue.data.secret, documentValue.data.data_hash), documentValue.data.data_hash);
                        }
                        documentsType2 = documentType;
                    }
                }
                if (documentsType2 != null) {
                    documentJson = documentJson2;
                    documentsType = documentsType2;
                } else {
                    documentJson = documentJson2;
                    documentsType = (TLRPC.TL_secureRequiredType) documentRequiredTypes.get(0);
                }
            } else {
                documentJson = null;
                documentsType = documentsType2;
            }
            if (deleteType) {
                setTypeValue(requiredType, null, null, documentsType, documentJson, documentOnly, documentRequiredTypes != null ? documentRequiredTypes.size() : 0);
            } else {
                TLRPC.TL_secureValue value = getValueByType(requiredType, false);
                if (value != null && value.data != null) {
                    String json2 = decryptData(value.data.data, decryptValueSecret(value.data.secret, value.data.data_hash), value.data.data_hash);
                    json = json2;
                } else {
                    json = null;
                }
                setTypeValue(requiredType, null, json, documentsType, documentJson, documentOnly, documentRequiredTypes != null ? documentRequiredTypes.size() : 0);
            }
        }
        if (finishRunnable != null) {
            finishRunnable.run();
        }
    }

    private TextDetailSecureCell addField(Context context, final TLRPC.TL_secureRequiredType requiredType, final ArrayList<TLRPC.TL_secureRequiredType> documentRequiredTypes, final boolean documentOnly, boolean last) {
        String text;
        String text2;
        String json;
        TLRPC.TL_secureRequiredType documentsType;
        String documentJson;
        boolean found;
        int count;
        String documentJson2;
        String text3;
        int availableDocumentTypesCount = documentRequiredTypes != null ? documentRequiredTypes.size() : 0;
        TextDetailSecureCell view = new TextDetailSecureCell(context);
        view.setBackgroundDrawable(Theme.getSelectorDrawable(true));
        if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
            if (documentRequiredTypes == null || documentRequiredTypes.isEmpty()) {
                text3 = LocaleController.getString("PassportPersonalDetails", R.string.PassportPersonalDetails);
            } else if (documentOnly && documentRequiredTypes.size() == 1) {
                text3 = getTextForType(documentRequiredTypes.get(0).type);
            } else if (documentOnly && documentRequiredTypes.size() == 2) {
                text3 = LocaleController.formatString("PassportTwoDocuments", R.string.PassportTwoDocuments, getTextForType(documentRequiredTypes.get(0).type), getTextForType(documentRequiredTypes.get(1).type));
            } else {
                text3 = LocaleController.getString("PassportIdentityDocument", R.string.PassportIdentityDocument);
            }
            view.setTextAndValue(text3, "", !last);
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress) {
            if (documentRequiredTypes == null || documentRequiredTypes.isEmpty()) {
                text = LocaleController.getString("PassportAddress", R.string.PassportAddress);
            } else if (documentOnly && documentRequiredTypes.size() == 1) {
                text = getTextForType(documentRequiredTypes.get(0).type);
            } else if (documentOnly && documentRequiredTypes.size() == 2) {
                text = LocaleController.formatString("PassportTwoDocuments", R.string.PassportTwoDocuments, getTextForType(documentRequiredTypes.get(0).type), getTextForType(documentRequiredTypes.get(1).type));
            } else {
                text = LocaleController.getString("PassportResidentialAddress", R.string.PassportResidentialAddress);
            }
            view.setTextAndValue(text, "", !last);
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypePhone) {
            view.setTextAndValue(LocaleController.getString("PassportPhone", R.string.PassportPhone), "", !last);
        } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeEmail) {
            view.setTextAndValue(LocaleController.getString("PassportEmail", R.string.PassportEmail), "", !last);
        }
        if (this.currentActivityType == 8) {
            this.linearLayout2.addView(view, r1.getChildCount() - 5, LayoutHelper.createLinear(-1, -2));
        } else {
            this.linearLayout2.addView(view, LayoutHelper.createLinear(-1, -2));
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public final void onClick(View view2) {
                PassportActivity.this.lambda$addField$65$PassportActivity(documentRequiredTypes, requiredType, documentOnly, view2);
            }
        });
        this.typesViews.put(requiredType, view);
        String documentJson3 = null;
        this.typesValues.put(requiredType, new HashMap<>());
        TLRPC.TL_secureValue value = getValueByType(requiredType, false);
        if (value != null) {
            if (value.plain_data instanceof TLRPC.TL_securePlainEmail) {
                String text4 = ((TLRPC.TL_securePlainEmail) value.plain_data).email;
                text2 = text4;
                json = null;
            } else if (value.plain_data instanceof TLRPC.TL_securePlainPhone) {
                String text5 = ((TLRPC.TL_securePlainPhone) value.plain_data).phone;
                text2 = text5;
                json = null;
            } else if (value.data != null) {
                String json2 = decryptData(value.data.data, decryptValueSecret(value.data.secret, value.data.data_hash), value.data.data_hash);
                text2 = null;
                json = json2;
            }
            TLRPC.TL_secureRequiredType documentsType2 = null;
            if (documentRequiredTypes == null && !documentRequiredTypes.isEmpty()) {
                boolean found2 = false;
                int a = 0;
                int count2 = documentRequiredTypes.size();
                while (a < count2) {
                    TLRPC.TL_secureRequiredType documentType = documentRequiredTypes.get(a);
                    String documentJson4 = documentJson3;
                    this.typesValues.put(documentType, new HashMap<>());
                    this.documentsToTypesLink.put(documentType, requiredType);
                    if (!found2) {
                        TLRPC.TL_secureValue documentValue = getValueByType(documentType, false);
                        if (documentValue == null) {
                            found = found2;
                            count = count2;
                        } else {
                            if (documentValue.data != null) {
                                count = count2;
                                documentJson2 = decryptData(documentValue.data.data, decryptValueSecret(documentValue.data.secret, documentValue.data.data_hash), documentValue.data.data_hash);
                            } else {
                                count = count2;
                                documentJson2 = documentJson4;
                            }
                            documentsType2 = documentType;
                            found2 = true;
                            documentJson3 = documentJson2;
                            a++;
                            count2 = count;
                        }
                    } else {
                        found = found2;
                        count = count2;
                    }
                    documentJson3 = documentJson4;
                    found2 = found;
                    a++;
                    count2 = count;
                }
                documentJson = documentJson3;
                if (documentsType2 != null) {
                    documentsType = documentsType2;
                } else {
                    TLRPC.TL_secureRequiredType documentsType3 = documentRequiredTypes.get(0);
                    documentsType = documentsType3;
                }
            } else {
                documentsType = null;
                documentJson = null;
            }
            setTypeValue(requiredType, text2, json, documentsType, documentJson, documentOnly, availableDocumentTypesCount);
            return view;
        }
        text2 = null;
        json = null;
        TLRPC.TL_secureRequiredType documentsType22 = null;
        if (documentRequiredTypes == null) {
        }
        documentsType = null;
        documentJson = null;
        setTypeValue(requiredType, text2, json, documentsType, documentJson, documentOnly, availableDocumentTypesCount);
        return view;
    }

    public void lambda$addField$65$PassportActivity(final ArrayList documentRequiredTypes, final TLRPC.TL_secureRequiredType requiredType, final boolean documentOnly, View v) {
        int i;
        String str;
        TLRPC.TL_secureRequiredType documentsType = null;
        if (documentRequiredTypes != null) {
            int count = documentRequiredTypes.size();
            for (int a = 0; a < count; a++) {
                TLRPC.TL_secureRequiredType documentType = (TLRPC.TL_secureRequiredType) documentRequiredTypes.get(a);
                if (getValueByType(documentType, false) != null || count == 1) {
                    documentsType = documentType;
                    break;
                }
            }
        }
        if ((requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) || (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress)) {
            if (documentsType == null && documentRequiredTypes != null && !documentRequiredTypes.isEmpty()) {
                AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                builder.setPositiveButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                if (requiredType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
                    builder.setTitle(LocaleController.getString("PassportIdentityDocument", R.string.PassportIdentityDocument));
                } else if (requiredType.type instanceof TLRPC.TL_secureValueTypeAddress) {
                    builder.setTitle(LocaleController.getString("PassportAddress", R.string.PassportAddress));
                }
                ArrayList<String> strings = new ArrayList<>();
                int count2 = documentRequiredTypes.size();
                for (int a2 = 0; a2 < count2; a2++) {
                    TLRPC.TL_secureRequiredType documentType2 = (TLRPC.TL_secureRequiredType) documentRequiredTypes.get(a2);
                    if (documentType2.type instanceof TLRPC.TL_secureValueTypeDriverLicense) {
                        strings.add(LocaleController.getString("PassportAddLicence", R.string.PassportAddLicence));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypePassport) {
                        strings.add(LocaleController.getString("PassportAddPassport", R.string.PassportAddPassport));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeInternalPassport) {
                        strings.add(LocaleController.getString("PassportAddInternalPassport", R.string.PassportAddInternalPassport));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeIdentityCard) {
                        strings.add(LocaleController.getString("PassportAddCard", R.string.PassportAddCard));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeUtilityBill) {
                        strings.add(LocaleController.getString("PassportAddBill", R.string.PassportAddBill));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeBankStatement) {
                        strings.add(LocaleController.getString("PassportAddBank", R.string.PassportAddBank));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeRentalAgreement) {
                        strings.add(LocaleController.getString("PassportAddAgreement", R.string.PassportAddAgreement));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypeTemporaryRegistration) {
                        strings.add(LocaleController.getString("PassportAddTemporaryRegistration", R.string.PassportAddTemporaryRegistration));
                    } else if (documentType2.type instanceof TLRPC.TL_secureValueTypePassportRegistration) {
                        strings.add(LocaleController.getString("PassportAddPassportRegistration", R.string.PassportAddPassportRegistration));
                    }
                }
                builder.setItems((CharSequence[]) strings.toArray(new CharSequence[0]), new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(DialogInterface dialogInterface, int i2) {
                        PassportActivity.this.lambda$null$62$PassportActivity(requiredType, documentRequiredTypes, documentOnly, dialogInterface, i2);
                    }
                });
                showDialog(builder.create());
                return;
            }
        } else {
            boolean phoneField = requiredType.type instanceof TLRPC.TL_secureValueTypePhone;
            if (phoneField || (requiredType.type instanceof TLRPC.TL_secureValueTypeEmail)) {
                TLRPC.TL_secureValue value = getValueByType(requiredType, false);
                if (value != null) {
                    AlertDialog.Builder builder2 = new AlertDialog.Builder(getParentActivity());
                    builder2.setPositiveButton(LocaleController.getString("OK", R.string.OK), new DialogInterface.OnClickListener() {
                        @Override
                        public final void onClick(DialogInterface dialogInterface, int i2) {
                            PassportActivity.this.lambda$null$64$PassportActivity(requiredType, documentOnly, dialogInterface, i2);
                        }
                    });
                    builder2.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
                    builder2.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    if (phoneField) {
                        i = R.string.PassportDeletePhoneAlert;
                        str = "PassportDeletePhoneAlert";
                    } else {
                        i = R.string.PassportDeleteEmailAlert;
                        str = "PassportDeleteEmailAlert";
                    }
                    builder2.setMessage(LocaleController.getString(str, i));
                    showDialog(builder2.create());
                    return;
                }
            }
        }
        openTypeActivity(requiredType, documentsType, documentRequiredTypes, documentOnly);
    }

    public void lambda$null$62$PassportActivity(TLRPC.TL_secureRequiredType requiredType, ArrayList documentRequiredTypes, boolean documentOnly, DialogInterface dialog, int which) {
        openTypeActivity(requiredType, (TLRPC.TL_secureRequiredType) documentRequiredTypes.get(which), documentRequiredTypes, documentOnly);
    }

    public void lambda$null$64$PassportActivity(TLRPC.TL_secureRequiredType requiredType, boolean documentOnly, DialogInterface dialog, int which) {
        needShowProgress();
        deleteValueInternal(requiredType, null, null, true, new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.needHideProgress();
            }
        }, new ErrorRunnable() {
            @Override
            public final void onError(String str, String str2) {
                PassportActivity.this.lambda$null$63$PassportActivity(str, str2);
            }
        }, documentOnly);
    }

    public void lambda$null$63$PassportActivity(String error, String text) {
        needHideProgress();
    }

    public class EncryptionResult {
        byte[] decrypyedFileSecret;
        byte[] encryptedData;
        byte[] fileHash;
        byte[] fileSecret;
        SecureDocumentKey secureDocumentKey;

        public EncryptionResult(byte[] d, byte[] fs, byte[] dfs, byte[] fh, byte[] fk, byte[] fi) {
            this.encryptedData = d;
            this.fileSecret = fs;
            this.fileHash = fh;
            this.decrypyedFileSecret = dfs;
            this.secureDocumentKey = new SecureDocumentKey(fk, fi);
        }
    }

    private SecureDocumentKey getSecureDocumentKey(byte[] file_secret, byte[] file_hash) {
        byte[] decrypted_file_secret = decryptValueSecret(file_secret, file_hash);
        byte[] file_secret_hash = Utilities.computeSHA512(decrypted_file_secret, file_hash);
        byte[] file_key = new byte[32];
        System.arraycopy(file_secret_hash, 0, file_key, 0, 32);
        byte[] file_iv = new byte[16];
        System.arraycopy(file_secret_hash, 32, file_iv, 0, 16);
        return new SecureDocumentKey(file_key, file_iv);
    }

    public byte[] decryptSecret(byte[] secret, byte[] passwordHash) {
        if (secret == null || secret.length != 32) {
            return null;
        }
        byte[] key = new byte[32];
        System.arraycopy(passwordHash, 0, key, 0, 32);
        byte[] iv = new byte[16];
        System.arraycopy(passwordHash, 32, iv, 0, 16);
        byte[] decryptedSecret = new byte[32];
        System.arraycopy(secret, 0, decryptedSecret, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(decryptedSecret, key, iv, 0, decryptedSecret.length, 0, 0);
        return decryptedSecret;
    }

    private byte[] decryptValueSecret(byte[] encryptedSecureValueSecret, byte[] hash) {
        if (encryptedSecureValueSecret == null || encryptedSecureValueSecret.length != 32 || hash == null || hash.length != 32) {
            return null;
        }
        byte[] key = new byte[32];
        System.arraycopy(this.saltedPassword, 0, key, 0, 32);
        byte[] iv = new byte[16];
        System.arraycopy(this.saltedPassword, 32, iv, 0, 16);
        byte[] decryptedSecret = new byte[32];
        System.arraycopy(this.secureSecret, 0, decryptedSecret, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(decryptedSecret, key, iv, 0, decryptedSecret.length, 0, 0);
        if (!checkSecret(decryptedSecret, null)) {
            return null;
        }
        byte[] secret_hash = Utilities.computeSHA512(decryptedSecret, hash);
        byte[] file_secret_key = new byte[32];
        System.arraycopy(secret_hash, 0, file_secret_key, 0, 32);
        byte[] file_secret_iv = new byte[16];
        System.arraycopy(secret_hash, 32, file_secret_iv, 0, 16);
        byte[] result = new byte[32];
        System.arraycopy(encryptedSecureValueSecret, 0, result, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(result, file_secret_key, file_secret_iv, 0, result.length, 0, 0);
        return result;
    }

    public EncryptionResult createSecureDocument(String path) {
        File file = new File(path);
        int length = (int) file.length();
        byte[] b = new byte[length];
        RandomAccessFile f = null;
        try {
            f = new RandomAccessFile(path, "rws");
            f.readFully(b);
        } catch (Exception e) {
        }
        EncryptionResult result = encryptData(b);
        try {
            f.seek(0L);
            f.write(result.encryptedData);
            f.close();
        } catch (Exception e2) {
        }
        return result;
    }

    private String decryptData(byte[] data, byte[] file_secret, byte[] file_hash) {
        if (data == null || file_secret == null || file_secret.length != 32 || file_hash == null || file_hash.length != 32) {
            return null;
        }
        byte[] file_secret_hash = Utilities.computeSHA512(file_secret, file_hash);
        byte[] file_key = new byte[32];
        System.arraycopy(file_secret_hash, 0, file_key, 0, 32);
        byte[] file_iv = new byte[16];
        System.arraycopy(file_secret_hash, 32, file_iv, 0, 16);
        byte[] decryptedData = new byte[data.length];
        System.arraycopy(data, 0, decryptedData, 0, data.length);
        Utilities.aesCbcEncryptionByteArraySafe(decryptedData, file_key, file_iv, 0, decryptedData.length, 0, 0);
        byte[] hash = Utilities.computeSHA256(decryptedData);
        if (!Arrays.equals(hash, file_hash)) {
            return null;
        }
        int dataOffset = decryptedData[0] & UByte.MAX_VALUE;
        return new String(decryptedData, dataOffset, decryptedData.length - dataOffset);
    }

    public static boolean checkSecret(byte[] secret, Long id) {
        if (secret == null || secret.length != 32) {
            return false;
        }
        int sum = 0;
        for (byte b : secret) {
            sum += b & UByte.MAX_VALUE;
        }
        if (sum % 255 != 239) {
            return false;
        }
        if (id != null && Utilities.bytesToLong(Utilities.computeSHA256(secret)) != id.longValue()) {
            return false;
        }
        return true;
    }

    public byte[] getRandomSecret() {
        byte[] secret = new byte[32];
        Utilities.random.nextBytes(secret);
        int sum = 0;
        for (byte b : secret) {
            sum += b & UByte.MAX_VALUE;
        }
        int sum2 = sum % 255;
        if (sum2 != 239) {
            int a = Utilities.random.nextInt(32);
            int val = (secret[a] & UByte.MAX_VALUE) + (239 - sum2);
            if (val < 255) {
                val += 255;
            }
            secret[a] = (byte) (val % 255);
        }
        return secret;
    }

    public EncryptionResult encryptData(byte[] data) {
        byte[] file_secret = getRandomSecret();
        int extraLen = Utilities.random.nextInt(208) + 32;
        while ((data.length + extraLen) % 16 != 0) {
            extraLen++;
        }
        byte[] padding = new byte[extraLen];
        Utilities.random.nextBytes(padding);
        padding[0] = (byte) extraLen;
        byte[] paddedData = new byte[data.length + extraLen];
        System.arraycopy(padding, 0, paddedData, 0, extraLen);
        System.arraycopy(data, 0, paddedData, extraLen, data.length);
        byte[] file_hash = Utilities.computeSHA256(paddedData);
        byte[] file_secret_hash = Utilities.computeSHA512(file_secret, file_hash);
        byte[] file_key = new byte[32];
        System.arraycopy(file_secret_hash, 0, file_key, 0, 32);
        byte[] file_iv = new byte[16];
        System.arraycopy(file_secret_hash, 32, file_iv, 0, 16);
        Utilities.aesCbcEncryptionByteArraySafe(paddedData, file_key, file_iv, 0, paddedData.length, 0, 1);
        byte[] key = new byte[32];
        System.arraycopy(this.saltedPassword, 0, key, 0, 32);
        byte[] iv = new byte[16];
        System.arraycopy(this.saltedPassword, 32, iv, 0, 16);
        byte[] decryptedSecret = new byte[32];
        System.arraycopy(this.secureSecret, 0, decryptedSecret, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(decryptedSecret, key, iv, 0, decryptedSecret.length, 0, 0);
        byte[] secret_hash = Utilities.computeSHA512(decryptedSecret, file_hash);
        byte[] file_secret_key = new byte[32];
        System.arraycopy(secret_hash, 0, file_secret_key, 0, 32);
        byte[] file_secret_iv = new byte[16];
        System.arraycopy(secret_hash, 32, file_secret_iv, 0, 16);
        byte[] encrypyed_file_secret = new byte[32];
        System.arraycopy(file_secret, 0, encrypyed_file_secret, 0, 32);
        Utilities.aesCbcEncryptionByteArraySafe(encrypyed_file_secret, file_secret_key, file_secret_iv, 0, encrypyed_file_secret.length, 0, 1);
        return new EncryptionResult(paddedData, encrypyed_file_secret, file_secret, file_hash, file_key, file_iv);
    }

    public void showAlertWithText(String title, String text) {
        if (getParentActivity() == null) {
            return;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
        builder.setTitle(title);
        builder.setMessage(text);
        showDialog(builder.create());
    }

    public void onPasscodeError(boolean clear) {
        if (getParentActivity() == null) {
            return;
        }
        Vibrator v = (Vibrator) getParentActivity().getSystemService("vibrator");
        if (v != null) {
            v.vibrate(200L);
        }
        if (clear) {
            this.inputFields[0].setText("");
        }
        AndroidUtilities.shakeView(this.inputFields[0], 2.0f, 0);
    }

    public void startPhoneVerification(boolean checkPermissions, final String phone, Runnable finishRunnable, ErrorRunnable errorRunnable, final PassportActivityDelegate delegate) {
        final TLRPC.TL_account_sendVerifyPhoneCode req = new TLRPC.TL_account_sendVerifyPhoneCode();
        req.phone_number = phone;
        req.settings = new TLRPC.TL_codeSettings();
        req.settings.allow_flashcall = false;
        req.settings.allow_app_hash = ApplicationLoader.hasPlayServices;
        SharedPreferences preferences = ApplicationLoader.applicationContext.getSharedPreferences("mainconfig", 0);
        if (req.settings.allow_app_hash) {
            preferences.edit().putString("sms_hash", BuildVars.SMS_HASH).commit();
        } else {
            preferences.edit().remove("sms_hash").commit();
        }
        ConnectionsManager.getInstance(this.currentAccount).sendRequest(req, new RequestDelegate() {
            @Override
            public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                PassportActivity.this.lambda$startPhoneVerification$67$PassportActivity(phone, delegate, req, tLObject, tL_error);
            }
        }, 2);
    }

    public void lambda$startPhoneVerification$67$PassportActivity(final String phone, final PassportActivityDelegate delegate, final TLRPC.TL_account_sendVerifyPhoneCode req, final TLObject response, final TLRPC.TL_error error) {
        AndroidUtilities.runOnUIThread(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$null$66$PassportActivity(error, phone, delegate, response, req);
            }
        });
    }

    public void lambda$null$66$PassportActivity(TLRPC.TL_error error, String phone, PassportActivityDelegate delegate, TLObject response, TLRPC.TL_account_sendVerifyPhoneCode req) {
        if (error != null) {
            AlertsCreator.processError(this.currentAccount, error, this, req, phone);
            return;
        }
        HashMap<String, String> values = new HashMap<>();
        values.put("phone", phone);
        PassportActivity activity = new PassportActivity(7, this.currentForm, this.currentPassword, this.currentType, (TLRPC.TL_secureValue) null, (TLRPC.TL_secureRequiredType) null, (TLRPC.TL_secureValue) null, values, (HashMap<String, String>) null);
        activity.currentAccount = this.currentAccount;
        activity.saltedPassword = this.saltedPassword;
        activity.secureSecret = this.secureSecret;
        activity.delegate = delegate;
        activity.currentPhoneVerification = (TLRPC.TL_auth_sentCode) response;
        presentFragment(activity, true);
    }

    public void updatePasswordInterface() {
        if (this.noPasswordImageView == null) {
            return;
        }
        TLRPC.TL_account_password tL_account_password = this.currentPassword;
        if (tL_account_password == null || this.usingSavedPassword != 0) {
            this.noPasswordImageView.setVisibility(8);
            this.noPasswordTextView.setVisibility(8);
            this.noPasswordSetTextView.setVisibility(8);
            this.passwordAvatarContainer.setVisibility(8);
            this.inputFieldContainers[0].setVisibility(8);
            this.doneItem.setVisibility(8);
            this.passwordForgotButton.setVisibility(8);
            this.passwordInfoRequestTextView.setVisibility(8);
            this.passwordRequestTextView.setVisibility(8);
            this.emptyView.setVisibility(0);
            return;
        }
        if (!tL_account_password.has_password) {
            this.passwordRequestTextView.setVisibility(0);
            this.noPasswordImageView.setVisibility(0);
            this.noPasswordTextView.setVisibility(0);
            this.noPasswordSetTextView.setVisibility(0);
            this.passwordAvatarContainer.setVisibility(8);
            this.inputFieldContainers[0].setVisibility(8);
            this.doneItem.setVisibility(8);
            this.passwordForgotButton.setVisibility(8);
            this.passwordInfoRequestTextView.setVisibility(8);
            this.passwordRequestTextView.setLayoutParams(LayoutHelper.createLinear(-1, -2, 0.0f, 25.0f, 0.0f, 0.0f));
            this.emptyView.setVisibility(8);
            return;
        }
        this.passwordRequestTextView.setVisibility(0);
        this.noPasswordImageView.setVisibility(8);
        this.noPasswordTextView.setVisibility(8);
        this.noPasswordSetTextView.setVisibility(8);
        this.emptyView.setVisibility(8);
        this.passwordAvatarContainer.setVisibility(0);
        this.inputFieldContainers[0].setVisibility(0);
        this.doneItem.setVisibility(0);
        this.passwordForgotButton.setVisibility(0);
        this.passwordInfoRequestTextView.setVisibility(0);
        this.passwordRequestTextView.setLayoutParams(LayoutHelper.createLinear(-1, -2, 0.0f, 0.0f, 0.0f, 0.0f));
        if (this.inputFields != null) {
            TLRPC.TL_account_password tL_account_password2 = this.currentPassword;
            if (tL_account_password2 != null && !TextUtils.isEmpty(tL_account_password2.hint)) {
                this.inputFields[0].setHint(this.currentPassword.hint);
            } else {
                this.inputFields[0].setHint(LocaleController.getString("LoginPassword", R.string.LoginPassword));
            }
        }
    }

    public void showEditDoneProgress(boolean animateDoneItem, final boolean show) {
        AnimatorSet animatorSet = this.doneItemAnimation;
        if (animatorSet != null) {
            animatorSet.cancel();
        }
        if (animateDoneItem && this.doneItem != null) {
            this.doneItemAnimation = new AnimatorSet();
            if (show) {
                this.progressView.setVisibility(0);
                this.doneItem.setEnabled(false);
                this.doneItemAnimation.playTogether(ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.SCALE_X, 0.1f), ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.SCALE_Y, 0.1f), ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.ALPHA, 0.0f), ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.SCALE_Y, 1.0f), ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.ALPHA, 1.0f));
            } else {
                this.doneItem.getContentView().setVisibility(0);
                this.doneItem.setEnabled(true);
                this.doneItemAnimation.playTogether(ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.SCALE_X, 0.1f), ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.SCALE_Y, 0.1f), ObjectAnimator.ofFloat(this.progressView, (Property<ContextProgressView, Float>) View.ALPHA, 0.0f), ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.SCALE_Y, 1.0f), ObjectAnimator.ofFloat(this.doneItem.getContentView(), (Property<View, Float>) View.ALPHA, 1.0f));
            }
            this.doneItemAnimation.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (PassportActivity.this.doneItemAnimation != null && PassportActivity.this.doneItemAnimation.equals(animation)) {
                        if (!show) {
                            PassportActivity.this.progressView.setVisibility(4);
                        } else {
                            PassportActivity.this.doneItem.getContentView().setVisibility(4);
                        }
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    if (PassportActivity.this.doneItemAnimation != null && PassportActivity.this.doneItemAnimation.equals(animation)) {
                        PassportActivity.this.doneItemAnimation = null;
                    }
                }
            });
            this.doneItemAnimation.setDuration(150L);
            this.doneItemAnimation.start();
            return;
        }
        if (this.acceptTextView != null) {
            this.doneItemAnimation = new AnimatorSet();
            if (show) {
                this.progressViewButton.setVisibility(0);
                this.bottomLayout.setEnabled(false);
                this.doneItemAnimation.playTogether(ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.SCALE_X, 0.1f), ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.SCALE_Y, 0.1f), ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.ALPHA, 0.0f), ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.SCALE_Y, 1.0f), ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.ALPHA, 1.0f));
            } else {
                this.acceptTextView.setVisibility(0);
                this.bottomLayout.setEnabled(true);
                this.doneItemAnimation.playTogether(ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.SCALE_X, 0.1f), ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.SCALE_Y, 0.1f), ObjectAnimator.ofFloat(this.progressViewButton, (Property<ContextProgressView, Float>) View.ALPHA, 0.0f), ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.SCALE_X, 1.0f), ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.SCALE_Y, 1.0f), ObjectAnimator.ofFloat(this.acceptTextView, (Property<TextView, Float>) View.ALPHA, 1.0f));
            }
            this.doneItemAnimation.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationEnd(Animator animation) {
                    if (PassportActivity.this.doneItemAnimation != null && PassportActivity.this.doneItemAnimation.equals(animation)) {
                        if (!show) {
                            PassportActivity.this.progressViewButton.setVisibility(4);
                        } else {
                            PassportActivity.this.acceptTextView.setVisibility(4);
                        }
                    }
                }

                @Override
                public void onAnimationCancel(Animator animation) {
                    if (PassportActivity.this.doneItemAnimation != null && PassportActivity.this.doneItemAnimation.equals(animation)) {
                        PassportActivity.this.doneItemAnimation = null;
                    }
                }
            });
            this.doneItemAnimation.setDuration(150L);
            this.doneItemAnimation.start();
        }
    }

    @Override
    public void didReceivedNotification(int id, int account, Object... args) {
        SecureDocumentCell cell;
        ActionBarMenuItem actionBarMenuItem;
        if (id == NotificationCenter.FileDidUpload) {
            String location = (String) args[0];
            SecureDocument document = this.uploadingDocuments.get(location);
            if (document != null) {
                document.inputFile = (TLRPC.TL_inputFile) args[1];
                this.uploadingDocuments.remove(location);
                if (this.uploadingDocuments.isEmpty() && (actionBarMenuItem = this.doneItem) != null) {
                    actionBarMenuItem.setEnabled(true);
                    this.doneItem.setAlpha(1.0f);
                }
                HashMap<SecureDocument, SecureDocumentCell> hashMap = this.documentsCells;
                if (hashMap != null && (cell = hashMap.get(document)) != null) {
                    cell.updateButtonState(true);
                }
                HashMap<String, String> hashMap2 = this.errorsValues;
                if (hashMap2 != null && hashMap2.containsKey("error_document_all")) {
                    this.errorsValues.remove("error_document_all");
                    checkTopErrorCell(false);
                }
                if (document.type == 0) {
                    if (this.bottomCell != null && !TextUtils.isEmpty(this.noAllDocumentsErrorText)) {
                        this.bottomCell.setText(this.noAllDocumentsErrorText);
                    }
                    this.errorsValues.remove("files_all");
                    return;
                }
                if (document.type == 4) {
                    if (this.bottomCellTranslation != null && !TextUtils.isEmpty(this.noAllTranslationErrorText)) {
                        this.bottomCellTranslation.setText(this.noAllTranslationErrorText);
                    }
                    this.errorsValues.remove("translation_all");
                    return;
                }
                return;
            }
            return;
        }
        if (id != NotificationCenter.FileDidFailUpload) {
            if (id == NotificationCenter.didSetTwoStepPassword) {
                if (args != null && args.length > 0) {
                    if (args[7] != null) {
                        EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
                        if (editTextBoldCursorArr[0] != null) {
                            editTextBoldCursorArr[0].setText((String) args[7]);
                        }
                    }
                    if (args[6] == null) {
                        TLRPC.TL_account_password tL_account_password = new TLRPC.TL_account_password();
                        this.currentPassword = tL_account_password;
                        tL_account_password.current_algo = (TLRPC.PasswordKdfAlgo) args[1];
                        this.currentPassword.new_secure_algo = (TLRPC.SecurePasswordKdfAlgo) args[2];
                        this.currentPassword.secure_random = (byte[]) args[3];
                        this.currentPassword.has_recovery = !TextUtils.isEmpty((String) args[4]);
                        this.currentPassword.hint = (String) args[5];
                        this.currentPassword.srp_id = -1L;
                        this.currentPassword.srp_B = new byte[256];
                        Utilities.random.nextBytes(this.currentPassword.srp_B);
                        EditTextBoldCursor[] editTextBoldCursorArr2 = this.inputFields;
                        if (editTextBoldCursorArr2[0] != null && editTextBoldCursorArr2[0].length() > 0) {
                            this.usingSavedPassword = 2;
                        }
                    }
                } else {
                    this.currentPassword = null;
                    loadPasswordInfo();
                }
                updatePasswordInterface();
                return;
            }
            int i = NotificationCenter.didRemoveTwoStepPassword;
        }
    }

    @Override
    public void onTransitionAnimationEnd(boolean isOpen, boolean backward) {
        if (this.presentAfterAnimation != null) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.this.lambda$onTransitionAnimationEnd$68$PassportActivity();
                }
            });
        }
        int i = this.currentActivityType;
        if (i == 5) {
            if (isOpen) {
                if (this.inputFieldContainers[0].getVisibility() == 0) {
                    this.inputFields[0].requestFocus();
                    AndroidUtilities.showKeyboard(this.inputFields[0]);
                }
                if (this.usingSavedPassword == 2) {
                    onPasswordDone(false);
                    return;
                }
                return;
            }
            return;
        }
        if (i == 7) {
            if (isOpen) {
                this.views[this.currentViewNum].onShow();
                return;
            }
            return;
        }
        if (i == 4) {
            if (isOpen) {
                this.inputFields[0].requestFocus();
                AndroidUtilities.showKeyboard(this.inputFields[0]);
                return;
            }
            return;
        }
        if (i == 6) {
            if (isOpen) {
                this.inputFields[0].requestFocus();
                AndroidUtilities.showKeyboard(this.inputFields[0]);
                return;
            }
            return;
        }
        if ((i == 2 || i == 1) && Build.VERSION.SDK_INT >= 21) {
            createChatAttachView();
        }
    }

    public void lambda$onTransitionAnimationEnd$68$PassportActivity() {
        presentFragment(this.presentAfterAnimation, true);
        this.presentAfterAnimation = null;
    }

    private void showAttachmentError() {
        if (getParentActivity() == null) {
            return;
        }
        ToastUtils.show(R.string.UnsupportedAttachment);
    }

    @Override
    public void onActivityResultFragment(int requestCode, int resultCode, Intent data) {
        if (resultCode == -1) {
            if (requestCode == 0 || requestCode == 2) {
                createChatAttachView();
                ChatAttachAlert chatAttachAlert = this.chatAttachAlert;
                if (chatAttachAlert != null) {
                    chatAttachAlert.onActivityResultFragment(requestCode, data, this.currentPicturePath);
                }
                this.currentPicturePath = null;
                return;
            }
            if (requestCode == 1) {
                if (data == null || data.getData() == null) {
                    showAttachmentError();
                    return;
                }
                ArrayList<SendMessagesHelper.SendingMediaInfo> photos = new ArrayList<>();
                SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                info.uri = data.getData();
                photos.add(info);
                processSelectedFiles(photos);
            }
        }
    }

    @Override
    public void onRequestPermissionsResultFragment(int requestCode, String[] permissions, int[] grantResults) {
        ChatAttachAlert chatAttachAlert;
        TextSettingsCell textSettingsCell;
        int i = this.currentActivityType;
        if ((i == 1 || i == 2) && (chatAttachAlert = this.chatAttachAlert) != null) {
            if (requestCode == 17 && chatAttachAlert != null) {
                chatAttachAlert.checkCamera(false);
                return;
            }
            if (requestCode == 21) {
                if (getParentActivity() != null && grantResults != null && grantResults.length != 0 && grantResults[0] != 0) {
                    AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
                    builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                    builder.setMessage(LocaleController.getString("PermissionNoAudioVideo", R.string.PermissionNoAudioVideo));
                    builder.setNegativeButton(LocaleController.getString("PermissionOpenSettings", R.string.PermissionOpenSettings), new DialogInterface.OnClickListener() {
                        @Override
                        public final void onClick(DialogInterface dialogInterface, int i2) {
                            PassportActivity.this.lambda$onRequestPermissionsResultFragment$69$PassportActivity(dialogInterface, i2);
                        }
                    });
                    builder.setPositiveButton(LocaleController.getString("OK", R.string.OK), null);
                    builder.show();
                    return;
                }
                return;
            }
            if (requestCode == 19 && grantResults != null && grantResults.length > 0 && grantResults[0] == 0) {
                processSelectedAttach(0);
                return;
            }
            if (requestCode == 22 && grantResults != null && grantResults.length > 0 && grantResults[0] == 0 && (textSettingsCell = this.scanDocumentCell) != null) {
                textSettingsCell.callOnClick();
                return;
            }
            return;
        }
        if (this.currentActivityType == 3 && requestCode == 6) {
            startPhoneVerification(false, this.pendingPhone, this.pendingFinishRunnable, this.pendingErrorRunnable, this.pendingDelegate);
        }
    }

    public void lambda$onRequestPermissionsResultFragment$69$PassportActivity(DialogInterface dialog, int which) {
        try {
            Intent intent = new Intent("android.settings.APPLICATION_DETAILS_SETTINGS");
            intent.setData(Uri.parse("package:" + ApplicationLoader.applicationContext.getPackageName()));
            getParentActivity().startActivity(intent);
        } catch (Exception e) {
            FileLog.e(e);
        }
    }

    @Override
    public void saveSelfArgs(Bundle args) {
        String str = this.currentPicturePath;
        if (str != null) {
            args.putString("path", str);
        }
    }

    @Override
    public void restoreSelfArgs(Bundle args) {
        this.currentPicturePath = args.getString("path");
    }

    @Override
    public boolean onBackPressed() {
        int i = this.currentActivityType;
        if (i == 7) {
            this.views[this.currentViewNum].onBackPressed(true);
            int a = 0;
            while (true) {
                SlideView[] slideViewArr = this.views;
                if (a >= slideViewArr.length) {
                    break;
                }
                if (slideViewArr[a] != null) {
                    slideViewArr[a].onDestroyActivity();
                }
                a++;
            }
        } else if (i == 0 || i == 5) {
            callCallback(false);
        } else if (i == 1 || i == 2) {
            return !checkDiscard();
        }
        return true;
    }

    @Override
    public void onDialogDismiss(Dialog dialog) {
        if (this.currentActivityType == 3 && Build.VERSION.SDK_INT >= 23 && dialog == this.permissionsDialog && !this.permissionsItems.isEmpty()) {
            getParentActivity().requestPermissions((String[]) this.permissionsItems.toArray(new String[0]), 6);
        }
    }

    public void needShowProgress() {
        if (getParentActivity() == null || getParentActivity().isFinishing() || this.progressDialog != null) {
            return;
        }
        AlertDialog alertDialog = new AlertDialog(getParentActivity(), 3);
        this.progressDialog = alertDialog;
        alertDialog.setCanCancel(false);
        this.progressDialog.show();
    }

    public void needHideProgress() {
        AlertDialog alertDialog = this.progressDialog;
        if (alertDialog == null) {
            return;
        }
        try {
            alertDialog.dismiss();
        } catch (Exception e) {
            FileLog.e(e);
        }
        this.progressDialog = null;
    }

    public void setPage(int page, boolean animated, Bundle params) {
        if (page == 3) {
            this.doneItem.setVisibility(8);
        }
        SlideView[] slideViewArr = this.views;
        final SlideView outView = slideViewArr[this.currentViewNum];
        final SlideView newView = slideViewArr[page];
        this.currentViewNum = page;
        newView.setParams(params, false);
        newView.onShow();
        if (animated) {
            newView.setTranslationX(AndroidUtilities.displaySize.x);
            AnimatorSet animatorSet = new AnimatorSet();
            animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
            animatorSet.setDuration(300L);
            animatorSet.playTogether(ObjectAnimator.ofFloat(outView, "translationX", -AndroidUtilities.displaySize.x), ObjectAnimator.ofFloat(newView, "translationX", 0.0f));
            animatorSet.addListener(new AnimatorListenerAdapter() {
                @Override
                public void onAnimationStart(Animator animation) {
                    newView.setVisibility(0);
                }

                @Override
                public void onAnimationEnd(Animator animation) {
                    outView.setVisibility(8);
                    outView.setX(0.0f);
                }
            });
            animatorSet.start();
            return;
        }
        newView.setTranslationX(0.0f);
        newView.setVisibility(0);
        if (outView != newView) {
            outView.setVisibility(8);
        }
    }

    public void fillNextCodeParams(Bundle params, TLRPC.TL_auth_sentCode res, boolean animated) {
        params.putString("phoneHash", res.phone_code_hash);
        if (res.next_type instanceof TLRPC.TL_auth_codeTypeCall) {
            params.putInt("nextType", 4);
        } else if (res.next_type instanceof TLRPC.TL_auth_codeTypeFlashCall) {
            params.putInt("nextType", 3);
        } else if (res.next_type instanceof TLRPC.TL_auth_codeTypeSms) {
            params.putInt("nextType", 2);
        }
        if (res.timeout == 0) {
            res.timeout = 60;
        }
        params.putInt("timeout", res.timeout * 1000);
        if (res.type instanceof TLRPC.TL_auth_sentCodeTypeCall) {
            params.putInt("type", 4);
            params.putInt("length", res.type.length);
            setPage(2, animated, params);
        } else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeFlashCall) {
            params.putInt("type", 3);
            params.putString("pattern", res.type.pattern);
            setPage(1, animated, params);
        } else if (res.type instanceof TLRPC.TL_auth_sentCodeTypeSms) {
            params.putInt("type", 2);
            params.putInt("length", res.type.length);
            setPage(0, animated, params);
        }
    }

    private void openAttachMenu() {
        if (getParentActivity() == null) {
            return;
        }
        if (this.uploadingFileType == 0 && this.documents.size() >= 20) {
            showAlertWithText(LocaleController.getString("AppName", R.string.AppName), LocaleController.formatString("PassportUploadMaxReached", R.string.PassportUploadMaxReached, LocaleController.formatPluralString("Files", 20)));
            return;
        }
        createChatAttachView();
        this.chatAttachAlert.setOpenWithFrontFaceCamera(this.uploadingFileType == 1);
        this.chatAttachAlert.setMaxSelectedPhotos(getMaxSelectedDocuments(), false);
        this.chatAttachAlert.loadGalleryPhotos();
        if (Build.VERSION.SDK_INT == 21 || Build.VERSION.SDK_INT == 22) {
            AndroidUtilities.hideKeyboard(this.fragmentView.findFocus());
        }
        this.chatAttachAlert.init();
        showDialog(this.chatAttachAlert);
    }

    private void createChatAttachView() {
        if (getParentActivity() != null && this.chatAttachAlert == null) {
            ChatAttachAlert chatAttachAlert = new ChatAttachAlert(getParentActivity(), this);
            this.chatAttachAlert = chatAttachAlert;
            chatAttachAlert.setDelegate(new ChatAttachAlert.ChatAttachViewDelegate() {
                @Override
                public void didPressedButton(int button, boolean arg, boolean notify, int scheduleDate) {
                    if (PassportActivity.this.getParentActivity() == null || PassportActivity.this.chatAttachAlert == null) {
                        return;
                    }
                    if (button != 8 && button != 7) {
                        if (PassportActivity.this.chatAttachAlert != null) {
                            PassportActivity.this.chatAttachAlert.dismissWithButtonClick(button);
                        }
                        PassportActivity.this.processSelectedAttach(button);
                        return;
                    }
                    if (button != 8) {
                        PassportActivity.this.chatAttachAlert.dismiss();
                    }
                    HashMap<Object, Object> selectedPhotos = PassportActivity.this.chatAttachAlert.getSelectedPhotos();
                    ArrayList<Object> selectedPhotosOrder = PassportActivity.this.chatAttachAlert.getSelectedPhotosOrder();
                    if (!selectedPhotos.isEmpty()) {
                        ArrayList<SendMessagesHelper.SendingMediaInfo> photos = new ArrayList<>();
                        for (int a = 0; a < selectedPhotosOrder.size(); a++) {
                            MediaController.PhotoEntry photoEntry = (MediaController.PhotoEntry) selectedPhotos.get(selectedPhotosOrder.get(a));
                            SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                            if (photoEntry.imagePath != null) {
                                info.path = photoEntry.imagePath;
                            } else if (photoEntry.path != null) {
                                info.path = photoEntry.path;
                            }
                            photos.add(info);
                            photoEntry.reset();
                        }
                        PassportActivity.this.processSelectedFiles(photos);
                    }
                }

                @Override
                public View getRevealView() {
                    return null;
                }

                @Override
                public void didSelectBot(TLRPC.User user) {
                }

                @Override
                public void onCameraOpened() {
                    AndroidUtilities.hideKeyboard(PassportActivity.this.fragmentView.findFocus());
                }

                @Override
                public void needEnterComment() {
                }
            });
        }
    }

    private int getMaxSelectedDocuments() {
        int i = this.uploadingFileType;
        if (i == 0) {
            return 20 - this.documents.size();
        }
        if (i == 4) {
            return 20 - this.translationDocuments.size();
        }
        return 1;
    }

    public void processSelectedAttach(int which) {
        if (which == 0) {
            if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission("android.permission.CAMERA") != 0) {
                getParentActivity().requestPermissions(new String[]{"android.permission.CAMERA"}, 19);
                return;
            }
            try {
                Intent takePictureIntent = new Intent("android.media.action.IMAGE_CAPTURE");
                File image = AndroidUtilities.generatePicturePath();
                if (image != null) {
                    if (Build.VERSION.SDK_INT >= 24) {
                        takePictureIntent.putExtra("output", FileProvider.getUriForFile(getParentActivity(), "im.giitqbkwzt.messenger.provider", image));
                        takePictureIntent.addFlags(2);
                        takePictureIntent.addFlags(1);
                    } else {
                        takePictureIntent.putExtra("output", Uri.fromFile(image));
                    }
                    this.currentPicturePath = image.getAbsolutePath();
                }
                startActivityForResult(takePictureIntent, 0);
                return;
            } catch (Exception e) {
                FileLog.e(e);
                return;
            }
        }
        if (which == 1) {
            if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(PermissionUtils.PERMISSION_READ_EXTERNAL_STORAGE) != 0) {
                getParentActivity().requestPermissions(new String[]{PermissionUtils.PERMISSION_READ_EXTERNAL_STORAGE}, 4);
                return;
            }
            PhotoAlbumPickerActivity fragment = new PhotoAlbumPickerActivity(0, false, false, null);
            fragment.setCurrentAccount(this.currentAccount);
            fragment.setMaxSelectedPhotos(getMaxSelectedDocuments(), false);
            fragment.setAllowSearchImages(false);
            fragment.setDelegate(new PhotoAlbumPickerActivity.PhotoAlbumPickerActivityDelegate() {
                @Override
                public void didSelectPhotos(ArrayList<SendMessagesHelper.SendingMediaInfo> photos, boolean notify, int scheduleDate, boolean blnOriginalImg) {
                    PassportActivity.this.processSelectedFiles(photos);
                }

                @Override
                public void startPhotoSelectActivity() {
                    try {
                        Intent photoPickerIntent = new Intent("android.intent.action.PICK");
                        photoPickerIntent.setType("image/*");
                        PassportActivity.this.startActivityForResult(photoPickerIntent, 1);
                    } catch (Exception e2) {
                        FileLog.e(e2);
                    }
                }
            });
            presentFragment(fragment);
            return;
        }
        if (which == 4) {
            if (Build.VERSION.SDK_INT >= 23 && getParentActivity().checkSelfPermission(PermissionUtils.PERMISSION_READ_EXTERNAL_STORAGE) != 0) {
                getParentActivity().requestPermissions(new String[]{PermissionUtils.PERMISSION_READ_EXTERNAL_STORAGE}, 4);
                return;
            }
            DocumentSelectActivity fragment2 = new DocumentSelectActivity(false);
            fragment2.setCurrentAccount(this.currentAccount);
            fragment2.setCanSelectOnlyImageFiles(true);
            fragment2.setMaxSelectedFiles(getMaxSelectedDocuments());
            fragment2.setDelegate(new DocumentSelectActivity.DocumentSelectActivityDelegate() {
                @Override
                public void startMusicSelectActivity(BaseFragment baseFragment) {
                    DocumentSelectActivity.DocumentSelectActivityDelegate.CC.$default$startMusicSelectActivity(this, baseFragment);
                }

                @Override
                public void didSelectFiles(DocumentSelectActivity activity, ArrayList<String> files, boolean notify, int scheduleDate) {
                    activity.finishFragment();
                    ArrayList<SendMessagesHelper.SendingMediaInfo> arrayList = new ArrayList<>();
                    int count = files.size();
                    for (int a = 0; a < count; a++) {
                        SendMessagesHelper.SendingMediaInfo info = new SendMessagesHelper.SendingMediaInfo();
                        info.path = files.get(a);
                        arrayList.add(info);
                    }
                    PassportActivity.this.processSelectedFiles(arrayList);
                }

                @Override
                public void startDocumentSelectActivity() {
                    try {
                        Intent photoPickerIntent = new Intent("android.intent.action.GET_CONTENT");
                        if (Build.VERSION.SDK_INT >= 18) {
                            photoPickerIntent.putExtra("android.intent.extra.ALLOW_MULTIPLE", true);
                        }
                        photoPickerIntent.setType("*/*");
                        PassportActivity.this.startActivityForResult(photoPickerIntent, 21);
                    } catch (Exception e2) {
                        FileLog.e(e2);
                    }
                }
            });
            presentFragment(fragment2);
        }
    }

    private void fillInitialValues() {
        if (this.initialValues != null) {
            return;
        }
        this.initialValues = getCurrentValues();
    }

    private String getCurrentValues() {
        StringBuilder values = new StringBuilder();
        int a = 0;
        while (true) {
            EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
            if (a >= editTextBoldCursorArr.length) {
                break;
            }
            values.append((CharSequence) editTextBoldCursorArr[a].getText());
            values.append(",");
            a++;
        }
        if (this.inputExtraFields != null) {
            int a2 = 0;
            while (true) {
                EditTextBoldCursor[] editTextBoldCursorArr2 = this.inputExtraFields;
                if (a2 >= editTextBoldCursorArr2.length) {
                    break;
                }
                values.append((CharSequence) editTextBoldCursorArr2[a2].getText());
                values.append(",");
                a2++;
            }
        }
        int count = this.documents.size();
        for (int a3 = 0; a3 < count; a3++) {
            values.append(this.documents.get(a3).secureFile.id);
        }
        SecureDocument secureDocument = this.frontDocument;
        if (secureDocument != null) {
            values.append(secureDocument.secureFile.id);
        }
        SecureDocument secureDocument2 = this.reverseDocument;
        if (secureDocument2 != null) {
            values.append(secureDocument2.secureFile.id);
        }
        SecureDocument secureDocument3 = this.selfieDocument;
        if (secureDocument3 != null) {
            values.append(secureDocument3.secureFile.id);
        }
        int count2 = this.translationDocuments.size();
        for (int a4 = 0; a4 < count2; a4++) {
            values.append(this.translationDocuments.get(a4).secureFile.id);
        }
        return values.toString();
    }

    public boolean isHasNotAnyChanges() {
        String str = this.initialValues;
        return str == null || str.equals(getCurrentValues());
    }

    public boolean checkDiscard() {
        if (isHasNotAnyChanges()) {
            return false;
        }
        AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
        builder.setPositiveButton(LocaleController.getString("PassportDiscard", R.string.PassportDiscard), new DialogInterface.OnClickListener() {
            @Override
            public final void onClick(DialogInterface dialogInterface, int i) {
                PassportActivity.this.lambda$checkDiscard$70$PassportActivity(dialogInterface, i);
            }
        });
        builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
        builder.setTitle(LocaleController.getString("DiscardChanges", R.string.DiscardChanges));
        builder.setMessage(LocaleController.getString("PassportDiscardChanges", R.string.PassportDiscardChanges));
        showDialog(builder.create());
        return true;
    }

    public void lambda$checkDiscard$70$PassportActivity(DialogInterface dialog, int which) {
        finishFragment();
    }

    public void processSelectedFiles(final ArrayList<SendMessagesHelper.SendingMediaInfo> photos) {
        final boolean allFieldsAreEmpty;
        if (photos.isEmpty()) {
            return;
        }
        int i = this.uploadingFileType;
        if (i == 1 || i == 4) {
            allFieldsAreEmpty = false;
        } else if (this.currentType.type instanceof TLRPC.TL_secureValueTypePersonalDetails) {
            allFieldsAreEmpty = true;
            int a = 0;
            while (true) {
                EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
                if (a < editTextBoldCursorArr.length) {
                    if (a == 5 || a == 8 || a == 4 || a == 6 || editTextBoldCursorArr[a].length() <= 0) {
                        a++;
                    } else {
                        allFieldsAreEmpty = false;
                        break;
                    }
                } else {
                    break;
                }
            }
        } else {
            allFieldsAreEmpty = false;
        }
        final int type = this.uploadingFileType;
        Utilities.globalQueue.postRunnable(new Runnable() {
            @Override
            public final void run() {
                PassportActivity.this.lambda$processSelectedFiles$73$PassportActivity(photos, type, allFieldsAreEmpty);
            }
        });
    }

    public void lambda$processSelectedFiles$73$PassportActivity(ArrayList photos, final int type, boolean needRecoginze) {
        TLRPC.PhotoSize size;
        int i = this.uploadingFileType;
        int count = Math.min((i == 0 || i == 4) ? 20 : 1, photos.size());
        int a = 0;
        for (int a2 = 0; a2 < count; a2++) {
            SendMessagesHelper.SendingMediaInfo info = (SendMessagesHelper.SendingMediaInfo) photos.get(a2);
            Bitmap bitmap = ImageLoader.loadBitmap(info.path, info.uri, 2048.0f, 2048.0f, false);
            if (bitmap != null && (size = ImageLoader.scaleAndSaveImage(bitmap, 2048.0f, 2048.0f, 89, false, 320, 320)) != null) {
                TLRPC.TL_secureFile secureFile = new TLRPC.TL_secureFile();
                secureFile.dc_id = (int) size.location.volume_id;
                secureFile.id = size.location.local_id;
                secureFile.date = (int) (System.currentTimeMillis() / 1000);
                final SecureDocument document = this.delegate.saveFile(secureFile);
                document.type = type;
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PassportActivity.this.lambda$null$71$PassportActivity(document, type);
                    }
                });
                if (needRecoginze && a == 0) {
                    try {
                        final MrzRecognizer.Result result = MrzRecognizer.recognize(bitmap, this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense);
                        if (result != null) {
                            a = 1;
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public final void run() {
                                    PassportActivity.this.lambda$null$72$PassportActivity(result);
                                }
                            });
                        }
                    } catch (Throwable e) {
                        FileLog.e(e);
                    }
                }
            }
        }
        SharedConfig.saveConfig();
    }

    public void lambda$null$71$PassportActivity(SecureDocument document, int type) {
        int i = this.uploadingFileType;
        if (i == 1) {
            SecureDocument secureDocument = this.selfieDocument;
            if (secureDocument != null) {
                SecureDocumentCell cell = this.documentsCells.remove(secureDocument);
                if (cell != null) {
                    this.selfieLayout.removeView(cell);
                }
                this.selfieDocument = null;
            }
        } else if (i == 4) {
            if (this.translationDocuments.size() >= 20) {
                return;
            }
        } else if (i == 2) {
            SecureDocument secureDocument2 = this.frontDocument;
            if (secureDocument2 != null) {
                SecureDocumentCell cell2 = this.documentsCells.remove(secureDocument2);
                if (cell2 != null) {
                    this.frontLayout.removeView(cell2);
                }
                this.frontDocument = null;
            }
        } else if (i == 3) {
            SecureDocument secureDocument3 = this.reverseDocument;
            if (secureDocument3 != null) {
                SecureDocumentCell cell3 = this.documentsCells.remove(secureDocument3);
                if (cell3 != null) {
                    this.reverseLayout.removeView(cell3);
                }
                this.reverseDocument = null;
            }
        } else if (i == 0 && this.documents.size() >= 20) {
            return;
        }
        this.uploadingDocuments.put(document.path, document);
        this.doneItem.setEnabled(false);
        this.doneItem.setAlpha(0.5f);
        FileLoader.getInstance(this.currentAccount).uploadFile(document.path, false, true, 16777216);
        addDocumentView(document, type);
        updateUploadText(type);
    }

    public void lambda$null$72$PassportActivity(MrzRecognizer.Result result) {
        if (result.type == 2) {
            if (!(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeIdentityCard)) {
                int a1 = 0;
                int count1 = this.availableDocumentTypes.size();
                while (true) {
                    if (a1 >= count1) {
                        break;
                    }
                    TLRPC.TL_secureRequiredType requiredType = this.availableDocumentTypes.get(a1);
                    if (!(requiredType.type instanceof TLRPC.TL_secureValueTypeIdentityCard)) {
                        a1++;
                    } else {
                        this.currentDocumentsType = requiredType;
                        updateInterfaceStringsForDocumentType();
                        break;
                    }
                }
            }
        } else if (result.type == 1) {
            if (!(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypePassport)) {
                int a12 = 0;
                int count12 = this.availableDocumentTypes.size();
                while (true) {
                    if (a12 >= count12) {
                        break;
                    }
                    TLRPC.TL_secureRequiredType requiredType2 = this.availableDocumentTypes.get(a12);
                    if (!(requiredType2.type instanceof TLRPC.TL_secureValueTypePassport)) {
                        a12++;
                    } else {
                        this.currentDocumentsType = requiredType2;
                        updateInterfaceStringsForDocumentType();
                        break;
                    }
                }
            }
        } else if (result.type == 3) {
            if (!(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeInternalPassport)) {
                int a13 = 0;
                int count13 = this.availableDocumentTypes.size();
                while (true) {
                    if (a13 >= count13) {
                        break;
                    }
                    TLRPC.TL_secureRequiredType requiredType3 = this.availableDocumentTypes.get(a13);
                    if (!(requiredType3.type instanceof TLRPC.TL_secureValueTypeInternalPassport)) {
                        a13++;
                    } else {
                        this.currentDocumentsType = requiredType3;
                        updateInterfaceStringsForDocumentType();
                        break;
                    }
                }
            }
        } else if (result.type == 4 && !(this.currentDocumentsType.type instanceof TLRPC.TL_secureValueTypeDriverLicense)) {
            int a14 = 0;
            int count14 = this.availableDocumentTypes.size();
            while (true) {
                if (a14 >= count14) {
                    break;
                }
                TLRPC.TL_secureRequiredType requiredType4 = this.availableDocumentTypes.get(a14);
                if (!(requiredType4.type instanceof TLRPC.TL_secureValueTypeDriverLicense)) {
                    a14++;
                } else {
                    this.currentDocumentsType = requiredType4;
                    updateInterfaceStringsForDocumentType();
                    break;
                }
            }
        }
        if (!TextUtils.isEmpty(result.firstName)) {
            this.inputFields[0].setText(result.firstName);
        }
        if (!TextUtils.isEmpty(result.middleName)) {
            this.inputFields[1].setText(result.middleName);
        }
        if (!TextUtils.isEmpty(result.lastName)) {
            this.inputFields[2].setText(result.lastName);
        }
        if (!TextUtils.isEmpty(result.number)) {
            this.inputFields[7].setText(result.number);
        }
        if (result.gender != 0) {
            int i = result.gender;
            if (i == 1) {
                this.currentGender = "male";
                this.inputFields[4].setText(LocaleController.getString("PassportMale", R.string.PassportMale));
            } else if (i == 2) {
                this.currentGender = "female";
                this.inputFields[4].setText(LocaleController.getString("PassportFemale", R.string.PassportFemale));
            }
        }
        if (!TextUtils.isEmpty(result.nationality)) {
            String str = result.nationality;
            this.currentCitizeship = str;
            String country = this.languageMap.get(str);
            if (country != null) {
                this.inputFields[5].setText(country);
            }
        }
        if (!TextUtils.isEmpty(result.issuingCountry)) {
            String str2 = result.issuingCountry;
            this.currentResidence = str2;
            String country2 = this.languageMap.get(str2);
            if (country2 != null) {
                this.inputFields[6].setText(country2);
            }
        }
        if (result.birthDay > 0 && result.birthMonth > 0 && result.birthYear > 0) {
            this.inputFields[3].setText(String.format(Locale.US, "%02d.%02d.%d", Integer.valueOf(result.birthDay), Integer.valueOf(result.birthMonth), Integer.valueOf(result.birthYear)));
        }
        if (result.expiryDay > 0 && result.expiryMonth > 0 && result.expiryYear > 0) {
            this.currentExpireDate[0] = result.expiryYear;
            this.currentExpireDate[1] = result.expiryMonth;
            this.currentExpireDate[2] = result.expiryDay;
            this.inputFields[8].setText(String.format(Locale.US, "%02d.%02d.%d", Integer.valueOf(result.expiryDay), Integer.valueOf(result.expiryMonth), Integer.valueOf(result.expiryYear)));
            return;
        }
        int[] iArr = this.currentExpireDate;
        iArr[2] = 0;
        iArr[1] = 0;
        iArr[0] = 0;
        this.inputFields[8].setText(LocaleController.getString("PassportNoExpireDate", R.string.PassportNoExpireDate));
    }

    public void setNeedActivityResult(boolean needActivityResult) {
        this.needActivityResult = needActivityResult;
    }

    private class ProgressView extends View {
        private Paint paint;
        private Paint paint2;
        private float progress;

        public ProgressView(Context context) {
            super(context);
            this.paint = new Paint();
            this.paint2 = new Paint();
            this.paint.setColor(Theme.getColor(Theme.key_login_progressInner));
            this.paint2.setColor(Theme.getColor(Theme.key_login_progressOuter));
        }

        public void setProgress(float value) {
            this.progress = value;
            invalidate();
        }

        @Override
        protected void onDraw(Canvas canvas) {
            int start = (int) (getMeasuredWidth() * this.progress);
            canvas.drawRect(0.0f, 0.0f, start, getMeasuredHeight(), this.paint2);
            canvas.drawRect(start, 0.0f, getMeasuredWidth(), getMeasuredHeight(), this.paint);
        }
    }

    public class PhoneConfirmationView extends SlideView implements NotificationCenter.NotificationCenterDelegate {
        private ImageView blackImageView;
        private ImageView blueImageView;
        private EditTextBoldCursor[] codeField;
        private LinearLayout codeFieldContainer;
        private int codeTime;
        private Timer codeTimer;
        private TextView confirmTextView;
        private Bundle currentParams;
        private boolean ignoreOnTextChange;
        private double lastCodeTime;
        private double lastCurrentTime;
        private String lastError;
        private int length;
        private boolean nextPressed;
        private int nextType;
        private int openTime;
        private String pattern;
        private String phone;
        private String phoneHash;
        private TextView problemText;
        private ProgressView progressView;
        private int time;
        private TextView timeText;
        private Timer timeTimer;
        private int timeout;
        private final Object timerSync;
        private TextView titleTextView;
        private int verificationType;
        private boolean waitingForEvent;

        public PhoneConfirmationView(Context context, int type) {
            super(context);
            this.timerSync = new Object();
            this.time = TimeConstants.MIN;
            this.codeTime = 15000;
            this.lastError = "";
            this.pattern = "*";
            this.verificationType = type;
            setOrientation(1);
            TextView textView = new TextView(context);
            this.confirmTextView = textView;
            textView.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
            this.confirmTextView.setTextSize(1, 14.0f);
            this.confirmTextView.setLineSpacing(AndroidUtilities.dp(2.0f), 1.0f);
            TextView textView2 = new TextView(context);
            this.titleTextView = textView2;
            textView2.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
            this.titleTextView.setTextSize(1, 18.0f);
            this.titleTextView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
            this.titleTextView.setGravity(LocaleController.isRTL ? 5 : 3);
            this.titleTextView.setLineSpacing(AndroidUtilities.dp(2.0f), 1.0f);
            this.titleTextView.setGravity(49);
            if (this.verificationType == 3) {
                this.confirmTextView.setGravity((LocaleController.isRTL ? 5 : 3) | 48);
                FrameLayout frameLayout = new FrameLayout(context);
                addView(frameLayout, LayoutHelper.createLinear(-2, -2, LocaleController.isRTL ? 5 : 3));
                ImageView imageView = new ImageView(context);
                imageView.setImageResource(R.drawable.phone_activate);
                if (LocaleController.isRTL) {
                    frameLayout.addView(imageView, LayoutHelper.createFrame(64.0f, 76.0f, 19, 2.0f, 2.0f, 0.0f, 0.0f));
                    frameLayout.addView(this.confirmTextView, LayoutHelper.createFrame(-1.0f, -2.0f, LocaleController.isRTL ? 5 : 3, 82.0f, 0.0f, 0.0f, 0.0f));
                } else {
                    frameLayout.addView(this.confirmTextView, LayoutHelper.createFrame(-1.0f, -2.0f, LocaleController.isRTL ? 5 : 3, 0.0f, 0.0f, 82.0f, 0.0f));
                    frameLayout.addView(imageView, LayoutHelper.createFrame(64.0f, 76.0f, 21, 0.0f, 2.0f, 0.0f, 2.0f));
                }
            } else {
                this.confirmTextView.setGravity(49);
                FrameLayout frameLayout2 = new FrameLayout(context);
                addView(frameLayout2, LayoutHelper.createLinear(-2, -2, 49));
                if (this.verificationType == 1) {
                    ImageView imageView2 = new ImageView(context);
                    this.blackImageView = imageView2;
                    imageView2.setImageResource(R.drawable.sms_devices);
                    this.blackImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText), PorterDuff.Mode.MULTIPLY));
                    frameLayout2.addView(this.blackImageView, LayoutHelper.createFrame(-2.0f, -2.0f, 51, 0.0f, 0.0f, 0.0f, 0.0f));
                    ImageView imageView3 = new ImageView(context);
                    this.blueImageView = imageView3;
                    imageView3.setImageResource(R.drawable.sms_bubble);
                    this.blueImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionBackground), PorterDuff.Mode.MULTIPLY));
                    frameLayout2.addView(this.blueImageView, LayoutHelper.createFrame(-2.0f, -2.0f, 51, 0.0f, 0.0f, 0.0f, 0.0f));
                    this.titleTextView.setText(LocaleController.getString("SentAppCodeTitle", R.string.SentAppCodeTitle));
                } else {
                    ImageView imageView4 = new ImageView(context);
                    this.blueImageView = imageView4;
                    imageView4.setImageResource(R.drawable.sms_code);
                    this.blueImageView.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_chats_actionBackground), PorterDuff.Mode.MULTIPLY));
                    frameLayout2.addView(this.blueImageView, LayoutHelper.createFrame(-2.0f, -2.0f, 51, 0.0f, 0.0f, 0.0f, 0.0f));
                    this.titleTextView.setText(LocaleController.getString("SentSmsCodeTitle", R.string.SentSmsCodeTitle));
                }
                addView(this.titleTextView, LayoutHelper.createLinear(-2, -2, 49, 0, 18, 0, 0));
                addView(this.confirmTextView, LayoutHelper.createLinear(-2, -2, 49, 0, 17, 0, 0));
            }
            LinearLayout linearLayout = new LinearLayout(context);
            this.codeFieldContainer = linearLayout;
            linearLayout.setOrientation(0);
            addView(this.codeFieldContainer, LayoutHelper.createLinear(-2, 36, 1));
            if (this.verificationType == 3) {
                this.codeFieldContainer.setVisibility(8);
            }
            TextView textView3 = new TextView(context) {
                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100.0f), Integer.MIN_VALUE));
                }
            };
            this.timeText = textView3;
            textView3.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteGrayText6));
            this.timeText.setLineSpacing(AndroidUtilities.dp(2.0f), 1.0f);
            if (this.verificationType == 3) {
                this.timeText.setTextSize(1, 14.0f);
                addView(this.timeText, LayoutHelper.createLinear(-2, -2, LocaleController.isRTL ? 5 : 3));
                this.progressView = new ProgressView(context);
                this.timeText.setGravity(LocaleController.isRTL ? 5 : 3);
                addView(this.progressView, LayoutHelper.createLinear(-1, 3, 0.0f, 12.0f, 0.0f, 0.0f));
            } else {
                this.timeText.setPadding(0, AndroidUtilities.dp(2.0f), 0, AndroidUtilities.dp(10.0f));
                this.timeText.setTextSize(1, 15.0f);
                this.timeText.setGravity(49);
                addView(this.timeText, LayoutHelper.createLinear(-2, -2, 49));
            }
            TextView textView4 = new TextView(context) {
                @Override
                protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
                    super.onMeasure(widthMeasureSpec, View.MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(100.0f), Integer.MIN_VALUE));
                }
            };
            this.problemText = textView4;
            textView4.setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlueText4));
            this.problemText.setLineSpacing(AndroidUtilities.dp(2.0f), 1.0f);
            this.problemText.setPadding(0, AndroidUtilities.dp(2.0f), 0, AndroidUtilities.dp(10.0f));
            this.problemText.setTextSize(1, 15.0f);
            this.problemText.setGravity(49);
            if (this.verificationType == 1) {
                this.problemText.setText(LocaleController.getString("DidNotGetTheCodeSms", R.string.DidNotGetTheCodeSms));
            } else {
                this.problemText.setText(LocaleController.getString("DidNotGetTheCode", R.string.DidNotGetTheCode));
            }
            addView(this.problemText, LayoutHelper.createLinear(-2, -2, 49));
            this.problemText.setOnClickListener(new View.OnClickListener() {
                @Override
                public final void onClick(View view) {
                    PassportActivity.PhoneConfirmationView.this.lambda$new$0$PassportActivity$PhoneConfirmationView(view);
                }
            });
        }

        public void lambda$new$0$PassportActivity$PhoneConfirmationView(View v) {
            if (this.nextPressed) {
                return;
            }
            boolean email = (this.nextType == 4 && this.verificationType == 2) || this.nextType == 0;
            if (!email) {
                resendCode();
                return;
            }
            try {
                PackageInfo pInfo = ApplicationLoader.applicationContext.getPackageManager().getPackageInfo(ApplicationLoader.applicationContext.getPackageName(), 0);
                String version = String.format(Locale.US, "%s (%d)", pInfo.versionName, Integer.valueOf(pInfo.versionCode));
                Intent mailer = new Intent("android.intent.action.SEND");
                mailer.setType("message/rfc822");
                mailer.putExtra("android.intent.extra.EMAIL", new String[]{"sms@stel.com"});
                mailer.putExtra("android.intent.extra.SUBJECT", "Android registration/login issue " + version + " " + this.phone);
                mailer.putExtra("android.intent.extra.TEXT", "Phone: " + this.phone + "\nApp version: " + version + "\nOS version: SDK " + Build.VERSION.SDK_INT + "\nDevice Name: " + Build.MANUFACTURER + Build.MODEL + "\nLocale: " + Locale.getDefault() + "\nError: " + this.lastError);
                getContext().startActivity(Intent.createChooser(mailer, "Send email..."));
            } catch (Exception e) {
                AlertsCreator.showSimpleAlert(PassportActivity.this, LocaleController.getString("NoMailInstalled", R.string.NoMailInstalled));
            }
        }

        @Override
        protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
            ImageView imageView;
            super.onMeasure(widthMeasureSpec, heightMeasureSpec);
            if (this.verificationType != 3 && (imageView = this.blueImageView) != null) {
                int innerHeight = imageView.getMeasuredHeight() + this.titleTextView.getMeasuredHeight() + this.confirmTextView.getMeasuredHeight() + AndroidUtilities.dp(35.0f);
                int requiredHeight = AndroidUtilities.dp(80.0f);
                int maxHeight = AndroidUtilities.dp(291.0f);
                if (PassportActivity.this.scrollHeight - innerHeight >= requiredHeight) {
                    if (PassportActivity.this.scrollHeight <= maxHeight) {
                        setMeasuredDimension(getMeasuredWidth(), PassportActivity.this.scrollHeight);
                        return;
                    } else {
                        setMeasuredDimension(getMeasuredWidth(), maxHeight);
                        return;
                    }
                }
                setMeasuredDimension(getMeasuredWidth(), innerHeight + requiredHeight);
            }
        }

        @Override
        protected void onLayout(boolean changed, int l, int t, int r, int b) {
            int t2;
            super.onLayout(changed, l, t, r, b);
            if (this.verificationType != 3 && this.blueImageView != null) {
                int bottom = this.confirmTextView.getBottom();
                int height = getMeasuredHeight() - bottom;
                if (this.problemText.getVisibility() == 0) {
                    int h = this.problemText.getMeasuredHeight();
                    t2 = (bottom + height) - h;
                    TextView textView = this.problemText;
                    textView.layout(textView.getLeft(), t2, this.problemText.getRight(), t2 + h);
                } else if (this.timeText.getVisibility() == 0) {
                    int h2 = this.timeText.getMeasuredHeight();
                    t2 = (bottom + height) - h2;
                    TextView textView2 = this.timeText;
                    textView2.layout(textView2.getLeft(), t2, this.timeText.getRight(), t2 + h2);
                } else {
                    t2 = bottom + height;
                }
                int h3 = this.codeFieldContainer.getMeasuredHeight();
                int t3 = (((t2 - bottom) - h3) / 2) + bottom;
                LinearLayout linearLayout = this.codeFieldContainer;
                linearLayout.layout(linearLayout.getLeft(), t3, this.codeFieldContainer.getRight(), t3 + h3);
            }
        }

        public void resendCode() {
            final Bundle params = new Bundle();
            params.putString("phone", this.phone);
            this.nextPressed = true;
            PassportActivity.this.needShowProgress();
            final TLRPC.TL_auth_resendCode req = new TLRPC.TL_auth_resendCode();
            req.phone_number = this.phone;
            req.phone_code_hash = this.phoneHash;
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.PhoneConfirmationView.this.lambda$resendCode$3$PassportActivity$PhoneConfirmationView(params, req, tLObject, tL_error);
                }
            }, 2);
        }

        public void lambda$resendCode$3$PassportActivity$PhoneConfirmationView(final Bundle params, final TLRPC.TL_auth_resendCode req, final TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.PhoneConfirmationView.this.lambda$null$2$PassportActivity$PhoneConfirmationView(error, params, response, req);
                }
            });
        }

        public void lambda$null$2$PassportActivity$PhoneConfirmationView(TLRPC.TL_error error, Bundle params, TLObject response, TLRPC.TL_auth_resendCode req) {
            this.nextPressed = false;
            if (error == null) {
                PassportActivity.this.fillNextCodeParams(params, (TLRPC.TL_auth_sentCode) response, true);
            } else {
                AlertDialog dialog = (AlertDialog) AlertsCreator.processError(PassportActivity.this.currentAccount, error, PassportActivity.this, req, new Object[0]);
                if (dialog != null && error.text.contains("PHONE_CODE_EXPIRED")) {
                    dialog.setPositiveButtonListener(new DialogInterface.OnClickListener() {
                        @Override
                        public final void onClick(DialogInterface dialogInterface, int i) {
                            PassportActivity.PhoneConfirmationView.this.lambda$null$1$PassportActivity$PhoneConfirmationView(dialogInterface, i);
                        }
                    });
                }
            }
            PassportActivity.this.needHideProgress();
        }

        public void lambda$null$1$PassportActivity$PhoneConfirmationView(DialogInterface dialog1, int which) {
            onBackPressed(true);
            PassportActivity.this.finishFragment();
        }

        @Override
        public boolean needBackButton() {
            return true;
        }

        @Override
        public void onCancelPressed() {
            this.nextPressed = false;
        }

        @Override
        public void setParams(Bundle params, boolean restore) {
            int i;
            int i2;
            if (params != null) {
                this.waitingForEvent = true;
                int i3 = this.verificationType;
                if (i3 == 2) {
                    AndroidUtilities.setWaitingForSms(true);
                    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveSmsCode);
                } else if (i3 == 3) {
                    AndroidUtilities.setWaitingForCall(true);
                    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveCall);
                }
                this.currentParams = params;
                this.phone = params.getString("phone");
                this.phoneHash = params.getString("phoneHash");
                int i4 = params.getInt("timeout");
                this.time = i4;
                this.timeout = i4;
                this.openTime = (int) (System.currentTimeMillis() / 1000);
                this.nextType = params.getInt("nextType");
                this.pattern = params.getString("pattern");
                int i5 = params.getInt("length");
                this.length = i5;
                if (i5 == 0) {
                    this.length = 5;
                }
                EditTextBoldCursor[] editTextBoldCursorArr = this.codeField;
                int i6 = 8;
                if (editTextBoldCursorArr == null || editTextBoldCursorArr.length != this.length) {
                    int a = this.length;
                    this.codeField = new EditTextBoldCursor[a];
                    int a2 = 0;
                    while (a2 < this.length) {
                        final int num = a2;
                        this.codeField[a2] = new EditTextBoldCursor(getContext());
                        this.codeField[a2].setTextColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                        this.codeField[a2].setCursorColor(Theme.getColor(Theme.key_windowBackgroundWhiteBlackText));
                        this.codeField[a2].setCursorSize(AndroidUtilities.dp(20.0f));
                        this.codeField[a2].setCursorWidth(1.5f);
                        Drawable pressedDrawable = getResources().getDrawable(R.drawable.search_dark_activated).mutate();
                        pressedDrawable.setColorFilter(new PorterDuffColorFilter(Theme.getColor(Theme.key_windowBackgroundWhiteInputFieldActivated), PorterDuff.Mode.MULTIPLY));
                        this.codeField[a2].setBackgroundDrawable(pressedDrawable);
                        this.codeField[a2].setImeOptions(268435461);
                        this.codeField[a2].setTextSize(1, 20.0f);
                        this.codeField[a2].setMaxLines(1);
                        this.codeField[a2].setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
                        this.codeField[a2].setPadding(0, 0, 0, 0);
                        this.codeField[a2].setGravity(49);
                        if (this.verificationType == 3) {
                            this.codeField[a2].setEnabled(false);
                            this.codeField[a2].setInputType(0);
                            this.codeField[a2].setVisibility(i6);
                        } else {
                            this.codeField[a2].setInputType(3);
                        }
                        this.codeFieldContainer.addView(this.codeField[a2], LayoutHelper.createLinear(34, 36, 1, 0, 0, a2 != this.length - 1 ? 7 : 0, 0));
                        this.codeField[a2].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) {
                                int len;
                                if (!PhoneConfirmationView.this.ignoreOnTextChange && (len = s.length()) >= 1) {
                                    if (len > 1) {
                                        String text = s.toString();
                                        PhoneConfirmationView.this.ignoreOnTextChange = true;
                                        for (int a3 = 0; a3 < Math.min(PhoneConfirmationView.this.length - num, len); a3++) {
                                            if (a3 != 0) {
                                                PhoneConfirmationView.this.codeField[num + a3].setText(text.substring(a3, a3 + 1));
                                            } else {
                                                s.replace(0, len, text.substring(a3, a3 + 1));
                                            }
                                        }
                                        PhoneConfirmationView.this.ignoreOnTextChange = false;
                                    }
                                    if (num != PhoneConfirmationView.this.length - 1) {
                                        PhoneConfirmationView.this.codeField[num + 1].setSelection(PhoneConfirmationView.this.codeField[num + 1].length());
                                        PhoneConfirmationView.this.codeField[num + 1].requestFocus();
                                    }
                                    if ((num == PhoneConfirmationView.this.length - 1 || (num == PhoneConfirmationView.this.length - 2 && len >= 2)) && PhoneConfirmationView.this.getCode().length() == PhoneConfirmationView.this.length) {
                                        PhoneConfirmationView.this.onNextPressed();
                                    }
                                }
                            }
                        });
                        this.codeField[a2].setOnKeyListener(new View.OnKeyListener() {
                            @Override
                            public final boolean onKey(View view, int i7, KeyEvent keyEvent) {
                                return PassportActivity.PhoneConfirmationView.this.lambda$setParams$4$PassportActivity$PhoneConfirmationView(num, view, i7, keyEvent);
                            }
                        });
                        this.codeField[a2].setOnEditorActionListener(new TextView.OnEditorActionListener() {
                            @Override
                            public final boolean onEditorAction(TextView textView, int i7, KeyEvent keyEvent) {
                                return PassportActivity.PhoneConfirmationView.this.lambda$setParams$5$PassportActivity$PhoneConfirmationView(textView, i7, keyEvent);
                            }
                        });
                        a2++;
                        i6 = 8;
                    }
                } else {
                    int a3 = 0;
                    while (true) {
                        EditTextBoldCursor[] editTextBoldCursorArr2 = this.codeField;
                        if (a3 >= editTextBoldCursorArr2.length) {
                            break;
                        }
                        editTextBoldCursorArr2[a3].setText("");
                        a3++;
                    }
                }
                ProgressView progressView = this.progressView;
                if (progressView != null) {
                    progressView.setVisibility(this.nextType != 0 ? 0 : 8);
                }
                if (this.phone == null) {
                    return;
                }
                String number = PhoneFormat.getInstance().format(Marker.ANY_NON_NULL_MARKER + this.phone);
                CharSequence str = "";
                int i7 = this.verificationType;
                if (i7 == 2) {
                    str = AndroidUtilities.replaceTags(LocaleController.formatString("SentSmsCode", R.string.SentSmsCode, LocaleController.addNbsp(number)));
                } else if (i7 == 3) {
                    str = AndroidUtilities.replaceTags(LocaleController.formatString("SentCallCode", R.string.SentCallCode, LocaleController.addNbsp(number)));
                } else if (i7 == 4) {
                    str = AndroidUtilities.replaceTags(LocaleController.formatString("SentCallOnly", R.string.SentCallOnly, LocaleController.addNbsp(number)));
                }
                this.confirmTextView.setText(str);
                if (this.verificationType != 3) {
                    AndroidUtilities.showKeyboard(this.codeField[0]);
                    this.codeField[0].requestFocus();
                } else {
                    AndroidUtilities.hideKeyboard(this.codeField[0]);
                }
                destroyTimer();
                destroyCodeTimer();
                this.lastCurrentTime = System.currentTimeMillis();
                if (this.verificationType == 3 && ((i2 = this.nextType) == 4 || i2 == 2)) {
                    this.problemText.setVisibility(8);
                    this.timeText.setVisibility(0);
                    int i8 = this.nextType;
                    if (i8 == 4) {
                        this.timeText.setText(LocaleController.formatString("CallText", R.string.CallText, 1, 0));
                    } else if (i8 == 2) {
                        this.timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, 1, 0));
                    }
                    createTimer();
                    return;
                }
                if (this.verificationType == 2 && ((i = this.nextType) == 4 || i == 3)) {
                    this.timeText.setText(LocaleController.formatString("CallText", R.string.CallText, 2, 0));
                    this.problemText.setVisibility(this.time < 1000 ? 0 : 8);
                    this.timeText.setVisibility(this.time < 1000 ? 8 : 0);
                    createTimer();
                    return;
                }
                if (this.verificationType == 4 && this.nextType == 2) {
                    this.timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, 2, 0));
                    this.problemText.setVisibility(this.time < 1000 ? 0 : 8);
                    this.timeText.setVisibility(this.time < 1000 ? 8 : 0);
                    createTimer();
                    return;
                }
                this.timeText.setVisibility(8);
                this.problemText.setVisibility(8);
                createCodeTimer();
            }
        }

        public boolean lambda$setParams$4$PassportActivity$PhoneConfirmationView(int num, View v, int keyCode, KeyEvent event) {
            if (keyCode == 67 && this.codeField[num].length() == 0 && num > 0) {
                EditTextBoldCursor[] editTextBoldCursorArr = this.codeField;
                editTextBoldCursorArr[num - 1].setSelection(editTextBoldCursorArr[num - 1].length());
                this.codeField[num - 1].requestFocus();
                this.codeField[num - 1].dispatchKeyEvent(event);
                return true;
            }
            return false;
        }

        public boolean lambda$setParams$5$PassportActivity$PhoneConfirmationView(TextView textView, int i, KeyEvent keyEvent) {
            if (i == 5) {
                onNextPressed();
                return true;
            }
            return false;
        }

        public void createCodeTimer() {
            if (this.codeTimer != null) {
                return;
            }
            this.codeTime = 15000;
            this.codeTimer = new Timer();
            this.lastCodeTime = System.currentTimeMillis();
            this.codeTimer.schedule(new AnonymousClass4(), 0L, 1000L);
        }

        public class AnonymousClass4 extends TimerTask {
            AnonymousClass4() {
            }

            @Override
            public void run() {
                AndroidUtilities.runOnUIThread(new Runnable() {
                    @Override
                    public final void run() {
                        PassportActivity.PhoneConfirmationView.AnonymousClass4.this.lambda$run$0$PassportActivity$PhoneConfirmationView$4();
                    }
                });
            }

            public void lambda$run$0$PassportActivity$PhoneConfirmationView$4() {
                double currentTime = System.currentTimeMillis();
                double d = PhoneConfirmationView.this.lastCodeTime;
                Double.isNaN(currentTime);
                double diff = currentTime - d;
                PhoneConfirmationView.this.lastCodeTime = currentTime;
                PhoneConfirmationView phoneConfirmationView = PhoneConfirmationView.this;
                double d2 = phoneConfirmationView.codeTime;
                Double.isNaN(d2);
                phoneConfirmationView.codeTime = (int) (d2 - diff);
                if (PhoneConfirmationView.this.codeTime <= 1000) {
                    PhoneConfirmationView.this.problemText.setVisibility(0);
                    PhoneConfirmationView.this.timeText.setVisibility(8);
                    PhoneConfirmationView.this.destroyCodeTimer();
                }
            }
        }

        public void destroyCodeTimer() {
            try {
                synchronized (this.timerSync) {
                    if (this.codeTimer != null) {
                        this.codeTimer.cancel();
                        this.codeTimer = null;
                    }
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }

        private void createTimer() {
            if (this.timeTimer != null) {
                return;
            }
            Timer timer = new Timer();
            this.timeTimer = timer;
            timer.schedule(new TimerTask() {
                @Override
                public void run() {
                    if (PhoneConfirmationView.this.timeTimer == null) {
                        return;
                    }
                    double currentTime = System.currentTimeMillis();
                    double d = PhoneConfirmationView.this.lastCurrentTime;
                    Double.isNaN(currentTime);
                    double diff = currentTime - d;
                    PhoneConfirmationView phoneConfirmationView = PhoneConfirmationView.this;
                    double d2 = phoneConfirmationView.time;
                    Double.isNaN(d2);
                    phoneConfirmationView.time = (int) (d2 - diff);
                    PhoneConfirmationView.this.lastCurrentTime = currentTime;
                    AndroidUtilities.runOnUIThread(new AnonymousClass1());
                }

                public class AnonymousClass1 implements Runnable {
                    AnonymousClass1() {
                    }

                    @Override
                    public void run() {
                        if (PhoneConfirmationView.this.time >= 1000) {
                            int minutes = (PhoneConfirmationView.this.time / 1000) / 60;
                            int seconds = (PhoneConfirmationView.this.time / 1000) - (minutes * 60);
                            if (PhoneConfirmationView.this.nextType == 4 || PhoneConfirmationView.this.nextType == 3) {
                                PhoneConfirmationView.this.timeText.setText(LocaleController.formatString("CallText", R.string.CallText, Integer.valueOf(minutes), Integer.valueOf(seconds)));
                            } else if (PhoneConfirmationView.this.nextType == 2) {
                                PhoneConfirmationView.this.timeText.setText(LocaleController.formatString("SmsText", R.string.SmsText, Integer.valueOf(minutes), Integer.valueOf(seconds)));
                            }
                            if (PhoneConfirmationView.this.progressView != null) {
                                PhoneConfirmationView.this.progressView.setProgress(1.0f - (PhoneConfirmationView.this.time / PhoneConfirmationView.this.timeout));
                                return;
                            }
                            return;
                        }
                        if (PhoneConfirmationView.this.progressView != null) {
                            PhoneConfirmationView.this.progressView.setProgress(1.0f);
                        }
                        PhoneConfirmationView.this.destroyTimer();
                        if (PhoneConfirmationView.this.verificationType != 3) {
                            if (PhoneConfirmationView.this.verificationType == 2 || PhoneConfirmationView.this.verificationType == 4) {
                                if (PhoneConfirmationView.this.nextType == 4 || PhoneConfirmationView.this.nextType == 2) {
                                    if (PhoneConfirmationView.this.nextType == 4) {
                                        PhoneConfirmationView.this.timeText.setText(LocaleController.getString("Calling", R.string.Calling));
                                    } else {
                                        PhoneConfirmationView.this.timeText.setText(LocaleController.getString("SendingSms", R.string.SendingSms));
                                    }
                                    PhoneConfirmationView.this.createCodeTimer();
                                    TLRPC.TL_auth_resendCode req = new TLRPC.TL_auth_resendCode();
                                    req.phone_number = PhoneConfirmationView.this.phone;
                                    req.phone_code_hash = PhoneConfirmationView.this.phoneHash;
                                    ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req, new RequestDelegate() {
                                        @Override
                                        public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                                            PassportActivity.PhoneConfirmationView.AnonymousClass5.AnonymousClass1.this.lambda$run$1$PassportActivity$PhoneConfirmationView$5$1(tLObject, tL_error);
                                        }
                                    }, 2);
                                    return;
                                }
                                if (PhoneConfirmationView.this.nextType == 3) {
                                    AndroidUtilities.setWaitingForSms(false);
                                    NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
                                    PhoneConfirmationView.this.waitingForEvent = false;
                                    PhoneConfirmationView.this.destroyCodeTimer();
                                    PhoneConfirmationView.this.resendCode();
                                    return;
                                }
                                return;
                            }
                            return;
                        }
                        AndroidUtilities.setWaitingForCall(false);
                        NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
                        PhoneConfirmationView.this.waitingForEvent = false;
                        PhoneConfirmationView.this.destroyCodeTimer();
                        PhoneConfirmationView.this.resendCode();
                    }

                    public void lambda$run$1$PassportActivity$PhoneConfirmationView$5$1(TLObject response, final TLRPC.TL_error error) {
                        if (error != null && error.text != null) {
                            AndroidUtilities.runOnUIThread(new Runnable() {
                                @Override
                                public final void run() {
                                    PassportActivity.PhoneConfirmationView.AnonymousClass5.AnonymousClass1.this.lambda$null$0$PassportActivity$PhoneConfirmationView$5$1(error);
                                }
                            });
                        }
                    }

                    public void lambda$null$0$PassportActivity$PhoneConfirmationView$5$1(TLRPC.TL_error error) {
                        PhoneConfirmationView.this.lastError = error.text;
                    }
                }
            }, 0L, 1000L);
        }

        public void destroyTimer() {
            try {
                synchronized (this.timerSync) {
                    if (this.timeTimer != null) {
                        this.timeTimer.cancel();
                        this.timeTimer = null;
                    }
                }
            } catch (Exception e) {
                FileLog.e(e);
            }
        }

        public String getCode() {
            if (this.codeField == null) {
                return "";
            }
            StringBuilder codeBuilder = new StringBuilder();
            int a = 0;
            while (true) {
                EditTextBoldCursor[] editTextBoldCursorArr = this.codeField;
                if (a < editTextBoldCursorArr.length) {
                    codeBuilder.append(PhoneFormat.stripExceptNumbers(editTextBoldCursorArr[a].getText().toString()));
                    a++;
                } else {
                    return codeBuilder.toString();
                }
            }
        }

        @Override
        public void onNextPressed() {
            if (this.nextPressed) {
                return;
            }
            String code = getCode();
            if (TextUtils.isEmpty(code)) {
                AndroidUtilities.shakeView(this.codeFieldContainer, 2.0f, 0);
                return;
            }
            this.nextPressed = true;
            int i = this.verificationType;
            if (i == 2) {
                AndroidUtilities.setWaitingForSms(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
            } else if (i == 3) {
                AndroidUtilities.setWaitingForCall(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
            }
            this.waitingForEvent = false;
            PassportActivity.this.showEditDoneProgress(true, true);
            final TLRPC.TL_account_verifyPhone req = new TLRPC.TL_account_verifyPhone();
            req.phone_number = this.phone;
            req.phone_code = code;
            req.phone_code_hash = this.phoneHash;
            destroyTimer();
            PassportActivity.this.needShowProgress();
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.PhoneConfirmationView.this.lambda$onNextPressed$7$PassportActivity$PhoneConfirmationView(req, tLObject, tL_error);
                }
            }, 2);
        }

        public void lambda$onNextPressed$7$PassportActivity$PhoneConfirmationView(final TLRPC.TL_account_verifyPhone req, TLObject response, final TLRPC.TL_error error) {
            AndroidUtilities.runOnUIThread(new Runnable() {
                @Override
                public final void run() {
                    PassportActivity.PhoneConfirmationView.this.lambda$null$6$PassportActivity$PhoneConfirmationView(error, req);
                }
            });
        }

        public void lambda$null$6$PassportActivity$PhoneConfirmationView(TLRPC.TL_error error, TLRPC.TL_account_verifyPhone req) {
            int i;
            int i2;
            PassportActivity.this.needHideProgress();
            this.nextPressed = false;
            if (error != null) {
                this.lastError = error.text;
                if ((this.verificationType == 3 && ((i2 = this.nextType) == 4 || i2 == 2)) || ((this.verificationType == 2 && ((i = this.nextType) == 4 || i == 3)) || (this.verificationType == 4 && this.nextType == 2))) {
                    createTimer();
                }
                int i3 = this.verificationType;
                if (i3 == 2) {
                    AndroidUtilities.setWaitingForSms(true);
                    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveSmsCode);
                } else if (i3 == 3) {
                    AndroidUtilities.setWaitingForCall(true);
                    NotificationCenter.getGlobalInstance().addObserver(this, NotificationCenter.didReceiveCall);
                }
                this.waitingForEvent = true;
                if (this.verificationType != 3) {
                    AlertsCreator.processError(PassportActivity.this.currentAccount, error, PassportActivity.this, req, new Object[0]);
                }
                PassportActivity.this.showEditDoneProgress(true, false);
                if (error.text.contains("PHONE_CODE_EMPTY") || error.text.contains("PHONE_CODE_INVALID")) {
                    int a = 0;
                    while (true) {
                        EditTextBoldCursor[] editTextBoldCursorArr = this.codeField;
                        if (a < editTextBoldCursorArr.length) {
                            editTextBoldCursorArr[a].setText("");
                            a++;
                        } else {
                            editTextBoldCursorArr[0].requestFocus();
                            return;
                        }
                    }
                } else if (error.text.contains("PHONE_CODE_EXPIRED")) {
                    onBackPressed(true);
                    PassportActivity.this.setPage(0, true, null);
                }
            } else {
                destroyTimer();
                destroyCodeTimer();
                PassportActivityDelegate passportActivityDelegate = PassportActivity.this.delegate;
                TLRPC.TL_secureRequiredType tL_secureRequiredType = PassportActivity.this.currentType;
                String str = (String) PassportActivity.this.currentValues.get("phone");
                final PassportActivity passportActivity = PassportActivity.this;
                passportActivityDelegate.saveValue(tL_secureRequiredType, str, null, null, null, null, null, null, null, null, new Runnable() {
                    @Override
                    public final void run() {
                        PassportActivity.this.finishFragment();
                    }
                }, null);
            }
        }

        @Override
        public boolean onBackPressed(boolean force) {
            if (!force) {
                AlertDialog.Builder builder = new AlertDialog.Builder(PassportActivity.this.getParentActivity());
                builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
                builder.setMessage(LocaleController.getString("StopVerification", R.string.StopVerification));
                builder.setPositiveButton(LocaleController.getString("Continue", R.string.Continue), null);
                builder.setNegativeButton(LocaleController.getString("Stop", R.string.Stop), new DialogInterface.OnClickListener() {
                    @Override
                    public final void onClick(DialogInterface dialogInterface, int i) {
                        PassportActivity.PhoneConfirmationView.this.lambda$onBackPressed$8$PassportActivity$PhoneConfirmationView(dialogInterface, i);
                    }
                });
                PassportActivity.this.showDialog(builder.create());
                return false;
            }
            TLRPC.TL_auth_cancelCode req = new TLRPC.TL_auth_cancelCode();
            req.phone_number = this.phone;
            req.phone_code_hash = this.phoneHash;
            ConnectionsManager.getInstance(PassportActivity.this.currentAccount).sendRequest(req, new RequestDelegate() {
                @Override
                public final void run(TLObject tLObject, TLRPC.TL_error tL_error) {
                    PassportActivity.PhoneConfirmationView.lambda$onBackPressed$9(tLObject, tL_error);
                }
            }, 2);
            destroyTimer();
            destroyCodeTimer();
            this.currentParams = null;
            int i = this.verificationType;
            if (i == 2) {
                AndroidUtilities.setWaitingForSms(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
            } else if (i == 3) {
                AndroidUtilities.setWaitingForCall(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
            }
            this.waitingForEvent = false;
            return true;
        }

        public void lambda$onBackPressed$8$PassportActivity$PhoneConfirmationView(DialogInterface dialogInterface, int i) {
            onBackPressed(true);
            PassportActivity.this.setPage(0, true, null);
        }

        public static void lambda$onBackPressed$9(TLObject response, TLRPC.TL_error error) {
        }

        @Override
        public void onDestroyActivity() {
            super.onDestroyActivity();
            int i = this.verificationType;
            if (i == 2) {
                AndroidUtilities.setWaitingForSms(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveSmsCode);
            } else if (i == 3) {
                AndroidUtilities.setWaitingForCall(false);
                NotificationCenter.getGlobalInstance().removeObserver(this, NotificationCenter.didReceiveCall);
            }
            this.waitingForEvent = false;
            destroyTimer();
            destroyCodeTimer();
        }

        @Override
        public void onShow() {
            super.onShow();
            LinearLayout linearLayout = this.codeFieldContainer;
            if (linearLayout != null && linearLayout.getVisibility() == 0) {
                for (int a = this.codeField.length - 1; a >= 0; a--) {
                    if (a == 0 || this.codeField[a].length() != 0) {
                        this.codeField[a].requestFocus();
                        EditTextBoldCursor[] editTextBoldCursorArr = this.codeField;
                        editTextBoldCursorArr[a].setSelection(editTextBoldCursorArr[a].length());
                        AndroidUtilities.showKeyboard(this.codeField[a]);
                        return;
                    }
                }
            }
        }

        @Override
        public void didReceivedNotification(int id, int account, Object... args) {
            if (!this.waitingForEvent || this.codeField == null) {
                return;
            }
            if (id == NotificationCenter.didReceiveSmsCode) {
                this.codeField[0].setText("" + args[0]);
                onNextPressed();
                return;
            }
            if (id == NotificationCenter.didReceiveCall) {
                String num = "" + args[0];
                if (!AndroidUtilities.checkPhonePattern(this.pattern, num)) {
                    return;
                }
                this.ignoreOnTextChange = true;
                this.codeField[0].setText(num);
                this.ignoreOnTextChange = false;
                onNextPressed();
            }
        }
    }

    @Override
    public ThemeDescription[] getThemeDescriptions() {
        ArrayList<ThemeDescription> arrayList = new ArrayList<>();
        arrayList.add(new ThemeDescription(this.fragmentView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundGray));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_actionBarDefault));
        arrayList.add(new ThemeDescription(this.scrollView, ThemeDescription.FLAG_LISTGLOWCOLOR, null, null, null, null, Theme.key_actionBarDefault));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_AB_ITEMSCOLOR, null, null, null, null, Theme.key_actionBarDefaultIcon));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_AB_TITLECOLOR, null, null, null, null, Theme.key_actionBarDefaultTitle));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_AB_SELECTORCOLOR, null, null, null, null, Theme.key_actionBarDefaultSelector));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_AB_SEARCH, null, null, null, null, Theme.key_actionBarDefaultSearch));
        arrayList.add(new ThemeDescription(this.actionBar, ThemeDescription.FLAG_AB_SEARCHPLACEHOLDER, null, null, null, null, Theme.key_actionBarDefaultSearchPlaceholder));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{View.class}, Theme.dividerPaint, null, null, Theme.key_divider));
        arrayList.add(new ThemeDescription(this.extraBackgroundView, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
        View view = this.extraBackgroundView2;
        if (view != null) {
            arrayList.add(new ThemeDescription(view, ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
        }
        for (int a = 0; a < this.dividers.size(); a++) {
            arrayList.add(new ThemeDescription(this.dividers.get(a), ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_divider));
        }
        for (Map.Entry<SecureDocument, SecureDocumentCell> entry : this.documentsCells.entrySet()) {
            SecureDocumentCell cell = entry.getValue();
            arrayList.add(new ThemeDescription(cell, ThemeDescription.FLAG_SELECTORWHITE, new Class[]{SecureDocumentCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
            arrayList.add(new ThemeDescription(cell, 0, new Class[]{SecureDocumentCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteBlackText));
            arrayList.add(new ThemeDescription(cell, 0, new Class[]{SecureDocumentCell.class}, new String[]{"valueTextView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteGrayText2));
        }
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_SELECTORWHITE, new Class[]{TextDetailSettingsCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteBlackText));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{TextDetailSettingsCell.class}, new String[]{"valueTextView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteGrayText2));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_SELECTORWHITE, new Class[]{TextSettingsCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{TextSettingsCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteBlackText));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{TextSettingsCell.class}, new String[]{"valueTextView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteValueText));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{ShadowSectionCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_SELECTORWHITE, new Class[]{TextDetailSecureCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{TextDetailSecureCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteBlackText));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{TextDetailSecureCell.class}, null, null, null, Theme.key_divider));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_TEXTCOLOR, new Class[]{TextDetailSecureCell.class}, new String[]{"valueTextView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteGrayText2));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_IMAGECOLOR, new Class[]{TextDetailSecureCell.class}, new String[]{"checkImageView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_featuredStickers_addedIcon));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_CELLBACKGROUNDCOLOR, new Class[]{HeaderCell.class}, null, null, null, Theme.key_windowBackgroundWhite));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{HeaderCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteBlueHeader));
        arrayList.add(new ThemeDescription(this.linearLayout2, ThemeDescription.FLAG_BACKGROUNDFILTER, new Class[]{TextInfoPrivacyCell.class}, null, null, null, Theme.key_windowBackgroundGrayShadow));
        arrayList.add(new ThemeDescription(this.linearLayout2, 0, new Class[]{TextInfoPrivacyCell.class}, new String[]{"textView"}, (Paint[]) null, (Drawable[]) null, (ThemeDescription.ThemeDescriptionDelegate) null, Theme.key_windowBackgroundWhiteGrayText4));
        if (this.inputFields != null) {
            int a2 = 0;
            while (true) {
                EditTextBoldCursor[] editTextBoldCursorArr = this.inputFields;
                if (a2 >= editTextBoldCursorArr.length) {
                    break;
                }
                arrayList.add(new ThemeDescription((View) editTextBoldCursorArr[a2].getParent(), ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CURSORCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_HINTTEXTCOLOR | ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
                arrayList.add(new ThemeDescription(this.inputFields[a2], ThemeDescription.FLAG_PROGRESSBAR | ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteRedText3));
                a2++;
            }
        } else {
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_PROGRESSBAR | ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_DRAWABLESELECTEDSTATE | ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
            arrayList.add(new ThemeDescription(null, ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_windowBackgroundWhiteRedText3));
        }
        if (this.inputExtraFields != null) {
            int a3 = 0;
            while (true) {
                EditTextBoldCursor[] editTextBoldCursorArr2 = this.inputExtraFields;
                if (a3 >= editTextBoldCursorArr2.length) {
                    break;
                }
                arrayList.add(new ThemeDescription((View) editTextBoldCursorArr2[a3].getParent(), ThemeDescription.FLAG_BACKGROUND, null, null, null, null, Theme.key_windowBackgroundWhite));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_TEXTCOLOR | ThemeDescription.FLAG_CURSORCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_HINTTEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteHintText));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_HINTTEXTCOLOR | ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueHeader));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteInputField));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_BACKGROUNDFILTER | ThemeDescription.FLAG_DRAWABLESELECTEDSTATE, null, null, null, null, Theme.key_windowBackgroundWhiteInputFieldActivated));
                arrayList.add(new ThemeDescription(this.inputExtraFields[a3], ThemeDescription.FLAG_PROGRESSBAR | ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_windowBackgroundWhiteRedText3));
                a3++;
            }
        }
        arrayList.add(new ThemeDescription(this.emptyView, ThemeDescription.FLAG_PROGRESSBAR, null, null, null, null, Theme.key_progressCircle));
        arrayList.add(new ThemeDescription(this.noPasswordImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_chat_messagePanelIcons));
        arrayList.add(new ThemeDescription(this.noPasswordTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText4));
        arrayList.add(new ThemeDescription(this.noPasswordSetTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText5));
        arrayList.add(new ThemeDescription(this.passwordForgotButton, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
        arrayList.add(new ThemeDescription(this.plusTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlackText));
        arrayList.add(new ThemeDescription(this.acceptTextView, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_passport_authorizeText));
        arrayList.add(new ThemeDescription(this.bottomLayout, ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_passport_authorizeBackground));
        arrayList.add(new ThemeDescription(this.bottomLayout, ThemeDescription.FLAG_DRAWABLESELECTEDSTATE | ThemeDescription.FLAG_BACKGROUNDFILTER, null, null, null, null, Theme.key_passport_authorizeBackgroundSelected));
        arrayList.add(new ThemeDescription(this.progressView, 0, null, null, null, null, Theme.key_contextProgressInner2));
        arrayList.add(new ThemeDescription(this.progressView, 0, null, null, null, null, Theme.key_contextProgressOuter2));
        arrayList.add(new ThemeDescription(this.progressViewButton, 0, null, null, null, null, Theme.key_contextProgressInner2));
        arrayList.add(new ThemeDescription(this.progressViewButton, 0, null, null, null, null, Theme.key_contextProgressOuter2));
        arrayList.add(new ThemeDescription(this.emptyImageView, ThemeDescription.FLAG_IMAGECOLOR, null, null, null, null, Theme.key_sessions_devicesImage));
        arrayList.add(new ThemeDescription(this.emptyTextView1, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
        arrayList.add(new ThemeDescription(this.emptyTextView2, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteGrayText2));
        arrayList.add(new ThemeDescription(this.emptyTextView3, ThemeDescription.FLAG_TEXTCOLOR, null, null, null, null, Theme.key_windowBackgroundWhiteBlueText4));
        return (ThemeDescription[]) arrayList.toArray(new ThemeDescription[0]);
    }
}