import { Ionicons } from "@expo/vector-icons"; import { useRouter } from "expo-router"; import { TFunction } from "i18next"; import type React from "react"; import { useEffect, useMemo } from "react"; import { useTranslation } from "react-i18next"; import { Linking, Platform, Switch, TouchableOpacity } from "react-native"; import { toast } from "sonner-native"; import { BITRATES } from "@/components/BitrateSelector"; import Dropdown from "@/components/common/Dropdown"; import DisabledSetting from "@/components/settings/DisabledSetting"; import * as ScreenOrientation from "@/packages/expo-screen-orientation"; import { ScreenOrientationEnum, useSettings } from "@/utils/atoms/settings"; import { BACKGROUND_FETCH_TASK, registerBackgroundFetchAsync, unregisterBackgroundFetchAsync, } from "@/utils/background-tasks"; import { Text } from "../common/Text"; import { ListGroup } from "../list/ListGroup"; import { ListItem } from "../list/ListItem"; const BackgroundFetch = !Platform.isTV ? require("expo-background-fetch") : null; const TaskManager = !Platform.isTV ? require("expo-task-manager") : null; export const OtherSettings: React.FC = () => { const router = useRouter(); const [settings, updateSettings, pluginSettings] = useSettings(); const { t } = useTranslation(); /******************** * Background task *******************/ const checkStatusAsync = async () => { if (Platform.isTV) return; await BackgroundFetch.getStatusAsync(); return await TaskManager.isTaskRegisteredAsync(BACKGROUND_FETCH_TASK); }; useEffect(() => { (async () => { const registered = await checkStatusAsync(); if (settings?.autoDownload === true && !registered) { registerBackgroundFetchAsync(); toast.success("Background downloads enabled"); } else if (settings?.autoDownload === false && registered) { unregisterBackgroundFetchAsync(); toast.info("Background downloads disabled"); } else if (settings?.autoDownload === true && registered) { // Don't to anything } else if (settings?.autoDownload === false && !registered) { // Don't to anything } else { updateSettings({ autoDownload: false }); } })(); }, [settings?.autoDownload]); /********************** *********************/ const disabled = useMemo( () => pluginSettings?.followDeviceOrientation?.locked === true && pluginSettings?.defaultVideoOrientation?.locked === true && pluginSettings?.safeAreaInControlsEnabled?.locked === true && pluginSettings?.showCustomMenuLinks?.locked === true && pluginSettings?.hiddenLibraries?.locked === true && pluginSettings?.disableHapticFeedback?.locked === true, [pluginSettings], ); const orientations = [ ScreenOrientation.OrientationLock.DEFAULT, ScreenOrientation.OrientationLock.PORTRAIT_UP, ScreenOrientation.OrientationLock.LANDSCAPE_LEFT, ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT, ]; const orientationTranslations = useMemo( () => ({ [ScreenOrientation.OrientationLock.DEFAULT]: "home.settings.other.orientations.DEFAULT", [ScreenOrientation.OrientationLock.PORTRAIT_UP]: "home.settings.other.orientations.PORTRAIT_UP", [ScreenOrientation.OrientationLock.LANDSCAPE_LEFT]: "home.settings.other.orientations.LANDSCAPE_LEFT", [ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT]: "home.settings.other.orientations.LANDSCAPE_RIGHT", }), [], ); if (!settings) return null; return ( updateSettings({ followDeviceOrientation: value }) } /> t(ScreenOrientationEnum[item])} title={ {t( orientationTranslations[ settings.defaultVideoOrientation as keyof typeof orientationTranslations ], ) || "Unknown Orientation"} } label={t("home.settings.other.orientation")} onSelected={(defaultVideoOrientation) => updateSettings({ defaultVideoOrientation }) } /> updateSettings({ safeAreaInControlsEnabled: value }) } /> {/* {(Platform.OS === "ios" || Platform.isTVOS)&& ( t(`home.settings.other.video_players.${VideoPlayer[item]}`)} title={ {t(`home.settings.other.video_players.${VideoPlayer[settings.defaultPlayer]}`)} } label={t("home.settings.other.orientation")} onSelected={(defaultPlayer) => updateSettings({ defaultPlayer }) } /> )} */} Linking.openURL( "https://jellyfin.org/docs/general/clients/web-config/#custom-menu-links", ) } > updateSettings({ showCustomMenuLinks: value }) } /> router.push("/settings/hide-libraries/page")} title={t("home.settings.other.hide_libraries")} showArrow /> item.key} titleExtractor={(item) => item.key} title={ {settings.defaultBitrate?.key} } label={t("home.settings.other.default_quality")} onSelected={(defaultBitrate) => updateSettings({ defaultBitrate })} /> updateSettings({ disableHapticFeedback }) } /> item.key} titleExtractor={(item) => item.key} title={ {t(settings?.maxAutoPlayEpisodeCount.key)} } label={t("home.settings.other.max_auto_play_episode_count")} onSelected={(maxAutoPlayEpisodeCount) => updateSettings({ maxAutoPlayEpisodeCount }) } /> ); }; const AUTOPLAY_EPISODES_COUNT = ( t: TFunction<"translation", undefined>, ): { key: string; value: number; }[] => [ { key: t("home.settings.other.disabled"), value: -1 }, { key: "1", value: 1 }, { key: "2", value: 2 }, { key: "3", value: 3 }, { key: "4", value: 4 }, { key: "5", value: 5 }, { key: "6", value: 6 }, { key: "7", value: 7 }, ];