package com.tencent.mm.plugin.wallet_core.ui.view;

import android.content.Context;
import android.content.Intent;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.widget.LinearLayout;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.au.b;
import com.tencent.mm.au.b.a;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.mm.ui.MMActivity;
import com.tencent.mm.wallet_core.ui.formview.WalletFormView;
import com.tencent.ytcommon.BuildConfig;
import com.tenpay.android.wechat.TenpaySecureEditText;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class WalletPhoneInputView extends LinearLayout {
    private int mMode = 0;
    private WalletFormView tNO;
    private WalletFormView tNP;
    private TenpaySecureEditText tNQ;
    private Map<String, a> tNR;
    private String tNS = BuildConfig.FLAVOR;
    private String tNT = BuildConfig.FLAVOR;
    private boolean tNU = true;

    public WalletPhoneInputView(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        AppMethodBeat.i(47913);
        init(context);
        a(context, attributeSet, -1);
        AppMethodBeat.o(47913);
    }

    public WalletPhoneInputView(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet, i);
        AppMethodBeat.i(47914);
        init(context);
        a(context, attributeSet, i);
        AppMethodBeat.o(47914);
    }

    private void init(Context context) {
        AppMethodBeat.i(47915);
        inflate(context, 2130971154, this);
        this.tNO = (WalletFormView) findViewById(2131829014);
        this.tNP = (WalletFormView) findViewById(2131829015);
        this.tNO.setOnClickListener(new 1(this));
        this.tNQ = (TenpaySecureEditText) this.tNP.findViewById(2131829013);
        this.tNQ.setFixedHeaderText("+");
        if (getContext() instanceof MMActivity) {
            this.tNP.setOnInfoIvClickListener(new 2(this));
            this.tNP.setLogicDelegate(new 3(this));
        }
        List<a> G = b.G(getContext(), getContext().getString(2131298789));
        this.tNR = new HashMap();
        for (a aVar : G) {
            this.tNR.put(aVar.fHD, aVar);
        }
        AppMethodBeat.o(47915);
    }

    private void a(Context context, AttributeSet attributeSet, int i) {
        AppMethodBeat.i(47916);
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, com.tencent.mm.plugin.wxpay.a.a.WalletPhoneInputViewAttrs, i, 0);
        int resourceId = obtainStyledAttributes.getResourceId(0, 0);
        if (resourceId != 0) {
            this.tNP.setHint(context.getString(resourceId));
        }
        int resourceId2 = obtainStyledAttributes.getResourceId(1, 0);
        if (resourceId2 != 0) {
            this.tNP.setTitleText(context.getString(resourceId2));
        }
        AppMethodBeat.o(47916);
    }

    public WalletFormView getPhoneNumberEt() {
        return this.tNP;
    }

    public String getCountryCode() {
        AppMethodBeat.i(47917);
        String str;
        if (cSA()) {
            str = "86";
            AppMethodBeat.o(47917);
            return str;
        }
        str = this.tNQ.getText().toString();
        AppMethodBeat.o(47917);
        return str;
    }

    public final boolean e(int i, int i2, Intent intent) {
        AppMethodBeat.i(47918);
        if (i == 65521) {
            if (i2 == 100) {
                String stringExtra = intent.getStringExtra("country_name");
                String stringExtra2 = intent.getStringExtra("couttry_code");
                ab.i("MicroMsg.WalletPhoneInputView", "countryName: %s, countryCode: %s", new Object[]{this.tNS, this.tNT});
                if (bo.isNullOrNil(stringExtra) || bo.isNullOrNil(stringExtra2)) {
                    ab.i("MicroMsg.WalletPhoneInputView", "cancel pick");
                    AppMethodBeat.o(47918);
                    return true;
                }
                this.tNS = stringExtra;
                this.tNT = stringExtra2;
                this.tNU = false;
                cSy();
                this.tNQ.clearFocus();
            }
            AppMethodBeat.o(47918);
            return true;
        }
        AppMethodBeat.o(47918);
        return false;
    }

    private void cSy() {
        AppMethodBeat.i(47919);
        this.tNO.setText(this.tNS);
        this.tNQ.setText(this.tNT);
        AppMethodBeat.o(47919);
    }

    private void cSz() {
        AppMethodBeat.i(47920);
        a aVar = (a) this.tNR.get("86");
        this.tNT = aVar.fHD;
        this.tNS = aVar.fHE;
        cSy();
        AppMethodBeat.o(47920);
    }

    public final boolean cSA() {
        return this.mMode == 0;
    }

    public final void cSB() {
        AppMethodBeat.i(47921);
        this.mMode = 0;
        cSz();
        this.tNO.setVisibility(8);
        this.tNQ.setVisibility(8);
        AppMethodBeat.o(47921);
    }

    public final void cSC() {
        AppMethodBeat.i(47922);
        this.mMode = 1;
        cSz();
        this.tNO.setVisibility(0);
        this.tNQ.setVisibility(0);
        this.tNQ.addTextChangedListener(new 4(this));
        this.tNQ.setOnFocusChangeListener(new 5(this));
        AppMethodBeat.o(47922);
    }
}
