import { Ionicons } from "@expo/vector-icons"; import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models"; import { Image } from "expo-image"; import { useAtomValue } from "jotai"; import type React from "react"; import { useMemo } from "react"; import { View } from "react-native"; import { GlassPosterView, isGlassEffectAvailable, } from "@/modules/glass-poster"; import { apiAtom } from "@/providers/JellyfinProvider"; import { ProgressBar } from "./common/ProgressBar"; import { WatchedIndicator } from "./WatchedIndicator"; export const TV_LANDSCAPE_WIDTH = 400; type ContinueWatchingPosterProps = { item: BaseItemDto; useEpisodePoster?: boolean; size?: "small" | "normal"; showPlayButton?: boolean; }; const ContinueWatchingPoster: React.FC = ({ item, useEpisodePoster = false, // TV version uses fixed width, size prop kept for API compatibility size: _size = "normal", showPlayButton = false, }) => { const api = useAtomValue(apiAtom); const url = useMemo(() => { if (!api) { return; } if (item.Type === "Episode" && useEpisodePoster) { return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=700&quality=80`; } if (item.Type === "Episode") { if (item.ParentBackdropItemId && item.ParentThumbImageTag) { return `${api?.basePath}/Items/${item.ParentBackdropItemId}/Images/Thumb?fillHeight=700&quality=80&tag=${item.ParentThumbImageTag}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=700&quality=80`; } if (item.Type === "Movie") { if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=700&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=700&quality=80`; } if (item.Type === "Program") { if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=700&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=700&quality=80`; } if (item.ImageTags?.Thumb) { return `${api?.basePath}/Items/${item.Id}/Images/Thumb?fillHeight=700&quality=80&tag=${item.ImageTags?.Thumb}`; } return `${api?.basePath}/Items/${item.Id}/Images/Primary?fillHeight=700&quality=80`; }, [api, item, useEpisodePoster]); const progress = useMemo(() => { if (item.Type === "Program") { if (!item.StartDate || !item.EndDate) { return 0; } const startDate = new Date(item.StartDate); const endDate = new Date(item.EndDate); const now = new Date(); const total = endDate.getTime() - startDate.getTime(); if (total <= 0) { return 0; } const elapsed = now.getTime() - startDate.getTime(); return (elapsed / total) * 100; } return item.UserData?.PlayedPercentage || 0; }, [item]); const isWatched = item.UserData?.Played === true; // Use glass effect on tvOS 26+ const useGlass = isGlassEffectAvailable(); if (!url) { return ( ); } if (useGlass) { return ( {showPlayButton && ( )} ); } // Fallback for older tvOS versions return ( {showPlayButton && ( )} ); }; export default ContinueWatchingPoster;