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

import X.0AA;
import X.0HH;
import X.2Pr;
import X.4ZZ;
import X.7he;
import X.C1566Ik9;
import X.C1573IkG;
import X.C1594Ikb;
import X.C1595Ikc;
import X.C1596Ikd;
import X.C1963IqY;
import X.C1971Iqg;
import X.C2153Itc;
import X.C2414Ixp;
import X.C4175Jl8;
import X.Cc1;
import X.Crj;
import X.M12;
import X.Qeg;
import X.TnV;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewStub;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.fragment.app.Fragment;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.ss.android.ugc.aweme.awemeservice.AwemeService;
import com.ss.android.ugc.aweme.feed.model.Aweme;
import com.ss.android.ugc.aweme.im.sdk.chat.viewmodel.ChatViewModel;
import java.util.HashMap;
import java.util.Objects;
import kotlin.h.b.n;

public final class DetailFeedReplyMessageFragment extends Hilt_DetailFeedReplyMessageFragment implements View.OnClickListener, C1596Ikd, C1595Ikc {
    public static final C1594Ikb LJII = new C1594Ikb((byte) 0);
    public String LJ;
    public C4175Jl8 LJFF;
    public String LJI;
    public final Crj LJIIIIZZ = 7he.LIZ(new C1573IkG(this));
    public HashMap LJIIIZ;

    static {
        Covode.recordClassIndex(84810);
    }

    public final View LIZ(int i) {
        if (this.LJIIIZ == null) {
            this.LJIIIZ = new HashMap();
        }
        View view = (View) this.LJIIIZ.get(Integer.valueOf(i));
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(i);
        this.LJIIIZ.put(Integer.valueOf(i), findViewById);
        return findViewById;
    }

    public final ChatViewModel LIZ() {
        return (ChatViewModel) this.LJIIIIZZ.getValue();
    }

    public final void LJI() {
        HashMap hashMap = this.LJIIIZ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final /* synthetic */ void onDestroyView() {
        DetailFeedReplyMessageFragment.super.onDestroyView();
        LJI();
    }

    public final void LIZ(String str) {
        if (C2153Itc.LIZ((Fragment) this) && str != null) {
            Qeg LIZ = LIZ(2131369470);
            n.LIZIZ(LIZ, "");
            LIZ.setText(str);
            LIZIZ(str);
        }
    }

    private void LIZ(boolean z) {
        if (C2153Itc.LIZ((Fragment) this)) {
            Qeg LIZ = LIZ(2131369470);
            n.LIZIZ(LIZ, "");
            CharSequence hint = LIZ.getHint();
            AppCompatTextView LIZ2 = LIZ(2131369470);
            n.LIZIZ(LIZ2, "");
            CharSequence text = LIZ2.getText();
            Bundle bundle = new Bundle();
            bundle.putCharSequence("hint", hint);
            bundle.putCharSequence("text", text);
            bundle.putBoolean("showEmojiPanel", z);
            C1566Ik9 ik9 = DetailFeedKeyboardDialogFragment.LIZLLL;
            0AA childFragmentManager = getChildFragmentManager();
            n.LIZIZ(childFragmentManager, "");
            DetailFeedKeyboardDialogFragment LIZ3 = ik9.LIZ(childFragmentManager);
            LIZ3.setArguments(bundle);
            LIZ3.LIZ((C1595Ikc) this);
            LIZ3.LIZ((C1596Ikd) this);
            0AA childFragmentManager2 = getChildFragmentManager();
            n.LIZIZ(childFragmentManager2, "");
            LIZ3.LIZ(childFragmentManager2);
        }
    }

    public final void onClick(View view) {
        if (!C2153Itc.LIZ((Fragment) this) || Cc1.LIZ(view, 500)) {
            return;
        }
        if (n.LIZ(view, LIZ(2131370108))) {
            if (C2153Itc.LIZ((Fragment) this)) {
                AppCompatTextView LIZ = LIZ(2131369470);
                n.LIZIZ(LIZ, "");
                CharSequence text = LIZ.getText();
                if (text != null) {
                    sendMessage(text);
                    Qeg LIZ2 = LIZ(2131369470);
                    n.LIZIZ(LIZ2, "");
                    LIZ2.setText("");
                    LIZIZ("");
                }
            }
        } else if (n.LIZ(view, LIZ(2131369470))) {
            LIZ(false);
        } else if (n.LIZ(view, LIZ(2131364520))) {
            LIZ(true);
        }
    }

    public final void sendMessage(CharSequence charSequence) {
        String string;
        TnV tnV;
        String aid;
        if (charSequence != null) {
            Bundle arguments = getArguments();
            if (!(arguments == null || (string = arguments.getString("enter_method", (String) null)) == null)) {
                Objects.requireNonNull(string, "null cannot be cast to non-null type java.lang.String");
                if (string.contentEquals("click_feed_dm_reply_msg")) {
                    Bundle arguments2 = getArguments();
                    if (arguments2 != null) {
                        tnV = arguments2.getSerializable("feed_param");
                    } else {
                        tnV = null;
                    }
                    if (!(tnV instanceof TnV)) {
                        tnV = null;
                    }
                    TnV tnV2 = tnV;
                    if (!(tnV2 == null || (aid = tnV2.getAid()) == null)) {
                        Aweme LIZIZ = AwemeService.LIZIZ().LIZIZ(aid);
                        ChatViewModel LIZ = LIZ();
                        n.LIZIZ(LIZIZ, "");
                        LIZ.LIZ(charSequence, LIZIZ);
                        if (2Pr.LIZ != null) {
                            return;
                        }
                    }
                }
            }
            LIZ().LIZ(charSequence, this.LJ);
        }
    }

    private final void LIZIZ(String str) {
        int i;
        int i2;
        boolean z;
        int length = str.length() - 1;
        int i3 = 0;
        boolean z2 = false;
        while (i3 <= length) {
            if (!z2) {
                i2 = i3;
            } else {
                i2 = length;
            }
            if (n.LIZ(str.charAt(i2), 32) <= 0) {
                z = true;
            } else {
                z = false;
            }
            if (z2) {
                if (!z) {
                    break;
                }
                length--;
            } else if (!z) {
                z2 = true;
            } else {
                i3++;
            }
        }
        boolean z3 = !TextUtils.isEmpty(str.subSequence(i3, length + 1).toString());
        4ZZ LIZ = LIZ(2131370108);
        n.LIZIZ(LIZ, "");
        boolean isActivated = LIZ.isActivated();
        4ZZ LIZ2 = LIZ(2131370108);
        n.LIZIZ(LIZ2, "");
        LIZ2.setActivated(z3);
        4ZZ LIZ3 = LIZ(2131370108);
        n.LIZIZ(LIZ3, "");
        LIZ3.setEnabled(z3);
        4ZZ LIZ4 = LIZ(2131370108);
        if (z3) {
            i = 2130968648;
        } else {
            i = 2130968627;
        }
        LIZ4.setTintColorRes(i);
        if (z3 && !isActivated) {
            C2414Ixp ixp = C2414Ixp.LIZ;
            4ZZ LIZ5 = LIZ(2131370108);
            n.LIZIZ(LIZ5, "");
            ixp.LIZ(LIZ5);
        }
    }

    /* JADX WARNING: Code restructure failed: missing block: B:16:0x00b8, code lost:
        if (r6 != null) goto L_0x0040;
     */
    /* JADX WARNING: Removed duplicated region for block: B:10:0x0049  */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void onViewCreated(android.view.View r8, android.os.Bundle r9) {
        /*
            r7 = this;
            X.M12.LIZ(r8)
            com.ss.android.ugc.aweme.im.sdk.chat.feature.reply.feature.feed.DetailFeedReplyMessageFragment.super.onViewCreated(r8, r9)
            android.os.Bundle r1 = r7.getArguments()
            r3 = 0
            if (r1 == 0) goto L_0x00bc
            java.lang.String r0 = "message"
            java.io.Serializable r1 = r1.getSerializable(r0)
        L_0x0013:
            X.Jl8 r1 = (X.C4175Jl8) r1
            r7.LJFF = r1
            java.lang.String r2 = ""
            if (r1 == 0) goto L_0x00ba
            com.ss.android.ugc.aweme.im.sdk.chat.viewmodel.ChatViewModel r0 = r7.LIZ()
            r0.LIZ(r1)
            java.lang.String r0 = r1.getConversationId()
            r7.LJ = r0
            int r1 = r1.getConversationType()
            int r0 = X.RN3.LIZIZ
            if (r1 != r0) goto L_0x00a2
            X.IcY r0 = X.C1003Ib4.LIZ
            X.Ib4 r1 = r0.LIZ()
            java.lang.String r0 = r7.LJ
            X.JlN r0 = r1.LIZ((java.lang.String) r0)
            java.lang.String r6 = X.C0939Ia2.LJ(r0)
        L_0x0040:
            boolean r0 = X.C3738Je5.LIZIZ(r6)
            r5 = 2131369470(0x7f0a1dfe, float:1.835892E38)
            if (r0 == 0) goto L_0x0066
            android.view.View r4 = r7.LIZ(r5)
            X.Qeg r4 = (X.Qeg) r4
            kotlin.h.b.n.LIZIZ(r4, r2)
            android.content.res.Resources r3 = r7.getResources()
            r2 = 2131823896(0x7f110d18, float:1.9280605E38)
            r0 = 1
            java.lang.Object[] r1 = new java.lang.Object[r0]
            r0 = 0
            r1[r0] = r6
            java.lang.String r0 = r3.getString(r2, r1)
            r4.setHint(r0)
        L_0x0066:
            android.view.View r0 = r7.LIZ(r5)
            X.Qeg r0 = (X.Qeg) r0
            r1 = r7
            r0.setOnClickListener(r1)
            r0 = 2131364520(0x7f0a0aa8, float:1.834888E38)
            android.view.View r0 = r7.LIZ(r0)
            X.4ZZ r0 = (X.4ZZ) r0
            r0.setOnClickListener(r1)
            r0 = 2131370108(0x7f0a207c, float:1.8360213E38)
            android.view.View r0 = r7.LIZ(r0)
            X.4ZZ r0 = (X.4ZZ) r0
            r0.setOnClickListener(r1)
            com.ss.android.ugc.aweme.im.sdk.chat.viewmodel.ChatViewModel r3 = r7.LIZ()
            X.1Bn<X.IZP<java.lang.Object>> r1 = r3.LIZLLL
            r2 = r7
            X.IkW r0 = new X.IkW
            r0.<init>(r7)
            r1.observe(r2, r0)
            X.1Bn<X.IZP<X.Jl8>> r1 = r3.LJ
            X.Ijz r0 = new X.Ijz
            r0.<init>(r7)
            r1.observe(r2, r0)
            return
        L_0x00a2:
            X.Ich r1 = X.C0937Ia0.LIZ
            java.lang.String r0 = r7.LJ
            long r0 = r1.LIZJ(r0)
            java.lang.String r0 = java.lang.String.valueOf(r0)
            com.ss.android.ugc.aweme.im.service.model.IMUser r0 = X.IBA.LIZ((java.lang.String) r0, (java.lang.String) r3)
            if (r0 == 0) goto L_0x00ba
            java.lang.String r6 = r0.getNickName()
            if (r6 != 0) goto L_0x0040
        L_0x00ba:
            r6 = r2
            goto L_0x0040
        L_0x00bc:
            r1 = r3
            goto L_0x0013
        */
        throw new UnsupportedOperationException("Method not decompiled: com.ss.android.ugc.aweme.im.sdk.chat.feature.reply.feature.feed.DetailFeedReplyMessageFragment.onViewCreated(android.view.View, android.os.Bundle):void");
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        int i;
        MethodCollector.i(1794);
        M12.LIZ(layoutInflater);
        View LIZ = 0HH.LIZ(layoutInflater, 2131559904, viewGroup, false);
        if (!C1971Iqg.LIZIZ()) {
            i = 2131369476;
        } else if (C1963IqY.LIZ().LJIILIIL) {
            i = 2131369478;
        } else {
            i = 2131369477;
        }
        ((ViewStub) LIZ.findViewById(i)).inflate();
        MethodCollector.o(1794);
        return LIZ;
    }
}
