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

import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.Spannable;
import android.text.Spannable.Factory;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.f;
import com.tencent.mm.ai.m;
import com.tencent.mm.bp.d;
import com.tencent.mm.kernel.g;
import com.tencent.mm.model.r;
import com.tencent.mm.plugin.account.a.a;
import com.tencent.mm.plugin.appbrand.jsapi.contact.e;
import com.tencent.mm.plugin.messenger.foundation.a.j;
import com.tencent.mm.protocal.protobuf.act;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.mm.ui.base.h;
import com.tencent.mm.ui.widget.MMSwitchBtn;
import com.tencent.ytcommon.BuildConfig;

public class BindLinkedInUI extends MMActivity implements f {
    private String dun;
    private String duo;
    private ProgressDialog fsh;
    private boolean gqJ = false;
    private String gqK;
    private boolean gqL = false;
    private boolean gqM = false;
    private boolean gqN = false;
    private Bundle gqO;
    private boolean gqP = false;
    private boolean gqQ = false;
    private TextView gqR;
    private TextView gqS;
    private View gqT;
    private MMSwitchBtn gqU;
    private TextView gqV;
    private TextView gqW;
    private TextView gqX;
    private String gqY;
    private String gqZ;
    private String gra;
    private String grb;
    private String name;
    private int status;

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

    static /* synthetic */ void a(BindLinkedInUI bindLinkedInUI) {
        AppMethodBeat.i(13418);
        bindLinkedInUI.goBack();
        AppMethodBeat.o(13418);
    }

    static /* synthetic */ void a(BindLinkedInUI bindLinkedInUI, boolean z, boolean z2) {
        AppMethodBeat.i(13421);
        bindLinkedInUI.m(z, z2);
        AppMethodBeat.o(13421);
    }

    static /* synthetic */ void e(BindLinkedInUI bindLinkedInUI) {
        AppMethodBeat.i(13420);
        bindLinkedInUI.dh(false);
        AppMethodBeat.o(13420);
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(13401);
        super.onCreate(bundle);
        g.Rg().a(549, this);
        g.Rg().a(e.CTRL_INDEX, this);
        this.gqO = getIntent().getBundleExtra("qrcode_bundle");
        this.gqM = this.gqO != null;
        if (this.gqO != null) {
            this.dun = this.gqO.getString("i");
            this.duo = this.gqO.getString("n");
            this.gqY = this.gqO.getString("t");
            this.gqZ = this.gqO.getString("o");
            this.gra = this.gqO.getString("s");
            this.grb = this.gqO.getString("r");
            if (this.dun == null || this.duo == null || this.gqY == null || this.gra == null || this.grb == null) {
                h.a(this, getString(2131298562), null, false, new 1(this));
            }
        }
        this.gqN = getIntent().getBooleanExtra("oversea_entry", false);
        Kh();
        if (this.gqM) {
            this.gqL = true;
        }
        initView();
        if (this.gqO != null && this.gqJ && this.gqK.equals(this.dun)) {
            this.gqP = true;
            dh(true);
        }
        AppMethodBeat.o(13401);
    }

    public void onDestroy() {
        AppMethodBeat.i(13402);
        g.Rg().b(e.CTRL_INDEX, this);
        g.Rg().b(549, this);
        super.onDestroy();
        AppMethodBeat.o(13402);
    }

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

    public void onPause() {
        AppMethodBeat.i(13404);
        super.onPause();
        AppMethodBeat.o(13404);
    }

    public final int getLayoutId() {
        return 2130968840;
    }

    private void Kh() {
        boolean z = true;
        AppMethodBeat.i(13405);
        this.gqK = (String) g.RP().Ry().get(286721, null);
        this.gqJ = !bo.isNullOrNil(this.gqK);
        this.name = (String) g.RP().Ry().get(286722, null);
        this.status = r.YD();
        if ((this.status & 4194304) == 0) {
            z = false;
        }
        this.gqL = z;
        AppMethodBeat.o(13405);
    }

    public final void initView() {
        AppMethodBeat.i(13406);
        if (this.gqM) {
            setMMTitle(2131298572);
        } else if (this.gqN) {
            setMMTitle(2131298575);
        } else {
            setMMTitle(2131298565);
        }
        this.gqR = (TextView) findViewById(2131821756);
        this.gqS = (TextView) findViewById(2131821755);
        this.gqT = findViewById(2131821757);
        this.gqU = (MMSwitchBtn) findViewById(2131821758);
        this.gqV = (TextView) findViewById(2131821759);
        this.gqW = (TextView) findViewById(2131821760);
        this.gqX = (TextView) findViewById(2131821761);
        this.gqR.setOnClickListener(new 6(this));
        this.gqV.setOnClickListener(new 7(this));
        this.gqW.setOnClickListener(new 8(this));
        this.gqX.setOnClickListener(new 9(this));
        setBackBtn(new 10(this));
        cu();
        AppMethodBeat.o(13406);
    }

    private void goBack() {
        AppMethodBeat.i(13407);
        if (!this.gqM) {
            setResult(-1);
            finish();
            AppMethodBeat.o(13407);
        } else if (this.gqQ) {
            Intent bh = a.gkE.bh(this);
            bh.addFlags(603979776);
            bh.putExtra("preferred_tab", 2);
            startActivity(bh);
            AppMethodBeat.o(13407);
        } else {
            setResult(-1);
            finish();
            AppMethodBeat.o(13407);
        }
    }

    private void dh(boolean z) {
        AppMethodBeat.i(13408);
        if (this.gqO == null) {
            ab.e("MicroMsg.BindLinkedInUI", "bindBundle is null !!");
            AppMethodBeat.o(13408);
            return;
        }
        com.tencent.mm.plugin.account.bind.a.a aVar = new com.tencent.mm.plugin.account.bind.a.a(this.gqU.zMU ? 1 : 2, this.dun, this.duo, BuildConfig.FLAVOR, this.gqY, this.gqZ, this.gra, this.grb);
        if (!z) {
            this.fsh = h.b(this, getString(2131300968), false, new 11(this, aVar));
        }
        g.Rg().a(aVar, 0);
        AppMethodBeat.o(13408);
    }

    private void vK(String str) {
        AppMethodBeat.i(13409);
        int indexOf = getString(2131298559).indexOf("%s");
        Spannable newSpannable = Factory.getInstance().newSpannable(getString(2131298559, new Object[]{str}));
        newSpannable.setSpan(new 12(this), indexOf, str.length() + indexOf, 33);
        this.gqR.setText(newSpannable);
        AppMethodBeat.o(13409);
    }

    private void d(boolean z, String str, boolean z2) {
        AppMethodBeat.i(13410);
        this.gqR.setVisibility(0);
        vK(str);
        this.gqT.setVisibility(0);
        this.gqW.setVisibility(8);
        if (z) {
            this.gqS.setVisibility(8);
            this.gqV.setVisibility(8);
            this.gqX.setVisibility(8);
            this.gqU.setCheck(z2);
            this.gqU.setSwitchListener(new MMSwitchBtn.a() {
                public final void di(boolean z) {
                    AppMethodBeat.i(13400);
                    BindLinkedInUI.a(BindLinkedInUI.this, z, true);
                    AppMethodBeat.o(13400);
                }
            });
            AppMethodBeat.o(13410);
            return;
        }
        this.gqS.setVisibility(0);
        this.gqV.setVisibility(0);
        this.gqX.setVisibility(0);
        this.gqU.setCheck(z2);
        this.gqU.setSwitchListener(new 2(this));
        AppMethodBeat.o(13410);
    }

    private void a(boolean z, boolean z2, String str, boolean z3) {
        AppMethodBeat.i(13411);
        this.gqX.setVisibility(8);
        if (z) {
            this.gqS.setVisibility(8);
            this.gqR.setVisibility(0);
            vK(str);
            this.gqT.setVisibility(0);
            this.gqV.setVisibility(8);
            if (z2) {
                this.gqW.setVisibility(0);
            }
            this.gqU.setCheck(z3);
            this.gqU.setSwitchListener(new 3(this));
            AppMethodBeat.o(13411);
            return;
        }
        this.gqR.setVisibility(8);
        this.gqR.setText(getString(2131298560));
        this.gqS.setVisibility(0);
        this.gqT.setVisibility(8);
        this.gqV.setVisibility(0);
        this.gqW.setVisibility(8);
        AppMethodBeat.o(13411);
    }

    private void cu() {
        boolean z = true;
        AppMethodBeat.i(13412);
        if (this.gqM && this.gqO == null) {
            ab.e("MicroMsg.BindLinkedInUI", "bindBundle is null");
            AppMethodBeat.o(13412);
        } else if (this.gqN) {
            a(this.gqJ, false, this.name, this.gqL);
            AppMethodBeat.o(13412);
        } else if (this.gqM) {
            if (!(this.gqJ && this.gqK.equals(this.dun))) {
                z = false;
            }
            d(z, this.duo, this.gqL);
            AppMethodBeat.o(13412);
        } else {
            a(this.gqJ, true, this.name, this.gqL);
            AppMethodBeat.o(13412);
        }
    }

    private void m(boolean z, boolean z2) {
        AppMethodBeat.i(13413);
        if (z) {
            this.status |= 4194304;
        } else {
            this.status &= -4194305;
        }
        int i = z ? 1 : 2;
        g.RP().Ry().set(7, Integer.valueOf(this.status));
        if (z2) {
            act act = new act();
            act.wkw = 33;
            act.pvD = i;
            ((j) g.K(j.class)).XL().c(new com.tencent.mm.plugin.messenger.foundation.a.a.j.a(23, act));
            a.gkF.BS();
        }
        AppMethodBeat.o(13413);
    }

    private boolean w(Intent intent) {
        AppMethodBeat.i(13414);
        Bundle bundleExtra = intent.getBundleExtra("result_data");
        String string = bundleExtra.getString("ret");
        String string2 = bundleExtra.getString("limid");
        String string3 = bundleExtra.getString("liname");
        String string4 = bundleExtra.getString("liurl");
        String string5 = bundleExtra.getString("liswitch");
        if (bo.isNullOrNil(string)) {
            ab.e("MicroMsg.BindLinkedInUI", "linkedin oauth ret is null, maybe canceled");
            AppMethodBeat.o(13414);
            return false;
        }
        int ank = bo.ank(string);
        if (ank != 0) {
            int i;
            ab.e("MicroMsg.BindLinkedInUI", "linkedin oauth bind failed ret %s ", new Object[]{Integer.valueOf(ank)});
            if (ank == 1) {
                i = 2131298570;
            } else {
                i = 2131298569;
            }
            h.b(this, getString(i), null, true);
            AppMethodBeat.o(13414);
            return false;
        } else if (bo.isNullOrNil(string2)) {
            ab.e("MicroMsg.BindLinkedInUI", "linkedin member id is null");
            AppMethodBeat.o(13414);
            return false;
        } else {
            ab.d("MicroMsg.BindLinkedInUI", "%s, %s, %s, %s", new Object[]{string2, string3, string4, string5});
            g.RP().Ry().set(286722, string3);
            g.RP().Ry().set(286721, string2);
            g.RP().Ry().set(286723, string4);
            if (!bo.isNullOrNil(string5)) {
                m(bo.ank(string5) == 1, false);
            }
            Kh();
            cu();
            string5 = getString(2131298566);
            4 4 = new 4(this);
            h.bQ(this, string5);
            AppMethodBeat.o(13414);
            return true;
        }
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(13415);
        ab.d("MicroMsg.BindLinkedInUI", "onActivityResult . requestCode:" + i + "  resultCode:" + i2);
        if (intent == null) {
            AppMethodBeat.o(13415);
            return;
        }
        switch (i) {
            case 100:
                w(intent);
                AppMethodBeat.o(13415);
                return;
            default:
                ab.e("MicroMsg.BindLinkedInUI", "onActivityResult unknow request");
                AppMethodBeat.o(13415);
                return;
        }
    }

    public void onSceneEnd(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(13416);
        if (this.fsh != null) {
            this.fsh.dismiss();
            this.fsh = null;
        }
        int i3;
        if (i == 0 && i2 == 0) {
            if (mVar.getType() == 549) {
                this.gqQ = true;
                if (this.gqP) {
                    i3 = 2131298567;
                } else {
                    i3 = 2131298566;
                }
            } else if (mVar.getType() == e.CTRL_INDEX) {
                i3 = 2131298577;
            } else {
                AppMethodBeat.o(13416);
                return;
            }
            String string = getString(i3);
            5 5 = new 5(this);
            h.bQ(this, string);
            Kh();
            this.gqL = this.gqU.zMU;
            cu();
            AppMethodBeat.o(13416);
            return;
        }
        if (mVar.getType() == 549) {
            if (i2 == 1) {
                i3 = 2131298570;
            } else {
                i3 = 2131298569;
            }
        } else if (mVar.getType() == e.CTRL_INDEX) {
            i3 = 2131298571;
        } else {
            AppMethodBeat.o(13416);
            return;
        }
        h.b(this, getString(i3), null, true);
        AppMethodBeat.o(13416);
    }

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

    static /* synthetic */ void c(BindLinkedInUI bindLinkedInUI) {
        AppMethodBeat.i(13419);
        Intent intent = new Intent();
        intent.putExtra("rawUrl", "http://www.linkedin.com/bind/plugin/");
        intent.putExtra("geta8key_username", r.Yz());
        if (bindLinkedInUI.gqN) {
            intent.putExtra("geta8key_scene", 3);
        } else {
            intent.putExtra("geta8key_scene", 8);
        }
        d.b(bindLinkedInUI, "webview", "com.tencent.mm.plugin.webview.ui.tools.WebViewUI", intent, 100);
        AppMethodBeat.o(13419);
    }
}
