7 Commits

Author SHA1 Message Date
zimplexing
d1f0a2eb87 feat: Optimize availability checking of api addresses 2025-07-25 16:32:15 +08:00
zimplexing
62c03beb5e fix: search input focus issue 2025-07-25 16:00:11 +08:00
zimplexing
5992a89db4 feat: Update scroll experience 2025-07-25 15:39:23 +08:00
zimplexing
c9587d7070 chore: bump version to 1.2.8 in package.json 2025-07-25 14:15:18 +08:00
zimplexing
75d7f675f7 fix: reload video with new source while preserving playback position 2025-07-25 13:58:26 +08:00
zimplexing
9cbd23c36a refactor: improve focus management and input handling in LoginModal 2025-07-25 13:34:11 +08:00
zimplexing
3fa2eb3159 feat: add useKeepAwake to LivePlayer and update version to 1.2.7 2025-07-21 19:03:12 +08:00
13 changed files with 387 additions and 267 deletions

View File

@@ -1,11 +1,12 @@
import React, { useEffect } from "react"; import React, { useEffect } from "react";
import { View, FlatList, StyleSheet, ActivityIndicator } from "react-native"; import { View, StyleSheet, ActivityIndicator } from "react-native";
import { ThemedView } from "@/components/ThemedView"; import { ThemedView } from "@/components/ThemedView";
import { ThemedText } from "@/components/ThemedText"; import { ThemedText } from "@/components/ThemedText";
import useFavoritesStore from "@/stores/favoritesStore"; import useFavoritesStore from "@/stores/favoritesStore";
import { Favorite } from "@/services/storage"; import { Favorite } from "@/services/storage";
import VideoCard from "@/components/VideoCard.tv"; import VideoCard from "@/components/VideoCard.tv";
import { api } from "@/services/api"; import { api } from "@/services/api";
import CustomScrollView from "@/components/CustomScrollView";
export default function FavoritesScreen() { export default function FavoritesScreen() {
const { favorites, loading, error, fetchFavorites } = useFavoritesStore(); const { favorites, loading, error, fetchFavorites } = useFavoritesStore();
@@ -14,31 +15,7 @@ export default function FavoritesScreen() {
fetchFavorites(); fetchFavorites();
}, [fetchFavorites]); }, [fetchFavorites]);
if (loading) { const renderItem = ({ item }: { item: Favorite & { key: string }; index: number }) => {
return (
<ThemedView style={styles.centered}>
<ActivityIndicator size="large" />
</ThemedView>
);
}
if (error) {
return (
<ThemedView style={styles.centered}>
<ThemedText type="subtitle">{error}</ThemedText>
</ThemedView>
);
}
if (favorites.length === 0) {
return (
<ThemedView style={styles.centered}>
<ThemedText type="subtitle"></ThemedText>
</ThemedView>
);
}
const renderItem = ({ item }: { item: Favorite & { key: string } }) => {
const [source, id] = item.key.split("+"); const [source, id] = item.key.split("+");
return ( return (
<VideoCard <VideoCard
@@ -60,12 +37,13 @@ export default function FavoritesScreen() {
<View style={styles.headerContainer}> <View style={styles.headerContainer}>
<ThemedText style={styles.headerTitle}></ThemedText> <ThemedText style={styles.headerTitle}></ThemedText>
</View> </View>
<FlatList <CustomScrollView
data={favorites} data={favorites}
renderItem={renderItem} renderItem={renderItem}
keyExtractor={(item) => item.key}
numColumns={5} numColumns={5}
contentContainerStyle={styles.list} loading={loading}
error={error}
emptyMessage="暂无收藏"
/> />
</ThemedView> </ThemedView>
); );

View File

@@ -9,15 +9,17 @@ import { Search, Settings, LogOut, Heart } from "lucide-react-native";
import { StyledButton } from "@/components/StyledButton"; import { StyledButton } from "@/components/StyledButton";
import useHomeStore, { RowItem, Category } from "@/stores/homeStore"; import useHomeStore, { RowItem, Category } from "@/stores/homeStore";
import useAuthStore from "@/stores/authStore"; import useAuthStore from "@/stores/authStore";
import CustomScrollView from "@/components/CustomScrollView";
const NUM_COLUMNS = 5; const NUM_COLUMNS = 5;
const { width } = Dimensions.get("window"); const { width } = Dimensions.get("window");
const ITEM_WIDTH = width / NUM_COLUMNS - 24;
// Threshold for triggering load more data (in pixels)
const LOAD_MORE_THRESHOLD = 200;
export default function HomeScreen() { export default function HomeScreen() {
const router = useRouter(); const router = useRouter();
const colorScheme = "dark"; const colorScheme = "dark";
const flatListRef = useRef<FlatList>(null);
const [selectedTag, setSelectedTag] = useState<string | null>(null); const [selectedTag, setSelectedTag] = useState<string | null>(null);
const { const {
@@ -43,7 +45,6 @@ export default function HomeScreen() {
useEffect(() => { useEffect(() => {
if (selectedCategory && !selectedCategory.tags) { if (selectedCategory && !selectedCategory.tags) {
fetchInitialData(); fetchInitialData();
flatListRef.current?.scrollToOffset({ animated: false, offset: 0 });
} else if (selectedCategory?.tags && !selectedCategory.tag) { } else if (selectedCategory?.tags && !selectedCategory.tag) {
// Category with tags selected, but no specific tag yet. Select the first one. // Category with tags selected, but no specific tag yet. Select the first one.
const defaultTag = selectedCategory.tags[0]; const defaultTag = selectedCategory.tags[0];
@@ -55,7 +56,6 @@ export default function HomeScreen() {
useEffect(() => { useEffect(() => {
if (selectedCategory && selectedCategory.tag) { if (selectedCategory && selectedCategory.tag) {
fetchInitialData(); fetchInitialData();
flatListRef.current?.scrollToOffset({ animated: false, offset: 0 });
} }
}, [fetchInitialData, selectedCategory, selectedCategory.tag]); }, [fetchInitialData, selectedCategory, selectedCategory.tag]);
@@ -86,7 +86,7 @@ export default function HomeScreen() {
); );
}; };
const renderContentItem = ({ item }: { item: RowItem }) => ( const renderContentItem = ({ item, index }: { item: RowItem; index: number }) => (
<View style={styles.itemContainer}> <View style={styles.itemContainer}>
<VideoCard <VideoCard
id={item.id} id={item.id}
@@ -196,21 +196,17 @@ export default function HomeScreen() {
</ThemedText> </ThemedText>
</View> </View>
) : ( ) : (
<FlatList <CustomScrollView
ref={flatListRef}
data={contentData} data={contentData}
renderItem={renderContentItem} renderItem={renderContentItem}
keyExtractor={(item, index) => `${item.source}-${item.id}-${index}`}
numColumns={NUM_COLUMNS} numColumns={NUM_COLUMNS}
contentContainerStyle={styles.listContent} loading={loading}
loadingMore={loadingMore}
error={error}
onEndReached={loadMoreData} onEndReached={loadMoreData}
onEndReachedThreshold={0.5} loadMoreThreshold={LOAD_MORE_THRESHOLD}
emptyMessage={selectedCategory?.tags ? "请选择一个子分类" : "该分类下暂无内容"}
ListFooterComponent={renderFooter} ListFooterComponent={renderFooter}
ListEmptyComponent={
<View style={styles.centerContainer}>
<ThemedText>{selectedCategory?.tags ? "请选择一个子分类" : "该分类下暂无内容"}</ThemedText>
</View>
}
/> />
)} )}
</ThemedView> </ThemedView>
@@ -272,7 +268,6 @@ const styles = StyleSheet.create({
}, },
itemContainer: { itemContainer: {
margin: 8, margin: 8,
width: ITEM_WIDTH,
alignItems: "center", alignItems: "center",
}, },
}); });

View File

@@ -8,7 +8,7 @@ import { PlayerControls } from "@/components/PlayerControls";
import { EpisodeSelectionModal } from "@/components/EpisodeSelectionModal"; import { EpisodeSelectionModal } from "@/components/EpisodeSelectionModal";
import { SourceSelectionModal } from "@/components/SourceSelectionModal"; import { SourceSelectionModal } from "@/components/SourceSelectionModal";
import { SeekingBar } from "@/components/SeekingBar"; import { SeekingBar } from "@/components/SeekingBar";
import { NextEpisodeOverlay } from "@/components/NextEpisodeOverlay"; // import { NextEpisodeOverlay } from "@/components/NextEpisodeOverlay";
import VideoLoadingAnimation from "@/components/VideoLoadingAnimation"; import VideoLoadingAnimation from "@/components/VideoLoadingAnimation";
import useDetailStore from "@/stores/detailStore"; import useDetailStore from "@/stores/detailStore";
import { useTVRemoteHandler } from "@/hooks/useTVRemoteHandler"; import { useTVRemoteHandler } from "@/hooks/useTVRemoteHandler";

View File

@@ -1,5 +1,5 @@
import React, { useState, useRef, useEffect } from "react"; import React, { useState, useRef, useEffect } from "react";
import { View, TextInput, StyleSheet, FlatList, Alert, Keyboard } from "react-native"; import { View, TextInput, StyleSheet, Alert, Keyboard, TouchableOpacity, 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 VideoCard from "@/components/VideoCard.tv"; import VideoCard from "@/components/VideoCard.tv";
@@ -12,6 +12,7 @@ import { RemoteControlModal } from "@/components/RemoteControlModal";
import { useSettingsStore } from "@/stores/settingsStore"; import { useSettingsStore } from "@/stores/settingsStore";
import { useRouter } from "expo-router"; import { useRouter } from "expo-router";
import { Colors } from "@/constants/Colors"; import { Colors } from "@/constants/Colors";
import CustomScrollView from "@/components/CustomScrollView";
export default function SearchScreen() { export default function SearchScreen() {
const [keyword, setKeyword] = useState(""); const [keyword, setKeyword] = useState("");
@@ -35,13 +36,13 @@ export default function SearchScreen() {
// eslint-disable-next-line react-hooks/exhaustive-deps // eslint-disable-next-line react-hooks/exhaustive-deps
}, [lastMessage]); }, [lastMessage]);
useEffect(() => { // useEffect(() => {
// Focus the text input when the screen loads // // Focus the text input when the screen loads
const timer = setTimeout(() => { // const timer = setTimeout(() => {
textInputRef.current?.focus(); // textInputRef.current?.focus();
}, 200); // }, 200);
return () => clearTimeout(timer); // return () => clearTimeout(timer);
}, []); // }, []);
const handleSearch = async (searchText?: string) => { const handleSearch = async (searchText?: string) => {
const term = typeof searchText === "string" ? searchText : keyword; const term = typeof searchText === "string" ? searchText : keyword;
@@ -80,7 +81,7 @@ export default function SearchScreen() {
showRemoteModal(); showRemoteModal();
}; };
const renderItem = ({ item }: { item: SearchResult }) => ( const renderItem = ({ item, index }: { item: SearchResult; index: number }) => (
<VideoCard <VideoCard
id={item.id.toString()} id={item.id.toString()}
source={item.source} source={item.source}
@@ -95,25 +96,36 @@ export default function SearchScreen() {
return ( return (
<ThemedView style={styles.container}> <ThemedView style={styles.container}>
<View style={styles.searchContainer}> <View style={styles.searchContainer}>
<TextInput <TouchableOpacity
ref={textInputRef} activeOpacity={1}
style={[ style={[
styles.input, styles.input,
{ {
backgroundColor: colorScheme === "dark" ? "#2c2c2e" : "#f0f0f0", backgroundColor: colorScheme === "dark" ? "#2c2c2e" : "#f0f0f0",
color: colorScheme === "dark" ? "white" : "black",
borderColor: isInputFocused ? Colors.dark.primary : "transparent", borderColor: isInputFocused ? Colors.dark.primary : "transparent",
borderWidth: 2,
}, },
]} ]}
placeholder="搜索电影、剧集..." onPress={() => textInputRef.current?.focus()}
placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"}
value={keyword}
onChangeText={setKeyword}
onFocus={() => setIsInputFocused(true)} onFocus={() => setIsInputFocused(true)}
onBlur={() => setIsInputFocused(false)} onBlur={() => setIsInputFocused(false)}
onSubmitEditing={onSearchPress} >
returnKeyType="search" <TextInput
/> ref={textInputRef}
style={[
styles.input,
{
color: colorScheme === "dark" ? "white" : "black",
},
]}
placeholder="搜索电影、剧集..."
placeholderTextColor={colorScheme === "dark" ? "#888" : "#555"}
value={keyword}
onChangeText={setKeyword}
onSubmitEditing={onSearchPress}
returnKeyType="search"
/>
</TouchableOpacity>
<StyledButton style={styles.searchButton} onPress={onSearchPress}> <StyledButton style={styles.searchButton} onPress={onSearchPress}>
<Search size={24} color={colorScheme === "dark" ? "white" : "black"} /> <Search size={24} color={colorScheme === "dark" ? "white" : "black"} />
</StyledButton> </StyledButton>
@@ -129,17 +141,13 @@ export default function SearchScreen() {
<ThemedText style={styles.errorText}>{error}</ThemedText> <ThemedText style={styles.errorText}>{error}</ThemedText>
</View> </View>
) : ( ) : (
<FlatList <CustomScrollView
data={results} data={results}
renderItem={renderItem} renderItem={renderItem}
keyExtractor={(item, index) => `${item.id}-${item.source}-${index}`} numColumns={5}
numColumns={5} // Adjust based on your card size and desired layout loading={loading}
contentContainerStyle={styles.listContent} error={error}
ListEmptyComponent={ emptyMessage="输入关键词开始搜索"
<View style={styles.centerContainer}>
<ThemedText></ThemedText>
</View>
}
/> />
)} )}
<RemoteControlModal /> <RemoteControlModal />

View File

@@ -0,0 +1,130 @@
import React, { useState, useCallback } from "react";
import { View, StyleSheet, ScrollView, Dimensions, ActivityIndicator } from "react-native";
import { ThemedText } from "@/components/ThemedText";
interface CustomScrollViewProps {
data: any[];
renderItem: ({ item, index }: { item: any; index: number }) => React.ReactNode;
numColumns?: number;
loading?: boolean;
loadingMore?: boolean;
error?: string | null;
onEndReached?: () => void;
loadMoreThreshold?: number;
emptyMessage?: string;
ListFooterComponent?: React.ComponentType<any> | React.ReactElement | null;
}
const { width } = Dimensions.get("window");
const CustomScrollView: React.FC<CustomScrollViewProps> = ({
data,
renderItem,
numColumns = 1,
loading = false,
loadingMore = false,
error = null,
onEndReached,
loadMoreThreshold = 200,
emptyMessage = "暂无内容",
ListFooterComponent,
}) => {
const ITEM_WIDTH = numColumns > 0 ? width / numColumns - 24 : width - 24;
const handleScroll = useCallback(
({ nativeEvent }: { nativeEvent: any }) => {
const { layoutMeasurement, contentOffset, contentSize } = nativeEvent;
const isCloseToBottom = layoutMeasurement.height + contentOffset.y >= contentSize.height - loadMoreThreshold;
if (isCloseToBottom && !loadingMore && onEndReached) {
onEndReached();
}
},
[onEndReached, loadingMore, loadMoreThreshold]
);
const renderFooter = () => {
if (ListFooterComponent) {
if (React.isValidElement(ListFooterComponent)) {
return ListFooterComponent;
} else if (typeof ListFooterComponent === "function") {
const Component = ListFooterComponent as React.ComponentType<any>;
return <Component />;
}
return null;
}
if (loadingMore) {
return <ActivityIndicator style={{ marginVertical: 20 }} size="large" />;
}
return null;
};
if (loading) {
return (
<View style={styles.centerContainer}>
<ActivityIndicator size="large" />
</View>
);
}
if (error) {
return (
<View style={styles.centerContainer}>
<ThemedText type="subtitle" style={{ padding: 10 }}>
{error}
</ThemedText>
</View>
);
}
if (data.length === 0) {
return (
<View style={styles.centerContainer}>
<ThemedText>{emptyMessage}</ThemedText>
</View>
);
}
return (
<ScrollView contentContainerStyle={styles.listContent} onScroll={handleScroll} scrollEventThrottle={16}>
{data.length > 0 ? (
<>
{/* Render content in a grid layout */}
{Array.from({ length: Math.ceil(data.length / numColumns) }).map((_, rowIndex) => (
<View key={rowIndex} style={{ flexDirection: "row", justifyContent: "space-between" }}>
{data.slice(rowIndex * numColumns, (rowIndex + 1) * numColumns).map((item, index) => (
<View key={index} style={[styles.itemContainer, { width: ITEM_WIDTH }]}>
{renderItem({ item, index: rowIndex * numColumns + index })}
</View>
))}
</View>
))}
{renderFooter()}
</>
) : (
<View style={styles.centerContainer}>
<ThemedText>{emptyMessage}</ThemedText>
</View>
)}
</ScrollView>
);
};
const styles = StyleSheet.create({
centerContainer: {
flex: 1,
paddingTop: 20,
justifyContent: "center",
alignItems: "center",
},
listContent: {
paddingHorizontal: 16,
paddingBottom: 20,
},
itemContainer: {
margin: 8,
alignItems: "center",
},
});
export default CustomScrollView;

View File

@@ -1,6 +1,7 @@
import React, { useRef, useState, useEffect } from "react"; import React, { useRef, useState, useEffect } from "react";
import { View, StyleSheet, Text, ActivityIndicator } from "react-native"; import { View, StyleSheet, Text, ActivityIndicator } from "react-native";
import { Video, ResizeMode, AVPlaybackStatus } from "expo-av"; import { Video, ResizeMode, AVPlaybackStatus } from "expo-av";
import { useKeepAwake } from "expo-keep-awake";
interface LivePlayerProps { interface LivePlayerProps {
streamUrl: string | null; streamUrl: string | null;
@@ -15,6 +16,7 @@ export default function LivePlayer({ streamUrl, channelTitle, onPlaybackStatusUp
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const [isTimeout, setIsTimeout] = useState(false); const [isTimeout, setIsTimeout] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout | null>(null); const timeoutRef = useRef<NodeJS.Timeout | null>(null);
useKeepAwake();
useEffect(() => { useEffect(() => {
if (timeoutRef.current) { if (timeoutRef.current) {

View File

@@ -1,5 +1,5 @@
import React, { useState, useRef, useEffect } from "react"; import React, { useState, useRef, useEffect } from "react";
import { Modal, View, TextInput, StyleSheet, ActivityIndicator, useTVEventHandler } from "react-native"; import { Modal, View, TextInput, StyleSheet, ActivityIndicator } from "react-native";
import { usePathname } from "expo-router"; import { usePathname } from "expo-router";
import Toast from "react-native-toast-message"; import Toast from "react-native-toast-message";
import useAuthStore from "@/stores/authStore"; import useAuthStore from "@/stores/authStore";
@@ -19,47 +19,24 @@ const LoginModal = () => {
const [isLoading, setIsLoading] = useState(false); const [isLoading, setIsLoading] = useState(false);
const usernameInputRef = useRef<TextInput>(null); const usernameInputRef = useRef<TextInput>(null);
const passwordInputRef = useRef<TextInput>(null); const passwordInputRef = useRef<TextInput>(null);
const loginButtonRef = useRef<View>(null);
const [focused, setFocused] = useState("username");
const pathname = usePathname(); const pathname = usePathname();
const isSettingsPage = pathname.includes("settings"); const isSettingsPage = pathname.includes("settings");
const tvEventHandler = (evt: any) => { // Focus management with better TV remote handling
if (!evt || !isLoginModalVisible || isSettingsPage) {
return;
}
const isUsernameVisible = serverConfig?.StorageType !== "localstorage";
if (evt.eventType === "down") {
if (focused === "username" && isUsernameVisible) {
passwordInputRef.current?.focus();
} else if (focused === "password") {
loginButtonRef.current?.focus();
}
}
if (evt.eventType === "up") {
if (focused === "button") {
passwordInputRef.current?.focus();
} else if (focused === "password" && isUsernameVisible) {
usernameInputRef.current?.focus();
}
}
};
useTVEventHandler(tvEventHandler);
useEffect(() => { useEffect(() => {
if (isLoginModalVisible && !isSettingsPage) { if (isLoginModalVisible && !isSettingsPage) {
const isUsernameVisible = serverConfig?.StorageType !== "localstorage"; const isUsernameVisible = serverConfig?.StorageType !== "localstorage";
setTimeout(() => {
// Use a small delay to ensure the modal is fully rendered
const focusTimeout = setTimeout(() => {
if (isUsernameVisible) { if (isUsernameVisible) {
usernameInputRef.current?.focus(); usernameInputRef.current?.focus();
} else { } else {
passwordInputRef.current?.focus(); passwordInputRef.current?.focus();
} }
}, 200); }, 100);
return () => clearTimeout(focusTimeout);
} }
}, [isLoginModalVisible, serverConfig, isSettingsPage]); }, [isLoginModalVisible, serverConfig, isSettingsPage]);
@@ -85,6 +62,11 @@ const LoginModal = () => {
} }
}; };
// Handle navigation between inputs using returnKeyType
const handleUsernameSubmit = () => {
passwordInputRef.current?.focus();
};
return ( return (
<Modal <Modal
transparent={true} transparent={true}
@@ -105,7 +87,8 @@ const LoginModal = () => {
value={username} value={username}
onChangeText={setUsername} onChangeText={setUsername}
returnKeyType="next" returnKeyType="next"
onFocus={() => setFocused("username")} onSubmitEditing={handleUsernameSubmit}
blurOnSubmit={false}
/> />
)} )}
<TextInput <TextInput
@@ -117,16 +100,14 @@ const LoginModal = () => {
value={password} value={password}
onChangeText={setPassword} onChangeText={setPassword}
returnKeyType="go" returnKeyType="go"
onFocus={() => setFocused("password")}
onSubmitEditing={handleLogin} onSubmitEditing={handleLogin}
/> />
<StyledButton <StyledButton
ref={loginButtonRef}
onFocus={() => setFocused("button")}
text={isLoading ? "" : "登录"} text={isLoading ? "" : "登录"}
onPress={handleLogin} onPress={handleLogin}
disabled={isLoading} disabled={isLoading}
style={styles.button} style={styles.button}
hasTVPreferredFocus={!serverConfig || serverConfig.StorageType === "localstorage"}
> >
{isLoading && <ActivityIndicator color="#fff" />} {isLoading && <ActivityIndicator color="#fff" />}
</StyledButton> </StyledButton>

View File

@@ -5,12 +5,24 @@ import useDetailStore from "@/stores/detailStore";
import usePlayerStore from "@/stores/playerStore"; import usePlayerStore from "@/stores/playerStore";
export const SourceSelectionModal: React.FC = () => { export const SourceSelectionModal: React.FC = () => {
const { showSourceModal, setShowSourceModal } = usePlayerStore(); const { showSourceModal, setShowSourceModal, loadVideo, currentEpisodeIndex, status } = usePlayerStore();
const { searchResults, detail, setDetail } = useDetailStore(); const { searchResults, detail, setDetail } = useDetailStore();
const onSelectSource = (index: number) => { const onSelectSource = (index: number) => {
console.log("onSelectSource", index, searchResults[index].source, detail?.source);
if (searchResults[index].source !== detail?.source) { if (searchResults[index].source !== detail?.source) {
setDetail(searchResults[index]); const newDetail = searchResults[index];
setDetail(newDetail);
// Reload the video with the new source, preserving current position
const currentPosition = status?.isLoaded ? status.positionMillis : undefined;
loadVideo({
source: newDetail.source,
id: newDetail.id.toString(),
episodeIndex: currentEpisodeIndex,
title: newDetail.title,
position: currentPosition
});
} }
setShowSourceModal(false); setShowSourceModal(false);
}; };

View File

@@ -1,14 +1,14 @@
import React, { useState, useEffect, useCallback, useRef } from "react"; import React, { useState, useCallback, useRef, forwardRef } from "react";
import { View, Text, Image, StyleSheet, Pressable, TouchableOpacity, Alert } from "react-native"; import { View, Text, Image, StyleSheet, 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 { Star, Play } from "lucide-react-native";
import { FavoriteManager, PlayRecordManager } from "@/services/storage"; import { PlayRecordManager } from "@/services/storage";
import { API, api } from "@/services/api"; import { API } from "@/services/api";
import { ThemedText } from "@/components/ThemedText"; import { ThemedText } from "@/components/ThemedText";
import { Colors } from "@/constants/Colors"; import { Colors } from "@/constants/Colors";
interface VideoCardProps { interface VideoCardProps extends React.ComponentProps<typeof TouchableOpacity> {
id: string; id: string;
source: string; source: string;
title: string; title: string;
@@ -25,166 +25,175 @@ interface VideoCardProps {
api: API; api: API;
} }
export default function VideoCard({ const VideoCard = forwardRef<View, VideoCardProps>(
id, (
source, {
title, id,
poster, source,
year, title,
rate, poster,
sourceName, year,
progress, rate,
episodeIndex, sourceName,
onFocus, progress,
onRecordDeleted, episodeIndex,
api, onFocus,
playTime = 0, onRecordDeleted,
}: VideoCardProps) { api,
const router = useRouter(); playTime = 0,
const [isFocused, setIsFocused] = useState(false); }: VideoCardProps,
ref
) => {
const router = useRouter();
const [isFocused, setIsFocused] = useState(false);
const longPressTriggered = useRef(false); const longPressTriggered = useRef(false);
const scale = useSharedValue(1); const scale = useSharedValue(1);
const animatedStyle = useAnimatedStyle(() => { const animatedStyle = useAnimatedStyle(() => {
return { return {
transform: [{ scale: scale.value }], transform: [{ scale: scale.value }],
};
});
const handlePress = () => {
if (longPressTriggered.current) {
longPressTriggered.current = false;
return;
}
// 如果有播放进度,直接转到播放页面
if (progress !== undefined && episodeIndex !== undefined) {
router.push({
pathname: "/play",
params: { source, id, episodeIndex: episodeIndex - 1, title, position: playTime * 1000 },
});
} else {
router.push({
pathname: "/detail",
params: { source, q: title },
});
}
}; };
});
const handlePress = () => { const handleFocus = useCallback(() => {
if (longPressTriggered.current) { setIsFocused(true);
longPressTriggered.current = false; scale.value = withSpring(1.05, { damping: 15, stiffness: 200 });
return; onFocus?.();
} }, [scale, onFocus]);
// 如果有播放进度,直接转到播放页面
if (progress !== undefined && episodeIndex !== undefined) {
router.push({
pathname: "/play",
params: { source, id, episodeIndex: episodeIndex - 1, title, position: playTime * 1000 },
});
} else {
router.push({
pathname: "/detail",
params: { source, q: title },
});
}
};
const handleFocus = useCallback(() => { const handleBlur = useCallback(() => {
setIsFocused(true); setIsFocused(false);
scale.value = withSpring(1.05, { damping: 15, stiffness: 200 }); scale.value = withSpring(1.0);
onFocus?.(); }, [scale]);
}, [scale, onFocus]);
const handleBlur = useCallback(() => { const handleLongPress = () => {
setIsFocused(false); // Only allow long press for items with progress (play records)
scale.value = withSpring(1.0); if (progress === undefined) return;
}, [scale]);
const handleLongPress = () => { longPressTriggered.current = true;
// Only allow long press for items with progress (play records)
if (progress === undefined) return;
longPressTriggered.current = true; // Show confirmation dialog to delete play record
Alert.alert("删除观看记录", `确定要删除"${title}"的观看记录吗?`, [
// Show confirmation dialog to delete play record {
Alert.alert("删除观看记录", `确定要删除"${title}"的观看记录吗?`, [ text: "取消",
{ style: "cancel",
text: "取消",
style: "cancel",
},
{
text: "删除",
style: "destructive",
onPress: async () => {
try {
// Delete from local storage
await PlayRecordManager.remove(source, id);
// Call the onRecordDeleted callback
if (onRecordDeleted) {
onRecordDeleted();
}
// 如果没有回调函数,则使用导航刷新作为备选方案
else if (router.canGoBack()) {
router.replace("/");
}
} catch (error) {
console.info("Failed to delete play record:", error);
Alert.alert("错误", "删除观看记录失败,请重试");
}
}, },
}, {
]); text: "删除",
}; style: "destructive",
onPress: async () => {
try {
// Delete from local storage
await PlayRecordManager.remove(source, id);
// 是否是继续观看的视频 // Call the onRecordDeleted callback
const isContinueWatching = progress !== undefined && progress > 0 && progress < 1; if (onRecordDeleted) {
onRecordDeleted();
}
// 如果没有回调函数,则使用导航刷新作为备选方案
else if (router.canGoBack()) {
router.replace("/");
}
} catch (error) {
console.info("Failed to delete play record:", error);
Alert.alert("错误", "删除观看记录失败,请重试");
}
},
},
]);
};
return ( // 是否是继续观看的视频
<Animated.View style={[styles.wrapper, animatedStyle]}> const isContinueWatching = progress !== undefined && progress > 0 && progress < 1;
<TouchableOpacity
onPress={handlePress}
onLongPress={handleLongPress}
onFocus={handleFocus}
onBlur={handleBlur}
style={styles.pressable}
activeOpacity={1}
delayLongPress={1000}
>
<View style={styles.card}>
<Image source={{ uri: api.getImageProxyUrl(poster) }} style={styles.poster} />
{isFocused && (
<View style={styles.overlay}>
{isContinueWatching && (
<View style={styles.continueWatchingBadge}>
<Play size={16} color="#ffffff" fill="#ffffff" />
<ThemedText style={styles.continueWatchingText}></ThemedText>
</View>
)}
</View>
)}
{/* 进度条 */} return (
{isContinueWatching && ( <Animated.View style={[styles.wrapper, animatedStyle]}>
<View style={styles.progressContainer}> <TouchableOpacity
<View style={[styles.progressBar, { width: `${(progress || 0) * 100}%` }]} /> onPress={handlePress}
</View> onLongPress={handleLongPress}
)} onFocus={handleFocus}
onBlur={handleBlur}
style={styles.pressable}
activeOpacity={1}
delayLongPress={1000}
>
<View style={styles.card}>
<Image source={{ uri: api.getImageProxyUrl(poster) }} style={styles.poster} />
{isFocused && (
<View style={styles.overlay}>
{isContinueWatching && (
<View style={styles.continueWatchingBadge}>
<Play size={16} color="#ffffff" fill="#ffffff" />
<ThemedText style={styles.continueWatchingText}></ThemedText>
</View>
)}
</View>
)}
{rate && ( {/* 进度条 */}
<View style={styles.ratingContainer}> {isContinueWatching && (
<Star size={12} color="#FFD700" fill="#FFD700" /> <View style={styles.progressContainer}>
<ThemedText style={styles.ratingText}>{rate}</ThemedText> <View style={[styles.progressBar, { width: `${(progress || 0) * 100}%` }]} />
</View> </View>
)} )}
{year && (
<View style={styles.yearBadge}> {rate && (
<Text style={styles.badgeText}>{year}</Text> <View style={styles.ratingContainer}>
</View> <Star size={12} color="#FFD700" fill="#FFD700" />
)} <ThemedText style={styles.ratingText}>{rate}</ThemedText>
{sourceName && ( </View>
<View style={styles.sourceNameBadge}> )}
<Text style={styles.badgeText}>{sourceName}</Text> {year && (
</View> <View style={styles.yearBadge}>
)} <Text style={styles.badgeText}>{year}</Text>
</View> </View>
<View style={styles.infoContainer}> )}
<ThemedText numberOfLines={1}>{title}</ThemedText> {sourceName && (
{isContinueWatching && ( <View style={styles.sourceNameBadge}>
<View style={styles.infoRow}> <Text style={styles.badgeText}>{sourceName}</Text>
<ThemedText style={styles.continueLabel}> </View>
{episodeIndex! + 1} {Math.round((progress || 0) * 100)}% )}
</ThemedText> </View>
</View> <View style={styles.infoContainer}>
)} <ThemedText numberOfLines={1}>{title}</ThemedText>
</View> {isContinueWatching && (
</TouchableOpacity> <View style={styles.infoRow}>
</Animated.View> <ThemedText style={styles.continueLabel}>
); {episodeIndex! + 1} {Math.round((progress || 0) * 100)}%
} </ThemedText>
</View>
)}
</View>
</TouchableOpacity>
</Animated.View>
);
}
);
VideoCard.displayName = "VideoCard";
export default VideoCard;
const CARD_WIDTH = 160; const CARD_WIDTH = 160;
const CARD_HEIGHT = 240; const CARD_HEIGHT = 240;

View File

@@ -2,7 +2,7 @@
"name": "OrionTV", "name": "OrionTV",
"private": true, "private": true,
"main": "expo-router/entry", "main": "expo-router/entry",
"version": "1.2.6", "version": "1.2.8",
"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",
@@ -80,4 +80,4 @@
} }
}, },
"packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e" "packageManager": "yarn@1.22.22+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e"
} }

View File

@@ -2,6 +2,7 @@ import { create } from "zustand";
import Cookies from "@react-native-cookies/cookies"; import Cookies from "@react-native-cookies/cookies";
import { api } from "@/services/api"; import { api } from "@/services/api";
import { useSettingsStore } from "./settingsStore"; import { useSettingsStore } from "./settingsStore";
import Toast from "react-native-toast-message";
interface AuthState { interface AuthState {
isLoggedIn: boolean; isLoggedIn: boolean;
@@ -24,6 +25,10 @@ const useAuthStore = create<AuthState>((set) => ({
} }
try { try {
const serverConfig = useSettingsStore.getState().serverConfig; const serverConfig = useSettingsStore.getState().serverConfig;
if (!serverConfig?.StorageType) {
Toast.show({ type: "error", text1: "请检查网络或者 API 地址是否可用" });
return
}
const cookies = await Cookies.get(api.baseURL); const cookies = await Cookies.get(api.baseURL);
if (serverConfig && serverConfig.StorageType === "localstorage" && !cookies.auth) { if (serverConfig && serverConfig.StorageType === "localstorage" && !cookies.auth) {
const loginResult = await api.login().catch(() => { const loginResult = await api.login().catch(() => {

View File

@@ -254,7 +254,6 @@ const usePlayerStore = create<PlayerState>((set, get) => ({
...existingRecord, ...existingRecord,
...updates, ...updates,
}); });
console.log("Play record saved")
} }
}, },

View File

@@ -56,9 +56,10 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
const config = await api.getServerConfig(); const config = await api.getServerConfig();
if (config) { if (config) {
storageConfig.setStorageType(config.StorageType); storageConfig.setStorageType(config.StorageType);
set({ serverConfig: config });
} }
set({ serverConfig: config });
} catch (error) { } catch (error) {
set({ serverConfig: null });
console.info("Failed to fetch server config:", error); console.info("Failed to fetch server config:", error);
} }
}, },