package com.tencent.mm.plugin.account.bind.ui;

import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.telephony.TelephonyManager;
import android.view.KeyEvent;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.m;
import com.tencent.mm.au.b;
import com.tencent.mm.bp.d;
import com.tencent.mm.kernel.g;
import com.tencent.mm.modelsimple.r;
import com.tencent.mm.plugin.account.friend.a.l;
import com.tencent.mm.plugin.account.friend.a.l.a;
import com.tencent.mm.plugin.account.friend.a.x;
import com.tencent.mm.plugin.account.friend.a.y;
import com.tencent.mm.plugin.account.friend.ui.i;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMWizardActivity;
import com.tencent.mm.ui.base.h;
import com.tencent.mm.ui.base.p;
import com.tencent.ytcommon.BuildConfig;

public class BindMContactIntroUI extends MMWizardActivity implements f {
    private String cFl;
    private boolean gqB = false;
    private ImageView gri;
    private TextView grj;
    private TextView grk;
    private Button grl;
    private Button grm;
    private a grn;
    private i gro;
    private String grp = null;
    private String grq = null;
    private int grr;
    private int grs = 0;
    private p tipDialog = null;

    public void onWindowFocusChanged(boolean z) {
        super.onWindowFocusChanged(z);
        AppMethodBeat.at(this, z);
    }

    static /* synthetic */ void c(BindMContactIntroUI bindMContactIntroUI) {
        AppMethodBeat.i(13450);
        bindMContactIntroUI.aoZ();
        AppMethodBeat.o(13450);
    }

    public final int getLayoutId() {
        return 2130968842;
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(13438);
        super.onCreate(bundle);
        g.Rg().a(132, this);
        g.Rg().a(255, this);
        g.Rg().a(254, this);
        setMMTitle(2131297565);
        AppMethodBeat.o(13438);
    }

    public void onDestroy() {
        AppMethodBeat.i(13439);
        g.Rg().b(132, this);
        g.Rg().b(255, this);
        g.Rg().b(254, this);
        if (this.gro != null) {
            this.gro.recycle();
        }
        super.onDestroy();
        AppMethodBeat.o(13439);
    }

    public void onResume() {
        AppMethodBeat.i(13440);
        super.onResume();
        initView();
        AppMethodBeat.o(13440);
    }

    public final void initView() {
        AppMethodBeat.i(13441);
        this.grr = getIntent().getIntExtra("bind_scene", 0);
        this.gqB = getIntent().getBooleanExtra("KEnterFromBanner", false);
        this.grs = getIntent().getIntExtra("key_upload_scene", 0);
        this.grn = l.apS();
        ab.d("MicroMsg.BindMContactIntroUI", "state " + this.grn);
        this.cFl = (String) g.RP().Ry().get(6, null);
        if (this.cFl == null || this.cFl.equals(BuildConfig.FLAVOR)) {
            this.cFl = (String) g.RP().Ry().get(4097, null);
        }
        this.gri = (ImageView) findViewById(2131821763);
        this.grj = (TextView) findViewById(2131821764);
        this.grk = (TextView) findViewById(2131821765);
        this.grl = (Button) findViewById(2131821766);
        this.grm = (Button) findViewById(2131821767);
        this.grl.setOnClickListener(new 1(this));
        this.grm.setOnClickListener(new 12(this));
        if (getIntent().getBooleanExtra("skip", false)) {
            addTextOptionMenu(0, getString(2131296958), new 21(this));
        } else {
            setBackBtn(new 22(this));
        }
        if (this.grn == a.gvA || this.grn == a.gvz) {
            String value = com.tencent.mm.m.g.Nu().getValue("ShowUnbindPhone");
            int i = 2;
            if (!bo.isNullOrNil(value)) {
                i = bo.ank(value);
            }
            if (i != 0) {
                addIconOptionMenu(1, 2130839555, new 23(this, i));
            }
        }
        cu();
        AppMethodBeat.o(13441);
    }

    private void cu() {
        AppMethodBeat.i(13442);
        switch (20.grv[this.grn.ordinal()]) {
            case 1:
                showOptionMenu(1, false);
                this.gri.setImageResource(2131231609);
                this.grk.setVisibility(0);
                this.grm.setVisibility(8);
                this.grj.setText(2131297548);
                this.grk.setText(2131297547);
                this.grl.setText(2131297522);
                AppMethodBeat.o(13442);
                return;
            case 2:
                showOptionMenu(1, false);
                this.gri.setImageResource(2131231609);
                this.grk.setVisibility(0);
                this.grm.setVisibility(0);
                this.grj.setText(String.format(getString(2131297586), new Object[]{this.cFl}));
                this.grk.setText(2131297576);
                this.grl.setText(2131297580);
                this.grm.setText(2131297533);
                AppMethodBeat.o(13442);
                return;
            case 3:
                showOptionMenu(1, true);
                this.gri.setImageResource(2131231608);
                this.grk.setVisibility(0);
                this.grm.setVisibility(0);
                this.grj.setText(String.format(getString(2131297586), new Object[]{this.cFl}));
                this.grk.setText(2131297529);
                this.grl.setText(2131297577);
                this.grm.setText(2131297531);
                AppMethodBeat.o(13442);
                return;
            case 4:
                showOptionMenu(1, true);
                this.gri.setImageResource(2131231608);
                this.grk.setVisibility(0);
                this.grm.setVisibility(0);
                this.grj.setText(String.format(getString(2131297586), new Object[]{this.cFl}));
                this.grk.setText(2131297529);
                this.grl.setText(2131297546);
                this.grm.setText(2131297531);
                break;
        }
        AppMethodBeat.o(13442);
    }

    public boolean onKeyDown(int i, KeyEvent keyEvent) {
        AppMethodBeat.i(13443);
        if (i == 4) {
            aoZ();
            AppMethodBeat.o(13443);
            return true;
        }
        boolean onKeyDown = super.onKeyDown(i, keyEvent);
        AppMethodBeat.o(13443);
        return onKeyDown;
    }

    private void aoZ() {
        AppMethodBeat.i(13444);
        aqX();
        if (this.grr == 2) {
            cancel();
            finish();
            AppMethodBeat.o(13444);
            return;
        }
        Ni(1);
        AppMethodBeat.o(13444);
    }

    private void dj(boolean z) {
        AppMethodBeat.i(13445);
        Intent intent = new Intent(this, BindMContactUI.class);
        if (z) {
            intent.putExtra("bind_scene", 3);
        } else {
            intent.putExtra("bind_scene", 0);
        }
        String simCountryIso = ((TelephonyManager) getSystemService("phone")).getSimCountryIso();
        if (!bo.isNullOrNil(simCountryIso)) {
            b.a k = b.k(this, simCountryIso, getString(2131298789));
            if (k != null) {
                intent.putExtra("country_name", k.fHE);
                intent.putExtra("couttry_code", k.fHD);
            }
        }
        MMWizardActivity.J(this, intent);
        AppMethodBeat.o(13445);
    }

    public void onSceneEnd(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(13446);
        ab.i("MicroMsg.BindMContactIntroUI", "summerunbind onSceneEnd type: " + mVar.getType() + " errType = " + i + " errCode = " + i2 + " errMsg = " + str);
        if (mVar.getType() == 132 && i == 0 && i2 == 0) {
            if (this.tipDialog != null) {
                this.tipDialog.dismiss();
                this.tipDialog = null;
            }
            if (((x) mVar).Ah() == 3) {
                ((com.tencent.mm.plugin.account.a.a.a) g.M(com.tencent.mm.plugin.account.a.a.a.class)).removeSelfAccount(this);
                if (bo.isNullOrNil(this.grq)) {
                    MMWizardActivity.J(this, new Intent(this, BindMContactStatusUI.class));
                } else {
                    h.a(this, this.grq, BuildConfig.FLAVOR, getString(2131296955), new 26(this));
                    AppMethodBeat.o(13446);
                    return;
                }
            }
            AppMethodBeat.o(13446);
            return;
        }
        Object obj;
        if (!com.tencent.mm.plugin.account.a.a.gkF.a(this, i, i2, str)) {
            obj = null;
            switch (i2) {
                case -214:
                    com.tencent.mm.h.a jY = com.tencent.mm.h.a.jY(str);
                    if (jY != null) {
                        jY.a(this, null, null);
                    }
                    obj = 1;
                    break;
                case -43:
                    Toast.makeText(this, 2131297535, 0).show();
                    obj = 1;
                    break;
                case -41:
                    Toast.makeText(this, 2131297537, 0).show();
                    obj = 1;
                    break;
                case -36:
                    Toast.makeText(this, 2131297540, 0).show();
                    obj = 1;
                    break;
                case -35:
                    Toast.makeText(this, 2131297536, 0).show();
                    obj = 1;
                    break;
                case -34:
                    Toast.makeText(this, 2131297538, 0).show();
                    obj = 1;
                    break;
            }
        }
        obj = 1;
        if (obj != null) {
            if (this.tipDialog != null) {
                this.tipDialog.dismiss();
                this.tipDialog = null;
            }
            AppMethodBeat.o(13446);
            return;
        }
        final x xVar;
        AppCompatActivity appCompatActivity;
        if (mVar.getType() == 254) {
            if (this.tipDialog != null) {
                this.tipDialog.dismiss();
                this.tipDialog = null;
            }
            if (i == 0 && i2 == 0) {
                this.grq = ((y) mVar).aqe().vZs;
                this.grp = ((y) mVar).aqd();
                if (bo.isNullOrNil(this.grq)) {
                    g.Rg().a(new r(2), 0);
                    AppMethodBeat.o(13446);
                    return;
                }
                xVar = new x(this.cFl, 3, BuildConfig.FLAVOR, 0, BuildConfig.FLAVOR);
                g.Rg().a(xVar, 0);
                appCompatActivity = this.mController.ylL;
                getString(2131297061);
                this.tipDialog = h.b(appCompatActivity, getString(2131297575), true, new OnCancelListener() {
                    public final void onCancel(DialogInterface dialogInterface) {
                        AppMethodBeat.i(13437);
                        g.Rg().c(xVar);
                        AppMethodBeat.o(13437);
                    }
                });
                AppMethodBeat.o(13446);
                return;
            } else if (i2 == -3) {
                ab.d("MicroMsg.BindMContactIntroUI", "summerunbind MMFunc_QueryHasPasswd err and set psw");
                h.a(this.mController.ylL, getString(2131303327), null, getString(2131303328), getString(2131303326), true, new OnClickListener() {
                    public final void onClick(DialogInterface dialogInterface, int i) {
                        AppMethodBeat.i(13423);
                        Intent intent = new Intent();
                        intent.putExtra("kintent_hint", BindMContactIntroUI.this.getString(2131303325));
                        intent.putExtra("from_unbind", true);
                        d.b(BindMContactIntroUI.this, "account", "com.tencent.mm.plugin.account.ui.RegByMobileSetPwdUI", intent, 1);
                        AppMethodBeat.o(13423);
                    }
                }, new OnClickListener() {
                    public final void onClick(DialogInterface dialogInterface, int i) {
                    }
                });
            } else if (i2 == -81) {
                h.a(this, 2131303004, 2131297061, new 4(this));
            } else if (i2 == -82) {
                h.a(this, 2131303005, 2131297061, new 5(this));
            } else if (i2 == -83) {
                h.a(this, 2131303002, 2131297061, new 6(this));
            } else if (i2 == -84) {
                h.a(this, 2131303003, 2131297061, new 7(this));
            } else if (i2 == -85) {
                h.a(this, 2131302999, 2131297061, new 8(this));
            } else if (i2 == -86) {
                h.a(this, 2131303007, 2131297061, new 9(this));
            }
        }
        if (mVar.getType() == 255) {
            if (this.tipDialog != null) {
                this.tipDialog.dismiss();
                this.tipDialog = null;
            }
            if (i2 == 0) {
                xVar = new x(this.cFl, 3, BuildConfig.FLAVOR, 0, BuildConfig.FLAVOR);
                g.Rg().a(xVar, 0);
                appCompatActivity = this.mController.ylL;
                getString(2131297061);
                this.tipDialog = h.b(appCompatActivity, getString(2131297575), true, new 10(this, xVar));
            } else {
                ab.i("MicroMsg.BindMContactIntroUI", "summerunbind old err_password");
                h.a(this.mController.ylL, getString(2131303327), null, getString(2131303328), getString(2131303326), true, new 11(this), new 13(this));
            }
        }
        if (mVar.getType() == 132) {
            if (this.tipDialog != null) {
                this.tipDialog.dismiss();
                this.tipDialog = null;
            }
            if (((x) mVar).Ah() == 3) {
                if (i2 == -82) {
                    h.a(this, 2131303005, 2131297061, new OnClickListener() {
                        public final void onClick(DialogInterface dialogInterface, int i) {
                        }
                    });
                    AppMethodBeat.o(13446);
                    return;
                } else if (i2 == -83) {
                    h.a(this, 2131303002, 2131297061, new 15(this));
                    AppMethodBeat.o(13446);
                    return;
                } else if (i2 == -84) {
                    h.a(this, 2131303003, 2131297061, new OnClickListener() {
                        public final void onClick(DialogInterface dialogInterface, int i) {
                        }
                    });
                    AppMethodBeat.o(13446);
                    return;
                } else if (i2 == -85) {
                    h.a(this, 2131302999, 2131297061, new OnClickListener() {
                        public final void onClick(DialogInterface dialogInterface, int i) {
                        }
                    });
                    AppMethodBeat.o(13446);
                    return;
                } else {
                    Toast.makeText(this, getString(2131297571, new Object[]{Integer.valueOf(i), Integer.valueOf(i2)}), 0).show();
                }
            }
        }
        AppMethodBeat.o(13446);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(13447);
        super.onActivityResult(i, i2, intent);
        ab.d("MicroMsg.BindMContactIntroUI", "summerunbind onAcvityResult requestCode:%d, resultCode:%d", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
        switch (i) {
            case 1:
                if (i2 == -1) {
                    ab.i("MicroMsg.BindMContactIntroUI", "summerunbind REQUEST_CODE_SET_PSW ok and start NetSceneCheckUnBind again mobile: " + this.cFl);
                    g.Rg().a(new y(y.gvW), 0);
                    getString(2131297061);
                    this.tipDialog = h.b(this, getString(2131296965), true, new 19(this));
                    break;
                }
                break;
        }
        AppMethodBeat.o(13447);
    }

    static /* synthetic */ void a(BindMContactIntroUI bindMContactIntroUI) {
        boolean z = false;
        AppMethodBeat.i(13448);
        switch (20.grv[bindMContactIntroUI.grn.ordinal()]) {
            case 1:
                bindMContactIntroUI.dj(false);
                AppMethodBeat.o(13448);
                return;
            case 2:
                String str = bindMContactIntroUI.cFl;
                if (bindMContactIntroUI.gro == null) {
                    bindMContactIntroUI.gro = new i(i.b.gyv, bindMContactIntroUI, new 25(bindMContactIntroUI, str));
                }
                i iVar = bindMContactIntroUI.gro;
                if (bindMContactIntroUI.grr == 0 || bindMContactIntroUI.grr == 3) {
                    z = true;
                }
                iVar.gys = z;
                bindMContactIntroUI.gro.wn(str);
                AppMethodBeat.o(13448);
                return;
            case 3:
                g.RP().Ry().set(12322, Boolean.FALSE);
                ((com.tencent.mm.plugin.account.a.a.a) g.M(com.tencent.mm.plugin.account.a.a.a.class)).showAddrBookUploadConfirm(bindMContactIntroUI, new 18(bindMContactIntroUI), true, bindMContactIntroUI.grs);
                break;
            case 4:
                bindMContactIntroUI.startActivity(new Intent(bindMContactIntroUI, MobileFriendUI.class));
                AppMethodBeat.o(13448);
                return;
        }
        AppMethodBeat.o(13448);
    }

    static /* synthetic */ void b(BindMContactIntroUI bindMContactIntroUI) {
        AppMethodBeat.i(13449);
        switch (20.grv[bindMContactIntroUI.grn.ordinal()]) {
            case 1:
                AppMethodBeat.o(13449);
                return;
            case 2:
                l.apT();
                bindMContactIntroUI.initView();
                AppMethodBeat.o(13449);
                return;
            case 3:
                bindMContactIntroUI.dj(true);
                break;
            case 4:
                bindMContactIntroUI.dj(true);
                AppMethodBeat.o(13449);
                return;
        }
        AppMethodBeat.o(13449);
    }

    static /* synthetic */ void d(BindMContactIntroUI bindMContactIntroUI) {
        AppMethodBeat.i(13451);
        h.d(bindMContactIntroUI.mController.ylL, bindMContactIntroUI.getString(2131297569), bindMContactIntroUI.getString(2131297570), bindMContactIntroUI.getString(2131296868), bindMContactIntroUI.getString(2131297568), null, new 24(bindMContactIntroUI));
        AppMethodBeat.o(13451);
    }

    static /* synthetic */ void g(BindMContactIntroUI bindMContactIntroUI) {
        AppMethodBeat.i(13452);
        bindMContactIntroUI.Ni(1);
        AppMethodBeat.o(13452);
    }

    static /* synthetic */ void apa() {
        AppMethodBeat.i(13453);
        int YD = com.tencent.mm.model.r.YD();
        l.apP();
        g.RP().Ry().set(7, Integer.valueOf(YD & -131073));
        com.tencent.mm.plugin.account.a.a.gkF.BS();
        AppMethodBeat.o(13453);
    }
}
