1*13cebe63S猫头猫import React from 'react'; 2*13cebe63S猫头猫import {Image, Pressable, StyleSheet, View} from 'react-native'; 3*13cebe63S猫头猫import rpx from '@/utils/rpx'; 4*13cebe63S猫头猫import Icon from 'react-native-vector-icons/MaterialCommunityIcons'; 5*13cebe63S猫头猫import MusicSheet from '@/core/musicSheet'; 6*13cebe63S猫头猫 7*13cebe63S猫头猫import Download from '@/core/download'; 8*13cebe63S猫头猫import {isSameMediaItem} from '@/utils/mediaItem'; 9*13cebe63S猫头猫import LocalMusicSheet from '@/core/localMusicSheet'; 10*13cebe63S猫头猫import {ROUTE_PATH} from '@/entry/router'; 11*13cebe63S猫头猫import {ImgAsset} from '@/constants/assetsConst'; 12*13cebe63S猫头猫import Toast from '@/utils/toast'; 13*13cebe63S猫头猫import useOrientation from '@/hooks/useOrientation'; 14*13cebe63S猫头猫import {showPanel} from '@/components/panels/usePanel'; 15*13cebe63S猫头猫import TrackPlayer from '@/core/trackPlayer'; 16*13cebe63S猫头猫import {iconSizeConst} from '@/constants/uiConst'; 17*13cebe63S猫头猫import PersistStatus from '@/core/persistStatus'; 18*13cebe63S猫头猫 19*13cebe63S猫头猫export default function Operations() { 20*13cebe63S猫头猫 //briefcase-download-outline briefcase-check-outline checkbox-marked-circle-outline 21*13cebe63S猫头猫 const favoriteMusicSheet = MusicSheet.useSheets('favorite'); 22*13cebe63S猫头猫 const musicItem = TrackPlayer.useCurrentMusic(); 23*13cebe63S猫头猫 const currentQuality = TrackPlayer.useCurrentQuality(); 24*13cebe63S猫头猫 const isDownloaded = LocalMusicSheet.useIsLocal(musicItem); 25*13cebe63S猫头猫 26*13cebe63S猫头猫 const rate = PersistStatus.useValue('music.rate', 100); 27*13cebe63S猫头猫 const orientation = useOrientation(); 28*13cebe63S猫头猫 29*13cebe63S猫头猫 const musicIndexInFav = 30*13cebe63S猫头猫 favoriteMusicSheet?.musicList.findIndex(_ => 31*13cebe63S猫头猫 isSameMediaItem(_, musicItem), 32*13cebe63S猫头猫 ) ?? -1; 33*13cebe63S猫头猫 34*13cebe63S猫头猫 return ( 35*13cebe63S猫头猫 <View 36*13cebe63S猫头猫 style={[ 37*13cebe63S猫头猫 style.wrapper, 38*13cebe63S猫头猫 orientation === 'horizonal' 39*13cebe63S猫头猫 ? { 40*13cebe63S猫头猫 marginBottom: 0, 41*13cebe63S猫头猫 } 42*13cebe63S猫头猫 : null, 43*13cebe63S猫头猫 ]}> 44*13cebe63S猫头猫 {musicIndexInFav !== -1 ? ( 45*13cebe63S猫头猫 <Icon 46*13cebe63S猫头猫 name="heart" 47*13cebe63S猫头猫 size={iconSizeConst.normal} 48*13cebe63S猫头猫 color="red" 49*13cebe63S猫头猫 onPress={() => { 50*13cebe63S猫头猫 MusicSheet.removeMusicByIndex( 51*13cebe63S猫头猫 'favorite', 52*13cebe63S猫头猫 musicIndexInFav, 53*13cebe63S猫头猫 ); 54*13cebe63S猫头猫 }} 55*13cebe63S猫头猫 /> 56*13cebe63S猫头猫 ) : ( 57*13cebe63S猫头猫 <Icon 58*13cebe63S猫头猫 name="heart-outline" 59*13cebe63S猫头猫 size={iconSizeConst.normal} 60*13cebe63S猫头猫 color="white" 61*13cebe63S猫头猫 onPress={() => { 62*13cebe63S猫头猫 if (musicItem) { 63*13cebe63S猫头猫 MusicSheet.addMusic('favorite', musicItem); 64*13cebe63S猫头猫 } 65*13cebe63S猫头猫 }} 66*13cebe63S猫头猫 /> 67*13cebe63S猫头猫 )} 68*13cebe63S猫头猫 <Pressable 69*13cebe63S猫头猫 onPress={() => { 70*13cebe63S猫头猫 if (!musicItem) { 71*13cebe63S猫头猫 return; 72*13cebe63S猫头猫 } 73*13cebe63S猫头猫 showPanel('MusicQuality', { 74*13cebe63S猫头猫 musicItem, 75*13cebe63S猫头猫 async onQualityPress(quality) { 76*13cebe63S猫头猫 const changeResult = 77*13cebe63S猫头猫 await TrackPlayer.changeQuality(quality); 78*13cebe63S猫头猫 if (!changeResult) { 79*13cebe63S猫头猫 Toast.warn('当前暂无此音质音乐'); 80*13cebe63S猫头猫 } 81*13cebe63S猫头猫 }, 82*13cebe63S猫头猫 }); 83*13cebe63S猫头猫 }}> 84*13cebe63S猫头猫 <Image 85*13cebe63S猫头猫 source={ImgAsset.quality[currentQuality]} 86*13cebe63S猫头猫 style={style.quality} 87*13cebe63S猫头猫 /> 88*13cebe63S猫头猫 </Pressable> 89*13cebe63S猫头猫 <Icon 90*13cebe63S猫头猫 name={isDownloaded ? 'check-circle-outline' : 'download'} 91*13cebe63S猫头猫 size={iconSizeConst.normal} 92*13cebe63S猫头猫 color="white" 93*13cebe63S猫头猫 onPress={() => { 94*13cebe63S猫头猫 if (musicItem && !isDownloaded) { 95*13cebe63S猫头猫 showPanel('MusicQuality', { 96*13cebe63S猫头猫 musicItem, 97*13cebe63S猫头猫 async onQualityPress(quality) { 98*13cebe63S猫头猫 Download.downloadMusic(musicItem, quality); 99*13cebe63S猫头猫 }, 100*13cebe63S猫头猫 }); 101*13cebe63S猫头猫 } 102*13cebe63S猫头猫 }} 103*13cebe63S猫头猫 /> 104*13cebe63S猫头猫 <Pressable 105*13cebe63S猫头猫 onPress={() => { 106*13cebe63S猫头猫 if (!musicItem) { 107*13cebe63S猫头猫 return; 108*13cebe63S猫头猫 } 109*13cebe63S猫头猫 showPanel('PlayRate', { 110*13cebe63S猫头猫 async onRatePress(newRate) { 111*13cebe63S猫头猫 if (rate !== newRate) { 112*13cebe63S猫头猫 try { 113*13cebe63S猫头猫 await TrackPlayer.setRate(newRate / 100); 114*13cebe63S猫头猫 PersistStatus.set('music.rate', newRate); 115*13cebe63S猫头猫 } catch {} 116*13cebe63S猫头猫 } 117*13cebe63S猫头猫 }, 118*13cebe63S猫头猫 }); 119*13cebe63S猫头猫 }}> 120*13cebe63S猫头猫 <Image source={ImgAsset.rate[rate!]} style={style.quality} /> 121*13cebe63S猫头猫 </Pressable> 122*13cebe63S猫头猫 <Icon 123*13cebe63S猫头猫 name="dots-vertical" 124*13cebe63S猫头猫 size={iconSizeConst.normal} 125*13cebe63S猫头猫 color="white" 126*13cebe63S猫头猫 onPress={() => { 127*13cebe63S猫头猫 if (musicItem) { 128*13cebe63S猫头猫 showPanel('MusicItemOptions', { 129*13cebe63S猫头猫 musicItem: musicItem, 130*13cebe63S猫头猫 from: ROUTE_PATH.MUSIC_DETAIL, 131*13cebe63S猫头猫 }); 132*13cebe63S猫头猫 } 133*13cebe63S猫头猫 }} 134*13cebe63S猫头猫 /> 135*13cebe63S猫头猫 </View> 136*13cebe63S猫头猫 ); 137*13cebe63S猫头猫} 138*13cebe63S猫头猫 139*13cebe63S猫头猫const style = StyleSheet.create({ 140*13cebe63S猫头猫 wrapper: { 141*13cebe63S猫头猫 width: '100%', 142*13cebe63S猫头猫 height: rpx(80), 143*13cebe63S猫头猫 marginBottom: rpx(24), 144*13cebe63S猫头猫 flexDirection: 'row', 145*13cebe63S猫头猫 alignItems: 'center', 146*13cebe63S猫头猫 justifyContent: 'space-around', 147*13cebe63S猫头猫 }, 148*13cebe63S猫头猫 quality: { 149*13cebe63S猫头猫 width: rpx(52), 150*13cebe63S猫头猫 height: rpx(52), 151*13cebe63S猫头猫 }, 152*13cebe63S猫头猫}); 153