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

fix: abrepeat #618

Merged
merged 5 commits into from
Oct 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ package com.noxplay.noxplayer

import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.Context
import android.content.Intent
import android.net.Uri
import android.util.Log
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.ReactContextBaseJavaModule
import com.facebook.react.bridge.ReactMethod
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import org.apache.tools.ant.taskdefs.condition.Os
buildscript {
ext {
minSdkVersion = 24
compileSdkVersion = 34
compileSdkVersion = 35
targetSdkVersion = 34

// We use NDK 23 which has both M1 support and is the side-by-side NDK version from AGP.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,24 @@ import { ActivityIndicator, Text } from 'react-native-paper';
import { useTranslation } from 'react-i18next';

import { styles } from '@components/style';
import { BiliSongsTabCard, BiliSongsArrayTabCard } from '../SongTab';
import { BiliSongRow } from '../SongRow';
import { UseBiliExplore } from './useBiliExplore';
import { BiliSongsTabCard, BiliSongsArrayTabCard } from './SongTab';
import { BiliSongRow } from './SongRow';
import useBiliExplore from '@stores/explore/bilibili';

interface Props {
useBiliExplore: UseBiliExplore;
style?: ViewStyle;
}
export default ({ style, useBiliExplore }: Props) => {
export default ({ style }: Props) => {
const { t } = useTranslation();
const {
loading,
refreshing,
onRefresh,
biliDynamic,
biliRanking,
biliMusicTop,
biliMusicHot,
biliMusicNew,
init,
} = useBiliExplore;
const loading = useBiliExplore(state => state.loading);
const refreshing = useBiliExplore(state => state.refreshing);
const onRefresh = useBiliExplore(state => state.onRefresh);
const biliDynamic = useBiliExplore(state => state.biliDynamic);
const biliRanking = useBiliExplore(state => state.biliRanking);
const biliMusicTop = useBiliExplore(state => state.biliMusicTop);
const biliMusicHot = useBiliExplore(state => state.biliMusicHot);
const biliMusicNew = useBiliExplore(state => state.biliMusicNew);
const init = useBiliExplore(state => state.init);

useEffect(() => {
init();
Expand Down
12 changes: 4 additions & 8 deletions src/components/explore/View.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,18 @@ import * as React from 'react';
import { StyleSheet } from 'react-native';

import { useNoxSetting } from '@stores/useApp';
import useBiliExplore from './bilibili/useBiliExplore';
import useYTMExplore from './ytmusic/useYTMExplore';
import BiliExplore from './bilibili/View';
import YTMExplore from './ytmusic/View';
import BiliExplore from './Bilibili';
import YTMExplore from './YTMusic';
import SiteSelector from '../login/SiteSelector';
import { Site } from '@enums/Network';
import { useAPM } from '@stores/usePersistStore';

const LoginComponent = ({ loginSite }: { loginSite: Site }) => {
const biliExplore = useBiliExplore();
const ytmExplore = useYTMExplore();
switch (loginSite) {
case Site.YTM:
return <YTMExplore useYTMExplore={ytmExplore} />;
return <YTMExplore />;
default:
return <BiliExplore useBiliExplore={biliExplore} />;
return <BiliExplore />;
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ import {
} from 'libmuse';

import { styles } from '@components/style';
import { UseYTMExplore } from './useYTMExplore';
import { YTSongRow } from '../SongRow';
import useYTMExplore from '@stores/explore/ytm';
import { YTSongRow } from './SongRow';
import { fetchYtmPlaylist } from '@utils/mediafetch/ytbPlaylist.muse';
import { BiliSongsArrayTabCard } from '../SongTab';
import { BiliSongsArrayTabCard } from './SongTab';
import SongTS from '@objects/Song';
import { Source } from '@enums/MediaFetch';

Expand Down Expand Up @@ -120,12 +120,12 @@ const YTMixedContent = ({ content, key }: ContentProps) => {
}
};

interface Props {
useYTMExplore: UseYTMExplore;
}
export default ({ useYTMExplore }: Props) => {
export default () => {
const [activeMood, setActiveMood] = useState('');
const { moods, refreshHome, initialize, contents } = useYTMExplore;
const moods = useYTMExplore(state => state.moods);
const refreshHome = useYTMExplore(state => state.refreshHome);
const initialize = useYTMExplore(state => state.initialize);
const contents = useYTMExplore(state => state.homedata)?.results;

const onClickMood = (mood: string) => {
const newMood = mood === activeMood ? '' : mood;
Expand Down
63 changes: 0 additions & 63 deletions src/components/explore/bilibili/useBiliExplore.tsx

This file was deleted.

43 changes: 0 additions & 43 deletions src/components/explore/ytmusic/useYTMExplore.tsx

This file was deleted.

5 changes: 4 additions & 1 deletion src/components/login/google/YTM.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,13 @@ const styles = StyleSheet.create({
},
avatarContainerStyle: {
flexDirection: 'row',
paddingLeft: 20,
paddingLeft: 10,
paddingVertical: 10,
flex: 0,
flexGrow: 0,
},
avatarUsernameStyle: {
paddingLeft: 10,
flex: 1,
},
});
2 changes: 1 addition & 1 deletion src/components/login/google/useYTMLogin.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { get_current_user } from 'libmuse';
import { useEffect, useState } from 'react';
import { useState } from 'react';

export interface User {
channel_id: string;
Expand Down
19 changes: 17 additions & 2 deletions src/components/player/controls/usePlayerControls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export default () => {
});

useTrackPlayerEvents([Event.PlaybackProgressUpdated], async event => {
const playmode = getState().playmode;
const { playmode } = getState();
saveLastPlayDuration(event.position);
const currentSongId = track?.song?.id ?? '';
// prepare for cross fading if enabled, playback is > 50% done and crossfade preparation isnt done
Expand Down Expand Up @@ -137,14 +137,28 @@ export default () => {
});

useTrackPlayerEvents([Event.PlaybackState], async event => {
console.log('[abrepeat] active track changed', event.state);
switch (event.state) {
case State.Loading:
loadingTracker.current = true;
break;
}
if (event.state !== State.Ready) return;
updateCurrentSongMetadata();
const song = (await TrackPlayer.getActiveTrack())?.song as NoxMedia.Song;
const { playmode, currentPlayingId } = getState();
if (!loadingTracker.current || playmode !== NoxRepeatMode.RepeatTrack) {
return;
}
const newABRepeat = getABRepeatRaw(currentPlayingId);
if (newABRepeat[0] === 0) return;
loadingTracker.current = false;
const trackDuration = (await TrackPlayer.getProgress()).duration;
TrackPlayer.seekTo(trackDuration * newABRepeat[0]);
});

useTrackPlayerEvents([Event.PlaybackActiveTrackChanged], async event => {
const song = event.track?.song as NoxMedia.Song;
console.log('[abrepeat] active track changed', song);
const newABRepeat = getABRepeatRaw(song.id);
logger.debug(`[SongReady] logging ABRepeat as ${newABRepeat}`);
setABRepeat(newABRepeat);
Expand All @@ -154,6 +168,7 @@ export default () => {
setBRepeatDuration(newABRepeat[1] * trackDuration);
if (newABRepeat[0] === 0) return;
TrackPlayer.seekTo(trackDuration * newABRepeat[0]);
console.log('[abrepeat] initialized');
});

return {
Expand Down
47 changes: 47 additions & 0 deletions src/stores/explore/bilibili.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { create } from 'zustand';

import { fetchDynamic } from '@utils/mediafetch/biliDynamic';
import { fetchRanking } from '@utils/mediafetch/biliRanking';
import { fetchCurrentMusicTop } from '@utils/mediafetch/biliMusicTop';
import { fetchMusicHot } from '@utils/mediafetch/biliMusicHot';
import { fetchMusicNew } from '@utils/mediafetch/biliMusicNew';
import { BiliCatSongs } from '@components/explore/SongTab';

interface BiliExplore {
biliDynamic: BiliCatSongs;
biliRanking: BiliCatSongs;
biliMusicTop: NoxMedia.Song[];
biliMusicHot: NoxMedia.Song[];
biliMusicNew: NoxMedia.Song[];
refreshing: boolean;
loading: boolean;
onRefresh: () => void;
init: () => void;
}

export default create<BiliExplore>((set, get) => ({
biliDynamic: {},
biliRanking: {},
biliMusicTop: [],
biliMusicHot: [],
biliMusicNew: [],
refreshing: false,
loading: true,
onRefresh: async () => {
set({ refreshing: true });
set({ biliDynamic: await fetchDynamic(), refreshing: false });
},
init: async () => {
if (!get().loading) {
return;
}
set({
loading: false,
biliRanking: await fetchRanking(),
biliDynamic: await fetchDynamic(),
biliMusicTop: await fetchCurrentMusicTop(),
biliMusicHot: await fetchMusicHot(),
biliMusicNew: await fetchMusicNew(),
});
},
}));
37 changes: 37 additions & 0 deletions src/stores/explore/ytm.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// a store version of hook. with this, we can use explore w/ android auto
import { get_home, Home, Mood } from 'libmuse';
import { create } from 'zustand';

interface YTMExplore {
homedata?: Home;
moods: Mood[];
continuation?: Home['continuation'];
refreshHome: (params?: string) => Promise<Home>;
loading: boolean;
initialize: () => Promise<void>;
}

export const useYTMExplore = create<YTMExplore>((set, get) => ({
moods: [],
loading: true,
initialize: async () => {
const { refreshHome, loading } = get();
if (!loading) {
return;
}
const homedata = await refreshHome();
set({
homedata,
moods: homedata.moods,
continuation: homedata.continuation,
loading: false,
});
},
refreshHome: async (params?: string) => {
const homedata = await get_home({ params });
set({ homedata, continuation: homedata.continuation });
return homedata;
},
}));

export default useYTMExplore;
Loading