package com.bytedance.android.livesdk.chatroom.view;

import X.08o;
import X.0CH;
import X.0HH;
import X.0dA;
import X.1MZ;
import X.1sO;
import X.2Ak;
import X.2Pr;
import X.2te;
import X.2th;
import X.C1064Fv7;
import X.C2579GeS;
import X.C2590Ged;
import X.C2608Gev;
import X.C2609Gew;
import X.C2610Gex;
import X.C2611Gey;
import X.C2614Gf1;
import X.C2615Gf2;
import X.C2632GfJ;
import X.C2675Gg0;
import X.GSF;
import X.LsC;
import X.M12;
import X.T0N;
import android.app.Dialog;
import android.content.res.ColorStateList;
import android.graphics.drawable.ColorDrawable;
import android.os.Build;
import android.os.Bundle;
import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.ImageView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import com.bytedance.android.livesdk.livesetting.comment.LiveInputDialogAnimationSetting;
import com.bytedance.android.livesdk.model.RoomSticker;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.HashMap;
import kotlin.h.b.n;

public final class StickerEditFragment extends DialogFragment {
    public static final C2614Gf1 LJIIJ = new C2614Gf1((byte) 0);
    public 1MZ LIZ;
    public 1sO LIZIZ;
    public Room LIZJ;
    public C2615Gf2 LIZLLL;
    public String LJ;
    public DataChannel LJFF;
    public RoomSticker LJI;
    public LsC<? super Boolean, 2Pr> LJII;
    public String LJIIIIZZ;
    public long LJIIIZ;
    public boolean LJIIJJI;
    public ImageView LJIIL;
    public final boolean LJIILIIL;
    public T0N LJIILJJIL;
    public ConstraintLayout LJIILL;
    public Integer LJIILLIIL = 0;
    public final TextWatcher LJIIZILJ = new C2608Gev(this);
    public HashMap LJIJ;

    static {
        Covode.recordClassIndex(14486);
    }

    private View LIZIZ() {
        if (this.LJIJ == null) {
            this.LJIJ = new HashMap();
        }
        View view = (View) this.LJIJ.get(2131371153);
        if (view != null) {
            return view;
        }
        View view2 = getView();
        if (view2 == null) {
            return null;
        }
        View findViewById = view2.findViewById(2131371153);
        this.LJIJ.put(2131371153, findViewById);
        return findViewById;
    }

    public final /* synthetic */ void onDestroyView() {
        StickerEditFragment.super.onDestroyView();
        HashMap hashMap = this.LJIJ;
        if (hashMap != null) {
            hashMap.clear();
        }
    }

    public final void LIZ() {
        try {
            dismissAllowingStateLoss();
            2te.constructor-impl(2Pr.LIZ);
        } catch (Throwable th) {
            2te.constructor-impl(2th.LIZ(th));
        }
    }

    public final void onDestroy() {
        StickerEditFragment.super.onDestroy();
        LsC<? super Boolean, 2Pr> lsC = this.LJII;
        if (lsC != null) {
            lsC.invoke(false);
        }
        this.LJII = null;
    }

    public final void onResume() {
        StickerEditFragment.super.onResume();
        1MZ r1 = this.LIZ;
        if (r1 != null) {
            r1.post(new C2609Gew(this));
        }
        1MZ r12 = this.LIZ;
        if (r12 != null) {
            r12.setOnFocusChangeListener(new C2611Gey(this));
        }
    }

    public final void onActivityCreated(Bundle bundle) {
        Window window;
        StickerEditFragment.super.onActivityCreated(bundle);
        Dialog dialog = getDialog();
        if (dialog != null && (window = dialog.getWindow()) != null) {
            window.setLayout(-1, -1);
        }
    }

    public final void LIZ(boolean z) {
        if (z) {
            ((ImageView) LIZIZ()).setImageResource(2131234996);
            08o.LIZ((ImageView) LIZIZ(), (ColorStateList) null);
            return;
        }
        ((ImageView) LIZIZ()).setImageResource(2131234994);
        08o.LIZ((ImageView) LIZIZ(), ColorStateList.valueOf(0dA.LIZ(LIZIZ(), 2130971317)));
    }

    public final void onCreate(Bundle bundle) {
        Room room;
        StickerEditFragment.super.onCreate(bundle);
        DataChannel LIZ2 = GSF.LIZ((Fragment) this);
        this.LJFF = LIZ2;
        Integer num = null;
        if (LIZ2 != null) {
            room = (Room) LIZ2.LIZIZ(C1064Fv7.class);
        } else {
            room = null;
        }
        this.LIZJ = room;
        Bundle arguments = getArguments();
        if (arguments != null) {
            num = Integer.valueOf(arguments.getInt("build_dialog"));
        }
        this.LJIILLIIL = num;
        setCancelable(true);
        setStyle(1, 2131887294);
        DataChannel dataChannel = this.LJFF;
        if (dataChannel != null) {
            dataChannel.LIZIZ((0CH) this, 2Ak.class, new C2590Ged(this));
        }
        C2675Gg0.LIZ().LIZ(C2632GfJ.class).LIZLLL(new C2610Gex(this));
    }

    public final Dialog onCreateDialog(Bundle bundle) {
        Dialog onCreateDialog = StickerEditFragment.super.onCreateDialog(bundle);
        n.LIZIZ(onCreateDialog, "");
        onCreateDialog.setCanceledOnTouchOutside(this.LJIILIIL);
        Window window = onCreateDialog.getWindow();
        if (window != null) {
            window.setGravity(80);
            window.setLayout(-1, -2);
            window.setBackgroundDrawable(new ColorDrawable(0));
            window.addFlags(32);
            if (!LiveInputDialogAnimationSetting.enableOpt() || Build.VERSION.SDK_INT < 30) {
                window.setSoftInputMode(3);
            } else {
                window.setSoftInputMode(19);
            }
            window.clearFlags(2);
            this.LJIIJJI = true;
        }
        return onCreateDialog;
    }

    /* JADX WARNING: Removed duplicated region for block: B:12:0x0034  */
    /* JADX WARNING: Removed duplicated region for block: B:21:0x0054  */
    /* JADX WARNING: Removed duplicated region for block: B:24:0x005a  */
    /* JADX WARNING: Removed duplicated region for block: B:38:0x00d1  */
    /* JADX WARNING: Removed duplicated region for block: B:45:0x00ea  */
    /* JADX WARNING: Removed duplicated region for block: B:46:0x00ef  */
    /* JADX WARNING: Removed duplicated region for block: B:61:? A[RETURN, SYNTHETIC] */
    /* Code decompiled incorrectly, please refer to instructions dump. */
    public final void onViewCreated(android.view.View r9, android.os.Bundle r10) {
        /*
            r8 = this;
            X.M12.LIZ(r9)
            com.bytedance.android.livesdk.chatroom.view.StickerEditFragment.super.onViewCreated(r9, r10)
            android.app.Dialog r1 = r8.getDialog()
            X.Gf0 r0 = X.C2613Gf0.LIZ
            r1.setOnKeyListener(r0)
            X.LsC<? super java.lang.Boolean, X.2Pr> r1 = r8.LJII
            r3 = 1
            if (r1 == 0) goto L_0x001b
            java.lang.Boolean r0 = java.lang.Boolean.valueOf(r3)
            r1.invoke(r0)
        L_0x001b:
            java.lang.Integer r1 = r8.LJIILLIIL
            java.lang.String r5 = ""
            r7 = 0
            if (r1 != 0) goto L_0x00f4
        L_0x0022:
            r4 = r5
        L_0x0023:
            r8.LJIIIIZZ = r4
            X.1MZ r1 = r8.LIZ
            r0 = 0
            if (r4 == 0) goto L_0x0030
            int r0 = r4.length()
            if (r0 != 0) goto L_0x00d6
        L_0x0030:
            X.1sO r1 = r8.LIZIZ
            if (r1 != 0) goto L_0x0037
            kotlin.h.b.n.LIZ(r5)
        L_0x0037:
            r0 = 2131829245(0x7f1121fd, float:1.9291454E38)
            r1.setText(r0)
            X.Gf2 r0 = r8.LIZLLL
            if (r0 == 0) goto L_0x004d
            java.lang.String r0 = r0.getContent()
            if (r0 == 0) goto L_0x004d
            int r0 = r0.length()
            if (r0 != 0) goto L_0x00d3
        L_0x004d:
            r8.LIZ(r3)
            X.Gf2 r0 = r8.LIZLLL
            if (r0 == 0) goto L_0x00d1
            T r1 = r0.LJFF
        L_0x0056:
            boolean r0 = r1 instanceof com.bytedance.android.livesdk.model.RoomSticker
            if (r0 == 0) goto L_0x00cb
            com.bytedance.ies.sdk.datachannel.DataChannel r6 = X.GSF.LIZ((androidx.fragment.app.Fragment) r8)
            r5 = r1
            com.bytedance.android.livesdk.model.RoomSticker r5 = (com.bytedance.android.livesdk.model.RoomSticker) r5
            X.GeO r2 = X.C2575GeO.LJ
            long r0 = r1.LJIIL
            java.lang.Long r0 = java.lang.Long.valueOf(r0)
            java.lang.String r4 = r2.LIZ((java.lang.Long) r0)
            X.M12.LIZ(r5)
            if (r6 == 0) goto L_0x00cf
            java.lang.Class<X.Fv7> r0 = X.C1064Fv7.class
            java.lang.Object r2 = r6.LIZIZ(r0)
            com.bytedance.android.livesdkapi.depend.model.live.Room r2 = (com.bytedance.android.livesdkapi.depend.model.live.Room) r2
        L_0x007a:
            X.GtO r1 = X.C3491GtA.LJFF
            java.lang.String r0 = "livesdk_live_character_edit_panel_show"
            X.GtA r3 = r1.LIZ(r0)
            r3.LIZ((com.bytedance.ies.sdk.datachannel.DataChannel) r6)
            if (r2 == 0) goto L_0x0095
            com.bytedance.android.live.base.model.user.User r0 = r2.getOwner()
            if (r0 == 0) goto L_0x0095
            long r0 = r0.getId()
            java.lang.Long r7 = java.lang.Long.valueOf(r0)
        L_0x0095:
            java.lang.String r1 = java.lang.String.valueOf(r7)
            java.lang.String r0 = "anchor_id"
            r3.LIZ((java.lang.String) r0, (java.lang.String) r1)
            java.lang.String r1 = "live_type"
            java.lang.String r0 = "video_live"
            r3.LIZ((java.lang.String) r1, (java.lang.String) r0)
            if (r2 == 0) goto L_0x00cc
            long r1 = r2.getId()
        L_0x00ab:
            java.lang.String r0 = "room_id"
            r3.LIZ((java.lang.String) r0, (long) r1)
            long r1 = r5.LJIIL
            java.lang.String r0 = "prop_id"
            r3.LIZ((java.lang.String) r0, (long) r1)
            java.lang.String r0 = "resource_id"
            r3.LIZ((java.lang.String) r0, (java.lang.String) r4)
            java.lang.String r0 = "live_take_detail"
            r3.LJ(r0)
            java.lang.String r1 = r5.LJIIIIZZ
            java.lang.String r0 = "prop_name"
            r3.LIZ((java.lang.String) r0, (java.lang.String) r1)
            r3.LIZLLL()
        L_0x00cb:
            return
        L_0x00cc:
            r1 = 0
            goto L_0x00ab
        L_0x00cf:
            r2 = r7
            goto L_0x007a
        L_0x00d1:
            r1 = r7
            goto L_0x0056
        L_0x00d3:
            r3 = 0
            goto L_0x004d
        L_0x00d6:
            if (r1 != 0) goto L_0x00da
            goto L_0x0030
        L_0x00da:
            int r2 = r1.getSelectionStart()
            android.text.Editable r1 = r1.getEditableText()
            if (r2 < 0) goto L_0x00ea
            int r0 = r1.length()
            if (r2 < r0) goto L_0x00ef
        L_0x00ea:
            r1.append(r4)
            goto L_0x0030
        L_0x00ef:
            r1.insert(r2, r4)
            goto L_0x0030
        L_0x00f4:
            int r0 = r1.intValue()
            if (r0 != r3) goto L_0x0104
            X.Gf2 r0 = r8.LIZLLL
            if (r0 == 0) goto L_0x0117
            java.lang.String r4 = r0.getContent()
            goto L_0x0023
        L_0x0104:
            int r1 = r1.intValue()
            r0 = 2
            if (r1 != r0) goto L_0x0022
            X.Gf2 r0 = r8.LIZLLL
            if (r0 == 0) goto L_0x0117
            T r0 = r0.LJFF
            if (r0 == 0) goto L_0x0117
            java.lang.String r4 = r0.LJIILJJIL
            goto L_0x0023
        L_0x0117:
            r4 = r7
            goto L_0x0023
        */
        throw new UnsupportedOperationException("Method not decompiled: com.bytedance.android.livesdk.chatroom.view.StickerEditFragment.onViewCreated(android.view.View, android.os.Bundle):void");
    }

    public final View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle) {
        M12.LIZ(layoutInflater);
        View LIZ2 = 0HH.LIZ(LayoutInflater.from(getContext()), 2131562051, viewGroup, false);
        this.LIZ = LIZ2.findViewById(2131371148);
        1sO findViewById = LIZ2.findViewById(2131364421);
        n.LIZIZ(findViewById, "");
        this.LIZIZ = findViewById;
        1MZ r1 = this.LIZ;
        if (r1 != null) {
            r1.addTextChangedListener(this.LJIIZILJ);
        }
        T0N findViewById2 = LIZ2.findViewById(2131372956);
        this.LJIILJJIL = findViewById2;
        if (findViewById2 != null) {
            findViewById2.setActivity(getActivity());
        }
        T0N t0n = this.LJIILJJIL;
        if (t0n != null) {
            t0n.setShowStatusBar(true);
        }
        this.LJIILL = LIZ2.findViewById(2131370688);
        ImageView imageView = (ImageView) LIZ2.findViewById(2131371153);
        this.LJIIL = imageView;
        if (imageView != null) {
            imageView.setOnClickListener(new C2579GeS(this));
        }
        return LIZ2;
    }
}
