package com.bytedance.android.livesdk.watch;

import X.0AA;
import X.0Rl;
import X.0S6;
import X.0cm;
import X.1Mn;
import X.1hK;
import X.8eL;
import X.C1678GBz;
import X.C1856GIv;
import X.C1977GNm;
import X.C2074GRf;
import X.C2291GZo;
import X.C2295GZs;
import X.C2316GaD;
import X.C2319GaG;
import X.C2320GaH;
import X.C2321GaI;
import X.C2322GaJ;
import X.C2323GaK;
import X.C2325GaM;
import X.C2326GaN;
import X.C2330GaR;
import X.C2333GaU;
import X.C2675Gg0;
import X.C3245GpC;
import X.C3264GpV;
import X.C3273Gpe;
import X.C3357Gr0;
import X.C3372GrF;
import X.C3401Gri;
import X.C3436GsH;
import X.C3491GtA;
import X.C3495GtE;
import X.C3712Gwj;
import X.C4303HEy;
import X.JRW;
import X.Lea;
import X.M12;
import X.T6t;
import X.T6u;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.text.TextUtils;
import com.bytedance.android.live.toolbar.IToolbarService;
import com.bytedance.android.livesdk.LiveRoomFragment;
import com.bytedance.android.livesdk.callback.IHostLongPressCallback;
import com.bytedance.android.livesdk.chatroom.ui.LivePlayFragment;
import com.bytedance.android.livesdk.dislike.LiveLongPressDialog;
import com.bytedance.android.livesdk.drawerfeed.LiveDrawerDialogV2;
import com.bytedance.android.livesdk.livesetting.performance.degrade.EnterRoomCommonOptSetting;
import com.bytedance.android.livesdk.livesetting.watchlive.firstscreen.DisableLiveOptimizeStrategy;
import com.bytedance.android.livesdk.pip.PipSwitchDialog;
import com.bytedance.android.livesdk.pip.ShareSettingsDialog;
import com.bytedance.android.livesdkapi.depend.model.live.Room;
import com.bytedance.android.livesdkapi.session.EnterRoomConfig;
import com.bytedance.covode.number.Covode;
import com.bytedance.ies.sdk.datachannel.DataChannel;
import com.ss.videoarch.strategy.LiveStrategyManager;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import kotlin.h.b.n;
import org.json.JSONObject;

public class WatchLiveService implements IWatchLiveService {
    public int liveRoomChangeCount;

    static {
        Covode.recordClassIndex(21603);
    }

    public void onInit() {
    }

    public int getLiveRoomChangeCount() {
        return this.liveRoomChangeCount;
    }

    public C3712Gwj getPreFetchManager() {
        return C3264GpV.LJIIJJI.LIZ();
    }

    public void preloadLivePlay() {
        C2316GaD.LIZIZ.LIZIZ();
    }

    public void preloadLiveRoomFragmentLayout() {
        if (!C2316GaD.LIZ) {
            0Rl.LJ.LIZ(2131561766, 1, 1);
            C2316GaD.LIZ = true;
        }
    }

    public List<C2333GaU> getLiveRoomStatusListener() {
        ArrayList arrayList = new ArrayList();
        for (C2323GaK LIZ : C2322GaJ.LIZ) {
            arrayList.add(LIZ.LIZ());
        }
        return arrayList;
    }

    public void setLiveRoomChangeCount(int i) {
        this.liveRoomChangeCount = i;
    }

    public void addLiveDuration(long j) {
        LivePlayFragment.LJJLJ.add(Long.valueOf(j));
    }

    public T6t createFollowGuideEvasionStrategy(DataChannel dataChannel) {
        M12.LIZ(dataChannel);
        return new T6t(dataChannel);
    }

    public T6u createShareGuideEvasionStrategy(DataChannel dataChannel) {
        M12.LIZ(dataChannel);
        return new T6u(dataChannel);
    }

    public void addLiveDurationTask(C3372GrF grF) {
        C3273Gpe LIZ = C3273Gpe.LIZ();
        if (grF != null) {
            LIZ.LIZ.add(grF);
            if (LIZ.LIZIZ) {
                LIZ.LIZ(grF);
            }
        }
    }

    public void registerRoomStatusProvider(C2323GaK gaK) {
        M12.LIZ(gaK);
        M12.LIZ(gaK);
        if (!C2322GaJ.LIZ.contains(gaK)) {
            C2322GaJ.LIZ.add(gaK);
        }
    }

    public void preloadWatchResource(Context context) {
        M12.LIZ(context);
        C2316GaD.LIZIZ.LIZ();
        0cm.LIZ(IToolbarService.class).preloadAudienceToolbarWidget();
        0S6.LJFF.LIZ(2131562197);
        0S6.LJFF.LIZ(2131559556);
    }

    public C3357Gr0 createLiveRoomFragment(EnterRoomConfig enterRoomConfig) {
        String concat;
        M12.LIZ(enterRoomConfig);
        LiveRoomFragment.LIZ = new C3436GsH();
        C2321GaI gaI = C2320GaH.LIZ().LIZ;
        if ((gaI == null || TextUtils.isEmpty(gaI.LIZ) || (!gaI.LIZ.equals(C3495GtE.FEED.typeName) && !gaI.LIZ.equals(C3495GtE.FEED_WITH_PREVIEW.typeName))) && enterRoomConfig != null) {
            String str = enterRoomConfig.LIZLLL.LJJJJI;
            String str2 = enterRoomConfig.LIZLLL.LJJJJJ;
            String str3 = enterRoomConfig.LIZLLL.LJJJJI;
            if (!TextUtils.isEmpty(str) || !TextUtils.isEmpty(str2) || !TextUtils.isEmpty(str3)) {
                if (!TextUtils.isEmpty(str)) {
                    concat = "from_merge_".concat(String.valueOf(str));
                } else if (!TextUtils.isEmpty(str3)) {
                    concat = "extra_from_merge_".concat(String.valueOf(str3));
                } else {
                    concat = "method_".concat(String.valueOf(str2));
                }
                C2320GaH.LIZ().LIZ = new C2321GaI(concat);
            }
        }
        1Mn.LIZ(C1977GNm.LIZ);
        LiveRoomFragment liveRoomFragment = new LiveRoomFragment();
        n.LIZIZ(liveRoomFragment, "");
        return liveRoomFragment;
    }

    public List<?> audienceToolbarList(DataChannel dataChannel, Context context) {
        M12.LIZ(dataChannel, context);
        return C2074GRf.LIZ.LIZ(dataChannel);
    }

    public C3401Gri createDrawerFeedFragment(C4303HEy hEy, Bundle bundle) {
        LiveDrawerDialogV2 liveDrawerDialogV2 = new LiveDrawerDialogV2();
        liveDrawerDialogV2.LJII = null;
        liveDrawerDialogV2.LIZLLL = bundle;
        liveDrawerDialogV2.LJFF = hEy;
        return liveDrawerDialogV2;
    }

    public void showMaskLayer(long j, boolean z) {
        C2675Gg0.LIZ().LIZ((Object) new C2326GaN(j, z));
    }

    public void optimizePullStream(int i, Map<String, String> map) {
        M12.LIZ(map);
        if (EnterRoomCommonOptSetting.INSTANCE.getEnable()) {
            8eL.LIZJ().submit(new C2319GaG(this, i, map));
        } else {
            optInnerPullStream(i, map);
        }
    }

    public boolean shouldDislikeActionShow(String str, String str2) {
        if (n.LIZ(str2, C3245GpC.HOURLY_RANK.getRankName()) || !Lea.LIZ((ArrayList) C2291GZo.LIZ.getValue(), str)) {
            return false;
        }
        return true;
    }

    public void openPipSwitchDialog(Activity activity, String str) {
        M12.LIZ(str);
        if (activity instanceof 1hK) {
            M12.LIZ(str);
            PipSwitchDialog pipSwitchDialog = new PipSwitchDialog();
            Bundle bundle = new Bundle();
            bundle.putString("enter_from", str);
            pipSwitchDialog.setArguments(bundle);
            0AA supportFragmentManager = ((1hK) activity).getSupportFragmentManager();
            n.LIZIZ(supportFragmentManager, "");
            pipSwitchDialog.show(supportFragmentManager, PipSwitchDialog.LIZ);
        }
    }

    public void openShareSettingsDialog(Activity activity, String str) {
        M12.LIZ(str);
        if (activity instanceof 1hK) {
            M12.LIZ(str);
            ShareSettingsDialog shareSettingsDialog = new ShareSettingsDialog();
            Bundle bundle = new Bundle();
            bundle.putString("enter_from", str);
            shareSettingsDialog.setArguments(bundle);
            0AA supportFragmentManager = ((1hK) activity).getSupportFragmentManager();
            n.LIZIZ(supportFragmentManager, "");
            shareSettingsDialog.show(supportFragmentManager, ShareSettingsDialog.LIZIZ);
        }
    }

    public final void optInnerPullStream(int i, Map<String, String> map) {
        if (i == 1) {
            String str = map.get("enter_from_merge");
            String str2 = "";
            if (str == null) {
                str = str2;
            }
            String str3 = map.get("enter_method");
            if (str3 != null) {
                str2 = str3;
            }
            String str4 = map.get("action_type");
            if (str4 == null) {
                str4 = "click";
            }
            if (!n.LIZ(DisableLiveOptimizeStrategy.INSTANCE.getValue().get(str + '-' + str2 + '-' + str4), true)) {
                JSONObject jSONObject = new JSONObject();
                try {
                    for (Map.Entry next : map.entrySet()) {
                        jSONObject.put((String) next.getKey(), next.getValue());
                    }
                } catch (Exception unused) {
                }
                LiveStrategyManager.inst().setRoomInfo(jSONObject.toString(), 50, 0);
            }
        }
    }

    public List<JRW> audienceVideoFullScreenAction(DataChannel dataChannel, C1856GIv gIv, Room room) {
        M12.LIZ(dataChannel, gIv);
        M12.LIZ(dataChannel, gIv);
        ArrayList arrayList = new ArrayList();
        if (C1678GBz.LIZ.LIZ()) {
            C3491GtA LIZ = C3491GtA.LJFF.LIZ("livesdk_live_user_adaptive_screen_show");
            LIZ.LIZ(dataChannel);
            LIZ.LIZLLL();
            arrayList.add(new C2325GaM(dataChannel));
        }
        return arrayList;
    }

    public void logReportLiveFromSharePanel(Room room, String str, String str2, String str3) {
        if (room != null) {
            C2330GaR gaR = C2330GaR.LIZ;
            if (str == null) {
                str = "";
            }
            if (str2 == null) {
                str2 = "";
            }
            gaR.LIZ(room, str, str2, str3);
        }
    }

    public void dislikeLiveFromSharePanel(Room room, String str, String str2, String str3) {
        String str4 = str;
        C2291GZo gZo = C2291GZo.LIZIZ;
        String str5 = "";
        if (str4 == null) {
            str4 = str5;
        }
        if (str2 != null) {
            str5 = str2;
        }
        gZo.LIZ(room, str4, str5, C2295GZs.SHARING_PANEL, str3);
    }

    public void logDislikeLiveFromLongPressSharePanel(Room room, String str, String str2, String str3) {
        String str4 = str;
        C2291GZo gZo = C2291GZo.LIZIZ;
        String str5 = "";
        if (str4 == null) {
            str4 = str5;
        }
        if (str2 != null) {
            str5 = str2;
        }
        gZo.LIZIZ(room, str4, str5, C2295GZs.LONG_PRESS, str3);
    }

    public void logDislikeLiveFromSharePanel(Room room, String str, String str2, String str3) {
        String str4 = str;
        C2291GZo gZo = C2291GZo.LIZIZ;
        String str5 = "";
        if (str4 == null) {
            str4 = str5;
        }
        if (str2 != null) {
            str5 = str2;
        }
        gZo.LIZIZ(room, str4, str5, C2295GZs.SHARING_PANEL, str3);
    }

    public DialogInterface openLongPressDialog(IHostLongPressCallback iHostLongPressCallback, Context context, Room room, String str, String str2, String str3, String str4) {
        if (context == null || room == null || !(context instanceof 1hK)) {
            return null;
        }
        LiveLongPressDialog liveLongPressDialog = new LiveLongPressDialog();
        liveLongPressDialog.LIZ = !shouldDislikeActionShow(str, str2);
        liveLongPressDialog.LIZLLL = str;
        liveLongPressDialog.LJ = str2;
        liveLongPressDialog.LJI = str4;
        M12.LIZ(room);
        liveLongPressDialog.LIZJ = room;
        liveLongPressDialog.LJFF = str3;
        liveLongPressDialog.LIZIZ = iHostLongPressCallback;
        0AA supportFragmentManager = ((1hK) context).getSupportFragmentManager();
        n.LIZIZ(supportFragmentManager, "");
        liveLongPressDialog.show(supportFragmentManager, "LiveLongPressDialog");
        return liveLongPressDialog;
    }
}
