package com.bytedance.android.livesdk.gifttray;

import X.0CB;
import X.0CH;
import X.29j;
import X.2AK;
import X.6Is;
import X.C1059Fv2;
import X.C1064Fv7;
import X.C1671GBs;
import X.C2675Gg0;
import X.C4366HHj;
import X.C4654HSl;
import X.C4657HSo;
import X.C4661HSs;
import X.C4666HSx;
import X.C4667HSy;
import X.DEF;
import X.H69;
import X.HLW;
import X.HR6;
import X.HR8;
import X.HRA;
import X.HRC;
import X.HT3;
import X.HT9;
import X.HTD;
import X.M12;
import X.Mjy;
import X.Mk2;
import X.Mk3;
import android.view.View;
import android.view.ViewGroup;
import com.bytedance.android.livesdk.livesetting.gift.LiveGiftEffectMessagePreloadSetting;
import com.bytedance.android.livesdk.model.Gift;
import com.bytedance.android.livesdk.model.message.AssetMessage;
import com.bytedance.android.livesdk.model.message.GiftMessage;
import com.bytedance.android.livesdk.model.message.LiveTrayMessage;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.covode.number.Covode;
import com.bytedance.frameworks.apm.trace.MethodCollector;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import java.util.Iterator;
import kotlin.h.b.n;

public final class LiveGiftTrayWidget extends AbsNormalGiftAnimWidget implements HTD, 6Is {
    public C4654HSl LIZIZ;
    public final int LIZJ = 1;
    public final Mjy LIZLLL = new Mjy();
    public C4667HSy LJ;

    static {
        Covode.recordClassIndex(16509);
    }

    public final void LIZ(AssetMessage assetMessage) {
    }

    public final int getLayoutId() {
        return 2131562192;
    }

    public final void onInit(Object[] objArr) {
    }

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

    public final void LIZ() {
        C4654HSl hSl = this.LIZIZ;
        if (hSl != null) {
            HT9.LIZ.LIZIZ(hSl.LIZ.size());
            HT9.LIZ.LIZ(hSl.getNotCommonShowAmount());
            HT9.LIZ.LIZJ(hSl.getNotEffectShowAmount());
            hSl.LIZ.clear();
            hSl.LIZIZ.clear();
            hSl.LJ.clear();
            hSl.LJFF.clear();
        }
    }

    public final void LIZIZ() {
        DataChannel dataChannel;
        MethodCollector.i(2258);
        C4654HSl hSl = this.LIZIZ;
        if (hSl != null) {
            Iterator<C4657HSo> it = hSl.LIZJ.iterator();
            while (it.hasNext()) {
                C4657HSo next = it.next();
                ViewGroup viewGroup = next.LJFF;
                if (viewGroup == null) {
                    n.LIZ("");
                }
                viewGroup.removeView(next.LIZJ);
                if (next.LJII) {
                    C4666HSx hSx = next.LIZJ;
                    if (hSx != null) {
                        hSx.LIZIZ();
                    }
                } else {
                    C4666HSx hSx2 = next.LIZJ;
                    if (hSx2 != null) {
                        hSx2.LIZIZ();
                    }
                }
                next.LIZJ = null;
                ViewGroup viewGroup2 = next.LJFF;
                if (viewGroup2 == null) {
                    n.LIZ("");
                }
                if (viewGroup2.getChildCount() == 0 && (dataChannel = next.LIZLLL) != null) {
                    dataChannel.LIZJ(29j.class, true);
                }
                next.LJ = null;
                next.LIZIZ = false;
                next.LIZ = true;
                next.LJIIIIZZ = false;
                next.LJII = false;
            }
            MethodCollector.o(2258);
            return;
        }
        MethodCollector.o(2258);
    }

    public final void onUnload() {
        boolean z;
        Boolean bool;
        this.LIZLLL.LIZ();
        C4654HSl hSl = this.LIZIZ;
        if (hSl != null) {
            C4661HSs hSs = HT9.LIZ;
            DataChannel dataChannel = hSl.LIZLLL;
            if (dataChannel == null || (bool = (Boolean) dataChannel.LIZIZ(C1059Fv2.class)) == null) {
                z = false;
            } else {
                z = bool.booleanValue();
            }
            hSs.LIZ(z, hSl.LIZ.size(), hSl.getNotEffectShowAmount(), hSl.getNotCommonShowAmount());
            hSl.LIZ.clear();
            hSl.LIZIZ.clear();
            Iterator<C4657HSo> it = hSl.LIZJ.iterator();
            while (it.hasNext()) {
                it.next().LJIIIZ.LIZ();
            }
            hSl.LJ.clear();
            hSl.LJFF.clear();
        }
    }

    private final void LIZIZ(HR8 hr8) {
        C4654HSl hSl = this.LIZIZ;
        if (hSl != null) {
            hSl.LIZ(hr8);
        }
    }

    public final void LIZ(HR8 hr8) {
        M12.LIZ(hr8);
        LIZIZ(hr8);
    }

    public final void LIZ(LiveTrayMessage liveTrayMessage) {
        M12.LIZ(liveTrayMessage);
        HR8 LIZ = HRA.LIZ.LIZ(liveTrayMessage);
        if (!this.LIZ) {
            C4654HSl hSl = this.LIZIZ;
            if (hSl != null) {
                hSl.LIZ(LIZ);
                return;
            }
            return;
        }
        HR6.LIZ.LIZ(LIZ, HLW.SCREEN_CLEAR_MODE);
    }

    public final void LIZIZ(GiftMessage giftMessage) {
        long j;
        Room room;
        M12.LIZ(giftMessage);
        giftMessage.LJIJJLI = true;
        HRA hra = HRA.LIZ;
        DataChannel dataChannel = this.dataChannel;
        if (dataChannel == null || (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) == null) {
            j = 0;
        } else {
            j = room.getOwnerUserId();
        }
        HR8 LIZ = hra.LIZ(giftMessage, j);
        LIZ.LIZ(HRC.VIDEO_ONLY);
        C4654HSl hSl = this.LIZIZ;
        if (hSl != null) {
            hSl.LIZ(LIZ);
        }
    }

    public final void LIZ(GiftMessage giftMessage) {
        long j;
        GiftMessage giftMessage2;
        Gift gift;
        Room room;
        if (giftMessage != null && giftMessage.LJIILL != 1) {
            HRA hra = HRA.LIZ;
            DataChannel dataChannel = this.dataChannel;
            if (dataChannel == null || (room = (Room) dataChannel.LIZIZ(C1064Fv7.class)) == null) {
                j = 0;
            } else {
                j = room.getOwnerUserId();
            }
            HR8 LIZ = hra.LIZ(giftMessage, j);
            if (this.LIZ) {
                HR6.LIZ.LIZ(LIZ, HLW.SCREEN_CLEAR_MODE);
            } else if (LiveGiftEffectMessagePreloadSetting.INSTANCE.getValue() != 1 || (giftMessage2 = LIZ.LJJIZ) == null || (gift = giftMessage2.LJIL) == null || gift.LJ != 2) {
                LIZIZ(LIZ);
            } else {
                C4667HSy hSy = this.LJ;
                if (hSy != null) {
                    hSy.LIZ(LIZ);
                }
            }
        }
    }

    public final void onLoad(Object[] objArr) {
        HT9.LIZ.LIZ();
        View view = this.contentView;
        0CH r3 = null;
        if (!(view instanceof C4654HSl)) {
            view = null;
        }
        C4654HSl hSl = (C4654HSl) view;
        this.LIZIZ = hSl;
        if (hSl != null) {
            hSl.setDataCenter(this.dataChannel);
        }
        C4654HSl hSl2 = this.LIZIZ;
        if (hSl2 != null) {
            C4657HSo hSo = new C4657HSo(0);
            C4657HSo hSo2 = new C4657HSo(1);
            hSo.LIZ((ViewGroup) hSl2);
            hSo2.LIZ((ViewGroup) hSl2);
            hSo.LJI = hSl2.LJI;
            hSo2.LJI = hSl2.LJI;
            hSo.LIZ(hSl2.LIZLLL);
            hSo2.LIZ(hSl2.LIZLLL);
            hSl2.LIZJ.add(hSo);
            hSl2.LIZJ.add(hSo2);
        }
        C4667HSy hSy = new C4667HSy();
        this.LJ = hSy;
        hSy.LIZ = this;
        this.LIZLLL.LIZ(((C4366HHj) C2675Gg0.LIZ().LIZ(C1671GBs.class).LIZ(Mk2.LIZ(Mk3.LIZ)).LIZ(DEF.LIZ(this))).LIZ(new H69(this)));
        DataChannel dataChannel = this.dataChannel;
        if (dataChannel != null) {
            DataChannel dataChannel2 = this.dataChannel;
            if (dataChannel2 != null) {
                r3 = dataChannel2.LIZIZ();
            }
            dataChannel.LIZ(r3, 2AK.class, new HT3(this));
        }
    }
}
