package com.tencent.mm.plugin.ipcall.ui;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.text.Spannable;
import android.text.Spannable.Factory;
import android.text.TextUtils;
import android.text.method.LinkMovementMethod;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.GridView;
import android.widget.ListView;
import android.widget.RelativeLayout;
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.bp.d;
import com.tencent.mm.model.aw;
import com.tencent.mm.plugin.ipcall.a.c;
import com.tencent.mm.plugin.ipcall.a.e.g;
import com.tencent.mm.plugin.ipcall.a.e.h;
import com.tencent.mm.plugin.ipcall.a.e.j;
import com.tencent.mm.plugin.ipcall.b.a;
import com.tencent.mm.pluginsdk.model.h$a;
import com.tencent.mm.protocal.protobuf.aqo;
import com.tencent.mm.protocal.protobuf.crt;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class IPCallRechargeUI extends MMActivity implements f {
    TextView kEq;
    private h$a lbF = new 1(this);
    private int lbo = -1;
    private String[] lbs;
    private ak mHandler = new 3(this);
    ProgressDialog nBv;
    private String[] nEc;
    private String[] nEd;
    private String nEe;
    private String nEf;
    private boolean nEg = false;
    private int nEh;
    private int nEi = -1;
    private String nEj;
    private String nEk;
    private h nEl = new h();
    private g nEm = new g();
    private j nEn = new j();
    RelativeLayout nEo;
    GridView nEp;
    ListView nEq;
    a nEr;
    Button nEs;
    com.tencent.mm.plugin.ipcall.a.d.f nEt;

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

    public IPCallRechargeUI() {
        AppMethodBeat.i(22268);
        AppMethodBeat.o(22268);
    }

    public final int getForceOrientation() {
        return 1;
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(22269);
        super.onCreate(bundle);
        aw.Rg().a(929, this);
        setMMTitle(2131300757);
        setBackBtn(new 5(this));
        addIconOptionMenu(0, 2130839555, new 6(this));
        this.nEo = (RelativeLayout) findViewById(2131824244);
        this.nEp = (GridView) findViewById(2131825189);
        this.nEq = (ListView) findViewById(2131825181);
        ViewGroup viewGroup = (ViewGroup) View.inflate(this.mController.ylL, 2130969904, null);
        this.nEq.addFooterView(viewGroup, null, false);
        this.nEr = new a(this);
        this.nEq.setAdapter(this.nEr);
        this.kEq = (TextView) viewGroup.findViewById(2131821051);
        this.nEs = (Button) findViewById(2131825190);
        String string = getString(2131300763);
        Spannable newSpannable = Factory.getInstance().newSpannable(string);
        newSpannable.setSpan(new 7(this), 0, string.length(), 33);
        this.kEq.setText(newSpannable);
        this.kEq.setMovementMethod(LinkMovementMethod.getInstance());
        AppCompatActivity appCompatActivity = this.mController.ylL;
        getString(2131297061);
        this.nBv = com.tencent.mm.ui.base.h.b(appCompatActivity, getString(2131300739), true, new 8(this));
        Ph(BuildConfig.FLAVOR);
        this.nEl.start();
        com.tencent.mm.plugin.report.service.h.pYm.a(257, 4, 1, true);
        AppMethodBeat.o(22269);
    }

    public void onDestroy() {
        AppMethodBeat.i(22270);
        super.onDestroy();
        this.nEl.nyL = bo.anU();
        this.nEl.finish();
        aw.Rg().b(929, this);
        AppMethodBeat.o(22270);
    }

    public final int getLayoutId() {
        return 2130969906;
    }

    private void Ph(String str) {
        String Pr;
        AppMethodBeat.i(22271);
        List bHf = c.bHc().bHf();
        if (bHf.size() == 0) {
            Pr = a.Pr(com.tencent.mm.plugin.ipcall.b.c.bIR());
        } else {
            Pr = a.Pr(((Integer) bHf.get(0)).toString());
        }
        this.nEt = new com.tencent.mm.plugin.ipcall.a.d.f(Pr, str);
        aw.Rg().a(this.nEt, 0);
        AppMethodBeat.o(22271);
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(22272);
        ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult. requestCode:[%d] resultCode:[%d]", new Object[]{Integer.valueOf(i), Integer.valueOf(i2)});
        boolean z;
        ArrayList stringArrayListExtra;
        if (i == 2001) {
            int intExtra;
            int intExtra2;
            String string;
            int i3;
            String str = BuildConfig.FLAVOR;
            z = false;
            if (intent != null) {
                intExtra = intent.getIntExtra("key_err_code", 0);
                String stringExtra = intent.getStringExtra("key_err_msg");
                long longExtra = intent.getLongExtra("key_launch_ts", 0);
                int intExtra3 = intent.getIntExtra("key_gw_error_code", 0);
                intExtra2 = intent.getIntExtra("key_response_position", 0);
                if (intExtra == 100000001) {
                    z = true;
                }
                ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult pay.errCode:[%d] errMsg:[%s] errGWCode:[%s] errPosition:[%d] isFailedConsume:[%s]", new Object[]{Integer.valueOf(intExtra), stringExtra, Integer.valueOf(intExtra3), Integer.valueOf(intExtra2), String.valueOf(z)});
                if (intExtra != 6 || intExtra3 == 0) {
                    this.nEm.nzd = (long) intExtra;
                } else {
                    this.nEm.nzd = (long) intExtra3;
                }
                if (intExtra2 == 3) {
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 9, 1, true);
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 11, 1, true);
                    this.nEm.nzd = 0;
                    this.nEm.nze = 2;
                    string = getString(2131300851);
                } else {
                    if (intExtra2 != 1) {
                        if (i2 == -1 && intExtra == 0) {
                            com.tencent.mm.plugin.report.service.h.pYm.a(257, 9, 1, true);
                            string = stringExtra;
                        } else if (z) {
                            com.tencent.mm.plugin.report.service.h.pYm.a(257, 9, 1, true);
                            com.tencent.mm.plugin.report.service.h.pYm.a(257, 12, 1, true);
                            this.nEm.nzd = 0;
                            this.nEm.nze = 1;
                        }
                    }
                    string = stringExtra;
                }
                this.nEm.nzc = longExtra;
                this.nEm.nyL = bo.anU();
                this.nEm.finish();
                i3 = intExtra3;
            } else {
                i3 = 0;
                intExtra2 = 0;
                intExtra = 0;
                string = str;
            }
            if (i2 == -1) {
                if (intent != null && intExtra == 0) {
                    stringArrayListExtra = intent.getStringArrayListExtra("key_response_product_ids");
                    intent.getStringArrayListExtra("key_response_series_ids");
                    Iterator it = stringArrayListExtra.iterator();
                    while (it.hasNext()) {
                        ab.i("MicroMsg.IPCallRechargeUI", "buy product ok productId:", new Object[]{bo.nullAsNil((String) it.next())});
                    }
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 6, 1, true);
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 10, 1, true);
                    Toast.makeText(this, 2131300814, 0).show();
                    finish();
                    AppMethodBeat.o(22272);
                    return;
                } else if (intent != null && intExtra == 100000002) {
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 6, 1, true);
                    JD(string);
                    AppMethodBeat.o(22272);
                    return;
                } else if (intent != null && intExtra == 109) {
                    JD(string);
                    AppMethodBeat.o(22272);
                    return;
                } else if (intent != null && intExtra == 1) {
                    string = getString(2131300812);
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 8, 1, true);
                    Toast.makeText(this, string, 0).show();
                    AppMethodBeat.o(22272);
                    return;
                } else if (intent == null || intExtra != 113) {
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 7, 1, true);
                    if (intExtra2 == 3) {
                        JD(string);
                        AppMethodBeat.o(22272);
                        return;
                    } else if (intExtra == 100000001 || intExtra == 6) {
                        if (i3 == 0) {
                            Toast.makeText(this, getString(2131300736), 0).show();
                            AppMethodBeat.o(22272);
                            return;
                        }
                        string = getString(2131300738);
                        if (!Pi(string)) {
                            Toast.makeText(this, string, 0).show();
                        }
                    }
                } else {
                    com.tencent.mm.ui.base.h.a(this, getString(2131300797), getString(2131300813), new 10(this));
                    AppMethodBeat.o(22272);
                    return;
                }
            }
            AppMethodBeat.o(22272);
            return;
        }
        if (i == 2002) {
            if (this.nBv != null && this.nBv.isShowing()) {
                this.nBv.dismiss();
            }
            String str2 = BuildConfig.FLAVOR;
            int i4 = 0;
            int i5 = 0;
            z = false;
            if (intent != null) {
                i4 = intent.getIntExtra("key_err_code", 0);
                str2 = intent.getStringExtra("key_err_msg");
                i5 = intent.getIntExtra("key_response_position", 0);
                if (i4 == 100000001) {
                    z = true;
                }
                ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult restore.errCode:[%d] errMsg:[%s] errPosition:[%d] isFailedConsume:[%s]", new Object[]{Integer.valueOf(i4), str2, Integer.valueOf(i5), String.valueOf(z)});
            }
            CharSequence charSequence = str2;
            this.nEn.nzm = (long) i4;
            this.nEn.nzk = 0;
            if (i2 != -1) {
                this.nEn.nzl = 2;
                ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult. restore failed");
                Toast.makeText(this, 2131300828, 0).show();
            } else if (intent == null || i4 != 0) {
                if (z) {
                    this.nEn.nzl = 1;
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 17, 1, true);
                    charSequence = getString(2131300829);
                } else if (i5 == 3) {
                    this.nEn.nzl = 2;
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 16, 1, true);
                } else {
                    this.nEn.nzl = 2;
                }
                ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult. restore not ok");
                Toast.makeText(this, charSequence, 0).show();
            } else {
                stringArrayListExtra = intent.getStringArrayListExtra("key_response_product_ids");
                if (stringArrayListExtra == null || stringArrayListExtra.size() <= 0) {
                    this.nEn.nzl = 3;
                    ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult. no product can be restored");
                    Toast.makeText(this, 2131300829, 0).show();
                } else {
                    this.nEn.nzl = 0;
                    com.tencent.mm.plugin.report.service.h.pYm.a(257, 15, 1, true);
                    ab.i("MicroMsg.IPCallRechargeUI", "onActivityResult. restore ok");
                    com.tencent.mm.ui.base.h.a(this, getString(2131300830), getString(2131300831), new 11(this));
                }
            }
            this.nEn.nyL = bo.anU();
            this.nEn.finish();
        }
        AppMethodBeat.o(22272);
    }

    private void JD(String str) {
        AppMethodBeat.i(22273);
        if (TextUtils.isEmpty(str)) {
            str = getString(2131300813);
        }
        com.tencent.mm.ui.base.h.a(this, str, getString(2131300813), new 12(this));
        AppMethodBeat.o(22273);
    }

    private boolean Pi(String str) {
        AppMethodBeat.i(22274);
        if (com.tencent.mm.plugin.ipcall.b.c.bIS() && this.nEi >= 0) {
            Object item = this.nEr.getItem(this.nEi);
            if ((item instanceof crt) && !bo.isNullOrNil(((crt) item).xpt)) {
                String str2 = ((crt) item).xpt;
                ab.i("MicroMsg.IPCallRechargeUI", "tryHandleShowWebViewPayDialog:".concat(String.valueOf(str2)));
                com.tencent.mm.ui.base.h.a(this, str, getString(2131300813), getString(2131300788), getString(2131296868), true, new 2(this, str2), null);
                AppMethodBeat.o(22274);
                return true;
            }
        }
        AppMethodBeat.o(22274);
        return false;
    }

    public void onSceneEnd(int i, int i2, String str, m mVar) {
        int i3 = 0;
        AppMethodBeat.i(22275);
        ab.i("MicroMsg.IPCallRechargeUI", "onSceneEnd>errCode:%d,onSceneEnd>errMsg:%s", new Object[]{Integer.valueOf(i2), str});
        if (mVar instanceof com.tencent.mm.plugin.ipcall.a.d.f) {
            h hVar = this.nEl;
            hVar.nzh = bo.anU();
            hVar.nzi = (long) i2;
            if (i == 0 && i2 == 0) {
                aqo aqo = ((com.tencent.mm.plugin.ipcall.a.d.f) mVar).nyq;
                this.nEr.ngC = aqo.CellList;
                this.nEr.nEx = aqo;
                this.nEr.notifyDataSetChanged();
                this.lbs = new String[aqo.CellList.size()];
                Iterator it = aqo.CellList.iterator();
                int i4 = 0;
                while (it.hasNext()) {
                    this.lbs[i4] = ((crt) it.next()).ProductID;
                    i4++;
                }
                this.nEj = aqo.wup;
                this.nEk = aqo.wuq;
                this.nEe = aqo.wuk;
                this.nEf = aqo.wuo;
                this.nEh = aqo.wun;
                if (this.nEg) {
                    this.nEd = new String[aqo.CellList.size()];
                    for (int i5 = 0; i5 < this.nEd.length; i5++) {
                        this.nEd[i5] = aqo.wuo;
                    }
                    this.nEc = new String[aqo.CellList.size()];
                    while (i3 < this.nEc.length) {
                        this.nEc[i3] = IPCallDynamicTextView.Pg(((crt) aqo.CellList.get(i3)).wOs);
                        i3++;
                    }
                }
                if (((com.tencent.mm.plugin.ipcall.a.d.f) mVar).nyr) {
                    ab.i("MicroMsg.IPCallRechargeUI", "onSceneEnd IsUnkownCurency=true");
                    if (this.lbs != null && this.lbs.length > 0) {
                        ab.i("MicroMsg.IPCallRechargeUI", "startQueryGooglePrice");
                        com.tencent.mm.pluginsdk.model.h.a(this, this.lbs, this.lbF);
                    }
                    AppMethodBeat.o(22275);
                    return;
                }
                if (this.nBv != null && this.nBv.isShowing()) {
                    this.nBv.dismiss();
                }
                bIt();
                AppMethodBeat.o(22275);
                return;
            }
            if (this.nBv != null && this.nBv.isShowing()) {
                this.nBv.dismiss();
            }
            Toast.makeText(this.mController.ylL, getString(2131300736), 0).show();
            finish();
        }
        AppMethodBeat.o(22275);
    }

    public final void bIt() {
        AppMethodBeat.i(22276);
        if (this.mHandler != null) {
            this.mHandler.sendEmptyMessage(1002);
        }
        AppMethodBeat.o(22276);
    }

    static /* synthetic */ void h(IPCallRechargeUI iPCallRechargeUI) {
        AppMethodBeat.i(22278);
        com.tencent.mm.ui.base.h.a(iPCallRechargeUI.mController.ylL, null, null, iPCallRechargeUI.getResources().getString(2131300827), false, new 9(iPCallRechargeUI));
        AppMethodBeat.o(22278);
    }

    static /* synthetic */ void j(IPCallRechargeUI iPCallRechargeUI) {
        AppMethodBeat.i(22279);
        if (iPCallRechargeUI.nEr != null) {
            iPCallRechargeUI.nEr.ngC = null;
            iPCallRechargeUI.nEr.notifyDataSetChanged();
        }
        if (iPCallRechargeUI.nEq != null) {
            iPCallRechargeUI.nEq.setVisibility(4);
        }
        if (iPCallRechargeUI.nBv != null) {
            iPCallRechargeUI.nBv.show();
        }
        iPCallRechargeUI.Ph(BuildConfig.FLAVOR);
        AppMethodBeat.o(22279);
    }

    static /* synthetic */ void k(IPCallRechargeUI iPCallRechargeUI) {
        AppMethodBeat.i(22280);
        if (!(bo.isNullOrNil(iPCallRechargeUI.nEj) || bo.isNullOrNil(iPCallRechargeUI.nEk))) {
            ab.i("MicroMsg.IPCallRechargeUI", "showGotoExchangeRecordsAlert");
            com.tencent.mm.ui.base.h.a(iPCallRechargeUI, iPCallRechargeUI.nEk, iPCallRechargeUI.nEj, iPCallRechargeUI.getString(2131300758), iPCallRechargeUI.getString(2131300759), false, null, new OnClickListener() {
                public final void onClick(DialogInterface dialogInterface, int i) {
                    AppMethodBeat.i(22254);
                    IPCallRechargeUI.this.finish();
                    Intent intent = new Intent();
                    intent.putExtra("rawUrl", IPCallRechargeUI.this.getString(2131300728));
                    intent.putExtra("showShare", false);
                    d.b(IPCallRechargeUI.this, "webview", ".ui.tools.WebViewUI", intent);
                    AppMethodBeat.o(22254);
                }
            });
        }
        AppMethodBeat.o(22280);
    }
}
