package com.tencent.mm.plugin.luckymoney.sns;

import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.ai.m;
import com.tencent.mm.plugin.luckymoney.model.ag;
import com.tencent.mm.plugin.luckymoney.model.ao;
import com.tencent.mm.plugin.luckymoney.model.ar;
import com.tencent.mm.plugin.luckymoney.model.i;
import com.tencent.mm.plugin.luckymoney.model.x;
import com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyBaseUI;
import com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyMoneyInputView;
import com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyMyRecordUI;
import com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyNumInputView;
import com.tencent.mm.plugin.luckymoney.ui.LuckyMoneyTextInputView;
import com.tencent.mm.plugin.luckymoney.ui.b;
import com.tencent.mm.plugin.luckymoney.ui.g;
import com.tencent.mm.plugin.luckymoney.ui.h.c;
import com.tencent.mm.plugin.report.service.h;
import com.tencent.mm.plugin.wallet_core.ui.j;
import com.tencent.mm.pluginsdk.wallet.PayInfo;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.ak;
import com.tencent.mm.sdk.platformtools.ap;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.sdk.platformtools.br;
import com.tencent.mm.ui.base.a;
import com.tencent.mm.wallet_core.ui.e;
import com.tencent.ytcommon.BuildConfig;
import com.tenpay.android.wechat.MyKeyboardWindow;
import java.util.Map;

@a(19)
public class SnsLuckyMoneyPrepareUI extends LuckyMoneyBaseUI implements g {
    private ap gGo = null;
    protected Dialog gII = null;
    private ScrollView hJh;
    protected TextView kGm = null;
    private TextView kGq;
    protected Button leS = null;
    protected MyKeyboardWindow mKeyboard;
    private int mType;
    private i nSs;
    protected LuckyMoneyNumInputView nTd = null;
    protected LuckyMoneyTextInputView nTf = null;
    protected Button nTg = null;
    protected View nTi;
    private TextView nTl;
    private b nTn = new b();
    protected LuckyMoneyMoneyInputView obC = null;
    private View obD;
    private View obE;
    private ViewGroup obF;
    private int obG;
    private String obH;
    private int obI;
    private boolean obJ;
    private String obK;
    private int obL;
    private com.tencent.mm.wallet_core.ui.a obM;

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

    public SnsLuckyMoneyPrepareUI() {
        AppMethodBeat.i(42532);
        AppMethodBeat.o(42532);
    }

    static /* synthetic */ int d(SnsLuckyMoneyPrepareUI snsLuckyMoneyPrepareUI) {
        AppMethodBeat.i(42544);
        int bMh = snsLuckyMoneyPrepareUI.bMh();
        AppMethodBeat.o(42544);
        return bMh;
    }

    static /* synthetic */ void n(SnsLuckyMoneyPrepareUI snsLuckyMoneyPrepareUI) {
        AppMethodBeat.i(42546);
        snsLuckyMoneyPrepareUI.bMp();
        AppMethodBeat.o(42546);
    }

    static /* synthetic */ void o(SnsLuckyMoneyPrepareUI snsLuckyMoneyPrepareUI) {
        AppMethodBeat.i(42547);
        snsLuckyMoneyPrepareUI.bMp();
        AppMethodBeat.o(42547);
    }

    public void onCreate(Bundle bundle) {
        AppMethodBeat.i(42533);
        super.onCreate(bundle);
        this.mType = getIntent().getIntExtra("key_type", 1);
        this.obG = getIntent().getIntExtra("key_way", 3);
        this.obJ = getIntent().getIntExtra("key_from", 0) == 1;
        this.obL = getIntent().getIntExtra("pay_channel", -1);
        b(new ag("v1.0", 0, (byte) 0), false);
        com.tencent.mm.plugin.luckymoney.b.a.bKN();
        this.nSs = com.tencent.mm.plugin.luckymoney.b.a.bKO().bLu();
        ab.d("MicroMsg.LuckyMoneyPrepareUI", "type=" + this.mType + ", fromAppPanel=" + this.obJ + ", config " + this.nSs);
        initView();
        h.pYm.e(11701, new Object[]{Integer.valueOf(4), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(bMh()), Integer.valueOf(1)});
        AppMethodBeat.o(42533);
    }

    public final void initView() {
        AppMethodBeat.i(42534);
        getResources().getDrawable(2130839226);
        setBackBtn(new 1(this));
        this.obD = findViewById(2131825633);
        this.obE = findViewById(2131825638);
        this.leS = (Button) findViewById(2131825637);
        this.nTf = (LuckyMoneyTextInputView) findViewById(2131825621);
        this.nTf.setHintText(getString(2131301090));
        this.nTg = (Button) findViewById(2131825630);
        this.mKeyboard = (MyKeyboardWindow) findViewById(2131822357);
        this.nTi = findViewById(2131822356);
        this.kGq = (TextView) findViewById(2131825618);
        this.nTd = (LuckyMoneyNumInputView) findViewById(2131825619);
        this.obC = (LuckyMoneyMoneyInputView) findViewById(2131825617);
        this.kGm = (TextView) findViewById(2131825629);
        this.obF = (ViewGroup) findViewById(2131825632);
        this.hJh = (ScrollView) findViewById(2131825615);
        this.nTl = (TextView) findViewById(2131825616);
        if (this.mType == 1) {
            this.obC.setTitle(getString(2131301211));
            this.obC.setShowGroupIcon(true);
        } else {
            this.obC.setTitle(getString(2131301212));
            this.obC.setShowGroupIcon(false);
        }
        this.obC.setOnInputValidChangerListener(this);
        this.nTd.setOnInputValidChangerListener(this);
        this.nTf.setOnInputValidChangerListener(this);
        EditText editText = (EditText) this.obC.findViewById(2131825536);
        EditText editText2 = (EditText) this.nTd.findViewById(2131825536);
        e.setNoSystemInputOnEditText(editText);
        ((InputMethodManager) this.mController.ylL.getSystemService("input_method")).showSoftInput(editText, 0);
        editText.setOnClickListener(new 19(this, editText, editText2));
        TextView textView = (TextView) this.obC.findViewById(2131825537);
        if (textView != null) {
            textView.setOnClickListener(new 20(this, editText, editText2));
        }
        e.setNoSystemInputOnEditText(editText2);
        ((InputMethodManager) this.mController.ylL.getSystemService("input_method")).showSoftInput(editText2, 0);
        editText2.setOnClickListener(new 21(this, editText, editText2));
        if (this.nSs != null) {
            if (this.mType == 1) {
                this.obC.setMaxAmount(this.nSs.nRR);
            } else {
                this.obC.setMaxAmount(this.nSs.nRP);
            }
            this.obC.setMinAmount(this.nSs.nRQ);
        }
        if (!this.obJ || getIntent().getIntExtra("key_chatroom_num", 0) > 1) {
            this.nTd.setNum(BuildConfig.FLAVOR);
        } else {
            this.nTd.setNum("1");
        }
        this.nTd.setMaxNum(this.nSs.nRO);
        this.nTd.setMinNum(1);
        ab.d("MicroMsg.LuckyMoneyPrepareUI", "init num=" + this.nTd.getInput());
        this.obC.setMaxLen(12);
        if (this.obJ) {
            if (getIntent().getIntExtra("key_chatroom_num", 0) > 0) {
                String string = getString(2131301124);
                String string2 = getString(2131301121);
                String string3 = getString(2131301123);
                String string4 = getString(2131301122);
                SpannableString spannableString = new SpannableString(string + string2);
                j jVar = new j(this);
                spannableString.setSpan(jVar, string.length(), string.length() + string2.length(), 33);
                SpannableString spannableString2 = new SpannableString(string3 + string4);
                j jVar2 = new j(this);
                spannableString2.setSpan(jVar2, string3.length(), string3.length() + string4.length(), 33);
                jVar.tHw = new 11(this, spannableString2);
                jVar2.tHw = new 15(this, spannableString);
                this.kGq.setMovementMethod(LinkMovementMethod.getInstance());
                this.kGq.setText(spannableString);
                this.kGq.setVisibility(0);
            } else {
                this.nTd.setVisibility(8);
            }
        } else if (this.mType == 1) {
            this.kGq.setText(this.nSs.nWH);
            this.kGq.setVisibility(0);
        } else if (this.mType == 0) {
            this.kGq.setText(this.nSs.nWI);
            this.kGq.setVisibility(0);
        }
        this.nTg.setOnClickListener(new 16(this));
        this.kGm.setText(e.G(0.0d));
        this.nTn.a(this.nTd);
        this.nTn.a(this.obC);
        this.nTn.a(this.nTf);
        this.nTn.i((TextView) findViewById(2131825639));
        if (this.obJ && this.mType == 1) {
            TextView textView2 = (TextView) findViewById(2131825620);
            textView2.setText(getString(2131301149, new Object[]{Integer.valueOf(getIntent().getIntExtra("key_chatroom_num", 8))}));
            textView2.setVisibility(0);
        }
        this.gGo = new ap(new 17(this), false);
        if (this.hJh != null) {
            this.hJh.setOnTouchListener(new 18(this));
        }
        this.obC.setType(this.mType);
        if (this.obJ && getIntent().getIntExtra("key_chatroom_num", 0) == 0) {
            this.obC.requestFocus();
            AppMethodBeat.o(42534);
            return;
        }
        this.nTd.requestFocus();
        AppMethodBeat.o(42534);
    }

    public void onDestroy() {
        AppMethodBeat.i(42535);
        super.onDestroy();
        this.nTn.clear();
        this.gGo.doT();
        if (this.gII != null && this.gII.isShowing()) {
            this.gII.dismiss();
        }
        AppMethodBeat.o(42535);
    }

    public final int getLayoutId() {
        return 2130969994;
    }

    public boolean dispatchKeyEvent(KeyEvent keyEvent) {
        AppMethodBeat.i(42536);
        if (keyEvent.getKeyCode() == 4 && this.obD.getVisibility() == 0) {
            this.obD.setVisibility(8);
            bMp();
            AppMethodBeat.o(42536);
            return true;
        }
        boolean dispatchKeyEvent = super.dispatchKeyEvent(keyEvent);
        AppMethodBeat.o(42536);
        return dispatchKeyEvent;
    }

    public final boolean c(int i, int i2, String str, m mVar) {
        AppMethodBeat.i(42537);
        if (mVar instanceof ao) {
            if (this.gII != null && this.gII.isShowing()) {
                this.gII.hide();
            }
            if (i == 0 && i2 == 0) {
                ao aoVar = (ao) mVar;
                this.obI = aoVar.kCd;
                this.obH = aoVar.nSX;
                this.obK = aoVar.nYY;
                PayInfo payInfo = new PayInfo();
                payInfo.czZ = aoVar.nYX;
                payInfo.cIf = 37;
                payInfo.cIb = this.obL;
                com.tencent.mm.pluginsdk.wallet.h.a(this, payInfo, 1);
                AppMethodBeat.o(42537);
                return true;
            } else if (i2 == 401) {
                this.nTg.setEnabled(false);
                this.nTg.setClickable(false);
                this.gGo.ae(5000, 5000);
                com.tencent.mm.ui.base.h.bQ(this, str);
                AppMethodBeat.o(42537);
                return true;
            } else {
                com.tencent.mm.ui.base.h.bQ(this, str);
                AppMethodBeat.o(42537);
                return true;
            }
        }
        if (mVar instanceof ar) {
            if (i == 0 && i2 == 0) {
                if (this.obJ) {
                    com.tencent.mm.ui.base.h.bQ(this, getString(2131300520));
                    finish();
                } else {
                    bMq();
                    this.obE.postDelayed(new 2(this), 1000);
                }
                AppMethodBeat.o(42537);
                return true;
            } else if (i2 == 402) {
                com.tencent.mm.ui.base.h.d(this.mController.ylL, str, BuildConfig.FLAVOR, getString(2131301191), getString(2131296868), new 3(this), new 4(this));
                AppMethodBeat.o(42537);
                return true;
            }
        } else if (mVar instanceof ag) {
            if (i == 0 && i2 == 0) {
                ag agVar = (ag) mVar;
                com.tencent.mm.plugin.luckymoney.b.a.bKN();
                this.nSs = com.tencent.mm.plugin.luckymoney.b.a.bKO().bLu();
                ab.d("MicroMsg.LuckyMoneyPrepareUI", "update config:" + this.nSs);
                if (this.mType == 1) {
                    this.obC.setMaxAmount(this.nSs.nRR);
                } else {
                    this.obC.setMaxAmount(this.nSs.nRP);
                }
                this.obC.setMinAmount(this.nSs.nRQ);
                this.nTd.setMaxNum(this.nSs.nRO);
                if (agVar.nYE && this.obJ) {
                    TextView textView = (TextView) findViewById(2131825631);
                    textView.setOnClickListener(new 5(this));
                    h.pYm.e(11701, new Object[]{Integer.valueOf(4), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(bMh()), Integer.valueOf(8)});
                    textView.setVisibility(0);
                }
                if (bo.isNullOrNil(agVar.kCx)) {
                    this.nTl.setVisibility(8);
                } else {
                    ab.i("MicroMsg.LuckyMoneyPrepareUI", "Put notice :" + agVar.kCx);
                    this.nTl.setText(agVar.kCx);
                    if (!bo.isNullOrNil(agVar.nYG)) {
                        this.nTl.setOnClickListener(new 6(this, agVar));
                    }
                    this.nTl.setVisibility(0);
                }
                c cVar = new c();
                cVar.textColor = getResources().getColor(2131690631);
                com.tencent.mm.plugin.luckymoney.ui.h.a(this, this.obF, agVar.nYI, cVar);
            }
            AppMethodBeat.o(42537);
            return true;
        }
        AppMethodBeat.o(42537);
        return false;
    }

    public void onActivityResult(int i, int i2, Intent intent) {
        AppMethodBeat.i(42538);
        String str;
        switch (i) {
            case 1:
                if (i2 == -1) {
                    h.pYm.e(11701, new Object[]{Integer.valueOf(4), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(bMh()), Integer.valueOf(5)});
                    String stringExtra = getIntent().getStringExtra("key_username");
                    if (this.obJ && !bo.isNullOrNil(stringExtra)) {
                        com.tencent.mm.ui.base.h.bQ(this, getString(2131300520));
                        Map z = br.z(this.obK, "msg");
                        if (z != null) {
                            str = (String) z.get(".msg.appmsg.wcpayinfo.paymsgid");
                            if (com.tencent.mm.plugin.luckymoney.b.a.bKN().bKQ().Qh(str)) {
                                ab.i("MicroMsg.LuckyMoneyPrepareUI", "insert a local msg for luckymoney");
                                if (!x.E(this.obK, stringExtra, 1)) {
                                    ab.e("MicroMsg.LuckyMoneyPrepareUI", "LuckyMoneyUtil.sendLocalMsg fail!");
                                    com.tencent.mm.plugin.luckymoney.b.a.bKN().bKQ().Qi(str);
                                }
                            } else {
                                ab.e("MicroMsg.LuckyMoneyPrepareUI", "it is a duplicate msg");
                            }
                            finish();
                            break;
                        }
                        ab.e("MicroMsg.LuckyMoneyPrepareUI", "luckymoneyPrepareUI onActivityResult values is null");
                        finish();
                        AppMethodBeat.o(42538);
                        return;
                    }
                    bMq();
                    new ak().postDelayed(new 7(this), 200);
                    this.leS.setOnClickListener(new 8(this));
                    ((ImageView) findViewById(2131825636)).setOnClickListener(new 9(this));
                    break;
                }
                break;
            case 2:
                if (i2 != -1 || intent == null) {
                    if (i2 == 0) {
                        Intent intent2 = new Intent();
                        intent2.setClass(this.mController.ylL, LuckyMoneyMyRecordUI.class);
                        intent2.putExtra("key_type", 1);
                        startActivity(intent2);
                        break;
                    }
                }
                str = intent.getStringExtra("Select_Conv_User");
                h.pYm.e(11701, new Object[]{Integer.valueOf(4), Integer.valueOf(0), Integer.valueOf(0), Integer.valueOf(bMh()), Integer.valueOf(7), str});
                if (!bo.isNullOrNil(str)) {
                    n(new ar(str.replaceAll(",", "|"), this.obH, "v1.0"));
                    break;
                } else {
                    finish();
                    break;
                }
                break;
        }
        super.onActivityResult(i, i2, intent);
        AppMethodBeat.o(42538);
    }

    /* Access modifiers changed, original: protected|final */
    public final void V(View view, int i) {
        AppMethodBeat.i(42539);
        this.mKeyboard = (MyKeyboardWindow) findViewById(2131822357);
        this.nTi = findViewById(2131822356);
        View findViewById = findViewById(2131822358);
        EditText editText = (EditText) view.findViewById(2131825536);
        if (this.mKeyboard == null || editText == null || this.nTi == null) {
            AppMethodBeat.o(42539);
            return;
        }
        e.setNoSystemInputOnEditText(editText);
        editText.setOnFocusChangeListener(new 10(this, i, editText));
        editText.setOnClickListener(new 12(this, i, editText));
        TextView textView = (TextView) view.findViewById(2131825537);
        if (textView != null) {
            textView.setOnClickListener(new 13(this, i, editText));
        }
        findViewById.setOnClickListener(new 14(this));
        AppMethodBeat.o(42539);
    }

    public boolean onKeyUp(int i, KeyEvent keyEvent) {
        AppMethodBeat.i(42540);
        if (i == 4 && this.nTi != null && this.nTi.isShown()) {
            aoB();
            AppMethodBeat.o(42540);
            return true;
        }
        boolean onKeyUp = super.onKeyUp(i, keyEvent);
        AppMethodBeat.o(42540);
        return onKeyUp;
    }

    /* Access modifiers changed, original: protected|final */
    public final void aoB() {
        AppMethodBeat.i(42541);
        if (this.nTi != null && this.nTi.isShown()) {
            this.nTi.setVisibility(8);
            this.obM.ic(false);
        }
        AppMethodBeat.o(42541);
    }

    public final void bLa() {
        double d;
        double d2;
        int input;
        AppMethodBeat.i(42542);
        com.tencent.mm.plugin.luckymoney.b.a.bKN();
        this.nSs = com.tencent.mm.plugin.luckymoney.b.a.bKO().bLu();
        if (this.obC.bKW() == 3 || this.nTd.bKW() == 3) {
            d = 0.0d;
            d2 = 0.0d;
        } else {
            input = this.nTd.getInput();
            d2 = this.obC.getInput();
            if (this.mType == 0) {
                d2 *= (double) input;
                d = this.obC.getInput();
            } else {
                d = input > 0 ? this.obC.getInput() / ((double) input) : 0.0d;
            }
        }
        if (this.nTn.bMy()) {
            this.nTg.setClickable(false);
            this.nTg.setEnabled(false);
        } else {
            if (d2 == 0.0d || d == 0.0d) {
                input = 1;
            } else if (d2 > this.nSs.nRR && this.nSs.nRR > 0.0d) {
                this.nTn.Dv(getString(2131301210, new Object[]{Math.round(this.nSs.nRR), bo.bc(this.nSs.nRU, BuildConfig.FLAVOR)}));
                input = 1;
            } else if (d > 0.0d) {
                int i;
                boolean i2;
                if (this.mType == 0) {
                    if (d > this.nSs.nRP && this.nSs.nRP > 0.0d) {
                        this.nTn.Dv(getString(2131301161, new Object[]{Math.round(this.nSs.nRP), bo.bc(this.nSs.nRU, BuildConfig.FLAVOR)}));
                        i2 = 1;
                    }
                    i2 = false;
                } else {
                    if (d > this.nSs.nRS && this.nSs.nRS > 0.0d) {
                        this.nTn.Dv(getString(2131301161, new Object[]{Math.round(this.nSs.nRS), bo.bc(this.nSs.nRU, BuildConfig.FLAVOR)}));
                        this.nTd.onError();
                        this.obC.onError();
                        i2 = 1;
                    }
                    i2 = false;
                }
                if (i2 == 0) {
                    if (this.mType == 0) {
                        if (d < this.nSs.nRQ) {
                            this.nTn.Dv(getString(2131301163, new Object[]{e.F(this.nSs.nRQ), bo.bc(this.nSs.nRU, BuildConfig.FLAVOR)}));
                            input = 1;
                        }
                    } else if (d < 0.01d) {
                        this.nTn.Dv(getString(2131301163, new Object[]{"0.01", bo.bc(this.nSs.nRU, BuildConfig.FLAVOR)}));
                        this.nTd.onError();
                        this.obC.onError();
                        input = 1;
                    }
                }
                input = i2;
            } else {
                boolean z = false;
            }
            if (input != 0) {
                this.nTg.setClickable(false);
                this.nTg.setEnabled(false);
            } else {
                this.nTg.setClickable(true);
                this.nTg.setEnabled(true);
            }
        }
        this.kGm.setText(e.G(d2));
        AppMethodBeat.o(42542);
    }

    private int bMh() {
        AppMethodBeat.i(42543);
        if (!this.obJ) {
            AppMethodBeat.o(42543);
            return 3;
        } else if (getIntent().getIntExtra("key_chatroom_num", 0) > 0) {
            AppMethodBeat.o(42543);
            return 2;
        } else {
            AppMethodBeat.o(42543);
            return 1;
        }
    }

    static /* synthetic */ void k(SnsLuckyMoneyPrepareUI snsLuckyMoneyPrepareUI) {
        AppMethodBeat.i(42545);
        if (!(snsLuckyMoneyPrepareUI.nTi == null || snsLuckyMoneyPrepareUI.nTi.isShown())) {
            snsLuckyMoneyPrepareUI.nTi.setVisibility(0);
            snsLuckyMoneyPrepareUI.obM.ic(true);
        }
        AppMethodBeat.o(42545);
    }

    static /* synthetic */ void b(SnsLuckyMoneyPrepareUI snsLuckyMoneyPrepareUI, int i) {
        AppMethodBeat.i(42548);
        snsLuckyMoneyPrepareUI.mKeyboard.setXMode(i);
        AppMethodBeat.o(42548);
    }
}
