downloads refactor

This commit is contained in:
Jorrin
2024-04-06 16:53:54 +02:00
parent bf6bd7af2f
commit c61f18941e
19 changed files with 179 additions and 195 deletions

View File

@@ -1,4 +1,3 @@
import type { Asset } from "expo-media-library";
import React from "react";
import { Alert, Platform } from "react-native";
import { ScrollView } from "react-native-gesture-handler";
@@ -12,13 +11,16 @@ import type { ScrapeMedia } from "@movie-web/provider-utils";
import { DownloadItem } from "~/components/DownloadItem";
import ScreenLayout from "~/components/layout/ScreenLayout";
import { MWButton } from "~/components/ui/Button";
import { useDownloadManager } from "~/hooks/DownloadManagerContext";
import { useDownloadManager } from "~/contexts/DownloadManagerContext";
import { PlayerStatus } from "~/stores/player/slices/interface";
import { usePlayerStore } from "~/stores/player/store";
const DownloadsScreen: React.FC = () => {
const { startDownload, downloads } = useDownloadManager();
const resetVideo = usePlayerStore((state) => state.resetVideo);
const setAsset = usePlayerStore((state) => state.setAsset);
const setVideoSrc = usePlayerStore((state) => state.setVideoSrc);
const setIsLocalFile = usePlayerStore((state) => state.setIsLocalFile);
const setPlayerStatus = usePlayerStore((state) => state.setPlayerStatus);
const router = useRouter();
const theme = useTheme();
@@ -39,10 +41,14 @@ const DownloadsScreen: React.FC = () => {
}, [router]),
);
const handlePress = (asset?: Asset) => {
if (!asset) return;
const handlePress = (localPath?: string) => {
if (!localPath) return;
resetVideo();
setAsset(asset);
setIsLocalFile(true);
setPlayerStatus(PlayerStatus.READY);
setVideoSrc({
uri: localPath,
});
router.push({
pathname: "/videoPlayer",
});
@@ -112,8 +118,8 @@ const DownloadsScreen: React.FC = () => {
{downloads.map((item) => (
<DownloadItem
key={item.id}
{...item}
onPress={() => handlePress(item.asset)}
item={item}
onPress={() => handlePress(item.localPath)}
/>
))}
</ScrollView>

View File

@@ -118,8 +118,8 @@ export default function SettingsScreen() {
return (
<ScreenLayout>
<View padding={4}>
<YStack gap="$4">
<View>
<YStack gap="$8">
<YStack gap="$4">
<Text fontSize="$7" fontWeight="$bold">
Appearance
@@ -181,7 +181,7 @@ export default function SettingsScreen() {
</Text>
<DefaultQualitySelector qualityType="data" />
</XStack>
<XStack gap="$4" alignItems="center">
<XStack gap="$3" alignItems="center">
<Text fontWeight="$semibold" flexGrow={1}>
Allow downloads on mobile data
</Text>
@@ -451,7 +451,7 @@ export function DefaultQualitySelector(props: DefaultQualitySelectorProps) {
{...props}
>
<MWSelect.Trigger
maxWidth="$12"
maxWidth="$10"
iconAfter={
<FontAwesome name="chevron-down" color={theme.inputIconColor.val} />
}

View File

@@ -10,7 +10,7 @@ import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
import { TamaguiProvider, Theme, useTheme } from "tamagui";
import tamaguiConfig from "tamagui.config";
import { DownloadManagerProvider } from "~/hooks/DownloadManagerContext";
import { DownloadManagerProvider } from "~/contexts/DownloadManagerContext";
import { useThemeStore } from "~/stores/theme";
// @ts-expect-error - Without named import it causes an infinite loop
import _styles from "../../tamagui-web.css";

View File

@@ -11,7 +11,6 @@ import { usePlayerStore } from "~/stores/player/store";
export default function VideoPlayerWrapper() {
const playerStatus = usePlayerStore((state) => state.interface.playerStatus);
const asset = usePlayerStore((state) => state.asset);
const { presentFullscreenPlayer } = usePlayer();
const params = useLocalSearchParams();
@@ -32,10 +31,6 @@ export default function VideoPlayerWrapper() {
void presentFullscreenPlayer();
if (asset) {
return <VideoPlayer />;
}
if (download) {
return <ScraperProcess data={data} download />;
}