Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: automatically next episode settings #51

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/screens/anime/watch/components/auto-next-settings.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { useAtom } from 'jotai/react';
import { ToggleLeft } from 'lucide-react-native';
import React from 'react';

import { shouldAutoNextEpisodeAtom } from '@/screens/settings/store';
import { Text, View } from '@/ui';
import Switch from '@/ui/core/switch';

const AutoNextSettings = () => {
const [shouldAutoNextEpisode, setShouldAutoNextEpisode] = useAtom(
shouldAutoNextEpisodeAtom
);

return (
<View className="flex flex-row items-center justify-between">
<View className="flex flex-row items-center px-4 py-2">
<ToggleLeft size={32} color="white" className="h-8 w-8 text-white" />

<Text variant="lg" weight="semibold" className="ml-2">
Automatically next episode
</Text>

<Text className="ml-4 h-1.5 w-1.5 rounded-full bg-thunder-400" />

<Switch
value={shouldAutoNextEpisode}
onValueChange={setShouldAutoNextEpisode}
/>
</View>
</View>
);
};

export default AutoNextSettings;
5 changes: 4 additions & 1 deletion src/screens/anime/watch/components/media-player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import RNVideo from 'react-native-video';
import { VideoFormat } from '@/core/video';
import providers from '@/providers';
import {
shouldAutoNextEpisodeAtom,
shouldSyncAdultAtom,
syncPercentageAtom,
} from '@/screens/settings/store';
Expand Down Expand Up @@ -91,6 +92,7 @@ const MediaPlayer: React.FC<MediaPlayerProps> = ({
const setVideoSize = useSetAtom(videoSizeAtom);

const shouldSyncAdult = useAtomValue(shouldSyncAdultAtom);
const shouldAutoNextEpisode = useAtomValue(shouldAutoNextEpisodeAtom);

const currentEpisode = useAtomValue(currentEpisodeAtom);
const sectionEpisodes = useAtomValue(sectionEpisodesAtom);
Expand Down Expand Up @@ -251,6 +253,7 @@ const MediaPlayer: React.FC<MediaPlayerProps> = ({
);

const handleVideoEnded = useCallback(() => {
if (!shouldAutoNextEpisode) return;
if (!currentEpisode) return;

const currentEpisodeIndex = sectionEpisodes.findIndex(
Expand All @@ -262,7 +265,7 @@ const MediaPlayer: React.FC<MediaPlayerProps> = ({
if (!nextEpisode) return;

navigation.setParams({ episodeId: nextEpisode.id });
}, [currentEpisode, navigation, sectionEpisodes]);
}, [currentEpisode, navigation, sectionEpisodes, shouldAutoNextEpisode]);

useEffect(() => {
if (!videos?.length) return;
Expand Down
2 changes: 2 additions & 0 deletions src/screens/anime/watch/components/media-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { View } from '@/ui';
import colors from '@/ui/theme/colors';

import { pausedAtom } from '../store';
import AutoNextSettings from './auto-next-settings';
import MediaPlayBackSettings from './media-playback-settings';
import MediaQualitySettings from './media-quality-settings';
import MediaSubtitleSettings from './media-subtitle-settings';
Expand Down Expand Up @@ -35,6 +36,7 @@ const MediaSettings = () => {
<MediaQualitySettings />
<MediaPlayBackSettings />
<MediaSubtitleSettings />
<AutoNextSettings />
</SettingsBottomSheet>
</View>
);
Expand Down
17 changes: 17 additions & 0 deletions src/screens/settings/components/player-settings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import Switch from '@/ui/core/switch';

import {
shouldAskForSyncingAtom,
shouldAutoNextEpisodeAtom,
shouldSyncAdultAtom,
syncPercentageAtom,
} from '../store';
Expand All @@ -22,6 +23,9 @@ const PlayerSettings = () => {
shouldAskForSyncingAtom
);
const [shouldSyncAdult, setShouldSyncAdult] = useAtom(shouldSyncAdultAtom);
const [shouldAutoNextEpisode, setShouldAutoNextEpisode] = useAtom(
shouldAutoNextEpisodeAtom
);
const syncPercentage = useAtomValue(syncPercentageAtom);

return (
Expand Down Expand Up @@ -56,6 +60,19 @@ const PlayerSettings = () => {

<Switch value={shouldSyncAdult} onValueChange={setShouldSyncAdult} />
</View>
<View className="flex flex-row items-center justify-between">
<View className="w-5/6">
<Text weight="normal">Should auto next episode</Text>
<Text weight="light" className="text-gray-200">
Automatically play the next episode once the video ends
</Text>
</View>

<Switch
value={shouldAutoNextEpisode}
onValueChange={setShouldAutoNextEpisode}
/>
</View>
<View>
<View className="mb-2 w-full">
<Text weight="normal">
Expand Down
12 changes: 6 additions & 6 deletions src/screens/settings/screen.tsx
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
import React from 'react';

import { Text, View } from '@/ui';
import { ScrollView, Text, View } from '@/ui';

import AccountSettings from './components/account-settings';
import AppSettings from './components/app-settings';
import PlayerSettings from './components/player-settings';

const SettingsScreen = () => {
return (
<View className="p-4">
<ScrollView className="px-4 pt-4">
<Text weight="semibold" className="mt-4 text-3xl">
Settings
</Text>

<View className="mt-8 space-y-8">
<View>
<View className="mt-8 mb-16">
<View className="mb-8">
<AppSettings />
</View>

<View>
<View className="mb-8">
<AccountSettings />
</View>

<View>
<PlayerSettings />
</View>
</View>
</View>
</ScrollView>
);
};

Expand Down
5 changes: 5 additions & 0 deletions src/screens/settings/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,8 @@ export const syncPercentageAtom = atomWithMMKV(
'player_settings__sync-percentage',
0.75
);

export const shouldAutoNextEpisodeAtom = atomWithMMKV(
'player_settings__should-auto-next-episode',
true
);
Loading