package com.bytedance.android.livesdk.liveroom;

import X.0bM;
import X.0c0;
import X.0cm;
import X.1Ol;
import X.1hK;
import X.C3264GpV;
import X.C3332Gqb;
import X.C3491GtA;
import X.C3714Gwl;
import X.C3827Gya;
import X.C4100H7d;
import X.GAX;
import android.text.TextUtils;
import android.view.Window;
import com.bytedance.android.live.livepullstream.api.IPullStreamService;
import com.bytedance.android.livesdk.LiveRoomFragment;
import com.bytedance.android.livesdk.livesetting.watchlive.InboxSameFlowSetting;
import com.bytedance.android.livesdkapi.host.IHostContext;
import com.bytedance.android.livesdkapi.host.IHostInboxPageSkyLightService;
import com.bytedance.android.livesdkapi.session.EnterRoomConfig;
import com.bytedance.android.livesdkapi.session.Event;
import com.bytedance.covode.number.Covode;
import java.util.HashMap;

public class RoomListener implements ISubController {
    public LiveRoomFragment fragment;
    public C3827Gya mRoomAction;
    public C3714Gwl mRoomEventListener;

    static {
        Covode.recordClassIndex(17598);
    }

    public void onCreate() {
    }

    public void onDestroy() {
    }

    public void onPause() {
    }

    public void onResume() {
    }

    public C3827Gya getRoomAction() {
        return this.mRoomAction;
    }

    public C3714Gwl getRoomEventListener() {
        return this.mRoomEventListener;
    }

    public void init() {
        initRoomEnvironment();
    }

    private String getLiveEnterMerge() {
        return GAX.LIZ.LIZ().LIZIZ.LIZLLL.LJJJJI;
    }

    private String getLiveEnterMethod() {
        return GAX.LIZ.LIZ().LIZIZ.LIZLLL.LJJJJJ;
    }

    public boolean initRoomEnvironment() {
        if (this.mRoomAction == null) {
            this.mRoomAction = new C3827Gya() {
                static {
                    Covode.recordClassIndex(17599);
                }

                public final void LIZ(String str) {
                    1hK activity;
                    C3264GpV.LJIIJJI.LIZ().LIZ();
                    0cm.LIZ(IPullStreamService.class).clearAsyncWarmUpPlayerManager();
                    1Ol.LLFII.LIZ("LivePlayActivity_Destory");
                    RoomListener.this.trySendExitPosition(str);
                    if (!(RoomListener.this.fragment == null || (activity = RoomListener.this.fragment.getActivity()) == null)) {
                        activity.finish();
                    }
                    C3491GtA LIZ2 = C3491GtA.LJFF.LIZ("livesdk_live_leave");
                    if (TextUtils.isEmpty(str)) {
                        str = "draw";
                    }
                    LIZ2.LIZ("leave_type", str);
                    LIZ2.LIZ();
                    LIZ2.LIZLLL();
                }
            };
        }
        if (this.mRoomEventListener == null) {
            this.mRoomEventListener = new C3714Gwl() {
                static {
                    Covode.recordClassIndex(17600);
                }

                public final void LIZ() {
                    0cm.LIZ(IHostContext.class).trafficDeteriorationAB(6);
                }

                public final void LIZ(boolean z) {
                    1hK activity;
                    Window window;
                    if (RoomListener.this.fragment != null && (activity = RoomListener.this.fragment.getActivity()) != null && (window = activity.getWindow()) != null) {
                        if (!z) {
                            activity.getWindow().setFlags(1024, 1024);
                        } else if (0bM.LIZ(activity)) {
                            window.clearFlags(1024);
                        }
                    }
                }
            };
        }
        if (this.mRoomAction == null || !C4100H7d.LIZ().LIZIZ().LIZLLL()) {
            return true;
        }
        HashMap hashMap = new HashMap();
        hashMap.put("enter_from_merge", getLiveEnterMerge());
        hashMap.put("enter_method", getLiveEnterMethod());
        hashMap.put("source", "live room fg");
        0c0.LIZ("ttlive_minor_mode_live", 1, hashMap);
        Event event = new Event("room_fg_enter_room_fail", 33028, C3332Gqb.BussinessApiCall);
        event.LIZ("ftc or delete by age gate.");
        GAX.LIZ.LIZ().LIZ(event);
        this.mRoomAction.LIZ("error");
        return false;
    }

    public RoomListener(LiveRoomFragment liveRoomFragment) {
        this.fragment = liveRoomFragment;
    }

    public void trySendExitPosition(String str) {
        LiveRoomFragment liveRoomFragment;
        if (InboxSameFlowSetting.INSTANCE.getEnable() && !"error".equals(str)) {
            try {
                if ("message".equals(getLiveEnterMerge()) && "live_cover".equals(getLiveEnterMethod()) && (liveRoomFragment = this.fragment) != null && liveRoomFragment.LJIILL != null) {
                    EnterRoomConfig LIZ = liveRoomFragment.LJIIZILJ.LIZ(liveRoomFragment.LJIILL.getCurrentItem());
                    long j = -1;
                    if (LIZ != null) {
                        j = LIZ.LIZLLL.LJJJJZI;
                    }
                    0cm.LIZ(IHostInboxPageSkyLightService.class).LIZ(j);
                }
            } catch (Throwable unused) {
            }
        }
    }
}
