From 5a8e250bf538649aea621655077fad5d69aae718 Mon Sep 17 00:00:00 2001
From: Adrian Castro <22133246+castdrian@users.noreply.github.com>
Date: Wed, 20 Mar 2024 17:41:44 +0100
Subject: [PATCH] feat: mp4 downloads
---
apps/expo/app.config.ts | 4 +
apps/expo/src/app/(tabs)/downloads.tsx | 26 +--
apps/expo/src/app/_layout.tsx | 9 +-
apps/expo/src/components/DownloadItem.tsx | 22 ++-
apps/expo/src/components/item/item.tsx | 11 +-
.../expo/src/hooks/DownloadManagerContext.tsx | 157 ++++++++++++++++++
6 files changed, 200 insertions(+), 29 deletions(-)
create mode 100644 apps/expo/src/hooks/DownloadManagerContext.tsx
diff --git a/apps/expo/app.config.ts b/apps/expo/app.config.ts
index 2008839..e096b8e 100644
--- a/apps/expo/app.config.ts
+++ b/apps/expo/app.config.ts
@@ -23,6 +23,10 @@ const defineConfig = (): ExpoConfig => ({
bundleIdentifier: "dev.movieweb.app",
supportsTablet: true,
requireFullScreen: true,
+ infoPlist: {
+ NSPhotoLibraryUsageDescription:
+ "This app saves videos to the photo library.",
+ },
},
android: {
package: "dev.movieweb.app",
diff --git a/apps/expo/src/app/(tabs)/downloads.tsx b/apps/expo/src/app/(tabs)/downloads.tsx
index d496dee..0972125 100644
--- a/apps/expo/src/app/(tabs)/downloads.tsx
+++ b/apps/expo/src/app/(tabs)/downloads.tsx
@@ -1,26 +1,12 @@
+import React from "react";
import { ScrollView } from "react-native-gesture-handler";
-import type { DownloadItemProps } from "~/components/DownloadItem";
import { DownloadItem } from "~/components/DownloadItem";
import ScreenLayout from "~/components/layout/ScreenLayout";
+import { useDownloadManager } from "~/hooks/DownloadManagerContext";
-export default function DownloadsScreen() {
- const downloads: DownloadItemProps[] = [
- {
- filename: "episode.mp4",
- progress: 0.3,
- speed: 1.2,
- fileSize: 500 * 1024 * 1024,
- downloaded: 150 * 1024 * 1024,
- },
- {
- filename: "episode.m3u8",
- progress: 0.7,
- speed: 0.8,
- fileSize: 200 * 1024 * 1024,
- downloaded: 140 * 1024 * 1024,
- },
- ];
+const DownloadsScreen: React.FC = () => {
+ const { downloads } = useDownloadManager();
return (
@@ -31,4 +17,6 @@ export default function DownloadsScreen() {
);
-}
+};
+
+export default DownloadsScreen;
diff --git a/apps/expo/src/app/_layout.tsx b/apps/expo/src/app/_layout.tsx
index 92e458b..78ccc46 100644
--- a/apps/expo/src/app/_layout.tsx
+++ b/apps/expo/src/app/_layout.tsx
@@ -9,6 +9,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 { useThemeStore } from "~/stores/theme";
// @ts-expect-error - Without named import it causes an infinite loop
import _styles from "../../tamagui-web.css";
@@ -59,9 +60,11 @@ export default function RootLayout() {
}
return (
-
-
-
+
+
+
+
+
);
}
diff --git a/apps/expo/src/components/DownloadItem.tsx b/apps/expo/src/components/DownloadItem.tsx
index 95583e6..5b43faf 100644
--- a/apps/expo/src/components/DownloadItem.tsx
+++ b/apps/expo/src/components/DownloadItem.tsx
@@ -7,6 +7,7 @@ export interface DownloadItemProps {
speed: number;
fileSize: number;
downloaded: number;
+ isFinished: boolean;
}
const formatBytes = (bytes: number, decimals = 2) => {
@@ -24,8 +25,9 @@ export const DownloadItem: React.FC = ({
speed,
fileSize,
downloaded,
+ isFinished,
}) => {
- const percentage = (progress * 100).toFixed(0);
+ const percentage = progress * 100;
const formattedFileSize = formatBytes(fileSize);
const formattedDownloaded = formatBytes(downloaded);
@@ -34,7 +36,11 @@ export const DownloadItem: React.FC = ({
{filename}
-