package com.parse.ui.login;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import com.parse.LogInCallback;
import com.parse.Parse;
import com.parse.ParseException;
import com.parse.ParseUser;
import com.parse.ui.R$id;
import com.parse.ui.R$layout;
import com.parse.ui.R$string;
import p037.p065.p078.C1910;
import p138.p176.p177.p242.p246.p251.C4303;

/* JADX INFO: loaded from: classes.dex */
public class ParseLoginFragment extends ParseLoginFragmentBase {
    public ParseLoginConfig config;
    public ParseLoginFragmentListener loginFragmentListener;
    public ParseOnLoginSuccessListener onLoginSuccessListener;
    public View parseLogin;
    public Button parseLoginButton;
    public TextView parseLoginHelpButton;
    public Button parseSignupButton;
    public EditText passwordField;
    public EditText usernameField;

    public interface ParseLoginFragmentListener {
        void onLoginHelpClicked();

        void onSignUpClicked(String str, String str2);
    }

    @Override // androidx.fragment.app.Fragment
    public void onAttach(Context context) {
        super.onAttach(context);
        C1910.InterfaceC1911 activity = getActivity();
        if (!(activity instanceof ParseLoginFragmentListener)) {
            throw new IllegalArgumentException("Activity must implemement ParseLoginFragmentListener");
        }
        this.loginFragmentListener = (ParseLoginFragmentListener) activity;
        if (!(activity instanceof ParseOnLoginSuccessListener)) {
            throw new IllegalArgumentException("Activity must implemement ParseOnLoginSuccessListener");
        }
        this.onLoginSuccessListener = (ParseOnLoginSuccessListener) activity;
        if (!(activity instanceof ParseOnLoadingListener)) {
            throw new IllegalArgumentException("Activity must implemement ParseOnLoadingListener");
        }
        this.onLoadingListener = (ParseOnLoadingListener) activity;
    }

    @Override // androidx.fragment.app.Fragment
    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
    }

    @Override // androidx.fragment.app.Fragment
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        boolean z;
        Integer num;
        this.config = ParseLoginConfig.fromBundle(this.mArguments, getActivity());
        View viewInflate = layoutInflater.inflate(R$layout.com_parse_ui_parse_login_fragment, viewGroup, false);
        ImageView imageView = (ImageView) viewInflate.findViewById(R$id.app_logo);
        this.parseLogin = viewInflate.findViewById(R$id.parse_login);
        this.usernameField = (EditText) viewInflate.findViewById(R$id.login_username_input);
        this.passwordField = (EditText) viewInflate.findViewById(R$id.login_password_input);
        this.parseLoginHelpButton = (Button) viewInflate.findViewById(R$id.parse_login_help);
        this.parseLoginButton = (Button) viewInflate.findViewById(R$id.parse_login_button);
        this.parseSignupButton = (Button) viewInflate.findViewById(R$id.parse_signup_button);
        if (imageView != null && (num = this.config.appLogo) != null) {
            imageView.setImageResource(num.intValue());
        }
        Boolean bool = this.config.parseLoginEnabled;
        if (bool != null ? bool.booleanValue() : false) {
            if (this.usernameField == null) {
                debugLog(R$string.com_parse_ui_login_warning_layout_missing_username_field);
            }
            if (this.passwordField == null) {
                debugLog(R$string.com_parse_ui_login_warning_layout_missing_password_field);
            }
            if (this.parseLoginButton == null) {
                debugLog(R$string.com_parse_ui_login_warning_layout_missing_login_button);
            }
            if (this.parseSignupButton == null) {
                debugLog(R$string.com_parse_ui_login_warning_layout_missing_signup_button);
            }
            if (this.parseLoginHelpButton == null) {
                debugLog(R$string.com_parse_ui_login_warning_layout_missing_login_help_button);
            }
            z = (this.usernameField == null || this.passwordField == null || this.parseLoginButton == null || this.parseSignupButton == null || this.parseLoginHelpButton == null) ? false : true;
            if (!z) {
                debugLog(R$string.com_parse_ui_login_warning_disabled_username_password_login);
            }
        } else {
            z = false;
        }
        if (z) {
            this.parseLogin.setVisibility(0);
            if (this.config.isParseLoginEmailAsUsername()) {
                this.usernameField.setHint(R$string.com_parse_ui_email_input_hint);
                this.usernameField.setInputType(32);
            }
            CharSequence charSequence = this.config.parseLoginButtonText;
            if (charSequence != null) {
                this.parseLoginButton.setText(charSequence);
            }
            this.parseLoginButton.setOnClickListener(new View.OnClickListener() { // from class: com.parse.ui.login.ParseLoginFragment.1
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    String correctedUsernameOrEmail = C4303.getCorrectedUsernameOrEmail(ParseLoginFragment.this.usernameField.getText().toString());
                    String string = ParseLoginFragment.this.passwordField.getText().toString();
                    if (correctedUsernameOrEmail.length() == 0) {
                        if (ParseLoginFragment.this.config.isParseLoginEmailAsUsername()) {
                            ParseLoginFragment.this.showToast(R$string.com_parse_ui_no_email_toast);
                            return;
                        } else {
                            ParseLoginFragment.this.showToast(R$string.com_parse_ui_no_username_toast);
                            return;
                        }
                    }
                    if (string.length() == 0) {
                        ParseLoginFragment.this.showToast(R$string.com_parse_ui_no_password_toast);
                        return;
                    }
                    ParseOnLoadingListener parseOnLoadingListener = ParseLoginFragment.this.onLoadingListener;
                    if (parseOnLoadingListener != null) {
                        parseOnLoadingListener.onLoadingStart(true);
                    }
                    ParseUser.logInInBackground(correctedUsernameOrEmail.toLowerCase(), string, new LogInCallback() { // from class: com.parse.ui.login.ParseLoginFragment.1.1
                        @Override // com.parse.ParseCallback2
                        public void done(ParseUser parseUser, Throwable th) {
                            ParseUser parseUser2 = parseUser;
                            ParseException parseException = (ParseException) th;
                            if (ParseLoginFragment.this.isActivityDestroyed()) {
                                return;
                            }
                            if (parseUser2 != null) {
                                ParseLoginFragment.this.loadingFinish();
                                ParseLoginFragment.this.onLoginSuccessListener.onLoginSuccess();
                                return;
                            }
                            ParseLoginFragment.this.loadingFinish();
                            if (parseException != null) {
                                ParseLoginFragment.this.getString(R$string.com_parse_ui_login_warning_parse_login_failed);
                                parseException.toString();
                                Parse.getLogLevel();
                                if (parseException.code != 101) {
                                    ParseLoginFragment.this.showToast(R$string.com_parse_ui_parse_login_failed_unknown_toast);
                                    if (parseException.code == 209) {
                                        ParseUser.logOut();
                                        return;
                                    }
                                    return;
                                }
                                ParseLoginFragment parseLoginFragment = ParseLoginFragment.this;
                                CharSequence charSequence2 = parseLoginFragment.config.parseLoginInvalidCredentialsToastText;
                                if (charSequence2 != null) {
                                    parseLoginFragment.showToast(charSequence2);
                                } else {
                                    parseLoginFragment.showToast(R$string.com_parse_ui_parse_login_invalid_credentials_toast);
                                }
                                ParseLoginFragment.this.passwordField.selectAll();
                                ParseLoginFragment.this.passwordField.requestFocus();
                            }
                        }
                    });
                }
            });
            CharSequence charSequence2 = this.config.parseSignupButtonText;
            if (charSequence2 != null) {
                this.parseSignupButton.setText(charSequence2);
            }
            this.parseSignupButton.setOnClickListener(new View.OnClickListener() { // from class: com.parse.ui.login.ParseLoginFragment.2
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    ParseLoginFragment.this.loginFragmentListener.onSignUpClicked(ParseLoginFragment.this.usernameField.getText().toString(), ParseLoginFragment.this.passwordField.getText().toString());
                }
            });
            CharSequence charSequence3 = this.config.parseLoginHelpText;
            if (charSequence3 != null) {
                this.parseLoginHelpButton.setText(charSequence3);
            }
            this.parseLoginHelpButton.setOnClickListener(new View.OnClickListener() { // from class: com.parse.ui.login.ParseLoginFragment.3
                @Override // android.view.View.OnClickListener
                public void onClick(View view) {
                    ParseLoginFragment.this.loginFragmentListener.onLoginHelpClicked();
                }
            });
        }
        return viewInflate;
    }
}
