import React from "react"; import { Alert, Platform } from "react-native"; import { useFocusEffect, useRouter } from "expo-router"; import { MaterialCommunityIcons } from "@expo/vector-icons"; import { isDevelopmentProvisioningProfile } from "modules/check-ios-certificate"; import { ScrollView, useTheme, YStack } from "tamagui"; import type { ScrapeMedia } from "@movie-web/provider-utils"; import { DownloadItem, ShowDownloadItem } from "~/components/DownloadItem"; import ScreenLayout from "~/components/layout/ScreenLayout"; import { MWButton } from "~/components/ui/Button"; import { useDownloadManager } from "~/hooks/useDownloadManager"; import { PlayerStatus } from "~/stores/player/slices/interface"; import { usePlayerStore } from "~/stores/player/store"; import { useDownloadHistoryStore } from "~/stores/settings"; const exampleMovieMedia: ScrapeMedia = { type: "movie", title: "Avengers: Endgame", releaseYear: 2019, imdbId: "tt4154796", tmdbId: "299534", }; const getExampleShowMedia = (seasonNumber: number, episodeNumber: number) => ({ type: "show", title: "Loki", releaseYear: 2021, imdbId: "tt9140554", tmdbId: "84958", season: { number: seasonNumber, tmdbId: seasonNumber.toString(), }, episode: { number: episodeNumber, tmdbId: episodeNumber.toString(), }, }) as const; const TestDownloadButton = (props: { media: ScrapeMedia; type: "hls" | "mp4"; url: string; }) => { const { startDownload } = useDownloadManager(); const theme = useTheme(); return ( } onPress={async () => { await startDownload(props.url, props.type, props.media).catch( console.error, ); }} > test download {props.type === "hls" ? " (hls)" : "(mp4)"}{" "} {props.media.type === "show" ? "show" : "movie"} ); }; const DownloadsScreen: React.FC = () => { const downloads = useDownloadHistoryStore((state) => state.downloads); const resetVideo = usePlayerStore((state) => state.resetVideo); const setVideoSrc = usePlayerStore((state) => state.setVideoSrc); const setIsLocalFile = usePlayerStore((state) => state.setIsLocalFile); const setPlayerStatus = usePlayerStore((state) => state.setPlayerStatus); const router = useRouter(); useFocusEffect( React.useCallback(() => { if (Platform.OS === "ios" && !isDevelopmentProvisioningProfile()) { Alert.alert( "Production Certificate", "Download functionality is not available when the application is signed with a distribution certificate.", [ { text: "OK", onPress: () => router.back(), }, ], ); } }, [router]), ); const handlePress = (localPath?: string) => { if (!localPath) return; resetVideo(); setIsLocalFile(true); setPlayerStatus(PlayerStatus.READY); setVideoSrc({ uri: localPath, }); router.push({ pathname: "/videoPlayer", }); }; return ( {downloads.map((download) => { if (download.downloads.length === 0) return null; if (download.media.type === "movie") { return ( handlePress(download.downloads[0]!.localPath)} /> ); } else { return ( ); } })} ); }; export default DownloadsScreen;