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

Revert "refactor: global enum" #359

Merged
merged 1 commit into from
Apr 8, 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
26 changes: 11 additions & 15 deletions src/AzusaPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,12 @@ import Playlist from './components/playlist/View';
import PlayerBottomPanel from './components/player/controls/PlayerProgressControls';
import { useNoxSetting } from '@stores/useApp';
import PlaylistDrawer from './components/playlists/View';
import { ViewEnum } from './enums/View';
import Settings from './components/setting/View';
import Explore from './components/explore/View';
import './localization/i18n';
import { useSafeAreaInsets } from 'react-native-safe-area-context';
import { ICONS } from '@enums/Icons';
import NoxBottomTab from './components/bottomtab/NoxBottomTab';

const { LightTheme, DarkTheme } = adaptNavigationTheme({
Expand All @@ -53,12 +55,12 @@ const NoxPlayer = ({ navigation, setNavigation = () => undefined }: Props) => {
<View style={{ flex: 1, justifyContent: 'flex-end' }}>
<Tab.Navigator style={PlayerStyle}>
<Tab.Screen
name={NoxEnum.View.View.PLAYER_COVER}
name={ViewEnum.PLAYER_COVER}
component={Player}
options={{ tabBarStyle: { display: 'none' } }}
/>
<Tab.Screen
name={NoxEnum.View.View.PLAYER_PLAYLIST}
name={ViewEnum.PLAYER_PLAYLIST}
component={Playlist}
options={{ tabBarStyle: { display: 'none' } }}
/>
Expand Down Expand Up @@ -111,36 +113,30 @@ const AzusaPlayer = () => {
}}
>
<Drawer.Navigator
initialRouteName={NoxEnum.View.View.PLAYER_HOME}
initialRouteName={ViewEnum.PLAYER_HOME}
drawerContent={PlaylistDrawer}
>
<Drawer.Screen
name={NoxEnum.View.View.PLAYER_HOME}
name={ViewEnum.PLAYER_HOME}
options={{
drawerIcon: () => (
<IconButton icon={NoxEnum.Icons.ScreenIcons.HomeScreen} />
),
drawerIcon: () => <IconButton icon={ICONS.homeScreen} />,
title: String(t('appDrawer.homeScreenName')),
header: () => null,
}}
component={NoxPlayerWrapper}
/>
<Drawer.Screen
name={NoxEnum.View.View.EXPORE}
name={ViewEnum.EXPORE}
options={{
drawerIcon: () => (
<IconButton icon={NoxEnum.Icons.ScreenIcons.ExploreScreen} />
),
drawerIcon: () => <IconButton icon={ICONS.exploreScreen} />,
title: String(t('appDrawer.exploreScreenName')),
}}
component={Explore}
/>
<Drawer.Screen
name={NoxEnum.View.View.SETTINGS}
name={ViewEnum.SETTINGS}
options={{
drawerIcon: () => (
<IconButton icon={NoxEnum.Icons.ScreenIcons.SettingScreen} />
),
drawerIcon: () => <IconButton icon={ICONS.settingScreen} />,
title: String(t('appDrawer.settingScreenName')),
header: () => null,
}}
Expand Down
7 changes: 4 additions & 3 deletions src/components/bottomtab/NoxBottomTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { IconButton } from 'react-native-paper';
import { useNavigation } from '@react-navigation/native';
import { getDrawerStatusFromState } from '@react-navigation/drawer';

import { ViewEnum } from '@enums/View';
import { useNoxSetting } from '@stores/useApp';

interface IconProps {
Expand Down Expand Up @@ -68,21 +69,21 @@ const NoxAndroidBottomTab = ({ navigation }: NoxComponent.NavigationProps2) => {
<BottomIconButton
icon={renderIcon(Routes.music)}
onPress={() => {
navigationGlobal.navigate(NoxEnum.View.View.PLAYER_HOME as never);
navigationGlobal.navigate(ViewEnum.PLAYER_HOME as never);
setRoute(Routes.music);
}}
/>
<BottomIconButton
icon={renderIcon(Routes.explore)}
onPress={() => {
navigationGlobal.navigate(NoxEnum.View.View.EXPORE as never);
navigationGlobal.navigate(ViewEnum.EXPORE as never);
setRoute(Routes.explore);
}}
/>
<BottomIconButton
icon={renderIcon(Routes.setting)}
onPress={() => {
navigationGlobal.navigate(NoxEnum.View.View.SETTINGS as never);
navigationGlobal.navigate(ViewEnum.SETTINGS as never);
setRoute(Routes.setting);
}}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/components/dialogs/CopiedPlaylistDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { useTranslation } from 'react-i18next';
import { useNoxSetting } from '@stores/useApp';
import logger from '@utils/Logger';
import noxPlayingList from '@stores/playingList';
import { NoxRepeatMode } from '@enums/RepeatMode';

const { getState } = noxPlayingList;

Expand Down Expand Up @@ -49,15 +50,15 @@ export default ({

const playlistList = () => {
const filteredPlaylists =
getState().playmode === NoxEnum.RNTP.NoxRepeatMode.SUGGEST
getState().playmode === NoxRepeatMode.SUGGEST
? playlistIds
: playlistIds.filter(val => val !== fromList.id);
return filteredPlaylists.map(val => [val, playlists[val].title]);
};

React.useEffect(() => {
// TODO: this is not scrolling?
if (visible && getState().playmode === NoxEnum.RNTP.NoxRepeatMode.SUGGEST) {
if (visible && getState().playmode === NoxRepeatMode.SUGGEST) {
playlistRef.current?.scrollToIndex({
index: playlistIds.indexOf(fromList.id),
});
Expand Down
5 changes: 2 additions & 3 deletions src/components/explore/bilibili/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import { fetchRanking } from '@utils/mediafetch/biliRanking';
import { styles } from '@components/style';
import { useNoxSetting } from '@stores/useApp';
import usePlayback from '@hooks/usePlayback';
import { ViewEnum } from '@enums/View';

interface BiliCatSongs {
[key: number]: NoxMedia.Song[];
Expand Down Expand Up @@ -55,9 +56,7 @@ const BiliSongCard = ({
<TouchableOpacity
style={{ height: 70, flexDirection: 'row' }}
onPress={() => {
navigationGlobal.navigate(
NoxEnum.View.View.PLAYER_PLAYLIST as never
);
navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never);
playAsSearchList({ songs, song: item });
}}
>
Expand Down
30 changes: 13 additions & 17 deletions src/components/landscape/LandscapeActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ import { Linking, StyleSheet, View } from 'react-native';
import { IconButton } from 'react-native-paper';
import { useNavigation } from '@react-navigation/native';

import { ICONS } from '@enums/Icons';
import RandomGIFButton from '../buttons/RandomGIF';
import { useNoxSetting } from '@stores/useApp';
import { ViewEnum } from '@enums/View';
import { logger } from '@utils/Logger';

interface Props {
Expand All @@ -19,17 +21,17 @@ export default ({ panelWidth = 110 }: Props) => {
const onPlaylistPress = () => {
navigationGlobal.navigate(
navigationGlobal.getState()?.routes?.at(-1)?.name ===
NoxEnum.View.View.PLAYER_PLAYLIST
? (NoxEnum.View.View.PLAYER_PLAYLISTS as never)
: (NoxEnum.View.View.PLAYER_PLAYLIST as never)
ViewEnum.PLAYER_PLAYLIST
? (ViewEnum.PLAYER_PLAYLISTS as never)
: (ViewEnum.PLAYER_PLAYLIST as never)
);
};

useEffect(() => {
function deepLinkHandler(data: { url: string }) {
if (data.url === 'trackplayer://notification.click') {
logger.debug('[Drawer] click from notification; navigate to home');
navigationGlobal.navigate(NoxEnum.View.View.PLAYER_HOME as never);
navigationGlobal.navigate(ViewEnum.PLAYER_HOME as never);
}
}
// This event will be fired when the app is already open and the notification is clicked
Expand Down Expand Up @@ -60,30 +62,24 @@ export default ({ panelWidth = 110 }: Props) => {
/>
</View>
<IconButton
icon={NoxEnum.Icons.ScreenIcons.HomeScreen}
icon={ICONS.homeScreen}
size={iconSize}
onPress={() =>
navigationGlobal.navigate(NoxEnum.View.View.LYRICS as never)
}
onPress={() => navigationGlobal.navigate(ViewEnum.LYRICS as never)}
/>
<IconButton
icon={NoxEnum.Icons.ScreenIcons.PlaylistScreen}
icon={ICONS.playlistScreen}
size={iconSize}
onPress={onPlaylistPress}
/>
<IconButton
icon={NoxEnum.Icons.ScreenIcons.ExploreScreen}
icon={ICONS.exploreScreen}
size={iconSize}
onPress={() =>
navigationGlobal.navigate(NoxEnum.View.View.EXPORE as never)
}
onPress={() => navigationGlobal.navigate(ViewEnum.EXPORE as never)}
/>
<IconButton
icon={NoxEnum.Icons.ScreenIcons.SettingScreen}
icon={ICONS.settingScreen}
size={iconSize}
onPress={() =>
navigationGlobal.navigate(NoxEnum.View.View.SETTINGS as never)
}
onPress={() => navigationGlobal.navigate(ViewEnum.SETTINGS as never)}
/>
</View>
);
Expand Down
11 changes: 6 additions & 5 deletions src/components/landscape/LandscapePlaylistPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createNativeStackNavigator } from '@react-navigation/native-stack';
import { Dimensions, View } from 'react-native';

import { ViewEnum } from '@enums/View';
import DummySettings from '../setting/DummySettings';
import LandscapeLyricView from './LandscapeLyric';
import { SettingsLandscape as Settings } from '../setting/View';
Expand All @@ -25,27 +26,27 @@ export default ({ panelWidth }: Props) => {
<View style={panelStyle}>
<Stack.Navigator>
<Stack.Screen
name={NoxEnum.View.View.LYRICS}
name={ViewEnum.LYRICS}
component={WrappedLyricView}
options={{ headerShown: false }}
/>
<Stack.Screen
name={NoxEnum.View.View.PLAYER_PLAYLIST}
name={ViewEnum.PLAYER_PLAYLIST}
component={Playlist}
options={{ headerShown: false }}
/>
<Stack.Screen
name={NoxEnum.View.View.PLAYER_PLAYLISTS}
name={ViewEnum.PLAYER_PLAYLISTS}
component={Playlists}
options={{ headerShown: false }}
/>
<Stack.Screen
name={NoxEnum.View.View.EXPORE}
name={ViewEnum.EXPORE}
component={DummySettings}
options={{ headerShown: false }}
/>
<Stack.Screen
name={NoxEnum.View.View.SETTINGS}
name={ViewEnum.SETTINGS}
component={Settings}
options={{ headerShown: false }}
/>
Expand Down
5 changes: 2 additions & 3 deletions src/components/player/PlayerTopInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { View, StyleSheet } from 'react-native';
import { IconButton } from 'react-native-paper';
import { useNavigation } from '@react-navigation/native';
import { ViewEnum } from '@enums/View';
import { useNoxSetting } from '@stores/useApp';
import RandomGIFButton from '../buttons/RandomGIF';

Expand Down Expand Up @@ -30,9 +31,7 @@ export default ({ navigation }: NoxComponent.NavigationProps) => {
<IconButton
icon="playlist-music"
onPress={() =>
navigationGlobal.navigate(
NoxEnum.View.View.PLAYER_PLAYLIST as never
)
navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never)
}
size={40}
/>
Expand Down
5 changes: 3 additions & 2 deletions src/components/player/controls/usePlayerControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { saveLastPlayDuration } from '@utils/ChromeStorage';
import { logger } from '@utils/Logger';
import appStore, { getABRepeatRaw, setCurrentPlaying } from '@stores/appStore';
import noxPlayingList from '@stores/playingList';
import { NoxRepeatMode } from '@enums/RepeatMode';
import { fadePlay } from '@utils/RNTPUtils';
import usePlaylistCRUD from '@hooks/usePlaylistCRUD';

Expand Down Expand Up @@ -50,7 +51,7 @@ export default () => {
event.position >
Math.min(bRepeatDuration, event.duration) - fadeIntervalSec
) {
if (getState().playmode !== NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) {
if (getState().playmode !== NoxRepeatMode.REPEAT_TRACK) {
logger.debug(
`[FADEOUT] fading out....${event.position} / ${event.duration}`
);
Expand All @@ -62,7 +63,7 @@ export default () => {
}
if (abRepeat[1] === 1) return;
if (event.position > bRepeatDuration) {
if (getState().playmode === NoxEnum.RNTP.NoxRepeatMode.REPEAT_TRACK) {
if (getState().playmode === NoxRepeatMode.REPEAT_TRACK) {
TrackPlayer.seekTo(abRepeat[0] * event.duration);
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/components/playlist/BiliSearch/BiliSearchbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { useTranslation } from 'react-i18next';
import ShareMenu, { ShareCallback } from 'react-native-share-menu';
import { useNavigation } from '@react-navigation/native';

import { ViewEnum } from '@enums/View';
import { useNoxSetting } from '@stores/useApp';
import usePlayback from '@hooks/usePlayback';
import useBiliSearch from '@hooks/useBiliSearch';
Expand Down Expand Up @@ -69,7 +70,7 @@ export default ({
};

const handleExternalSearch = (data: string) => {
navigationGlobal.navigate(NoxEnum.View.View.PLAYER_PLAYLIST as never);
navigationGlobal.navigate(ViewEnum.PLAYER_PLAYLIST as never);
return handleSearch(data);
};

Expand Down
5 changes: 3 additions & 2 deletions src/components/playlist/BiliSearch/Icons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as React from 'react';
import Svg, { Path } from 'react-native-svg';
import { Image } from 'expo-image';
import { StyleSheet } from 'react-native';
import { SEARCH_OPTIONS } from '@enums/Storage';

const ICONS = {
BILIBILI: () => (
Expand Down Expand Up @@ -38,9 +39,9 @@ const ICONS = {

export const getIcon = (icon: string) => {
switch (icon) {
case NoxEnum.Storage.SearchOptions.BILIBILI:
case SEARCH_OPTIONS.BILIBILI:
return ICONS.BILIBILI;
case NoxEnum.Storage.SearchOptions.YOUTUBE:
case SEARCH_OPTIONS.YOUTUBE:
return ICONS.YOUTUBE;
default:
return ICONS.MUSICFREE;
Expand Down
9 changes: 4 additions & 5 deletions src/components/playlist/BiliSearch/SearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import * as DocumentPicker from 'expo-document-picker';
import { Platform, NativeModules, PermissionsAndroid } from 'react-native';
import { useTranslation } from 'react-i18next';

import { SEARCH_OPTIONS } from '@enums/Storage';
import useAlert from '@components/dialogs/useAlert';
import { MUSICFREE } from '@utils/mediafetch/musicfree';
import ICONS from './Icons';
Expand Down Expand Up @@ -31,9 +32,7 @@ export default ({
const { OneWayAlert } = useAlert();
const playerStyle = useNoxSetting(state => state.playerStyle);
const setSearchOption = useNoxSetting(state => state.setSearchOption);
const setDefaultSearch = (
defaultSearch: NoxEnum.Storage.SearchOptions | MUSICFREE
) => {
const setDefaultSearch = (defaultSearch: SEARCH_OPTIONS | MUSICFREE) => {
toggleVisible();
setSearchOption(defaultSearch);
};
Expand Down Expand Up @@ -73,12 +72,12 @@ export default ({
<Menu visible={visible} onDismiss={toggleVisible} anchor={menuCoords}>
<Menu.Item
leadingIcon={ICONS.BILIBILI}
onPress={() => setDefaultSearch(NoxEnum.Storage.SearchOptions.BILIBILI)}
onPress={() => setDefaultSearch(SEARCH_OPTIONS.BILIBILI)}
title={'Bilibili'}
/>
<Menu.Item
leadingIcon={ICONS.YOUTUBE}
onPress={() => setDefaultSearch(NoxEnum.Storage.SearchOptions.YOUTUBE)}
onPress={() => setDefaultSearch(SEARCH_OPTIONS.YOUTUBE)}
title={'Youtube'}
/>
{showMusicFree && (
Expand Down
6 changes: 4 additions & 2 deletions src/components/playlist/Info/PlaylistSearchMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import * as React from 'react';
import { Menu } from 'react-native-paper';
import { useTranslation } from 'react-i18next';

import { SearchRegex } from '@enums/Playlist';

interface Props {
visible?: boolean;
toggleVisible?: () => void;
Expand All @@ -19,10 +21,10 @@ export default ({

return (
<Menu visible={visible} onDismiss={toggleVisible} anchor={menuCoords}>
{Object.keys(NoxEnum.Playlist.SearchRegex).map((entry, index) => (
{Object.keys(SearchRegex).map((entry, index) => (
<Menu.Item
onPress={() => {
setSearchCategory(NoxEnum.Playlist.SearchRegex[entry]?.text);
setSearchCategory(SearchRegex[entry]?.text);
toggleVisible();
}}
title={String(t(`PlaylistRegex.${entry}`))}
Expand Down
Loading
Loading