mirror of
https://github.com/streamyfin/streamyfin.git
synced 2026-01-15 15:48:05 +00:00
feat: KSPlayer as an option for iOS + other improvements (#1266)
This commit is contained in:
committed by
GitHub
parent
d1795c9df8
commit
74d86b5d12
212
app/(auth)/(tabs)/(favorites)/see-all.tsx
Normal file
212
app/(auth)/(tabs)/(favorites)/see-all.tsx
Normal file
@@ -0,0 +1,212 @@
|
||||
import type { Api } from "@jellyfin/sdk";
|
||||
import type {
|
||||
BaseItemDto,
|
||||
BaseItemKind,
|
||||
} from "@jellyfin/sdk/lib/generated-client";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { Stack, useLocalSearchParams } from "expo-router";
|
||||
import { t } from "i18next";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useWindowDimensions, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { TouchableItemRouter } from "@/components/common/TouchableItemRouter";
|
||||
import { ItemCardText } from "@/components/ItemCardText";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { ItemPoster } from "@/components/posters/ItemPoster";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
|
||||
type FavoriteTypes =
|
||||
| "Series"
|
||||
| "Movie"
|
||||
| "Episode"
|
||||
| "Video"
|
||||
| "BoxSet"
|
||||
| "Playlist";
|
||||
|
||||
const favoriteTypes: readonly FavoriteTypes[] = [
|
||||
"Series",
|
||||
"Movie",
|
||||
"Episode",
|
||||
"Video",
|
||||
"BoxSet",
|
||||
"Playlist",
|
||||
] as const;
|
||||
|
||||
function isFavoriteType(value: unknown): value is FavoriteTypes {
|
||||
return (
|
||||
typeof value === "string" &&
|
||||
(favoriteTypes as readonly string[]).includes(value)
|
||||
);
|
||||
}
|
||||
|
||||
export default function FavoritesSeeAllScreen() {
|
||||
const insets = useSafeAreaInsets();
|
||||
const { width: screenWidth } = useWindowDimensions();
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
|
||||
const searchParams = useLocalSearchParams<{
|
||||
type?: string;
|
||||
title?: string;
|
||||
}>();
|
||||
const typeParam = searchParams.type;
|
||||
const titleParam = searchParams.title;
|
||||
|
||||
const itemType = useMemo(() => {
|
||||
if (!isFavoriteType(typeParam)) return null;
|
||||
return typeParam as BaseItemKind;
|
||||
}, [typeParam]);
|
||||
|
||||
const headerTitle = useMemo(() => {
|
||||
if (typeof titleParam === "string" && titleParam.trim().length > 0)
|
||||
return titleParam;
|
||||
return "";
|
||||
}, [titleParam]);
|
||||
|
||||
const pageSize = 50;
|
||||
|
||||
const fetchItems = useCallback(
|
||||
async ({ pageParam }: { pageParam: number }): Promise<BaseItemDto[]> => {
|
||||
if (!api || !user?.Id || !itemType) return [];
|
||||
|
||||
const response = await getItemsApi(api as Api).getItems({
|
||||
userId: user.Id,
|
||||
sortBy: ["SeriesSortName", "SortName"],
|
||||
sortOrder: ["Ascending"],
|
||||
filters: ["IsFavorite"],
|
||||
recursive: true,
|
||||
fields: ["PrimaryImageAspectRatio"],
|
||||
collapseBoxSetItems: false,
|
||||
excludeLocationTypes: ["Virtual"],
|
||||
enableTotalRecordCount: true,
|
||||
startIndex: pageParam,
|
||||
limit: pageSize,
|
||||
includeItemTypes: [itemType],
|
||||
});
|
||||
|
||||
return response.data.Items || [];
|
||||
},
|
||||
[api, itemType, user?.Id],
|
||||
);
|
||||
|
||||
const { data, isFetching, fetchNextPage, hasNextPage, isLoading } =
|
||||
useInfiniteQuery({
|
||||
queryKey: ["favorites", "see-all", itemType],
|
||||
queryFn: ({ pageParam = 0 }) => fetchItems({ pageParam }),
|
||||
getNextPageParam: (lastPage, pages) => {
|
||||
if (!lastPage || lastPage.length < pageSize) return undefined;
|
||||
return pages.reduce((acc, page) => acc + page.length, 0);
|
||||
},
|
||||
initialPageParam: 0,
|
||||
enabled: !!api && !!user?.Id && !!itemType,
|
||||
});
|
||||
|
||||
const flatData = useMemo(() => data?.pages.flat() ?? [], [data]);
|
||||
|
||||
const nrOfCols = useMemo(() => {
|
||||
if (screenWidth < 350) return 2;
|
||||
if (screenWidth < 600) return 3;
|
||||
if (screenWidth < 900) return 5;
|
||||
return 6;
|
||||
}, [screenWidth]);
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item, index }: { item: BaseItemDto; index: number }) => (
|
||||
<TouchableItemRouter
|
||||
item={item}
|
||||
style={{
|
||||
width: "100%",
|
||||
}}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
alignSelf:
|
||||
index % nrOfCols === 0
|
||||
? "flex-end"
|
||||
: (index + 1) % nrOfCols === 0
|
||||
? "flex-start"
|
||||
: "center",
|
||||
width: "89%",
|
||||
}}
|
||||
>
|
||||
<ItemPoster item={item} />
|
||||
<ItemCardText item={item} />
|
||||
</View>
|
||||
</TouchableItemRouter>
|
||||
),
|
||||
[nrOfCols],
|
||||
);
|
||||
|
||||
const keyExtractor = useCallback((item: BaseItemDto) => item.Id || "", []);
|
||||
|
||||
const handleEndReached = useCallback(() => {
|
||||
if (hasNextPage) {
|
||||
fetchNextPage();
|
||||
}
|
||||
}, [fetchNextPage, hasNextPage]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen
|
||||
options={{
|
||||
headerTitle: headerTitle,
|
||||
headerBlurEffect: "none",
|
||||
headerTransparent: true,
|
||||
headerShadowVisible: false,
|
||||
}}
|
||||
/>
|
||||
{!itemType ? (
|
||||
<View className='flex-1 items-center justify-center px-6'>
|
||||
<Text className='text-neutral-500'>
|
||||
{t("favorites.noData", { defaultValue: "No items found." })}
|
||||
</Text>
|
||||
</View>
|
||||
) : isLoading ? (
|
||||
<View className='justify-center items-center h-full'>
|
||||
<Loader />
|
||||
</View>
|
||||
) : (
|
||||
<FlashList
|
||||
data={flatData}
|
||||
renderItem={renderItem}
|
||||
keyExtractor={keyExtractor}
|
||||
numColumns={nrOfCols}
|
||||
onEndReached={handleEndReached}
|
||||
onEndReachedThreshold={0.8}
|
||||
contentInsetAdjustmentBehavior='automatic'
|
||||
contentContainerStyle={{
|
||||
paddingBottom: 24,
|
||||
paddingLeft: insets.left,
|
||||
paddingRight: insets.right,
|
||||
}}
|
||||
ItemSeparatorComponent={() => (
|
||||
<View
|
||||
style={{
|
||||
width: 10,
|
||||
height: 10,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
ListEmptyComponent={
|
||||
<View className='flex flex-col items-center justify-center h-full py-12'>
|
||||
<Text className='font-bold text-xl text-neutral-500'>
|
||||
{t("home.no_items", { defaultValue: "No items" })}
|
||||
</Text>
|
||||
</View>
|
||||
}
|
||||
ListFooterComponent={
|
||||
isFetching ? (
|
||||
<View style={{ paddingVertical: 16 }}>
|
||||
<Loader />
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
)}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -238,6 +238,42 @@ export default function IndexLayout() {
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='settings/plugins/streamystats/page'
|
||||
options={{
|
||||
title: "Streamystats",
|
||||
headerBlurEffect: "none",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
headerShadowVisible: false,
|
||||
headerLeft: () => (
|
||||
<TouchableOpacity
|
||||
onPress={() => _router.back()}
|
||||
className='pl-0.5'
|
||||
style={{ marginRight: Platform.OS === "android" ? 16 : 0 }}
|
||||
>
|
||||
<Feather name='chevron-left' size={28} color='white' />
|
||||
</TouchableOpacity>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='settings/plugins/kefinTweaks/page'
|
||||
options={{
|
||||
title: "KefinTweaks",
|
||||
headerBlurEffect: "none",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
headerShadowVisible: false,
|
||||
headerLeft: () => (
|
||||
<TouchableOpacity
|
||||
onPress={() => _router.back()}
|
||||
className='pl-0.5'
|
||||
style={{ marginRight: Platform.OS === "android" ? 16 : 0 }}
|
||||
>
|
||||
<Feather name='chevron-left' size={28} color='white' />
|
||||
</TouchableOpacity>
|
||||
),
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='settings/intro/page'
|
||||
options={{
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import { ScrollView } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import DisabledSetting from "@/components/settings/DisabledSetting";
|
||||
import { KefinTweaksSettings } from "@/components/settings/KefinTweaks";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
|
||||
export default function page() {
|
||||
const { pluginSettings } = useSettings();
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
contentInsetAdjustmentBehavior='automatic'
|
||||
contentContainerStyle={{
|
||||
paddingLeft: insets.left,
|
||||
paddingRight: insets.right,
|
||||
}}
|
||||
>
|
||||
<DisabledSetting
|
||||
disabled={pluginSettings?.useKefinTweaks?.locked === true}
|
||||
className='px-4'
|
||||
>
|
||||
<KefinTweaksSettings />
|
||||
</DisabledSetting>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -60,7 +60,7 @@ export default function page() {
|
||||
),
|
||||
});
|
||||
}
|
||||
}, [navigation, value]);
|
||||
}, [navigation, value, pluginSettings?.marlinServerUrl?.locked, t]);
|
||||
|
||||
if (!settings) return null;
|
||||
|
||||
@@ -75,7 +75,10 @@ export default function page() {
|
||||
<DisabledSetting disabled={disabled} className='px-4'>
|
||||
<ListGroup>
|
||||
<DisabledSetting
|
||||
disabled={pluginSettings?.searchEngine?.locked === true}
|
||||
disabled={
|
||||
pluginSettings?.searchEngine?.locked === true ||
|
||||
!!pluginSettings?.streamyStatsServerUrl?.value
|
||||
}
|
||||
showText={!pluginSettings?.marlinServerUrl?.locked}
|
||||
>
|
||||
<ListItem
|
||||
@@ -89,6 +92,7 @@ export default function page() {
|
||||
>
|
||||
<Switch
|
||||
value={settings.searchEngine === "Marlin"}
|
||||
disabled={!!pluginSettings?.streamyStatsServerUrl?.value}
|
||||
onValueChange={(value) => {
|
||||
updateSettings({
|
||||
searchEngine: value ? "Marlin" : "Jellyfin",
|
||||
|
||||
245
app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx
Normal file
245
app/(auth)/(tabs)/(home)/settings/plugins/streamystats/page.tsx
Normal file
@@ -0,0 +1,245 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useNavigation } from "expo-router";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
Linking,
|
||||
ScrollView,
|
||||
Switch,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { toast } from "sonner-native";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { ListGroup } from "@/components/list/ListGroup";
|
||||
import { ListItem } from "@/components/list/ListItem";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
|
||||
export default function page() {
|
||||
const { t } = useTranslation();
|
||||
const navigation = useNavigation();
|
||||
const insets = useSafeAreaInsets();
|
||||
|
||||
const {
|
||||
settings,
|
||||
updateSettings,
|
||||
pluginSettings,
|
||||
refreshStreamyfinPluginSettings,
|
||||
} = useSettings();
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
// Local state for all editable fields
|
||||
const [url, setUrl] = useState<string>(settings?.streamyStatsServerUrl || "");
|
||||
const [useForSearch, setUseForSearch] = useState<boolean>(
|
||||
settings?.searchEngine === "Streamystats",
|
||||
);
|
||||
const [movieRecs, setMovieRecs] = useState<boolean>(
|
||||
settings?.streamyStatsMovieRecommendations ?? false,
|
||||
);
|
||||
const [seriesRecs, setSeriesRecs] = useState<boolean>(
|
||||
settings?.streamyStatsSeriesRecommendations ?? false,
|
||||
);
|
||||
const [promotedWatchlists, setPromotedWatchlists] = useState<boolean>(
|
||||
settings?.streamyStatsPromotedWatchlists ?? false,
|
||||
);
|
||||
|
||||
const isUrlLocked = pluginSettings?.streamyStatsServerUrl?.locked === true;
|
||||
const isStreamystatsEnabled = !!url;
|
||||
|
||||
const onSave = useCallback(() => {
|
||||
const cleanUrl = url.endsWith("/") ? url.slice(0, -1) : url;
|
||||
updateSettings({
|
||||
streamyStatsServerUrl: cleanUrl,
|
||||
searchEngine: useForSearch ? "Streamystats" : "Jellyfin",
|
||||
streamyStatsMovieRecommendations: movieRecs,
|
||||
streamyStatsSeriesRecommendations: seriesRecs,
|
||||
streamyStatsPromotedWatchlists: promotedWatchlists,
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ["search"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["streamystats"] });
|
||||
toast.success(t("home.settings.plugins.streamystats.toasts.saved"));
|
||||
}, [
|
||||
url,
|
||||
useForSearch,
|
||||
movieRecs,
|
||||
seriesRecs,
|
||||
promotedWatchlists,
|
||||
updateSettings,
|
||||
queryClient,
|
||||
t,
|
||||
]);
|
||||
|
||||
// Set up header save button
|
||||
useEffect(() => {
|
||||
navigation.setOptions({
|
||||
headerRight: () => (
|
||||
<TouchableOpacity onPress={onSave}>
|
||||
<Text className='text-blue-500 font-medium'>
|
||||
{t("home.settings.plugins.streamystats.save")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
),
|
||||
});
|
||||
}, [navigation, onSave, t]);
|
||||
|
||||
const handleClearStreamystats = useCallback(() => {
|
||||
setUrl("");
|
||||
setUseForSearch(false);
|
||||
setMovieRecs(false);
|
||||
setSeriesRecs(false);
|
||||
setPromotedWatchlists(false);
|
||||
updateSettings({
|
||||
streamyStatsServerUrl: "",
|
||||
searchEngine: "Jellyfin",
|
||||
streamyStatsMovieRecommendations: false,
|
||||
streamyStatsSeriesRecommendations: false,
|
||||
streamyStatsPromotedWatchlists: false,
|
||||
});
|
||||
queryClient.invalidateQueries({ queryKey: ["streamystats"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["search"] });
|
||||
toast.success(t("home.settings.plugins.streamystats.toasts.disabled"));
|
||||
}, [updateSettings, queryClient, t]);
|
||||
|
||||
const handleOpenLink = () => {
|
||||
Linking.openURL("https://github.com/fredrikburmester/streamystats");
|
||||
};
|
||||
|
||||
const handleRefreshFromServer = useCallback(async () => {
|
||||
const newPluginSettings = await refreshStreamyfinPluginSettings(true);
|
||||
// Update local state with new values
|
||||
const newUrl = newPluginSettings?.streamyStatsServerUrl?.value || "";
|
||||
setUrl(newUrl);
|
||||
if (newUrl) {
|
||||
setUseForSearch(true);
|
||||
}
|
||||
toast.success(t("home.settings.plugins.streamystats.toasts.refreshed"));
|
||||
}, [refreshStreamyfinPluginSettings, t]);
|
||||
|
||||
if (!settings) return null;
|
||||
|
||||
return (
|
||||
<ScrollView
|
||||
contentInsetAdjustmentBehavior='automatic'
|
||||
contentContainerStyle={{
|
||||
paddingLeft: insets.left,
|
||||
paddingRight: insets.right,
|
||||
}}
|
||||
>
|
||||
<View className='px-4'>
|
||||
<ListGroup className='flex-1'>
|
||||
<ListItem
|
||||
title={t("home.settings.plugins.streamystats.url")}
|
||||
disabledByAdmin={isUrlLocked}
|
||||
>
|
||||
<TextInput
|
||||
editable={!isUrlLocked}
|
||||
className='text-white text-right flex-1'
|
||||
placeholder={t(
|
||||
"home.settings.plugins.streamystats.server_url_placeholder",
|
||||
)}
|
||||
value={url}
|
||||
keyboardType='url'
|
||||
returnKeyType='done'
|
||||
autoCapitalize='none'
|
||||
textContentType='URL'
|
||||
onChangeText={setUrl}
|
||||
/>
|
||||
</ListItem>
|
||||
</ListGroup>
|
||||
|
||||
<Text className='px-4 text-xs text-neutral-500 mt-1'>
|
||||
{t("home.settings.plugins.streamystats.streamystats_search_hint")}{" "}
|
||||
<Text className='text-blue-500' onPress={handleOpenLink}>
|
||||
{t(
|
||||
"home.settings.plugins.streamystats.read_more_about_streamystats",
|
||||
)}
|
||||
</Text>
|
||||
</Text>
|
||||
|
||||
<ListGroup
|
||||
title={t("home.settings.plugins.streamystats.features_title")}
|
||||
className='mt-4'
|
||||
>
|
||||
<ListItem
|
||||
title={t("home.settings.plugins.streamystats.enable_search")}
|
||||
disabledByAdmin={pluginSettings?.searchEngine?.locked === true}
|
||||
>
|
||||
<Switch
|
||||
value={useForSearch}
|
||||
disabled={!isStreamystatsEnabled}
|
||||
onValueChange={setUseForSearch}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
title={t(
|
||||
"home.settings.plugins.streamystats.enable_movie_recommendations",
|
||||
)}
|
||||
disabledByAdmin={
|
||||
pluginSettings?.streamyStatsMovieRecommendations?.locked === true
|
||||
}
|
||||
>
|
||||
<Switch
|
||||
value={movieRecs}
|
||||
onValueChange={setMovieRecs}
|
||||
disabled={!isStreamystatsEnabled}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
title={t(
|
||||
"home.settings.plugins.streamystats.enable_series_recommendations",
|
||||
)}
|
||||
disabledByAdmin={
|
||||
pluginSettings?.streamyStatsSeriesRecommendations?.locked === true
|
||||
}
|
||||
>
|
||||
<Switch
|
||||
value={seriesRecs}
|
||||
onValueChange={setSeriesRecs}
|
||||
disabled={!isStreamystatsEnabled}
|
||||
/>
|
||||
</ListItem>
|
||||
<ListItem
|
||||
title={t(
|
||||
"home.settings.plugins.streamystats.enable_promoted_watchlists",
|
||||
)}
|
||||
disabledByAdmin={
|
||||
pluginSettings?.streamyStatsPromotedWatchlists?.locked === true
|
||||
}
|
||||
>
|
||||
<Switch
|
||||
value={promotedWatchlists}
|
||||
onValueChange={setPromotedWatchlists}
|
||||
disabled={!isStreamystatsEnabled}
|
||||
/>
|
||||
</ListItem>
|
||||
</ListGroup>
|
||||
<Text className='px-4 text-xs text-neutral-500 mt-1'>
|
||||
{t("home.settings.plugins.streamystats.home_sections_hint")}
|
||||
</Text>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={handleRefreshFromServer}
|
||||
className='mt-6 py-3 rounded-xl bg-neutral-800'
|
||||
>
|
||||
<Text className='text-center text-blue-500'>
|
||||
{t("home.settings.plugins.streamystats.refresh_from_server")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
|
||||
{/* Disable button - only show if URL is not locked and Streamystats is enabled */}
|
||||
{!isUrlLocked && isStreamystatsEnabled && (
|
||||
<TouchableOpacity
|
||||
onPress={handleClearStreamystats}
|
||||
className='mt-3 mb-4 py-3 rounded-xl bg-neutral-800'
|
||||
>
|
||||
<Text className='text-center text-red-500'>
|
||||
{t("home.settings.plugins.streamystats.disable_streamystats")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
</ScrollView>
|
||||
);
|
||||
}
|
||||
@@ -21,14 +21,16 @@ const Page: React.FC = () => {
|
||||
const { offline } = useLocalSearchParams() as { offline?: string };
|
||||
const isOffline = offline === "true";
|
||||
|
||||
const { data: item, isError } = useItemQuery(id, false, undefined, [
|
||||
// Exclude MediaSources/MediaStreams from initial fetch for faster loading
|
||||
// (especially important for plugins like Gelato)
|
||||
const { data: item, isError } = useItemQuery(id, isOffline, undefined, [
|
||||
ItemFields.MediaSources,
|
||||
ItemFields.MediaSourceCount,
|
||||
ItemFields.MediaStreams,
|
||||
]);
|
||||
|
||||
// preload media sources
|
||||
const { data: itemWithSources } = useItemQuery(id, false, undefined, []);
|
||||
// Lazily preload item with full media sources in background
|
||||
const { data: itemWithSources } = useItemQuery(id, isOffline, undefined, []);
|
||||
|
||||
const opacity = useSharedValue(1);
|
||||
const animatedStyle = useAnimatedStyle(() => {
|
||||
@@ -0,0 +1,192 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { getItemsApi, getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Image } from "expo-image";
|
||||
import { useLocalSearchParams, useNavigation } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, TouchableOpacity, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicTrackItem } from "@/components/music/MusicTrackItem";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useMusicPlayer } from "@/providers/MusicPlayerProvider";
|
||||
import { getPrimaryImageUrl } from "@/utils/jellyfin/image/getPrimaryImageUrl";
|
||||
import { runtimeTicksToMinutes } from "@/utils/time";
|
||||
|
||||
const { width: SCREEN_WIDTH } = Dimensions.get("window");
|
||||
const ARTWORK_SIZE = SCREEN_WIDTH * 0.5;
|
||||
|
||||
export default function AlbumDetailScreen() {
|
||||
const { albumId } = useLocalSearchParams<{ albumId: string }>();
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const navigation = useNavigation();
|
||||
const { t } = useTranslation();
|
||||
const { playQueue } = useMusicPlayer();
|
||||
|
||||
const { data: album, isLoading: loadingAlbum } = useQuery({
|
||||
queryKey: ["music-album", albumId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getUserLibraryApi(api!).getItem({
|
||||
userId: user?.Id,
|
||||
itemId: albumId!,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!albumId,
|
||||
});
|
||||
|
||||
const { data: tracks, isLoading: loadingTracks } = useQuery({
|
||||
queryKey: ["music-album-tracks", albumId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: albumId,
|
||||
sortBy: ["IndexNumber"],
|
||||
sortOrder: ["Ascending"],
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!albumId,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
navigation.setOptions({ title: album?.Name ?? "" });
|
||||
}, [album?.Name, navigation]);
|
||||
|
||||
const imageUrl = useMemo(
|
||||
() => (album ? getPrimaryImageUrl({ api, item: album }) : null),
|
||||
[api, album],
|
||||
);
|
||||
|
||||
const totalDuration = useMemo(() => {
|
||||
if (!tracks) return "";
|
||||
const totalTicks = tracks.reduce(
|
||||
(acc, track) => acc + (track.RunTimeTicks || 0),
|
||||
0,
|
||||
);
|
||||
return runtimeTicksToMinutes(totalTicks);
|
||||
}, [tracks]);
|
||||
|
||||
const handlePlayAll = useCallback(() => {
|
||||
if (tracks && tracks.length > 0) {
|
||||
playQueue(tracks, 0);
|
||||
}
|
||||
}, [playQueue, tracks]);
|
||||
|
||||
const handleShuffle = useCallback(() => {
|
||||
if (tracks && tracks.length > 0) {
|
||||
const shuffled = [...tracks].sort(() => Math.random() - 0.5);
|
||||
playQueue(shuffled, 0);
|
||||
}
|
||||
}, [playQueue, tracks]);
|
||||
|
||||
const isLoading = loadingAlbum || loadingTracks;
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!album) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.album_not_found")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={tracks || []}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
}}
|
||||
ListHeaderComponent={
|
||||
<View className='items-center px-4 pt-4 pb-6'>
|
||||
{/* Album artwork */}
|
||||
<View
|
||||
style={{
|
||||
width: ARTWORK_SIZE,
|
||||
height: ARTWORK_SIZE,
|
||||
borderRadius: 8,
|
||||
overflow: "hidden",
|
||||
backgroundColor: "#1a1a1a",
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 8 },
|
||||
shadowOpacity: 0.3,
|
||||
shadowRadius: 12,
|
||||
elevation: 8,
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<Image
|
||||
source={{ uri: imageUrl }}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
contentFit='cover'
|
||||
cachePolicy='memory-disk'
|
||||
/>
|
||||
) : (
|
||||
<View className='flex-1 items-center justify-center bg-neutral-800'>
|
||||
<Ionicons name='disc' size={60} color='#666' />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Album info */}
|
||||
<Text className='text-white text-xl font-bold mt-4 text-center'>
|
||||
{album.Name}
|
||||
</Text>
|
||||
<Text className='text-purple-400 text-base mt-1'>
|
||||
{album.AlbumArtist || album.Artists?.join(", ")}
|
||||
</Text>
|
||||
<Text className='text-neutral-500 text-sm mt-1'>
|
||||
{album.ProductionYear && `${album.ProductionYear} • `}
|
||||
{tracks?.length} tracks • {totalDuration}
|
||||
</Text>
|
||||
|
||||
{/* Play buttons */}
|
||||
<View className='flex flex-row mt-4'>
|
||||
<TouchableOpacity
|
||||
onPress={handlePlayAll}
|
||||
className='flex flex-row items-center bg-purple-600 px-6 py-3 rounded-full mr-3'
|
||||
>
|
||||
<Ionicons name='play' size={20} color='white' />
|
||||
<Text className='text-white font-medium ml-2'>
|
||||
{t("music.play")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={handleShuffle}
|
||||
className='flex flex-row items-center bg-neutral-800 px-6 py-3 rounded-full'
|
||||
>
|
||||
<Ionicons name='shuffle' size={20} color='white' />
|
||||
<Text className='text-white font-medium ml-2'>
|
||||
{t("music.shuffle")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
}
|
||||
renderItem={({ item, index }) => (
|
||||
<View className='px-4'>
|
||||
<MusicTrackItem
|
||||
track={item}
|
||||
index={index + 1}
|
||||
queue={tracks}
|
||||
showArtwork={false}
|
||||
/>
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,220 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { getItemsApi, getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Image } from "expo-image";
|
||||
import { useLocalSearchParams, useNavigation } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, TouchableOpacity, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { HorizontalScroll } from "@/components/common/HorizontalScroll";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicAlbumCard } from "@/components/music/MusicAlbumCard";
|
||||
import { MusicTrackItem } from "@/components/music/MusicTrackItem";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useMusicPlayer } from "@/providers/MusicPlayerProvider";
|
||||
import { getPrimaryImageUrl } from "@/utils/jellyfin/image/getPrimaryImageUrl";
|
||||
|
||||
const { width: SCREEN_WIDTH } = Dimensions.get("window");
|
||||
const ARTWORK_SIZE = SCREEN_WIDTH * 0.4;
|
||||
|
||||
export default function ArtistDetailScreen() {
|
||||
const { artistId } = useLocalSearchParams<{ artistId: string }>();
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const navigation = useNavigation();
|
||||
const { t } = useTranslation();
|
||||
const { playQueue } = useMusicPlayer();
|
||||
|
||||
const { data: artist, isLoading: loadingArtist } = useQuery({
|
||||
queryKey: ["music-artist", artistId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getUserLibraryApi(api!).getItem({
|
||||
userId: user?.Id,
|
||||
itemId: artistId!,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!artistId,
|
||||
});
|
||||
|
||||
const { data: albums, isLoading: loadingAlbums } = useQuery({
|
||||
queryKey: ["music-artist-albums", artistId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
artistIds: [artistId!],
|
||||
includeItemTypes: ["MusicAlbum"],
|
||||
sortBy: ["ProductionYear", "SortName"],
|
||||
sortOrder: ["Descending", "Ascending"],
|
||||
recursive: true,
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!artistId,
|
||||
});
|
||||
|
||||
const { data: topTracks, isLoading: loadingTracks } = useQuery({
|
||||
queryKey: ["music-artist-top-tracks", artistId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
artistIds: [artistId!],
|
||||
includeItemTypes: ["Audio"],
|
||||
sortBy: ["PlayCount"],
|
||||
sortOrder: ["Descending"],
|
||||
limit: 10,
|
||||
recursive: true,
|
||||
filters: ["IsPlayed"],
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!artistId,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
navigation.setOptions({ title: artist?.Name ?? "" });
|
||||
}, [artist?.Name, navigation]);
|
||||
|
||||
const imageUrl = useMemo(
|
||||
() => (artist ? getPrimaryImageUrl({ api, item: artist }) : null),
|
||||
[api, artist],
|
||||
);
|
||||
|
||||
const handlePlayAllTracks = useCallback(() => {
|
||||
if (topTracks && topTracks.length > 0) {
|
||||
playQueue(topTracks, 0);
|
||||
}
|
||||
}, [playQueue, topTracks]);
|
||||
|
||||
const isLoading = loadingArtist || loadingAlbums || loadingTracks;
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!artist) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.artist_not_found")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
const sections = [];
|
||||
|
||||
// Top tracks section
|
||||
if (topTracks && topTracks.length > 0) {
|
||||
sections.push({
|
||||
id: "top-tracks",
|
||||
title: t("music.top_tracks"),
|
||||
type: "tracks" as const,
|
||||
data: topTracks,
|
||||
});
|
||||
}
|
||||
|
||||
// Albums section
|
||||
if (albums && albums.length > 0) {
|
||||
sections.push({
|
||||
id: "albums",
|
||||
title: t("music.tabs.albums"),
|
||||
type: "albums" as const,
|
||||
data: albums,
|
||||
});
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={sections}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
}}
|
||||
ListHeaderComponent={
|
||||
<View className='items-center px-4 pt-4 pb-6'>
|
||||
{/* Artist image */}
|
||||
<View
|
||||
style={{
|
||||
width: ARTWORK_SIZE,
|
||||
height: ARTWORK_SIZE,
|
||||
borderRadius: ARTWORK_SIZE / 2,
|
||||
overflow: "hidden",
|
||||
backgroundColor: "#1a1a1a",
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 8 },
|
||||
shadowOpacity: 0.3,
|
||||
shadowRadius: 12,
|
||||
elevation: 8,
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<Image
|
||||
source={{ uri: imageUrl }}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
contentFit='cover'
|
||||
cachePolicy='memory-disk'
|
||||
/>
|
||||
) : (
|
||||
<View className='flex-1 items-center justify-center bg-neutral-800'>
|
||||
<Ionicons name='person' size={60} color='#666' />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Artist info */}
|
||||
<Text className='text-white text-2xl font-bold mt-4 text-center'>
|
||||
{artist.Name}
|
||||
</Text>
|
||||
<Text className='text-neutral-500 text-sm mt-1'>
|
||||
{albums?.length || 0} {t("music.tabs.albums").toLowerCase()}
|
||||
</Text>
|
||||
|
||||
{/* Play button */}
|
||||
{topTracks && topTracks.length > 0 && (
|
||||
<TouchableOpacity
|
||||
onPress={handlePlayAllTracks}
|
||||
className='flex flex-row items-center bg-purple-600 px-6 py-3 rounded-full mt-4'
|
||||
>
|
||||
<Ionicons name='play' size={20} color='white' />
|
||||
<Text className='text-white font-medium ml-2'>
|
||||
{t("music.play_top_tracks")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</View>
|
||||
}
|
||||
renderItem={({ item: section }) => (
|
||||
<View className='mb-6'>
|
||||
<Text className='text-lg font-bold px-4 mb-3'>{section.title}</Text>
|
||||
{section.type === "albums" ? (
|
||||
<HorizontalScroll
|
||||
data={section.data}
|
||||
height={200}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
renderItem={(item) => <MusicAlbumCard album={item} />}
|
||||
/>
|
||||
) : (
|
||||
<View className='px-4'>
|
||||
{section.data.slice(0, 5).map((track, index) => (
|
||||
<MusicTrackItem
|
||||
key={track.Id}
|
||||
track={track}
|
||||
index={index + 1}
|
||||
queue={section.data}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.id}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { getItemsApi, getUserLibraryApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { Image } from "expo-image";
|
||||
import { useLocalSearchParams, useNavigation } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useEffect, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, TouchableOpacity, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicTrackItem } from "@/components/music/MusicTrackItem";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useMusicPlayer } from "@/providers/MusicPlayerProvider";
|
||||
import { getPrimaryImageUrl } from "@/utils/jellyfin/image/getPrimaryImageUrl";
|
||||
import { runtimeTicksToMinutes } from "@/utils/time";
|
||||
|
||||
const { width: SCREEN_WIDTH } = Dimensions.get("window");
|
||||
const ARTWORK_SIZE = SCREEN_WIDTH * 0.5;
|
||||
|
||||
export default function PlaylistDetailScreen() {
|
||||
const { playlistId } = useLocalSearchParams<{ playlistId: string }>();
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const navigation = useNavigation();
|
||||
const { t } = useTranslation();
|
||||
const { playQueue } = useMusicPlayer();
|
||||
|
||||
const { data: playlist, isLoading: loadingPlaylist } = useQuery({
|
||||
queryKey: ["music-playlist", playlistId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getUserLibraryApi(api!).getItem({
|
||||
userId: user?.Id,
|
||||
itemId: playlistId!,
|
||||
});
|
||||
return response.data;
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!playlistId,
|
||||
});
|
||||
|
||||
const { data: tracks, isLoading: loadingTracks } = useQuery({
|
||||
queryKey: ["music-playlist-tracks", playlistId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: playlistId,
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: !!api && !!user?.Id && !!playlistId,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
navigation.setOptions({ title: playlist?.Name ?? "" });
|
||||
}, [playlist?.Name, navigation]);
|
||||
|
||||
const imageUrl = useMemo(
|
||||
() => (playlist ? getPrimaryImageUrl({ api, item: playlist }) : null),
|
||||
[api, playlist],
|
||||
);
|
||||
|
||||
const totalDuration = useMemo(() => {
|
||||
if (!tracks) return "";
|
||||
const totalTicks = tracks.reduce(
|
||||
(acc, track) => acc + (track.RunTimeTicks || 0),
|
||||
0,
|
||||
);
|
||||
return runtimeTicksToMinutes(totalTicks);
|
||||
}, [tracks]);
|
||||
|
||||
const handlePlayAll = useCallback(() => {
|
||||
if (tracks && tracks.length > 0) {
|
||||
playQueue(tracks, 0);
|
||||
}
|
||||
}, [playQueue, tracks]);
|
||||
|
||||
const handleShuffle = useCallback(() => {
|
||||
if (tracks && tracks.length > 0) {
|
||||
const shuffled = [...tracks].sort(() => Math.random() - 0.5);
|
||||
playQueue(shuffled, 0);
|
||||
}
|
||||
}, [playQueue, tracks]);
|
||||
|
||||
const isLoading = loadingPlaylist || loadingTracks;
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!playlist) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>
|
||||
{t("music.playlist_not_found")}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={tracks || []}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
}}
|
||||
ListHeaderComponent={
|
||||
<View className='items-center px-4 pt-4 pb-6'>
|
||||
{/* Playlist artwork */}
|
||||
<View
|
||||
style={{
|
||||
width: ARTWORK_SIZE,
|
||||
height: ARTWORK_SIZE,
|
||||
borderRadius: 8,
|
||||
overflow: "hidden",
|
||||
backgroundColor: "#1a1a1a",
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 8 },
|
||||
shadowOpacity: 0.3,
|
||||
shadowRadius: 12,
|
||||
elevation: 8,
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<Image
|
||||
source={{ uri: imageUrl }}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
contentFit='cover'
|
||||
cachePolicy='memory-disk'
|
||||
/>
|
||||
) : (
|
||||
<View className='flex-1 items-center justify-center bg-neutral-800'>
|
||||
<Ionicons name='list' size={60} color='#666' />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Playlist info */}
|
||||
<Text className='text-white text-xl font-bold mt-4 text-center'>
|
||||
{playlist.Name}
|
||||
</Text>
|
||||
<Text className='text-neutral-500 text-sm mt-1'>
|
||||
{tracks?.length} tracks • {totalDuration}
|
||||
</Text>
|
||||
|
||||
{/* Play buttons */}
|
||||
<View className='flex flex-row mt-4'>
|
||||
<TouchableOpacity
|
||||
onPress={handlePlayAll}
|
||||
className='flex flex-row items-center bg-purple-600 px-6 py-3 rounded-full mr-3'
|
||||
>
|
||||
<Ionicons name='play' size={20} color='white' />
|
||||
<Text className='text-white font-medium ml-2'>
|
||||
{t("music.play")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={handleShuffle}
|
||||
className='flex flex-row items-center bg-neutral-800 px-6 py-3 rounded-full'
|
||||
>
|
||||
<Ionicons name='shuffle' size={20} color='white' />
|
||||
<Text className='text-white font-medium ml-2'>
|
||||
{t("music.shuffle")}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
</View>
|
||||
}
|
||||
renderItem={({ item, index }) => (
|
||||
<View className='px-4'>
|
||||
<MusicTrackItem track={item} index={index + 1} queue={tracks} />
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import type {
|
||||
BaseItemDto,
|
||||
BaseItemDtoQueryResult,
|
||||
BaseItemKind,
|
||||
ItemFilter,
|
||||
} from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import {
|
||||
getFilterApi,
|
||||
@@ -27,7 +28,11 @@ import { useOrientation } from "@/hooks/useOrientation";
|
||||
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import {
|
||||
FilterByOption,
|
||||
FilterByPreferenceAtom,
|
||||
filterByAtom,
|
||||
genreFilterAtom,
|
||||
getFilterByPreference,
|
||||
getSortByPreference,
|
||||
getSortOrderPreference,
|
||||
SortByOption,
|
||||
@@ -39,8 +44,10 @@ import {
|
||||
sortOrderOptions,
|
||||
sortOrderPreferenceAtom,
|
||||
tagsFilterAtom,
|
||||
useFilterOptions,
|
||||
yearFilterAtom,
|
||||
} from "@/utils/atoms/filters";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
|
||||
const Page = () => {
|
||||
const searchParams = useLocalSearchParams();
|
||||
@@ -54,9 +61,13 @@ const Page = () => {
|
||||
const [selectedYears, setSelectedYears] = useAtom(yearFilterAtom);
|
||||
const [selectedTags, setSelectedTags] = useAtom(tagsFilterAtom);
|
||||
const [sortBy, _setSortBy] = useAtom(sortByAtom);
|
||||
const [filterBy, _setFilterBy] = useAtom(filterByAtom);
|
||||
const [sortOrder, _setSortOrder] = useAtom(sortOrderAtom);
|
||||
const [sortByPreference, setSortByPreference] = useAtom(sortByPreferenceAtom);
|
||||
const [sortOrderPreference, setOderByPreference] = useAtom(
|
||||
const [filterByPreference, setFilterByPreference] = useAtom(
|
||||
FilterByPreferenceAtom,
|
||||
);
|
||||
const [sortOrderPreference, setOrderByPreference] = useAtom(
|
||||
sortOrderPreferenceAtom,
|
||||
);
|
||||
|
||||
@@ -77,12 +88,20 @@ const Page = () => {
|
||||
} else {
|
||||
_setSortBy([SortByOption.SortName]);
|
||||
}
|
||||
const fp = getFilterByPreference(libraryId, filterByPreference);
|
||||
if (fp) {
|
||||
_setFilterBy([fp]);
|
||||
} else {
|
||||
_setFilterBy([]);
|
||||
}
|
||||
}, [
|
||||
libraryId,
|
||||
sortOrderPreference,
|
||||
sortByPreference,
|
||||
_setSortOrder,
|
||||
_setSortBy,
|
||||
filterByPreference,
|
||||
_setFilterBy,
|
||||
]);
|
||||
|
||||
const setSortBy = useCallback(
|
||||
@@ -100,14 +119,28 @@ const Page = () => {
|
||||
(sortOrder: SortOrderOption[]) => {
|
||||
const sop = getSortOrderPreference(libraryId, sortOrderPreference);
|
||||
if (sortOrder[0] !== sop) {
|
||||
setOderByPreference({
|
||||
setOrderByPreference({
|
||||
...sortOrderPreference,
|
||||
[libraryId]: sortOrder[0],
|
||||
});
|
||||
}
|
||||
_setSortOrder(sortOrder);
|
||||
},
|
||||
[libraryId, sortOrderPreference, setOderByPreference, _setSortOrder],
|
||||
[libraryId, sortOrderPreference, setOrderByPreference, _setSortOrder],
|
||||
);
|
||||
|
||||
const setFilter = useCallback(
|
||||
(filterBy: FilterByOption[]) => {
|
||||
const fp = getFilterByPreference(libraryId, filterByPreference);
|
||||
if (filterBy[0] !== fp) {
|
||||
setFilterByPreference({
|
||||
...filterByPreference,
|
||||
[libraryId]: filterBy[0],
|
||||
});
|
||||
}
|
||||
_setFilterBy(filterBy);
|
||||
},
|
||||
[libraryId, filterByPreference, setFilterByPreference, _setFilterBy],
|
||||
);
|
||||
|
||||
const nrOfCols = useMemo(() => {
|
||||
@@ -168,6 +201,7 @@ const Page = () => {
|
||||
sortBy: [sortBy[0], "SortName", "ProductionYear"],
|
||||
sortOrder: [sortOrder[0]],
|
||||
enableImageTypes: ["Primary", "Backdrop", "Banner", "Thumb"],
|
||||
filters: filterBy as ItemFilter[],
|
||||
// true is needed for merged versions
|
||||
recursive: true,
|
||||
imageTypeLimit: 1,
|
||||
@@ -190,6 +224,7 @@ const Page = () => {
|
||||
selectedTags,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
filterBy,
|
||||
],
|
||||
);
|
||||
|
||||
@@ -203,6 +238,7 @@ const Page = () => {
|
||||
selectedTags,
|
||||
sortBy,
|
||||
sortOrder,
|
||||
filterBy,
|
||||
],
|
||||
queryFn: fetchItems,
|
||||
getNextPageParam: (lastPage, pages) => {
|
||||
@@ -268,7 +304,8 @@ const Page = () => {
|
||||
);
|
||||
|
||||
const keyExtractor = useCallback((item: BaseItemDto) => item.Id || "", []);
|
||||
|
||||
const generalFilters = useFilterOptions();
|
||||
const settings = useSettings();
|
||||
const ListHeaderComponent = useCallback(
|
||||
() => (
|
||||
<FlatList
|
||||
@@ -404,6 +441,26 @@ const Page = () => {
|
||||
/>
|
||||
),
|
||||
},
|
||||
{
|
||||
key: "filterOptions",
|
||||
component: (
|
||||
<FilterButton
|
||||
className='mr-1'
|
||||
id={libraryId}
|
||||
queryKey='filters'
|
||||
queryFn={async () => generalFilters.map((s) => s.key)}
|
||||
set={setFilter}
|
||||
values={filterBy}
|
||||
title={t("library.filters.filter_by")}
|
||||
renderItemLabel={(item) =>
|
||||
generalFilters.find((i) => i.key === item)?.value || ""
|
||||
}
|
||||
searchFilter={(item, search) =>
|
||||
item.toLowerCase().includes(search.toLowerCase())
|
||||
}
|
||||
/>
|
||||
),
|
||||
},
|
||||
]}
|
||||
renderItem={({ item }) => item.component}
|
||||
keyExtractor={(item) => item.key}
|
||||
@@ -424,6 +481,9 @@ const Page = () => {
|
||||
sortOrder,
|
||||
setSortOrder,
|
||||
isFetching,
|
||||
filterBy,
|
||||
setFilter,
|
||||
settings,
|
||||
],
|
||||
);
|
||||
|
||||
|
||||
@@ -39,7 +39,6 @@ export default function index() {
|
||||
() =>
|
||||
data
|
||||
?.filter((l) => !settings?.hiddenLibraries?.includes(l.Id!))
|
||||
.filter((l) => l.CollectionType !== "music")
|
||||
.filter((l) => l.CollectionType !== "books") || [],
|
||||
[data, settings?.hiddenLibraries],
|
||||
);
|
||||
|
||||
81
app/(auth)/(tabs)/(libraries)/music/[libraryId]/_layout.tsx
Normal file
81
app/(auth)/(tabs)/(libraries)/music/[libraryId]/_layout.tsx
Normal file
@@ -0,0 +1,81 @@
|
||||
import {
|
||||
createMaterialTopTabNavigator,
|
||||
MaterialTopTabNavigationEventMap,
|
||||
MaterialTopTabNavigationOptions,
|
||||
} from "@react-navigation/material-top-tabs";
|
||||
import type {
|
||||
ParamListBase,
|
||||
TabNavigationState,
|
||||
} from "@react-navigation/native";
|
||||
import { Stack, useLocalSearchParams, withLayoutContext } from "expo-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
|
||||
const { Navigator } = createMaterialTopTabNavigator();
|
||||
|
||||
const TAB_LABEL_FONT_SIZE = 13;
|
||||
const TAB_ITEM_HORIZONTAL_PADDING = 18;
|
||||
const TAB_ITEM_MIN_WIDTH = 110;
|
||||
|
||||
export const Tab = withLayoutContext<
|
||||
MaterialTopTabNavigationOptions,
|
||||
typeof Navigator,
|
||||
TabNavigationState<ParamListBase>,
|
||||
MaterialTopTabNavigationEventMap
|
||||
>(Navigator);
|
||||
|
||||
const Layout = () => {
|
||||
const { libraryId } = useLocalSearchParams<{ libraryId: string }>();
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<>
|
||||
<Stack.Screen options={{ title: t("music.title") }} />
|
||||
<Tab
|
||||
initialRouteName='suggestions'
|
||||
keyboardDismissMode='none'
|
||||
screenOptions={{
|
||||
tabBarBounces: true,
|
||||
tabBarLabelStyle: {
|
||||
fontSize: TAB_LABEL_FONT_SIZE,
|
||||
fontWeight: "600",
|
||||
flexWrap: "nowrap",
|
||||
},
|
||||
tabBarItemStyle: {
|
||||
width: "auto",
|
||||
minWidth: TAB_ITEM_MIN_WIDTH,
|
||||
paddingHorizontal: TAB_ITEM_HORIZONTAL_PADDING,
|
||||
},
|
||||
tabBarStyle: { backgroundColor: "black" },
|
||||
animationEnabled: true,
|
||||
lazy: true,
|
||||
swipeEnabled: true,
|
||||
tabBarIndicatorStyle: { backgroundColor: "#9334E9" },
|
||||
tabBarScrollEnabled: true,
|
||||
}}
|
||||
>
|
||||
<Tab.Screen
|
||||
name='suggestions'
|
||||
initialParams={{ libraryId }}
|
||||
options={{ title: t("music.tabs.suggestions") }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name='albums'
|
||||
initialParams={{ libraryId }}
|
||||
options={{ title: t("music.tabs.albums") }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name='artists'
|
||||
initialParams={{ libraryId }}
|
||||
options={{ title: t("music.tabs.artists") }}
|
||||
/>
|
||||
<Tab.Screen
|
||||
name='playlists'
|
||||
initialParams={{ libraryId }}
|
||||
options={{ title: t("music.tabs.playlists") }}
|
||||
/>
|
||||
</Tab>
|
||||
</>
|
||||
);
|
||||
};
|
||||
|
||||
export default Layout;
|
||||
136
app/(auth)/(tabs)/(libraries)/music/[libraryId]/albums.tsx
Normal file
136
app/(auth)/(tabs)/(libraries)/music/[libraryId]/albums.tsx
Normal file
@@ -0,0 +1,136 @@
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useRoute } from "@react-navigation/native";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, RefreshControl, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicAlbumCard } from "@/components/music/MusicAlbumCard";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
|
||||
const ITEMS_PER_PAGE = 40;
|
||||
|
||||
export default function AlbumsScreen() {
|
||||
const localParams = useLocalSearchParams<{ libraryId?: string | string[] }>();
|
||||
const route = useRoute<any>();
|
||||
const libraryId =
|
||||
(Array.isArray(localParams.libraryId)
|
||||
? localParams.libraryId[0]
|
||||
: localParams.libraryId) ?? route?.params?.libraryId;
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
refetch,
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ["music-albums", libraryId, user?.Id],
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: libraryId,
|
||||
includeItemTypes: ["MusicAlbum"],
|
||||
sortBy: ["SortName"],
|
||||
sortOrder: ["Ascending"],
|
||||
limit: ITEMS_PER_PAGE,
|
||||
startIndex: pageParam,
|
||||
recursive: true,
|
||||
});
|
||||
return {
|
||||
items: response.data.Items || [],
|
||||
totalCount: response.data.TotalRecordCount || 0,
|
||||
startIndex: pageParam,
|
||||
};
|
||||
},
|
||||
getNextPageParam: (lastPage) => {
|
||||
const nextStart = lastPage.startIndex + ITEMS_PER_PAGE;
|
||||
return nextStart < lastPage.totalCount ? nextStart : undefined;
|
||||
},
|
||||
initialPageParam: 0,
|
||||
enabled: !!api && !!user?.Id && !!libraryId,
|
||||
});
|
||||
|
||||
const albums = useMemo(() => {
|
||||
return data?.pages.flatMap((page) => page.items) || [];
|
||||
}, [data]);
|
||||
|
||||
const numColumns = 2;
|
||||
const screenWidth = Dimensions.get("window").width;
|
||||
const gap = 12;
|
||||
const padding = 16;
|
||||
const itemWidth =
|
||||
(screenWidth - padding * 2 - gap * (numColumns - 1)) / numColumns;
|
||||
|
||||
const handleEndReached = useCallback(() => {
|
||||
if (hasNextPage && !isFetchingNextPage) {
|
||||
fetchNextPage();
|
||||
}
|
||||
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (albums.length === 0) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.no_albums")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={albums}
|
||||
numColumns={numColumns}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
paddingTop: 16,
|
||||
paddingHorizontal: padding,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={false}
|
||||
onRefresh={refetch}
|
||||
tintColor='#9334E9'
|
||||
/>
|
||||
}
|
||||
onEndReached={handleEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
renderItem={({ item, index }) => (
|
||||
<View
|
||||
style={{
|
||||
width: itemWidth,
|
||||
marginRight: index % numColumns === 0 ? gap : 0,
|
||||
marginBottom: gap,
|
||||
}}
|
||||
>
|
||||
<MusicAlbumCard album={item} width={itemWidth} />
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
ListFooterComponent={
|
||||
isFetchingNextPage ? (
|
||||
<View className='py-4'>
|
||||
<Loader />
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
170
app/(auth)/(tabs)/(libraries)/music/[libraryId]/artists.tsx
Normal file
170
app/(auth)/(tabs)/(libraries)/music/[libraryId]/artists.tsx
Normal file
@@ -0,0 +1,170 @@
|
||||
import { getArtistsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useRoute } from "@react-navigation/native";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, RefreshControl, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicArtistCard } from "@/components/music/MusicArtistCard";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
|
||||
// Web uses Limit=100
|
||||
const ITEMS_PER_PAGE = 100;
|
||||
|
||||
export default function ArtistsScreen() {
|
||||
const localParams = useLocalSearchParams<{ libraryId?: string | string[] }>();
|
||||
const route = useRoute<any>();
|
||||
const libraryId =
|
||||
(Array.isArray(localParams.libraryId)
|
||||
? localParams.libraryId[0]
|
||||
: localParams.libraryId) ?? route?.params?.libraryId;
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isReady = Boolean(api && user?.Id && libraryId);
|
||||
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
isError,
|
||||
error,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
refetch,
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ["music-artists", libraryId, user?.Id],
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
const response = await getArtistsApi(api!).getArtists({
|
||||
userId: user?.Id,
|
||||
parentId: libraryId,
|
||||
sortBy: ["SortName"],
|
||||
sortOrder: ["Ascending"],
|
||||
fields: ["PrimaryImageAspectRatio", "SortName"],
|
||||
imageTypeLimit: 1,
|
||||
enableImageTypes: ["Primary", "Backdrop", "Banner", "Thumb"],
|
||||
limit: ITEMS_PER_PAGE,
|
||||
startIndex: pageParam,
|
||||
});
|
||||
return {
|
||||
items: response.data.Items || [],
|
||||
totalCount: response.data.TotalRecordCount || 0,
|
||||
startIndex: pageParam,
|
||||
};
|
||||
},
|
||||
getNextPageParam: (lastPage) => {
|
||||
const nextStart = lastPage.startIndex + ITEMS_PER_PAGE;
|
||||
return nextStart < lastPage.totalCount ? nextStart : undefined;
|
||||
},
|
||||
initialPageParam: 0,
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
const artists = useMemo(() => {
|
||||
return data?.pages.flatMap((page) => page.items) || [];
|
||||
}, [data]);
|
||||
|
||||
const numColumns = 3;
|
||||
const screenWidth = Dimensions.get("window").width;
|
||||
const gap = 12;
|
||||
const padding = 16;
|
||||
const itemWidth =
|
||||
(screenWidth - padding * 2 - gap * (numColumns - 1)) / numColumns;
|
||||
|
||||
const handleEndReached = useCallback(() => {
|
||||
if (hasNextPage && !isFetchingNextPage) {
|
||||
fetchNextPage();
|
||||
}
|
||||
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
||||
|
||||
if (!api || !user?.Id) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!libraryId) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Missing music library id.
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Failed to load artists: {(error as Error)?.message || "Unknown error"}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (artists.length === 0) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.no_artists")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={artists}
|
||||
numColumns={numColumns}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
paddingTop: 16,
|
||||
paddingHorizontal: padding,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={false}
|
||||
onRefresh={refetch}
|
||||
tintColor='#9334E9'
|
||||
/>
|
||||
}
|
||||
onEndReached={handleEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
renderItem={({ item, index }) => (
|
||||
<View
|
||||
style={{
|
||||
width: itemWidth,
|
||||
marginRight: index % numColumns !== numColumns - 1 ? gap : 0,
|
||||
marginBottom: gap,
|
||||
}}
|
||||
>
|
||||
<MusicArtistCard artist={item} size={itemWidth} />
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
ListFooterComponent={
|
||||
isFetchingNextPage ? (
|
||||
<View className='py-4'>
|
||||
<Loader />
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
170
app/(auth)/(tabs)/(libraries)/music/[libraryId]/playlists.tsx
Normal file
170
app/(auth)/(tabs)/(libraries)/music/[libraryId]/playlists.tsx
Normal file
@@ -0,0 +1,170 @@
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useRoute } from "@react-navigation/native";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useInfiniteQuery } from "@tanstack/react-query";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Dimensions, RefreshControl, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicPlaylistCard } from "@/components/music/MusicPlaylistCard";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
|
||||
const ITEMS_PER_PAGE = 40;
|
||||
|
||||
export default function PlaylistsScreen() {
|
||||
const localParams = useLocalSearchParams<{ libraryId?: string | string[] }>();
|
||||
const route = useRoute<any>();
|
||||
const libraryId =
|
||||
(Array.isArray(localParams.libraryId)
|
||||
? localParams.libraryId[0]
|
||||
: localParams.libraryId) ?? route?.params?.libraryId;
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isReady = Boolean(api && user?.Id && libraryId);
|
||||
|
||||
const {
|
||||
data,
|
||||
isLoading,
|
||||
isError,
|
||||
error,
|
||||
fetchNextPage,
|
||||
hasNextPage,
|
||||
isFetchingNextPage,
|
||||
refetch,
|
||||
} = useInfiniteQuery({
|
||||
queryKey: ["music-playlists", libraryId, user?.Id],
|
||||
queryFn: async ({ pageParam = 0 }) => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: libraryId,
|
||||
includeItemTypes: ["Playlist"],
|
||||
sortBy: ["SortName"],
|
||||
sortOrder: ["Ascending"],
|
||||
limit: ITEMS_PER_PAGE,
|
||||
startIndex: pageParam,
|
||||
recursive: true,
|
||||
mediaTypes: ["Audio"],
|
||||
});
|
||||
return {
|
||||
items: response.data.Items || [],
|
||||
totalCount: response.data.TotalRecordCount || 0,
|
||||
startIndex: pageParam,
|
||||
};
|
||||
},
|
||||
getNextPageParam: (lastPage) => {
|
||||
const nextStart = lastPage.startIndex + ITEMS_PER_PAGE;
|
||||
return nextStart < lastPage.totalCount ? nextStart : undefined;
|
||||
},
|
||||
initialPageParam: 0,
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
const playlists = useMemo(() => {
|
||||
return data?.pages.flatMap((page) => page.items) || [];
|
||||
}, [data]);
|
||||
|
||||
const numColumns = 2;
|
||||
const screenWidth = Dimensions.get("window").width;
|
||||
const gap = 12;
|
||||
const padding = 16;
|
||||
const itemWidth =
|
||||
(screenWidth - padding * 2 - gap * (numColumns - 1)) / numColumns;
|
||||
|
||||
const handleEndReached = useCallback(() => {
|
||||
if (hasNextPage && !isFetchingNextPage) {
|
||||
fetchNextPage();
|
||||
}
|
||||
}, [hasNextPage, isFetchingNextPage, fetchNextPage]);
|
||||
|
||||
if (!api || !user?.Id) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!libraryId) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Missing music library id.
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isError) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Failed to load playlists:{" "}
|
||||
{(error as Error)?.message || "Unknown error"}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (playlists.length === 0) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.no_playlists")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={playlists}
|
||||
numColumns={numColumns}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
paddingTop: 16,
|
||||
paddingHorizontal: padding,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={false}
|
||||
onRefresh={refetch}
|
||||
tintColor='#9334E9'
|
||||
/>
|
||||
}
|
||||
onEndReached={handleEndReached}
|
||||
onEndReachedThreshold={0.5}
|
||||
renderItem={({ item, index }) => (
|
||||
<View
|
||||
style={{
|
||||
width: itemWidth,
|
||||
marginRight: index % numColumns === 0 ? gap : 0,
|
||||
marginBottom: gap,
|
||||
}}
|
||||
>
|
||||
<MusicPlaylistCard playlist={item} width={itemWidth} />
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
ListFooterComponent={
|
||||
isFetchingNextPage ? (
|
||||
<View className='py-4'>
|
||||
<Loader />
|
||||
</View>
|
||||
) : null
|
||||
}
|
||||
/>
|
||||
);
|
||||
}
|
||||
286
app/(auth)/(tabs)/(libraries)/music/[libraryId]/suggestions.tsx
Normal file
286
app/(auth)/(tabs)/(libraries)/music/[libraryId]/suggestions.tsx
Normal file
@@ -0,0 +1,286 @@
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { getItemsApi } from "@jellyfin/sdk/lib/utils/api";
|
||||
import { useRoute } from "@react-navigation/native";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useQuery } from "@tanstack/react-query";
|
||||
import { useLocalSearchParams } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import { useCallback, useMemo } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { RefreshControl, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { HorizontalScroll } from "@/components/common/HorizontalScroll";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { MusicAlbumCard } from "@/components/music/MusicAlbumCard";
|
||||
import { MusicTrackItem } from "@/components/music/MusicTrackItem";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { writeDebugLog } from "@/utils/log";
|
||||
|
||||
export default function SuggestionsScreen() {
|
||||
const localParams = useLocalSearchParams<{ libraryId?: string | string[] }>();
|
||||
const route = useRoute<any>();
|
||||
const libraryId =
|
||||
(Array.isArray(localParams.libraryId)
|
||||
? localParams.libraryId[0]
|
||||
: localParams.libraryId) ?? route?.params?.libraryId;
|
||||
const [api] = useAtom(apiAtom);
|
||||
const [user] = useAtom(userAtom);
|
||||
const insets = useSafeAreaInsets();
|
||||
const { t } = useTranslation();
|
||||
|
||||
const isReady = Boolean(api && user?.Id && libraryId);
|
||||
|
||||
writeDebugLog("Music suggestions params", {
|
||||
libraryId,
|
||||
localParams,
|
||||
routeParams: route?.params,
|
||||
isReady,
|
||||
});
|
||||
|
||||
// Latest audio - uses the same endpoint as web: /Users/{userId}/Items/Latest
|
||||
// This returns the most recently added albums
|
||||
const {
|
||||
data: latestAlbums,
|
||||
isLoading: loadingLatest,
|
||||
isError: isLatestError,
|
||||
error: latestError,
|
||||
refetch: refetchLatest,
|
||||
} = useQuery({
|
||||
queryKey: ["music-latest", libraryId, user?.Id],
|
||||
queryFn: async () => {
|
||||
// Prefer the exact endpoint the Web client calls (HAR):
|
||||
// /Users/{userId}/Items/Latest?IncludeItemTypes=Audio&ParentId=...
|
||||
// IMPORTANT: must use api.get(...) (not axiosInstance.get(fullUrl)) so the auth header is attached.
|
||||
const res = await api!.get<BaseItemDto[]>(
|
||||
`/Users/${user!.Id}/Items/Latest`,
|
||||
{
|
||||
params: {
|
||||
IncludeItemTypes: "Audio",
|
||||
Limit: 20,
|
||||
Fields: "PrimaryImageAspectRatio",
|
||||
ParentId: libraryId,
|
||||
ImageTypeLimit: 1,
|
||||
EnableImageTypes: "Primary,Backdrop,Banner,Thumb",
|
||||
EnableTotalRecordCount: false,
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
if (Array.isArray(res.data) && res.data.length > 0) {
|
||||
return res.data;
|
||||
}
|
||||
|
||||
// Fallback: ask for albums directly via /Items (more reliable across server variants)
|
||||
const fallback = await getItemsApi(api!).getItems({
|
||||
userId: user!.Id,
|
||||
parentId: libraryId,
|
||||
includeItemTypes: ["MusicAlbum"],
|
||||
sortBy: ["DateCreated"],
|
||||
sortOrder: ["Descending"],
|
||||
limit: 20,
|
||||
recursive: true,
|
||||
fields: ["PrimaryImageAspectRatio", "SortName"],
|
||||
imageTypeLimit: 1,
|
||||
enableImageTypes: ["Primary", "Backdrop", "Banner", "Thumb"],
|
||||
enableTotalRecordCount: false,
|
||||
});
|
||||
return fallback.data.Items || [];
|
||||
},
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
// Recently played - matches web: SortBy=DatePlayed, Filters=IsPlayed
|
||||
const {
|
||||
data: recentlyPlayed,
|
||||
isLoading: loadingRecentlyPlayed,
|
||||
isError: isRecentlyPlayedError,
|
||||
error: recentlyPlayedError,
|
||||
refetch: refetchRecentlyPlayed,
|
||||
} = useQuery({
|
||||
queryKey: ["music-recently-played", libraryId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: libraryId,
|
||||
includeItemTypes: ["Audio"],
|
||||
sortBy: ["DatePlayed"],
|
||||
sortOrder: ["Descending"],
|
||||
limit: 10,
|
||||
recursive: true,
|
||||
fields: ["PrimaryImageAspectRatio", "SortName"],
|
||||
filters: ["IsPlayed"],
|
||||
imageTypeLimit: 1,
|
||||
enableImageTypes: ["Primary", "Backdrop", "Banner", "Thumb"],
|
||||
enableTotalRecordCount: false,
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
// Frequently played - matches web: SortBy=PlayCount, Filters=IsPlayed
|
||||
const {
|
||||
data: frequentlyPlayed,
|
||||
isLoading: loadingFrequent,
|
||||
isError: isFrequentError,
|
||||
error: frequentError,
|
||||
refetch: refetchFrequent,
|
||||
} = useQuery({
|
||||
queryKey: ["music-frequently-played", libraryId, user?.Id],
|
||||
queryFn: async () => {
|
||||
const response = await getItemsApi(api!).getItems({
|
||||
userId: user?.Id,
|
||||
parentId: libraryId,
|
||||
includeItemTypes: ["Audio"],
|
||||
sortBy: ["PlayCount"],
|
||||
sortOrder: ["Descending"],
|
||||
limit: 10,
|
||||
recursive: true,
|
||||
fields: ["PrimaryImageAspectRatio", "SortName"],
|
||||
filters: ["IsPlayed"],
|
||||
imageTypeLimit: 1,
|
||||
enableImageTypes: ["Primary", "Backdrop", "Banner", "Thumb"],
|
||||
enableTotalRecordCount: false,
|
||||
});
|
||||
return response.data.Items || [];
|
||||
},
|
||||
enabled: isReady,
|
||||
});
|
||||
|
||||
const isLoading = loadingLatest || loadingRecentlyPlayed || loadingFrequent;
|
||||
|
||||
const handleRefresh = useCallback(() => {
|
||||
refetchLatest();
|
||||
refetchRecentlyPlayed();
|
||||
refetchFrequent();
|
||||
}, [refetchLatest, refetchRecentlyPlayed, refetchFrequent]);
|
||||
|
||||
const sections = useMemo(() => {
|
||||
const result: {
|
||||
title: string;
|
||||
data: BaseItemDto[];
|
||||
type: "albums" | "tracks";
|
||||
}[] = [];
|
||||
|
||||
// Latest albums section
|
||||
if (latestAlbums && latestAlbums.length > 0) {
|
||||
result.push({
|
||||
title: t("music.recently_added"),
|
||||
data: latestAlbums,
|
||||
type: "albums",
|
||||
});
|
||||
}
|
||||
|
||||
// Recently played tracks
|
||||
if (recentlyPlayed && recentlyPlayed.length > 0) {
|
||||
result.push({
|
||||
title: t("music.recently_played"),
|
||||
data: recentlyPlayed,
|
||||
type: "tracks",
|
||||
});
|
||||
}
|
||||
|
||||
// Frequently played tracks
|
||||
if (frequentlyPlayed && frequentlyPlayed.length > 0) {
|
||||
result.push({
|
||||
title: t("music.frequently_played"),
|
||||
data: frequentlyPlayed,
|
||||
type: "tracks",
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [latestAlbums, frequentlyPlayed, recentlyPlayed, t]);
|
||||
|
||||
if (!api || !user?.Id) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!libraryId) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Missing music library id.
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Loader />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (isLatestError || isRecentlyPlayedError || isFrequentError) {
|
||||
const msg =
|
||||
(latestError as Error | undefined)?.message ||
|
||||
(recentlyPlayedError as Error | undefined)?.message ||
|
||||
(frequentError as Error | undefined)?.message ||
|
||||
"Unknown error";
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black px-6'>
|
||||
<Text className='text-neutral-500 text-center'>
|
||||
Failed to load music: {msg}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (sections.length === 0) {
|
||||
return (
|
||||
<View className='flex-1 justify-center items-center bg-black'>
|
||||
<Text className='text-neutral-500'>{t("music.no_suggestions")}</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={sections}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 100,
|
||||
paddingTop: 16,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl
|
||||
refreshing={false}
|
||||
onRefresh={handleRefresh}
|
||||
tintColor='#9334E9'
|
||||
/>
|
||||
}
|
||||
renderItem={({ item: section }) => (
|
||||
<View className='mb-6'>
|
||||
<Text className='text-lg font-bold px-4 mb-3'>{section.title}</Text>
|
||||
{section.type === "albums" ? (
|
||||
<HorizontalScroll
|
||||
data={section.data}
|
||||
height={200}
|
||||
keyExtractor={(item) => item.Id!}
|
||||
renderItem={(item) => <MusicAlbumCard album={item} />}
|
||||
/>
|
||||
) : (
|
||||
<View className='px-4'>
|
||||
{section.data.slice(0, 5).map((track, index, _tracks) => (
|
||||
<MusicTrackItem
|
||||
key={track.Id}
|
||||
track={track}
|
||||
index={index + 1}
|
||||
queue={section.data}
|
||||
/>
|
||||
))}
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
)}
|
||||
keyExtractor={(item) => item.title}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -39,6 +39,7 @@ import { useJellyseerr } from "@/hooks/useJellyseerr";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import { eventBus } from "@/utils/eventBus";
|
||||
import { createStreamystatsApi } from "@/utils/streamystats";
|
||||
|
||||
type SearchType = "Library" | "Discover";
|
||||
|
||||
@@ -117,6 +118,54 @@ export default function search() {
|
||||
|
||||
return (searchApi.data.Items as BaseItemDto[]) || [];
|
||||
}
|
||||
|
||||
if (searchEngine === "Streamystats") {
|
||||
if (!settings?.streamyStatsServerUrl || !api.accessToken) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const streamyStatsApi = createStreamystatsApi({
|
||||
serverUrl: settings.streamyStatsServerUrl,
|
||||
jellyfinToken: api.accessToken,
|
||||
});
|
||||
|
||||
const typeMap: Record<BaseItemKind, string> = {
|
||||
Movie: "movies",
|
||||
Series: "series",
|
||||
Episode: "episodes",
|
||||
Person: "actors",
|
||||
BoxSet: "movies",
|
||||
Audio: "audio",
|
||||
} as Record<BaseItemKind, string>;
|
||||
|
||||
const searchType = types.length === 1 ? typeMap[types[0]] : "media";
|
||||
const response = await streamyStatsApi.searchIds(
|
||||
query,
|
||||
searchType as "movies" | "series" | "episodes" | "actors" | "media",
|
||||
10,
|
||||
);
|
||||
|
||||
const allIds: string[] = [
|
||||
...(response.data.movies || []),
|
||||
...(response.data.series || []),
|
||||
...(response.data.episodes || []),
|
||||
...(response.data.actors || []),
|
||||
...(response.data.audio || []),
|
||||
];
|
||||
|
||||
if (!allIds.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const itemsResponse = await getItemsApi(api).getItems({
|
||||
ids: allIds,
|
||||
enableImageTypes: ["Primary", "Backdrop", "Thumb"],
|
||||
});
|
||||
|
||||
return (itemsResponse.data.Items as BaseItemDto[]) || [];
|
||||
}
|
||||
|
||||
// Marlin search
|
||||
if (!settings?.marlinServerUrl) {
|
||||
return [];
|
||||
}
|
||||
@@ -141,12 +190,11 @@ export default function search() {
|
||||
});
|
||||
|
||||
return (response2.data.Items as BaseItemDto[]) || [];
|
||||
} catch (error) {
|
||||
console.error("Error during search:", error);
|
||||
return []; // Ensure an empty array is returned in case of an error
|
||||
} catch (_error) {
|
||||
return [];
|
||||
}
|
||||
},
|
||||
[api, searchEngine, settings],
|
||||
[api, searchEngine, settings, user?.Id],
|
||||
);
|
||||
|
||||
type HeaderSearchBarRef = {
|
||||
|
||||
297
app/(auth)/(tabs)/(watchlists)/[watchlistId].tsx
Normal file
297
app/(auth)/(tabs)/(watchlists)/[watchlistId].tsx
Normal file
@@ -0,0 +1,297 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useLocalSearchParams, useNavigation, useRouter } from "expo-router";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
RefreshControl,
|
||||
TouchableOpacity,
|
||||
useWindowDimensions,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { HeaderBackButton } from "@/components/common/HeaderBackButton";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { TouchableItemRouter } from "@/components/common/TouchableItemRouter";
|
||||
import { ItemCardText } from "@/components/ItemCardText";
|
||||
import { ItemPoster } from "@/components/posters/ItemPoster";
|
||||
import { useOrientation } from "@/hooks/useOrientation";
|
||||
import {
|
||||
useDeleteWatchlist,
|
||||
useRemoveFromWatchlist,
|
||||
} from "@/hooks/useWatchlistMutations";
|
||||
import {
|
||||
useWatchlistDetailQuery,
|
||||
useWatchlistItemsQuery,
|
||||
} from "@/hooks/useWatchlists";
|
||||
import * as ScreenOrientation from "@/packages/expo-screen-orientation";
|
||||
import { userAtom } from "@/providers/JellyfinProvider";
|
||||
|
||||
export default function WatchlistDetailScreen() {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const navigation = useNavigation();
|
||||
const insets = useSafeAreaInsets();
|
||||
const { watchlistId } = useLocalSearchParams<{ watchlistId: string }>();
|
||||
const user = useAtomValue(userAtom);
|
||||
const { width: screenWidth } = useWindowDimensions();
|
||||
const { orientation } = useOrientation();
|
||||
|
||||
const watchlistIdNum = watchlistId
|
||||
? Number.parseInt(watchlistId, 10)
|
||||
: undefined;
|
||||
|
||||
const nrOfCols = useMemo(() => {
|
||||
if (screenWidth < 300) return 2;
|
||||
if (screenWidth < 500) return 3;
|
||||
if (screenWidth < 800) return 5;
|
||||
if (screenWidth < 1000) return 6;
|
||||
if (screenWidth < 1500) return 7;
|
||||
return 6;
|
||||
}, [screenWidth]);
|
||||
|
||||
const {
|
||||
data: watchlist,
|
||||
isLoading: watchlistLoading,
|
||||
refetch: refetchWatchlist,
|
||||
} = useWatchlistDetailQuery(watchlistIdNum);
|
||||
|
||||
const {
|
||||
data: items,
|
||||
isLoading: itemsLoading,
|
||||
refetch: refetchItems,
|
||||
} = useWatchlistItemsQuery(watchlistIdNum);
|
||||
|
||||
const deleteWatchlist = useDeleteWatchlist();
|
||||
const removeFromWatchlist = useRemoveFromWatchlist();
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const isOwner = useMemo(
|
||||
() => watchlist?.userId === user?.Id,
|
||||
[watchlist?.userId, user?.Id],
|
||||
);
|
||||
|
||||
// Set up header
|
||||
useEffect(() => {
|
||||
navigation.setOptions({
|
||||
headerTitle: watchlist?.name || "",
|
||||
headerLeft: () => <HeaderBackButton />,
|
||||
headerRight: isOwner
|
||||
? () => (
|
||||
<View className='flex-row gap-2'>
|
||||
<TouchableOpacity
|
||||
onPress={() =>
|
||||
router.push(`/(auth)/(tabs)/(watchlists)/edit/${watchlistId}`)
|
||||
}
|
||||
className='p-2'
|
||||
>
|
||||
<Ionicons name='pencil' size={20} color='white' />
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity onPress={handleDelete} className='p-2'>
|
||||
<Ionicons name='trash-outline' size={20} color='#ef4444' />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
)
|
||||
: undefined,
|
||||
});
|
||||
}, [navigation, watchlist?.name, isOwner, watchlistId]);
|
||||
|
||||
const handleRefresh = useCallback(async () => {
|
||||
setRefreshing(true);
|
||||
await Promise.all([refetchWatchlist(), refetchItems()]);
|
||||
setRefreshing(false);
|
||||
}, [refetchWatchlist, refetchItems]);
|
||||
|
||||
const handleDelete = useCallback(() => {
|
||||
Alert.alert(
|
||||
t("watchlists.delete_confirm_title"),
|
||||
t("watchlists.delete_confirm_message", { name: watchlist?.name }),
|
||||
[
|
||||
{ text: t("watchlists.cancel_button"), style: "cancel" },
|
||||
{
|
||||
text: t("watchlists.delete_button"),
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
if (watchlistIdNum) {
|
||||
await deleteWatchlist.mutateAsync(watchlistIdNum);
|
||||
router.back();
|
||||
}
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
}, [deleteWatchlist, watchlistIdNum, watchlist?.name, router, t]);
|
||||
|
||||
const handleRemoveItem = useCallback(
|
||||
(item: BaseItemDto) => {
|
||||
if (!watchlistIdNum || !item.Id) return;
|
||||
|
||||
Alert.alert(
|
||||
t("watchlists.remove_item_title"),
|
||||
t("watchlists.remove_item_message", { name: item.Name }),
|
||||
[
|
||||
{ text: t("watchlists.cancel_button"), style: "cancel" },
|
||||
{
|
||||
text: t("watchlists.remove_button"),
|
||||
style: "destructive",
|
||||
onPress: async () => {
|
||||
await removeFromWatchlist.mutateAsync({
|
||||
watchlistId: watchlistIdNum,
|
||||
itemId: item.Id!,
|
||||
watchlistName: watchlist?.name,
|
||||
});
|
||||
},
|
||||
},
|
||||
],
|
||||
);
|
||||
},
|
||||
[removeFromWatchlist, watchlistIdNum, watchlist?.name, t],
|
||||
);
|
||||
|
||||
const renderItem = useCallback(
|
||||
({ item, index }: { item: BaseItemDto; index: number }) => (
|
||||
<TouchableItemRouter
|
||||
key={item.Id}
|
||||
style={{
|
||||
width: "100%",
|
||||
marginBottom: 4,
|
||||
}}
|
||||
item={item}
|
||||
onLongPress={isOwner ? () => handleRemoveItem(item) : undefined}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
alignSelf:
|
||||
orientation === ScreenOrientation.OrientationLock.PORTRAIT_UP
|
||||
? index % nrOfCols === 0
|
||||
? "flex-end"
|
||||
: (index + 1) % nrOfCols === 0
|
||||
? "flex-start"
|
||||
: "center"
|
||||
: "center",
|
||||
width: "89%",
|
||||
}}
|
||||
>
|
||||
<ItemPoster item={item} />
|
||||
<ItemCardText item={item} />
|
||||
</View>
|
||||
</TouchableItemRouter>
|
||||
),
|
||||
[isOwner, handleRemoveItem, orientation, nrOfCols],
|
||||
);
|
||||
|
||||
const ListHeader = useMemo(
|
||||
() =>
|
||||
watchlist ? (
|
||||
<View className='px-4 pt-4 pb-6 mb-4 border-b border-neutral-800'>
|
||||
{watchlist.description && (
|
||||
<Text className='text-neutral-400 mb-2'>
|
||||
{watchlist.description}
|
||||
</Text>
|
||||
)}
|
||||
<View className='flex-row items-center gap-4'>
|
||||
<View className='flex-row items-center gap-1'>
|
||||
<Ionicons name='film-outline' size={14} color='#9ca3af' />
|
||||
<Text className='text-neutral-400 text-sm'>
|
||||
{items?.length ?? 0}{" "}
|
||||
{(items?.length ?? 0) === 1
|
||||
? t("watchlists.item")
|
||||
: t("watchlists.items")}
|
||||
</Text>
|
||||
</View>
|
||||
<View className='flex-row items-center gap-1'>
|
||||
<Ionicons
|
||||
name={
|
||||
watchlist.isPublic ? "globe-outline" : "lock-closed-outline"
|
||||
}
|
||||
size={14}
|
||||
color='#9ca3af'
|
||||
/>
|
||||
<Text className='text-neutral-400 text-sm'>
|
||||
{watchlist.isPublic
|
||||
? t("watchlists.public")
|
||||
: t("watchlists.private")}
|
||||
</Text>
|
||||
</View>
|
||||
{!isOwner && (
|
||||
<Text className='text-neutral-500 text-sm'>
|
||||
{t("watchlists.by_owner")}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
</View>
|
||||
) : null,
|
||||
[watchlist, items?.length, isOwner, t],
|
||||
);
|
||||
|
||||
const EmptyComponent = useMemo(
|
||||
() => (
|
||||
<View className='flex-1 items-center justify-center px-8 py-16'>
|
||||
<Ionicons name='film-outline' size={48} color='#4b5563' />
|
||||
<Text className='text-neutral-400 text-center mt-4'>
|
||||
{t("watchlists.empty_watchlist")}
|
||||
</Text>
|
||||
{isOwner && (
|
||||
<Text className='text-neutral-500 text-center mt-2 text-sm'>
|
||||
{t("watchlists.empty_watchlist_hint")}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
),
|
||||
[isOwner, t],
|
||||
);
|
||||
|
||||
const keyExtractor = useCallback((item: BaseItemDto) => item.Id || "", []);
|
||||
|
||||
if (watchlistLoading || itemsLoading) {
|
||||
return (
|
||||
<View className='flex-1 items-center justify-center'>
|
||||
<ActivityIndicator size='large' />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!watchlist) {
|
||||
return (
|
||||
<View className='flex-1 items-center justify-center px-8'>
|
||||
<Text className='text-lg text-neutral-400'>
|
||||
{t("watchlists.not_found")}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
key={orientation}
|
||||
data={items ?? []}
|
||||
numColumns={nrOfCols}
|
||||
contentInsetAdjustmentBehavior='automatic'
|
||||
ListHeaderComponent={ListHeader}
|
||||
ListEmptyComponent={EmptyComponent}
|
||||
extraData={[orientation, nrOfCols]}
|
||||
keyExtractor={keyExtractor}
|
||||
contentContainerStyle={{
|
||||
paddingBottom: 24,
|
||||
paddingLeft: insets.left,
|
||||
paddingRight: insets.right,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />
|
||||
}
|
||||
renderItem={renderItem}
|
||||
ItemSeparatorComponent={() => (
|
||||
<View
|
||||
style={{
|
||||
width: 10,
|
||||
height: 10,
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
74
app/(auth)/(tabs)/(watchlists)/_layout.tsx
Normal file
74
app/(auth)/(tabs)/(watchlists)/_layout.tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { Stack, useRouter } from "expo-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Platform, TouchableOpacity } from "react-native";
|
||||
import { nestedTabPageScreenOptions } from "@/components/stacks/NestedTabPageStack";
|
||||
import { useStreamystatsEnabled } from "@/hooks/useWatchlists";
|
||||
|
||||
export default function WatchlistsLayout() {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const streamystatsEnabled = useStreamystatsEnabled();
|
||||
|
||||
return (
|
||||
<Stack>
|
||||
<Stack.Screen
|
||||
name='index'
|
||||
options={{
|
||||
headerShown: !Platform.isTV,
|
||||
headerTitle: t("watchlists.title"),
|
||||
headerBlurEffect: "none",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
headerShadowVisible: false,
|
||||
headerRight: streamystatsEnabled
|
||||
? () => (
|
||||
<TouchableOpacity
|
||||
onPress={() =>
|
||||
router.push("/(auth)/(tabs)/(watchlists)/create")
|
||||
}
|
||||
className='p-1.5'
|
||||
>
|
||||
<Ionicons name='add' size={24} color='white' />
|
||||
</TouchableOpacity>
|
||||
)
|
||||
: undefined,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='[watchlistId]'
|
||||
options={{
|
||||
title: "",
|
||||
headerShown: true,
|
||||
headerBlurEffect: "none",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
headerShadowVisible: false,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='create'
|
||||
options={{
|
||||
title: t("watchlists.create_title"),
|
||||
presentation: "modal",
|
||||
headerShown: true,
|
||||
headerStyle: { backgroundColor: "#171717" },
|
||||
headerTintColor: "white",
|
||||
contentStyle: { backgroundColor: "#171717" },
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='edit/[watchlistId]'
|
||||
options={{
|
||||
title: t("watchlists.edit_title"),
|
||||
presentation: "modal",
|
||||
headerShown: true,
|
||||
headerStyle: { backgroundColor: "#171717" },
|
||||
headerTintColor: "white",
|
||||
contentStyle: { backgroundColor: "#171717" },
|
||||
}}
|
||||
/>
|
||||
{Object.entries(nestedTabPageScreenOptions).map(([name, options]) => (
|
||||
<Stack.Screen key={name} name={name} options={options} />
|
||||
))}
|
||||
</Stack>
|
||||
);
|
||||
}
|
||||
221
app/(auth)/(tabs)/(watchlists)/create.tsx
Normal file
221
app/(auth)/(tabs)/(watchlists)/create.tsx
Normal file
@@ -0,0 +1,221 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useRouter } from "expo-router";
|
||||
import { useCallback, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ScrollView,
|
||||
Switch,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Button } from "@/components/Button";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { useCreateWatchlist } from "@/hooks/useWatchlistMutations";
|
||||
import type {
|
||||
StreamystatsWatchlistAllowedItemType,
|
||||
StreamystatsWatchlistSortOrder,
|
||||
} from "@/utils/streamystats/types";
|
||||
|
||||
const ITEM_TYPES: Array<{
|
||||
value: StreamystatsWatchlistAllowedItemType;
|
||||
label: string;
|
||||
}> = [
|
||||
{ value: null, label: "All Types" },
|
||||
{ value: "Movie", label: "Movies Only" },
|
||||
{ value: "Series", label: "Series Only" },
|
||||
{ value: "Episode", label: "Episodes Only" },
|
||||
];
|
||||
|
||||
const SORT_OPTIONS: Array<{
|
||||
value: StreamystatsWatchlistSortOrder;
|
||||
label: string;
|
||||
}> = [
|
||||
{ value: "custom", label: "Custom Order" },
|
||||
{ value: "name", label: "Name" },
|
||||
{ value: "dateAdded", label: "Date Added" },
|
||||
{ value: "releaseDate", label: "Release Date" },
|
||||
];
|
||||
|
||||
export default function CreateWatchlistScreen() {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const createWatchlist = useCreateWatchlist();
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [isPublic, setIsPublic] = useState(false);
|
||||
const [allowedItemType, setAllowedItemType] =
|
||||
useState<StreamystatsWatchlistAllowedItemType>(null);
|
||||
const [defaultSortOrder, setDefaultSortOrder] =
|
||||
useState<StreamystatsWatchlistSortOrder>("custom");
|
||||
|
||||
const handleCreate = useCallback(async () => {
|
||||
if (!name.trim()) return;
|
||||
|
||||
try {
|
||||
await createWatchlist.mutateAsync({
|
||||
name: name.trim(),
|
||||
description: description.trim() || undefined,
|
||||
isPublic,
|
||||
allowedItemType,
|
||||
defaultSortOrder,
|
||||
});
|
||||
router.back();
|
||||
} catch {
|
||||
// Error handled by mutation
|
||||
}
|
||||
}, [
|
||||
name,
|
||||
description,
|
||||
isPublic,
|
||||
allowedItemType,
|
||||
defaultSortOrder,
|
||||
createWatchlist,
|
||||
router,
|
||||
]);
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
||||
className='flex-1'
|
||||
style={{ backgroundColor: "#171717" }}
|
||||
>
|
||||
<ScrollView
|
||||
className='flex-1'
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 20,
|
||||
}}
|
||||
keyboardShouldPersistTaps='handled'
|
||||
>
|
||||
{/* Name */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.name_label")} *
|
||||
</Text>
|
||||
<TextInput
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
placeholder={t("watchlists.name_placeholder")}
|
||||
placeholderTextColor='#6b7280'
|
||||
className='bg-neutral-800 text-white px-4 py-3 rounded-lg text-base'
|
||||
autoFocus
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Description */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.description_label")}
|
||||
</Text>
|
||||
<TextInput
|
||||
value={description}
|
||||
onChangeText={setDescription}
|
||||
placeholder={t("watchlists.description_placeholder")}
|
||||
placeholderTextColor='#6b7280'
|
||||
className='bg-neutral-800 text-white px-4 py-3 rounded-lg text-base'
|
||||
multiline
|
||||
numberOfLines={3}
|
||||
textAlignVertical='top'
|
||||
style={{ minHeight: 80 }}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Public Toggle */}
|
||||
<View className='px-4 py-4 flex-row items-center justify-between'>
|
||||
<View className='flex-1 mr-4'>
|
||||
<Text className='text-base font-medium text-white'>
|
||||
{t("watchlists.is_public_label")}
|
||||
</Text>
|
||||
<Text className='text-sm text-neutral-400 mt-1'>
|
||||
{t("watchlists.is_public_description")}
|
||||
</Text>
|
||||
</View>
|
||||
<Switch
|
||||
value={isPublic}
|
||||
onValueChange={setIsPublic}
|
||||
trackColor={{ false: "#374151", true: "#7c3aed" }}
|
||||
thumbColor={isPublic ? "#a78bfa" : "#9ca3af"}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Content Type */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.allowed_type_label")}
|
||||
</Text>
|
||||
<View className='flex-row flex-wrap gap-2'>
|
||||
{ITEM_TYPES.map((type) => (
|
||||
<TouchableOpacity
|
||||
key={type.value ?? "all"}
|
||||
onPress={() => setAllowedItemType(type.value)}
|
||||
className={`px-4 py-2 rounded-lg ${allowedItemType === type.value ? "bg-purple-600" : "bg-neutral-800"}`}
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
allowedItemType === type.value
|
||||
? "text-white font-medium"
|
||||
: "text-neutral-300"
|
||||
}
|
||||
>
|
||||
{type.label}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Sort Order */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.sort_order_label")}
|
||||
</Text>
|
||||
<View className='flex-row flex-wrap gap-2'>
|
||||
{SORT_OPTIONS.map((sort) => (
|
||||
<TouchableOpacity
|
||||
key={sort.value}
|
||||
onPress={() => setDefaultSortOrder(sort.value)}
|
||||
className={`px-4 py-2 rounded-lg ${defaultSortOrder === sort.value ? "bg-purple-600" : "bg-neutral-800"}`}
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
defaultSortOrder === sort.value
|
||||
? "text-white font-medium"
|
||||
: "text-neutral-300"
|
||||
}
|
||||
>
|
||||
{sort.label}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Create Button */}
|
||||
<View className='px-4 pt-4'>
|
||||
<Button
|
||||
onPress={handleCreate}
|
||||
disabled={!name.trim() || createWatchlist.isPending}
|
||||
className={`py-3 ${!name.trim() ? "opacity-50" : ""}`}
|
||||
>
|
||||
{createWatchlist.isPending ? (
|
||||
<ActivityIndicator color='white' />
|
||||
) : (
|
||||
<View className='flex-row items-center'>
|
||||
<Ionicons name='add' size={20} color='white' />
|
||||
<Text className='text-white font-semibold text-base'>
|
||||
{t("watchlists.create_button")}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
);
|
||||
}
|
||||
273
app/(auth)/(tabs)/(watchlists)/edit/[watchlistId].tsx
Normal file
273
app/(auth)/(tabs)/(watchlists)/edit/[watchlistId].tsx
Normal file
@@ -0,0 +1,273 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||
import { useCallback, useEffect, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
KeyboardAvoidingView,
|
||||
Platform,
|
||||
ScrollView,
|
||||
Switch,
|
||||
TextInput,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Button } from "@/components/Button";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { useUpdateWatchlist } from "@/hooks/useWatchlistMutations";
|
||||
import { useWatchlistDetailQuery } from "@/hooks/useWatchlists";
|
||||
import type {
|
||||
StreamystatsWatchlistAllowedItemType,
|
||||
StreamystatsWatchlistSortOrder,
|
||||
} from "@/utils/streamystats/types";
|
||||
|
||||
const ITEM_TYPES: Array<{
|
||||
value: StreamystatsWatchlistAllowedItemType;
|
||||
label: string;
|
||||
}> = [
|
||||
{ value: null, label: "All Types" },
|
||||
{ value: "Movie", label: "Movies Only" },
|
||||
{ value: "Series", label: "Series Only" },
|
||||
{ value: "Episode", label: "Episodes Only" },
|
||||
];
|
||||
|
||||
const SORT_OPTIONS: Array<{
|
||||
value: StreamystatsWatchlistSortOrder;
|
||||
label: string;
|
||||
}> = [
|
||||
{ value: "custom", label: "Custom Order" },
|
||||
{ value: "name", label: "Name" },
|
||||
{ value: "dateAdded", label: "Date Added" },
|
||||
{ value: "releaseDate", label: "Release Date" },
|
||||
];
|
||||
|
||||
export default function EditWatchlistScreen() {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const { watchlistId } = useLocalSearchParams<{ watchlistId: string }>();
|
||||
const watchlistIdNum = watchlistId
|
||||
? Number.parseInt(watchlistId, 10)
|
||||
: undefined;
|
||||
|
||||
const { data: watchlist, isLoading } =
|
||||
useWatchlistDetailQuery(watchlistIdNum);
|
||||
const updateWatchlist = useUpdateWatchlist();
|
||||
|
||||
const [name, setName] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [isPublic, setIsPublic] = useState(false);
|
||||
const [allowedItemType, setAllowedItemType] =
|
||||
useState<StreamystatsWatchlistAllowedItemType>(null);
|
||||
const [defaultSortOrder, setDefaultSortOrder] =
|
||||
useState<StreamystatsWatchlistSortOrder>("custom");
|
||||
|
||||
// Initialize form with watchlist data
|
||||
useEffect(() => {
|
||||
if (watchlist) {
|
||||
setName(watchlist.name);
|
||||
setDescription(watchlist.description ?? "");
|
||||
setIsPublic(watchlist.isPublic);
|
||||
setAllowedItemType(
|
||||
(watchlist.allowedItemType as StreamystatsWatchlistAllowedItemType) ??
|
||||
null,
|
||||
);
|
||||
setDefaultSortOrder(
|
||||
(watchlist.defaultSortOrder as StreamystatsWatchlistSortOrder) ??
|
||||
"custom",
|
||||
);
|
||||
}
|
||||
}, [watchlist]);
|
||||
|
||||
const handleSave = useCallback(async () => {
|
||||
if (!name.trim() || !watchlistIdNum) return;
|
||||
|
||||
try {
|
||||
await updateWatchlist.mutateAsync({
|
||||
watchlistId: watchlistIdNum,
|
||||
data: {
|
||||
name: name.trim(),
|
||||
description: description.trim() || undefined,
|
||||
isPublic,
|
||||
allowedItemType,
|
||||
defaultSortOrder,
|
||||
},
|
||||
});
|
||||
router.back();
|
||||
} catch {
|
||||
// Error handled by mutation
|
||||
}
|
||||
}, [
|
||||
name,
|
||||
description,
|
||||
isPublic,
|
||||
allowedItemType,
|
||||
defaultSortOrder,
|
||||
watchlistIdNum,
|
||||
updateWatchlist,
|
||||
router,
|
||||
]);
|
||||
|
||||
if (isLoading) {
|
||||
return (
|
||||
<View
|
||||
className='flex-1 items-center justify-center'
|
||||
style={{ backgroundColor: "#171717" }}
|
||||
>
|
||||
<ActivityIndicator size='large' />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
if (!watchlist) {
|
||||
return (
|
||||
<View
|
||||
className='flex-1 items-center justify-center px-8'
|
||||
style={{ backgroundColor: "#171717" }}
|
||||
>
|
||||
<Text className='text-lg text-neutral-400'>
|
||||
{t("watchlists.not_found")}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<KeyboardAvoidingView
|
||||
behavior={Platform.OS === "ios" ? "padding" : "height"}
|
||||
className='flex-1'
|
||||
style={{ backgroundColor: "#171717" }}
|
||||
>
|
||||
<ScrollView
|
||||
className='flex-1'
|
||||
contentContainerStyle={{
|
||||
paddingBottom: insets.bottom + 20,
|
||||
}}
|
||||
keyboardShouldPersistTaps='handled'
|
||||
>
|
||||
{/* Name */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.name_label")} *
|
||||
</Text>
|
||||
<TextInput
|
||||
value={name}
|
||||
onChangeText={setName}
|
||||
placeholder={t("watchlists.name_placeholder")}
|
||||
placeholderTextColor='#6b7280'
|
||||
className='bg-neutral-800 text-white px-4 py-3 rounded-lg text-base'
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Description */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.description_label")}
|
||||
</Text>
|
||||
<TextInput
|
||||
value={description}
|
||||
onChangeText={setDescription}
|
||||
placeholder={t("watchlists.description_placeholder")}
|
||||
placeholderTextColor='#6b7280'
|
||||
className='bg-neutral-800 text-white px-4 py-3 rounded-lg text-base'
|
||||
multiline
|
||||
numberOfLines={3}
|
||||
textAlignVertical='top'
|
||||
style={{ minHeight: 80 }}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Public Toggle */}
|
||||
<View className='px-4 py-4 flex-row items-center justify-between'>
|
||||
<View className='flex-1 mr-4'>
|
||||
<Text className='text-base font-medium text-white'>
|
||||
{t("watchlists.is_public_label")}
|
||||
</Text>
|
||||
<Text className='text-sm text-neutral-400 mt-1'>
|
||||
{t("watchlists.is_public_description")}
|
||||
</Text>
|
||||
</View>
|
||||
<Switch
|
||||
value={isPublic}
|
||||
onValueChange={setIsPublic}
|
||||
trackColor={{ false: "#374151", true: "#7c3aed" }}
|
||||
thumbColor={isPublic ? "#a78bfa" : "#9ca3af"}
|
||||
/>
|
||||
</View>
|
||||
|
||||
{/* Content Type */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.allowed_type_label")}
|
||||
</Text>
|
||||
<View className='flex-row flex-wrap gap-2'>
|
||||
{ITEM_TYPES.map((type) => (
|
||||
<TouchableOpacity
|
||||
key={type.value ?? "all"}
|
||||
onPress={() => setAllowedItemType(type.value)}
|
||||
className={`px-4 py-2 rounded-lg ${allowedItemType === type.value ? "bg-purple-600" : "bg-neutral-800"}`}
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
allowedItemType === type.value
|
||||
? "text-white font-medium"
|
||||
: "text-neutral-300"
|
||||
}
|
||||
>
|
||||
{type.label}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Sort Order */}
|
||||
<View className='px-4 py-4'>
|
||||
<Text className='text-sm font-medium text-neutral-400 mb-2'>
|
||||
{t("watchlists.sort_order_label")}
|
||||
</Text>
|
||||
<View className='flex-row flex-wrap gap-2'>
|
||||
{SORT_OPTIONS.map((sort) => (
|
||||
<TouchableOpacity
|
||||
key={sort.value}
|
||||
onPress={() => setDefaultSortOrder(sort.value)}
|
||||
className={`px-4 py-2 rounded-lg ${defaultSortOrder === sort.value ? "bg-purple-600" : "bg-neutral-800"}`}
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
defaultSortOrder === sort.value
|
||||
? "text-white font-medium"
|
||||
: "text-neutral-300"
|
||||
}
|
||||
>
|
||||
{sort.label}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
))}
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Save Button */}
|
||||
<View className='px-4 pt-4'>
|
||||
<Button
|
||||
onPress={handleSave}
|
||||
disabled={!name.trim() || updateWatchlist.isPending}
|
||||
className={`py-3 ${!name.trim() ? "opacity-50" : ""}`}
|
||||
>
|
||||
{updateWatchlist.isPending ? (
|
||||
<ActivityIndicator color='white' />
|
||||
) : (
|
||||
<View className='flex-row items-center'>
|
||||
<Ionicons name='checkmark' size={20} color='white' />
|
||||
<Text className='text-white font-semibold text-base'>
|
||||
{t("watchlists.save_button")}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</Button>
|
||||
</View>
|
||||
</ScrollView>
|
||||
</KeyboardAvoidingView>
|
||||
);
|
||||
}
|
||||
239
app/(auth)/(tabs)/(watchlists)/index.tsx
Normal file
239
app/(auth)/(tabs)/(watchlists)/index.tsx
Normal file
@@ -0,0 +1,239 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { FlashList } from "@shopify/flash-list";
|
||||
import { useRouter } from "expo-router";
|
||||
import { useAtomValue } from "jotai";
|
||||
import { useCallback, useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Platform, RefreshControl, TouchableOpacity, View } from "react-native";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Button } from "@/components/Button";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import {
|
||||
useStreamystatsEnabled,
|
||||
useWatchlistsQuery,
|
||||
} from "@/hooks/useWatchlists";
|
||||
import { userAtom } from "@/providers/JellyfinProvider";
|
||||
import type { StreamystatsWatchlist } from "@/utils/streamystats/types";
|
||||
|
||||
interface WatchlistCardProps {
|
||||
watchlist: StreamystatsWatchlist;
|
||||
isOwner: boolean;
|
||||
onPress: () => void;
|
||||
}
|
||||
|
||||
const WatchlistCard: React.FC<WatchlistCardProps> = ({
|
||||
watchlist,
|
||||
isOwner,
|
||||
onPress,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onPress={onPress}
|
||||
className='bg-neutral-900 rounded-xl p-4 mx-4 mb-3'
|
||||
activeOpacity={0.7}
|
||||
>
|
||||
<View className='flex-row items-center justify-between mb-2'>
|
||||
<Text className='text-lg font-semibold flex-1' numberOfLines={1}>
|
||||
{watchlist.name}
|
||||
</Text>
|
||||
<View className='flex-row items-center gap-2'>
|
||||
{isOwner && (
|
||||
<View className='bg-purple-600/20 px-2 py-1 rounded'>
|
||||
<Text className='text-purple-400 text-xs'>
|
||||
{t("watchlists.you")}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
<Ionicons
|
||||
name={watchlist.isPublic ? "globe-outline" : "lock-closed-outline"}
|
||||
size={16}
|
||||
color='#9ca3af'
|
||||
/>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{watchlist.description && (
|
||||
<Text className='text-neutral-400 text-sm mb-2' numberOfLines={2}>
|
||||
{watchlist.description}
|
||||
</Text>
|
||||
)}
|
||||
|
||||
<View className='flex-row items-center gap-4'>
|
||||
<View className='flex-row items-center gap-1'>
|
||||
<Ionicons name='film-outline' size={14} color='#9ca3af' />
|
||||
<Text className='text-neutral-400 text-sm'>
|
||||
{watchlist.itemCount ?? 0}{" "}
|
||||
{(watchlist.itemCount ?? 0) === 1
|
||||
? t("watchlists.item")
|
||||
: t("watchlists.items")}
|
||||
</Text>
|
||||
</View>
|
||||
{watchlist.allowedItemType && (
|
||||
<View className='bg-neutral-800 px-2 py-0.5 rounded'>
|
||||
<Text className='text-neutral-400 text-xs'>
|
||||
{watchlist.allowedItemType}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
);
|
||||
};
|
||||
|
||||
const EmptyState: React.FC<{ onCreatePress: () => void }> = ({
|
||||
onCreatePress: _onCreatePress,
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<View className='flex-1 items-center justify-center px-8'>
|
||||
<Ionicons name='list-outline' size={64} color='#4b5563' />
|
||||
<Text className='text-xl font-semibold mt-4 text-center'>
|
||||
{t("watchlists.empty_title")}
|
||||
</Text>
|
||||
<Text className='text-neutral-400 text-center mt-2 mb-6'>
|
||||
{t("watchlists.empty_description")}
|
||||
</Text>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
const NotConfiguredState: React.FC = () => {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
|
||||
return (
|
||||
<View className='flex-1 items-center justify-center px-8'>
|
||||
<Ionicons name='settings-outline' size={64} color='#4b5563' />
|
||||
<Text className='text-xl font-semibold mt-4 text-center'>
|
||||
{t("watchlists.not_configured_title")}
|
||||
</Text>
|
||||
<Text className='text-neutral-400 text-center mt-2 mb-6'>
|
||||
{t("watchlists.not_configured_description")}
|
||||
</Text>
|
||||
<Button
|
||||
onPress={() =>
|
||||
router.push(
|
||||
"/(auth)/(tabs)/(home)/settings/plugins/streamystats/page",
|
||||
)
|
||||
}
|
||||
className='px-6'
|
||||
>
|
||||
<Text className='font-semibold'>{t("watchlists.go_to_settings")}</Text>
|
||||
</Button>
|
||||
</View>
|
||||
);
|
||||
};
|
||||
|
||||
export default function WatchlistsScreen() {
|
||||
const { t } = useTranslation();
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const user = useAtomValue(userAtom);
|
||||
const streamystatsEnabled = useStreamystatsEnabled();
|
||||
const { data: watchlists, isLoading, refetch } = useWatchlistsQuery();
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const handleRefresh = useCallback(async () => {
|
||||
setRefreshing(true);
|
||||
await refetch();
|
||||
setRefreshing(false);
|
||||
}, [refetch]);
|
||||
|
||||
const handleCreatePress = useCallback(() => {
|
||||
router.push("/(auth)/(tabs)/(watchlists)/create");
|
||||
}, [router]);
|
||||
|
||||
const handleWatchlistPress = useCallback(
|
||||
(watchlistId: number) => {
|
||||
router.push(`/(auth)/(tabs)/(watchlists)/${watchlistId}`);
|
||||
},
|
||||
[router],
|
||||
);
|
||||
|
||||
// Separate watchlists into "mine" and "public"
|
||||
const { myWatchlists, publicWatchlists } = useMemo(() => {
|
||||
if (!watchlists) return { myWatchlists: [], publicWatchlists: [] };
|
||||
|
||||
const mine: StreamystatsWatchlist[] = [];
|
||||
const pub: StreamystatsWatchlist[] = [];
|
||||
|
||||
for (const w of watchlists) {
|
||||
if (w.userId === user?.Id) {
|
||||
mine.push(w);
|
||||
} else {
|
||||
pub.push(w);
|
||||
}
|
||||
}
|
||||
|
||||
return { myWatchlists: mine, publicWatchlists: pub };
|
||||
}, [watchlists, user?.Id]);
|
||||
|
||||
// Combine into sections for FlashList
|
||||
const sections = useMemo(() => {
|
||||
const result: Array<
|
||||
| { type: "header"; title: string }
|
||||
| { type: "watchlist"; data: StreamystatsWatchlist; isOwner: boolean }
|
||||
> = [];
|
||||
|
||||
if (myWatchlists.length > 0) {
|
||||
result.push({ type: "header", title: t("watchlists.my_watchlists") });
|
||||
for (const w of myWatchlists) {
|
||||
result.push({ type: "watchlist", data: w, isOwner: true });
|
||||
}
|
||||
}
|
||||
|
||||
if (publicWatchlists.length > 0) {
|
||||
result.push({ type: "header", title: t("watchlists.public_watchlists") });
|
||||
for (const w of publicWatchlists) {
|
||||
result.push({ type: "watchlist", data: w, isOwner: false });
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}, [myWatchlists, publicWatchlists, t]);
|
||||
|
||||
if (!streamystatsEnabled) {
|
||||
return <NotConfiguredState />;
|
||||
}
|
||||
|
||||
if (!isLoading && (!watchlists || watchlists.length === 0)) {
|
||||
return <EmptyState onCreatePress={handleCreatePress} />;
|
||||
}
|
||||
|
||||
return (
|
||||
<FlashList
|
||||
data={sections}
|
||||
contentInsetAdjustmentBehavior='automatic'
|
||||
contentContainerStyle={{
|
||||
paddingTop: Platform.OS === "android" ? 10 : 0,
|
||||
paddingBottom: 100,
|
||||
paddingLeft: insets.left,
|
||||
paddingRight: insets.right,
|
||||
}}
|
||||
refreshControl={
|
||||
<RefreshControl refreshing={refreshing} onRefresh={handleRefresh} />
|
||||
}
|
||||
renderItem={({ item }) => {
|
||||
if (item.type === "header") {
|
||||
return (
|
||||
<Text className='text-lg font-bold px-4 pt-4 pb-2'>
|
||||
{item.title}
|
||||
</Text>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<WatchlistCard
|
||||
watchlist={item.data}
|
||||
isOwner={item.isOwner}
|
||||
onPress={() => handleWatchlistPress(item.data.id)}
|
||||
/>
|
||||
);
|
||||
}}
|
||||
getItemType={(item) => item.type}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -10,8 +10,10 @@ import type {
|
||||
import { useFocusEffect, useRouter, withLayoutContext } from "expo-router";
|
||||
import { useCallback } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { Platform } from "react-native";
|
||||
import { Platform, View } from "react-native";
|
||||
import { SystemBars } from "react-native-edge-to-edge";
|
||||
import { MiniPlayerBar } from "@/components/music/MiniPlayerBar";
|
||||
import { MusicPlaybackEngine } from "@/components/music/MusicPlaybackEngine";
|
||||
import { Colors } from "@/constants/Colors";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import { eventBus } from "@/utils/eventBus";
|
||||
@@ -47,7 +49,7 @@ export default function TabLayout() {
|
||||
);
|
||||
|
||||
return (
|
||||
<>
|
||||
<View style={{ flex: 1 }}>
|
||||
<SystemBars hidden={false} style='light' />
|
||||
<NativeTabs
|
||||
sidebarAdaptable={false}
|
||||
@@ -100,6 +102,17 @@ export default function TabLayout() {
|
||||
: (_e) => ({ sfSymbol: "heart.fill" }),
|
||||
}}
|
||||
/>
|
||||
<NativeTabs.Screen
|
||||
name='(watchlists)'
|
||||
options={{
|
||||
title: t("watchlists.title"),
|
||||
tabBarItemHidden: !settings?.streamyStatsServerUrl,
|
||||
tabBarIcon:
|
||||
Platform.OS === "android"
|
||||
? (_e) => require("@/assets/icons/list.png")
|
||||
: (_e) => ({ sfSymbol: "list.bullet.rectangle" }),
|
||||
}}
|
||||
/>
|
||||
<NativeTabs.Screen
|
||||
name='(libraries)'
|
||||
options={{
|
||||
@@ -122,6 +135,8 @@ export default function TabLayout() {
|
||||
}}
|
||||
/>
|
||||
</NativeTabs>
|
||||
</>
|
||||
<MiniPlayerBar />
|
||||
<MusicPlaybackEngine />
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
539
app/(auth)/now-playing.tsx
Normal file
539
app/(auth)/now-playing.tsx
Normal file
@@ -0,0 +1,539 @@
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import type { BaseItemDto } from "@jellyfin/sdk/lib/generated-client/models";
|
||||
import { Image } from "expo-image";
|
||||
import { useRouter } from "expo-router";
|
||||
import { useAtom } from "jotai";
|
||||
import React, { useCallback, useEffect, useMemo, useState } from "react";
|
||||
import {
|
||||
Dimensions,
|
||||
FlatList,
|
||||
Platform,
|
||||
ScrollView,
|
||||
TouchableOpacity,
|
||||
View,
|
||||
} from "react-native";
|
||||
import { Slider } from "react-native-awesome-slider";
|
||||
import { useSharedValue } from "react-native-reanimated";
|
||||
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { apiAtom } from "@/providers/JellyfinProvider";
|
||||
import {
|
||||
type RepeatMode,
|
||||
useMusicPlayer,
|
||||
} from "@/providers/MusicPlayerProvider";
|
||||
import { formatDuration } from "@/utils/time";
|
||||
|
||||
const { width: SCREEN_WIDTH } = Dimensions.get("window");
|
||||
const ARTWORK_SIZE = SCREEN_WIDTH - 80;
|
||||
|
||||
type ViewMode = "player" | "queue";
|
||||
|
||||
export default function NowPlayingScreen() {
|
||||
const [api] = useAtom(apiAtom);
|
||||
const router = useRouter();
|
||||
const insets = useSafeAreaInsets();
|
||||
const [viewMode, setViewMode] = useState<ViewMode>("player");
|
||||
|
||||
const {
|
||||
currentTrack,
|
||||
queue,
|
||||
queueIndex,
|
||||
isPlaying,
|
||||
progress,
|
||||
duration,
|
||||
repeatMode,
|
||||
shuffleEnabled,
|
||||
togglePlayPause,
|
||||
next,
|
||||
previous,
|
||||
seek,
|
||||
setRepeatMode,
|
||||
toggleShuffle,
|
||||
jumpToIndex,
|
||||
removeFromQueue,
|
||||
stop,
|
||||
} = useMusicPlayer();
|
||||
|
||||
const sliderProgress = useSharedValue(0);
|
||||
const sliderMin = useSharedValue(0);
|
||||
const sliderMax = useSharedValue(1);
|
||||
|
||||
useEffect(() => {
|
||||
sliderProgress.value = progress;
|
||||
}, [progress, sliderProgress]);
|
||||
|
||||
useEffect(() => {
|
||||
sliderMax.value = duration > 0 ? duration : 1;
|
||||
}, [duration, sliderMax]);
|
||||
|
||||
const imageUrl = useMemo(() => {
|
||||
if (!api || !currentTrack) return null;
|
||||
const albumId = currentTrack.AlbumId || currentTrack.ParentId;
|
||||
if (albumId) {
|
||||
return `${api.basePath}/Items/${albumId}/Images/Primary?maxHeight=600&maxWidth=600`;
|
||||
}
|
||||
return `${api.basePath}/Items/${currentTrack.Id}/Images/Primary?maxHeight=600&maxWidth=600`;
|
||||
}, [api, currentTrack]);
|
||||
|
||||
const progressText = useMemo(() => {
|
||||
const progressTicks = progress * 10000000;
|
||||
return formatDuration(progressTicks);
|
||||
}, [progress]);
|
||||
|
||||
const durationText = useMemo(() => {
|
||||
const durationTicks = duration * 10000000;
|
||||
return formatDuration(durationTicks);
|
||||
}, [duration]);
|
||||
|
||||
const handleSliderComplete = useCallback(
|
||||
(value: number) => {
|
||||
seek(value);
|
||||
},
|
||||
[seek],
|
||||
);
|
||||
|
||||
const handleClose = useCallback(() => {
|
||||
router.back();
|
||||
}, [router]);
|
||||
|
||||
const handleStop = useCallback(() => {
|
||||
stop();
|
||||
router.back();
|
||||
}, [stop, router]);
|
||||
|
||||
const cycleRepeatMode = useCallback(() => {
|
||||
const modes: RepeatMode[] = ["off", "all", "one"];
|
||||
const currentIndex = modes.indexOf(repeatMode);
|
||||
const nextMode = modes[(currentIndex + 1) % modes.length];
|
||||
setRepeatMode(nextMode);
|
||||
}, [repeatMode, setRepeatMode]);
|
||||
|
||||
const getRepeatIcon = (): string => {
|
||||
switch (repeatMode) {
|
||||
case "one":
|
||||
return "repeat";
|
||||
case "all":
|
||||
return "repeat";
|
||||
default:
|
||||
return "repeat";
|
||||
}
|
||||
};
|
||||
|
||||
const canGoNext = queueIndex < queue.length - 1 || repeatMode === "all";
|
||||
const canGoPrevious = queueIndex > 0 || progress > 3 || repeatMode === "all";
|
||||
|
||||
if (!currentTrack) {
|
||||
return (
|
||||
<View
|
||||
className='flex-1 bg-[#121212] items-center justify-center'
|
||||
style={{
|
||||
paddingTop: Platform.OS === "android" ? insets.top : 0,
|
||||
paddingBottom: Platform.OS === "android" ? insets.bottom : 0,
|
||||
}}
|
||||
>
|
||||
<Text className='text-neutral-500'>No track playing</Text>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<View
|
||||
className='flex-1 bg-[#121212]'
|
||||
style={{
|
||||
paddingTop: Platform.OS === "android" ? insets.top : 0,
|
||||
paddingBottom: Platform.OS === "android" ? insets.bottom : 0,
|
||||
}}
|
||||
>
|
||||
{/* Header */}
|
||||
<View className='flex-row items-center justify-between px-4 pt-3 pb-2'>
|
||||
<TouchableOpacity
|
||||
onPress={handleClose}
|
||||
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||
className='p-2'
|
||||
>
|
||||
<Ionicons name='chevron-down' size={28} color='white' />
|
||||
</TouchableOpacity>
|
||||
|
||||
<View className='flex-row'>
|
||||
<TouchableOpacity
|
||||
onPress={() => setViewMode("player")}
|
||||
className='px-3 py-1'
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
viewMode === "player"
|
||||
? "text-white font-semibold"
|
||||
: "text-neutral-500"
|
||||
}
|
||||
>
|
||||
Now Playing
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
<TouchableOpacity
|
||||
onPress={() => setViewMode("queue")}
|
||||
className='px-3 py-1'
|
||||
>
|
||||
<Text
|
||||
className={
|
||||
viewMode === "queue"
|
||||
? "text-white font-semibold"
|
||||
: "text-neutral-500"
|
||||
}
|
||||
>
|
||||
Queue ({queue.length})
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={handleStop}
|
||||
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||
className='p-2'
|
||||
>
|
||||
<Ionicons name='close' size={24} color='#666' />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
{viewMode === "player" ? (
|
||||
<PlayerView
|
||||
api={api}
|
||||
currentTrack={currentTrack}
|
||||
imageUrl={imageUrl}
|
||||
sliderProgress={sliderProgress}
|
||||
sliderMin={sliderMin}
|
||||
sliderMax={sliderMax}
|
||||
progressText={progressText}
|
||||
durationText={durationText}
|
||||
isPlaying={isPlaying}
|
||||
repeatMode={repeatMode}
|
||||
shuffleEnabled={shuffleEnabled}
|
||||
canGoNext={canGoNext}
|
||||
canGoPrevious={canGoPrevious}
|
||||
onSliderComplete={handleSliderComplete}
|
||||
onTogglePlayPause={togglePlayPause}
|
||||
onNext={next}
|
||||
onPrevious={previous}
|
||||
onCycleRepeat={cycleRepeatMode}
|
||||
onToggleShuffle={toggleShuffle}
|
||||
getRepeatIcon={getRepeatIcon}
|
||||
queue={queue}
|
||||
queueIndex={queueIndex}
|
||||
/>
|
||||
) : (
|
||||
<QueueView
|
||||
api={api}
|
||||
queue={queue}
|
||||
queueIndex={queueIndex}
|
||||
onJumpToIndex={jumpToIndex}
|
||||
onRemoveFromQueue={removeFromQueue}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
}
|
||||
|
||||
interface PlayerViewProps {
|
||||
api: any;
|
||||
currentTrack: BaseItemDto;
|
||||
imageUrl: string | null;
|
||||
sliderProgress: any;
|
||||
sliderMin: any;
|
||||
sliderMax: any;
|
||||
progressText: string;
|
||||
durationText: string;
|
||||
isPlaying: boolean;
|
||||
repeatMode: RepeatMode;
|
||||
shuffleEnabled: boolean;
|
||||
canGoNext: boolean;
|
||||
canGoPrevious: boolean;
|
||||
onSliderComplete: (value: number) => void;
|
||||
onTogglePlayPause: () => void;
|
||||
onNext: () => void;
|
||||
onPrevious: () => void;
|
||||
onCycleRepeat: () => void;
|
||||
onToggleShuffle: () => void;
|
||||
getRepeatIcon: () => string;
|
||||
queue: BaseItemDto[];
|
||||
queueIndex: number;
|
||||
}
|
||||
|
||||
const PlayerView: React.FC<PlayerViewProps> = ({
|
||||
currentTrack,
|
||||
imageUrl,
|
||||
sliderProgress,
|
||||
sliderMin,
|
||||
sliderMax,
|
||||
progressText,
|
||||
durationText,
|
||||
isPlaying,
|
||||
repeatMode,
|
||||
shuffleEnabled,
|
||||
canGoNext,
|
||||
canGoPrevious,
|
||||
onSliderComplete,
|
||||
onTogglePlayPause,
|
||||
onNext,
|
||||
onPrevious,
|
||||
onCycleRepeat,
|
||||
onToggleShuffle,
|
||||
getRepeatIcon,
|
||||
queue,
|
||||
queueIndex,
|
||||
}) => {
|
||||
return (
|
||||
<ScrollView className='flex-1 px-6' showsVerticalScrollIndicator={false}>
|
||||
{/* Album artwork */}
|
||||
<View
|
||||
className='self-center mb-8 mt-4'
|
||||
style={{
|
||||
width: ARTWORK_SIZE,
|
||||
height: ARTWORK_SIZE,
|
||||
borderRadius: 12,
|
||||
overflow: "hidden",
|
||||
backgroundColor: "#1a1a1a",
|
||||
shadowColor: "#000",
|
||||
shadowOffset: { width: 0, height: 8 },
|
||||
shadowOpacity: 0.4,
|
||||
shadowRadius: 16,
|
||||
elevation: 10,
|
||||
}}
|
||||
>
|
||||
{imageUrl ? (
|
||||
<Image
|
||||
source={{ uri: imageUrl }}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
contentFit='cover'
|
||||
cachePolicy='memory-disk'
|
||||
/>
|
||||
) : (
|
||||
<View className='flex-1 items-center justify-center bg-neutral-800'>
|
||||
<Ionicons name='musical-note' size={80} color='#666' />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Track info */}
|
||||
<View className='mb-6'>
|
||||
<Text numberOfLines={1} className='text-white text-2xl font-bold'>
|
||||
{currentTrack.Name}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className='text-purple-400 text-lg mt-1'>
|
||||
{currentTrack.Artists?.join(", ") || currentTrack.AlbumArtist}
|
||||
</Text>
|
||||
{currentTrack.Album && (
|
||||
<Text numberOfLines={1} className='text-neutral-500 text-sm mt-1'>
|
||||
{currentTrack.Album}
|
||||
</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Progress slider */}
|
||||
<View className='mb-4'>
|
||||
<Slider
|
||||
theme={{
|
||||
maximumTrackTintColor: "#333",
|
||||
minimumTrackTintColor: "#9334E9",
|
||||
bubbleBackgroundColor: "#9334E9",
|
||||
bubbleTextColor: "#fff",
|
||||
}}
|
||||
progress={sliderProgress}
|
||||
minimumValue={sliderMin}
|
||||
maximumValue={sliderMax}
|
||||
onSlidingComplete={onSliderComplete}
|
||||
thumbWidth={16}
|
||||
sliderHeight={6}
|
||||
containerStyle={{ borderRadius: 10 }}
|
||||
renderBubble={() => null}
|
||||
/>
|
||||
<View className='flex flex-row justify-between px-1 mt-2'>
|
||||
<Text className='text-neutral-500 text-xs'>{progressText}</Text>
|
||||
<Text className='text-neutral-500 text-xs'>{durationText}</Text>
|
||||
</View>
|
||||
</View>
|
||||
|
||||
{/* Main Controls */}
|
||||
<View className='flex flex-row items-center justify-center mb-4'>
|
||||
<TouchableOpacity
|
||||
onPress={onPrevious}
|
||||
disabled={!canGoPrevious}
|
||||
className='p-4'
|
||||
style={{ opacity: canGoPrevious ? 1 : 0.3 }}
|
||||
>
|
||||
<Ionicons name='play-skip-back' size={32} color='white' />
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={onTogglePlayPause}
|
||||
className='mx-8 bg-white rounded-full p-4'
|
||||
>
|
||||
<Ionicons
|
||||
name={isPlaying ? "pause" : "play"}
|
||||
size={36}
|
||||
color='#121212'
|
||||
style={isPlaying ? {} : { marginLeft: 4 }}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity
|
||||
onPress={onNext}
|
||||
disabled={!canGoNext}
|
||||
className='p-4'
|
||||
style={{ opacity: canGoNext ? 1 : 0.3 }}
|
||||
>
|
||||
<Ionicons name='play-skip-forward' size={32} color='white' />
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
{/* Shuffle & Repeat Controls */}
|
||||
<View className='flex flex-row items-center justify-center mb-6'>
|
||||
<TouchableOpacity onPress={onToggleShuffle} className='p-3 mx-4'>
|
||||
<Ionicons
|
||||
name='shuffle'
|
||||
size={24}
|
||||
color={shuffleEnabled ? "#9334E9" : "#666"}
|
||||
/>
|
||||
</TouchableOpacity>
|
||||
|
||||
<TouchableOpacity onPress={onCycleRepeat} className='p-3 mx-4 relative'>
|
||||
<Ionicons
|
||||
name={getRepeatIcon() as any}
|
||||
size={24}
|
||||
color={repeatMode !== "off" ? "#9334E9" : "#666"}
|
||||
/>
|
||||
{repeatMode === "one" && (
|
||||
<View className='absolute -top-1 -right-1 bg-purple-600 rounded-full w-4 h-4 items-center justify-center'>
|
||||
<Text className='text-white text-[10px] font-bold'>1</Text>
|
||||
</View>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
|
||||
{/* Queue info */}
|
||||
{queue.length > 1 && (
|
||||
<View className='items-center mb-8'>
|
||||
<Text className='text-neutral-500 text-sm'>
|
||||
{queueIndex + 1} of {queue.length}
|
||||
</Text>
|
||||
</View>
|
||||
)}
|
||||
</ScrollView>
|
||||
);
|
||||
};
|
||||
|
||||
interface QueueViewProps {
|
||||
api: any;
|
||||
queue: BaseItemDto[];
|
||||
queueIndex: number;
|
||||
onJumpToIndex: (index: number) => void;
|
||||
onRemoveFromQueue: (index: number) => void;
|
||||
}
|
||||
|
||||
const QueueView: React.FC<QueueViewProps> = ({
|
||||
api,
|
||||
queue,
|
||||
queueIndex,
|
||||
onJumpToIndex,
|
||||
onRemoveFromQueue,
|
||||
}) => {
|
||||
const renderQueueItem = useCallback(
|
||||
({ item, index }: { item: BaseItemDto; index: number }) => {
|
||||
const isCurrentTrack = index === queueIndex;
|
||||
const isPast = index < queueIndex;
|
||||
|
||||
const albumId = item.AlbumId || item.ParentId;
|
||||
const imageUrl = api
|
||||
? albumId
|
||||
? `${api.basePath}/Items/${albumId}/Images/Primary?maxHeight=80&maxWidth=80`
|
||||
: `${api.basePath}/Items/${item.Id}/Images/Primary?maxHeight=80&maxWidth=80`
|
||||
: null;
|
||||
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onPress={() => onJumpToIndex(index)}
|
||||
className={`flex-row items-center px-4 py-3 ${isCurrentTrack ? "bg-purple-900/30" : ""}`}
|
||||
style={{ opacity: isPast ? 0.5 : 1 }}
|
||||
>
|
||||
{/* Track number / Now playing indicator */}
|
||||
<View className='w-8 items-center'>
|
||||
{isCurrentTrack ? (
|
||||
<Ionicons name='musical-note' size={16} color='#9334E9' />
|
||||
) : (
|
||||
<Text className='text-neutral-500 text-sm'>{index + 1}</Text>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Album art */}
|
||||
<View className='w-12 h-12 rounded overflow-hidden bg-neutral-800 mr-3'>
|
||||
{imageUrl ? (
|
||||
<Image
|
||||
source={{ uri: imageUrl }}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
contentFit='cover'
|
||||
cachePolicy='memory-disk'
|
||||
/>
|
||||
) : (
|
||||
<View className='flex-1 items-center justify-center'>
|
||||
<Ionicons name='musical-note' size={16} color='#666' />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
|
||||
{/* Track info */}
|
||||
<View className='flex-1 mr-2'>
|
||||
<Text
|
||||
numberOfLines={1}
|
||||
className={`text-base ${isCurrentTrack ? "text-purple-400 font-semibold" : "text-white"}`}
|
||||
>
|
||||
{item.Name}
|
||||
</Text>
|
||||
<Text numberOfLines={1} className='text-neutral-500 text-sm'>
|
||||
{item.Artists?.join(", ") || item.AlbumArtist}
|
||||
</Text>
|
||||
</View>
|
||||
|
||||
{/* Remove button (not for current track) */}
|
||||
{!isCurrentTrack && (
|
||||
<TouchableOpacity
|
||||
onPress={() => onRemoveFromQueue(index)}
|
||||
hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
|
||||
className='p-2'
|
||||
>
|
||||
<Ionicons name='close' size={20} color='#666' />
|
||||
</TouchableOpacity>
|
||||
)}
|
||||
</TouchableOpacity>
|
||||
);
|
||||
},
|
||||
[api, queueIndex, onJumpToIndex, onRemoveFromQueue],
|
||||
);
|
||||
|
||||
const _upNext = queue.slice(queueIndex + 1);
|
||||
const history = queue.slice(0, queueIndex);
|
||||
|
||||
return (
|
||||
<FlatList
|
||||
data={queue}
|
||||
keyExtractor={(item, index) => `${item.Id}-${index}`}
|
||||
renderItem={renderQueueItem}
|
||||
showsVerticalScrollIndicator={false}
|
||||
initialScrollIndex={queueIndex > 2 ? queueIndex - 2 : 0}
|
||||
getItemLayout={(_, index) => ({
|
||||
length: 72,
|
||||
offset: 72 * index,
|
||||
index,
|
||||
})}
|
||||
ListHeaderComponent={
|
||||
<View className='px-4 py-2'>
|
||||
<Text className='text-neutral-400 text-xs uppercase tracking-wider'>
|
||||
{history.length > 0 ? "Playing from queue" : "Up next"}
|
||||
</Text>
|
||||
</View>
|
||||
}
|
||||
ListEmptyComponent={
|
||||
<View className='flex-1 items-center justify-center py-20'>
|
||||
<Text className='text-neutral-500'>Queue is empty</Text>
|
||||
</View>
|
||||
}
|
||||
/>
|
||||
);
|
||||
};
|
||||
@@ -1,7 +1,33 @@
|
||||
import { Stack } from "expo-router";
|
||||
import { useEffect } from "react";
|
||||
import { AppState } from "react-native";
|
||||
import { SystemBars } from "react-native-edge-to-edge";
|
||||
|
||||
import { useOrientation } from "@/hooks/useOrientation";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
|
||||
export default function Layout() {
|
||||
const { settings } = useSettings();
|
||||
const { lockOrientation, unlockOrientation } = useOrientation();
|
||||
|
||||
useEffect(() => {
|
||||
if (settings?.defaultVideoOrientation) {
|
||||
lockOrientation(settings.defaultVideoOrientation);
|
||||
}
|
||||
|
||||
// Re-apply orientation lock when app returns to foreground (iOS resets it)
|
||||
const subscription = AppState.addEventListener("change", (nextAppState) => {
|
||||
if (nextAppState === "active" && settings?.defaultVideoOrientation) {
|
||||
lockOrientation(settings.defaultVideoOrientation);
|
||||
}
|
||||
});
|
||||
|
||||
return () => {
|
||||
subscription.remove();
|
||||
unlockOrientation();
|
||||
};
|
||||
}, [settings?.defaultVideoOrientation, lockOrientation, unlockOrientation]);
|
||||
|
||||
return (
|
||||
<>
|
||||
<SystemBars hidden />
|
||||
|
||||
@@ -22,53 +22,69 @@ import { BITRATES } from "@/components/BitrateSelector";
|
||||
import { Text } from "@/components/common/Text";
|
||||
import { Loader } from "@/components/Loader";
|
||||
import { Controls } from "@/components/video-player/controls/Controls";
|
||||
import {
|
||||
OUTLINE_THICKNESS,
|
||||
OutlineThickness,
|
||||
VLC_COLORS,
|
||||
VLCColor,
|
||||
} from "@/constants/SubtitleConstants";
|
||||
import { PlayerProvider } from "@/components/video-player/controls/contexts/PlayerContext";
|
||||
import { VideoProvider } from "@/components/video-player/controls/contexts/VideoContext";
|
||||
import { useHaptic } from "@/hooks/useHaptic";
|
||||
import { useOrientation } from "@/hooks/useOrientation";
|
||||
import { usePlaybackManager } from "@/hooks/usePlaybackManager";
|
||||
import { useInvalidatePlaybackProgressCache } from "@/hooks/useRevalidatePlaybackProgressCache";
|
||||
import { useWebSocket } from "@/hooks/useWebsockets";
|
||||
import { VlcPlayerView } from "@/modules";
|
||||
import type {
|
||||
PlaybackStatePayload,
|
||||
ProgressUpdatePayload,
|
||||
VlcPlayerViewRef,
|
||||
} from "@/modules/VlcPlayer.types";
|
||||
import {
|
||||
type PlaybackStatePayload,
|
||||
type ProgressUpdatePayload,
|
||||
type SfOnErrorEventPayload,
|
||||
type SfOnPictureInPictureChangePayload,
|
||||
type SfOnPlaybackStateChangePayload,
|
||||
type SfOnProgressEventPayload,
|
||||
SfPlayerView,
|
||||
type SfPlayerViewRef,
|
||||
type SfVideoSource,
|
||||
setHardwareDecode,
|
||||
type VlcPlayerSource,
|
||||
VlcPlayerView,
|
||||
type VlcPlayerViewRef,
|
||||
} from "@/modules";
|
||||
import { useDownload } from "@/providers/DownloadProvider";
|
||||
import { DownloadedItem } from "@/providers/Downloads/types";
|
||||
import { apiAtom, userAtom } from "@/providers/JellyfinProvider";
|
||||
import { useSettings } from "@/utils/atoms/settings";
|
||||
import { getPrimaryImageUrl } from "@/utils/jellyfin/image/getPrimaryImageUrl";
|
||||
import { useSettings, VideoPlayerIOS } from "@/utils/atoms/settings";
|
||||
import { getStreamUrl } from "@/utils/jellyfin/media/getStreamUrl";
|
||||
import {
|
||||
getMpvAudioId,
|
||||
getMpvSubtitleId,
|
||||
} from "@/utils/jellyfin/subtitleUtils";
|
||||
import { writeToLog } from "@/utils/log";
|
||||
import { generateDeviceProfile } from "@/utils/profiles/native";
|
||||
import { msToTicks, ticksToSeconds } from "@/utils/time";
|
||||
|
||||
export default function page() {
|
||||
const videoRef = useRef<VlcPlayerViewRef>(null);
|
||||
const videoRef = useRef<SfPlayerViewRef | VlcPlayerViewRef>(null);
|
||||
const user = useAtomValue(userAtom);
|
||||
const api = useAtomValue(apiAtom);
|
||||
const { t } = useTranslation();
|
||||
const navigation = useNavigation();
|
||||
const { settings } = useSettings();
|
||||
|
||||
// Determine which player to use:
|
||||
// - Android always uses VLC
|
||||
// - iOS uses user setting (KSPlayer by default, VLC optional)
|
||||
const useVlcPlayer =
|
||||
Platform.OS === "android" ||
|
||||
(Platform.OS === "ios" && settings.videoPlayerIOS === VideoPlayerIOS.VLC);
|
||||
|
||||
const [isPlaybackStopped, setIsPlaybackStopped] = useState(false);
|
||||
const [showControls, _setShowControls] = useState(true);
|
||||
const [isPipMode, setIsPipMode] = useState(false);
|
||||
const [aspectRatio, setAspectRatio] = useState<
|
||||
"default" | "16:9" | "4:3" | "1:1" | "21:9"
|
||||
>("default");
|
||||
const [scaleFactor, setScaleFactor] = useState<
|
||||
1.0 | 1.1 | 1.2 | 1.3 | 1.4 | 1.5 | 1.6 | 1.7 | 1.8 | 1.9 | 2.0
|
||||
>(1.0);
|
||||
const [aspectRatio] = useState<"default" | "16:9" | "4:3" | "1:1" | "21:9">(
|
||||
"default",
|
||||
);
|
||||
const [isZoomedToFill, setIsZoomedToFill] = useState(false);
|
||||
const [isPlaying, setIsPlaying] = useState(false);
|
||||
const [isMuted, setIsMuted] = useState(false);
|
||||
const [isBuffering, setIsBuffering] = useState(true);
|
||||
const [isVideoLoaded, setIsVideoLoaded] = useState(false);
|
||||
const [tracksReady, setTracksReady] = useState(false);
|
||||
const [hasPlaybackStarted, setHasPlaybackStarted] = useState(false);
|
||||
|
||||
const progress = useSharedValue(0);
|
||||
const isSeeking = useSharedValue(false);
|
||||
@@ -110,11 +126,10 @@ export default function page() {
|
||||
/** Playback position in ticks. */
|
||||
playbackPosition?: string;
|
||||
}>();
|
||||
const { settings } = useSettings();
|
||||
const { lockOrientation, unlockOrientation } = useOrientation();
|
||||
|
||||
const offline = offlineStr === "true";
|
||||
const playbackManager = usePlaybackManager();
|
||||
const playbackManager = usePlaybackManager({ isOffline: offline });
|
||||
|
||||
const audioIndex = audioIndexStr
|
||||
? Number.parseInt(audioIndexStr, 10)
|
||||
@@ -141,7 +156,7 @@ export default function page() {
|
||||
return Number.parseInt(playbackPositionFromUrl, 10);
|
||||
}
|
||||
return item?.UserData?.PlaybackPositionTicks ?? 0;
|
||||
}, [playbackPositionFromUrl]);
|
||||
}, [playbackPositionFromUrl, item?.UserData?.PlaybackPositionTicks]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchItemData = async () => {
|
||||
@@ -174,6 +189,7 @@ export default function page() {
|
||||
}
|
||||
}, [itemId, offline, api, user?.Id]);
|
||||
|
||||
// Lock orientation based on user settings
|
||||
useEffect(() => {
|
||||
if (settings?.defaultVideoOrientation) {
|
||||
lockOrientation(settings.defaultVideoOrientation);
|
||||
@@ -182,7 +198,7 @@ export default function page() {
|
||||
return () => {
|
||||
unlockOrientation();
|
||||
};
|
||||
}, [settings?.defaultVideoOrientation]);
|
||||
}, [settings?.defaultVideoOrientation, lockOrientation, unlockOrientation]);
|
||||
|
||||
interface Stream {
|
||||
mediaSource: MediaSourceInfo;
|
||||
@@ -230,21 +246,25 @@ export default function page() {
|
||||
return;
|
||||
}
|
||||
|
||||
const native = generateDeviceProfile();
|
||||
const transcoding = generateDeviceProfile({ transcode: true });
|
||||
// Calculate start ticks directly from item to avoid stale closure
|
||||
const startTicks = playbackPositionFromUrl
|
||||
? Number.parseInt(playbackPositionFromUrl, 10)
|
||||
: (item?.UserData?.PlaybackPositionTicks ?? 0);
|
||||
|
||||
const res = await getStreamUrl({
|
||||
api,
|
||||
item,
|
||||
startTimeTicks: getInitialPlaybackTicks(),
|
||||
startTimeTicks: startTicks,
|
||||
userId: user.Id,
|
||||
audioStreamIndex: audioIndex,
|
||||
maxStreamingBitrate: bitrateValue,
|
||||
mediaSourceId: mediaSourceId,
|
||||
subtitleStreamIndex: subtitleIndex,
|
||||
deviceProfile: bitrateValue ? transcoding : native,
|
||||
deviceProfile: generateDeviceProfile(),
|
||||
});
|
||||
if (!res) return;
|
||||
const { mediaSource, sessionId, url } = res;
|
||||
|
||||
if (!sessionId || !mediaSource || !url) {
|
||||
Alert.alert(
|
||||
t("player.error"),
|
||||
@@ -273,14 +293,14 @@ export default function page() {
|
||||
]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!stream || !api) return;
|
||||
if (!stream || !api || offline) return;
|
||||
const reportPlaybackStart = async () => {
|
||||
await getPlaystateApi(api).reportPlaybackStart({
|
||||
playbackStartInfo: currentPlayStateInfo() as PlaybackStartInfo,
|
||||
});
|
||||
};
|
||||
reportPlaybackStart();
|
||||
}, [stream, api]);
|
||||
}, [stream, api, offline]);
|
||||
|
||||
const togglePlay = async () => {
|
||||
lightHapticFeedback();
|
||||
@@ -292,17 +312,19 @@ export default function page() {
|
||||
);
|
||||
} else {
|
||||
videoRef.current?.play();
|
||||
await getPlaystateApi(api!).reportPlaybackStart({
|
||||
playbackStartInfo: currentPlayStateInfo() as PlaybackStartInfo,
|
||||
});
|
||||
if (!offline && api) {
|
||||
await getPlaystateApi(api).reportPlaybackStart({
|
||||
playbackStartInfo: currentPlayStateInfo() as PlaybackStartInfo,
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const reportPlaybackStopped = useCallback(async () => {
|
||||
if (!item?.Id || !stream?.sessionId) return;
|
||||
if (!item?.Id || !stream?.sessionId || offline || !api) return;
|
||||
|
||||
const currentTimeInTicks = msToTicks(progress.get());
|
||||
await getPlaystateApi(api!).onPlaybackStopped({
|
||||
await getPlaystateApi(api).onPlaybackStopped({
|
||||
itemId: item.Id,
|
||||
mediaSourceId: mediaSourceId,
|
||||
positionTicks: currentTimeInTicks,
|
||||
@@ -325,7 +347,8 @@ export default function page() {
|
||||
});
|
||||
reportPlaybackStopped();
|
||||
setIsPlaybackStopped(true);
|
||||
videoRef.current?.stop();
|
||||
// KSPlayer doesn't have a stop method, use pause instead
|
||||
videoRef.current?.pause();
|
||||
revalidateProgressCache();
|
||||
}, [videoRef, reportPlaybackStopped, progress]);
|
||||
|
||||
@@ -338,6 +361,7 @@ export default function page() {
|
||||
|
||||
const currentPlayStateInfo = useCallback(() => {
|
||||
if (!stream || !item?.Id) return;
|
||||
|
||||
return {
|
||||
itemId: item.Id,
|
||||
audioStreamIndex: audioIndex ? audioIndex : undefined,
|
||||
@@ -379,11 +403,63 @@ export default function page() {
|
||||
[],
|
||||
);
|
||||
|
||||
const onProgress = useCallback(
|
||||
/** Progress handler for iOS (SfPlayer) - position in seconds */
|
||||
const onProgressSf = useCallback(
|
||||
async (data: { nativeEvent: SfOnProgressEventPayload }) => {
|
||||
if (isSeeking.get() || isPlaybackStopped) return;
|
||||
|
||||
const { position } = data.nativeEvent;
|
||||
// KSPlayer reports position in seconds, convert to ms
|
||||
const currentTime = position * 1000;
|
||||
|
||||
if (isBuffering) {
|
||||
setIsBuffering(false);
|
||||
}
|
||||
|
||||
progress.set(currentTime);
|
||||
|
||||
// Update URL immediately after seeking, or every 30 seconds during normal playback
|
||||
const now = Date.now();
|
||||
const shouldUpdateUrl = wasJustSeeking.get();
|
||||
wasJustSeeking.value = false;
|
||||
|
||||
if (
|
||||
shouldUpdateUrl ||
|
||||
now - lastUrlUpdateTime.get() > URL_UPDATE_INTERVAL
|
||||
) {
|
||||
router.setParams({
|
||||
playbackPosition: msToTicks(currentTime).toString(),
|
||||
});
|
||||
lastUrlUpdateTime.value = now;
|
||||
}
|
||||
|
||||
if (!item?.Id) return;
|
||||
|
||||
playbackManager.reportPlaybackProgress(
|
||||
currentPlayStateInfo() as PlaybackProgressInfo,
|
||||
);
|
||||
},
|
||||
[
|
||||
item?.Id,
|
||||
audioIndex,
|
||||
subtitleIndex,
|
||||
mediaSourceId,
|
||||
isPlaying,
|
||||
stream,
|
||||
isSeeking,
|
||||
isPlaybackStopped,
|
||||
isBuffering,
|
||||
],
|
||||
);
|
||||
|
||||
/** Progress handler for Android (VLC) - currentTime in milliseconds */
|
||||
const onProgressVlc = useCallback(
|
||||
async (data: ProgressUpdatePayload) => {
|
||||
if (isSeeking.get() || isPlaybackStopped) return;
|
||||
|
||||
const { currentTime } = data.nativeEvent;
|
||||
// VLC reports currentTime in milliseconds
|
||||
|
||||
if (isBuffering) {
|
||||
setIsBuffering(false);
|
||||
}
|
||||
@@ -429,6 +505,168 @@ export default function page() {
|
||||
return ticksToSeconds(getInitialPlaybackTicks());
|
||||
}, [getInitialPlaybackTicks]);
|
||||
|
||||
/** Build video source config for iOS (SfPlayer/KSPlayer) */
|
||||
const sfVideoSource = useMemo<SfVideoSource | undefined>(() => {
|
||||
if (!stream?.url || useVlcPlayer) return undefined;
|
||||
|
||||
const mediaSource = stream.mediaSource;
|
||||
const isTranscoding = Boolean(mediaSource?.TranscodingUrl);
|
||||
|
||||
// For offline playback, subtitles are embedded in the downloaded file
|
||||
// For online playback, get external subtitle URLs from server
|
||||
let externalSubs: string[] | undefined;
|
||||
if (!offline && api?.basePath) {
|
||||
externalSubs = mediaSource?.MediaStreams?.filter(
|
||||
(s) =>
|
||||
s.Type === "Subtitle" &&
|
||||
s.DeliveryMethod === "External" &&
|
||||
s.DeliveryUrl,
|
||||
).map((s) => `${api.basePath}${s.DeliveryUrl}`);
|
||||
}
|
||||
|
||||
// Calculate track IDs for initial selection
|
||||
const initialSubtitleId = getMpvSubtitleId(
|
||||
mediaSource,
|
||||
subtitleIndex,
|
||||
isTranscoding,
|
||||
);
|
||||
const initialAudioId = getMpvAudioId(mediaSource, audioIndex);
|
||||
|
||||
// Calculate start position directly here to avoid timing issues
|
||||
const startTicks = playbackPositionFromUrl
|
||||
? Number.parseInt(playbackPositionFromUrl, 10)
|
||||
: (item?.UserData?.PlaybackPositionTicks ?? 0);
|
||||
const startPos = ticksToSeconds(startTicks);
|
||||
|
||||
// For transcoded streams, the server already handles seeking via startTimeTicks,
|
||||
// so we should NOT also tell the player to seek (would cause double-seeking).
|
||||
// For direct play/stream, the player needs to seek itself.
|
||||
const playerStartPos = isTranscoding ? 0 : startPos;
|
||||
|
||||
// Build source config - headers only needed for online streaming
|
||||
const source: SfVideoSource = {
|
||||
url: stream.url,
|
||||
startPosition: playerStartPos,
|
||||
autoplay: true,
|
||||
initialSubtitleId,
|
||||
initialAudioId,
|
||||
};
|
||||
|
||||
// Add external subtitles only for online playback
|
||||
if (externalSubs && externalSubs.length > 0) {
|
||||
source.externalSubtitles = externalSubs;
|
||||
}
|
||||
|
||||
// Add auth headers only for online streaming (not for local file:// URLs)
|
||||
if (!offline && api?.accessToken) {
|
||||
source.headers = {
|
||||
Authorization: `MediaBrowser Token="${api.accessToken}"`,
|
||||
};
|
||||
}
|
||||
|
||||
return source;
|
||||
}, [
|
||||
stream?.url,
|
||||
stream?.mediaSource,
|
||||
item?.UserData?.PlaybackPositionTicks,
|
||||
playbackPositionFromUrl,
|
||||
api?.basePath,
|
||||
api?.accessToken,
|
||||
subtitleIndex,
|
||||
audioIndex,
|
||||
offline,
|
||||
useVlcPlayer,
|
||||
]);
|
||||
|
||||
/** Build video source config for Android (VLC) */
|
||||
const vlcVideoSource = useMemo<VlcPlayerSource | undefined>(() => {
|
||||
if (!stream?.url || !useVlcPlayer) return undefined;
|
||||
|
||||
const mediaSource = stream.mediaSource;
|
||||
const isTranscoding = Boolean(mediaSource?.TranscodingUrl);
|
||||
|
||||
// For VLC, external subtitles need name and DeliveryUrl
|
||||
let externalSubs: { name: string; DeliveryUrl: string }[] | undefined;
|
||||
if (!offline && api?.basePath) {
|
||||
externalSubs = mediaSource?.MediaStreams?.filter(
|
||||
(s) =>
|
||||
s.Type === "Subtitle" &&
|
||||
s.DeliveryMethod === "External" &&
|
||||
s.DeliveryUrl,
|
||||
).map((s) => ({
|
||||
name: s.DisplayTitle || s.Title || `Subtitle ${s.Index}`,
|
||||
DeliveryUrl: `${api.basePath}${s.DeliveryUrl}`,
|
||||
}));
|
||||
}
|
||||
|
||||
// Build VLC init options (required for VLC to work properly)
|
||||
const initOptions: string[] = [""];
|
||||
|
||||
// Get all subtitle and audio streams
|
||||
const allSubs =
|
||||
mediaSource?.MediaStreams?.filter((s) => s.Type === "Subtitle") ?? [];
|
||||
const textSubs = allSubs.filter((s) => s.IsTextSubtitleStream);
|
||||
const allAudio =
|
||||
mediaSource?.MediaStreams?.filter((s) => s.Type === "Audio") ?? [];
|
||||
|
||||
// Find chosen tracks
|
||||
const chosenSubtitleTrack = allSubs.find((s) => s.Index === subtitleIndex);
|
||||
const chosenAudioTrack = allAudio.find((a) => a.Index === audioIndex);
|
||||
|
||||
// Set subtitle track
|
||||
if (
|
||||
chosenSubtitleTrack &&
|
||||
(!isTranscoding || chosenSubtitleTrack.IsTextSubtitleStream)
|
||||
) {
|
||||
const finalIndex = !isTranscoding
|
||||
? allSubs.indexOf(chosenSubtitleTrack)
|
||||
: [...textSubs].reverse().indexOf(chosenSubtitleTrack);
|
||||
if (finalIndex >= 0) {
|
||||
initOptions.push(`--sub-track=${finalIndex}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Set audio track
|
||||
if (!isTranscoding && chosenAudioTrack) {
|
||||
const audioTrackIndex = allAudio.indexOf(chosenAudioTrack);
|
||||
if (audioTrackIndex >= 0) {
|
||||
initOptions.push(`--audio-track=${audioTrackIndex}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Add subtitle styling
|
||||
if (settings.subtitleSize) {
|
||||
initOptions.push(`--sub-text-scale=${settings.subtitleSize}`);
|
||||
}
|
||||
initOptions.push("--sub-margin=40");
|
||||
|
||||
// For transcoded streams, the server already handles seeking via startTimeTicks,
|
||||
// so we should NOT also tell the player to seek (would cause double-seeking).
|
||||
// For direct play/stream, the player needs to seek itself.
|
||||
const playerStartPos = isTranscoding ? 0 : startPosition;
|
||||
|
||||
const source: VlcPlayerSource = {
|
||||
uri: stream.url,
|
||||
startPosition: playerStartPos,
|
||||
autoplay: true,
|
||||
isNetwork: !offline,
|
||||
externalSubtitles: externalSubs,
|
||||
initOptions,
|
||||
};
|
||||
|
||||
return source;
|
||||
}, [
|
||||
stream?.url,
|
||||
stream?.mediaSource,
|
||||
startPosition,
|
||||
useVlcPlayer,
|
||||
api?.basePath,
|
||||
offline,
|
||||
subtitleIndex,
|
||||
audioIndex,
|
||||
settings.subtitleSize,
|
||||
]);
|
||||
|
||||
const volumeUpCb = useCallback(async () => {
|
||||
if (Platform.isTV) return;
|
||||
|
||||
@@ -508,11 +746,55 @@ export default function page() {
|
||||
setVolume: setVolumeCb,
|
||||
});
|
||||
|
||||
const onPlaybackStateChanged = useCallback(
|
||||
async (e: PlaybackStatePayload) => {
|
||||
const { state, isBuffering, isPlaying } = e.nativeEvent;
|
||||
if (state === "Playing") {
|
||||
/** Playback state handler for iOS (SfPlayer) */
|
||||
const onPlaybackStateChangedSf = useCallback(
|
||||
async (e: { nativeEvent: SfOnPlaybackStateChangePayload }) => {
|
||||
const { isPaused, isPlaying: playing, isLoading } = e.nativeEvent;
|
||||
|
||||
if (playing) {
|
||||
setIsPlaying(true);
|
||||
setIsBuffering(false);
|
||||
setHasPlaybackStarted(true);
|
||||
if (item?.Id) {
|
||||
playbackManager.reportPlaybackProgress(
|
||||
currentPlayStateInfo() as PlaybackProgressInfo,
|
||||
);
|
||||
}
|
||||
if (!Platform.isTV) await activateKeepAwakeAsync();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPaused) {
|
||||
setIsPlaying(false);
|
||||
if (item?.Id) {
|
||||
playbackManager.reportPlaybackProgress(
|
||||
currentPlayStateInfo() as PlaybackProgressInfo,
|
||||
);
|
||||
}
|
||||
if (!Platform.isTV) await deactivateKeepAwake();
|
||||
return;
|
||||
}
|
||||
|
||||
if (isLoading) {
|
||||
setIsBuffering(true);
|
||||
}
|
||||
},
|
||||
[playbackManager, item?.Id, progress],
|
||||
);
|
||||
|
||||
/** Playback state handler for Android (VLC) */
|
||||
const onPlaybackStateChangedVlc = useCallback(
|
||||
async (e: PlaybackStatePayload) => {
|
||||
const {
|
||||
state,
|
||||
isBuffering: buffering,
|
||||
isPlaying: playing,
|
||||
} = e.nativeEvent;
|
||||
|
||||
if (state === "Playing" || playing) {
|
||||
setIsPlaying(true);
|
||||
setIsBuffering(false);
|
||||
setHasPlaybackStarted(true);
|
||||
if (item?.Id) {
|
||||
playbackManager.reportPlaybackProgress(
|
||||
currentPlayStateInfo() as PlaybackProgressInfo,
|
||||
@@ -533,86 +815,38 @@ export default function page() {
|
||||
return;
|
||||
}
|
||||
|
||||
if (isPlaying) {
|
||||
setIsPlaying(true);
|
||||
setIsBuffering(false);
|
||||
} else if (isBuffering) {
|
||||
if (state === "Buffering" || buffering) {
|
||||
setIsBuffering(true);
|
||||
}
|
||||
},
|
||||
[playbackManager, item?.Id, progress],
|
||||
);
|
||||
|
||||
const allAudio =
|
||||
stream?.mediaSource.MediaStreams?.filter(
|
||||
(audio) => audio.Type === "Audio",
|
||||
) || [];
|
||||
|
||||
// Move all the external subtitles last, because vlc places them last.
|
||||
const allSubs =
|
||||
stream?.mediaSource.MediaStreams?.filter(
|
||||
(sub) => sub.Type === "Subtitle",
|
||||
).sort((a, b) => Number(a.IsExternal) - Number(b.IsExternal)) || [];
|
||||
|
||||
const externalSubtitles = allSubs
|
||||
.filter((sub: any) => sub.DeliveryMethod === "External")
|
||||
.map((sub: any) => ({
|
||||
name: sub.DisplayTitle,
|
||||
DeliveryUrl: offline ? sub.DeliveryUrl : api?.basePath + sub.DeliveryUrl,
|
||||
}));
|
||||
/** The text based subtitle tracks */
|
||||
const textSubs = allSubs.filter((sub) => sub.IsTextSubtitleStream);
|
||||
/** The user chosen subtitle track from the server */
|
||||
const chosenSubtitleTrack = allSubs.find(
|
||||
(sub) => sub.Index === subtitleIndex,
|
||||
/** PiP handler for iOS (SfPlayer) */
|
||||
const onPictureInPictureChangeSf = useCallback(
|
||||
(e: { nativeEvent: SfOnPictureInPictureChangePayload }) => {
|
||||
const { isActive } = e.nativeEvent;
|
||||
setIsPipMode(isActive);
|
||||
// Hide controls when entering PiP
|
||||
if (isActive) {
|
||||
_setShowControls(false);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
/** The user chosen audio track from the server */
|
||||
const chosenAudioTrack = allAudio.find((audio) => audio.Index === audioIndex);
|
||||
/** Whether the stream we're playing is not transcoding*/
|
||||
const notTranscoding = !stream?.mediaSource.TranscodingUrl;
|
||||
/** The initial options to pass to the VLC Player */
|
||||
const initOptions = [``];
|
||||
if (
|
||||
chosenSubtitleTrack &&
|
||||
(notTranscoding || chosenSubtitleTrack.IsTextSubtitleStream)
|
||||
) {
|
||||
// If not transcoding, we can the index as normal.
|
||||
// If transcoding, we need to reverse the text based subtitles, because VLC reverses the HLS subtitles.
|
||||
const finalIndex = notTranscoding
|
||||
? allSubs.indexOf(chosenSubtitleTrack)
|
||||
: [...textSubs].reverse().indexOf(chosenSubtitleTrack);
|
||||
initOptions.push(`--sub-track=${finalIndex}`);
|
||||
|
||||
// Add VLC subtitle styling options from settings
|
||||
const textColor = (settings.vlcTextColor ?? "White") as VLCColor;
|
||||
const backgroundColor = (settings.vlcBackgroundColor ??
|
||||
"Black") as VLCColor;
|
||||
const outlineColor = (settings.vlcOutlineColor ?? "Black") as VLCColor;
|
||||
const outlineThickness = (settings.vlcOutlineThickness ??
|
||||
"Normal") as OutlineThickness;
|
||||
const backgroundOpacity = settings.vlcBackgroundOpacity ?? 128;
|
||||
const outlineOpacity = settings.vlcOutlineOpacity ?? 255;
|
||||
const isBold = settings.vlcIsBold ?? false;
|
||||
// Add subtitle styling options
|
||||
initOptions.push(`--freetype-color=${VLC_COLORS[textColor]}`);
|
||||
initOptions.push(`--freetype-background-opacity=${backgroundOpacity}`);
|
||||
initOptions.push(
|
||||
`--freetype-background-color=${VLC_COLORS[backgroundColor]}`,
|
||||
);
|
||||
initOptions.push(`--freetype-outline-opacity=${outlineOpacity}`);
|
||||
initOptions.push(`--freetype-outline-color=${VLC_COLORS[outlineColor]}`);
|
||||
initOptions.push(
|
||||
`--freetype-outline-thickness=${OUTLINE_THICKNESS[outlineThickness]}`,
|
||||
);
|
||||
initOptions.push(`--sub-text-scale=${settings.subtitleSize}`);
|
||||
initOptions.push("--sub-margin=40");
|
||||
if (isBold) {
|
||||
initOptions.push("--freetype-bold");
|
||||
}
|
||||
}
|
||||
if (notTranscoding && chosenAudioTrack) {
|
||||
initOptions.push(`--audio-track=${allAudio.indexOf(chosenAudioTrack)}`);
|
||||
}
|
||||
/** PiP handler for Android (VLC) */
|
||||
const onPipStartedVlc = useCallback(
|
||||
(e: { nativeEvent: { pipStarted: boolean } }) => {
|
||||
const { pipStarted } = e.nativeEvent;
|
||||
setIsPipMode(pipStarted);
|
||||
// Hide controls when entering PiP
|
||||
if (pipStarted) {
|
||||
_setShowControls(false);
|
||||
}
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
const [isMounted, setIsMounted] = useState(false);
|
||||
|
||||
@@ -626,6 +860,7 @@ export default function page() {
|
||||
const startPictureInPicture = useCallback(async () => {
|
||||
return videoRef.current?.startPictureInPicture?.();
|
||||
}, []);
|
||||
|
||||
const play = useCallback(() => {
|
||||
videoRef.current?.play?.();
|
||||
}, []);
|
||||
@@ -634,70 +869,65 @@ export default function page() {
|
||||
videoRef.current?.pause?.();
|
||||
}, []);
|
||||
|
||||
const seek = useCallback((position: number) => {
|
||||
videoRef.current?.seekTo?.(position);
|
||||
}, []);
|
||||
const getAudioTracks = useCallback(async () => {
|
||||
return videoRef.current?.getAudioTracks?.() || null;
|
||||
}, []);
|
||||
|
||||
const getSubtitleTracks = useCallback(async () => {
|
||||
return videoRef.current?.getSubtitleTracks?.() || null;
|
||||
}, []);
|
||||
|
||||
const setSubtitleTrack = useCallback((index: number) => {
|
||||
videoRef.current?.setSubtitleTrack?.(index);
|
||||
}, []);
|
||||
|
||||
const setSubtitleURL = useCallback((url: string, _customName?: string) => {
|
||||
// Note: VlcPlayer type only expects url parameter
|
||||
videoRef.current?.setSubtitleURL?.(url);
|
||||
}, []);
|
||||
|
||||
const setAudioTrack = useCallback((index: number) => {
|
||||
videoRef.current?.setAudioTrack?.(index);
|
||||
}, []);
|
||||
|
||||
const setVideoAspectRatio = useCallback(
|
||||
async (aspectRatio: string | null) => {
|
||||
return (
|
||||
videoRef.current?.setVideoAspectRatio?.(aspectRatio) ||
|
||||
Promise.resolve()
|
||||
);
|
||||
const seek = useCallback(
|
||||
(position: number) => {
|
||||
if (useVlcPlayer) {
|
||||
// VLC expects milliseconds
|
||||
videoRef.current?.seekTo?.(position);
|
||||
} else {
|
||||
// KSPlayer expects seconds, convert from ms
|
||||
videoRef.current?.seekTo?.(position / 1000);
|
||||
}
|
||||
},
|
||||
[],
|
||||
[useVlcPlayer],
|
||||
);
|
||||
|
||||
const setVideoScaleFactor = useCallback(async (scaleFactor: number) => {
|
||||
return (
|
||||
videoRef.current?.setVideoScaleFactor?.(scaleFactor) || Promise.resolve()
|
||||
const handleZoomToggle = useCallback(async () => {
|
||||
// Zoom toggle only supported when using SfPlayer (KSPlayer)
|
||||
if (useVlcPlayer) return;
|
||||
const newZoomState = !isZoomedToFill;
|
||||
setIsZoomedToFill(newZoomState);
|
||||
await (videoRef.current as SfPlayerViewRef)?.setVideoZoomToFill?.(
|
||||
newZoomState,
|
||||
);
|
||||
}, []);
|
||||
}, [isZoomedToFill, useVlcPlayer]);
|
||||
|
||||
// Prepare metadata for iOS native media controls
|
||||
const nowPlayingMetadata = useMemo(() => {
|
||||
if (!item || !api) return undefined;
|
||||
// Apply KSPlayer global settings before video loads (only when using KSPlayer)
|
||||
useEffect(() => {
|
||||
if (Platform.OS === "ios" && !useVlcPlayer) {
|
||||
setHardwareDecode(settings.ksHardwareDecode);
|
||||
}
|
||||
}, [settings.ksHardwareDecode, useVlcPlayer]);
|
||||
|
||||
const artworkUri = getPrimaryImageUrl({
|
||||
api,
|
||||
item,
|
||||
quality: 90,
|
||||
width: 500,
|
||||
});
|
||||
// Apply subtitle settings when video loads (SfPlayer-specific)
|
||||
useEffect(() => {
|
||||
if (useVlcPlayer || !isVideoLoaded || !videoRef.current) return;
|
||||
|
||||
return {
|
||||
title: item.Name || "",
|
||||
artist:
|
||||
item.Type === "Episode"
|
||||
? item.SeriesName || ""
|
||||
: item.AlbumArtist || "",
|
||||
albumTitle:
|
||||
item.Type === "Episode" && item.SeasonName
|
||||
? item.SeasonName
|
||||
: undefined,
|
||||
artworkUri: artworkUri || undefined,
|
||||
const sfRef = videoRef.current as SfPlayerViewRef;
|
||||
const applySubtitleSettings = async () => {
|
||||
if (settings.mpvSubtitleScale !== undefined) {
|
||||
await sfRef?.setSubtitleScale?.(settings.mpvSubtitleScale);
|
||||
}
|
||||
if (settings.mpvSubtitleMarginY !== undefined) {
|
||||
await sfRef?.setSubtitleMarginY?.(settings.mpvSubtitleMarginY);
|
||||
}
|
||||
if (settings.mpvSubtitleAlignX !== undefined) {
|
||||
await sfRef?.setSubtitleAlignX?.(settings.mpvSubtitleAlignX);
|
||||
}
|
||||
if (settings.mpvSubtitleAlignY !== undefined) {
|
||||
await sfRef?.setSubtitleAlignY?.(settings.mpvSubtitleAlignY);
|
||||
}
|
||||
if (settings.mpvSubtitleFontSize !== undefined) {
|
||||
await sfRef?.setSubtitleFontSize?.(settings.mpvSubtitleFontSize);
|
||||
}
|
||||
// Apply subtitle size from general settings
|
||||
if (settings.subtitleSize) {
|
||||
await sfRef?.setSubtitleFontSize?.(settings.subtitleSize);
|
||||
}
|
||||
};
|
||||
}, [item, api]);
|
||||
|
||||
applySubtitleSettings();
|
||||
}, [isVideoLoaded, settings, useVlcPlayer]);
|
||||
|
||||
// Show error UI first, before checking loading/missing‐data
|
||||
if (itemStatus.isError || streamStatus.isError) {
|
||||
@@ -708,7 +938,7 @@ export default function page() {
|
||||
);
|
||||
}
|
||||
|
||||
// Then show loader while either side is still fetching or data isn’t present
|
||||
// Then show loader while either side is still fetching or data isn't present
|
||||
if (itemStatus.isLoading || streamStatus.isLoading || !item || !stream) {
|
||||
// …loader UI…
|
||||
return (
|
||||
@@ -726,91 +956,117 @@ export default function page() {
|
||||
);
|
||||
|
||||
return (
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
backgroundColor: "black",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
}}
|
||||
<PlayerProvider
|
||||
playerRef={videoRef}
|
||||
item={item}
|
||||
mediaSource={stream?.mediaSource}
|
||||
isVideoLoaded={isVideoLoaded}
|
||||
tracksReady={tracksReady}
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
position: "relative",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
<VlcPlayerView
|
||||
ref={videoRef}
|
||||
source={{
|
||||
uri: stream?.url || "",
|
||||
autoplay: true,
|
||||
isNetwork: !offline,
|
||||
startPosition,
|
||||
externalSubtitles,
|
||||
initOptions,
|
||||
<VideoProvider>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
backgroundColor: "black",
|
||||
height: "100%",
|
||||
width: "100%",
|
||||
}}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
nowPlayingMetadata={nowPlayingMetadata}
|
||||
onVideoProgress={onProgress}
|
||||
progressUpdateInterval={1000}
|
||||
onVideoStateChange={onPlaybackStateChanged}
|
||||
onVideoLoadEnd={() => {
|
||||
setIsVideoLoaded(true);
|
||||
}}
|
||||
onVideoError={(e) => {
|
||||
console.error("Video Error:", e.nativeEvent);
|
||||
Alert.alert(
|
||||
t("player.error"),
|
||||
t("player.an_error_occured_while_playing_the_video"),
|
||||
);
|
||||
writeToLog("ERROR", "Video Error", e.nativeEvent);
|
||||
}}
|
||||
onPipStarted={(e) => {
|
||||
setIsPipMode(e.nativeEvent.pipStarted);
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
{isMounted === true && item && !isPipMode && (
|
||||
<Controls
|
||||
mediaSource={stream?.mediaSource}
|
||||
item={item}
|
||||
videoRef={videoRef}
|
||||
togglePlay={togglePlay}
|
||||
isPlaying={isPlaying}
|
||||
isSeeking={isSeeking}
|
||||
progress={progress}
|
||||
cacheProgress={cacheProgress}
|
||||
isBuffering={isBuffering}
|
||||
showControls={showControls}
|
||||
setShowControls={setShowControls}
|
||||
isVideoLoaded={isVideoLoaded}
|
||||
startPictureInPicture={startPictureInPicture}
|
||||
play={play}
|
||||
pause={pause}
|
||||
seek={seek}
|
||||
enableTrickplay={true}
|
||||
getAudioTracks={getAudioTracks}
|
||||
getSubtitleTracks={getSubtitleTracks}
|
||||
offline={offline}
|
||||
setSubtitleTrack={setSubtitleTrack}
|
||||
setSubtitleURL={setSubtitleURL}
|
||||
setAudioTrack={setAudioTrack}
|
||||
setVideoAspectRatio={setVideoAspectRatio}
|
||||
setVideoScaleFactor={setVideoScaleFactor}
|
||||
aspectRatio={aspectRatio}
|
||||
scaleFactor={scaleFactor}
|
||||
setAspectRatio={setAspectRatio}
|
||||
setScaleFactor={setScaleFactor}
|
||||
isVlc
|
||||
api={api}
|
||||
downloadedFiles={downloadedFiles}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
>
|
||||
<View
|
||||
style={{
|
||||
display: "flex",
|
||||
width: "100%",
|
||||
height: "100%",
|
||||
position: "relative",
|
||||
flexDirection: "column",
|
||||
justifyContent: "center",
|
||||
}}
|
||||
>
|
||||
{useVlcPlayer ? (
|
||||
<VlcPlayerView
|
||||
ref={videoRef as React.RefObject<VlcPlayerViewRef>}
|
||||
source={vlcVideoSource!}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
onVideoProgress={onProgressVlc}
|
||||
onVideoStateChange={onPlaybackStateChangedVlc}
|
||||
onPipStarted={onPipStartedVlc}
|
||||
onVideoLoadEnd={() => setIsVideoLoaded(true)}
|
||||
onVideoError={(e: PlaybackStatePayload) => {
|
||||
console.error("Video Error:", e.nativeEvent);
|
||||
Alert.alert(
|
||||
t("player.error"),
|
||||
t("player.an_error_occured_while_playing_the_video"),
|
||||
);
|
||||
writeToLog("ERROR", "Video Error", e.nativeEvent);
|
||||
}}
|
||||
progressUpdateInterval={1000}
|
||||
/>
|
||||
) : (
|
||||
<SfPlayerView
|
||||
ref={videoRef as React.RefObject<SfPlayerViewRef>}
|
||||
source={sfVideoSource}
|
||||
style={{ width: "100%", height: "100%" }}
|
||||
onProgress={onProgressSf}
|
||||
onPlaybackStateChange={onPlaybackStateChangedSf}
|
||||
onPictureInPictureChange={onPictureInPictureChangeSf}
|
||||
onLoad={() => setIsVideoLoaded(true)}
|
||||
onError={(e: { nativeEvent: SfOnErrorEventPayload }) => {
|
||||
console.error("Video Error:", e.nativeEvent);
|
||||
Alert.alert(
|
||||
t("player.error"),
|
||||
t("player.an_error_occured_while_playing_the_video"),
|
||||
);
|
||||
writeToLog("ERROR", "Video Error", e.nativeEvent);
|
||||
}}
|
||||
onTracksReady={() => {
|
||||
setTracksReady(true);
|
||||
}}
|
||||
/>
|
||||
)}
|
||||
{!hasPlaybackStarted && (
|
||||
<View
|
||||
style={{
|
||||
position: "absolute",
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
backgroundColor: "black",
|
||||
justifyContent: "center",
|
||||
alignItems: "center",
|
||||
}}
|
||||
>
|
||||
<Loader />
|
||||
</View>
|
||||
)}
|
||||
</View>
|
||||
{isMounted === true && item && !isPipMode && (
|
||||
<Controls
|
||||
mediaSource={stream?.mediaSource}
|
||||
item={item}
|
||||
togglePlay={togglePlay}
|
||||
isPlaying={isPlaying}
|
||||
isSeeking={isSeeking}
|
||||
progress={progress}
|
||||
cacheProgress={cacheProgress}
|
||||
isBuffering={isBuffering}
|
||||
showControls={showControls}
|
||||
setShowControls={setShowControls}
|
||||
startPictureInPicture={startPictureInPicture}
|
||||
play={play}
|
||||
pause={pause}
|
||||
seek={seek}
|
||||
enableTrickplay={true}
|
||||
offline={offline}
|
||||
aspectRatio={aspectRatio}
|
||||
isZoomedToFill={isZoomedToFill}
|
||||
onZoomToggle={handleZoomToggle}
|
||||
api={api}
|
||||
downloadedFiles={downloadedFiles}
|
||||
/>
|
||||
)}
|
||||
</View>
|
||||
</VideoProvider>
|
||||
</PlayerProvider>
|
||||
);
|
||||
}
|
||||
|
||||
105
app/_layout.tsx
105
app/_layout.tsx
@@ -15,6 +15,7 @@ import {
|
||||
getOrSetDeviceId,
|
||||
JellyfinProvider,
|
||||
} from "@/providers/JellyfinProvider";
|
||||
import { MusicPlayerProvider } from "@/providers/MusicPlayerProvider";
|
||||
import { NetworkStatusProvider } from "@/providers/NetworkStatusProvider";
|
||||
import { PlaySettingsProvider } from "@/providers/PlaySettingsProvider";
|
||||
import { WebSocketProvider } from "@/providers/WebSocketProvider";
|
||||
@@ -344,55 +345,65 @@ function Layout() {
|
||||
<LogProvider>
|
||||
<WebSocketProvider>
|
||||
<DownloadProvider>
|
||||
<GlobalModalProvider>
|
||||
<BottomSheetModalProvider>
|
||||
<ThemeProvider value={DarkTheme}>
|
||||
<SystemBars style='light' hidden={false} />
|
||||
<Stack initialRouteName='(auth)/(tabs)'>
|
||||
<Stack.Screen
|
||||
name='(auth)/(tabs)'
|
||||
options={{
|
||||
headerShown: false,
|
||||
title: "",
|
||||
header: () => null,
|
||||
<MusicPlayerProvider>
|
||||
<GlobalModalProvider>
|
||||
<BottomSheetModalProvider>
|
||||
<ThemeProvider value={DarkTheme}>
|
||||
<SystemBars style='light' hidden={false} />
|
||||
<Stack initialRouteName='(auth)/(tabs)'>
|
||||
<Stack.Screen
|
||||
name='(auth)/(tabs)'
|
||||
options={{
|
||||
headerShown: false,
|
||||
title: "",
|
||||
header: () => null,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='(auth)/player'
|
||||
options={{
|
||||
headerShown: false,
|
||||
title: "",
|
||||
header: () => null,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='(auth)/now-playing'
|
||||
options={{
|
||||
headerShown: false,
|
||||
presentation: "modal",
|
||||
gestureEnabled: true,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='login'
|
||||
options={{
|
||||
headerShown: true,
|
||||
title: "",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen name='+not-found' />
|
||||
</Stack>
|
||||
<Toaster
|
||||
duration={4000}
|
||||
toastOptions={{
|
||||
style: {
|
||||
backgroundColor: "#262626",
|
||||
borderColor: "#363639",
|
||||
borderWidth: 1,
|
||||
},
|
||||
titleStyle: {
|
||||
color: "white",
|
||||
},
|
||||
}}
|
||||
closeButton
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='(auth)/player'
|
||||
options={{
|
||||
headerShown: false,
|
||||
title: "",
|
||||
header: () => null,
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name='login'
|
||||
options={{
|
||||
headerShown: true,
|
||||
title: "",
|
||||
headerTransparent: Platform.OS === "ios",
|
||||
}}
|
||||
/>
|
||||
<Stack.Screen name='+not-found' />
|
||||
</Stack>
|
||||
<Toaster
|
||||
duration={4000}
|
||||
toastOptions={{
|
||||
style: {
|
||||
backgroundColor: "#262626",
|
||||
borderColor: "#363639",
|
||||
borderWidth: 1,
|
||||
},
|
||||
titleStyle: {
|
||||
color: "white",
|
||||
},
|
||||
}}
|
||||
closeButton
|
||||
/>
|
||||
<GlobalModal />
|
||||
</ThemeProvider>
|
||||
</BottomSheetModalProvider>
|
||||
</GlobalModalProvider>
|
||||
<GlobalModal />
|
||||
</ThemeProvider>
|
||||
</BottomSheetModalProvider>
|
||||
</GlobalModalProvider>
|
||||
</MusicPlayerProvider>
|
||||
</DownloadProvider>
|
||||
</WebSocketProvider>
|
||||
</LogProvider>
|
||||
|
||||
@@ -262,12 +262,12 @@ const Login: React.FC = () => {
|
||||
<Input
|
||||
placeholder={t("login.username_placeholder")}
|
||||
onChangeText={(text: string) =>
|
||||
setCredentials({ ...credentials, username: text })
|
||||
setCredentials((prev) => ({ ...prev, username: text }))
|
||||
}
|
||||
onEndEditing={(e) => {
|
||||
const newValue = e.nativeEvent.text;
|
||||
if (newValue && newValue !== credentials.username) {
|
||||
setCredentials({ ...credentials, username: newValue });
|
||||
setCredentials((prev) => ({ ...prev, username: newValue }));
|
||||
}
|
||||
}}
|
||||
value={credentials.username}
|
||||
@@ -286,12 +286,12 @@ const Login: React.FC = () => {
|
||||
<Input
|
||||
placeholder={t("login.password_placeholder")}
|
||||
onChangeText={(text: string) =>
|
||||
setCredentials({ ...credentials, password: text })
|
||||
setCredentials((prev) => ({ ...prev, password: text }))
|
||||
}
|
||||
onEndEditing={(e) => {
|
||||
const newValue = e.nativeEvent.text;
|
||||
if (newValue && newValue !== credentials.password) {
|
||||
setCredentials({ ...credentials, password: newValue });
|
||||
setCredentials((prev) => ({ ...prev, password: newValue }));
|
||||
}
|
||||
}}
|
||||
value={credentials.password}
|
||||
@@ -398,8 +398,8 @@ const Login: React.FC = () => {
|
||||
style={{ flex: 1 }}
|
||||
>
|
||||
{api?.basePath ? (
|
||||
<View className='flex flex-col flex-1 items-center justify-center'>
|
||||
<View className='px-4 -mt-20 w-full'>
|
||||
<View className='flex flex-col flex-1 justify-center'>
|
||||
<View className='px-4 w-full'>
|
||||
<View className='flex flex-col space-y-2'>
|
||||
<Text className='text-2xl font-bold -mb-2'>
|
||||
{serverName ? (
|
||||
@@ -415,12 +415,15 @@ const Login: React.FC = () => {
|
||||
<Input
|
||||
placeholder={t("login.username_placeholder")}
|
||||
onChangeText={(text) =>
|
||||
setCredentials({ ...credentials, username: text })
|
||||
setCredentials((prev) => ({ ...prev, username: text }))
|
||||
}
|
||||
onEndEditing={(e) => {
|
||||
const newValue = e.nativeEvent.text;
|
||||
if (newValue && newValue !== credentials.username) {
|
||||
setCredentials({ ...credentials, username: newValue });
|
||||
setCredentials((prev) => ({
|
||||
...prev,
|
||||
username: newValue,
|
||||
}));
|
||||
}
|
||||
}}
|
||||
value={credentials.username}
|
||||
@@ -437,12 +440,15 @@ const Login: React.FC = () => {
|
||||
<Input
|
||||
placeholder={t("login.password_placeholder")}
|
||||
onChangeText={(text) =>
|
||||
setCredentials({ ...credentials, password: text })
|
||||
setCredentials((prev) => ({ ...prev, password: text }))
|
||||
}
|
||||
onEndEditing={(e) => {
|
||||
const newValue = e.nativeEvent.text;
|
||||
if (newValue && newValue !== credentials.password) {
|
||||
setCredentials({ ...credentials, password: newValue });
|
||||
setCredentials((prev) => ({
|
||||
...prev,
|
||||
password: newValue,
|
||||
}));
|
||||
}
|
||||
}}
|
||||
value={credentials.password}
|
||||
|
||||
Reference in New Issue
Block a user