mirror of
https://github.com/zoriya/Kyoo.git
synced 2025-06-02 21:24:20 -04:00
Allow downloaded items to be played
This commit is contained in:
parent
c0cf11ee79
commit
213d5b74b5
@ -35,6 +35,7 @@ export const Button = ({
|
|||||||
{...css(
|
{...css(
|
||||||
{
|
{
|
||||||
flexGrow: 0,
|
flexGrow: 0,
|
||||||
|
overflow: "hidden",
|
||||||
p: ts(0.5),
|
p: ts(0.5),
|
||||||
borderRadius: ts(5),
|
borderRadius: ts(5),
|
||||||
borderColor: (theme) => theme.accent,
|
borderColor: (theme) => theme.accent,
|
||||||
@ -44,8 +45,7 @@ export const Button = ({
|
|||||||
text: { color: (theme: Theme) => theme.colors.white },
|
text: { color: (theme: Theme) => theme.colors.white },
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
// @ts-ignore ??
|
props as any,
|
||||||
props,
|
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<P {...css({ textAlign: "center" }, "text")}>{text}</P>
|
<P {...css({ textAlign: "center" }, "text")}>{text}</P>
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
"@tanstack/react-query": "*",
|
"@tanstack/react-query": "*",
|
||||||
"expo-file-system": "*",
|
"expo-file-system": "*",
|
||||||
"expo-linear-gradient": "*",
|
"expo-linear-gradient": "*",
|
||||||
|
"expo-router": "*",
|
||||||
"i18next": "*",
|
"i18next": "*",
|
||||||
"moti": "*",
|
"moti": "*",
|
||||||
"react": "*",
|
"react": "*",
|
||||||
@ -31,11 +32,15 @@
|
|||||||
},
|
},
|
||||||
"optionalDependencies": {
|
"optionalDependencies": {
|
||||||
"@kesha-antonov/react-native-background-downloader": "^2.10.0",
|
"@kesha-antonov/react-native-background-downloader": "^2.10.0",
|
||||||
"expo-file-system": "^15.6.0"
|
"expo-file-system": "^15.6.0",
|
||||||
|
"expo-router": "^2.0.14"
|
||||||
},
|
},
|
||||||
"peerDependenciesMeta": {
|
"peerDependenciesMeta": {
|
||||||
"@kesha-antonov/react-native-background-downloader": {
|
"@kesha-antonov/react-native-background-downloader": {
|
||||||
"optional": true
|
"optional": true
|
||||||
|
},
|
||||||
|
"expo-router": {
|
||||||
|
"optional": true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -45,6 +45,7 @@ import DownloadForOffline from "@material-symbols/svg-400/rounded/download_for_o
|
|||||||
import Downloading from "@material-symbols/svg-400/rounded/downloading.svg";
|
import Downloading from "@material-symbols/svg-400/rounded/downloading.svg";
|
||||||
import Error from "@material-symbols/svg-400/rounded/error.svg";
|
import Error from "@material-symbols/svg-400/rounded/error.svg";
|
||||||
import NotStarted from "@material-symbols/svg-400/rounded/not_started.svg";
|
import NotStarted from "@material-symbols/svg-400/rounded/not_started.svg";
|
||||||
|
import { useRouter } from "expo-router";
|
||||||
|
|
||||||
const DownloadedItem = ({
|
const DownloadedItem = ({
|
||||||
name,
|
name,
|
||||||
@ -62,11 +63,12 @@ const DownloadedItem = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { css } = useYoshiki();
|
const { css } = useYoshiki();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const router = useRouter();
|
||||||
const { error, status, pause, resume, remove, play } = useAtomValue(statusAtom);
|
const { error, status, pause, resume, remove, play } = useAtomValue(statusAtom);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<PressableFeedback
|
<PressableFeedback
|
||||||
onPress={() => play?.()}
|
onPress={() => play?.(router)}
|
||||||
{...css(
|
{...css(
|
||||||
{
|
{
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
@ -36,6 +36,8 @@ import { atom, useSetAtom, PrimitiveAtom, useStore } from "jotai";
|
|||||||
import { getCurrentAccount, storage } from "@kyoo/models/src/account-internal";
|
import { getCurrentAccount, storage } from "@kyoo/models/src/account-internal";
|
||||||
import { ReactNode, useEffect } from "react";
|
import { ReactNode, useEffect } from "react";
|
||||||
import { Platform, ToastAndroid } from "react-native";
|
import { Platform, ToastAndroid } from "react-native";
|
||||||
|
import { useQueryClient } from "@tanstack/react-query";
|
||||||
|
import { Router } from "expo-router/build/types";
|
||||||
|
|
||||||
export type State = {
|
export type State = {
|
||||||
status: "DOWNLOADING" | "PAUSED" | "DONE" | "FAILED" | "STOPPED";
|
status: "DOWNLOADING" | "PAUSED" | "DONE" | "FAILED" | "STOPPED";
|
||||||
@ -46,7 +48,7 @@ export type State = {
|
|||||||
pause: (() => void) | null;
|
pause: (() => void) | null;
|
||||||
resume: (() => void) | null;
|
resume: (() => void) | null;
|
||||||
remove: () => void;
|
remove: () => void;
|
||||||
play: () => void;
|
play: (router: Router) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const downloadAtom = atom<
|
export const downloadAtom = atom<
|
||||||
@ -94,8 +96,7 @@ const setupDownloadTask = (
|
|||||||
store.set(downloadAtom, (x) => x.filter((y) => y.data.id !== task.id));
|
store.set(downloadAtom, (x) => x.filter((y) => y.data.id !== task.id));
|
||||||
},
|
},
|
||||||
play: () => {
|
play: () => {
|
||||||
// TODO: set useQuery cache
|
ToastAndroid.show("The file has not finished downloading", ToastAndroid.LONG);
|
||||||
// TODO: move to the play page.
|
|
||||||
},
|
},
|
||||||
} as State);
|
} as State);
|
||||||
|
|
||||||
@ -188,6 +189,7 @@ export const useDownloader = () => {
|
|||||||
|
|
||||||
export const DownloadProvider = ({ children }: { children: ReactNode }) => {
|
export const DownloadProvider = ({ children }: { children: ReactNode }) => {
|
||||||
const store = useStore();
|
const store = useStore();
|
||||||
|
const queryClient = useQueryClient();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function run() {
|
async function run() {
|
||||||
@ -210,8 +212,21 @@ export const DownloadProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
availableSize: dl.state.availableSize,
|
availableSize: dl.state.availableSize,
|
||||||
pause: null,
|
pause: null,
|
||||||
resume: null,
|
resume: null,
|
||||||
play: () => {
|
play: (router: Router) => {
|
||||||
// TODO: setup this
|
dl.data.links.direct = dl.path;
|
||||||
|
queryClient.setQueryData(
|
||||||
|
toQueryKey(Player.query(dl.data.kind, dl.data.slug)),
|
||||||
|
dl.data,
|
||||||
|
);
|
||||||
|
queryClient.setQueryData(
|
||||||
|
toQueryKey(Player.infoQuery(dl.data.kind, dl.data.slug)),
|
||||||
|
dl.info,
|
||||||
|
);
|
||||||
|
router.push(
|
||||||
|
dl.data.kind === "episode"
|
||||||
|
? { pathname: "/watch/[slug]", params: { slug: dl.data.slug } }
|
||||||
|
: { pathname: "/movie/[slug]/watch", params: { slug: dl.data.slug } },
|
||||||
|
);
|
||||||
},
|
},
|
||||||
remove: () => {
|
remove: () => {
|
||||||
deleteAsync(dl.path);
|
deleteAsync(dl.path);
|
||||||
@ -228,7 +243,7 @@ export const DownloadProvider = ({ children }: { children: ReactNode }) => {
|
|||||||
RNBackgroundDownloader.ensureDownloadsAreRunning();
|
RNBackgroundDownloader.ensureDownloadsAreRunning();
|
||||||
}
|
}
|
||||||
run();
|
run();
|
||||||
}, [store]);
|
}, [store, queryClient]);
|
||||||
|
|
||||||
return children;
|
return children;
|
||||||
};
|
};
|
||||||
|
@ -2950,6 +2950,7 @@ __metadata:
|
|||||||
"@shopify/flash-list": ^1.6.3
|
"@shopify/flash-list": ^1.6.3
|
||||||
"@types/react": 18.2.39
|
"@types/react": 18.2.39
|
||||||
expo-file-system: ^15.6.0
|
expo-file-system: ^15.6.0
|
||||||
|
expo-router: ^2.0.14
|
||||||
react-native-uuid: ^2.0.1
|
react-native-uuid: ^2.0.1
|
||||||
typescript: ^5.3.2
|
typescript: ^5.3.2
|
||||||
peerDependencies:
|
peerDependencies:
|
||||||
@ -2959,6 +2960,7 @@ __metadata:
|
|||||||
"@tanstack/react-query": "*"
|
"@tanstack/react-query": "*"
|
||||||
expo-file-system: "*"
|
expo-file-system: "*"
|
||||||
expo-linear-gradient: "*"
|
expo-linear-gradient: "*"
|
||||||
|
expo-router: "*"
|
||||||
i18next: "*"
|
i18next: "*"
|
||||||
moti: "*"
|
moti: "*"
|
||||||
react: "*"
|
react: "*"
|
||||||
@ -2972,9 +2974,13 @@ __metadata:
|
|||||||
optional: true
|
optional: true
|
||||||
expo-file-system:
|
expo-file-system:
|
||||||
optional: true
|
optional: true
|
||||||
|
expo-router:
|
||||||
|
optional: true
|
||||||
peerDependenciesMeta:
|
peerDependenciesMeta:
|
||||||
"@kesha-antonov/react-native-background-downloader":
|
"@kesha-antonov/react-native-background-downloader":
|
||||||
optional: true
|
optional: true
|
||||||
|
expo-router:
|
||||||
|
optional: true
|
||||||
languageName: unknown
|
languageName: unknown
|
||||||
linkType: soft
|
linkType: soft
|
||||||
|
|
||||||
@ -8088,7 +8094,7 @@ __metadata:
|
|||||||
languageName: node
|
languageName: node
|
||||||
linkType: hard
|
linkType: hard
|
||||||
|
|
||||||
"expo-router@npm:2.0.14":
|
"expo-router@npm:2.0.14, expo-router@npm:^2.0.14":
|
||||||
version: 2.0.14
|
version: 2.0.14
|
||||||
resolution: "expo-router@npm:2.0.14"
|
resolution: "expo-router@npm:2.0.14"
|
||||||
dependencies:
|
dependencies:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user