163c74e8eSmaotoumaoimport React, { useMemo } from "react"; 263c74e8eSmaotoumaoimport { Image, Pressable, StyleSheet, View } from "react-native"; 363c74e8eSmaotoumaoimport rpx from "@/utils/rpx"; 413cebe63S猫头猫 563c74e8eSmaotoumaoimport Download from "@/core/download"; 663c74e8eSmaotoumaoimport LocalMusicSheet from "@/core/localMusicSheet"; 7*b4c389f4Smaotoumaoimport { ROUTE_PATH } from "@/core/router"; 863c74e8eSmaotoumaoimport { ImgAsset } from "@/constants/assetsConst"; 963c74e8eSmaotoumaoimport Toast from "@/utils/toast"; 1063c74e8eSmaotoumaoimport toast from "@/utils/toast"; 1163c74e8eSmaotoumaoimport useOrientation from "@/hooks/useOrientation"; 1263c74e8eSmaotoumaoimport { showPanel } from "@/components/panels/usePanel"; 1363c74e8eSmaotoumaoimport TrackPlayer from "@/core/trackPlayer"; 1463c74e8eSmaotoumaoimport { iconSizeConst } from "@/constants/uiConst"; 15819a9075Smaotoumaoimport PersistStatus from "@/core/persistStatus.ts"; 1663c74e8eSmaotoumaoimport HeartIcon from "../heartIcon"; 1763c74e8eSmaotoumaoimport Icon from "@/components/base/icon.tsx"; 1863c74e8eSmaotoumaoimport PluginManager from "@/core/pluginManager.ts"; 1913cebe63S猫头猫 2013cebe63S猫头猫export default function Operations() { 2113cebe63S猫头猫 //briefcase-download-outline briefcase-check-outline checkbox-marked-circle-outline 2213cebe63S猫头猫 const musicItem = TrackPlayer.useCurrentMusic(); 2313cebe63S猫头猫 const currentQuality = TrackPlayer.useCurrentQuality(); 2413cebe63S猫头猫 const isDownloaded = LocalMusicSheet.useIsLocal(musicItem); 2513cebe63S猫头猫 26819a9075Smaotoumao const rate = PersistStatus.useValue('music.rate', 100); 2713cebe63S猫头猫 const orientation = useOrientation(); 2813cebe63S猫头猫 29da2a2959S猫头猫 const supportComment = useMemo(() => { 30da2a2959S猫头猫 return !musicItem 31da2a2959S猫头猫 ? false 32da2a2959S猫头猫 : !!PluginManager.getByMedia(musicItem)?.instance?.getMusicComments; 33da2a2959S猫头猫 }, [musicItem]); 34da2a2959S猫头猫 3513cebe63S猫头猫 return ( 3613cebe63S猫头猫 <View 3713cebe63S猫头猫 style={[ 38da2a2959S猫头猫 styles.wrapper, 39ab5f994aSmaotoumao orientation === 'horizontal' ? styles.horizontalWrapper : null, 4013cebe63S猫头猫 ]}> 415b5a8d79S猫头猫 <HeartIcon /> 4213cebe63S猫头猫 <Pressable 4313cebe63S猫头猫 onPress={() => { 4413cebe63S猫头猫 if (!musicItem) { 4513cebe63S猫头猫 return; 4613cebe63S猫头猫 } 4713cebe63S猫头猫 showPanel('MusicQuality', { 4813cebe63S猫头猫 musicItem, 4913cebe63S猫头猫 async onQualityPress(quality) { 5013cebe63S猫头猫 const changeResult = 5113cebe63S猫头猫 await TrackPlayer.changeQuality(quality); 5213cebe63S猫头猫 if (!changeResult) { 5313cebe63S猫头猫 Toast.warn('当前暂无此音质音乐'); 5413cebe63S猫头猫 } 5513cebe63S猫头猫 }, 5613cebe63S猫头猫 }); 5713cebe63S猫头猫 }}> 5813cebe63S猫头猫 <Image 5913cebe63S猫头猫 source={ImgAsset.quality[currentQuality]} 60da2a2959S猫头猫 style={styles.quality} 6113cebe63S猫头猫 /> 6213cebe63S猫头猫 </Pressable> 6313cebe63S猫头猫 <Icon 645589cdf3S猫头猫 name={isDownloaded ? 'check-circle-outline' : 'arrow-down-tray'} 6513cebe63S猫头猫 size={iconSizeConst.normal} 6613cebe63S猫头猫 color="white" 6713cebe63S猫头猫 onPress={() => { 6813cebe63S猫头猫 if (musicItem && !isDownloaded) { 6913cebe63S猫头猫 showPanel('MusicQuality', { 70756bc302S猫头猫 type: 'download', 7113cebe63S猫头猫 musicItem, 7213cebe63S猫头猫 async onQualityPress(quality) { 7313cebe63S猫头猫 Download.downloadMusic(musicItem, quality); 7413cebe63S猫头猫 }, 7513cebe63S猫头猫 }); 7613cebe63S猫头猫 } 7713cebe63S猫头猫 }} 7813cebe63S猫头猫 /> 7913cebe63S猫头猫 <Pressable 8013cebe63S猫头猫 onPress={() => { 8113cebe63S猫头猫 if (!musicItem) { 8213cebe63S猫头猫 return; 8313cebe63S猫头猫 } 8413cebe63S猫头猫 showPanel('PlayRate', { 8513cebe63S猫头猫 async onRatePress(newRate) { 8613cebe63S猫头猫 if (rate !== newRate) { 8713cebe63S猫头猫 try { 8813cebe63S猫头猫 await TrackPlayer.setRate(newRate / 100); 89819a9075Smaotoumao PersistStatus.set('music.rate', newRate); 9013cebe63S猫头猫 } catch {} 9113cebe63S猫头猫 } 9213cebe63S猫头猫 }, 9313cebe63S猫头猫 }); 9413cebe63S猫头猫 }}> 95da2a2959S猫头猫 <Image source={ImgAsset.rate[rate!]} style={styles.quality} /> 9613cebe63S猫头猫 </Pressable> 9713cebe63S猫头猫 <Icon 98da2a2959S猫头猫 name="chat-bubble-oval-left-ellipsis" 99da2a2959S猫头猫 size={iconSizeConst.normal} 100da2a2959S猫头猫 color="white" 101a12c1865S猫头猫 opacity={supportComment ? 1 : 0.2} 102da2a2959S猫头猫 onPress={() => { 103da2a2959S猫头猫 if (!supportComment) { 104a12c1865S猫头猫 toast.warn('当前歌曲暂无评论'); 105da2a2959S猫头猫 return; 106da2a2959S猫头猫 } 107da2a2959S猫头猫 if (musicItem) { 108da2a2959S猫头猫 showPanel('MusicComment', { 109da2a2959S猫头猫 musicItem, 110da2a2959S猫头猫 }); 111da2a2959S猫头猫 } 112da2a2959S猫头猫 }} 113da2a2959S猫头猫 /> 114da2a2959S猫头猫 <Icon 1155589cdf3S猫头猫 name="ellipsis-vertical" 11613cebe63S猫头猫 size={iconSizeConst.normal} 11713cebe63S猫头猫 color="white" 11813cebe63S猫头猫 onPress={() => { 11913cebe63S猫头猫 if (musicItem) { 12013cebe63S猫头猫 showPanel('MusicItemOptions', { 12113cebe63S猫头猫 musicItem: musicItem, 12213cebe63S猫头猫 from: ROUTE_PATH.MUSIC_DETAIL, 12313cebe63S猫头猫 }); 12413cebe63S猫头猫 } 12513cebe63S猫头猫 }} 12613cebe63S猫头猫 /> 12713cebe63S猫头猫 </View> 12813cebe63S猫头猫 ); 12913cebe63S猫头猫} 13013cebe63S猫头猫 131da2a2959S猫头猫const styles = StyleSheet.create({ 13213cebe63S猫头猫 wrapper: { 13313cebe63S猫头猫 width: '100%', 13413cebe63S猫头猫 height: rpx(80), 13513cebe63S猫头猫 marginBottom: rpx(24), 13613cebe63S猫头猫 flexDirection: 'row', 13713cebe63S猫头猫 alignItems: 'center', 13813cebe63S猫头猫 justifyContent: 'space-around', 13913cebe63S猫头猫 }, 140da2a2959S猫头猫 horizontalWrapper: { 141da2a2959S猫头猫 marginBottom: 0, 142da2a2959S猫头猫 }, 14313cebe63S猫头猫 quality: { 14413cebe63S猫头猫 width: rpx(52), 14513cebe63S猫头猫 height: rpx(52), 14613cebe63S猫头猫 }, 14713cebe63S猫头猫}); 148