package com.ss.android.ugc.aweme.ecommerce.address.edit.viewholder;

import X.0CB;
import X.0CH;
import X.6Is;
import X.C1834Aic;
import X.C5675C8h;
import X.C5679C8l;
import X.C5681C8n;
import X.C5695C9b;
import X.C5698C9e;
import X.C5708C9o;
import X.C9A;
import X.C9F;
import X.C9Z;
import X.Crj;
import X.M12;
import android.text.TextWatcher;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewParent;
import android.widget.FrameLayout;
import com.bytedance.covode.number.Covode;
import com.bytedance.jedi.arch.JediViewModel;
import com.bytedance.jedi.ext.adapter.JediSimpleViewHolder;
import com.ss.android.ugc.aweme.ecommerce.address.candinput.CandHelper;
import com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditFragment;
import com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel;
import java.util.Objects;
import kotlin.h.b.n;

public final class TextInputItemViewHolder extends JediSimpleViewHolder<C5698C9e> implements 6Is {
    public final CandHelper LJFF;
    public long LJI = -1;
    public int LJIIIZ;
    public boolean LJIIJ = C5695C9b.LIZ();
    public boolean LJIIJJI;
    public final AddressEditFragment LJIIL;
    public final Crj LJIILIIL;
    public TextWatcher LJIILJJIL;

    static {
        Covode.recordClassIndex(68208);
    }

    public final AddressEditViewModel LJIIL() {
        return (AddressEditViewModel) this.LJIILIIL.getValue();
    }

    public final void onStateChanged(0CH r1, 0CB r2) {
        super.onStateChanged(r1, r2);
    }

    public final void LJIIIZ() {
        TextInputItemViewHolder.super.LJIIIZ();
        this.LJFF.LIZIZ();
    }

    public final void LIZ(boolean z) {
        Integer num = ((C5698C9e) LJIIJJI()).LIZ.LJI;
        if (num != null && num.intValue() == 5) {
            LJIIL().LIZ(z);
        }
    }

    public final int LIZ(int i) {
        View view = this.itemView;
        n.LIZIZ(view, "");
        ViewParent parent = view.getParent();
        Objects.requireNonNull(parent, "null cannot be cast to non-null type android.view.ViewGroup");
        ViewGroup viewGroup = (ViewGroup) parent;
        int childCount = viewGroup.getChildCount();
        int i2 = 0;
        for (int i3 = i; i3 < childCount; i3++) {
            View childAt = viewGroup.getChildAt(i3);
            if (childAt == null) {
                n.LIZIZ();
            }
            i2 += childAt.getHeight();
            ViewGroup.LayoutParams layoutParams = childAt.getLayoutParams();
            if (!(layoutParams instanceof ViewGroup.MarginLayoutParams)) {
                layoutParams = null;
            }
            ViewGroup.MarginLayoutParams marginLayoutParams = (ViewGroup.MarginLayoutParams) layoutParams;
            if (marginLayoutParams != null) {
                if (i3 > i) {
                    i2 += marginLayoutParams.topMargin;
                }
                i2 += marginLayoutParams.bottomMargin;
            }
            if (i2 >= viewGroup.getHeight()) {
                break;
            }
        }
        return i2;
    }

    /* JADX WARNING: type inference failed for: r0v41, types: [android.view.View$OnClickListener, X.Aic] */
    public final /* synthetic */ void LIZ(Object obj) {
        int i;
        C5698C9e c9e = (C5698C9e) obj;
        M12.LIZ(c9e);
        if (n.LIZ(c9e.LIZ.LIZJ, "address") && this.LJIIJ) {
            AddressEditViewModel LJIIL2 = LJIIL();
            View view = this.itemView;
            n.LIZIZ(view, "");
            C5708C9o c9o = (C5708C9o) view.findViewById(2131366061);
            n.LIZIZ(c9o, "");
            M12.LIZ(c9o);
            JediViewModel.LIZ(LJIIL2, C9Z.LIZ, new C9F(LJIIL2, c9o));
        }
        this.LJFF.LIZ(LJIIL(), c9e.LIZ.LIZJ);
        View view2 = this.itemView;
        n.LIZIZ(view2, "");
        ((C5708C9o) view2.findViewById(2131366061)).setIndicatorClickListener(new C9A(this, c9e));
        Integer num = c9e.LIZ.LJI;
        int i2 = 0;
        if (num != null) {
            if (num.intValue() == 0) {
                View view3 = this.itemView;
                n.LIZIZ(view3, "");
                ((C5708C9o) view3.findViewById(2131366061)).getEditText().setTag(0);
                View view4 = this.itemView;
                n.LIZIZ(view4, "");
                ((C5708C9o) view4.findViewById(2131366061)).setInputType(1);
            } else if (num.intValue() == 5) {
                View view5 = this.itemView;
                n.LIZIZ(view5, "");
                ((C5708C9o) view5.findViewById(2131366061)).getEditText().setTag(5);
                View view6 = this.itemView;
                n.LIZIZ(view6, "");
                ((C5708C9o) view6.findViewById(2131366061)).setInputType(32);
            }
        }
        View view7 = this.itemView;
        Objects.requireNonNull(view7, "null cannot be cast to non-null type com.ss.android.ugc.aweme.ecommerce.address.widget.inputitem.InputItem");
        C5679C8l c8l = (C5679C8l) view7;
        TextWatcher textWatcher = this.LJIILJJIL;
        if (textWatcher != null) {
            ((C5708C9o) c8l.LIZ(2131366061)).getEditText().removeTextChangedListener(textWatcher);
        }
        c8l.setTitle(c9e.LIZ.LJFF);
        ((C5708C9o) c8l.LIZ(2131366061)).setHint(c9e.LIZ.LIZIZ);
        Integer num2 = c9e.LIZ.LJ;
        if (num2 != null) {
            i = num2.intValue();
        } else {
            i = Integer.MAX_VALUE;
        }
        ((C5708C9o) c8l.LIZ(2131366061)).setMaxLines(i);
        if (i > 1) {
            ((C5708C9o) c8l.LIZ(2131366061)).setInputType(((C5708C9o) c8l.LIZ(2131366061)).getInputType() | 131072);
        }
        Integer num3 = c9e.LIZ.LIZLLL;
        if (num3 != null) {
            i2 = num3.intValue();
        }
        ((C5708C9o) c8l.LIZ(2131366061)).setMaxLength(i2);
        Object obj2 = c9e.LIZIZ;
        if (!(obj2 instanceof String)) {
            obj2 = null;
        }
        String str = (String) obj2;
        if (str != null) {
            ((C5708C9o) c8l.LIZ(2131366061)).setText(str);
        } else {
            ((C5708C9o) c8l.LIZ(2131366061)).setText("");
        }
        String str2 = c9e.LIZJ;
        if (str2 != null) {
            c8l.LIZ(str2);
        } else {
            c8l.LIZ();
        }
        View view8 = this.itemView;
        n.LIZIZ(view8, "");
        FrameLayout frameLayout = (FrameLayout) view8.findViewById(2131363692);
        n.LIZIZ(frameLayout, "");
        frameLayout.setOnClickListener(new C1834Aic(c8l, this, c9e));
        String str3 = this.LJFF.LJ;
        if (n.LIZ(str3, "sug") || n.LIZ(str3, "auto")) {
            this.LJIIIZ = ((C5708C9o) c8l.LIZ(2131366061)).getEditText().getText().length();
        }
        this.LJIILJJIL = new C5681C8n(c8l, this, c9e);
        ((C5708C9o) c8l.LIZ(2131366061)).getEditText().addTextChangedListener(this.LJIILJJIL);
        ((C5708C9o) c8l.LIZ(2131366061)).setOnEditTextFocusChangeListener(new C5675C8h(c8l, this, c9e));
    }

    /* JADX WARNING: Illegal instructions before constructor call */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public TextInputItemViewHolder(android.view.ViewGroup r6, com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditFragment r7) {
        /*
            r5 = this;
            X.M12.LIZ(r6, r7)
            X.C94 r2 = X.C6754Cfm.LIZLLL
            android.content.Context r1 = r6.getContext()
            java.lang.String r4 = ""
            kotlin.h.b.n.LIZIZ(r1, r4)
            r0 = 2131559011(0x7f0d0263, float:1.8743354E38)
            android.view.View r0 = r2.LIZ(r1, r0, r6)
            r5.<init>(r0)
            r5.LJIIL = r7
            java.lang.Class<com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel> r1 = com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditViewModel.class
            X.KEN r0 = X.KEM.LIZ
            X.D1G r1 = r0.LIZ(r1)
            X.BI6 r0 = new X.BI6
            r0.<init>(r5, r1, r1)
            X.Crj r0 = X.7he.LIZ(r0)
            r5.LJIILIIL = r0
            com.ss.android.ugc.aweme.ecommerce.address.candinput.CandHelper r3 = new com.ss.android.ugc.aweme.ecommerce.address.candinput.CandHelper
            android.content.Context r2 = r6.getContext()
            kotlin.h.b.n.LIZIZ(r2, r4)
            android.view.View r1 = r5.itemView
            kotlin.h.b.n.LIZIZ(r1, r4)
            r0 = 2131366061(0x7f0a10ad, float:1.8352005E38)
            android.view.View r0 = r1.findViewById(r0)
            X.C9o r0 = (X.C5708C9o) r0
            android.widget.EditText r0 = r0.getEditText()
            r3.<init>(r2, r0)
            r5.LJFF = r3
            r0 = -1
            r5.LJI = r0
            boolean r0 = X.C5695C9b.LIZ()
            r5.LJIIJ = r0
            return
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.ecommerce.address.edit.viewholder.TextInputItemViewHolder.<init>(android.view.ViewGroup, com.ss.android.ugc.aweme.ecommerce.address.edit.AddressEditFragment):void");
    }
}
