mirror of
https://github.com/zimplexing/OrionTV.git
synced 2026-02-16 05:04:42 +08:00
Compare commits
14 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
803fc87fd9 | ||
|
|
d42a3e014e | ||
|
|
83bf083a6f | ||
|
|
c9e5464000 | ||
|
|
30724a1e19 | ||
|
|
5043b33222 | ||
|
|
b238ffe3ba | ||
|
|
74ad0872cb | ||
|
|
504f12067b | ||
|
|
9f721c22d5 | ||
|
|
5b4c8db317 | ||
|
|
d8f7953109 | ||
|
|
bd22fa2996 | ||
|
|
08e24dd748 |
6
.prettierrc
Normal file
6
.prettierrc
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"tabWidth": 2,
|
||||||
|
"useTabs": false,
|
||||||
|
"singleQuote": false,
|
||||||
|
"printWidth": 120
|
||||||
|
}
|
||||||
@@ -107,7 +107,11 @@ yarn android-tv
|
|||||||
|
|
||||||
#### 使用 demo 地址
|
#### 使用 demo 地址
|
||||||
|
|
||||||
在设置中可以使用 demo 地址: https://orion-tv.vercel.app 需要代理且不保证稳定和可用性。
|
在设置中可以使用 demo 地址:https://orion-tv.edu.deal 不保证稳定和可用性。
|
||||||
|
|
||||||
|
## 其他
|
||||||
|
- 最低版本是android 7,可用,但是不推荐
|
||||||
|
- 如果使用https的后端接口无法访问,在确认服务没有问题的情况下,请检查https的TLS协议,Android 10 之后版本才支持 TLS1.3
|
||||||
|
|
||||||
## 📜 主要脚本
|
## 📜 主要脚本
|
||||||
|
|
||||||
|
|||||||
@@ -1,13 +1,14 @@
|
|||||||
import {Link, Stack} from 'expo-router';
|
import { Link, Stack } from "expo-router";
|
||||||
import {StyleSheet} from 'react-native';
|
import { StyleSheet } from "react-native";
|
||||||
|
|
||||||
import {ThemedText} from '@/components/ThemedText';
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
import {ThemedView} from '@/components/ThemedView';
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
|
import React from "react";
|
||||||
|
|
||||||
export default function NotFoundScreen() {
|
export default function NotFoundScreen() {
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<Stack.Screen options={{title: 'Oops!'}} />
|
<Stack.Screen options={{ title: "Oops!" }} />
|
||||||
<ThemedView style={styles.container}>
|
<ThemedView style={styles.container}>
|
||||||
<ThemedText type="title">This screen doesn't exist.</ThemedText>
|
<ThemedText type="title">This screen doesn't exist.</ThemedText>
|
||||||
<Link href="/" style={styles.link}>
|
<Link href="/" style={styles.link}>
|
||||||
@@ -21,8 +22,8 @@ export default function NotFoundScreen() {
|
|||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: {
|
container: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
padding: 20,
|
padding: 20,
|
||||||
},
|
},
|
||||||
link: {
|
link: {
|
||||||
|
|||||||
@@ -1,25 +1,26 @@
|
|||||||
import {
|
import { DarkTheme, DefaultTheme, ThemeProvider } from "@react-navigation/native";
|
||||||
DarkTheme,
|
|
||||||
DefaultTheme,
|
|
||||||
ThemeProvider,
|
|
||||||
} from "@react-navigation/native";
|
|
||||||
import { useFonts } from "expo-font";
|
import { useFonts } from "expo-font";
|
||||||
import { Stack } from "expo-router";
|
import { Stack } from "expo-router";
|
||||||
import * as SplashScreen from "expo-splash-screen";
|
import * as SplashScreen from "expo-splash-screen";
|
||||||
import { useEffect } from "react";
|
import { useEffect } from "react";
|
||||||
import { Platform } from "react-native";
|
import { Platform } from "react-native";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
|
||||||
import { useColorScheme } from "@/hooks/useColorScheme";
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
import { initializeApi } from "@/services/api";
|
|
||||||
|
|
||||||
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
// Prevent the splash screen from auto-hiding before asset loading is complete.
|
||||||
SplashScreen.preventAutoHideAsync();
|
SplashScreen.preventAutoHideAsync();
|
||||||
|
|
||||||
export default function RootLayout() {
|
export default function RootLayout() {
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = "dark";
|
||||||
const [loaded, error] = useFonts({
|
const [loaded, error] = useFonts({
|
||||||
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
|
SpaceMono: require("../assets/fonts/SpaceMono-Regular.ttf"),
|
||||||
});
|
});
|
||||||
|
const initializeSettings = useSettingsStore((state) => state.loadSettings);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
initializeSettings();
|
||||||
|
}, [initializeSettings]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (loaded || error) {
|
if (loaded || error) {
|
||||||
@@ -30,10 +31,6 @@ export default function RootLayout() {
|
|||||||
}
|
}
|
||||||
}, [loaded, error]);
|
}, [loaded, error]);
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
initializeApi();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
if (!loaded && !error) {
|
if (!loaded && !error) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -43,12 +40,11 @@ export default function RootLayout() {
|
|||||||
<Stack>
|
<Stack>
|
||||||
<Stack.Screen name="index" options={{ headerShown: false }} />
|
<Stack.Screen name="index" options={{ headerShown: false }} />
|
||||||
<Stack.Screen name="detail" options={{ headerShown: false }} />
|
<Stack.Screen name="detail" options={{ headerShown: false }} />
|
||||||
{Platform.OS !== "web" && (
|
{Platform.OS !== "web" && <Stack.Screen name="play" options={{ headerShown: false }} />}
|
||||||
<Stack.Screen name="play" options={{ headerShown: false }} />
|
|
||||||
)}
|
|
||||||
<Stack.Screen name="search" options={{ headerShown: false }} />
|
<Stack.Screen name="search" options={{ headerShown: false }} />
|
||||||
<Stack.Screen name="+not-found" />
|
<Stack.Screen name="+not-found" />
|
||||||
</Stack>
|
</Stack>
|
||||||
|
<Toast />
|
||||||
</ThemeProvider>
|
</ThemeProvider>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
160
app/detail.tsx
160
app/detail.tsx
@@ -1,15 +1,17 @@
|
|||||||
import React, { useEffect, useState, useRef } from 'react';
|
import React, { useEffect, useState, useRef } from "react";
|
||||||
import { View, Text, StyleSheet, Image, ScrollView, ActivityIndicator } from 'react-native';
|
import { View, Text, StyleSheet, Image, ScrollView, ActivityIndicator, FlatList } from "react-native";
|
||||||
import { useLocalSearchParams, useRouter } from 'expo-router';
|
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||||
import { ThemedView } from '@/components/ThemedView';
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
import { ThemedText } from '@/components/ThemedText';
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
import { api, SearchResult } from '@/services/api';
|
import { api, SearchResult } from "@/services/api";
|
||||||
import { getResolutionFromM3U8 } from '@/services/m3u8';
|
import { getResolutionFromM3U8 } from "@/services/m3u8";
|
||||||
import { DetailButton } from '@/components/DetailButton';
|
import { StyledButton } from "@/components/StyledButton";
|
||||||
|
import { useResponsive } from "@/hooks/useResponsive";
|
||||||
|
|
||||||
export default function DetailScreen() {
|
export default function DetailScreen() {
|
||||||
const { source, q } = useLocalSearchParams();
|
const { source, q } = useLocalSearchParams();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { isMobile, screenWidth, numColumns } = useResponsive();
|
||||||
const [searchResults, setSearchResults] = useState<(SearchResult & { resolution?: string | null })[]>([]);
|
const [searchResults, setSearchResults] = useState<(SearchResult & { resolution?: string | null })[]>([]);
|
||||||
const [detail, setDetail] = useState<(SearchResult & { resolution?: string | null }) | null>(null);
|
const [detail, setDetail] = useState<(SearchResult & { resolution?: string | null }) | null>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
@@ -24,7 +26,7 @@ export default function DetailScreen() {
|
|||||||
controllerRef.current = new AbortController();
|
controllerRef.current = new AbortController();
|
||||||
const signal = controllerRef.current.signal;
|
const signal = controllerRef.current.signal;
|
||||||
|
|
||||||
if (typeof q === 'string') {
|
if (typeof q === "string") {
|
||||||
const fetchDetailData = async () => {
|
const fetchDetailData = async () => {
|
||||||
setLoading(true);
|
setLoading(true);
|
||||||
setSearchResults([]);
|
setSearchResults([]);
|
||||||
@@ -35,15 +37,15 @@ export default function DetailScreen() {
|
|||||||
try {
|
try {
|
||||||
const resources = await api.getResources(signal);
|
const resources = await api.getResources(signal);
|
||||||
if (!resources || resources.length === 0) {
|
if (!resources || resources.length === 0) {
|
||||||
setError('没有可用的播放源');
|
setError("没有可用的播放源");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let foundFirstResult = false;
|
let foundFirstResult = false;
|
||||||
// Prioritize source from params if available
|
// Prioritize source from params if available
|
||||||
if (typeof source === 'string') {
|
if (typeof source === "string") {
|
||||||
const index = resources.findIndex(r => r.key === source);
|
const index = resources.findIndex((r) => r.key === source);
|
||||||
if (index > 0) {
|
if (index > 0) {
|
||||||
resources.unshift(resources.splice(index, 1)[0]);
|
resources.unshift(resources.splice(index, 1)[0]);
|
||||||
}
|
}
|
||||||
@@ -61,14 +63,14 @@ export default function DetailScreen() {
|
|||||||
resolution = await getResolutionFromM3U8(searchResult.episodes[0], signal);
|
resolution = await getResolutionFromM3U8(searchResult.episodes[0], signal);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ((e as Error).name !== 'AbortError') {
|
if ((e as Error).name !== "AbortError") {
|
||||||
console.error(`Failed to get resolution for ${resource.name}`, e);
|
console.error(`Failed to get resolution for ${resource.name}`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const resultWithResolution = { ...searchResult, resolution };
|
const resultWithResolution = { ...searchResult, resolution };
|
||||||
|
|
||||||
setSearchResults(prev => [...prev, resultWithResolution]);
|
setSearchResults((prev) => [...prev, resultWithResolution]);
|
||||||
|
|
||||||
if (!foundFirstResult) {
|
if (!foundFirstResult) {
|
||||||
setDetail(resultWithResolution);
|
setDetail(resultWithResolution);
|
||||||
@@ -77,19 +79,19 @@ export default function DetailScreen() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ((e as Error).name !== 'AbortError') {
|
if ((e as Error).name !== "AbortError") {
|
||||||
console.error(`Error searching in resource ${resource.name}:`, e);
|
console.error(`Error searching in resource ${resource.name}:`, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!foundFirstResult) {
|
if (!foundFirstResult) {
|
||||||
setError('未找到播放源');
|
setError("未找到播放源");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if ((e as Error).name !== 'AbortError') {
|
if ((e as Error).name !== "AbortError") {
|
||||||
setError(e instanceof Error ? e.message : '获取资源列表失败');
|
setError(e instanceof Error ? e.message : "获取资源列表失败");
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@@ -108,7 +110,7 @@ export default function DetailScreen() {
|
|||||||
if (!detail) return;
|
if (!detail) return;
|
||||||
controllerRef.current?.abort(); // Cancel any ongoing fetches
|
controllerRef.current?.abort(); // Cancel any ongoing fetches
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/play',
|
pathname: "/play",
|
||||||
params: {
|
params: {
|
||||||
source: detail.source,
|
source: detail.source,
|
||||||
id: detail.id.toString(),
|
id: detail.id.toString(),
|
||||||
@@ -147,9 +149,12 @@ export default function DetailScreen() {
|
|||||||
return (
|
return (
|
||||||
<ThemedView style={styles.container}>
|
<ThemedView style={styles.container}>
|
||||||
<ScrollView>
|
<ScrollView>
|
||||||
<View style={styles.topContainer}>
|
<View style={[styles.topContainer, isMobile && screenWidth < 600 && styles.topContainerMobile]}>
|
||||||
<Image source={{ uri: detail.poster }} style={styles.poster} />
|
<Image
|
||||||
<View style={styles.infoContainer}>
|
source={{ uri: detail.poster }}
|
||||||
|
style={[styles.poster, isMobile && screenWidth < 600 && styles.posterMobile]}
|
||||||
|
/>
|
||||||
|
<View style={[styles.infoContainer, isMobile && screenWidth < 600 && styles.infoContainerMobile]}>
|
||||||
<ThemedText style={styles.title} numberOfLines={1}>
|
<ThemedText style={styles.title} numberOfLines={1}>
|
||||||
{detail.title}
|
{detail.title}
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
@@ -171,38 +176,52 @@ export default function DetailScreen() {
|
|||||||
</View>
|
</View>
|
||||||
<View style={styles.sourceList}>
|
<View style={styles.sourceList}>
|
||||||
{searchResults.map((item, index) => (
|
{searchResults.map((item, index) => (
|
||||||
<DetailButton
|
<StyledButton
|
||||||
key={index}
|
key={index}
|
||||||
onPress={() => setDetail(item)}
|
onPress={() => setDetail(item)}
|
||||||
hasTVPreferredFocus={index === 0}
|
hasTVPreferredFocus={index === 0}
|
||||||
style={[styles.sourceButton, detail?.source === item.source && styles.sourceButtonSelected]}
|
isSelected={detail?.source === item.source}
|
||||||
|
style={styles.sourceButton}
|
||||||
>
|
>
|
||||||
<ThemedText style={styles.sourceButtonText}>{item.source_name}</ThemedText>
|
<ThemedText style={styles.sourceButtonText}>{item.source_name}</ThemedText>
|
||||||
{item.episodes.length > 1 && (
|
{item.episodes.length > 1 && (
|
||||||
<View style={styles.badge}>
|
<View style={styles.badge}>
|
||||||
<Text style={styles.badgeText}>
|
<Text style={styles.badgeText}>
|
||||||
{item.episodes.length > 99 ? '99+' : `${item.episodes.length}`}
|
{item.episodes.length > 99 ? "99+" : `${item.episodes.length}`} 集
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
{item.resolution && (
|
{item.resolution && (
|
||||||
<View style={[styles.badge, { backgroundColor: '#28a745' }]}>
|
<View style={[styles.badge, { backgroundColor: "#28a745" }]}>
|
||||||
<Text style={styles.badgeText}>{item.resolution}</Text>
|
<Text style={styles.badgeText}>{item.resolution}</Text>
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
</DetailButton>
|
</StyledButton>
|
||||||
))}
|
))}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
<View style={styles.episodesContainer}>
|
<View style={styles.episodesContainer}>
|
||||||
<ThemedText style={styles.episodesTitle}>播放列表</ThemedText>
|
<ThemedText style={styles.episodesTitle}>播放列表</ThemedText>
|
||||||
<ScrollView contentContainerStyle={styles.episodeList}>
|
<FlatList
|
||||||
{detail.episodes.map((episode, index) => (
|
data={detail.episodes}
|
||||||
<DetailButton key={index} style={styles.episodeButton} onPress={() => handlePlay(episode, index)}>
|
renderItem={({ item, index }) => (
|
||||||
<ThemedText style={styles.episodeButtonText}>{`第 ${index + 1} 集`}</ThemedText>
|
<StyledButton
|
||||||
</DetailButton>
|
style={styles.episodeButton}
|
||||||
))}
|
onPress={() => handlePlay(item, index)}
|
||||||
</ScrollView>
|
text={`第 ${index + 1} 集`}
|
||||||
|
textStyle={styles.episodeButtonText}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
keyExtractor={(_item, index) => index.toString()}
|
||||||
|
numColumns={numColumns(80, 10)}
|
||||||
|
key={numColumns(80, 10)} // Re-render on column change
|
||||||
|
contentContainerStyle={styles.episodeList}
|
||||||
|
// The FlatList should not be scrollable itself, the parent ScrollView handles it.
|
||||||
|
// This can be achieved by making it non-scrollable and letting it expand.
|
||||||
|
// However, for performance, if the list is very long, a fixed height would be better.
|
||||||
|
// For now, we let the parent ScrollView handle scrolling.
|
||||||
|
scrollEnabled={false}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</ScrollView>
|
</ScrollView>
|
||||||
@@ -212,33 +231,48 @@ export default function DetailScreen() {
|
|||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
container: { flex: 1 },
|
container: { flex: 1 },
|
||||||
centered: { flex: 1, justifyContent: 'center', alignItems: 'center' },
|
centered: { flex: 1, justifyContent: "center", alignItems: "center" },
|
||||||
topContainer: {
|
topContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
padding: 20,
|
padding: 20,
|
||||||
},
|
},
|
||||||
|
topContainerMobile: {
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
poster: {
|
poster: {
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 300,
|
height: 300,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
},
|
},
|
||||||
|
posterMobile: {
|
||||||
|
width: "80%",
|
||||||
|
height: undefined,
|
||||||
|
aspectRatio: 2 / 3, // Maintain aspect ratio
|
||||||
|
marginBottom: 20,
|
||||||
|
},
|
||||||
infoContainer: {
|
infoContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
marginLeft: 20,
|
marginLeft: 20,
|
||||||
justifyContent: 'flex-start',
|
justifyContent: "flex-start",
|
||||||
|
},
|
||||||
|
infoContainerMobile: {
|
||||||
|
marginLeft: 0,
|
||||||
|
width: "100%",
|
||||||
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
fontSize: 28,
|
fontSize: 28,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
paddingTop: 20,
|
paddingTop: 20,
|
||||||
},
|
},
|
||||||
metaContainer: {
|
metaContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
metaText: {
|
metaText: {
|
||||||
color: '#aaa',
|
color: "#aaa",
|
||||||
marginRight: 10,
|
marginRight: 10,
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
},
|
},
|
||||||
@@ -247,7 +281,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: '#ccc',
|
color: "#ccc",
|
||||||
lineHeight: 22,
|
lineHeight: 22,
|
||||||
},
|
},
|
||||||
bottomContainer: {
|
bottomContainer: {
|
||||||
@@ -257,70 +291,52 @@ const styles = StyleSheet.create({
|
|||||||
marginTop: 20,
|
marginTop: 20,
|
||||||
},
|
},
|
||||||
sourcesTitleContainer: {
|
sourcesTitleContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
sourcesTitle: {
|
sourcesTitle: {
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
sourceList: {
|
sourceList: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
flexWrap: 'wrap',
|
flexWrap: "wrap",
|
||||||
},
|
},
|
||||||
sourceButton: {
|
sourceButton: {
|
||||||
backgroundColor: '#333',
|
margin: 8,
|
||||||
paddingHorizontal: 15,
|
|
||||||
paddingVertical: 10,
|
|
||||||
borderRadius: 8,
|
|
||||||
margin: 5,
|
|
||||||
flexDirection: 'row',
|
|
||||||
alignItems: 'center',
|
|
||||||
borderWidth: 2,
|
|
||||||
borderColor: 'transparent',
|
|
||||||
},
|
|
||||||
sourceButtonSelected: {
|
|
||||||
backgroundColor: '#007bff',
|
|
||||||
},
|
},
|
||||||
sourceButtonText: {
|
sourceButtonText: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
},
|
},
|
||||||
badge: {
|
badge: {
|
||||||
backgroundColor: 'red',
|
backgroundColor: "red",
|
||||||
borderRadius: 10,
|
borderRadius: 10,
|
||||||
paddingHorizontal: 6,
|
paddingHorizontal: 6,
|
||||||
paddingVertical: 2,
|
paddingVertical: 2,
|
||||||
marginLeft: 8,
|
marginLeft: 8,
|
||||||
},
|
},
|
||||||
badgeText: {
|
badgeText: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
episodesContainer: {
|
episodesContainer: {
|
||||||
marginTop: 20,
|
marginTop: 20,
|
||||||
},
|
},
|
||||||
episodesTitle: {
|
episodesTitle: {
|
||||||
fontSize: 20,
|
fontSize: 20,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
episodeList: {
|
episodeList: {
|
||||||
flexDirection: 'row',
|
// flexDirection is now handled by FlatList's numColumns
|
||||||
flexWrap: 'wrap',
|
|
||||||
},
|
},
|
||||||
episodeButton: {
|
episodeButton: {
|
||||||
backgroundColor: '#333',
|
|
||||||
paddingHorizontal: 20,
|
|
||||||
paddingVertical: 10,
|
|
||||||
borderRadius: 8,
|
|
||||||
margin: 5,
|
margin: 5,
|
||||||
borderWidth: 2,
|
|
||||||
borderColor: 'transparent',
|
|
||||||
},
|
},
|
||||||
episodeButtonText: {
|
episodeButtonText: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
309
app/index.tsx
309
app/index.tsx
@@ -1,214 +1,72 @@
|
|||||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
import React, { useEffect, useCallback, useRef } from "react";
|
||||||
import { View, StyleSheet, ActivityIndicator, FlatList, Pressable, Dimensions } from 'react-native';
|
import { View, StyleSheet, ActivityIndicator, FlatList, Pressable } from "react-native";
|
||||||
import { ThemedView } from '@/components/ThemedView';
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
import { ThemedText } from '@/components/ThemedText';
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
import { api } from '@/services/api';
|
import { api } from "@/services/api";
|
||||||
import { SearchResult } from '@/services/api';
|
import VideoCard from "@/components/VideoCard.tv";
|
||||||
import { PlayRecord } from '@/services/storage';
|
import { useFocusEffect, useRouter } from "expo-router";
|
||||||
|
import { Search, Settings } from "lucide-react-native";
|
||||||
export type RowItem = (SearchResult | PlayRecord) & {
|
import { SettingsModal } from "@/components/SettingsModal";
|
||||||
id: string;
|
import { StyledButton } from "@/components/StyledButton";
|
||||||
source: string;
|
import useHomeStore, { RowItem, Category } from "@/stores/homeStore";
|
||||||
title: string;
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
poster: string;
|
import { useResponsive } from "@/hooks/useResponsive";
|
||||||
progress?: number;
|
|
||||||
lastPlayed?: number;
|
|
||||||
episodeIndex?: number;
|
|
||||||
sourceName?: string;
|
|
||||||
totalEpisodes?: number;
|
|
||||||
year?: string;
|
|
||||||
rate?: string;
|
|
||||||
};
|
|
||||||
import VideoCard from '@/components/VideoCard.tv';
|
|
||||||
import { PlayRecordManager } from '@/services/storage';
|
|
||||||
import { useFocusEffect, useRouter } from 'expo-router';
|
|
||||||
import { useColorScheme } from 'react-native';
|
|
||||||
import { Search, Settings } from 'lucide-react-native';
|
|
||||||
import { SettingsModal } from '@/components/SettingsModal';
|
|
||||||
|
|
||||||
// --- 类别定义 ---
|
|
||||||
interface Category {
|
|
||||||
title: string;
|
|
||||||
type?: 'movie' | 'tv' | 'record';
|
|
||||||
tag?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
const initialCategories: Category[] = [
|
|
||||||
{ title: '最近播放', type: 'record' },
|
|
||||||
{ title: '热门剧集', type: 'tv', tag: '热门' },
|
|
||||||
{ title: '综艺', type: 'tv', tag: '综艺' },
|
|
||||||
{ title: '热门电影', type: 'movie', tag: '热门' },
|
|
||||||
{ title: '豆瓣 Top250', type: 'movie', tag: 'top250' },
|
|
||||||
{ title: '儿童', type: 'movie', tag: '少儿' },
|
|
||||||
{ title: '美剧', type: 'tv', tag: '美剧' },
|
|
||||||
{ title: '韩剧', type: 'tv', tag: '韩剧' },
|
|
||||||
{ title: '日剧', type: 'tv', tag: '日剧' },
|
|
||||||
{ title: '日漫', type: 'tv', tag: '日本动画' },
|
|
||||||
];
|
|
||||||
|
|
||||||
const NUM_COLUMNS = 5;
|
|
||||||
const { width } = Dimensions.get('window');
|
|
||||||
const ITEM_WIDTH = width / NUM_COLUMNS - 24;
|
|
||||||
|
|
||||||
export default function HomeScreen() {
|
export default function HomeScreen() {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const colorScheme = useColorScheme();
|
const { isMobile, screenWidth, numColumns } = useResponsive();
|
||||||
|
const colorScheme = "dark";
|
||||||
const [categories, setCategories] = useState<Category[]>(initialCategories);
|
|
||||||
const [selectedCategory, setSelectedCategory] = useState<Category>(categories[0]);
|
|
||||||
const [contentData, setContentData] = useState<RowItem[]>([]);
|
|
||||||
|
|
||||||
const [loading, setLoading] = useState(true);
|
|
||||||
const [loadingMore, setLoadingMore] = useState(false);
|
|
||||||
const [error, setError] = useState<string | null>(null);
|
|
||||||
const [isSettingsVisible, setSettingsVisible] = useState(false);
|
|
||||||
|
|
||||||
const [pageStart, setPageStart] = useState(0);
|
|
||||||
const [hasMore, setHasMore] = useState(true);
|
|
||||||
|
|
||||||
const flatListRef = useRef<FlatList>(null);
|
const flatListRef = useRef<FlatList>(null);
|
||||||
|
|
||||||
// --- 数据获取逻辑 ---
|
// Calculate item width based on screen size and number of columns
|
||||||
const fetchPlayRecords = async () => {
|
const itemWidth = isMobile ? screenWidth / numColumns(150, 16) - 24 : screenWidth / 5 - 24;
|
||||||
const records = await PlayRecordManager.getAll();
|
const calculatedNumColumns = numColumns(150, 16);
|
||||||
return Object.entries(records)
|
|
||||||
.map(([key, record]) => {
|
|
||||||
const [source, id] = key.split('+');
|
|
||||||
return {
|
|
||||||
id,
|
|
||||||
source,
|
|
||||||
title: record.title,
|
|
||||||
poster: record.cover,
|
|
||||||
progress: record.play_time / record.total_time,
|
|
||||||
lastPlayed: record.save_time,
|
|
||||||
episodeIndex: record.index,
|
|
||||||
sourceName: record.source_name,
|
|
||||||
totalEpisodes: record.total_episodes,
|
|
||||||
} as RowItem;
|
|
||||||
})
|
|
||||||
.filter(record => record.progress !== undefined && record.progress > 0 && record.progress < 1)
|
|
||||||
.sort((a, b) => (b.lastPlayed || 0) - (a.lastPlayed || 0));
|
|
||||||
};
|
|
||||||
|
|
||||||
const fetchData = async (category: Category, start: number, preloadedRecords?: RowItem[]) => {
|
const {
|
||||||
if (category.type === 'record') {
|
categories,
|
||||||
const records = preloadedRecords ?? (await fetchPlayRecords());
|
selectedCategory,
|
||||||
if (records.length === 0 && categories.some(c => c.type === 'record')) {
|
contentData,
|
||||||
// 如果没有播放记录,则移除"最近播放"分类并选择第一个真实分类
|
loading,
|
||||||
const newCategories = categories.filter(c => c.type !== 'record');
|
loadingMore,
|
||||||
setCategories(newCategories);
|
error,
|
||||||
if (newCategories.length > 0) {
|
fetchInitialData,
|
||||||
handleCategorySelect(newCategories[0]);
|
loadMoreData,
|
||||||
}
|
selectCategory,
|
||||||
} else {
|
refreshPlayRecords,
|
||||||
setContentData(records);
|
} = useHomeStore();
|
||||||
setHasMore(false);
|
|
||||||
}
|
|
||||||
setLoading(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!category.type || !category.tag) return;
|
const showSettingsModal = useSettingsStore((state) => state.showModal);
|
||||||
|
|
||||||
setLoadingMore(start > 0);
|
|
||||||
setError(null);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const result = await api.getDoubanData(category.type, category.tag, 20, start);
|
|
||||||
|
|
||||||
if (result.list.length === 0) {
|
|
||||||
setHasMore(false);
|
|
||||||
} else {
|
|
||||||
const newItems = result.list.map(item => ({
|
|
||||||
...item,
|
|
||||||
id: item.title, // 临时ID
|
|
||||||
source: 'douban',
|
|
||||||
})) as RowItem[];
|
|
||||||
|
|
||||||
setContentData(prev => (start === 0 ? newItems : [...prev, ...newItems]));
|
|
||||||
setPageStart(prev => prev + result.list.length);
|
|
||||||
setHasMore(true);
|
|
||||||
}
|
|
||||||
} catch (err: any) {
|
|
||||||
if (err.message === 'API_URL_NOT_SET') {
|
|
||||||
setError('请点击右上角设置按钮,配置您的 API 地址');
|
|
||||||
} else {
|
|
||||||
setError('加载失败,请重试');
|
|
||||||
}
|
|
||||||
} finally {
|
|
||||||
setLoading(false);
|
|
||||||
setLoadingMore(false);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// --- Effects ---
|
|
||||||
useFocusEffect(
|
useFocusEffect(
|
||||||
useCallback(() => {
|
useCallback(() => {
|
||||||
const manageRecordCategory = async () => {
|
refreshPlayRecords();
|
||||||
const records = await fetchPlayRecords();
|
}, [refreshPlayRecords])
|
||||||
const hasRecords = records.length > 0;
|
|
||||||
|
|
||||||
setCategories(currentCategories => {
|
|
||||||
const recordCategoryExists = currentCategories.some(c => c.type === 'record');
|
|
||||||
if (hasRecords && !recordCategoryExists) {
|
|
||||||
// Add 'Recent Plays' if records exist and the tab doesn't
|
|
||||||
return [initialCategories[0], ...currentCategories];
|
|
||||||
}
|
|
||||||
return currentCategories;
|
|
||||||
});
|
|
||||||
|
|
||||||
// If 'Recent Plays' is selected, always refresh its data.
|
|
||||||
// This will also handle removing the tab if records have disappeared.
|
|
||||||
if (selectedCategory.type === 'record') {
|
|
||||||
loadInitialData(records);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
manageRecordCategory();
|
|
||||||
}, [selectedCategory])
|
|
||||||
);
|
);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
loadInitialData();
|
fetchInitialData();
|
||||||
}, [selectedCategory]);
|
|
||||||
|
|
||||||
const loadInitialData = (records?: RowItem[]) => {
|
|
||||||
setLoading(true);
|
|
||||||
setContentData([]);
|
|
||||||
setPageStart(0);
|
|
||||||
setHasMore(true);
|
|
||||||
flatListRef.current?.scrollToOffset({ animated: false, offset: 0 });
|
flatListRef.current?.scrollToOffset({ animated: false, offset: 0 });
|
||||||
fetchData(selectedCategory, 0, records);
|
}, [selectedCategory, fetchInitialData]);
|
||||||
};
|
|
||||||
|
|
||||||
const loadMoreData = () => {
|
|
||||||
if (loading || loadingMore || !hasMore || selectedCategory.type === 'record') return;
|
|
||||||
fetchData(selectedCategory, pageStart);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleCategorySelect = (category: Category) => {
|
const handleCategorySelect = (category: Category) => {
|
||||||
setSelectedCategory(category);
|
selectCategory(category);
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- 渲染组件 ---
|
|
||||||
const renderCategory = ({ item }: { item: Category }) => {
|
const renderCategory = ({ item }: { item: Category }) => {
|
||||||
const isSelected = selectedCategory.title === item.title;
|
const isSelected = selectedCategory?.title === item.title;
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<StyledButton
|
||||||
style={({ focused }) => [
|
text={item.title}
|
||||||
styles.categoryButton,
|
|
||||||
isSelected && styles.categoryButtonSelected,
|
|
||||||
focused && styles.categoryButtonFocused,
|
|
||||||
]}
|
|
||||||
onPress={() => handleCategorySelect(item)}
|
onPress={() => handleCategorySelect(item)}
|
||||||
>
|
isSelected={isSelected}
|
||||||
<ThemedText style={[styles.categoryText, isSelected && styles.categoryTextSelected]}>{item.title}</ThemedText>
|
style={styles.categoryButton}
|
||||||
</Pressable>
|
textStyle={styles.categoryText}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderContentItem = ({ item }: { item: RowItem }) => (
|
const renderContentItem = ({ item }: { item: RowItem }) => (
|
||||||
<View style={styles.itemContainer}>
|
<View style={[styles.itemContainer, { width: itemWidth }]}>
|
||||||
<VideoCard
|
<VideoCard
|
||||||
id={item.id}
|
id={item.id}
|
||||||
source={item.source}
|
source={item.source}
|
||||||
@@ -217,11 +75,12 @@ export default function HomeScreen() {
|
|||||||
year={item.year}
|
year={item.year}
|
||||||
rate={item.rate}
|
rate={item.rate}
|
||||||
progress={item.progress}
|
progress={item.progress}
|
||||||
|
playTime={item.play_time}
|
||||||
episodeIndex={item.episodeIndex}
|
episodeIndex={item.episodeIndex}
|
||||||
sourceName={item.sourceName}
|
sourceName={item.sourceName}
|
||||||
totalEpisodes={item.totalEpisodes}
|
totalEpisodes={item.totalEpisodes}
|
||||||
api={api}
|
api={api}
|
||||||
onRecordDeleted={loadInitialData} // For "Recent Plays"
|
onRecordDeleted={fetchInitialData} // For "Recent Plays"
|
||||||
/>
|
/>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -237,18 +96,16 @@ export default function HomeScreen() {
|
|||||||
<View style={styles.headerContainer}>
|
<View style={styles.headerContainer}>
|
||||||
<ThemedText style={styles.headerTitle}>首页</ThemedText>
|
<ThemedText style={styles.headerTitle}>首页</ThemedText>
|
||||||
<View style={styles.rightHeaderButtons}>
|
<View style={styles.rightHeaderButtons}>
|
||||||
<Pressable
|
<StyledButton
|
||||||
style={({ focused }) => [styles.searchButton, focused && styles.searchButtonFocused]}
|
style={styles.searchButton}
|
||||||
onPress={() => router.push({ pathname: '/search' })}
|
onPress={() => router.push({ pathname: "/search" })}
|
||||||
|
variant="ghost"
|
||||||
>
|
>
|
||||||
<Search color={colorScheme === 'dark' ? 'white' : 'black'} size={24} />
|
<Search color={colorScheme === "dark" ? "white" : "black"} size={24} />
|
||||||
</Pressable>
|
</StyledButton>
|
||||||
<Pressable
|
<StyledButton style={styles.searchButton} onPress={showSettingsModal} variant="ghost">
|
||||||
style={({ focused }) => [styles.searchButton, focused && styles.searchButtonFocused]}
|
<Settings color={colorScheme === "dark" ? "white" : "black"} size={24} />
|
||||||
onPress={() => setSettingsVisible(true)}
|
</StyledButton>
|
||||||
>
|
|
||||||
<Settings color={colorScheme === 'dark' ? 'white' : 'black'} size={24} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -257,7 +114,7 @@ export default function HomeScreen() {
|
|||||||
<FlatList
|
<FlatList
|
||||||
data={categories}
|
data={categories}
|
||||||
renderItem={renderCategory}
|
renderItem={renderCategory}
|
||||||
keyExtractor={item => item.title}
|
keyExtractor={(item) => item.title}
|
||||||
horizontal
|
horizontal
|
||||||
showsHorizontalScrollIndicator={false}
|
showsHorizontalScrollIndicator={false}
|
||||||
contentContainerStyle={styles.categoryListContent}
|
contentContainerStyle={styles.categoryListContent}
|
||||||
@@ -281,7 +138,8 @@ export default function HomeScreen() {
|
|||||||
data={contentData}
|
data={contentData}
|
||||||
renderItem={renderContentItem}
|
renderItem={renderContentItem}
|
||||||
keyExtractor={(item, index) => `${item.source}-${item.id}-${index}`}
|
keyExtractor={(item, index) => `${item.source}-${item.id}-${index}`}
|
||||||
numColumns={NUM_COLUMNS}
|
numColumns={calculatedNumColumns}
|
||||||
|
key={calculatedNumColumns} // Re-render FlatList when numColumns changes
|
||||||
contentContainerStyle={styles.listContent}
|
contentContainerStyle={styles.listContent}
|
||||||
onEndReached={loadMoreData}
|
onEndReached={loadMoreData}
|
||||||
onEndReachedThreshold={0.5}
|
onEndReachedThreshold={0.5}
|
||||||
@@ -293,14 +151,7 @@ export default function HomeScreen() {
|
|||||||
}
|
}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<SettingsModal
|
<SettingsModal />
|
||||||
visible={isSettingsVisible}
|
|
||||||
onCancel={() => setSettingsVisible(false)}
|
|
||||||
onSave={() => {
|
|
||||||
setSettingsVisible(false);
|
|
||||||
loadInitialData();
|
|
||||||
}}
|
|
||||||
/>
|
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -313,61 +164,47 @@ const styles = StyleSheet.create({
|
|||||||
centerContainer: {
|
centerContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
paddingTop: 20,
|
paddingTop: 20,
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
// Header
|
// Header
|
||||||
headerContainer: {
|
headerContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
justifyContent: 'space-between',
|
justifyContent: "space-between",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
paddingHorizontal: 24,
|
paddingHorizontal: 24,
|
||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
headerTitle: {
|
headerTitle: {
|
||||||
fontSize: 32,
|
fontSize: 32,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
paddingTop: 16,
|
paddingTop: 16,
|
||||||
},
|
},
|
||||||
rightHeaderButtons: {
|
rightHeaderButtons: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
searchButton: {
|
searchButton: {
|
||||||
padding: 10,
|
padding: 10,
|
||||||
borderRadius: 30,
|
borderRadius: 30,
|
||||||
marginLeft: 10,
|
marginLeft: 10,
|
||||||
},
|
},
|
||||||
searchButtonFocused: {
|
|
||||||
backgroundColor: '#007AFF',
|
|
||||||
transform: [{ scale: 1.1 }],
|
|
||||||
},
|
|
||||||
// Category Selector
|
// Category Selector
|
||||||
categoryContainer: {
|
categoryContainer: {
|
||||||
paddingBottom: 10,
|
paddingBottom: 6,
|
||||||
},
|
},
|
||||||
categoryListContent: {
|
categoryListContent: {
|
||||||
paddingHorizontal: 16,
|
paddingHorizontal: 16,
|
||||||
},
|
},
|
||||||
categoryButton: {
|
categoryButton: {
|
||||||
paddingHorizontal: 12,
|
paddingHorizontal: 2,
|
||||||
paddingVertical: 6,
|
paddingVertical: 6,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
marginHorizontal: 5,
|
marginHorizontal: 6,
|
||||||
},
|
|
||||||
categoryButtonSelected: {
|
|
||||||
backgroundColor: '#007AFF', // A bright blue for selected state
|
|
||||||
},
|
|
||||||
categoryButtonFocused: {
|
|
||||||
backgroundColor: '#0056b3', // A darker blue for focused state
|
|
||||||
elevation: 5,
|
|
||||||
},
|
},
|
||||||
categoryText: {
|
categoryText: {
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: '500',
|
fontWeight: "500",
|
||||||
},
|
|
||||||
categoryTextSelected: {
|
|
||||||
color: '#FFFFFF',
|
|
||||||
},
|
},
|
||||||
// Content Grid
|
// Content Grid
|
||||||
listContent: {
|
listContent: {
|
||||||
@@ -376,7 +213,7 @@ const styles = StyleSheet.create({
|
|||||||
},
|
},
|
||||||
itemContainer: {
|
itemContainer: {
|
||||||
margin: 8,
|
margin: 8,
|
||||||
width: ITEM_WIDTH,
|
// width is now set dynamically in renderContentItem
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
283
app/play.tsx
283
app/play.tsx
@@ -1,101 +1,137 @@
|
|||||||
import React, { useState, useRef } from "react";
|
import React, { useEffect, useRef } from "react";
|
||||||
import {
|
import { View, StyleSheet, ActivityIndicator, BackHandler, Platform, SafeAreaView, Dimensions } from "react-native";
|
||||||
View,
|
import { useLocalSearchParams, useRouter } from "expo-router";
|
||||||
StyleSheet,
|
|
||||||
TouchableOpacity,
|
|
||||||
ActivityIndicator,
|
|
||||||
} from "react-native";
|
|
||||||
import { useRouter } from "expo-router";
|
|
||||||
import { Video, ResizeMode } from "expo-av";
|
import { Video, ResizeMode } from "expo-av";
|
||||||
|
import * as ScreenOrientation from "expo-screen-orientation";
|
||||||
import { useKeepAwake } from "expo-keep-awake";
|
import { useKeepAwake } from "expo-keep-awake";
|
||||||
|
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
||||||
import { ThemedView } from "@/components/ThemedView";
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
import { PlayerControls } from "@/components/PlayerControls";
|
import { PlayerControls } from "@/components/PlayerControls";
|
||||||
|
import { PlayerControlsMobile } from "@/components/PlayerControls.mobile";
|
||||||
import { EpisodeSelectionModal } from "@/components/EpisodeSelectionModal";
|
import { EpisodeSelectionModal } from "@/components/EpisodeSelectionModal";
|
||||||
|
import { SourceSelectionModal } from "@/components/SourceSelectionModal";
|
||||||
|
import { SeekingBar } from "@/components/SeekingBar";
|
||||||
import { NextEpisodeOverlay } from "@/components/NextEpisodeOverlay";
|
import { NextEpisodeOverlay } from "@/components/NextEpisodeOverlay";
|
||||||
import { LoadingOverlay } from "@/components/LoadingOverlay";
|
import { LoadingOverlay } from "@/components/LoadingOverlay";
|
||||||
import { usePlaybackManager } from "@/hooks/usePlaybackManager";
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
import { useTVRemoteHandler } from "@/hooks/useTVRemoteHandler";
|
import { useTVRemoteHandler } from "@/hooks/useTVRemoteHandler";
|
||||||
|
import { useResponsive } from "@/hooks/useResponsive";
|
||||||
|
|
||||||
export default function PlayScreen() {
|
export default function PlayScreen() {
|
||||||
const router = useRouter();
|
|
||||||
const videoRef = useRef<Video>(null);
|
const videoRef = useRef<Video>(null);
|
||||||
|
const router = useRouter();
|
||||||
useKeepAwake();
|
useKeepAwake();
|
||||||
|
const { isMobile } = useResponsive();
|
||||||
|
const { source, id, episodeIndex, position } = useLocalSearchParams<{
|
||||||
|
source: string;
|
||||||
|
id: string;
|
||||||
|
episodeIndex: string;
|
||||||
|
position: string;
|
||||||
|
}>();
|
||||||
|
|
||||||
const {
|
const {
|
||||||
detail,
|
detail,
|
||||||
episodes,
|
episodes,
|
||||||
currentEpisodeIndex,
|
currentEpisodeIndex,
|
||||||
status,
|
|
||||||
isLoading,
|
isLoading,
|
||||||
setIsLoading,
|
showControls,
|
||||||
|
showEpisodeModal,
|
||||||
|
showSourceModal,
|
||||||
showNextEpisodeOverlay,
|
showNextEpisodeOverlay,
|
||||||
|
initialPosition,
|
||||||
|
introEndTime,
|
||||||
|
setVideoRef,
|
||||||
|
loadVideo,
|
||||||
playEpisode,
|
playEpisode,
|
||||||
togglePlayPause,
|
togglePlayPause,
|
||||||
seek,
|
seek,
|
||||||
handlePlaybackStatusUpdate,
|
handlePlaybackStatusUpdate,
|
||||||
setShowNextEpisodeOverlay,
|
|
||||||
} = usePlaybackManager(videoRef);
|
|
||||||
|
|
||||||
const [showControls, setShowControls] = useState(true);
|
|
||||||
const [showEpisodeModal, setShowEpisodeModal] = useState(false);
|
|
||||||
const [episodeGroupSize] = useState(30);
|
|
||||||
const [selectedEpisodeGroup, setSelectedEpisodeGroup] = useState(
|
|
||||||
Math.floor(currentEpisodeIndex / episodeGroupSize)
|
|
||||||
);
|
|
||||||
|
|
||||||
const { currentFocus, setCurrentFocus } = useTVRemoteHandler({
|
|
||||||
showControls,
|
|
||||||
setShowControls,
|
setShowControls,
|
||||||
|
setShowEpisodeModal,
|
||||||
|
setShowSourceModal,
|
||||||
|
setShowNextEpisodeOverlay,
|
||||||
|
reset,
|
||||||
|
} = usePlayerStore();
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
async function lockOrientation() {
|
||||||
|
if (isMobile) {
|
||||||
|
await ScreenOrientation.lockAsync(ScreenOrientation.OrientationLock.LANDSCAPE_RIGHT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
lockOrientation();
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
if (isMobile) {
|
||||||
|
ScreenOrientation.unlockAsync();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}, [isMobile]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
setVideoRef(videoRef);
|
||||||
|
if (source && id) {
|
||||||
|
loadVideo(source, id, parseInt(episodeIndex || "0", 10), parseInt(position || "0", 10));
|
||||||
|
}
|
||||||
|
return () => {
|
||||||
|
reset(); // Reset state when component unmounts
|
||||||
|
};
|
||||||
|
}, [source, id, episodeIndex, position, setVideoRef, loadVideo, reset]);
|
||||||
|
|
||||||
|
const { onScreenPress: onTVScreenPress } = useTVRemoteHandler();
|
||||||
|
|
||||||
|
const handleScreenPress = () => {
|
||||||
|
if (isMobile) {
|
||||||
|
setShowControls(!showControls);
|
||||||
|
} else {
|
||||||
|
onTVScreenPress();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const singleTap = Gesture.Tap()
|
||||||
|
.onEnd(() => {
|
||||||
|
handleScreenPress();
|
||||||
|
})
|
||||||
|
.runOnJS(true);
|
||||||
|
|
||||||
|
const doubleTap = Gesture.Tap()
|
||||||
|
.numberOfTaps(2)
|
||||||
|
.onEnd((e) => {
|
||||||
|
if (!isMobile) return;
|
||||||
|
const tapPositionX = e.x;
|
||||||
|
const screenWidth = Dimensions.get("window").width;
|
||||||
|
if (tapPositionX < screenWidth / 2) {
|
||||||
|
seek(-10); // Seek back
|
||||||
|
} else {
|
||||||
|
seek(10); // Seek forward
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.runOnJS(true);
|
||||||
|
|
||||||
|
const composedGesture = Gesture.Exclusive(doubleTap, singleTap);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const backAction = () => {
|
||||||
|
if (showControls) {
|
||||||
|
setShowControls(false);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
router.back();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const backHandler = BackHandler.addEventListener("hardwareBackPress", backAction);
|
||||||
|
|
||||||
|
return () => backHandler.remove();
|
||||||
|
}, [
|
||||||
|
showControls,
|
||||||
showEpisodeModal,
|
showEpisodeModal,
|
||||||
onPlayPause: togglePlayPause,
|
showSourceModal,
|
||||||
onSeek: seek,
|
setShowControls,
|
||||||
onShowEpisodes: () => setShowEpisodeModal(true),
|
setShowEpisodeModal,
|
||||||
onPlayNextEpisode: () => {
|
setShowSourceModal,
|
||||||
if (currentEpisodeIndex < episodes.length - 1) {
|
router,
|
||||||
playEpisode(currentEpisodeIndex + 1);
|
]);
|
||||||
}
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
const [isSeeking, setIsSeeking] = useState(false);
|
|
||||||
const [seekPosition, setSeekPosition] = useState(0);
|
|
||||||
const [progressPosition, setProgressPosition] = useState(0);
|
|
||||||
|
|
||||||
const formatTime = (milliseconds: number) => {
|
|
||||||
if (!milliseconds) return "00:00";
|
|
||||||
const totalSeconds = Math.floor(milliseconds / 1000);
|
|
||||||
const minutes = Math.floor(totalSeconds / 60);
|
|
||||||
const seconds = totalSeconds % 60;
|
|
||||||
return `${minutes.toString().padStart(2, "0")}:${seconds
|
|
||||||
.toString()
|
|
||||||
.padStart(2, "0")}`;
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSeekStart = () => setIsSeeking(true);
|
|
||||||
|
|
||||||
const handleSeekMove = (event: { nativeEvent: { locationX: number } }) => {
|
|
||||||
if (!status?.isLoaded || !status.durationMillis) return;
|
|
||||||
const { locationX } = event.nativeEvent;
|
|
||||||
const progressBarWidth = 300;
|
|
||||||
const progress = Math.max(0, Math.min(locationX / progressBarWidth, 1));
|
|
||||||
setSeekPosition(progress);
|
|
||||||
};
|
|
||||||
|
|
||||||
const handleSeekRelease = (event: { nativeEvent: { locationX: number } }) => {
|
|
||||||
if (!videoRef.current || !status?.isLoaded || !status.durationMillis)
|
|
||||||
return;
|
|
||||||
const wasPlaying = status.isPlaying;
|
|
||||||
const { locationX } = event.nativeEvent;
|
|
||||||
const progressBarWidth = 300;
|
|
||||||
const progress = Math.max(0, Math.min(locationX / progressBarWidth, 1));
|
|
||||||
const newPosition = progress * status.durationMillis;
|
|
||||||
videoRef.current.setPositionAsync(newPosition).then(() => {
|
|
||||||
if (wasPlaying) {
|
|
||||||
videoRef.current?.playAsync();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
setIsSeeking(false);
|
|
||||||
};
|
|
||||||
|
|
||||||
if (!detail && isLoading) {
|
if (!detail && isLoading) {
|
||||||
return (
|
return (
|
||||||
@@ -106,79 +142,46 @@ export default function PlayScreen() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const currentEpisode = episodes[currentEpisodeIndex];
|
const currentEpisode = episodes[currentEpisodeIndex];
|
||||||
const videoTitle = detail?.videoInfo?.title || "";
|
|
||||||
const hasNextEpisode = currentEpisodeIndex < episodes.length - 1;
|
const PlayerComponent = isMobile ? PlayerControlsMobile : PlayerControls;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<ThemedView style={styles.container}>
|
<SafeAreaView style={styles.container}>
|
||||||
<TouchableOpacity
|
<ThemedView focusable style={styles.container}>
|
||||||
activeOpacity={1}
|
<GestureDetector gesture={composedGesture}>
|
||||||
style={styles.videoContainer}
|
<View style={styles.videoContainer}>
|
||||||
onPress={() => {
|
<Video
|
||||||
setShowControls(!showControls);
|
ref={videoRef}
|
||||||
setCurrentFocus(null);
|
style={styles.videoPlayer}
|
||||||
}}
|
source={{ uri: currentEpisode?.url }}
|
||||||
>
|
resizeMode={ResizeMode.CONTAIN}
|
||||||
<Video
|
onPlaybackStatusUpdate={handlePlaybackStatusUpdate}
|
||||||
ref={videoRef}
|
onLoad={() => {
|
||||||
style={styles.videoPlayer}
|
const jumpPosition = introEndTime || initialPosition;
|
||||||
source={{ uri: currentEpisode?.url }}
|
if (jumpPosition > 0) {
|
||||||
resizeMode={ResizeMode.CONTAIN}
|
videoRef.current?.setPositionAsync(jumpPosition);
|
||||||
onPlaybackStatusUpdate={(s) => {
|
}
|
||||||
handlePlaybackStatusUpdate(s);
|
usePlayerStore.setState({ isLoading: false });
|
||||||
if (s.isLoaded && !isSeeking) {
|
}}
|
||||||
setProgressPosition(s.positionMillis / (s.durationMillis || 1));
|
onLoadStart={() => usePlayerStore.setState({ isLoading: true })}
|
||||||
}
|
useNativeControls={false}
|
||||||
}}
|
shouldPlay
|
||||||
onLoad={() => setIsLoading(false)}
|
/>
|
||||||
onLoadStart={() => setIsLoading(true)}
|
|
||||||
useNativeControls={false}
|
|
||||||
shouldPlay
|
|
||||||
/>
|
|
||||||
|
|
||||||
{showControls && (
|
{showControls && <PlayerComponent showControls={showControls} setShowControls={setShowControls} />}
|
||||||
<PlayerControls
|
|
||||||
videoTitle={videoTitle}
|
|
||||||
currentEpisodeTitle={currentEpisode?.title}
|
|
||||||
status={status}
|
|
||||||
isSeeking={isSeeking}
|
|
||||||
seekPosition={seekPosition}
|
|
||||||
progressPosition={progressPosition}
|
|
||||||
currentFocus={currentFocus}
|
|
||||||
hasNextEpisode={hasNextEpisode}
|
|
||||||
onSeekStart={handleSeekStart}
|
|
||||||
onSeekMove={handleSeekMove}
|
|
||||||
onSeekRelease={handleSeekRelease}
|
|
||||||
onSeek={seek}
|
|
||||||
onTogglePlayPause={togglePlayPause}
|
|
||||||
onPlayNextEpisode={() => playEpisode(currentEpisodeIndex + 1)}
|
|
||||||
onShowEpisodes={() => setShowEpisodeModal(true)}
|
|
||||||
formatTime={formatTime}
|
|
||||||
/>
|
|
||||||
)}
|
|
||||||
|
|
||||||
<LoadingOverlay visible={isLoading} />
|
<SeekingBar />
|
||||||
|
|
||||||
<NextEpisodeOverlay
|
<LoadingOverlay visible={isLoading} />
|
||||||
visible={showNextEpisodeOverlay}
|
|
||||||
onCancel={() => setShowNextEpisodeOverlay(false)}
|
|
||||||
/>
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<EpisodeSelectionModal
|
<NextEpisodeOverlay visible={showNextEpisodeOverlay} onCancel={() => setShowNextEpisodeOverlay(false)} />
|
||||||
visible={showEpisodeModal}
|
</View>
|
||||||
episodes={episodes}
|
</GestureDetector>
|
||||||
currentEpisodeIndex={currentEpisodeIndex}
|
|
||||||
episodeGroupSize={episodeGroupSize}
|
<EpisodeSelectionModal />
|
||||||
selectedEpisodeGroup={selectedEpisodeGroup}
|
<SourceSelectionModal />
|
||||||
setSelectedEpisodeGroup={setSelectedEpisodeGroup}
|
</ThemedView>
|
||||||
onSelectEpisode={(index) => {
|
</SafeAreaView>
|
||||||
playEpisode(index);
|
|
||||||
setShowEpisodeModal(false);
|
|
||||||
}}
|
|
||||||
onClose={() => setShowEpisodeModal(false)}
|
|
||||||
/>
|
|
||||||
</ThemedView>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
106
app/search.tsx
106
app/search.tsx
@@ -1,29 +1,25 @@
|
|||||||
import React, { useState, useRef, useEffect } from 'react';
|
import React, { useState, useRef, useEffect } from "react";
|
||||||
import {
|
import { View, TextInput, StyleSheet, FlatList, ActivityIndicator, Text, Keyboard } from "react-native";
|
||||||
View,
|
import { ThemedView } from "@/components/ThemedView";
|
||||||
TextInput,
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
StyleSheet,
|
import VideoCard from "@/components/VideoCard.tv";
|
||||||
FlatList,
|
import { api, SearchResult } from "@/services/api";
|
||||||
ActivityIndicator,
|
import { Search } from "lucide-react-native";
|
||||||
Pressable,
|
import { StyledButton } from "@/components/StyledButton";
|
||||||
Text,
|
import { useResponsive } from "@/hooks/useResponsive";
|
||||||
Keyboard,
|
|
||||||
useColorScheme,
|
|
||||||
} from 'react-native';
|
|
||||||
import { ThemedView } from '@/components/ThemedView';
|
|
||||||
import { ThemedText } from '@/components/ThemedText';
|
|
||||||
import VideoCard from '@/components/VideoCard.tv';
|
|
||||||
import { api, SearchResult } from '@/services/api';
|
|
||||||
import { Search } from 'lucide-react-native';
|
|
||||||
|
|
||||||
export default function SearchScreen() {
|
export default function SearchScreen() {
|
||||||
const [keyword, setKeyword] = useState('');
|
const [keyword, setKeyword] = useState("");
|
||||||
const [results, setResults] = useState<SearchResult[]>([]);
|
const [results, setResults] = useState<SearchResult[]>([]);
|
||||||
const [loading, setLoading] = useState(false);
|
const [loading, setLoading] = useState(false);
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
const textInputRef = useRef<TextInput>(null);
|
const textInputRef = useRef<TextInput>(null);
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = "dark"; // Replace with useColorScheme() if needed
|
||||||
const [isInputFocused, setIsInputFocused] = useState(false);
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
||||||
|
const { isMobile, screenWidth, numColumns } = useResponsive();
|
||||||
|
|
||||||
|
const itemWidth = isMobile ? screenWidth / numColumns(150, 16) - 24 : screenWidth / 5 - 24;
|
||||||
|
const calculatedNumColumns = numColumns(150, 16);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
// Focus the text input when the screen loads
|
// Focus the text input when the screen loads
|
||||||
@@ -46,26 +42,28 @@ export default function SearchScreen() {
|
|||||||
if (response.results.length > 0) {
|
if (response.results.length > 0) {
|
||||||
setResults(response.results);
|
setResults(response.results);
|
||||||
} else {
|
} else {
|
||||||
setError('没有找到相关内容');
|
setError("没有找到相关内容");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
setError('搜索失败,请稍后重试。');
|
setError("搜索失败,请稍后重试。");
|
||||||
console.error('Search failed:', err);
|
console.error("Search failed:", err);
|
||||||
} finally {
|
} finally {
|
||||||
setLoading(false);
|
setLoading(false);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const renderItem = ({ item }: { item: SearchResult }) => (
|
const renderItem = ({ item }: { item: SearchResult }) => (
|
||||||
<VideoCard
|
<View style={{ width: itemWidth, margin: 8 }}>
|
||||||
id={item.id.toString()}
|
<VideoCard
|
||||||
source={item.source}
|
id={item.id.toString()}
|
||||||
title={item.title}
|
source={item.source}
|
||||||
poster={item.poster}
|
title={item.title}
|
||||||
year={item.year}
|
poster={item.poster}
|
||||||
sourceName={item.source_name}
|
year={item.year}
|
||||||
api={api}
|
sourceName={item.source_name}
|
||||||
/>
|
api={api}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@@ -76,13 +74,13 @@ export default function SearchScreen() {
|
|||||||
style={[
|
style={[
|
||||||
styles.input,
|
styles.input,
|
||||||
{
|
{
|
||||||
backgroundColor: colorScheme === 'dark' ? '#2c2c2e' : '#f0f0f0',
|
backgroundColor: colorScheme === "dark" ? "#2c2c2e" : "#f0f0f0",
|
||||||
color: colorScheme === 'dark' ? 'white' : 'black',
|
color: colorScheme === "dark" ? "white" : "black",
|
||||||
borderColor: isInputFocused ? '#007bff' : 'transparent',
|
borderColor: isInputFocused ? "#007bff" : "transparent",
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
placeholder="搜索电影、剧集..."
|
placeholder="搜索电影、剧集..."
|
||||||
placeholderTextColor={colorScheme === 'dark' ? '#888' : '#555'}
|
placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"}
|
||||||
value={keyword}
|
value={keyword}
|
||||||
onChangeText={setKeyword}
|
onChangeText={setKeyword}
|
||||||
onFocus={() => setIsInputFocused(true)}
|
onFocus={() => setIsInputFocused(true)}
|
||||||
@@ -90,18 +88,9 @@ export default function SearchScreen() {
|
|||||||
onSubmitEditing={handleSearch} // Allow searching with remote 'enter' button
|
onSubmitEditing={handleSearch} // Allow searching with remote 'enter' button
|
||||||
returnKeyType="search"
|
returnKeyType="search"
|
||||||
/>
|
/>
|
||||||
<Pressable
|
<StyledButton style={styles.searchButton} onPress={handleSearch}>
|
||||||
style={({ focused }) => [
|
<Search size={24} color={colorScheme === "dark" ? "white" : "black"} />
|
||||||
styles.searchButton,
|
</StyledButton>
|
||||||
{
|
|
||||||
backgroundColor: colorScheme === 'dark' ? '#3a3a3c' : '#e0e0e0',
|
|
||||||
},
|
|
||||||
focused && styles.focusedButton,
|
|
||||||
]}
|
|
||||||
onPress={handleSearch}
|
|
||||||
>
|
|
||||||
<Search size={24} color={colorScheme === 'dark' ? 'white' : 'black'} />
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
{loading ? (
|
{loading ? (
|
||||||
@@ -117,7 +106,8 @@ export default function SearchScreen() {
|
|||||||
data={results}
|
data={results}
|
||||||
renderItem={renderItem}
|
renderItem={renderItem}
|
||||||
keyExtractor={(item, index) => `${item.id}-${item.source}-${index}`}
|
keyExtractor={(item, index) => `${item.id}-${item.source}-${index}`}
|
||||||
numColumns={5} // Adjust based on your card size and desired layout
|
numColumns={calculatedNumColumns}
|
||||||
|
key={calculatedNumColumns}
|
||||||
contentContainerStyle={styles.listContent}
|
contentContainerStyle={styles.listContent}
|
||||||
ListEmptyComponent={
|
ListEmptyComponent={
|
||||||
<View style={styles.centerContainer}>
|
<View style={styles.centerContainer}>
|
||||||
@@ -136,39 +126,35 @@ const styles = StyleSheet.create({
|
|||||||
paddingTop: 50,
|
paddingTop: 50,
|
||||||
},
|
},
|
||||||
searchContainer: {
|
searchContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
paddingHorizontal: 20,
|
paddingHorizontal: 20,
|
||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
height: 50,
|
height: 50,
|
||||||
backgroundColor: '#2c2c2e', // Default for dark mode, overridden inline
|
backgroundColor: "#2c2c2e", // Default for dark mode, overridden inline
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
paddingHorizontal: 15,
|
paddingHorizontal: 15,
|
||||||
color: 'white', // Default for dark mode, overridden inline
|
color: "white", // Default for dark mode, overridden inline
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
marginRight: 10,
|
marginRight: 10,
|
||||||
borderWidth: 2,
|
borderWidth: 2,
|
||||||
borderColor: 'transparent', // Default, overridden for focus
|
borderColor: "transparent", // Default, overridden for focus
|
||||||
},
|
},
|
||||||
searchButton: {
|
searchButton: {
|
||||||
padding: 12,
|
padding: 12,
|
||||||
// backgroundColor is now set dynamically
|
// backgroundColor is now set dynamically
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
},
|
},
|
||||||
focusedButton: {
|
|
||||||
backgroundColor: '#007bff',
|
|
||||||
transform: [{ scale: 1.1 }],
|
|
||||||
},
|
|
||||||
centerContainer: {
|
centerContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
errorText: {
|
errorText: {
|
||||||
color: 'red',
|
color: "red",
|
||||||
},
|
},
|
||||||
listContent: {
|
listContent: {
|
||||||
paddingHorizontal: 10,
|
paddingHorizontal: 10,
|
||||||
|
|||||||
@@ -1,55 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import {
|
|
||||||
Pressable,
|
|
||||||
StyleSheet,
|
|
||||||
StyleProp,
|
|
||||||
ViewStyle,
|
|
||||||
PressableProps,
|
|
||||||
} from "react-native";
|
|
||||||
|
|
||||||
interface DetailButtonProps extends PressableProps {
|
|
||||||
children: React.ReactNode;
|
|
||||||
style?: StyleProp<ViewStyle>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const DetailButton: React.FC<DetailButtonProps> = ({
|
|
||||||
children,
|
|
||||||
style,
|
|
||||||
...rest
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<Pressable
|
|
||||||
style={({ focused }) => [
|
|
||||||
styles.button,
|
|
||||||
style,
|
|
||||||
focused && styles.buttonFocused,
|
|
||||||
]}
|
|
||||||
{...rest}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Pressable>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
|
||||||
button: {
|
|
||||||
backgroundColor: "#333",
|
|
||||||
paddingHorizontal: 15,
|
|
||||||
paddingVertical: 10,
|
|
||||||
borderRadius: 8,
|
|
||||||
margin: 5,
|
|
||||||
borderWidth: 2,
|
|
||||||
borderColor: "transparent",
|
|
||||||
flexDirection: "row",
|
|
||||||
alignItems: "center",
|
|
||||||
},
|
|
||||||
buttonFocused: {
|
|
||||||
backgroundColor: "#0056b3",
|
|
||||||
borderColor: "#fff",
|
|
||||||
elevation: 5,
|
|
||||||
shadowColor: "#fff",
|
|
||||||
shadowOffset: { width: 0, height: 0 },
|
|
||||||
shadowOpacity: 1,
|
|
||||||
shadowRadius: 15,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
@@ -1,74 +1,52 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import {
|
import { View, Text, StyleSheet, Modal, FlatList, Pressable } from "react-native";
|
||||||
View,
|
import { StyledButton } from "./StyledButton";
|
||||||
Text,
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
StyleSheet,
|
import { useState } from "react";
|
||||||
Modal,
|
|
||||||
FlatList,
|
|
||||||
Pressable,
|
|
||||||
TouchableOpacity,
|
|
||||||
} from "react-native";
|
|
||||||
|
|
||||||
interface Episode {
|
interface Episode {
|
||||||
title?: string;
|
title?: string;
|
||||||
url: string;
|
url: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
interface EpisodeSelectionModalProps {
|
interface EpisodeSelectionModalProps {}
|
||||||
visible: boolean;
|
|
||||||
episodes: Episode[];
|
export const EpisodeSelectionModal: React.FC<EpisodeSelectionModalProps> = () => {
|
||||||
currentEpisodeIndex: number;
|
const { showEpisodeModal, episodes, currentEpisodeIndex, playEpisode, setShowEpisodeModal } = usePlayerStore();
|
||||||
episodeGroupSize: number;
|
|
||||||
selectedEpisodeGroup: number;
|
const [episodeGroupSize] = useState(30);
|
||||||
setSelectedEpisodeGroup: (group: number) => void;
|
const [selectedEpisodeGroup, setSelectedEpisodeGroup] = useState(Math.floor(currentEpisodeIndex / episodeGroupSize));
|
||||||
onSelectEpisode: (index: number) => void;
|
|
||||||
onClose: () => void;
|
const onSelectEpisode = (index: number) => {
|
||||||
}
|
playEpisode(index);
|
||||||
|
setShowEpisodeModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
setShowEpisodeModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
export const EpisodeSelectionModal: React.FC<EpisodeSelectionModalProps> = ({
|
|
||||||
visible,
|
|
||||||
episodes,
|
|
||||||
currentEpisodeIndex,
|
|
||||||
episodeGroupSize,
|
|
||||||
selectedEpisodeGroup,
|
|
||||||
setSelectedEpisodeGroup,
|
|
||||||
onSelectEpisode,
|
|
||||||
onClose,
|
|
||||||
}) => {
|
|
||||||
return (
|
return (
|
||||||
<Modal
|
<Modal visible={showEpisodeModal} transparent={true} animationType="slide" onRequestClose={onClose}>
|
||||||
visible={visible}
|
|
||||||
transparent={true}
|
|
||||||
animationType="slide"
|
|
||||||
onRequestClose={onClose}
|
|
||||||
>
|
|
||||||
<View style={styles.modalContainer}>
|
<View style={styles.modalContainer}>
|
||||||
<View style={styles.modalContent}>
|
<View style={styles.modalContent}>
|
||||||
<Text style={styles.modalTitle}>选择剧集</Text>
|
<Text style={styles.modalTitle}>选择剧集</Text>
|
||||||
|
|
||||||
{episodes.length > episodeGroupSize && (
|
{episodes.length > episodeGroupSize && (
|
||||||
<View style={styles.episodeGroupContainer}>
|
<View style={styles.episodeGroupContainer}>
|
||||||
{Array.from(
|
{Array.from({ length: Math.ceil(episodes.length / episodeGroupSize) }, (_, groupIndex) => (
|
||||||
{ length: Math.ceil(episodes.length / episodeGroupSize) },
|
<StyledButton
|
||||||
(_, groupIndex) => (
|
key={groupIndex}
|
||||||
<TouchableOpacity
|
text={`${groupIndex * episodeGroupSize + 1}-${Math.min(
|
||||||
key={groupIndex}
|
(groupIndex + 1) * episodeGroupSize,
|
||||||
style={[
|
episodes.length
|
||||||
styles.episodeGroupButton,
|
)}`}
|
||||||
selectedEpisodeGroup === groupIndex &&
|
onPress={() => setSelectedEpisodeGroup(groupIndex)}
|
||||||
styles.episodeGroupButtonSelected,
|
isSelected={selectedEpisodeGroup === groupIndex}
|
||||||
]}
|
style={styles.episodeGroupButton}
|
||||||
onPress={() => setSelectedEpisodeGroup(groupIndex)}
|
textStyle={styles.episodeGroupButtonText}
|
||||||
>
|
/>
|
||||||
<Text style={styles.episodeGroupButtonText}>
|
))}
|
||||||
{`${groupIndex * episodeGroupSize + 1}-${Math.min(
|
|
||||||
(groupIndex + 1) * episodeGroupSize,
|
|
||||||
episodes.length
|
|
||||||
)}`}
|
|
||||||
</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
)
|
|
||||||
)}
|
|
||||||
</View>
|
</View>
|
||||||
)}
|
)}
|
||||||
<FlatList
|
<FlatList
|
||||||
@@ -77,40 +55,22 @@ export const EpisodeSelectionModal: React.FC<EpisodeSelectionModalProps> = ({
|
|||||||
(selectedEpisodeGroup + 1) * episodeGroupSize
|
(selectedEpisodeGroup + 1) * episodeGroupSize
|
||||||
)}
|
)}
|
||||||
numColumns={5}
|
numColumns={5}
|
||||||
keyExtractor={(_, index) =>
|
contentContainerStyle={styles.episodeList}
|
||||||
`episode-${selectedEpisodeGroup * episodeGroupSize + index}`
|
keyExtractor={(_, index) => `episode-${selectedEpisodeGroup * episodeGroupSize + index}`}
|
||||||
}
|
|
||||||
renderItem={({ item, index }) => {
|
renderItem={({ item, index }) => {
|
||||||
const absoluteIndex =
|
const absoluteIndex = selectedEpisodeGroup * episodeGroupSize + index;
|
||||||
selectedEpisodeGroup * episodeGroupSize + index;
|
|
||||||
return (
|
return (
|
||||||
<Pressable
|
<StyledButton
|
||||||
style={({ focused }) => [
|
text={item.title || `第 ${absoluteIndex + 1} 集`}
|
||||||
styles.episodeItem,
|
|
||||||
currentEpisodeIndex === absoluteIndex &&
|
|
||||||
styles.episodeItemSelected,
|
|
||||||
focused && styles.focusedButton,
|
|
||||||
]}
|
|
||||||
onPress={() => onSelectEpisode(absoluteIndex)}
|
onPress={() => onSelectEpisode(absoluteIndex)}
|
||||||
|
isSelected={currentEpisodeIndex === absoluteIndex}
|
||||||
hasTVPreferredFocus={currentEpisodeIndex === absoluteIndex}
|
hasTVPreferredFocus={currentEpisodeIndex === absoluteIndex}
|
||||||
>
|
style={styles.episodeItem}
|
||||||
<Text style={styles.episodeItemText}>
|
textStyle={styles.episodeItemText}
|
||||||
{item.title || `第 ${absoluteIndex + 1} 集`}
|
/>
|
||||||
</Text>
|
|
||||||
</Pressable>
|
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<Pressable
|
|
||||||
style={({ focused }) => [
|
|
||||||
styles.closeButton,
|
|
||||||
focused && styles.focusedButton,
|
|
||||||
]}
|
|
||||||
onPress={onClose}
|
|
||||||
>
|
|
||||||
<Text style={{ color: "white" }}>关闭</Text>
|
|
||||||
</Pressable>
|
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</Modal>
|
</Modal>
|
||||||
@@ -125,64 +85,40 @@ const styles = StyleSheet.create({
|
|||||||
backgroundColor: "transparent",
|
backgroundColor: "transparent",
|
||||||
},
|
},
|
||||||
modalContent: {
|
modalContent: {
|
||||||
width: 400,
|
width: 600,
|
||||||
height: "100%",
|
height: "100%",
|
||||||
backgroundColor: "rgba(0, 0, 0, 0.85)",
|
backgroundColor: "rgba(0, 0, 0, 0.85)",
|
||||||
padding: 20,
|
padding: 20,
|
||||||
},
|
},
|
||||||
modalTitle: {
|
modalTitle: {
|
||||||
color: "white",
|
color: "white",
|
||||||
marginBottom: 20,
|
marginBottom: 12,
|
||||||
textAlign: "center",
|
textAlign: "center",
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: "bold",
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
episodeItem: {
|
episodeList: {
|
||||||
backgroundColor: "#333",
|
justifyContent: "flex-start",
|
||||||
paddingVertical: 12,
|
|
||||||
borderRadius: 8,
|
|
||||||
margin: 4,
|
|
||||||
flex: 1,
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
},
|
},
|
||||||
episodeItemSelected: {
|
episodeItem: {
|
||||||
backgroundColor: "#007bff",
|
paddingVertical: 2,
|
||||||
|
margin: 4,
|
||||||
|
width: "18%",
|
||||||
},
|
},
|
||||||
episodeItemText: {
|
episodeItemText: {
|
||||||
color: "white",
|
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
},
|
},
|
||||||
episodeGroupContainer: {
|
episodeGroupContainer: {
|
||||||
flexDirection: "row",
|
flexDirection: "row",
|
||||||
flexWrap: "wrap",
|
flexWrap: "wrap",
|
||||||
justifyContent: "center",
|
justifyContent: "center",
|
||||||
marginBottom: 15,
|
|
||||||
paddingHorizontal: 10,
|
paddingHorizontal: 10,
|
||||||
},
|
},
|
||||||
episodeGroupButton: {
|
episodeGroupButton: {
|
||||||
backgroundColor: "#444",
|
paddingHorizontal: 6,
|
||||||
paddingHorizontal: 12,
|
margin: 8,
|
||||||
paddingVertical: 6,
|
|
||||||
borderRadius: 15,
|
|
||||||
margin: 5,
|
|
||||||
},
|
|
||||||
episodeGroupButtonSelected: {
|
|
||||||
backgroundColor: "#007bff",
|
|
||||||
},
|
},
|
||||||
episodeGroupButtonText: {
|
episodeGroupButtonText: {
|
||||||
color: "white",
|
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
},
|
},
|
||||||
closeButton: {
|
|
||||||
backgroundColor: "#333",
|
|
||||||
padding: 15,
|
|
||||||
borderRadius: 8,
|
|
||||||
alignItems: "center",
|
|
||||||
marginTop: 20,
|
|
||||||
},
|
|
||||||
focusedButton: {
|
|
||||||
backgroundColor: "rgba(119, 119, 119, 0.9)",
|
|
||||||
transform: [{ scale: 1.1 }],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,52 +1,32 @@
|
|||||||
import React from "react";
|
import React, { ComponentProps } from "react";
|
||||||
import { Pressable, StyleSheet, StyleProp, ViewStyle } from "react-native";
|
import { StyledButton } from "./StyledButton";
|
||||||
|
import { StyleSheet, View, Text } from "react-native";
|
||||||
|
|
||||||
interface MediaButtonProps {
|
type StyledButtonProps = ComponentProps<typeof StyledButton> & {
|
||||||
onPress: () => void;
|
timeLabel?: string;
|
||||||
children: React.ReactNode;
|
|
||||||
isFocused?: boolean;
|
|
||||||
isDisabled?: boolean;
|
|
||||||
style?: StyleProp<ViewStyle>;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const MediaButton: React.FC<MediaButtonProps> = ({
|
|
||||||
onPress,
|
|
||||||
children,
|
|
||||||
isFocused = false,
|
|
||||||
isDisabled = false,
|
|
||||||
style,
|
|
||||||
}) => {
|
|
||||||
return (
|
|
||||||
<Pressable
|
|
||||||
onPress={onPress}
|
|
||||||
disabled={isDisabled}
|
|
||||||
style={[
|
|
||||||
styles.mediaControlButton,
|
|
||||||
isFocused && styles.focusedButton,
|
|
||||||
isDisabled && styles.disabledButton,
|
|
||||||
style,
|
|
||||||
]}
|
|
||||||
>
|
|
||||||
{children}
|
|
||||||
</Pressable>
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const MediaButton = ({ timeLabel, ...props }: StyledButtonProps) => (
|
||||||
|
<View>
|
||||||
|
<StyledButton {...props} style={[styles.mediaControlButton, props.style]} variant="ghost" />
|
||||||
|
{timeLabel && <Text style={styles.timeLabel}>{timeLabel}</Text>}
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
mediaControlButton: {
|
mediaControlButton: {
|
||||||
backgroundColor: "rgba(51, 51, 51, 0.8)",
|
|
||||||
padding: 12,
|
padding: 12,
|
||||||
borderRadius: 8,
|
|
||||||
alignItems: "center",
|
|
||||||
justifyContent: "center",
|
|
||||||
minWidth: 80,
|
minWidth: 80,
|
||||||
margin: 5,
|
|
||||||
},
|
},
|
||||||
focusedButton: {
|
timeLabel: {
|
||||||
backgroundColor: "rgba(119, 119, 119, 0.9)",
|
position: "absolute",
|
||||||
transform: [{ scale: 1.1 }],
|
top: 14,
|
||||||
},
|
right: 12,
|
||||||
disabledButton: {
|
color: "white",
|
||||||
opacity: 0.5,
|
fontSize: 10,
|
||||||
|
fontWeight: "bold",
|
||||||
|
backgroundColor: "rgba(0,0,0,0.6)",
|
||||||
|
paddingHorizontal: 4,
|
||||||
|
borderRadius: 3,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,16 +1,14 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { View, StyleSheet, TouchableOpacity } from "react-native";
|
import { View, StyleSheet } from "react-native";
|
||||||
import { ThemedText } from "@/components/ThemedText";
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
|
import { StyledButton } from "./StyledButton";
|
||||||
|
|
||||||
interface NextEpisodeOverlayProps {
|
interface NextEpisodeOverlayProps {
|
||||||
visible: boolean;
|
visible: boolean;
|
||||||
onCancel: () => void;
|
onCancel: () => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const NextEpisodeOverlay: React.FC<NextEpisodeOverlayProps> = ({
|
export const NextEpisodeOverlay: React.FC<NextEpisodeOverlayProps> = ({ visible, onCancel }) => {
|
||||||
visible,
|
|
||||||
onCancel,
|
|
||||||
}) => {
|
|
||||||
if (!visible) {
|
if (!visible) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -18,12 +16,13 @@ export const NextEpisodeOverlay: React.FC<NextEpisodeOverlayProps> = ({
|
|||||||
return (
|
return (
|
||||||
<View style={styles.nextEpisodeOverlay}>
|
<View style={styles.nextEpisodeOverlay}>
|
||||||
<View style={styles.nextEpisodeContent}>
|
<View style={styles.nextEpisodeContent}>
|
||||||
<ThemedText style={styles.nextEpisodeTitle}>
|
<ThemedText style={styles.nextEpisodeTitle}>即将播放下一集...</ThemedText>
|
||||||
即将播放下一集...
|
<StyledButton
|
||||||
</ThemedText>
|
text="取消"
|
||||||
<TouchableOpacity style={styles.nextEpisodeButton} onPress={onCancel}>
|
onPress={onCancel}
|
||||||
<ThemedText style={styles.nextEpisodeButtonText}>取消</ThemedText>
|
style={styles.nextEpisodeButton}
|
||||||
</TouchableOpacity>
|
textStyle={styles.nextEpisodeButtonText}
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
);
|
);
|
||||||
@@ -48,10 +47,8 @@ const styles = StyleSheet.create({
|
|||||||
marginBottom: 10,
|
marginBottom: 10,
|
||||||
},
|
},
|
||||||
nextEpisodeButton: {
|
nextEpisodeButton: {
|
||||||
backgroundColor: "#333",
|
|
||||||
padding: 8,
|
padding: 8,
|
||||||
paddingHorizontal: 15,
|
paddingHorizontal: 15,
|
||||||
borderRadius: 5,
|
|
||||||
},
|
},
|
||||||
nextEpisodeButtonText: {
|
nextEpisodeButtonText: {
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
|
|||||||
179
components/PlayerControls.mobile.tsx
Normal file
179
components/PlayerControls.mobile.tsx
Normal file
@@ -0,0 +1,179 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { View, Text, StyleSheet, Pressable } from "react-native";
|
||||||
|
import { Pause, Play, SkipForward, List, Tv } from "lucide-react-native";
|
||||||
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
|
import { MediaButton } from "@/components/MediaButton";
|
||||||
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
|
interface PlayerControlsProps {
|
||||||
|
showControls: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const PlayerControlsMobile: React.FC<PlayerControlsProps> = ({ showControls }) => {
|
||||||
|
const {
|
||||||
|
detail,
|
||||||
|
currentEpisodeIndex,
|
||||||
|
currentSourceIndex,
|
||||||
|
status,
|
||||||
|
isSeeking,
|
||||||
|
seekPosition,
|
||||||
|
progressPosition,
|
||||||
|
togglePlayPause,
|
||||||
|
playEpisode,
|
||||||
|
setShowEpisodeModal,
|
||||||
|
setShowSourceModal,
|
||||||
|
} = usePlayerStore();
|
||||||
|
|
||||||
|
const videoTitle = detail?.videoInfo?.title || "";
|
||||||
|
const currentEpisode = detail?.episodes[currentEpisodeIndex];
|
||||||
|
const currentEpisodeTitle = currentEpisode?.title;
|
||||||
|
const hasNextEpisode = currentEpisodeIndex < (detail?.episodes.length || 0) - 1;
|
||||||
|
|
||||||
|
const formatTime = (milliseconds: number) => {
|
||||||
|
if (!milliseconds) return "00:00";
|
||||||
|
const totalSeconds = Math.floor(milliseconds / 1000);
|
||||||
|
const minutes = Math.floor(totalSeconds / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPlayNextEpisode = () => {
|
||||||
|
if (hasNextEpisode) {
|
||||||
|
playEpisode(currentEpisodeIndex + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.controlsOverlay}>
|
||||||
|
<View style={styles.topControls}>
|
||||||
|
<Text style={styles.controlTitle} numberOfLines={2}>
|
||||||
|
{videoTitle} {currentEpisodeTitle ? `- ${currentEpisodeTitle}` : ""}
|
||||||
|
</Text>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.middleControls}>
|
||||||
|
{/* This area can be used for gesture-based seeking indicators in the future */}
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.bottomControlsContainer}>
|
||||||
|
<View style={styles.timeAndActions}>
|
||||||
|
<ThemedText style={styles.timeText}>
|
||||||
|
{status?.isLoaded
|
||||||
|
? `${formatTime(status.positionMillis)} / ${formatTime(status.durationMillis || 0)}`
|
||||||
|
: "00:00 / 00:00"}
|
||||||
|
</ThemedText>
|
||||||
|
<View style={styles.actions}>
|
||||||
|
<MediaButton onPress={() => setShowEpisodeModal(true)}>
|
||||||
|
<List color="white" size={22} />
|
||||||
|
</MediaButton>
|
||||||
|
<MediaButton onPress={() => setShowSourceModal(true)}>
|
||||||
|
<Tv color="white" size={22} />
|
||||||
|
</MediaButton>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.progressBarContainer}>
|
||||||
|
<View style={styles.progressBarBackground} />
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.progressBarFilled,
|
||||||
|
{
|
||||||
|
width: `${(isSeeking ? seekPosition : progressPosition) * 100}%`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
<Pressable style={styles.progressBarTouchable} />
|
||||||
|
</View>
|
||||||
|
|
||||||
|
<View style={styles.mainControls}>
|
||||||
|
<View style={styles.placeholder} />
|
||||||
|
<MediaButton onPress={togglePlayPause}>
|
||||||
|
{status?.isLoaded && status.isPlaying ? (
|
||||||
|
<Pause color="white" size={36} />
|
||||||
|
) : (
|
||||||
|
<Play color="white" size={36} />
|
||||||
|
)}
|
||||||
|
</MediaButton>
|
||||||
|
<MediaButton onPress={onPlayNextEpisode} disabled={!hasNextEpisode}>
|
||||||
|
<SkipForward color={hasNextEpisode ? "white" : "#666"} size={28} />
|
||||||
|
</MediaButton>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
controlsOverlay: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.4)",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
paddingHorizontal: 15,
|
||||||
|
paddingVertical: 10,
|
||||||
|
},
|
||||||
|
topControls: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
controlTitle: {
|
||||||
|
color: "white",
|
||||||
|
fontSize: 14,
|
||||||
|
fontWeight: "bold",
|
||||||
|
textAlign: "center",
|
||||||
|
},
|
||||||
|
middleControls: {
|
||||||
|
flex: 1,
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
bottomControlsContainer: {
|
||||||
|
width: "100%",
|
||||||
|
},
|
||||||
|
timeAndActions: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "space-between",
|
||||||
|
alignItems: "center",
|
||||||
|
marginBottom: 5,
|
||||||
|
},
|
||||||
|
timeText: {
|
||||||
|
color: "white",
|
||||||
|
fontSize: 12,
|
||||||
|
},
|
||||||
|
actions: {
|
||||||
|
flexDirection: "row",
|
||||||
|
gap: 15,
|
||||||
|
},
|
||||||
|
progressBarContainer: {
|
||||||
|
width: "100%",
|
||||||
|
height: 4,
|
||||||
|
position: "relative",
|
||||||
|
marginVertical: 10,
|
||||||
|
},
|
||||||
|
progressBarBackground: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.3)",
|
||||||
|
borderRadius: 2,
|
||||||
|
},
|
||||||
|
progressBarFilled: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: "#ff0000",
|
||||||
|
borderRadius: 2,
|
||||||
|
},
|
||||||
|
progressBarTouchable: {
|
||||||
|
position: "absolute",
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
height: 20,
|
||||||
|
top: -8,
|
||||||
|
zIndex: 10,
|
||||||
|
},
|
||||||
|
mainControls: {
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "space-around",
|
||||||
|
alignItems: "center",
|
||||||
|
marginTop: 5,
|
||||||
|
},
|
||||||
|
placeholder: {
|
||||||
|
width: 28, // to balance the skip forward button
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,76 +1,76 @@
|
|||||||
import React from "react";
|
import React, { useCallback, useState } from "react";
|
||||||
import {
|
import { View, Text, StyleSheet, TouchableOpacity, Pressable } from "react-native";
|
||||||
View,
|
|
||||||
Text,
|
|
||||||
StyleSheet,
|
|
||||||
TouchableOpacity,
|
|
||||||
Pressable,
|
|
||||||
} from "react-native";
|
|
||||||
import { useRouter } from "expo-router";
|
import { useRouter } from "expo-router";
|
||||||
import { AVPlaybackStatus } from "expo-av";
|
import { AVPlaybackStatus } from "expo-av";
|
||||||
import {
|
import {
|
||||||
ArrowLeft,
|
|
||||||
Pause,
|
Pause,
|
||||||
Play,
|
Play,
|
||||||
SkipForward,
|
SkipForward,
|
||||||
List,
|
List,
|
||||||
ChevronsRight,
|
ChevronsRight,
|
||||||
ChevronsLeft,
|
ChevronsLeft,
|
||||||
|
Tv,
|
||||||
|
ArrowDownToDot,
|
||||||
|
ArrowUpFromDot,
|
||||||
} from "lucide-react-native";
|
} from "lucide-react-native";
|
||||||
import { ThemedText } from "@/components/ThemedText";
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
import { MediaButton } from "@/components/MediaButton";
|
import { MediaButton } from "@/components/MediaButton";
|
||||||
|
|
||||||
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
interface PlayerControlsProps {
|
interface PlayerControlsProps {
|
||||||
videoTitle: string;
|
showControls: boolean;
|
||||||
currentEpisodeTitle?: string;
|
setShowControls: (show: boolean) => void;
|
||||||
status: AVPlaybackStatus | null;
|
|
||||||
isSeeking: boolean;
|
|
||||||
seekPosition: number;
|
|
||||||
progressPosition: number;
|
|
||||||
currentFocus: string | null;
|
|
||||||
hasNextEpisode: boolean;
|
|
||||||
onSeekStart: () => void;
|
|
||||||
onSeekMove: (event: { nativeEvent: { locationX: number } }) => void;
|
|
||||||
onSeekRelease: (event: { nativeEvent: { locationX: number } }) => void;
|
|
||||||
onSeek: (forward: boolean) => void;
|
|
||||||
onTogglePlayPause: () => void;
|
|
||||||
onPlayNextEpisode: () => void;
|
|
||||||
onShowEpisodes: () => void;
|
|
||||||
formatTime: (time: number) => string;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const PlayerControls: React.FC<PlayerControlsProps> = ({
|
export const PlayerControls: React.FC<PlayerControlsProps> = ({ showControls, setShowControls }) => {
|
||||||
videoTitle,
|
|
||||||
currentEpisodeTitle,
|
|
||||||
status,
|
|
||||||
isSeeking,
|
|
||||||
seekPosition,
|
|
||||||
progressPosition,
|
|
||||||
currentFocus,
|
|
||||||
hasNextEpisode,
|
|
||||||
onSeekStart,
|
|
||||||
onSeekMove,
|
|
||||||
onSeekRelease,
|
|
||||||
onSeek,
|
|
||||||
onTogglePlayPause,
|
|
||||||
onPlayNextEpisode,
|
|
||||||
onShowEpisodes,
|
|
||||||
formatTime,
|
|
||||||
}) => {
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const {
|
||||||
|
detail,
|
||||||
|
currentEpisodeIndex,
|
||||||
|
currentSourceIndex,
|
||||||
|
status,
|
||||||
|
isSeeking,
|
||||||
|
seekPosition,
|
||||||
|
progressPosition,
|
||||||
|
seek,
|
||||||
|
togglePlayPause,
|
||||||
|
playEpisode,
|
||||||
|
setShowEpisodeModal,
|
||||||
|
setShowSourceModal,
|
||||||
|
setIntroEndTime,
|
||||||
|
setOutroStartTime,
|
||||||
|
introEndTime,
|
||||||
|
outroStartTime,
|
||||||
|
} = usePlayerStore();
|
||||||
|
|
||||||
|
const videoTitle = detail?.videoInfo?.title || "";
|
||||||
|
const currentEpisode = detail?.episodes[currentEpisodeIndex];
|
||||||
|
const currentEpisodeTitle = currentEpisode?.title;
|
||||||
|
const currentSource = detail?.sources[currentSourceIndex];
|
||||||
|
const currentSourceName = currentSource?.source_name;
|
||||||
|
const hasNextEpisode = currentEpisodeIndex < (detail?.episodes.length || 0) - 1;
|
||||||
|
|
||||||
|
const formatTime = (milliseconds: number) => {
|
||||||
|
if (!milliseconds) return "00:00";
|
||||||
|
const totalSeconds = Math.floor(milliseconds / 1000);
|
||||||
|
const minutes = Math.floor(totalSeconds / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
const onPlayNextEpisode = () => {
|
||||||
|
if (hasNextEpisode) {
|
||||||
|
playEpisode(currentEpisodeIndex + 1);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<View style={styles.controlsOverlay}>
|
<View style={styles.controlsOverlay}>
|
||||||
<View style={styles.topControls}>
|
<View style={styles.topControls}>
|
||||||
<TouchableOpacity
|
|
||||||
style={styles.controlButton}
|
|
||||||
onPress={() => router.back()}
|
|
||||||
>
|
|
||||||
<ArrowLeft color="white" size={24} />
|
|
||||||
</TouchableOpacity>
|
|
||||||
|
|
||||||
<Text style={styles.controlTitle}>
|
<Text style={styles.controlTitle}>
|
||||||
{videoTitle} {currentEpisodeTitle ? `- ${currentEpisodeTitle}` : ""}
|
{videoTitle} {currentEpisodeTitle ? `- ${currentEpisodeTitle}` : ""}{" "}
|
||||||
|
{currentSourceName ? `(${currentSourceName})` : ""}
|
||||||
</Text>
|
</Text>
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
@@ -81,40 +81,25 @@ export const PlayerControls: React.FC<PlayerControlsProps> = ({
|
|||||||
style={[
|
style={[
|
||||||
styles.progressBarFilled,
|
styles.progressBarFilled,
|
||||||
{
|
{
|
||||||
width: `${
|
width: `${(isSeeking ? seekPosition : progressPosition) * 100}%`,
|
||||||
(isSeeking ? seekPosition : progressPosition) * 100
|
|
||||||
}%`,
|
|
||||||
},
|
},
|
||||||
]}
|
]}
|
||||||
/>
|
/>
|
||||||
<Pressable
|
<Pressable style={styles.progressBarTouchable} />
|
||||||
style={styles.progressBarTouchable}
|
|
||||||
onPressIn={onSeekStart}
|
|
||||||
onTouchMove={onSeekMove}
|
|
||||||
onTouchEnd={onSeekRelease}
|
|
||||||
/>
|
|
||||||
</View>
|
</View>
|
||||||
|
|
||||||
<ThemedText style={{ color: "white", marginTop: 5 }}>
|
<ThemedText style={{ color: "white", marginTop: 5 }}>
|
||||||
{status?.isLoaded
|
{status?.isLoaded
|
||||||
? `${formatTime(status.positionMillis)} / ${formatTime(
|
? `${formatTime(status.positionMillis)} / ${formatTime(status.durationMillis || 0)}`
|
||||||
status.durationMillis || 0
|
|
||||||
)}`
|
|
||||||
: "00:00 / 00:00"}
|
: "00:00 / 00:00"}
|
||||||
</ThemedText>
|
</ThemedText>
|
||||||
|
|
||||||
<View style={styles.bottomControls}>
|
<View style={styles.bottomControls}>
|
||||||
<MediaButton
|
<MediaButton onPress={setIntroEndTime} timeLabel={introEndTime ? formatTime(introEndTime) : undefined}>
|
||||||
onPress={() => onSeek(false)}
|
<ArrowDownToDot color="white" size={24} />
|
||||||
isFocused={currentFocus === "skipBack"}
|
|
||||||
>
|
|
||||||
<ChevronsLeft color="white" size={24} />
|
|
||||||
</MediaButton>
|
</MediaButton>
|
||||||
|
|
||||||
<MediaButton
|
<MediaButton onPress={togglePlayPause} hasTVPreferredFocus={showControls}>
|
||||||
onPress={onTogglePlayPause}
|
|
||||||
isFocused={currentFocus === "playPause"}
|
|
||||||
>
|
|
||||||
{status?.isLoaded && status.isPlaying ? (
|
{status?.isLoaded && status.isPlaying ? (
|
||||||
<Pause color="white" size={24} />
|
<Pause color="white" size={24} />
|
||||||
) : (
|
) : (
|
||||||
@@ -122,27 +107,21 @@ export const PlayerControls: React.FC<PlayerControlsProps> = ({
|
|||||||
)}
|
)}
|
||||||
</MediaButton>
|
</MediaButton>
|
||||||
|
|
||||||
<MediaButton
|
<MediaButton onPress={onPlayNextEpisode} disabled={!hasNextEpisode}>
|
||||||
onPress={onPlayNextEpisode}
|
|
||||||
isFocused={currentFocus === "nextEpisode"}
|
|
||||||
isDisabled={!hasNextEpisode}
|
|
||||||
>
|
|
||||||
<SkipForward color={hasNextEpisode ? "white" : "#666"} size={24} />
|
<SkipForward color={hasNextEpisode ? "white" : "#666"} size={24} />
|
||||||
</MediaButton>
|
</MediaButton>
|
||||||
|
|
||||||
<MediaButton
|
<MediaButton onPress={setOutroStartTime} timeLabel={outroStartTime ? formatTime(outroStartTime) : undefined}>
|
||||||
onPress={() => onSeek(true)}
|
<ArrowUpFromDot color="white" size={24} />
|
||||||
isFocused={currentFocus === "skipForward"}
|
|
||||||
>
|
|
||||||
<ChevronsRight color="white" size={24} />
|
|
||||||
</MediaButton>
|
</MediaButton>
|
||||||
|
|
||||||
<MediaButton
|
<MediaButton onPress={() => setShowEpisodeModal(true)}>
|
||||||
onPress={onShowEpisodes}
|
|
||||||
isFocused={currentFocus === "episodes"}
|
|
||||||
>
|
|
||||||
<List color="white" size={24} />
|
<List color="white" size={24} />
|
||||||
</MediaButton>
|
</MediaButton>
|
||||||
|
|
||||||
|
<MediaButton onPress={() => setShowSourceModal(true)}>
|
||||||
|
<Tv color="white" size={24} />
|
||||||
|
</MediaButton>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
86
components/SeekingBar.tsx
Normal file
86
components/SeekingBar.tsx
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { View, StyleSheet, Text } from "react-native";
|
||||||
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
|
const formatTime = (milliseconds: number) => {
|
||||||
|
if (isNaN(milliseconds) || milliseconds < 0) {
|
||||||
|
return "00:00";
|
||||||
|
}
|
||||||
|
const totalSeconds = Math.floor(milliseconds / 1000);
|
||||||
|
const hours = Math.floor(totalSeconds / 3600);
|
||||||
|
const minutes = Math.floor((totalSeconds % 3600) / 60);
|
||||||
|
const seconds = totalSeconds % 60;
|
||||||
|
|
||||||
|
if (hours > 0) {
|
||||||
|
return `${hours.toString().padStart(2, "0")}:${minutes.toString().padStart(2, "0")}:${seconds
|
||||||
|
.toString()
|
||||||
|
.padStart(2, "0")}`;
|
||||||
|
}
|
||||||
|
return `${minutes.toString().padStart(2, "0")}:${seconds.toString().padStart(2, "0")}`;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const SeekingBar = () => {
|
||||||
|
const { isSeeking, seekPosition, status } = usePlayerStore();
|
||||||
|
|
||||||
|
if (!isSeeking || !status?.isLoaded) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const durationMillis = status.durationMillis || 0;
|
||||||
|
const currentPositionMillis = seekPosition * durationMillis;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<View style={styles.seekingContainer}>
|
||||||
|
<Text style={styles.timeText}>
|
||||||
|
{formatTime(currentPositionMillis)} / {formatTime(durationMillis)}
|
||||||
|
</Text>
|
||||||
|
<View style={styles.seekingBarContainer}>
|
||||||
|
<View style={styles.seekingBarBackground} />
|
||||||
|
<View
|
||||||
|
style={[
|
||||||
|
styles.seekingBarFilled,
|
||||||
|
{
|
||||||
|
width: `${seekPosition * 100}%`,
|
||||||
|
},
|
||||||
|
]}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
seekingContainer: {
|
||||||
|
position: "absolute",
|
||||||
|
bottom: 80,
|
||||||
|
left: "5%",
|
||||||
|
right: "5%",
|
||||||
|
alignItems: "center",
|
||||||
|
},
|
||||||
|
timeText: {
|
||||||
|
color: "white",
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: "bold",
|
||||||
|
backgroundColor: "rgba(0,0,0,0.6)",
|
||||||
|
paddingHorizontal: 12,
|
||||||
|
paddingVertical: 6,
|
||||||
|
borderRadius: 8,
|
||||||
|
marginBottom: 10,
|
||||||
|
},
|
||||||
|
seekingBarContainer: {
|
||||||
|
width: "100%",
|
||||||
|
height: 5,
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.3)",
|
||||||
|
borderRadius: 2.5,
|
||||||
|
},
|
||||||
|
seekingBarBackground: {
|
||||||
|
...StyleSheet.absoluteFillObject,
|
||||||
|
backgroundColor: "rgba(255, 255, 255, 0.3)",
|
||||||
|
borderRadius: 2.5,
|
||||||
|
},
|
||||||
|
seekingBarFilled: {
|
||||||
|
height: "100%",
|
||||||
|
backgroundColor: "#ff0000",
|
||||||
|
borderRadius: 2.5,
|
||||||
|
},
|
||||||
|
});
|
||||||
@@ -1,49 +1,40 @@
|
|||||||
import React, { useState, useEffect, useRef } from 'react';
|
import React, { useState, useEffect, useRef } from "react";
|
||||||
import { Modal, View, Text, TextInput, StyleSheet, Pressable, useColorScheme } from 'react-native';
|
import { Modal, View, Text, TextInput, StyleSheet } from "react-native";
|
||||||
import { SettingsManager } from '@/services/storage';
|
import { ThemedText } from "./ThemedText";
|
||||||
import { api } from '@/services/api';
|
import { ThemedView } from "./ThemedView";
|
||||||
import { ThemedText } from './ThemedText';
|
import { useSettingsStore } from "@/stores/settingsStore";
|
||||||
import { ThemedView } from './ThemedView';
|
import { StyledButton } from "./StyledButton";
|
||||||
|
|
||||||
interface SettingsModalProps {
|
export const SettingsModal: React.FC = () => {
|
||||||
visible: boolean;
|
const { isModalVisible, hideModal, apiBaseUrl, setApiBaseUrl, saveSettings, loadSettings } = useSettingsStore();
|
||||||
onCancel: () => void;
|
|
||||||
onSave: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const SettingsModal: React.FC<SettingsModalProps> = ({ visible, onCancel, onSave }) => {
|
|
||||||
const [apiUrl, setApiUrl] = useState('');
|
|
||||||
const [isInputFocused, setIsInputFocused] = useState(false);
|
const [isInputFocused, setIsInputFocused] = useState(false);
|
||||||
const colorScheme = useColorScheme();
|
const colorScheme = "dark"; // Replace with useColorScheme() if needed
|
||||||
const inputRef = useRef<TextInput>(null);
|
const inputRef = useRef<TextInput>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (visible) {
|
if (isModalVisible) {
|
||||||
SettingsManager.get().then(settings => {
|
loadSettings();
|
||||||
setApiUrl(settings.apiBaseUrl);
|
|
||||||
});
|
|
||||||
const timer = setTimeout(() => {
|
const timer = setTimeout(() => {
|
||||||
inputRef.current?.focus();
|
inputRef.current?.focus();
|
||||||
}, 200);
|
}, 200);
|
||||||
return () => clearTimeout(timer);
|
return () => clearTimeout(timer);
|
||||||
}
|
}
|
||||||
}, [visible]);
|
}, [isModalVisible, loadSettings]);
|
||||||
|
|
||||||
const handleSave = async () => {
|
const handleSave = () => {
|
||||||
await SettingsManager.save({ apiBaseUrl: apiUrl });
|
saveSettings();
|
||||||
api.setBaseUrl(apiUrl);
|
|
||||||
onSave();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const styles = StyleSheet.create({
|
const styles = StyleSheet.create({
|
||||||
modalContainer: {
|
modalContainer: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.6)',
|
backgroundColor: "rgba(0, 0, 0, 0.6)",
|
||||||
},
|
},
|
||||||
modalContent: {
|
modalContent: {
|
||||||
width: '80%',
|
width: "80%",
|
||||||
maxWidth: 500,
|
maxWidth: 500,
|
||||||
padding: 24,
|
padding: 24,
|
||||||
borderRadius: 12,
|
borderRadius: 12,
|
||||||
@@ -51,9 +42,9 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ visible, onCancel,
|
|||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
marginBottom: 20,
|
marginBottom: 20,
|
||||||
textAlign: 'center',
|
textAlign: "center",
|
||||||
},
|
},
|
||||||
input: {
|
input: {
|
||||||
height: 50,
|
height: 50,
|
||||||
@@ -62,80 +53,63 @@ export const SettingsModal: React.FC<SettingsModalProps> = ({ visible, onCancel,
|
|||||||
paddingHorizontal: 15,
|
paddingHorizontal: 15,
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
marginBottom: 24,
|
marginBottom: 24,
|
||||||
backgroundColor: colorScheme === 'dark' ? '#3a3a3c' : '#f0f0f0',
|
backgroundColor: colorScheme === "dark" ? "#3a3a3c" : "#f0f0f0",
|
||||||
color: colorScheme === 'dark' ? 'white' : 'black',
|
color: colorScheme === "dark" ? "white" : "black",
|
||||||
borderColor: 'transparent',
|
borderColor: "transparent",
|
||||||
},
|
},
|
||||||
inputFocused: {
|
inputFocused: {
|
||||||
borderColor: '#007AFF',
|
borderColor: "#007AFF",
|
||||||
shadowColor: '#007AFF',
|
shadowColor: "#007AFF",
|
||||||
shadowOffset: { width: 0, height: 0 },
|
shadowOffset: { width: 0, height: 0 },
|
||||||
shadowOpacity: 0.8,
|
shadowOpacity: 0.8,
|
||||||
shadowRadius: 10,
|
shadowRadius: 10,
|
||||||
elevation: 5,
|
elevation: 5,
|
||||||
},
|
},
|
||||||
buttonContainer: {
|
buttonContainer: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
justifyContent: 'space-around',
|
justifyContent: "space-around",
|
||||||
},
|
},
|
||||||
button: {
|
button: {
|
||||||
flex: 1,
|
flex: 1,
|
||||||
paddingVertical: 12,
|
|
||||||
borderRadius: 8,
|
|
||||||
alignItems: 'center',
|
|
||||||
marginHorizontal: 8,
|
marginHorizontal: 8,
|
||||||
},
|
},
|
||||||
buttonSave: {
|
|
||||||
backgroundColor: '#007AFF',
|
|
||||||
},
|
|
||||||
buttonCancel: {
|
|
||||||
backgroundColor: colorScheme === 'dark' ? '#444' : '#ccc',
|
|
||||||
},
|
|
||||||
buttonText: {
|
buttonText: {
|
||||||
color: 'white',
|
|
||||||
fontSize: 18,
|
fontSize: 18,
|
||||||
fontWeight: '500',
|
|
||||||
},
|
|
||||||
focusedButton: {
|
|
||||||
transform: [{ scale: 1.05 }],
|
|
||||||
shadowColor: '#000',
|
|
||||||
shadowOffset: { width: 0, height: 4 },
|
|
||||||
shadowOpacity: 0.3,
|
|
||||||
shadowRadius: 5,
|
|
||||||
elevation: 8,
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Modal animationType="fade" transparent={true} visible={visible} onRequestClose={onCancel}>
|
<Modal animationType="fade" transparent={true} visible={isModalVisible} onRequestClose={hideModal}>
|
||||||
<View style={styles.modalContainer}>
|
<View style={styles.modalContainer}>
|
||||||
<ThemedView style={styles.modalContent}>
|
<ThemedView style={styles.modalContent}>
|
||||||
<ThemedText style={styles.title}>设置</ThemedText>
|
<ThemedText style={styles.title}>设置</ThemedText>
|
||||||
<TextInput
|
<TextInput
|
||||||
ref={inputRef}
|
ref={inputRef}
|
||||||
style={[styles.input, isInputFocused && styles.inputFocused]}
|
style={[styles.input, isInputFocused && styles.inputFocused]}
|
||||||
value={apiUrl}
|
value={apiBaseUrl}
|
||||||
onChangeText={setApiUrl}
|
onChangeText={setApiBaseUrl}
|
||||||
placeholder="输入 API 地址"
|
placeholder="输入 API 地址"
|
||||||
placeholderTextColor={colorScheme === 'dark' ? '#888' : '#555'}
|
placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"}
|
||||||
autoCapitalize="none"
|
autoCapitalize="none"
|
||||||
autoCorrect={false}
|
autoCorrect={false}
|
||||||
onFocus={() => setIsInputFocused(true)}
|
onFocus={() => setIsInputFocused(true)}
|
||||||
onBlur={() => setIsInputFocused(false)}
|
onBlur={() => setIsInputFocused(false)}
|
||||||
/>
|
/>
|
||||||
<View style={styles.buttonContainer}>
|
<View style={styles.buttonContainer}>
|
||||||
<Pressable
|
<StyledButton
|
||||||
style={({ focused }) => [styles.button, styles.buttonCancel, focused && styles.focusedButton]}
|
text="取消"
|
||||||
onPress={onCancel}
|
onPress={hideModal}
|
||||||
>
|
style={styles.button}
|
||||||
<Text style={styles.buttonText}>取消</Text>
|
textStyle={styles.buttonText}
|
||||||
</Pressable>
|
variant="default"
|
||||||
<Pressable
|
/>
|
||||||
style={({ focused }) => [styles.button, styles.buttonSave, focused && styles.focusedButton]}
|
<StyledButton
|
||||||
|
text="保存"
|
||||||
onPress={handleSave}
|
onPress={handleSave}
|
||||||
>
|
style={styles.button}
|
||||||
<Text style={styles.buttonText}>保存</Text>
|
textStyle={styles.buttonText}
|
||||||
</Pressable>
|
variant="primary"
|
||||||
|
/>
|
||||||
</View>
|
</View>
|
||||||
</ThemedView>
|
</ThemedView>
|
||||||
</View>
|
</View>
|
||||||
|
|||||||
78
components/SourceSelectionModal.tsx
Normal file
78
components/SourceSelectionModal.tsx
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { View, Text, StyleSheet, Modal, FlatList } from "react-native";
|
||||||
|
import { StyledButton } from "./StyledButton";
|
||||||
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
|
export const SourceSelectionModal: React.FC = () => {
|
||||||
|
const { showSourceModal, sources, currentSourceIndex, switchSource, setShowSourceModal } = usePlayerStore();
|
||||||
|
|
||||||
|
const onSelectSource = (index: number) => {
|
||||||
|
if (index !== currentSourceIndex) {
|
||||||
|
switchSource(index);
|
||||||
|
}
|
||||||
|
setShowSourceModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
const onClose = () => {
|
||||||
|
setShowSourceModal(false);
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Modal visible={showSourceModal} transparent={true} animationType="slide" onRequestClose={onClose}>
|
||||||
|
<View style={styles.modalContainer}>
|
||||||
|
<View style={styles.modalContent}>
|
||||||
|
<Text style={styles.modalTitle}>选择播放源</Text>
|
||||||
|
<FlatList
|
||||||
|
data={sources}
|
||||||
|
numColumns={3}
|
||||||
|
contentContainerStyle={styles.sourceList}
|
||||||
|
keyExtractor={(item, index) => `source-${item.source}-${item.id}-${index}`}
|
||||||
|
renderItem={({ item, index }) => (
|
||||||
|
<StyledButton
|
||||||
|
text={item.source_name}
|
||||||
|
onPress={() => onSelectSource(index)}
|
||||||
|
isSelected={currentSourceIndex === index}
|
||||||
|
hasTVPreferredFocus={currentSourceIndex === index}
|
||||||
|
style={styles.sourceItem}
|
||||||
|
textStyle={styles.sourceItemText}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</View>
|
||||||
|
</View>
|
||||||
|
</Modal>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
modalContainer: {
|
||||||
|
flex: 1,
|
||||||
|
flexDirection: "row",
|
||||||
|
justifyContent: "flex-end",
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
},
|
||||||
|
modalContent: {
|
||||||
|
width: 600,
|
||||||
|
height: "100%",
|
||||||
|
backgroundColor: "rgba(0, 0, 0, 0.85)",
|
||||||
|
padding: 20,
|
||||||
|
},
|
||||||
|
modalTitle: {
|
||||||
|
color: "white",
|
||||||
|
marginBottom: 12,
|
||||||
|
textAlign: "center",
|
||||||
|
fontSize: 18,
|
||||||
|
fontWeight: "bold",
|
||||||
|
},
|
||||||
|
sourceList: {
|
||||||
|
justifyContent: "flex-start",
|
||||||
|
},
|
||||||
|
sourceItem: {
|
||||||
|
paddingVertical: 2,
|
||||||
|
margin: 4,
|
||||||
|
width: "31%",
|
||||||
|
},
|
||||||
|
sourceItemText: {
|
||||||
|
fontSize: 14,
|
||||||
|
},
|
||||||
|
});
|
||||||
147
components/StyledButton.tsx
Normal file
147
components/StyledButton.tsx
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import React from "react";
|
||||||
|
import { Animated, Pressable, StyleSheet, StyleProp, ViewStyle, PressableProps, TextStyle } from "react-native";
|
||||||
|
import { ThemedText } from "./ThemedText";
|
||||||
|
import { Colors } from "@/constants/Colors";
|
||||||
|
import { useButtonAnimation } from "@/hooks/useButtonAnimation";
|
||||||
|
import { useResponsive } from "@/hooks/useResponsive";
|
||||||
|
|
||||||
|
interface StyledButtonProps extends PressableProps {
|
||||||
|
children?: React.ReactNode;
|
||||||
|
text?: string;
|
||||||
|
variant?: "default" | "primary" | "ghost";
|
||||||
|
isSelected?: boolean;
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
textStyle?: StyleProp<TextStyle>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const StyledButton: React.FC<StyledButtonProps> = ({
|
||||||
|
children,
|
||||||
|
text,
|
||||||
|
variant = "default",
|
||||||
|
isSelected = false,
|
||||||
|
style,
|
||||||
|
textStyle,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
|
const colorScheme = "dark";
|
||||||
|
const colors = Colors[colorScheme];
|
||||||
|
const [isFocused, setIsFocused] = React.useState(false);
|
||||||
|
const animationStyle = useButtonAnimation(isFocused);
|
||||||
|
const { isMobile } = useResponsive();
|
||||||
|
|
||||||
|
const variantStyles = {
|
||||||
|
default: StyleSheet.create({
|
||||||
|
button: {
|
||||||
|
backgroundColor: colors.border,
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: colors.text,
|
||||||
|
},
|
||||||
|
selectedButton: {
|
||||||
|
backgroundColor: colors.tint,
|
||||||
|
},
|
||||||
|
focusedButton: {
|
||||||
|
backgroundColor: colors.link,
|
||||||
|
borderColor: colors.background,
|
||||||
|
},
|
||||||
|
selectedText: {
|
||||||
|
color: Colors.dark.text,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
primary: StyleSheet.create({
|
||||||
|
button: {
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: colors.text,
|
||||||
|
},
|
||||||
|
focusedButton: {
|
||||||
|
backgroundColor: colors.link,
|
||||||
|
borderColor: colors.background,
|
||||||
|
},
|
||||||
|
selectedButton: {
|
||||||
|
backgroundColor: "rgba(0, 122, 255, 0.3)",
|
||||||
|
},
|
||||||
|
selectedText: {
|
||||||
|
color: colors.link,
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
ghost: StyleSheet.create({
|
||||||
|
button: {
|
||||||
|
backgroundColor: "transparent",
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
color: colors.text,
|
||||||
|
},
|
||||||
|
focusedButton: {
|
||||||
|
backgroundColor: "rgba(119, 119, 119, 0.9)",
|
||||||
|
},
|
||||||
|
selectedButton: {},
|
||||||
|
selectedText: {},
|
||||||
|
}),
|
||||||
|
};
|
||||||
|
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
button: {
|
||||||
|
paddingHorizontal: isMobile ? 12 : 16,
|
||||||
|
paddingVertical: isMobile ? 8 : 10,
|
||||||
|
borderRadius: 8,
|
||||||
|
borderWidth: 2,
|
||||||
|
borderColor: "transparent",
|
||||||
|
flexDirection: "row",
|
||||||
|
alignItems: "center",
|
||||||
|
justifyContent: "center",
|
||||||
|
},
|
||||||
|
focusedButton: {
|
||||||
|
backgroundColor: colors.link,
|
||||||
|
borderColor: colors.background,
|
||||||
|
elevation: 5,
|
||||||
|
shadowColor: colors.link,
|
||||||
|
shadowOffset: { width: 0, height: 0 },
|
||||||
|
shadowOpacity: 1,
|
||||||
|
shadowRadius: 15,
|
||||||
|
},
|
||||||
|
selectedButton: {
|
||||||
|
backgroundColor: colors.tint,
|
||||||
|
},
|
||||||
|
text: {
|
||||||
|
fontSize: isMobile ? 14 : 16,
|
||||||
|
fontWeight: "500",
|
||||||
|
color: colors.text,
|
||||||
|
},
|
||||||
|
selectedText: {
|
||||||
|
color: Colors.dark.text,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View style={[animationStyle, style]}>
|
||||||
|
<Pressable
|
||||||
|
onFocus={() => setIsFocused(true)}
|
||||||
|
onBlur={() => setIsFocused(false)}
|
||||||
|
style={({ focused }) => [
|
||||||
|
styles.button,
|
||||||
|
variantStyles[variant].button,
|
||||||
|
isSelected && (variantStyles[variant].selectedButton ?? styles.selectedButton),
|
||||||
|
focused && (variantStyles[variant].focusedButton ?? styles.focusedButton),
|
||||||
|
]}
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{text ? (
|
||||||
|
<ThemedText
|
||||||
|
style={[
|
||||||
|
styles.text,
|
||||||
|
variantStyles[variant].text,
|
||||||
|
isSelected && (variantStyles[variant].selectedText ?? styles.selectedText),
|
||||||
|
textStyle,
|
||||||
|
]}
|
||||||
|
>
|
||||||
|
{text}
|
||||||
|
</ThemedText>
|
||||||
|
) : (
|
||||||
|
children
|
||||||
|
)}
|
||||||
|
</Pressable>
|
||||||
|
</Animated.View>
|
||||||
|
);
|
||||||
|
};
|
||||||
@@ -1,22 +1,14 @@
|
|||||||
import {View, type ViewProps} from 'react-native';
|
import { View, type ViewProps } from "react-native";
|
||||||
|
|
||||||
import {useThemeColor} from '@/hooks/useThemeColor';
|
import { useThemeColor } from "@/hooks/useThemeColor";
|
||||||
|
|
||||||
export type ThemedViewProps = ViewProps & {
|
export type ThemedViewProps = ViewProps & {
|
||||||
lightColor?: string;
|
lightColor?: string;
|
||||||
darkColor?: string;
|
darkColor?: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function ThemedView({
|
export function ThemedView({ style, lightColor, darkColor, ...otherProps }: ThemedViewProps) {
|
||||||
style,
|
const backgroundColor = useThemeColor({ light: lightColor, dark: darkColor }, "background");
|
||||||
lightColor,
|
|
||||||
darkColor,
|
|
||||||
...otherProps
|
|
||||||
}: ThemedViewProps) {
|
|
||||||
const backgroundColor = useThemeColor(
|
|
||||||
{light: lightColor, dark: darkColor},
|
|
||||||
'background',
|
|
||||||
);
|
|
||||||
|
|
||||||
return <View style={[{backgroundColor}, style]} {...otherProps} />;
|
return <View style={[{ backgroundColor }, style]} {...otherProps} />;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import React, { useState, useEffect, useCallback, useRef } from 'react';
|
import React, { useState, useEffect, useCallback, useRef } from "react";
|
||||||
import { View, Text, Image, StyleSheet, Pressable, TouchableOpacity, Alert } from 'react-native';
|
import { View, Text, Image, StyleSheet, Pressable, TouchableOpacity, Alert } from "react-native";
|
||||||
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from 'react-native-reanimated';
|
import Animated, { useSharedValue, useAnimatedStyle, withSpring } from "react-native-reanimated";
|
||||||
import { useRouter } from 'expo-router';
|
import { useRouter } from "expo-router";
|
||||||
import { Heart, Star, Play, Trash2 } from 'lucide-react-native';
|
import { Heart, Star, Play, Trash2 } from "lucide-react-native";
|
||||||
import { FavoriteManager, PlayRecordManager } from '@/services/storage';
|
import { FavoriteManager, PlayRecordManager } from "@/services/storage";
|
||||||
import { API, api } from '@/services/api';
|
import { API, api } from "@/services/api";
|
||||||
import { ThemedText } from '@/components/ThemedText';
|
import { ThemedText } from "@/components/ThemedText";
|
||||||
|
|
||||||
interface VideoCardProps {
|
interface VideoCardProps {
|
||||||
id: string;
|
id: string;
|
||||||
@@ -16,6 +16,7 @@ interface VideoCardProps {
|
|||||||
rate?: string;
|
rate?: string;
|
||||||
sourceName?: string;
|
sourceName?: string;
|
||||||
progress?: number; // 播放进度,0-1之间的小数
|
progress?: number; // 播放进度,0-1之间的小数
|
||||||
|
playTime?: number; // 播放时间 in ms
|
||||||
episodeIndex?: number; // 剧集索引
|
episodeIndex?: number; // 剧集索引
|
||||||
totalEpisodes?: number; // 总集数
|
totalEpisodes?: number; // 总集数
|
||||||
onFocus?: () => void;
|
onFocus?: () => void;
|
||||||
@@ -37,6 +38,7 @@ export default function VideoCard({
|
|||||||
onFocus,
|
onFocus,
|
||||||
onRecordDeleted,
|
onRecordDeleted,
|
||||||
api,
|
api,
|
||||||
|
playTime,
|
||||||
}: VideoCardProps) {
|
}: VideoCardProps) {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
const [isFocused, setIsFocused] = useState(false);
|
const [isFocused, setIsFocused] = useState(false);
|
||||||
@@ -59,12 +61,12 @@ export default function VideoCard({
|
|||||||
// 如果有播放进度,直接转到播放页面
|
// 如果有播放进度,直接转到播放页面
|
||||||
if (progress !== undefined && episodeIndex !== undefined) {
|
if (progress !== undefined && episodeIndex !== undefined) {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/play',
|
pathname: "/play",
|
||||||
params: { source, id, episodeIndex },
|
params: { source, id, episodeIndex, position: playTime },
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
router.push({
|
router.push({
|
||||||
pathname: '/detail',
|
pathname: "/detail",
|
||||||
params: { source, q: title },
|
params: { source, q: title },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -88,14 +90,14 @@ export default function VideoCard({
|
|||||||
longPressTriggered.current = true;
|
longPressTriggered.current = true;
|
||||||
|
|
||||||
// Show confirmation dialog to delete play record
|
// Show confirmation dialog to delete play record
|
||||||
Alert.alert('删除观看记录', `确定要删除"${title}"的观看记录吗?`, [
|
Alert.alert("删除观看记录", `确定要删除"${title}"的观看记录吗?`, [
|
||||||
{
|
{
|
||||||
text: '取消',
|
text: "取消",
|
||||||
style: 'cancel',
|
style: "cancel",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
text: '删除',
|
text: "删除",
|
||||||
style: 'destructive',
|
style: "destructive",
|
||||||
onPress: async () => {
|
onPress: async () => {
|
||||||
try {
|
try {
|
||||||
// Delete from local storage
|
// Delete from local storage
|
||||||
@@ -107,11 +109,11 @@ export default function VideoCard({
|
|||||||
}
|
}
|
||||||
// 如果没有回调函数,则使用导航刷新作为备选方案
|
// 如果没有回调函数,则使用导航刷新作为备选方案
|
||||||
else if (router.canGoBack()) {
|
else if (router.canGoBack()) {
|
||||||
router.replace('/');
|
router.replace("/");
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Failed to delete play record:', error);
|
console.error("Failed to delete play record:", error);
|
||||||
Alert.alert('错误', '删除观看记录失败,请重试');
|
Alert.alert("错误", "删除观看记录失败,请重试");
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@@ -171,7 +173,7 @@ export default function VideoCard({
|
|||||||
</View>
|
</View>
|
||||||
<View style={styles.infoContainer}>
|
<View style={styles.infoContainer}>
|
||||||
<ThemedText numberOfLines={1}>{title}</ThemedText>
|
<ThemedText numberOfLines={1}>{title}</ThemedText>
|
||||||
{isContinueWatching && !isFocused && (
|
{isContinueWatching && (
|
||||||
<View style={styles.infoRow}>
|
<View style={styles.infoRow}>
|
||||||
<ThemedText style={styles.continueLabel}>
|
<ThemedText style={styles.continueLabel}>
|
||||||
第{episodeIndex! + 1}集 已观看 {Math.round((progress || 0) * 100)}%
|
第{episodeIndex! + 1}集 已观看 {Math.round((progress || 0) * 100)}%
|
||||||
@@ -192,126 +194,126 @@ const styles = StyleSheet.create({
|
|||||||
marginHorizontal: 8,
|
marginHorizontal: 8,
|
||||||
},
|
},
|
||||||
pressable: {
|
pressable: {
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
card: {
|
card: {
|
||||||
width: CARD_WIDTH,
|
width: CARD_WIDTH,
|
||||||
height: CARD_HEIGHT,
|
height: CARD_HEIGHT,
|
||||||
borderRadius: 8,
|
borderRadius: 8,
|
||||||
backgroundColor: '#222',
|
backgroundColor: "#222",
|
||||||
overflow: 'hidden',
|
overflow: "hidden",
|
||||||
},
|
},
|
||||||
poster: {
|
poster: {
|
||||||
width: '100%',
|
width: "100%",
|
||||||
height: '100%',
|
height: "100%",
|
||||||
},
|
},
|
||||||
overlay: {
|
overlay: {
|
||||||
...StyleSheet.absoluteFillObject,
|
...StyleSheet.absoluteFillObject,
|
||||||
backgroundColor: 'rgba(0,0,0,0.3)',
|
backgroundColor: "rgba(0,0,0,0.3)",
|
||||||
justifyContent: 'center',
|
justifyContent: "center",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
},
|
},
|
||||||
buttonRow: {
|
buttonRow: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
top: 8,
|
top: 8,
|
||||||
left: 8,
|
left: 8,
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
gap: 8,
|
gap: 8,
|
||||||
},
|
},
|
||||||
iconButton: {
|
iconButton: {
|
||||||
padding: 4,
|
padding: 4,
|
||||||
},
|
},
|
||||||
favButton: {
|
favButton: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
top: 8,
|
top: 8,
|
||||||
left: 8,
|
left: 8,
|
||||||
},
|
},
|
||||||
ratingContainer: {
|
ratingContainer: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
top: 8,
|
top: 8,
|
||||||
right: 8,
|
right: 8,
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
||||||
borderRadius: 6,
|
borderRadius: 6,
|
||||||
paddingHorizontal: 6,
|
paddingHorizontal: 6,
|
||||||
paddingVertical: 3,
|
paddingVertical: 3,
|
||||||
},
|
},
|
||||||
ratingText: {
|
ratingText: {
|
||||||
color: '#FFD700',
|
color: "#FFD700",
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
marginLeft: 4,
|
marginLeft: 4,
|
||||||
},
|
},
|
||||||
infoContainer: {
|
infoContainer: {
|
||||||
width: CARD_WIDTH,
|
width: CARD_WIDTH,
|
||||||
marginTop: 8,
|
marginTop: 8,
|
||||||
alignItems: 'flex-start', // Align items to the start
|
alignItems: "flex-start", // Align items to the start
|
||||||
marginBottom: 16,
|
marginBottom: 16,
|
||||||
paddingHorizontal: 4, // Add some padding
|
paddingHorizontal: 4, // Add some padding
|
||||||
},
|
},
|
||||||
infoRow: {
|
infoRow: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
justifyContent: 'space-between',
|
justifyContent: "space-between",
|
||||||
width: '100%',
|
width: "100%",
|
||||||
},
|
},
|
||||||
title: {
|
title: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
fontSize: 16,
|
fontSize: 16,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
textAlign: 'center',
|
textAlign: "center",
|
||||||
},
|
},
|
||||||
yearBadge: {
|
yearBadge: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
top: 8,
|
top: 8,
|
||||||
right: 8,
|
right: 8,
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
||||||
borderRadius: 6,
|
borderRadius: 6,
|
||||||
paddingHorizontal: 6,
|
paddingHorizontal: 6,
|
||||||
paddingVertical: 3,
|
paddingVertical: 3,
|
||||||
},
|
},
|
||||||
sourceNameBadge: {
|
sourceNameBadge: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
top: 8,
|
top: 8,
|
||||||
left: 8,
|
left: 8,
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.7)',
|
backgroundColor: "rgba(0, 0, 0, 0.7)",
|
||||||
borderRadius: 6,
|
borderRadius: 6,
|
||||||
paddingHorizontal: 6,
|
paddingHorizontal: 6,
|
||||||
paddingVertical: 3,
|
paddingVertical: 3,
|
||||||
},
|
},
|
||||||
badgeText: {
|
badgeText: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
progressContainer: {
|
progressContainer: {
|
||||||
position: 'absolute',
|
position: "absolute",
|
||||||
bottom: 0,
|
bottom: 0,
|
||||||
left: 0,
|
left: 0,
|
||||||
right: 0,
|
right: 0,
|
||||||
height: 3,
|
height: 3,
|
||||||
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
backgroundColor: "rgba(0, 0, 0, 0.5)",
|
||||||
},
|
},
|
||||||
progressBar: {
|
progressBar: {
|
||||||
height: 3,
|
height: 3,
|
||||||
backgroundColor: '#ff0000',
|
backgroundColor: "#ff0000",
|
||||||
},
|
},
|
||||||
continueWatchingBadge: {
|
continueWatchingBadge: {
|
||||||
flexDirection: 'row',
|
flexDirection: "row",
|
||||||
alignItems: 'center',
|
alignItems: "center",
|
||||||
backgroundColor: 'rgba(255, 0, 0, 0.8)',
|
backgroundColor: "rgba(255, 0, 0, 0.8)",
|
||||||
paddingHorizontal: 10,
|
paddingHorizontal: 10,
|
||||||
paddingVertical: 5,
|
paddingVertical: 5,
|
||||||
borderRadius: 5,
|
borderRadius: 5,
|
||||||
},
|
},
|
||||||
continueWatchingText: {
|
continueWatchingText: {
|
||||||
color: 'white',
|
color: "white",
|
||||||
marginLeft: 5,
|
marginLeft: 5,
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontWeight: 'bold',
|
fontWeight: "bold",
|
||||||
},
|
},
|
||||||
continueLabel: {
|
continueLabel: {
|
||||||
color: '#ff5252',
|
color: "#ff5252",
|
||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|||||||
77
docs/components/StyledButton.md
Normal file
77
docs/components/StyledButton.md
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
# StyledButton 组件设计文档
|
||||||
|
|
||||||
|
## 1. 目的
|
||||||
|
|
||||||
|
为了统一整个应用中的按钮样式和行为,减少代码重复,并提高开发效率和一致性,我们设计了一个通用的 `StyledButton` 组件。
|
||||||
|
|
||||||
|
该组件将取代以下位置的自定义 `Pressable` 和 `TouchableOpacity` 实现:
|
||||||
|
|
||||||
|
- `app/index.tsx` (分类按钮, 头部图标按钮)
|
||||||
|
- `components/DetailButton.tsx`
|
||||||
|
- `components/EpisodeSelectionModal.tsx` (剧集分组按钮, 剧集项按钮, 关闭按钮)
|
||||||
|
- `components/SettingsModal.tsx` (取消和保存按钮)
|
||||||
|
- `app/search.tsx` (清除按钮)
|
||||||
|
- `components/MediaButton.tsx` (媒体控制按钮)
|
||||||
|
- `components/NextEpisodeOverlay.tsx` (取消按钮)
|
||||||
|
|
||||||
|
## 2. API 设计
|
||||||
|
|
||||||
|
`StyledButton` 组件将基于 React Native 的 `Pressable` 构建,并提供以下 props:
|
||||||
|
|
||||||
|
```typescript
|
||||||
|
import { PressableProps, StyleProp, ViewStyle, TextStyle } from "react-native";
|
||||||
|
|
||||||
|
interface StyledButtonProps extends PressableProps {
|
||||||
|
// 按钮的主要内容,可以是文本或图标等 React 节点
|
||||||
|
children?: React.ReactNode;
|
||||||
|
|
||||||
|
// 如果按钮只包含文本,可以使用此 prop 快速设置
|
||||||
|
text?: string;
|
||||||
|
|
||||||
|
// 按钮的视觉变体,用于应用不同的预设样式
|
||||||
|
// 'default': 默认灰色背景
|
||||||
|
// 'primary': 主题色背景,用于关键操作
|
||||||
|
// 'ghost': 透明背景,通常用于图标按钮
|
||||||
|
variant?: "default" | "primary" | "ghost";
|
||||||
|
|
||||||
|
// 按钮是否处于选中状态
|
||||||
|
isSelected?: boolean;
|
||||||
|
|
||||||
|
// 覆盖容器的样式
|
||||||
|
style?: StyleProp<ViewStyle>;
|
||||||
|
|
||||||
|
// 覆盖文本的样式 (当使用 `text` prop 时生效)
|
||||||
|
textStyle?: StyleProp<TextStyle>;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## 3. 样式和行为
|
||||||
|
|
||||||
|
### 状态样式:
|
||||||
|
|
||||||
|
- **默认状态 (`default`)**:
|
||||||
|
- 背景色: `#333`
|
||||||
|
- 边框: `transparent`
|
||||||
|
- **聚焦状态 (`focused`)**:
|
||||||
|
- 背景色: `#0056b3` (深蓝色)
|
||||||
|
- 边框: `#fff`
|
||||||
|
- 阴影/光晕效果
|
||||||
|
- 轻微放大 (`transform: scale(1.1)`)
|
||||||
|
- **选中状态 (`isSelected`)**:
|
||||||
|
- 背景色: `#007AFF` (亮蓝色)
|
||||||
|
- **主操作 (`primary`)**:
|
||||||
|
- 默认背景色: `#007AFF`
|
||||||
|
- **透明背景 (`ghost`)**:
|
||||||
|
- 默认背景色: `transparent`
|
||||||
|
|
||||||
|
### 结构:
|
||||||
|
|
||||||
|
组件内部将使用 `Pressable` 作为根元素,并根据 `focused` 和 `isSelected` props 动态计算样式。如果 `children` 和 `text` prop 都提供了,`children` 将优先被渲染。
|
||||||
|
|
||||||
|
## 4. 实现计划
|
||||||
|
|
||||||
|
1. **创建 `components/StyledButton.tsx` 文件**。
|
||||||
|
2. **实现上述 API 和样式逻辑**。
|
||||||
|
3. **逐个重构目标文件**,将原有的 `Pressable`/`TouchableOpacity` 替换为新的 `StyledButton` 组件。
|
||||||
|
4. **删除旧的、不再需要的样式**。
|
||||||
|
5. **测试所有被修改的界面**,确保按钮的功能和视觉效果符合预期。
|
||||||
18
hooks/useButtonAnimation.ts
Normal file
18
hooks/useButtonAnimation.ts
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
import { useRef, useEffect } from 'react';
|
||||||
|
import { Animated } from 'react-native';
|
||||||
|
|
||||||
|
export const useButtonAnimation = (isFocused: boolean) => {
|
||||||
|
const scaleValue = useRef(new Animated.Value(1)).current;
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
Animated.spring(scaleValue, {
|
||||||
|
toValue: isFocused ? 1.1 : 1,
|
||||||
|
friction: 5,
|
||||||
|
useNativeDriver: true,
|
||||||
|
}).start();
|
||||||
|
}, [ isFocused, scaleValue]);
|
||||||
|
|
||||||
|
return {
|
||||||
|
transform: [{ scale: scaleValue }],
|
||||||
|
};
|
||||||
|
};
|
||||||
@@ -1 +0,0 @@
|
|||||||
export {useColorScheme} from 'react-native';
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
// NOTE: The default React Native styling doesn't support server rendering.
|
|
||||||
// Server rendered styles should not change between the first render of the HTML
|
|
||||||
// and the first render on the client. Typically, web developers will use CSS media queries
|
|
||||||
// to render different styles on the client and server, these aren't directly supported in React Native
|
|
||||||
// but can be achieved using a styling library like Nativewind.
|
|
||||||
export function useColorScheme() {
|
|
||||||
return 'light';
|
|
||||||
}
|
|
||||||
43
hooks/useResponsive.ts
Normal file
43
hooks/useResponsive.ts
Normal file
@@ -0,0 +1,43 @@
|
|||||||
|
import { useState, useEffect } from "react";
|
||||||
|
import { Dimensions, Platform } from "react-native";
|
||||||
|
|
||||||
|
const isMobile = Platform.OS === "android" || Platform.OS === "ios";
|
||||||
|
|
||||||
|
interface ResponsiveInfo {
|
||||||
|
isMobile: boolean;
|
||||||
|
screenWidth: number;
|
||||||
|
numColumns: (itemWidth: number, gap?: number) => number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useResponsive(): ResponsiveInfo {
|
||||||
|
const [screenWidth, setScreenWidth] = useState(Dimensions.get("window").width);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
const onChange = (result: { window: { width: number } }) => {
|
||||||
|
setScreenWidth(result.window.width);
|
||||||
|
};
|
||||||
|
|
||||||
|
const subscription = Dimensions.addEventListener("change", onChange);
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
subscription.remove();
|
||||||
|
};
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const calculateNumColumns = (itemWidth: number, gap: number = 16) => {
|
||||||
|
if (!isMobile) {
|
||||||
|
// For TV, you might want a fixed number or a different logic
|
||||||
|
return 5;
|
||||||
|
}
|
||||||
|
const containerPadding = 16; // Horizontal padding of the container
|
||||||
|
const availableWidth = screenWidth - containerPadding * 2;
|
||||||
|
const num = Math.floor(availableWidth / (itemWidth + gap));
|
||||||
|
return Math.max(1, num); // Ensure at least one column
|
||||||
|
};
|
||||||
|
|
||||||
|
return {
|
||||||
|
isMobile,
|
||||||
|
screenWidth,
|
||||||
|
numColumns: calculateNumColumns,
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,114 +1,133 @@
|
|||||||
import { useState, useEffect, useRef } from "react";
|
import { useEffect, useRef, useCallback } from "react";
|
||||||
import { useTVEventHandler } from "react-native";
|
import { useTVEventHandler, HWEvent } from "react-native";
|
||||||
|
import usePlayerStore from "@/stores/playerStore";
|
||||||
|
|
||||||
interface TVRemoteHandlerProps {
|
const SEEK_STEP = 20 * 1000; // 快进/快退的时间步长(毫秒)
|
||||||
showControls: boolean;
|
|
||||||
setShowControls: (show: boolean) => void;
|
|
||||||
showEpisodeModal: boolean;
|
|
||||||
onPlayPause: () => void;
|
|
||||||
onSeek: (forward: boolean) => void;
|
|
||||||
onShowEpisodes: () => void;
|
|
||||||
onPlayNextEpisode: () => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
const focusGraph: Record<string, Record<string, string>> = {
|
// 定时器延迟时间(毫秒)
|
||||||
skipBack: { right: "playPause" },
|
const CONTROLS_TIMEOUT = 5000;
|
||||||
playPause: { left: "skipBack", right: "nextEpisode" },
|
|
||||||
nextEpisode: { left: "playPause", right: "skipForward" },
|
/**
|
||||||
skipForward: { left: "nextEpisode", right: "episodes" },
|
* 管理播放器控件的显示/隐藏、遥控器事件和自动隐藏定时器。
|
||||||
episodes: { left: "skipForward" },
|
* @returns onScreenPress - 一个函数,用于处理屏幕点击事件,以显示控件并重置定时器。
|
||||||
};
|
*/
|
||||||
|
export const useTVRemoteHandler = () => {
|
||||||
|
const { showControls, setShowControls, showEpisodeModal, togglePlayPause, seek } = usePlayerStore();
|
||||||
|
|
||||||
export const useTVRemoteHandler = ({
|
|
||||||
showControls,
|
|
||||||
setShowControls,
|
|
||||||
showEpisodeModal,
|
|
||||||
onPlayPause,
|
|
||||||
onSeek,
|
|
||||||
onShowEpisodes,
|
|
||||||
onPlayNextEpisode,
|
|
||||||
}: TVRemoteHandlerProps) => {
|
|
||||||
const [currentFocus, setCurrentFocus] = useState<string | null>(null);
|
|
||||||
const controlsTimer = useRef<NodeJS.Timeout | null>(null);
|
const controlsTimer = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
const fastForwardIntervalRef = useRef<NodeJS.Timeout | null>(null);
|
||||||
|
|
||||||
const actionMap: Record<string, () => void> = {
|
// 重置或启动隐藏控件的定时器
|
||||||
playPause: onPlayPause,
|
const resetTimer = useCallback(() => {
|
||||||
skipBack: () => onSeek(false),
|
// 清除之前的定时器
|
||||||
skipForward: () => onSeek(true),
|
|
||||||
nextEpisode: onPlayNextEpisode,
|
|
||||||
episodes: onShowEpisodes,
|
|
||||||
};
|
|
||||||
|
|
||||||
// Centralized timer logic driven by state changes.
|
|
||||||
useEffect(() => {
|
|
||||||
if (controlsTimer.current) {
|
if (controlsTimer.current) {
|
||||||
clearTimeout(controlsTimer.current);
|
clearTimeout(controlsTimer.current);
|
||||||
}
|
}
|
||||||
|
// 设置新的定时器
|
||||||
|
controlsTimer.current = setTimeout(() => {
|
||||||
|
setShowControls(false);
|
||||||
|
}, CONTROLS_TIMEOUT);
|
||||||
|
}, [setShowControls]);
|
||||||
|
|
||||||
// Only set a timer to hide controls if they are shown AND no element is focused.
|
// 当控件显示时,启动定时器
|
||||||
if (showControls && currentFocus === null) {
|
useEffect(() => {
|
||||||
controlsTimer.current = setTimeout(() => {
|
if (showControls) {
|
||||||
setShowControls(false);
|
resetTimer();
|
||||||
}, 5000);
|
} else {
|
||||||
|
// 如果控件被隐藏,清除定时器
|
||||||
|
if (controlsTimer.current) {
|
||||||
|
clearTimeout(controlsTimer.current);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 组件卸载时清除定时器
|
||||||
return () => {
|
return () => {
|
||||||
if (controlsTimer.current) {
|
if (controlsTimer.current) {
|
||||||
clearTimeout(controlsTimer.current);
|
clearTimeout(controlsTimer.current);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}, [showControls, currentFocus]);
|
}, [showControls, resetTimer]);
|
||||||
|
|
||||||
useTVEventHandler((event) => {
|
// 组件卸载时清除快进定时器
|
||||||
if (showEpisodeModal) {
|
useEffect(() => {
|
||||||
return;
|
return () => {
|
||||||
}
|
if (fastForwardIntervalRef.current) {
|
||||||
|
clearInterval(fastForwardIntervalRef.current);
|
||||||
// If controls are hidden, the first interaction will just show them.
|
|
||||||
if (!showControls) {
|
|
||||||
if (["up", "down", "left", "right", "select"].includes(event.eventType)) {
|
|
||||||
setShowControls(true);
|
|
||||||
}
|
}
|
||||||
return;
|
};
|
||||||
}
|
}, []);
|
||||||
|
|
||||||
// --- Event handling when controls are visible ---
|
// 处理遥控器事件
|
||||||
|
const handleTVEvent = useCallback(
|
||||||
|
(event: HWEvent) => {
|
||||||
|
if (showEpisodeModal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.eventType === "longRight" || event.eventType === "longLeft") {
|
||||||
|
if (event.eventKeyAction === 1) {
|
||||||
|
if (fastForwardIntervalRef.current) {
|
||||||
|
clearInterval(fastForwardIntervalRef.current);
|
||||||
|
fastForwardIntervalRef.current = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
resetTimer();
|
||||||
|
|
||||||
|
if (showControls) {
|
||||||
|
// 如果控制条已显示,则不处理后台的快进/快退等操作
|
||||||
|
// 避免与控制条上的按钮焦点冲突
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (currentFocus === null) {
|
|
||||||
// When no specific element is focused on the control bar
|
|
||||||
switch (event.eventType) {
|
switch (event.eventType) {
|
||||||
case "left":
|
|
||||||
onSeek(false);
|
|
||||||
break;
|
|
||||||
case "right":
|
|
||||||
onSeek(true);
|
|
||||||
break;
|
|
||||||
case "select":
|
case "select":
|
||||||
onPlayPause();
|
togglePlayPause();
|
||||||
|
setShowControls(true);
|
||||||
break;
|
break;
|
||||||
case "down":
|
|
||||||
setCurrentFocus("playPause");
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
// When an element on the control bar is focused
|
|
||||||
switch (event.eventType) {
|
|
||||||
case "left":
|
case "left":
|
||||||
case "right":
|
seek(-SEEK_STEP); // 快退15秒
|
||||||
const nextFocus = focusGraph[currentFocus]?.[event.eventType];
|
break;
|
||||||
if (nextFocus) {
|
case "longLeft":
|
||||||
setCurrentFocus(nextFocus);
|
if (!fastForwardIntervalRef.current && event.eventKeyAction === 0) {
|
||||||
|
fastForwardIntervalRef.current = setInterval(() => {
|
||||||
|
seek(-SEEK_STEP);
|
||||||
|
}, 200);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case "up":
|
case "right":
|
||||||
setCurrentFocus(null);
|
seek(SEEK_STEP);
|
||||||
break;
|
break;
|
||||||
case "select":
|
case "longRight":
|
||||||
actionMap[currentFocus]?.();
|
// 长按开始: 启动连续快进
|
||||||
|
if (!fastForwardIntervalRef.current && event.eventKeyAction === 0) {
|
||||||
|
fastForwardIntervalRef.current = setInterval(() => {
|
||||||
|
seek(SEEK_STEP);
|
||||||
|
}, 200);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "down":
|
||||||
|
setShowControls(true);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
[showControls, showEpisodeModal, setShowControls, resetTimer, togglePlayPause, seek]
|
||||||
|
);
|
||||||
|
|
||||||
return { currentFocus, setCurrentFocus };
|
useTVEventHandler(handleTVEvent);
|
||||||
|
|
||||||
|
// 处理屏幕点击事件
|
||||||
|
const onScreenPress = () => {
|
||||||
|
// 切换控件的显示状态
|
||||||
|
const newShowControls = !showControls;
|
||||||
|
setShowControls(newShowControls);
|
||||||
|
|
||||||
|
// 如果控件变为显示状态,则重置定时器
|
||||||
|
if (newShowControls) {
|
||||||
|
resetTimer();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
return { onScreenPress };
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -3,15 +3,13 @@
|
|||||||
* https://docs.expo.dev/guides/color-schemes/
|
* https://docs.expo.dev/guides/color-schemes/
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import {useColorScheme} from 'react-native';
|
|
||||||
|
|
||||||
import {Colors} from '@/constants/Colors';
|
import {Colors} from '@/constants/Colors';
|
||||||
|
|
||||||
export function useThemeColor(
|
export function useThemeColor(
|
||||||
props: {light?: string; dark?: string},
|
props: {light?: string; dark?: string},
|
||||||
colorName: keyof typeof Colors.light & keyof typeof Colors.dark,
|
colorName: keyof typeof Colors.light & keyof typeof Colors.dark,
|
||||||
) {
|
) {
|
||||||
const theme = useColorScheme() ?? 'light';
|
const theme = 'dark';
|
||||||
const colorFromProps = props[theme];
|
const colorFromProps = props[theme];
|
||||||
|
|
||||||
if (colorFromProps) {
|
if (colorFromProps) {
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
"name": "OrionTV",
|
"name": "OrionTV",
|
||||||
"private": true,
|
"private": true,
|
||||||
"main": "expo-router/entry",
|
"main": "expo-router/entry",
|
||||||
"version": "1.0.6",
|
"version": "1.1.0",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
"start": "EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
||||||
"start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
"start-tv": "EXPO_TV=1 EXPO_USE_METRO_WORKSPACE_ROOT=1 expo start",
|
||||||
@@ -36,6 +36,7 @@
|
|||||||
"expo-font": "~12.0.7",
|
"expo-font": "~12.0.7",
|
||||||
"expo-linking": "~6.3.1",
|
"expo-linking": "~6.3.1",
|
||||||
"expo-router": "~3.5.16",
|
"expo-router": "~3.5.16",
|
||||||
|
"expo-screen-orientation": "6",
|
||||||
"expo-splash-screen": "~0.27.5",
|
"expo-splash-screen": "~0.27.5",
|
||||||
"expo-status-bar": "~1.12.1",
|
"expo-status-bar": "~1.12.1",
|
||||||
"expo-system-ui": "~3.0.6",
|
"expo-system-ui": "~3.0.6",
|
||||||
@@ -44,13 +45,15 @@
|
|||||||
"react": "18.2.0",
|
"react": "18.2.0",
|
||||||
"react-dom": "18.2.0",
|
"react-dom": "18.2.0",
|
||||||
"react-native": "npm:react-native-tvos@~0.74.2-0",
|
"react-native": "npm:react-native-tvos@~0.74.2-0",
|
||||||
"react-native-gesture-handler": "~2.16.1",
|
"react-native-gesture-handler": "^2.27.1",
|
||||||
"react-native-media-console": "*",
|
"react-native-media-console": "*",
|
||||||
"react-native-reanimated": "~3.10.1",
|
"react-native-reanimated": "~3.10.1",
|
||||||
"react-native-safe-area-context": "4.10.1",
|
"react-native-safe-area-context": "4.10.1",
|
||||||
"react-native-screens": "3.31.1",
|
"react-native-screens": "3.31.1",
|
||||||
"react-native-svg": "^15.12.0",
|
"react-native-svg": "^15.12.0",
|
||||||
"react-native-web": "~0.19.10"
|
"react-native-toast-message": "^2.3.3",
|
||||||
|
"react-native-web": "~0.19.10",
|
||||||
|
"zustand": "^5.0.6"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.20.0",
|
"@babel/core": "^7.20.0",
|
||||||
|
|||||||
@@ -10,7 +10,10 @@ const STORAGE_KEYS = {
|
|||||||
} as const;
|
} as const;
|
||||||
|
|
||||||
// --- Type Definitions (aligned with api.ts) ---
|
// --- Type Definitions (aligned with api.ts) ---
|
||||||
export type PlayRecord = ApiPlayRecord;
|
export interface PlayRecord extends ApiPlayRecord {
|
||||||
|
introEndTime?: number;
|
||||||
|
outroStartTime?: number;
|
||||||
|
}
|
||||||
|
|
||||||
export interface FavoriteItem {
|
export interface FavoriteItem {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
147
stores/homeStore.ts
Normal file
147
stores/homeStore.ts
Normal file
@@ -0,0 +1,147 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { api, SearchResult, PlayRecord } from '@/services/api';
|
||||||
|
import { PlayRecordManager } from '@/services/storage';
|
||||||
|
|
||||||
|
export type RowItem = (SearchResult | PlayRecord) & {
|
||||||
|
id: string;
|
||||||
|
source: string;
|
||||||
|
title: string;
|
||||||
|
poster: string;
|
||||||
|
progress?: number;
|
||||||
|
play_time?: number;
|
||||||
|
lastPlayed?: number;
|
||||||
|
episodeIndex?: number;
|
||||||
|
sourceName?: string;
|
||||||
|
totalEpisodes?: number;
|
||||||
|
year?: string;
|
||||||
|
rate?: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface Category {
|
||||||
|
title: string;
|
||||||
|
type?: 'movie' | 'tv' | 'record';
|
||||||
|
tag?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
const initialCategories: Category[] = [
|
||||||
|
{ title: '最近播放', type: 'record' },
|
||||||
|
{ title: '热门剧集', type: 'tv', tag: '热门' },
|
||||||
|
{ title: '综艺', type: 'tv', tag: '综艺' },
|
||||||
|
{ title: '热门电影', type: 'movie', tag: '热门' },
|
||||||
|
{ title: '豆瓣 Top250', type: 'movie', tag: 'top250' },
|
||||||
|
{ title: '儿童', type: 'movie', tag: '少儿' },
|
||||||
|
{ title: '美剧', type: 'tv', tag: '美剧' },
|
||||||
|
{ title: '韩剧', type: 'tv', tag: '韩剧' },
|
||||||
|
{ title: '日剧', type: 'tv', tag: '日剧' },
|
||||||
|
{ title: '日漫', type: 'tv', tag: '日本动画' },
|
||||||
|
];
|
||||||
|
|
||||||
|
interface HomeState {
|
||||||
|
categories: Category[];
|
||||||
|
selectedCategory: Category;
|
||||||
|
contentData: RowItem[];
|
||||||
|
loading: boolean;
|
||||||
|
loadingMore: boolean;
|
||||||
|
pageStart: number;
|
||||||
|
hasMore: boolean;
|
||||||
|
error: string | null;
|
||||||
|
fetchInitialData: () => Promise<void>;
|
||||||
|
loadMoreData: () => Promise<void>;
|
||||||
|
selectCategory: (category: Category) => void;
|
||||||
|
refreshPlayRecords: () => Promise<void>;
|
||||||
|
}
|
||||||
|
|
||||||
|
const useHomeStore = create<HomeState>((set, get) => ({
|
||||||
|
categories: initialCategories,
|
||||||
|
selectedCategory: initialCategories[0],
|
||||||
|
contentData: [],
|
||||||
|
loading: true,
|
||||||
|
loadingMore: false,
|
||||||
|
pageStart: 0,
|
||||||
|
hasMore: true,
|
||||||
|
error: null,
|
||||||
|
|
||||||
|
fetchInitialData: async () => {
|
||||||
|
set({ loading: true, contentData: [], pageStart: 0, hasMore: true, error: null });
|
||||||
|
await get().loadMoreData();
|
||||||
|
},
|
||||||
|
|
||||||
|
loadMoreData: async () => {
|
||||||
|
const { selectedCategory, pageStart, loadingMore, hasMore } = get();
|
||||||
|
if (loadingMore || !hasMore) return;
|
||||||
|
|
||||||
|
if (pageStart > 0) {
|
||||||
|
set({ loadingMore: true });
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (selectedCategory.type === 'record') {
|
||||||
|
const records = await PlayRecordManager.getAll();
|
||||||
|
const rowItems = Object.entries(records)
|
||||||
|
.map(([key, record]) => {
|
||||||
|
const [source, id] = key.split('+');
|
||||||
|
return { ...record, id, source, progress: record.play_time / record.total_time, poster: record.cover, sourceName: record.source_name, episodeIndex: record.index, totalEpisodes: record.total_episodes, lastPlayed: record.save_time, play_time: record.play_time };
|
||||||
|
})
|
||||||
|
.filter(record => record.progress !== undefined && record.progress > 0 && record.progress < 1)
|
||||||
|
.sort((a, b) => (b.lastPlayed || 0) - (a.lastPlayed || 0));
|
||||||
|
|
||||||
|
set({ contentData: rowItems, hasMore: false });
|
||||||
|
} else if (selectedCategory.type && selectedCategory.tag) {
|
||||||
|
const result = await api.getDoubanData(selectedCategory.type, selectedCategory.tag, 20, pageStart);
|
||||||
|
if (result.list.length === 0) {
|
||||||
|
set({ hasMore: false });
|
||||||
|
} else {
|
||||||
|
const newItems = result.list.map(item => ({
|
||||||
|
...item,
|
||||||
|
id: item.title,
|
||||||
|
source: 'douban',
|
||||||
|
})) as RowItem[];
|
||||||
|
set(state => ({
|
||||||
|
contentData: pageStart === 0 ? newItems : [...state.contentData, ...newItems],
|
||||||
|
pageStart: state.pageStart + result.list.length,
|
||||||
|
hasMore: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
set({ hasMore: false });
|
||||||
|
}
|
||||||
|
} catch (err: any) {
|
||||||
|
if (err.message === 'API_URL_NOT_SET') {
|
||||||
|
set({ error: '请点击右上角设置按钮,配置您的 API 地址' });
|
||||||
|
} else {
|
||||||
|
set({ error: '加载失败,请重试' });
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
set({ loading: false, loadingMore: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
selectCategory: (category: Category) => {
|
||||||
|
set({ selectedCategory: category });
|
||||||
|
get().fetchInitialData();
|
||||||
|
},
|
||||||
|
|
||||||
|
refreshPlayRecords: async () => {
|
||||||
|
const records = await PlayRecordManager.getAll();
|
||||||
|
const hasRecords = Object.keys(records).length > 0;
|
||||||
|
set(state => {
|
||||||
|
const recordCategoryExists = state.categories.some(c => c.type === 'record');
|
||||||
|
if (hasRecords && !recordCategoryExists) {
|
||||||
|
return { categories: [initialCategories[0], ...state.categories] };
|
||||||
|
}
|
||||||
|
if (!hasRecords && recordCategoryExists) {
|
||||||
|
const newCategories = state.categories.filter(c => c.type !== 'record');
|
||||||
|
if (state.selectedCategory.type === 'record') {
|
||||||
|
get().selectCategory(newCategories[0] || null);
|
||||||
|
}
|
||||||
|
return { categories: newCategories };
|
||||||
|
}
|
||||||
|
return {};
|
||||||
|
});
|
||||||
|
if (get().selectedCategory.type === 'record') {
|
||||||
|
get().fetchInitialData();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default useHomeStore;
|
||||||
327
stores/playerStore.ts
Normal file
327
stores/playerStore.ts
Normal file
@@ -0,0 +1,327 @@
|
|||||||
|
import { create } from "zustand";
|
||||||
|
import Toast from "react-native-toast-message";
|
||||||
|
import { AVPlaybackStatus, Video } from "expo-av";
|
||||||
|
import { RefObject } from "react";
|
||||||
|
import { api, VideoDetail as ApiVideoDetail, SearchResult } from "@/services/api";
|
||||||
|
import { PlayRecord, PlayRecordManager } from "@/services/storage";
|
||||||
|
|
||||||
|
interface Episode {
|
||||||
|
url: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
interface VideoDetail {
|
||||||
|
videoInfo: ApiVideoDetail["videoInfo"];
|
||||||
|
episodes: Episode[];
|
||||||
|
sources: SearchResult[];
|
||||||
|
}
|
||||||
|
|
||||||
|
interface PlayerState {
|
||||||
|
videoRef: RefObject<Video> | null;
|
||||||
|
detail: VideoDetail | null;
|
||||||
|
episodes: Episode[];
|
||||||
|
sources: SearchResult[];
|
||||||
|
currentSourceIndex: number;
|
||||||
|
currentEpisodeIndex: number;
|
||||||
|
status: AVPlaybackStatus | null;
|
||||||
|
isLoading: boolean;
|
||||||
|
showControls: boolean;
|
||||||
|
showEpisodeModal: boolean;
|
||||||
|
showSourceModal: boolean;
|
||||||
|
showNextEpisodeOverlay: boolean;
|
||||||
|
isSeeking: boolean;
|
||||||
|
seekPosition: number;
|
||||||
|
progressPosition: number;
|
||||||
|
initialPosition: number;
|
||||||
|
introEndTime?: number;
|
||||||
|
outroStartTime?: number;
|
||||||
|
setVideoRef: (ref: RefObject<Video>) => void;
|
||||||
|
loadVideo: (source: string, id: string, episodeIndex: number, position?: number) => Promise<void>;
|
||||||
|
switchSource: (newSourceIndex: number) => Promise<void>;
|
||||||
|
playEpisode: (index: number) => void;
|
||||||
|
togglePlayPause: () => void;
|
||||||
|
seek: (duration: number) => void;
|
||||||
|
handlePlaybackStatusUpdate: (newStatus: AVPlaybackStatus) => void;
|
||||||
|
setLoading: (loading: boolean) => void;
|
||||||
|
setShowControls: (show: boolean) => void;
|
||||||
|
setShowEpisodeModal: (show: boolean) => void;
|
||||||
|
setShowSourceModal: (show: boolean) => void;
|
||||||
|
setShowNextEpisodeOverlay: (show: boolean) => void;
|
||||||
|
setIntroEndTime: () => void;
|
||||||
|
setOutroStartTime: () => void;
|
||||||
|
reset: () => void;
|
||||||
|
_seekTimeout?: NodeJS.Timeout;
|
||||||
|
// Internal helper
|
||||||
|
_savePlayRecord: (updates?: Partial<PlayRecord>) => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
const usePlayerStore = create<PlayerState>((set, get) => ({
|
||||||
|
videoRef: null,
|
||||||
|
detail: null,
|
||||||
|
episodes: [],
|
||||||
|
sources: [],
|
||||||
|
currentSourceIndex: 0,
|
||||||
|
currentEpisodeIndex: 0,
|
||||||
|
status: null,
|
||||||
|
isLoading: true,
|
||||||
|
showControls: false,
|
||||||
|
showEpisodeModal: false,
|
||||||
|
showSourceModal: false,
|
||||||
|
showNextEpisodeOverlay: false,
|
||||||
|
isSeeking: false,
|
||||||
|
seekPosition: 0,
|
||||||
|
progressPosition: 0,
|
||||||
|
initialPosition: 0,
|
||||||
|
introEndTime: undefined,
|
||||||
|
outroStartTime: undefined,
|
||||||
|
_seekTimeout: undefined,
|
||||||
|
|
||||||
|
setVideoRef: (ref) => set({ videoRef: ref }),
|
||||||
|
|
||||||
|
loadVideo: async (source, id, episodeIndex, position) => {
|
||||||
|
set({
|
||||||
|
isLoading: true,
|
||||||
|
detail: null,
|
||||||
|
episodes: [],
|
||||||
|
sources: [],
|
||||||
|
currentEpisodeIndex: 0,
|
||||||
|
initialPosition: position || 0,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
const videoDetail = await api.getVideoDetail(source, id);
|
||||||
|
const episodes = videoDetail.episodes.map((ep, index) => ({ url: ep, title: `第 ${index + 1} 集` }));
|
||||||
|
|
||||||
|
const searchResults = await api.searchVideos(videoDetail.videoInfo.title);
|
||||||
|
const sources = searchResults.results.filter((r) => r.title === videoDetail.videoInfo.title);
|
||||||
|
const currentSourceIndex = sources.findIndex((s) => s.source === source && s.id.toString() === id);
|
||||||
|
const playRecord = await PlayRecordManager.get(source, id);
|
||||||
|
|
||||||
|
set({
|
||||||
|
detail: { videoInfo: videoDetail.videoInfo, episodes, sources },
|
||||||
|
episodes,
|
||||||
|
sources,
|
||||||
|
currentSourceIndex: currentSourceIndex !== -1 ? currentSourceIndex : 0,
|
||||||
|
currentEpisodeIndex: episodeIndex,
|
||||||
|
isLoading: false,
|
||||||
|
introEndTime: playRecord?.introEndTime,
|
||||||
|
outroStartTime: playRecord?.outroStartTime,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to load video details", error);
|
||||||
|
set({ isLoading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
switchSource: async (newSourceIndex: number) => {
|
||||||
|
const { sources, currentEpisodeIndex, status, detail } = get();
|
||||||
|
if (!detail || newSourceIndex < 0 || newSourceIndex >= sources.length) return;
|
||||||
|
|
||||||
|
const newSource = sources[newSourceIndex];
|
||||||
|
const position = status?.isLoaded ? status.positionMillis : 0;
|
||||||
|
|
||||||
|
set({ isLoading: true, showSourceModal: false });
|
||||||
|
|
||||||
|
try {
|
||||||
|
const videoDetail = await api.getVideoDetail(newSource.source, newSource.id.toString());
|
||||||
|
const episodes = videoDetail.episodes.map((ep, index) => ({ url: ep, title: `第 ${index + 1} 集` }));
|
||||||
|
|
||||||
|
set({
|
||||||
|
detail: {
|
||||||
|
...detail,
|
||||||
|
videoInfo: videoDetail.videoInfo,
|
||||||
|
episodes,
|
||||||
|
},
|
||||||
|
episodes,
|
||||||
|
currentSourceIndex: newSourceIndex,
|
||||||
|
currentEpisodeIndex: currentEpisodeIndex < episodes.length ? currentEpisodeIndex : 0,
|
||||||
|
initialPosition: position,
|
||||||
|
isLoading: false,
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to switch source", error);
|
||||||
|
set({ isLoading: false });
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
playEpisode: (index) => {
|
||||||
|
const { episodes, videoRef } = get();
|
||||||
|
if (index >= 0 && index < episodes.length) {
|
||||||
|
set({
|
||||||
|
currentEpisodeIndex: index,
|
||||||
|
showNextEpisodeOverlay: false,
|
||||||
|
initialPosition: 0,
|
||||||
|
progressPosition: 0,
|
||||||
|
seekPosition: 0,
|
||||||
|
});
|
||||||
|
videoRef?.current?.replayAsync();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
togglePlayPause: () => {
|
||||||
|
const { status, videoRef } = get();
|
||||||
|
if (status?.isLoaded) {
|
||||||
|
if (status.isPlaying) {
|
||||||
|
videoRef?.current?.pauseAsync();
|
||||||
|
} else {
|
||||||
|
videoRef?.current?.playAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
seek: (duration) => {
|
||||||
|
const { status, videoRef } = get();
|
||||||
|
if (!status?.isLoaded || !status.durationMillis) return;
|
||||||
|
|
||||||
|
const newPosition = Math.max(0, Math.min(status.positionMillis + duration, status.durationMillis));
|
||||||
|
videoRef?.current?.setPositionAsync(newPosition);
|
||||||
|
|
||||||
|
set({
|
||||||
|
isSeeking: true,
|
||||||
|
seekPosition: newPosition / status.durationMillis,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (get()._seekTimeout) {
|
||||||
|
clearTimeout(get()._seekTimeout);
|
||||||
|
}
|
||||||
|
const timeoutId = setTimeout(() => set({ isSeeking: false }), 1000);
|
||||||
|
set({ _seekTimeout: timeoutId });
|
||||||
|
},
|
||||||
|
|
||||||
|
setIntroEndTime: () => {
|
||||||
|
const { status, detail, introEndTime: existingIntroEndTime } = get();
|
||||||
|
if (!status?.isLoaded || !detail) return;
|
||||||
|
|
||||||
|
if (existingIntroEndTime) {
|
||||||
|
// Clear the time
|
||||||
|
set({ introEndTime: undefined });
|
||||||
|
get()._savePlayRecord({ introEndTime: undefined });
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "已清除片头时间",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Set the time
|
||||||
|
const newIntroEndTime = status.positionMillis;
|
||||||
|
set({ introEndTime: newIntroEndTime });
|
||||||
|
get()._savePlayRecord({ introEndTime: newIntroEndTime });
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "设置成功",
|
||||||
|
text2: "片头时间已记录。",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
setOutroStartTime: () => {
|
||||||
|
const { status, detail, outroStartTime: existingOutroStartTime } = get();
|
||||||
|
if (!status?.isLoaded || !detail) return;
|
||||||
|
|
||||||
|
if (existingOutroStartTime) {
|
||||||
|
// Clear the time
|
||||||
|
set({ outroStartTime: undefined });
|
||||||
|
get()._savePlayRecord({ outroStartTime: undefined });
|
||||||
|
Toast.show({
|
||||||
|
type: "info",
|
||||||
|
text1: "已清除片尾时间",
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
// Set the time
|
||||||
|
const newOutroStartTime = status.positionMillis;
|
||||||
|
set({ outroStartTime: newOutroStartTime });
|
||||||
|
get()._savePlayRecord({ outroStartTime: newOutroStartTime });
|
||||||
|
Toast.show({
|
||||||
|
type: "success",
|
||||||
|
text1: "设置成功",
|
||||||
|
text2: "片尾时间已记录。",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_savePlayRecord: (updates = {}) => {
|
||||||
|
const { detail, currentEpisodeIndex, episodes, status, introEndTime, outroStartTime } = get();
|
||||||
|
if (detail && status?.isLoaded) {
|
||||||
|
const { videoInfo } = detail;
|
||||||
|
const existingRecord = {
|
||||||
|
introEndTime,
|
||||||
|
outroStartTime,
|
||||||
|
};
|
||||||
|
PlayRecordManager.save(videoInfo.source, videoInfo.id, {
|
||||||
|
title: videoInfo.title,
|
||||||
|
cover: videoInfo.cover || "",
|
||||||
|
index: currentEpisodeIndex,
|
||||||
|
total_episodes: episodes.length,
|
||||||
|
play_time: status.positionMillis,
|
||||||
|
total_time: status.durationMillis || 0,
|
||||||
|
source_name: videoInfo.source_name,
|
||||||
|
...existingRecord,
|
||||||
|
...updates,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
handlePlaybackStatusUpdate: (newStatus) => {
|
||||||
|
if (!newStatus.isLoaded) {
|
||||||
|
if (newStatus.error) {
|
||||||
|
console.error(`Playback Error: ${newStatus.error}`);
|
||||||
|
}
|
||||||
|
set({ status: newStatus });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { detail, currentEpisodeIndex, episodes, outroStartTime, playEpisode } = get();
|
||||||
|
|
||||||
|
if (outroStartTime && newStatus.positionMillis >= outroStartTime) {
|
||||||
|
if (currentEpisodeIndex < episodes.length - 1) {
|
||||||
|
playEpisode(currentEpisodeIndex + 1);
|
||||||
|
return; // Stop further processing for this update
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (detail && newStatus.durationMillis) {
|
||||||
|
get()._savePlayRecord();
|
||||||
|
|
||||||
|
const isNearEnd = newStatus.positionMillis / newStatus.durationMillis > 0.95;
|
||||||
|
if (isNearEnd && currentEpisodeIndex < episodes.length - 1 && !outroStartTime) {
|
||||||
|
set({ showNextEpisodeOverlay: true });
|
||||||
|
} else {
|
||||||
|
set({ showNextEpisodeOverlay: false });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newStatus.didJustFinish) {
|
||||||
|
if (currentEpisodeIndex < episodes.length - 1) {
|
||||||
|
playEpisode(currentEpisodeIndex + 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const progressPosition = newStatus.durationMillis ? newStatus.positionMillis / newStatus.durationMillis : 0;
|
||||||
|
set({ status: newStatus, progressPosition });
|
||||||
|
},
|
||||||
|
|
||||||
|
setLoading: (loading) => set({ isLoading: loading }),
|
||||||
|
setShowControls: (show) => set({ showControls: show }),
|
||||||
|
setShowEpisodeModal: (show) => set({ showEpisodeModal: show }),
|
||||||
|
setShowSourceModal: (show) => set({ showSourceModal: show }),
|
||||||
|
setShowNextEpisodeOverlay: (show) => set({ showNextEpisodeOverlay: show }),
|
||||||
|
|
||||||
|
reset: () => {
|
||||||
|
set({
|
||||||
|
detail: null,
|
||||||
|
episodes: [],
|
||||||
|
sources: [],
|
||||||
|
currentSourceIndex: 0,
|
||||||
|
currentEpisodeIndex: 0,
|
||||||
|
status: null,
|
||||||
|
isLoading: true,
|
||||||
|
showControls: false,
|
||||||
|
showEpisodeModal: false,
|
||||||
|
showSourceModal: false,
|
||||||
|
showNextEpisodeOverlay: false,
|
||||||
|
initialPosition: 0,
|
||||||
|
introEndTime: undefined,
|
||||||
|
outroStartTime: undefined,
|
||||||
|
});
|
||||||
|
},
|
||||||
|
}));
|
||||||
|
|
||||||
|
export default usePlayerStore;
|
||||||
34
stores/settingsStore.ts
Normal file
34
stores/settingsStore.ts
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
import { create } from 'zustand';
|
||||||
|
import { SettingsManager } from '@/services/storage';
|
||||||
|
import { api } from '@/services/api';
|
||||||
|
import useHomeStore from './homeStore';
|
||||||
|
|
||||||
|
interface SettingsState {
|
||||||
|
apiBaseUrl: string;
|
||||||
|
isModalVisible: boolean;
|
||||||
|
loadSettings: () => Promise<void>;
|
||||||
|
setApiBaseUrl: (url: string) => void;
|
||||||
|
saveSettings: () => Promise<void>;
|
||||||
|
showModal: () => void;
|
||||||
|
hideModal: () => void;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSettingsStore = create<SettingsState>((set, get) => ({
|
||||||
|
apiBaseUrl: 'https://orion-tv.edu.deal',
|
||||||
|
isModalVisible: false,
|
||||||
|
loadSettings: async () => {
|
||||||
|
const settings = await SettingsManager.get();
|
||||||
|
set({ apiBaseUrl: settings.apiBaseUrl });
|
||||||
|
api.setBaseUrl(settings.apiBaseUrl);
|
||||||
|
},
|
||||||
|
setApiBaseUrl: (url) => set({ apiBaseUrl: url }),
|
||||||
|
saveSettings: async () => {
|
||||||
|
const { apiBaseUrl } = get();
|
||||||
|
await SettingsManager.save({ apiBaseUrl });
|
||||||
|
api.setBaseUrl(apiBaseUrl);
|
||||||
|
set({ isModalVisible: false });
|
||||||
|
useHomeStore.getState().fetchInitialData();
|
||||||
|
},
|
||||||
|
showModal: () => set({ isModalVisible: true }),
|
||||||
|
hideModal: () => set({ isModalVisible: false }),
|
||||||
|
}));
|
||||||
40
yarn.lock
40
yarn.lock
@@ -4004,6 +4004,11 @@ expo-router@~3.5.16:
|
|||||||
react-native-helmet-async "2.0.4"
|
react-native-helmet-async "2.0.4"
|
||||||
schema-utils "^4.0.1"
|
schema-utils "^4.0.1"
|
||||||
|
|
||||||
|
expo-screen-orientation@6:
|
||||||
|
version "6.4.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/expo-screen-orientation/-/expo-screen-orientation-6.4.1.tgz#1c4428a058921e48b5caa45367e626b8bec10e24"
|
||||||
|
integrity sha512-VM0C9ORNL1aT6Dr2OUeryzV519n0FjtXI2m+HlijOMi1QT2bPg4tBkCd7HLgywU4dZ1Esa46ewUudmk+fOqmMQ==
|
||||||
|
|
||||||
expo-splash-screen@0.27.7, expo-splash-screen@~0.27.5:
|
expo-splash-screen@0.27.7, expo-splash-screen@~0.27.5:
|
||||||
version "0.27.7"
|
version "0.27.7"
|
||||||
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.27.7.tgz#52171be54d8c008880d928e802819d767fbd3c12"
|
resolved "https://registry.yarnpkg.com/expo-splash-screen/-/expo-splash-screen-0.27.7.tgz#52171be54d8c008880d928e802819d767fbd3c12"
|
||||||
@@ -5850,7 +5855,7 @@ lodash.throttle@^4.1.1:
|
|||||||
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
|
resolved "https://registry.yarnpkg.com/lodash.throttle/-/lodash.throttle-4.1.1.tgz#c23e91b710242ac70c37f1e1cda9274cc39bf2f4"
|
||||||
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==
|
integrity sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==
|
||||||
|
|
||||||
lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.19, lodash@^4.17.21:
|
lodash@^4.17.10, lodash@^4.17.13, lodash@^4.17.19:
|
||||||
version "4.17.21"
|
version "4.17.21"
|
||||||
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c"
|
||||||
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg==
|
||||||
@@ -5879,7 +5884,7 @@ logkitty@^0.7.1:
|
|||||||
dayjs "^1.8.15"
|
dayjs "^1.8.15"
|
||||||
yargs "^15.1.0"
|
yargs "^15.1.0"
|
||||||
|
|
||||||
loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.4.0:
|
loose-envify@^1.0.0, loose-envify@^1.1.0:
|
||||||
version "1.4.0"
|
version "1.4.0"
|
||||||
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"
|
||||||
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
|
integrity sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==
|
||||||
@@ -6920,15 +6925,6 @@ prompts@^2.0.1, prompts@^2.2.1, prompts@^2.3.2, prompts@^2.4.2:
|
|||||||
kleur "^3.0.3"
|
kleur "^3.0.3"
|
||||||
sisteransi "^1.0.5"
|
sisteransi "^1.0.5"
|
||||||
|
|
||||||
prop-types@^15.7.2:
|
|
||||||
version "15.8.1"
|
|
||||||
resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.8.1.tgz#67d87bf1a694f48435cf332c24af10214a3140b5"
|
|
||||||
integrity sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==
|
|
||||||
dependencies:
|
|
||||||
loose-envify "^1.4.0"
|
|
||||||
object-assign "^4.1.1"
|
|
||||||
react-is "^16.13.1"
|
|
||||||
|
|
||||||
psl@^1.1.33:
|
psl@^1.1.33:
|
||||||
version "1.15.0"
|
version "1.15.0"
|
||||||
resolved "https://registry.yarnpkg.com/psl/-/psl-1.15.0.tgz#bdace31896f1d97cec6a79e8224898ce93d974c6"
|
resolved "https://registry.yarnpkg.com/psl/-/psl-1.15.0.tgz#bdace31896f1d97cec6a79e8224898ce93d974c6"
|
||||||
@@ -7037,7 +7033,7 @@ react-freeze@^1.0.0:
|
|||||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e"
|
||||||
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
|
integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg==
|
||||||
|
|
||||||
react-is@^16.13.0, react-is@^16.13.1, react-is@^16.7.0, react-is@^16.8.4:
|
react-is@^16.13.0, react-is@^16.7.0, react-is@^16.8.4:
|
||||||
version "16.13.1"
|
version "16.13.1"
|
||||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4"
|
||||||
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
|
integrity sha512-24e6ynE2H+OKt4kqsOvNd8kBpV65zoxbA4BVsEOB3ARVWQki/DHzaUoC5KuON/BiccDaCCTZBuOcfZs70kR8bQ==
|
||||||
@@ -7047,16 +7043,14 @@ react-is@^17.0.1:
|
|||||||
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0"
|
||||||
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w==
|
||||||
|
|
||||||
react-native-gesture-handler@~2.16.1:
|
react-native-gesture-handler@^2.27.1:
|
||||||
version "2.16.2"
|
version "2.27.1"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.16.2.tgz#032bd2a07334292d7f6cff1dc9d1ec928f72e26d"
|
resolved "https://registry.yarnpkg.com/react-native-gesture-handler/-/react-native-gesture-handler-2.27.1.tgz#8865b2345f4c65536517f20cedc420481fc72d49"
|
||||||
integrity sha512-vGFlrDKlmyI+BT+FemqVxmvO7nqxU33cgXVsn6IKAFishvlG3oV2Ds67D5nPkHMea8T+s1IcuMm0bF8ntZtAyg==
|
integrity sha512-57TUWerhdz589OcDD21e/YlL923Ma4OIpyWsP0hy7gItBCPm5d7qIUW7Yo/cS2wo1qDdOhJaNlvlBD1lDou1fA==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@egjs/hammerjs" "^2.0.17"
|
"@egjs/hammerjs" "^2.0.17"
|
||||||
hoist-non-react-statics "^3.3.0"
|
hoist-non-react-statics "^3.3.0"
|
||||||
invariant "^2.2.4"
|
invariant "^2.2.4"
|
||||||
lodash "^4.17.21"
|
|
||||||
prop-types "^15.7.2"
|
|
||||||
|
|
||||||
react-native-helmet-async@2.0.4:
|
react-native-helmet-async@2.0.4:
|
||||||
version "2.0.4"
|
version "2.0.4"
|
||||||
@@ -7108,6 +7102,11 @@ react-native-svg@^15.12.0:
|
|||||||
css-tree "^1.1.3"
|
css-tree "^1.1.3"
|
||||||
warn-once "0.1.1"
|
warn-once "0.1.1"
|
||||||
|
|
||||||
|
react-native-toast-message@^2.3.3:
|
||||||
|
version "2.3.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/react-native-toast-message/-/react-native-toast-message-2.3.3.tgz#e301508d386a9902ff6b4559ecc6674f8cfdf97a"
|
||||||
|
integrity sha512-4IIUHwUPvKHu4gjD0Vj2aGQzqPATiblL1ey8tOqsxOWRPGGu52iIbL8M/mCz4uyqecvPdIcMY38AfwRuUADfQQ==
|
||||||
|
|
||||||
react-native-web@~0.19.10:
|
react-native-web@~0.19.10:
|
||||||
version "0.19.13"
|
version "0.19.13"
|
||||||
resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.19.13.tgz#2d84849bf0251ec0e3a8072fda7f9a7c29375331"
|
resolved "https://registry.yarnpkg.com/react-native-web/-/react-native-web-0.19.13.tgz#2d84849bf0251ec0e3a8072fda7f9a7c29375331"
|
||||||
@@ -8953,3 +8952,8 @@ zod@^3.22.4:
|
|||||||
version "3.25.67"
|
version "3.25.67"
|
||||||
resolved "https://registry.yarnpkg.com/zod/-/zod-3.25.67.tgz#62987e4078e2ab0f63b491ef0c4f33df24236da8"
|
resolved "https://registry.yarnpkg.com/zod/-/zod-3.25.67.tgz#62987e4078e2ab0f63b491ef0c4f33df24236da8"
|
||||||
integrity sha512-idA2YXwpCdqUSKRCACDE6ItZD9TZzy3OZMtpfLoh6oPR47lipysRrJfjzMqFxQ3uJuUPyUeWe1r9vLH33xO/Qw==
|
integrity sha512-idA2YXwpCdqUSKRCACDE6ItZD9TZzy3OZMtpfLoh6oPR47lipysRrJfjzMqFxQ3uJuUPyUeWe1r9vLH33xO/Qw==
|
||||||
|
|
||||||
|
zustand@^5.0.6:
|
||||||
|
version "5.0.6"
|
||||||
|
resolved "https://registry.yarnpkg.com/zustand/-/zustand-5.0.6.tgz#a2da43d8dc3d31e314279e5baec06297bea70a5c"
|
||||||
|
integrity sha512-ihAqNeUVhe0MAD+X8M5UzqyZ9k3FFZLBTtqo6JLPwV53cbRB/mJwBI0PxcIgqhBBHlEs8G45OTDTMq3gNcLq3A==
|
||||||
|
|||||||
Reference in New Issue
Block a user