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

import android.content.Context;
import android.content.res.TypedArray;
import android.telephony.PhoneNumberUtils;
import android.text.InputFilter;
import android.text.InputFilter.LengthFilter;
import android.text.SpannableStringBuilder;
import android.text.TextUtils.TruncateAt;
import android.text.method.KeyListener;
import android.text.style.ForegroundColorSpan;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnFocusChangeListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AutoCompleteTextView;
import android.widget.BaseAdapter;
import android.widget.Filter;
import android.widget.Filterable;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.TextView.OnEditorActionListener;
import com.tencent.matrix.trace.core.AppMethodBeat;
import com.tencent.mm.kernel.g;
import com.tencent.mm.plugin.recharge.model.b;
import com.tencent.mm.sdk.platformtools.ab;
import com.tencent.mm.sdk.platformtools.bo;
import com.tencent.ytcommon.BuildConfig;
import java.util.ArrayList;
import java.util.List;

public class MallEditText extends LinearLayout implements OnFocusChangeListener {
    private OnFocusChangeListener gJD;
    private ImageView gJG;
    private String gJH;
    private String gJI;
    private int gJJ;
    public boolean gJL;
    private boolean gJN;
    private int gJO;
    private int gJP;
    private TextView goa;
    private int gravity;
    private boolean hNO;
    private int imeOptions;
    private int inputType;
    private int pGA;
    private b pGs;
    AutoCompleteTextView pGt;
    boolean pGu;
    private a pGv;
    private List<String[]> pGw;
    private com.tencent.mm.plugin.recharge.model.a pGx;
    private Runnable pGy;
    private boolean pGz;

    class a extends BaseAdapter implements Filterable {
        public List<com.tencent.mm.plugin.recharge.model.a> pGC;
        public boolean pGD;
        private List<com.tencent.mm.plugin.recharge.model.a> pGE;
        private a pGF;
        private String pGG;

        private a() {
            AppMethodBeat.i(44219);
            this.pGC = new ArrayList();
            this.pGD = false;
            AppMethodBeat.o(44219);
        }

        /* synthetic */ a(MallEditText mallEditText, byte b) {
            this();
        }

        public final /* synthetic */ Object getItem(int i) {
            AppMethodBeat.i(44226);
            com.tencent.mm.plugin.recharge.model.a BA = BA(i);
            AppMethodBeat.o(44226);
            return BA;
        }

        public final void cK(List<com.tencent.mm.plugin.recharge.model.a> list) {
            AppMethodBeat.i(44220);
            this.pGE = list;
            this.pGC.clear();
            this.pGD = false;
            AppMethodBeat.o(44220);
        }

        public final Filter getFilter() {
            AppMethodBeat.i(44221);
            ab.d("MicroMsg.MallEditText", "getFilter");
            if (this.pGF == null) {
                this.pGF = new a(this, (byte) 0);
            }
            a aVar = this.pGF;
            AppMethodBeat.o(44221);
            return aVar;
        }

        public final int getCount() {
            AppMethodBeat.i(44222);
            int size;
            if (this.pGD) {
                size = this.pGC.size() + 2;
                AppMethodBeat.o(44222);
                return size;
            } else if (this.pGC.size() > 0) {
                size = this.pGC.size() + 1;
                AppMethodBeat.o(44222);
                return size;
            } else {
                AppMethodBeat.o(44222);
                return 0;
            }
        }

        public final synchronized com.tencent.mm.plugin.recharge.model.a BA(int i) {
            com.tencent.mm.plugin.recharge.model.a aVar = null;
            synchronized (this) {
                AppMethodBeat.i(44223);
                if (this.pGD) {
                    if (i == 0) {
                        AppMethodBeat.o(44223);
                    } else if (i <= this.pGC.size()) {
                        aVar = (com.tencent.mm.plugin.recharge.model.a) this.pGC.get(i - 1);
                        AppMethodBeat.o(44223);
                    } else {
                        AppMethodBeat.o(44223);
                    }
                } else if (i < this.pGC.size()) {
                    aVar = (com.tencent.mm.plugin.recharge.model.a) this.pGC.get(i);
                    AppMethodBeat.o(44223);
                } else {
                    AppMethodBeat.o(44223);
                }
            }
            return aVar;
        }

        public final long getItemId(int i) {
            return (long) i;
        }

        public final View getView(int i, View view, ViewGroup viewGroup) {
            AppMethodBeat.i(44224);
            switch (getItemViewType(i)) {
                case 0:
                    c cVar;
                    if (view == null) {
                        view = View.inflate(MallEditText.this.getContext(), 2130970472, null);
                        c cVar2 = new c(MallEditText.this, (byte) 0);
                        cVar2.pGK = (TextView) view.findViewById(2131826879);
                        cVar2.gtb = (TextView) view.findViewById(2131826880);
                        view.setTag(cVar2);
                        cVar = cVar2;
                    } else {
                        cVar = (c) view.getTag();
                    }
                    com.tencent.mm.plugin.recharge.model.a BA = BA(i);
                    if (!(BA == null || cVar == null || cVar.pGK == null || cVar.gtb == null)) {
                        String VB = b.VB(BA.pFM);
                        ab.d("MicroMsg.MallEditText", "record.record " + VB + ", record.name " + BA.name);
                        if (com.tencent.mm.plugin.recharge.model.a.pFK.equals(BA.pFO)) {
                            cVar.pGK.setText(VB);
                        } else {
                            SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(VB);
                            for (int i2 : BA.pFO) {
                                int i22;
                                if (i22 >= 0) {
                                    if (i22 >= 7) {
                                        i22 += 2;
                                    } else if (i22 >= 3) {
                                        i22++;
                                    }
                                    spannableStringBuilder.setSpan(new ForegroundColorSpan(-65536), i22, i22 + 1, 34);
                                }
                            }
                            cVar.pGK.setText(spannableStringBuilder);
                        }
                        if (BA.name == null || bo.isNullOrNil(BA.name.trim())) {
                            cVar.gtb.setText(BuildConfig.FLAVOR);
                        } else {
                            cVar.gtb.setText(MallEditText.this.getResources().getString(2131301395, new Object[]{BA.name}));
                        }
                        view.setBackgroundResource(2130838396);
                        break;
                    }
                    break;
                case 1:
                    view = View.inflate(MallEditText.this.getContext(), 2130970473, null);
                    view.setOnClickListener(new 2(this));
                    break;
                case 2:
                    view = View.inflate(MallEditText.this.getContext(), 2130970471, null);
                    view.setOnClickListener(new OnClickListener() {
                        public final void onClick(View view) {
                            AppMethodBeat.i(44211);
                            MallEditText.this.pGt.dismissDropDown();
                            AppMethodBeat.o(44211);
                        }
                    });
                    break;
                case 3:
                    View inflate = View.inflate(MallEditText.this.getContext(), 2130970473, null);
                    ((TextView) inflate).setText(2131301384);
                    inflate.setOnClickListener(new 3(this));
                    view = inflate;
                    break;
            }
            AppMethodBeat.o(44224);
            return view;
        }

        public final int getItemViewType(int i) {
            AppMethodBeat.i(44225);
            if (this.pGD) {
                if (i == 0) {
                    AppMethodBeat.o(44225);
                    return 2;
                } else if (i <= this.pGC.size()) {
                    AppMethodBeat.o(44225);
                    return 0;
                } else {
                    AppMethodBeat.o(44225);
                    return 3;
                }
            } else if (i < this.pGC.size()) {
                AppMethodBeat.o(44225);
                return 0;
            } else {
                AppMethodBeat.o(44225);
                return 1;
            }
        }

        public final int getViewTypeCount() {
            return 4;
        }
    }

    static /* synthetic */ void c(MallEditText mallEditText) {
        AppMethodBeat.i(44245);
        mallEditText.cee();
        AppMethodBeat.o(44245);
    }

    public MallEditText(Context context, AttributeSet attributeSet, int i) {
        super(context, attributeSet);
        AppMethodBeat.i(44227);
        this.pGv = null;
        this.gJH = BuildConfig.FLAVOR;
        this.gJI = BuildConfig.FLAVOR;
        this.inputType = 1;
        this.hNO = true;
        this.gJP = -1;
        this.gJO = 1;
        this.gravity = 19;
        this.gJJ = -1;
        this.gJN = false;
        this.pGx = null;
        this.gJL = true;
        this.pGy = null;
        this.pGz = false;
        this.pGA = 0;
        TypedArray obtainStyledAttributes = context.obtainStyledAttributes(attributeSet, com.tencent.mm.plugin.wxpay.a.a.MallEditText, i, 0);
        int resourceId = obtainStyledAttributes.getResourceId(6, 0);
        if (resourceId != 0) {
            this.gJH = context.getString(resourceId);
        }
        resourceId = obtainStyledAttributes.getResourceId(7, 0);
        if (resourceId != 0) {
            this.gJI = context.getString(resourceId);
        }
        this.inputType = obtainStyledAttributes.getInteger(4, 1);
        this.gJL = obtainStyledAttributes.getBoolean(3, true);
        this.gravity = obtainStyledAttributes.getInt(0, 19);
        this.hNO = obtainStyledAttributes.getBoolean(1, true);
        this.gJP = obtainStyledAttributes.getInteger(2, -1);
        this.gJJ = obtainStyledAttributes.getInteger(8, 0);
        this.imeOptions = obtainStyledAttributes.getInteger(5, 5);
        obtainStyledAttributes.recycle();
        View inflate = LayoutInflater.from(context).inflate(2130970469, this, true);
        this.goa = (TextView) inflate.findViewById(2131826877);
        this.pGt = (AutoCompleteTextView) inflate.findViewById(2131821052);
        if (com.tencent.mm.bz.a.ga(context)) {
            this.pGt.setTextSize(0, ((float) context.getResources().getDimensionPixelSize(2131427813)) * 1.25f);
        } else {
            this.pGt.setTextSize(0, (float) com.tencent.mm.bz.a.al(context, 2131427813));
        }
        this.gJG = (ImageView) inflate.findViewById(2131821053);
        ab.d("MicroMsg.MallEditText", "setFormat editType:" + this.gJJ);
        this.pGt.setImeOptions(this.imeOptions);
        switch (this.gJJ) {
            case 0:
                if (!this.gJL) {
                    this.gJG.setImageResource(2130839547);
                    this.gJG.setVisibility(0);
                    break;
                }
                break;
            case 1:
                this.gJO = 13;
                this.gJP = 13;
                this.inputType = 2;
                setInfoTvImageResource(2130840001);
                this.gJG.setVisibility(0);
                break;
        }
        this.inputType = 1;
        this.pGt.addTextChangedListener(new 1(this));
        this.pGt.setOnFocusChangeListener(this);
        if (!bo.isNullOrNil(this.gJH)) {
            this.pGt.setHint(this.gJH);
        }
        if (this.inputType == 2) {
            this.pGt.setKeyListener(new 2(this));
        } else {
            this.pGt.setInputType(this.inputType);
            this.pGt.setRawInputType(this.inputType);
        }
        this.pGt.setGravity(this.gravity);
        if (!this.hNO) {
            this.pGt.setEnabled(false);
            this.pGt.setTextColor(getResources().getColor(2131689761));
            this.pGt.setFocusable(false);
            this.pGt.setClickable(false);
        }
        if (this.gJL) {
            this.gJN = false;
        } else {
            this.gJN = true;
            this.pGt.setEnabled(false);
            this.pGt.setFocusable(false);
            this.pGt.setClickable(false);
        }
        if (this.gJP != -1) {
            this.pGt.setFilters(new InputFilter[]{new LengthFilter(this.gJP)});
        }
        ab.d("MicroMsg.MallEditText", "initData editType:" + this.gJJ);
        switch (this.gJJ) {
            case 1:
                ab.d("MicroMsg.MallEditText", "setMobileEditTv");
                List ceb = com.tencent.mm.plugin.recharge.a.a.cea().ceb();
                this.pGv = new a(this, (byte) 0);
                this.pGv.cK(ceb);
                if (ceb != null && ceb.size() > 0) {
                    this.pGx = (com.tencent.mm.plugin.recharge.model.a) ceb.get(0);
                    setInput(this.pGx);
                } else if (this.pGw == null) {
                    new Runnable() {
                        public final void run() {
                            AppMethodBeat.i(44209);
                            try {
                                MallEditText.this.pGw = com.tencent.mm.pluginsdk.a.cJ(MallEditText.this.getContext());
                                AppMethodBeat.o(44209);
                            } catch (Exception e) {
                                ab.printErrStackTrace("MicroMsg.MallEditText", e, BuildConfig.FLAVOR, new Object[0]);
                                AppMethodBeat.o(44209);
                            }
                        }
                    }.run();
                }
                if (ceb == null || ceb.size() == 0) {
                    g.RQ();
                    this.pGt.setText((String) g.RP().Ry().get(6, null));
                    this.pGt.setSelection(this.pGt.getText().length());
                    cee();
                }
                this.pGt.setAdapter(this.pGv);
                this.pGt.setOnItemClickListener(new OnItemClickListener() {
                    public final void onItemClick(AdapterView<?> adapterView, View view, int i, long j) {
                        AppMethodBeat.i(44210);
                        MallEditText.this.pGx = MallEditText.this.pGv.BA(i);
                        if (MallEditText.this.pGx != null) {
                            ab.d("MicroMsg.MallEditText", "onItemClick record.record " + MallEditText.this.pGx.pFM + ", record.name " + MallEditText.this.pGx.name);
                            MallEditText.this.setInput(MallEditText.this.pGx);
                        }
                        MallEditText.this.pGt.dismissDropDown();
                        AppMethodBeat.o(44210);
                    }
                });
                break;
        }
        AppMethodBeat.o(44227);
    }

    public MallEditText(Context context, AttributeSet attributeSet) {
        this(context, attributeSet, 0);
    }

    public void setOnInputValidChangeListener(b bVar) {
        this.pGs = bVar;
    }

    public void setHintStr(String str) {
        AppMethodBeat.i(44228);
        this.pGt.setHint(str);
        AppMethodBeat.o(44228);
    }

    public void setInfoTvOnClickListener(OnClickListener onClickListener) {
        AppMethodBeat.i(44229);
        this.gJG.setOnClickListener(onClickListener);
        AppMethodBeat.o(44229);
    }

    public void setInfoTvImageResource(int i) {
        AppMethodBeat.i(44230);
        this.pGu = i == 2130839158;
        this.gJG.setImageResource(i);
        AppMethodBeat.o(44230);
    }

    public void setInput(com.tencent.mm.plugin.recharge.model.a aVar) {
        AppMethodBeat.i(44231);
        this.pGx = aVar;
        if (aVar != null) {
            this.pGt.setText(aVar.pFM);
            this.pGt.setSelection(this.pGt.getText().length());
            cee();
            ab.d("MicroMsg.MallEditText", "editTv.setText " + aVar.pFM + ", name " + aVar.name + ", isInputValid " + this.gJN);
            if (bo.isNullOrNil(aVar.name) || !this.gJN) {
                this.goa.setText(BuildConfig.FLAVOR);
                this.goa.setVisibility(8);
                AppMethodBeat.o(44231);
                return;
            }
            this.goa.setText(aVar.name);
            this.goa.setVisibility(0);
            AppMethodBeat.o(44231);
            return;
        }
        this.pGt.setText(BuildConfig.FLAVOR);
        cee();
        ab.d("MicroMsg.MallEditText", "editTv.setText null");
        this.goa.setText(BuildConfig.FLAVOR);
        this.goa.setVisibility(8);
        AppMethodBeat.o(44231);
    }

    private void setInputForce(com.tencent.mm.plugin.recharge.model.a aVar) {
        AppMethodBeat.i(44232);
        this.pGx = aVar;
        if (aVar != null) {
            KeyListener keyListener = this.pGt.getKeyListener();
            this.pGt.setKeyListener(null);
            this.pGt.setText(aVar.pFM);
            this.pGt.setSelection(this.pGt.getText().length());
            this.pGt.setKeyListener(keyListener);
            cee();
            ab.d("MicroMsg.MallEditText", "editTv.setText " + aVar.pFM + ", name " + aVar.name + ", isInputValid " + this.gJN);
            if (bo.isNullOrNil(aVar.name) || !this.gJN) {
                this.goa.setText(BuildConfig.FLAVOR);
                this.goa.setVisibility(8);
                AppMethodBeat.o(44232);
                return;
            }
            this.goa.setText(aVar.name);
            this.goa.setVisibility(0);
            AppMethodBeat.o(44232);
            return;
        }
        this.pGt.setText(BuildConfig.FLAVOR);
        cee();
        ab.d("MicroMsg.MallEditText", "editTv.setText null");
        this.goa.setText(BuildConfig.FLAVOR);
        this.goa.setVisibility(8);
        AppMethodBeat.o(44232);
    }

    private void cee() {
        AppMethodBeat.i(44233);
        boolean asa = asa();
        if (asa != this.gJN) {
            ab.d("MicroMsg.MallEditText", "View:" + this.gJI + ", editType:" + this.gJJ + " inputValid change to " + asa);
            this.gJN = asa;
            if (this.pGs != null) {
                this.pGs.hY(this.gJN);
            }
            if (!asa) {
                if (this.goa.getVisibility() == 0) {
                    this.goa.setText(BuildConfig.FLAVOR);
                    this.goa.setVisibility(8);
                }
                this.pGx = null;
            }
        }
        if (this.pGs != null) {
            this.pGs.ceg();
        }
        AppMethodBeat.o(44233);
    }

    public String getText() {
        AppMethodBeat.i(44234);
        String bc;
        switch (this.gJJ) {
            case 1:
                bc = bo.bc(this.pGt.getText().toString(), BuildConfig.FLAVOR);
                AppMethodBeat.o(44234);
                return bc;
            default:
                bc = bo.bc(this.pGt.getText().toString(), BuildConfig.FLAVOR);
                AppMethodBeat.o(44234);
                return bc;
        }
    }

    public final boolean asa() {
        AppMethodBeat.i(44235);
        switch (this.gJJ) {
            case 1:
                String obj = this.pGt.getText().toString();
                if (obj.length() < this.gJO || obj.length() > this.gJP || !PhoneNumberUtils.isGlobalPhoneNumber(b.ws(obj))) {
                    AppMethodBeat.o(44235);
                    return false;
                }
                AppMethodBeat.o(44235);
                return true;
            default:
                if (this.pGt.getText().length() >= this.gJO) {
                    AppMethodBeat.o(44235);
                    return true;
                }
                AppMethodBeat.o(44235);
                return false;
        }
    }

    public void setEllipsize(TruncateAt truncateAt) {
        AppMethodBeat.i(44236);
        this.pGt.setEllipsize(truncateAt);
        AppMethodBeat.o(44236);
    }

    public final boolean cef() {
        AppMethodBeat.i(44237);
        if (getVisibility() != 0) {
            AppMethodBeat.o(44237);
            return true;
        } else if (bo.isNullOrNil(getText())) {
            ab.d("MicroMsg.MallEditText", "View:" + this.gJI + ", editType:" + this.gJJ + " checkInputValid : empty ");
            AppMethodBeat.o(44237);
            return false;
        } else if (this.gJN) {
            AppMethodBeat.o(44237);
            return true;
        } else {
            ab.d("MicroMsg.MallEditText", "View:" + this.gJI + ", editType:" + this.gJJ + " checkInputValid : illegal ");
            AppMethodBeat.o(44237);
            return false;
        }
    }

    public boolean onInterceptTouchEvent(MotionEvent motionEvent) {
        if (this.gJL) {
            return false;
        }
        return true;
    }

    public void setOnClickListener(OnClickListener onClickListener) {
        AppMethodBeat.i(44238);
        super.setOnClickListener(onClickListener);
        this.pGt.setOnClickListener(onClickListener);
        AppMethodBeat.o(44238);
    }

    public void setOnFocusChangeListener(OnFocusChangeListener onFocusChangeListener) {
        AppMethodBeat.i(44239);
        super.setOnFocusChangeListener(onFocusChangeListener);
        this.gJD = onFocusChangeListener;
        AppMethodBeat.o(44239);
    }

    public void onFocusChange(View view, boolean z) {
        AppMethodBeat.i(44240);
        if (this.gJD != null) {
            this.gJD.onFocusChange(this, z);
        }
        if (!((!this.pGz) != z || z || this.pGy == null)) {
            this.pGy.run();
        }
        this.pGz = z;
        ab.d("MicroMsg.MallEditText", "View:" + this.gJI + ", editType:" + this.gJJ + " onFocusChange to " + z);
        if (this.pGs != null) {
            this.pGs.hY(this.gJN);
        }
        AppMethodBeat.o(44240);
    }

    public void setImeOptions(int i) {
        AppMethodBeat.i(44241);
        this.pGt.setImeOptions(i);
        AppMethodBeat.o(44241);
    }

    public void setOnEditorActionListener(OnEditorActionListener onEditorActionListener) {
        AppMethodBeat.i(44242);
        this.pGt.setOnEditorActionListener(onEditorActionListener);
        AppMethodBeat.o(44242);
    }

    public com.tencent.mm.plugin.recharge.model.a getInputRecord() {
        AppMethodBeat.i(44243);
        com.tencent.mm.plugin.recharge.model.a aVar;
        if (this.pGx != null) {
            aVar = this.pGx;
            AppMethodBeat.o(44243);
            return aVar;
        }
        this.pGx = new com.tencent.mm.plugin.recharge.model.a(getText(), this.goa.getText().toString(), 0);
        aVar = this.pGx;
        AppMethodBeat.o(44243);
        return aVar;
    }

    public void getFocus() {
        AppMethodBeat.i(44244);
        this.pGt.findFocus();
        AppMethodBeat.o(44244);
    }
}
