package com.bytedance.android.livesdk.olddialog;

import X.0b0;
import X.0bM;
import X.1Mn;
import X.29b;
import X.29d;
import X.C1044Fun;
import X.C1059Fv2;
import X.C1064Fv7;
import X.C1627GAa;
import X.C2307Ga4;
import X.C2313GaA;
import X.C2675Gg0;
import X.C3491GtA;
import X.C3543Gu0;
import X.C4215HBo;
import X.C4345HGo;
import X.C4453HKs;
import X.C4495HMi;
import X.C4503HMq;
import X.C4515HNc;
import X.C4517HNe;
import X.C4519HNg;
import X.C4522HNj;
import X.C4523HNk;
import X.C4526HNn;
import X.C4527HNo;
import X.C4529HNq;
import X.C4530HNr;
import X.C4533HNu;
import X.C4534HNv;
import X.C4536HNx;
import X.C4593HQc;
import X.C5065HdS;
import X.C5069HdW;
import X.G08;
import X.GAY;
import X.GMS;
import X.HFX;
import X.HLZ;
import X.HM4;
import X.HN0;
import X.HND;
import X.HO5;
import X.HRS;
import X.M12;
import X.Mjy;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.os.SystemClock;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import androidx.fragment.app.Fragment;
import com.bytedance.android.live.base.model.user.User;
import com.bytedance.android.livesdk.LiveDialogFragment;
import com.bytedance.android.livesdk.gift.model.GiftPage;
import com.bytedance.android.livesdk.gift.model.Prop;
import com.bytedance.android.livesdk.livesetting.wallet.LiveEnableRechargeSucceedAnimationSetting;
import com.bytedance.android.livesdk.model.Gift;
import com.bytedance.android.livesdk.model.Hashtag;
import com.bytedance.android.livesdk.olddialog.widget.LiveNewGiftBottomWidget;
import com.bytedance.android.livesdk.olddialog.widget.LiveNewGiftGuestInfoWidget;
import com.bytedance.android.livesdk.olddialog.widget.LiveNewGiftPageIndicatorWidget;
import com.bytedance.android.livesdk.olddialog.widget.LiveNewGiftPanelWidget;
import com.bytedance.android.livesdk.service.assets.GiftManager;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.widget.WidgetManager;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.bytedance.ies.sdk.datachannel.DataChannelGlobal;
import com.bytedance.ies.sdk.widgets.FluencyOpt;
import com.bytedance.ies.sdk.widgets.WidgetCreateTimeUtil;
import com.ss.ugc.live.sdk.message.interfaces.IMessageManager;
import java.util.ArrayList;
import java.util.List;

public class LiveNewGiftDialog extends LiveDialogFragment implements HM4, C4530HNr, HND {
    public LiveNewGiftPanelWidget LIZ;
    public LiveNewGiftBottomWidget LIZIZ;
    public C1627GAa LIZJ;
    public String LIZLLL;
    public int LJ;
    public Room LJFF;
    public boolean LJI;
    public HLZ LJII;
    public C4519HNg LJIIIIZZ;
    public C4515HNc LJIIIZ;
    public String LJIIJ;
    public long LJIIJJI;
    public Runnable LJIIZILJ;
    public final List<GiftPage> LJIJ = new ArrayList();
    public final Mjy LJIJI = new Mjy();
    public final WidgetCreateTimeUtil LJIJJ = new WidgetCreateTimeUtil();

    static {
        Covode.recordClassIndex(19826);
    }

    public final C2307Ga4 b_() {
        return C2307Ga4.PANEL_GIFT;
    }

    public final void LIZLLL() {
        C2675Gg0.LIZ().LIZ((Object) new C4533HNu());
        getView().findViewById(2131365311).setVisibility(8);
    }

    public final boolean LJIIIIZZ() {
        if (this.LJIILIIL != null) {
            this.LJIILIIL.LIZJ(29b.class, false);
        }
        return super.LJIIIIZZ();
    }

    public void dismiss() {
        if (this.LJIILIIL != null) {
            this.LJIILIIL.LIZJ(29b.class, false);
        }
        Mjy mjy = this.LJIJI;
        if (mjy != null) {
            mjy.LIZ();
        }
        super.dismiss();
    }

    public void onResume() {
        LiveNewGiftDialog.super.onResume();
        LiveNewGiftPanelWidget liveNewGiftPanelWidget = this.LIZ;
        if (liveNewGiftPanelWidget != null) {
            liveNewGiftPanelWidget.LJIJ = SystemClock.uptimeMillis() - this.LJIIJJI;
        }
    }

    public void onStop() {
        LiveNewGiftDialog.super.onStop();
        if (this.LJIILIIL != null) {
            this.LJIILIIL.LIZIZ(29d.class, false);
        }
    }

    public final C1044Fun LIZ() {
        int i;
        int i2;
        int i3;
        IMessageManager iMessageManager;
        if (this.LJIILIIL != null) {
            boolean booleanValue = ((Boolean) this.LJIILIIL.LIZIZ(HFX.class)).booleanValue();
            C4515HNc hNc = this.LJIIIZ;
            DataChannel dataChannel = this.LJIILIIL;
            hNc.LIZJ = dataChannel;
            if (dataChannel != null) {
                iMessageManager = (IMessageManager) dataChannel.LIZIZ(C4345HGo.class);
            } else {
                iMessageManager = null;
            }
            hNc.LIZIZ = iMessageManager;
            IMessageManager iMessageManager2 = hNc.LIZIZ;
            if (iMessageManager2 != null) {
                iMessageManager2.addMessageListener(C4453HKs.GIFT_UPDATE.getIntType(), hNc);
            }
            if (!booleanValue) {
                i = 2131561597;
                i3 = 2131887270;
                i2 = 5;
                C1044Fun fun = new C1044Fun(i);
                fun.LIZIZ = i3;
                fun.LJIIJJI = 48;
                fun.LJI = i2;
                return fun;
            }
        }
        i = 2131561596;
        i3 = 2131887269;
        i2 = 80;
        C1044Fun fun2 = new C1044Fun(i);
        fun2.LIZIZ = i3;
        fun2.LJIIJJI = 48;
        fun2.LJI = i2;
        return fun2;
    }

    public void onDestroy() {
        IMessageManager iMessageManager;
        LiveNewGiftDialog.super.onDestroy();
        HRS.LIZ.LIZ();
        DataChannelGlobal.LIZLLL.LIZIZ((Object) this);
        HN0 LIZ2 = HN0.LIZ();
        if (LIZ2.LIZIZ.contains(this)) {
            LIZ2.LIZIZ.remove(this);
        }
        C4519HNg hNg = this.LJIIIIZZ;
        if (hNg != null && hNg.LIZJ != null && this.LJIIIIZZ.LIZLLL != null && this.LJIIIIZZ.LJ != null) {
            C4515HNc hNc = this.LJIIIZ;
            if (!(hNc == null || (iMessageManager = hNc.LIZIZ) == null)) {
                iMessageManager.removeMessageListener(hNc);
            }
            this.LJIJJ.send();
            this.LJIIIIZZ.LIZJ.removeObservers(this);
            this.LJIIIIZZ.LIZLLL.removeObservers(this);
            this.LJIIIIZZ.LJ.removeObservers(this);
            int intValue = ((Integer) this.LJIIIIZZ.LIZIZ.getValue()).intValue();
            for (int i = 0; i < this.LJIJ.size(); i++) {
                if (this.LJIJ.get(i).pageType == intValue) {
                    HO5 ho5 = HO5.LJIIIIZZ;
                    GiftPage giftPage = this.LJIJ.get(i);
                    M12.LIZ(giftPage);
                    C3491GtA LIZ3 = C3491GtA.LJFF.LIZ("tab_leave");
                    LIZ3.LIZ();
                    LIZ3.LIZ("gift_dialog_request_id", C4529HNq.LIZ);
                    LIZ3.LIZ("live", giftPage.pageName);
                    LIZ3.LIZ("tab_position", i + 1);
                    LIZ3.LIZ("stay_duration", (GMS.LIZ() - ho5.LJFF) / 1000);
                    LIZ3.LIZLLL();
                    return;
                }
            }
        }
    }

    public void onStart() {
        boolean z;
        super.onStart();
        if (this.LJIILIIL != null) {
            boolean booleanValue = ((Boolean) this.LJIILIIL.LIZIZ(HFX.class)).booleanValue();
            if (!booleanValue || (!this.LJI && !0bM.LIZ(getContext()))) {
                z = false;
            } else {
                z = true;
            }
            Window window = getDialog().getWindow();
            if (window != null) {
                if (!booleanValue || (!this.LJI && !0bM.LIZ(getContext()))) {
                    window.addFlags(1024);
                } else {
                    window.clearFlags(1024);
                }
                if (z) {
                    window.setLayout(-1, -2);
                    WindowManager.LayoutParams attributes = window.getAttributes();
                    attributes.width = 0b0.LIZJ();
                    attributes.height = 0b0.LIZIZ() - 0b0.LIZLLL();
                    window.setAttributes(attributes);
                } else if (booleanValue) {
                    window.setLayout(-1, -1);
                } else {
                    window.setLayout(0b0.LIZLLL(2131166139), -1);
                }
            }
            if (this.LJIIZILJ != null) {
                new Handler(Looper.getMainLooper()).postDelayed(this.LJIIZILJ, 10);
            }
            this.LJIILIIL.LIZIZ(29d.class, true);
        }
    }

    public final void LIZ(List<GiftPage> list) {
        if (list != null) {
            LIZIZ(list);
        }
        LiveNewGiftPanelWidget liveNewGiftPanelWidget = this.LIZ;
        if (liveNewGiftPanelWidget != null) {
            liveNewGiftPanelWidget.LJIILIIL = false;
            liveNewGiftPanelWidget.LJIIJJI = false;
        }
    }

    public final void LIZIZ(List<GiftPage> list) {
        this.LJIJ.clear();
        boolean z = false;
        for (GiftPage next : list) {
            if (((Integer) this.LJIIIIZZ.LIZIZ.getValue()).intValue() == next.pageType) {
                z = true;
            }
            this.LJIJ.add(next);
        }
        if (!z) {
            this.LJIIIIZZ.LIZIZ.setValue(1);
        }
        LiveNewGiftPanelWidget liveNewGiftPanelWidget = this.LIZ;
        if (liveNewGiftPanelWidget != null) {
            liveNewGiftPanelWidget.LIZ(this.LJIJ);
        }
        LiveNewGiftBottomWidget liveNewGiftBottomWidget = this.LIZIZ;
        if (liveNewGiftBottomWidget != null) {
            liveNewGiftBottomWidget.LIZ(this.LJIJ);
        }
    }

    public void onCreate(Bundle bundle) {
        String str;
        super.onCreate(bundle);
        C5069HdW.LIZ.LIZ = true;
        C4495HMi.LJIIJJI.LJFF = this.LIZLLL;
        this.LJIIJJI = SystemClock.uptimeMillis();
        C2313GaA.LIZ();
        String str2 = "";
        if (this.LJIILIIL == null || this.LJIILIIL.LIZIZ(G08.class) == null) {
            str = str2;
        } else {
            str2 = ((Hashtag) this.LJIILIIL.LIZIZ(G08.class)).title;
            str = String.valueOf(((Hashtag) this.LJIILIIL.LIZIZ(G08.class)).id);
        }
        C4503HMq.LIZ(this.LIZLLL, 0b0.LJFF(), str2, str, (List<Long>) null);
        C5065HdS.LIZ.LIZ = true;
    }

    public final void LIZJ(List<Prop> list) {
        LiveNewGiftPanelWidget liveNewGiftPanelWidget = this.LIZ;
        liveNewGiftPanelWidget.LJFF.clear();
        liveNewGiftPanelWidget.LJFF.addAll(list);
        if (!(liveNewGiftPanelWidget.LJII == null || liveNewGiftPanelWidget.LJII.LIZIZ == null || liveNewGiftPanelWidget.LJII.LIZIZ.getValue() == null || liveNewGiftPanelWidget.LJII == null || ((Integer) liveNewGiftPanelWidget.LJII.LIZIZ.getValue()).intValue() != 5)) {
            liveNewGiftPanelWidget.LIZIZ(list);
        }
        if (!(list == null || list.isEmpty() || list.get(0).banner == null)) {
            this.LJIIJ = list.get(0).banner.LJFF;
        }
        LiveNewGiftBottomWidget liveNewGiftBottomWidget = this.LIZIZ;
        String str = this.LJIIJ;
        if (str == null || !(liveNewGiftBottomWidget.LIZIZ == null || liveNewGiftBottomWidget.LIZIZ.LIZIZ == null || liveNewGiftBottomWidget.LIZIZ.LIZIZ.getValue() == null || ((Integer) liveNewGiftBottomWidget.LIZIZ.LIZIZ.getValue()).intValue() == 5)) {
            liveNewGiftBottomWidget.LIZJ.setVisibility(8);
        } else {
            liveNewGiftBottomWidget.LIZJ.setVisibility(0);
        }
        liveNewGiftBottomWidget.LIZLLL = str;
    }

    public void onViewCreated(View view, Bundle bundle) {
        long j;
        super.onViewCreated(view, bundle);
        C4529HNq.LIZJ.LIZ();
        if (this.LJIILIIL != null) {
            this.LJFF = (Room) this.LJIILIIL.LIZIZ(C1064Fv7.class);
            this.LJI = ((Boolean) this.LJIILIIL.LIZIZ(C1059Fv2.class)).booleanValue();
        }
        View view2 = getView();
        if (view2 != null) {
            view2.findViewById(2131367977).setOnClickListener(new C4526HNn(this));
        }
        View view3 = getView();
        if (!(view3 == null || getContext() == null || this.LJIILIIL == null)) {
            WidgetManager of = WidgetManager.of((Fragment) this, view3, (FluencyOpt) 1Mn.LIZ);
            of.mWidgetCreateTimeListener = this.LJIJJ;
            boolean booleanValue = ((Boolean) this.LJIILIIL.LIZIZ(HFX.class)).booleanValue();
            LiveNewGiftPanelWidget liveNewGiftPanelWidget = new LiveNewGiftPanelWidget();
            this.LIZ = liveNewGiftPanelWidget;
            liveNewGiftPanelWidget.LJII = this.LJIIIIZZ;
            this.LIZ.LIZLLL = this.LJII;
            this.LIZ.LJIIIIZZ = booleanValue;
            this.LIZ.LJIIJ = this.LIZLLL;
            this.LIZ.LJIIZILJ = this.LJIIJJI;
            long j2 = 0;
            if (this.LJIIIIZZ.LJI.getValue() != null) {
                j = ((Long) this.LJIIIIZZ.LJI.getValue()).longValue();
            } else {
                j = 0;
            }
            long LIZ2 = C4522HNj.LIZ(getContext(), "default_dialog_item");
            if (j == 0) {
                j = LIZ2;
            }
            this.LIZ.LJIIIZ = j;
            ((ViewGroup) getView().findViewById(2131364066)).setClipChildren(!booleanValue);
            of.load(2131367978, this.LIZ, false);
            LiveNewGiftPageIndicatorWidget liveNewGiftPageIndicatorWidget = new LiveNewGiftPageIndicatorWidget();
            liveNewGiftPageIndicatorWidget.LIZIZ = this.LJIIIIZZ;
            of.load(2131368325, liveNewGiftPageIndicatorWidget);
            LiveNewGiftBottomWidget liveNewGiftBottomWidget = new LiveNewGiftBottomWidget();
            this.LIZIZ = liveNewGiftBottomWidget;
            liveNewGiftBottomWidget.LIZIZ = this.LJIIIIZZ;
            this.LIZIZ.LJ = this.LIZLLL;
            of.load(2131367975, this.LIZIZ, false);
            LIZIZ(GiftManager.inst().getGiftPageList());
            if (booleanValue && this.LJII == HLZ.GUEST) {
                LiveNewGiftGuestInfoWidget liveNewGiftGuestInfoWidget = new LiveNewGiftGuestInfoWidget();
                liveNewGiftGuestInfoWidget.LIZ = this.LJIIIIZZ;
                of.load(2131365314, liveNewGiftGuestInfoWidget);
                getView().findViewById(2131365314).setVisibility(0);
            }
            AnonymousClass1 r8 = new C4593HQc() {
                static {
                    Covode.recordClassIndex(19827);
                }

                public final void LIZ(List<Gift> list) {
                }

                public final void LIZ(List<GiftPage> list, int i) {
                    LiveNewGiftDialog.this.LIZIZ(list);
                }
            };
            GiftManager inst = GiftManager.inst();
            Room room = this.LJFF;
            if (room != null) {
                j2 = room.getId();
            }
            inst.syncGiftList(r8, j2, 3, this.LJI, "");
            HN0 LIZ3 = HN0.LIZ();
            if (!LIZ3.LIZIZ.contains(this)) {
                LIZ3.LIZIZ.add(this);
            }
            if (this.LJFF != null) {
                HN0.LIZ().LIZ(this.LJFF.getId());
            }
        }
        this.LJIIIIZZ.LIZJ.observe(this, new C4517HNe(this));
        this.LJIIIIZZ.LIZLLL.observe(this, new GAY(this));
        this.LJIIIIZZ.LJ.observe(this, new C4527HNo(this));
        if (this.LJIILIIL != null) {
            this.LJIILIIL.LIZJ(29b.class, true);
            this.LJIILIIL.LIZ((Object) this, 29b.class, new C4523HNk(this));
        }
        if (LiveEnableRechargeSucceedAnimationSetting.INSTANCE.enable()) {
            this.LJIJI.LIZ(C2675Gg0.LIZ().LIZ(C4536HNx.class).LIZLLL(new C4534HNv(this)));
        }
        this.LIZJ.LIZ = getContext();
    }

    public static LiveNewGiftDialog LIZ(Room room, User user, C3543Gu0 gu0, String str, Runnable runnable, long j) {
        LiveNewGiftDialog liveNewGiftDialog = new LiveNewGiftDialog();
        if (user == null || user.getId() == room.getOwnerUserId()) {
            liveNewGiftDialog.LJII = HLZ.ANCHOR;
        } else {
            liveNewGiftDialog.LJII = HLZ.GUEST;
        }
        liveNewGiftDialog.LJFF = room;
        if (C4215HBo.LIZ && "icon".equals(str)) {
            str = "gift_guide_bubble";
        }
        liveNewGiftDialog.LIZLLL = str;
        liveNewGiftDialog.LIZJ = new C1627GAa();
        C4515HNc hNc = new C4515HNc();
        liveNewGiftDialog.LJIIIZ = hNc;
        M12.LIZ(liveNewGiftDialog);
        hNc.LIZ = liveNewGiftDialog;
        liveNewGiftDialog.LJIIIZ.LIZLLL = str;
        liveNewGiftDialog.LIZJ.LIZIZ = user;
        liveNewGiftDialog.LJIIIIZZ = new C4519HNg();
        if (C3543Gu0.DEFAULT != gu0) {
            liveNewGiftDialog.LJIIIIZZ.LIZIZ.setValue(Integer.valueOf(gu0.value));
        } else {
            liveNewGiftDialog.LJIIIIZZ.LIZIZ.setValue(Integer.valueOf(GiftManager.inst().checkTabCanDisplay(C4522HNj.LIZ(0b0.LJ(), "sp_gift_page_type", 1))));
        }
        if ("gift_panel".equals(str) && GiftManager.inst().getTabByGiftId(j) != -1) {
            liveNewGiftDialog.LJIIIIZZ.LIZIZ.setValue(Integer.valueOf(GiftManager.inst().getTabByGiftId(j)));
        }
        liveNewGiftDialog.LJIIIIZZ.LJI.setValue(Long.valueOf(j));
        liveNewGiftDialog.LJIIIIZZ.LIZ = user;
        liveNewGiftDialog.LJIIZILJ = runnable;
        return liveNewGiftDialog;
    }
}
