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

import X.0CB;
import X.0CH;
import X.0cm;
import X.0cn;
import X.0yx;
import X.29s;
import X.2A8;
import X.2AS;
import X.2Ak;
import X.2Ce;
import X.2ss;
import X.4F1;
import X.6Is;
import X.7vl;
import X.C1064Fv7;
import X.C1097Fve;
import X.C1100Fvh;
import X.C1138FwJ;
import X.C1190Fx9;
import X.C1434G2p;
import X.C2512GdN;
import X.C2776Ghd;
import X.C2849Gio;
import X.C2852Gir;
import X.C2853Gis;
import X.C2854Git;
import X.C2855Giu;
import X.C2856Giv;
import X.C2857Giw;
import X.C2858Gix;
import X.C2859Giy;
import X.C2860Giz;
import X.C2861Gj0;
import X.C2862Gj1;
import X.C2863Gj2;
import X.C2864Gj3;
import X.C2865Gj4;
import X.C2866Gj5;
import X.C2867Gj6;
import X.C2868Gj7;
import X.C2869Gj8;
import X.C2870Gj9;
import X.C2873GjC;
import X.C3028Glh;
import X.C4100H7d;
import X.C4345HGo;
import X.C4366HHj;
import X.C4453HKs;
import X.C6455Hzs;
import X.Crj;
import X.GXB;
import X.M12;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import androidx.recyclerview.widget.RecyclerView;
import com.bytedance.android.live.ICommentService;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.livesdk.chatroom.CommentApi;
import com.bytedance.android.livesdk.model.RoomAuthStatus;
import com.bytedance.android.livesdk.model.UserAttr;
import com.bytedance.android.livesdk.model.message.RoomVerifyMessage;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.widgets.AnimatableRecyclableWidget;
import com.bytedance.ies.sdk.widgets.WidgetExtendsKt;
import com.ss.ugc.live.sdk.message.data.IMessage;
import com.ss.ugc.live.sdk.message.interfaces.IMessageManager;
import com.ss.ugc.live.sdk.message.interfaces.OnMessageListener;
import kotlin.h.b.n;
import org.json.JSONObject;

public final class QuickCommentWidget extends AnimatableRecyclableWidget implements Handler.Callback, 0cn, 6Is, OnMessageListener {
    public static final C2873GjC LJI = new C2873GjC((byte) 0);
    public final 2ss LIZ = new 2ss(this);
    public Room LIZIZ;
    public boolean LIZJ = true;
    public boolean LIZLLL = true;
    public final Handler LJ = new Handler(Looper.getMainLooper(), this);
    public boolean LJFF;
    public final Crj LJII = 7vl.LIZ(new C2867Gj6(this));
    public C2863Gj2 LJIIIIZZ;

    static {
        Covode.recordClassIndex(14556);
    }

    private final RecyclerView LIZLLL() {
        return (RecyclerView) this.LJII.getValue();
    }

    public final int getLayoutId() {
        return 2131561934;
    }

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

    public final void LIZ() {
        LIZJ();
    }

    public final void LIZIZ() {
        animateHide();
        this.LJFF = false;
    }

    public final void onHideAnimationEnd() {
        super.onHideAnimationEnd();
        LIZJ();
    }

    public final void onHideAnimationStart() {
        super.onHideAnimationStart();
        RecyclerView LIZLLL2 = LIZLLL();
        if (LIZLLL2 != null) {
            LIZLLL2.setEnabled(false);
        }
    }

    public final void LIZJ() {
        this.LIZJ = false;
        this.LJFF = false;
        if (isShowing()) {
            this.LJ.removeCallbacksAndMessages((Object) null);
            hide();
            cancelHideAnimation();
        }
    }

    public final void onUnload() {
        LIZJ();
        IMessageManager iMessageManager = (IMessageManager) this.dataChannel.LIZIZ(C4345HGo.class);
        if (iMessageManager != null) {
            iMessageManager.removeMessageListener(this);
        }
        0cm.LIZ(ICommentService.class).removeCommentEventListener(this);
    }

    public final void onMessage(IMessage iMessage) {
        if (!(iMessage instanceof RoomVerifyMessage)) {
            iMessage = null;
        }
        RoomVerifyMessage roomVerifyMessage = (RoomVerifyMessage) iMessage;
        if (roomVerifyMessage != null && roomVerifyMessage.LIZ == 3) {
            LIZJ();
        }
    }

    public final boolean handleMessage(Message message) {
        M12.LIZ(message);
        if (message.what != 1) {
            return false;
        }
        Room room = this.LIZIZ;
        if (room != null) {
            ((C4366HHj) ((CommentApi) 0yx.LIZ().LIZ(CommentApi.class)).sendChatEvent(room.getId(), 1).LIZ(new C6455Hzs()).LIZ(WidgetExtendsKt.autoDispose(this))).LIZ(C2868Gj7.LIZ, C2869Gj8.LIZ);
        }
        LIZIZ();
        return true;
    }

    public final void onInit(Object[] objArr) {
        this.LJIIIIZZ = new C2863Gj2();
        RecyclerView LIZLLL2 = LIZLLL();
        if (LIZLLL2 != null) {
            C2863Gj2 gj2 = this.LJIIIIZZ;
            if (gj2 == null) {
                n.LIZ("");
            }
            M12.LIZ(LIZLLL2);
            gj2.LIZLLL = LIZLLL2;
            RecyclerView recyclerView = gj2.LIZLLL;
            if (recyclerView == null) {
                n.LIZ("");
            }
            recyclerView.LIZ(new C2864Gj3(gj2));
        }
        RecyclerView LIZLLL3 = LIZLLL();
        if (LIZLLL3 != null) {
            LIZLLL3.setAdapter(this.LIZ);
        }
        RecyclerView LIZLLL4 = LIZLLL();
        if (LIZLLL4 != null) {
            LIZLLL4.LIZ(new 4F1(this));
        }
    }

    public final void onLoad(Object[] objArr) {
        RoomAuthStatus roomAuthStatus;
        RoomAuthStatus roomAuthStatus2;
        UserAttr userAttr;
        RecyclerView LIZLLL2 = LIZLLL();
        if (LIZLLL2 != null) {
            LIZLLL2.setEnabled(true);
        }
        C2863Gj2 gj2 = this.LJIIIIZZ;
        if (gj2 == null) {
            n.LIZ("");
        }
        DataChannel dataChannel = this.dataChannel;
        n.LIZIZ(dataChannel, "");
        M12.LIZ(dataChannel);
        gj2.LIZJ = dataChannel;
        this.LIZIZ = (Room) this.dataChannel.LIZIZ(C1064Fv7.class);
        LIZJ();
        this.LIZJ = true;
        this.LIZLLL = true;
        C3028Glh LIZIZ2 = C4100H7d.LIZ().LIZIZ();
        n.LIZIZ(LIZIZ2, "");
        if (!LIZIZ2.LJ()) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        User user = (User) this.dataChannel.LIZIZ(C1434G2p.class);
        if (user == null || (userAttr = user.getUserAttr()) == null || !userAttr.LIZ) {
            this.dataChannel.LIZIZ((0CH) this, C2512GdN.class, new C2856Giv(this));
        } else {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        Room room = this.LIZIZ;
        if (!(room == null || (roomAuthStatus2 = room.getRoomAuthStatus()) == null || roomAuthStatus2.getQuickCommentState() != 2)) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        Room room2 = this.LIZIZ;
        if (room2 == null || (roomAuthStatus = room2.getRoomAuthStatus()) == null || roomAuthStatus.enableChat) {
            IMessageManager iMessageManager = (IMessageManager) this.dataChannel.LIZIZ(C4345HGo.class);
            if (iMessageManager != null) {
                iMessageManager.addMessageListener(C4453HKs.ROOM_VERIFY.getIntType(), this);
            }
        } else {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        if (C4100H7d.LIZ().LIZIZ().LIZ(C2849Gio.COMMENT)) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        if (C2776Ghd.LIZIZ(this.LIZIZ) && !C2776Ghd.LIZ(this.LIZIZ)) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        Room room3 = this.LIZIZ;
        if (room3 != null && room3.isThirdParty) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        Integer num = (Integer) this.dataChannel.LIZIZ(GXB.class);
        if (num != null && num.intValue() > 0) {
            this.LIZJ = false;
            this.LIZLLL = false;
        }
        DataChannel dataChannel2 = this.dataChannel;
        dataChannel2.LIZIZ((0CH) this, 2Ce.class, new C2857Giw(this));
        dataChannel2.LIZIZ((0CH) this, 2A8.class, new C2858Gix(this));
        dataChannel2.LIZIZ((0CH) this, 2AS.class, new C2865Gj4(this));
        dataChannel2.LIZIZ((0CH) this, C1138FwJ.class, new C2859Giy(this));
        dataChannel2.LIZIZ((0CH) this, C1100Fvh.class, new C2860Giz(this));
        dataChannel2.LIZIZ((0CH) this, C1097Fve.class, new C2861Gj0(this));
        dataChannel2.LIZIZ((0CH) this, 2Ak.class, new C2862Gj1(this));
        dataChannel2.LIZIZ((0CH) this, GXB.class, new C2855Giu(this));
        dataChannel2.LIZIZ((0CH) this, 29s.class, new C2853Gis(this));
        dataChannel2.LIZIZ((0CH) this, C1190Fx9.class, new C2854Git(this));
        if (this.LIZJ) {
            this.LJ.postDelayed(new C2870Gj9(this), 3000);
            0cm.LIZ(ICommentService.class).addCommentEventListener(this);
        }
    }

    public final void LIZ(boolean z, JSONObject jSONObject) {
        String str;
        boolean z2;
        String str2;
        Room room = this.LIZIZ;
        if (room != null) {
            if (z) {
                str = "1";
            } else {
                str = "0";
            }
            CommentApi commentApi = (CommentApi) 0yx.LIZ().LIZ(CommentApi.class);
            long id = room.getId();
            long ownerUserId = room.getOwnerUserId();
            User owner = room.getOwner();
            if (owner != null) {
                z2 = owner.isSubscribed();
            } else {
                z2 = false;
            }
            if (jSONObject == null || (str2 = jSONObject.toString()) == null) {
                str2 = "";
            }
            ((C4366HHj) commentApi.queryQuickComments(id, ownerUserId, z2, str, str2).LIZ(new C6455Hzs()).LIZ(WidgetExtendsKt.autoDispose(this))).LIZ(new C2852Gir(this, z, jSONObject), new C2866Gj5(this, z, jSONObject));
        }
    }
}
