package com.ss.android.ugc.aweme.im.sdk.chat.feature.story;

import X.0CH;
import X.3Mp;
import X.3af;
import X.4Qu;
import X.4RG;
import X.4ZZ;
import X.4wf;
import X.7he;
import X.9EH;
import X.9Il;
import X.ARQ;
import X.Axw;
import X.C0911IZa;
import X.C0937Ia0;
import X.C1265IfI;
import X.C1347Igc;
import X.C1350Igf;
import X.C1360Igp;
import X.C1519IjO;
import X.C1577IkK;
import X.C1688Im7;
import X.C2116It1;
import X.C2118It3;
import X.C2119It4;
import X.C2123It8;
import X.C2129ItE;
import X.C2130ItF;
import X.C2135ItK;
import X.C2136ItL;
import X.C2138ItN;
import X.C2147ItW;
import X.C2148ItX;
import X.C2149ItY;
import X.C2152Itb;
import X.C2154Itd;
import X.C2159Iti;
import X.C2161Itk;
import X.C2163Itm;
import X.C2165Ito;
import X.C2166Itp;
import X.C2167Itq;
import X.C2414Ixp;
import X.C2591J1q;
import X.C3792Jex;
import X.C4175Jl8;
import X.Crj;
import X.DPU;
import X.IBA;
import X.IXK;
import X.J0Z;
import X.M12;
import android.content.Context;
import android.text.Editable;
import android.text.InputFilter;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.covode.number.Covode;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.BaseContent;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.EmojiContent;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.ShareStoryContent;
import com.ss.android.ugc.aweme.im.sdk.chat.data.model.TextContent;
import com.ss.android.ugc.aweme.im.service.model.IMUser;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;

public final class StoryInputView implements C1360Igp, C1350Igf, C2166Itp {
    public static final String LJI = StoryInputView.class.getSimpleName();
    public static final C2163Itm LJII = new C2163Itm((byte) 0);
    public 4wf LIZ;
    public 4ZZ LIZIZ;
    public 4ZZ LIZJ;
    public View LIZLLL;
    public final J0Z LJ;
    public final ViewGroup LJFF;
    public final ViewGroup LJIIIIZZ;
    public final Crj LJIIIZ = 7he.LIZ(new C2135ItK(this));
    public final Crj LJIIJ = 7he.LIZ(new C2147ItW(this));
    public final Crj LJIIJJI = 7he.LIZ(new C2149ItY(this));
    public final Crj LJIIL = 7he.LIZ(new C2148ItX(this));
    public C2591J1q LJIILIIL;
    public C2116It1 LJIILJJIL;
    public C2165Ito LJIILL;
    public final Crj LJIILLIIL = 7he.LIZ(new C2129ItE(this));
    public final Crj LJIIZILJ = 7he.LIZ(new C2138ItN(this));
    public final Crj LJIJ = 7he.LIZ(new C2130ItF(this));
    public int LJIJI = 4;
    public int LJIJJ = -1;
    public boolean LJIJJLI = true;
    public boolean LJIL = true;
    public boolean LJJ;
    public final C1265IfI LJJI;
    public final ShareStoryContent LJJIFFI;

    private final int LJIILIIL() {
        return ((Number) this.LJIIJ.getValue()).intValue();
    }

    private final int LJIILJJIL() {
        return ((Number) this.LJIIJJI.getValue()).intValue();
    }

    private final int LJIJJ() {
        return ((Number) this.LJIIL.getValue()).intValue();
    }

    private final View.OnClickListener LJIJJLI() {
        return (View.OnClickListener) this.LJIILLIIL.getValue();
    }

    private final TextWatcher LJIL() {
        return (TextWatcher) this.LJIJ.getValue();
    }

    public final void LIZ(C2166Itp itp) {
    }

    public final void LIZ(C2167Itq itq) {
    }

    public final void LIZ(C4175Jl8 jl8) {
        M12.LIZ(jl8);
    }

    public final void LIZIZ() {
    }

    public final void LIZJ() {
    }

    public final void LJ() {
    }

    public final C1350Igf LJFF() {
        return (C1350Igf) this.LJIIIZ.getValue();
    }

    public final boolean LJIILL() {
        return false;
    }

    public final boolean LJIILLIIL() {
        return false;
    }

    public final boolean LJIIZILJ() {
        return false;
    }

    public final void onPause() {
        C2136ItL.onPause(this);
    }

    public final void onResume() {
        C2136ItL.onResume(this);
    }

    public final void LIZ(boolean z) {
        4ZZ r0 = this.LIZJ;
        if (r0 == null) {
            n.LIZ("");
        }
        boolean isActivated = r0.isActivated();
        4ZZ r02 = this.LIZJ;
        if (r02 == null) {
            n.LIZ("");
        }
        r02.setActivated(z);
        4ZZ r1 = this.LIZJ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setTintColorRes(z ? 2130968648 : 2130968667);
        if (z && !isActivated) {
            C2414Ixp ixp = C2414Ixp.LIZ;
            4ZZ r03 = this.LIZJ;
            if (r03 == null) {
                n.LIZ("");
            }
            ixp.LIZ(r03);
        }
    }

    public final void LIZ(List<? extends 4Qu> list) {
        C2591J1q j1q = this.LJIILIIL;
        if (j1q == null) {
            n.LIZ("");
        }
        j1q.LIZ(list);
    }

    public final int LIZ() {
        return this.LJIIIIZZ.getHeight();
    }

    public final Context LJI() {
        Context context = this.LJIIIIZZ.getContext();
        n.LIZIZ(context, "");
        return context;
    }

    public final void LJIIJJI() {
        4wf r1 = this.LIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setText("");
    }

    public final void LJIIL() {
        C2116It1 it1 = this.LJIILJJIL;
        if (it1 == null) {
            n.LIZ("");
        }
        it1.LIZ(-1);
    }

    static {
        Covode.recordClassIndex(84884);
    }

    private void LJJ() {
        4wf r1 = this.LIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setVisibility(0);
        this.LJIJI = 4;
    }

    public final int LIZLLL() {
        C2116It1 it1 = this.LJIILJJIL;
        if (it1 == null) {
            n.LIZ("");
        }
        if (!it1.LIZLLL) {
            return 0;
        }
        C2116It1 it12 = this.LJIILJJIL;
        if (it12 == null) {
            n.LIZ("");
        }
        return it12.getSoftKeyboardHeight();
    }

    public final boolean LJIJI() {
        C2116It1 it1 = this.LJIILJJIL;
        if (it1 == null) {
            n.LIZ("");
        }
        if (it1.LIZ()) {
            LJIIL();
        }
        return false;
    }

    public final void onDestroy() {
        String str = LJI;
        n.LIZIZ(str, "");
        M12.LIZ(str, "onDestroy");
        this.LJ.LJIIIIZZ();
    }

    public final void LJIIIIZZ() {
        if (!this.LJIL) {
            4wf r0 = this.LIZ;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.setVisibility(8);
        }
        if (!this.LJIJJLI) {
            4ZZ r02 = this.LIZIZ;
            if (r02 == null) {
                n.LIZ("");
            }
            r02.setVisibility(8);
        }
    }

    public final void LJIIIZ() {
        4ZZ r1 = this.LIZIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setIconRes(2131755099);
        4ZZ r12 = this.LIZIZ;
        if (r12 == null) {
            n.LIZ("");
        }
        r12.setTintColor(2130968666);
        4ZZ r13 = this.LIZIZ;
        if (r13 == null) {
            n.LIZ("");
        }
        r13.setSelected(false);
    }

    public final void LJIIJ() {
        KeyEvent keyEvent = new KeyEvent(0, 67);
        4wf r0 = this.LIZ;
        if (r0 == null) {
            n.LIZ("");
        }
        if (!r0.LIZ()) {
            4wf r02 = this.LIZ;
            if (r02 == null) {
                n.LIZ("");
            }
            r02.dispatchKeyEvent(keyEvent);
        }
    }

    public final boolean LJII() {
        if ((this.LJJI.isAuthorSupporterChat() && C1347Igc.LIZIZ()) || this.LJJI.isGroupChat()) {
            return false;
        }
        IMUser LIZ2 = IBA.LIZ(String.valueOf(C0937Ia0.LIZ.LIZJ(this.LJJI.getConversationId())), C0911IZa.LIZ(this.LJJI.getConversationId()));
        if (LIZ2 == null) {
            return true;
        }
        if (LIZ2.getFollowStatus() == 2 || 3Mp.LIZ(LIZ2)) {
            return false;
        }
        return true;
    }

    public final void LJIJ() {
        String str;
        String str2;
        String str3;
        ShareStoryContent shareStoryContent;
        int i;
        boolean z;
        int i2;
        boolean z2;
        long currentTimeMillis = System.currentTimeMillis();
        4wf r0 = this.LIZ;
        if (r0 == null) {
            n.LIZ("");
        }
        Editable text = r0.getText();
        if (text != null) {
            n.LIZIZ(text, "");
            String obj = text.toString();
            int length = obj.length() - 1;
            int i3 = 0;
            boolean z3 = false;
            while (i3 <= length) {
                if (!z3) {
                    i2 = i3;
                } else {
                    i2 = length;
                }
                if (n.LIZ(obj.charAt(i2), 32) <= 0) {
                    z2 = true;
                } else {
                    z2 = false;
                }
                if (z3) {
                    if (!z2) {
                        break;
                    }
                    length--;
                } else if (!z2) {
                    z3 = true;
                } else {
                    i3++;
                }
            }
            if (TextUtils.isEmpty(obj.subSequence(i3, length + 1).toString())) {
                4wf r02 = this.LIZ;
                if (r02 == null) {
                    n.LIZ("");
                }
                3af r1 = new 3af(r02);
                r1.LJ(2131825906);
                3af.LIZ(r1);
            } else if (text.length() > 6000) {
                4wf r03 = this.LIZ;
                if (r03 == null) {
                    n.LIZ("");
                }
                3af r2 = new 3af(r03);
                r2.LIZ(9EH.LJJIFFI.LIZ().getResources().getString(2131825895));
                3af.LIZ(r2);
            } else {
                TextContent.Companion companion = TextContent.Companion;
                String obj2 = text.toString();
                int length2 = obj2.length() - 1;
                int i4 = 0;
                boolean z4 = false;
                while (i4 <= length2) {
                    if (!z4) {
                        i = i4;
                    } else {
                        i = length2;
                    }
                    if (n.LIZ(obj2.charAt(i), 32) <= 0) {
                        z = true;
                    } else {
                        z = false;
                    }
                    if (z4) {
                        if (!z) {
                            break;
                        }
                        length2--;
                    } else if (!z) {
                        z4 = true;
                    } else {
                        i4++;
                    }
                }
                TextContent obtain$default = TextContent.Companion.obtain$default(companion, obj2.subSequence(i4, length2 + 1).toString(), (Aweme) null, 2, (Object) null);
                obtain$default.setSendStartTime(Long.valueOf(currentTimeMillis));
                IXK.LIZ(this.LJJI.getConversationId(), (BaseContent) obtain$default);
                ArrayList arrayList = new ArrayList();
                DPU dpu = DPU.LIZ;
                String conversationId = this.LJJI.getConversationId();
                ShareStoryContent shareStoryContent2 = this.LJJIFFI;
                if (shareStoryContent2 == null || (str = shareStoryContent2.getItemId()) == null) {
                    str = "";
                }
                if (!dpu.LIZIZ(conversationId, str) && (shareStoryContent = this.LJJIFFI) != null) {
                    DPU dpu2 = DPU.LIZ;
                    String conversationId2 = this.LJJI.getConversationId();
                    String itemId = shareStoryContent.getItemId();
                    n.LIZIZ(itemId, "");
                    dpu2.LIZ(conversationId2, itemId);
                    arrayList.add(shareStoryContent);
                }
                arrayList.add(obtain$default);
                LinkedHashMap linkedHashMap = new LinkedHashMap();
                ShareStoryContent shareStoryContent3 = this.LJJIFFI;
                if (shareStoryContent3 == null || (str2 = shareStoryContent3.getItemId()) == null) {
                    str2 = "";
                }
                linkedHashMap.put("from_group_id", str2);
                ShareStoryContent shareStoryContent4 = this.LJJIFFI;
                if (shareStoryContent4 == null || (str3 = shareStoryContent4.getStoryCollectionId()) == null) {
                    str3 = "";
                }
                linkedHashMap.put("from_story_collection_id", str3);
                C1577IkK LIZ2 = C1519IjO.LIZ.LIZ();
                LIZ2.LIZIZ(this.LJJI.getConversationId());
                LIZ2.LIZ((List<? extends C1688Im7>) arrayList);
                LIZ2.LIZ((Map<String, String>) linkedHashMap);
                LIZ2.LIZ((C3792Jex) new C2119It4(this));
                4wf r04 = this.LIZ;
                if (r04 == null) {
                    n.LIZ("");
                }
                r04.setText("");
            }
        }
    }

    public final void LIZIZ(int i) {
        this.LJIIIIZZ.setVisibility(i);
    }

    public static final /* synthetic */ 4wf LIZ(StoryInputView storyInputView) {
        4wf r1 = storyInputView.LIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        return r1;
    }

    public static final /* synthetic */ 4ZZ LIZIZ(StoryInputView storyInputView) {
        4ZZ r1 = storyInputView.LIZIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        return r1;
    }

    /* JADX WARNING: type inference failed for: r0v0, types: [X.Itb, android.text.TextWatcher] */
    public final void LIZ(C2161Itk itk) {
        M12.LIZ(itk);
        4wf r1 = this.LIZ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.addTextChangedListener(new C2152Itb(itk));
    }

    public final void LIZ(C2165Ito ito) {
        M12.LIZ(ito);
        this.LJIILL = ito;
    }

    private final void LIZIZ(boolean z) {
        int LJIJJ2;
        if (this.LJJ != z) {
            this.LJJ = z;
            4wf r1 = this.LIZ;
            if (r1 == null) {
                n.LIZ("");
            }
            if (z) {
                LJIJJ2 = LJIILIIL();
            } else {
                LJIJJ2 = LJIJJ();
            }
            r1.setHintTextColor(LJIJJ2);
            4wf r12 = this.LIZ;
            if (r12 == null) {
                n.LIZ("");
            }
            r12.setTextColor(LJIILJJIL());
            4wf r0 = this.LIZ;
            if (r0 == null) {
                n.LIZ("");
            }
            r0.setSelected(z);
            4ZZ r02 = this.LIZIZ;
            if (r02 == null) {
                n.LIZ("");
            }
            r02.setActivated(z);
            if (z) {
                LJJ();
            }
            View view = this.LIZLLL;
            if (view == null) {
                n.LIZ("");
            }
            view.setBackgroundResource(2131233021);
            LJIIIIZZ();
        }
    }

    public final void LIZ(int i) {
        C2591J1q j1q = this.LJIILIIL;
        if (j1q == null) {
            n.LIZ("");
        }
        j1q.LIZ((List<? extends 4Qu>) null);
        if (i == -2) {
            String str = LJI;
            n.LIZIZ(str, "");
            M12.LIZ(str, "switchPanel SOFT_KEYBOARD");
            C2116It1 it1 = this.LJIILJJIL;
            if (it1 == null) {
                n.LIZ("");
            }
            it1.LIZLLL();
        } else if (i == -1) {
            String str2 = LJI;
            n.LIZIZ(str2, "");
            M12.LIZ(str2, "switchPanel NONE");
            LJIIL();
        } else if (i == 1) {
            String str3 = LJI;
            n.LIZIZ(str3, "");
            M12.LIZ(str3, "switchPanel EMOJI_PANEL");
            C2116It1 it12 = this.LJIILJJIL;
            if (it12 == null) {
                n.LIZ("");
            }
            if (it12.LIZIZ() == 1) {
                n.LIZIZ(str3, "");
                M12.LIZ(str3, "switchPanel currentPanelType == EMOJI_PANEL");
                LJIIL();
                return;
            }
            this.LJ.LJII();
            C2116It1 it13 = this.LJIILJJIL;
            if (it13 == null) {
                n.LIZ("");
            }
            it13.LIZ(1);
        }
    }

    public final void LIZ(4RG r7) {
        String str;
        ShareStoryContent shareStoryContent;
        M12.LIZ(r7);
        4Qu r0 = r7.LIZLLL;
        n.LIZIZ(r0, "");
        int stickerType = r0.getStickerType();
        if ((stickerType == 10 || stickerType == 2 || stickerType == 3) && LJII()) {
            4ZZ r02 = this.LIZJ;
            if (r02 == null) {
                n.LIZ("");
            }
            3af r1 = new 3af(r02);
            r1.LJ(2131823887);
            3af.LIZ(r1);
            return;
        }
        ArrayList arrayList = new ArrayList();
        DPU dpu = DPU.LIZ;
        String conversationId = this.LJJI.getConversationId();
        ShareStoryContent shareStoryContent2 = this.LJJIFFI;
        if (shareStoryContent2 == null || (str = shareStoryContent2.getItemId()) == null) {
            str = "";
        }
        if (!dpu.LIZIZ(conversationId, str) && (shareStoryContent = this.LJJIFFI) != null) {
            DPU dpu2 = DPU.LIZ;
            String conversationId2 = this.LJJI.getConversationId();
            String itemId = shareStoryContent.getItemId();
            n.LIZIZ(itemId, "");
            dpu2.LIZ(conversationId2, itemId);
            arrayList.add(shareStoryContent);
        }
        EmojiContent obtain = EmojiContent.obtain(r7.LIZLLL);
        n.LIZIZ(obtain, "");
        arrayList.add(obtain);
        C1577IkK LIZ2 = C1519IjO.LIZ.LIZ();
        LIZ2.LIZIZ(this.LJJI.getConversationId());
        LIZ2.LIZ((List<? extends C1688Im7>) arrayList);
        LIZ2.LIZ((C3792Jex) new C2118It3(this));
    }

    public final void LIZ(String str) {
        M12.LIZ(str);
        if (!TextUtils.isEmpty(str)) {
            4wf r0 = this.LIZ;
            if (r0 == null) {
                n.LIZ("");
            }
            Editable text = r0.getText();
            if (text == null || text.length() + str.length() <= 6000) {
                if (this.LJIJJ == -1) {
                    LIZ(-2);
                }
                4wf r02 = this.LIZ;
                if (r02 == null) {
                    n.LIZ("");
                }
                r02.LIZ(str);
                return;
            }
            3af r1 = new 3af(this.LJIIIIZZ);
            r1.LJ(2131825895);
            3af.LIZ(r1);
        }
    }

    public final void LIZ(int i, View view) {
        int i2 = 0;
        if (i == -2) {
            String str = LJI;
            n.LIZIZ(str, "");
            M12.LIZ(str, "onPanelChange SOFT_KEYBOARD");
            LIZIZ(true);
            LJIIIZ();
        } else if (i == -1) {
            String str2 = LJI;
            n.LIZIZ(str2, "");
            M12.LIZ(str2, "onPanelChange NONE");
            if (this.LJIJJLI) {
                4ZZ r0 = this.LIZIZ;
                if (r0 == null) {
                    n.LIZ("");
                }
                if (r0.isSelected()) {
                    LJIIIZ();
                }
            }
            LIZIZ(false);
        } else if (i == 1) {
            String str3 = LJI;
            n.LIZIZ(str3, "");
            M12.LIZ(str3, "onPanelChange EMOJI_PANEL");
            LIZIZ(true);
        }
        C2165Ito ito = this.LJIILL;
        if (ito != null) {
            if (i == -1) {
                i2 = 8;
            }
            ito.LIZ(i2);
        }
        this.LJIJJ = i;
    }

    public StoryInputView(ViewGroup viewGroup, C1265IfI ifI, ShareStoryContent shareStoryContent, 0CH r12) {
        M12.LIZ(viewGroup, ifI, r12);
        this.LJFF = viewGroup;
        this.LJJI = ifI;
        this.LJJIFFI = shareStoryContent;
        if (ifI.isAuthorSupporterChat()) {
            this.LJIL = C1347Igc.LIZ();
            this.LJIJJLI = C1347Igc.LIZJ();
        }
        View findViewById = viewGroup.findViewById(2131366076);
        n.LIZIZ(findViewById, "");
        ViewGroup viewGroup2 = (ViewGroup) findViewById;
        this.LJIIIIZZ = viewGroup2;
        4wf findViewById2 = viewGroup.findViewById(2131367730);
        n.LIZIZ(findViewById2, "");
        this.LIZ = findViewById2;
        View findViewById3 = viewGroup.findViewById(2131364396);
        n.LIZIZ(findViewById3, "");
        this.LIZLLL = findViewById3;
        4ZZ findViewById4 = viewGroup.findViewById(2131364501);
        n.LIZIZ(findViewById4, "");
        this.LIZIZ = findViewById4;
        4ZZ findViewById5 = viewGroup.findViewById(2131370089);
        n.LIZIZ(findViewById5, "");
        this.LIZJ = findViewById5;
        View findViewById6 = viewGroup.findViewById(2131370248);
        n.LIZIZ(findViewById6, "");
        findViewById6.setVisibility(8);
        4ZZ r0 = this.LIZJ;
        if (r0 == null) {
            n.LIZ("");
        }
        r0.setVisibility(0);
        View findViewById7 = viewGroup.findViewById(2131368341);
        n.LIZIZ(findViewById7, "");
        C2116It1 it1 = (C2116It1) findViewById7;
        this.LJIILJJIL = it1;
        if (it1 == null) {
            n.LIZ("");
        }
        it1.setOuterView(viewGroup2);
        4wf r02 = this.LIZ;
        if (r02 == null) {
            n.LIZ("");
        }
        it1.setEditText(r02);
        it1.setQuickChat(false);
        this.LJIILIIL = new C2591J1q(this, viewGroup2, ifI.getConversationId());
        LJIIIIZZ();
        4wf r2 = this.LIZ;
        if (r2 == null) {
            n.LIZ("");
        }
        r2.removeTextChangedListener(LJIL());
        r2.addTextChangedListener(LJIL());
        r2.setFilters(new InputFilter[]{new ARQ(r2)});
        r2.setOnClickListener(LJIJJLI());
        r2.setOnFocusChangeListener(new C2159Iti(this));
        4ZZ r1 = this.LIZJ;
        if (r1 == null) {
            n.LIZ("");
        }
        r1.setOnClickListener(LJIJJLI());
        4ZZ r13 = this.LIZIZ;
        if (r13 == null) {
            n.LIZ("");
        }
        r13.setOnClickListener(LJIJJLI());
        C2116It1 it12 = this.LJIILJJIL;
        if (it12 == null) {
            n.LIZ("");
        }
        it12.setOnPanelChangeListener(this);
        it12.setOnClickListener(LJIJJLI());
        View view = this.LIZLLL;
        if (view == null) {
            n.LIZ("");
        }
        view.getViewTreeObserver().addOnGlobalLayoutListener(new C2154Itd(this));
        C2116It1 it13 = this.LJIILJJIL;
        if (it13 == null) {
            n.LIZ("");
        }
        C2123It8 it8 = new C2123It8(this, it13, r12);
        it8.LJ();
        it8.LIZJ();
        it8.LIZ.LIZJ = true;
        it8.LIZ.LJIIIIZZ.add(4);
        Axw.LIZIZ.LIZ();
        if (9Il.LJ.LIZIZ(1)) {
            it8.LIZIZ();
        } else {
            it8.LIZ();
        }
        it8.LIZLLL();
        J0Z LJFF2 = it8.LJFF();
        this.LJ = LJFF2;
        LJFF2.LIZ(LJIJJLI());
        C2116It1 it14 = this.LJIILJJIL;
        if (it14 == null) {
            n.LIZ("");
        }
        it14.LIZ(LJFF2.LIZIZ);
    }
}
