113cebe63S猫头猫import React from 'react'; 213cebe63S猫头猫import {StyleSheet, View} from 'react-native'; 313cebe63S猫头猫import rpx from '@/utils/rpx'; 413cebe63S猫头猫import {iconSizeConst} from '@/constants/uiConst'; 513cebe63S猫头猫import LyricIcon from '@/assets/icons/lyric.svg'; 613cebe63S猫头猫import TranslationIcon from '@/assets/icons/translation.svg'; 713cebe63S猫头猫import Config from '@/core/config'; 813cebe63S猫头猫import useColors from '@/hooks/useColors'; 913cebe63S猫头猫import LyricManager from '@/core/lyricManager'; 1013cebe63S猫头猫import LyricUtil from '@/native/lyricUtil'; 1113cebe63S猫头猫import Toast from '@/utils/toast'; 1213cebe63S猫头猫import {hidePanel, showPanel} from '@/components/panels/usePanel'; 1313cebe63S猫头猫import TrackPlayer from '@/core/trackPlayer'; 1413cebe63S猫头猫import MediaExtra from '@/core/mediaExtra'; 1513cebe63S猫头猫import PersistStatus from '@/core/persistStatus'; 165b5a8d79S猫头猫import useOrientation from '@/hooks/useOrientation'; 175b5a8d79S猫头猫import HeartIcon from '../heartIcon'; 18*5589cdf3S猫头猫import Icon from '@/components/base/icon.tsx'; 1913cebe63S猫头猫 2013cebe63S猫头猫interface ILyricOperationsProps { 2113cebe63S猫头猫 scrollToCurrentLrcItem: () => void; 2213cebe63S猫头猫} 2313cebe63S猫头猫 2413cebe63S猫头猫export default function LyricOperations(props: ILyricOperationsProps) { 2513cebe63S猫头猫 const {scrollToCurrentLrcItem} = props; 2613cebe63S猫头猫 2713cebe63S猫头猫 const lyricConfig = Config.useConfig('setting.lyric'); 2813cebe63S猫头猫 2913cebe63S猫头猫 const hasTranslation = LyricManager.useLyricState()?.hasTranslation; 3013cebe63S猫头猫 const showTranslation = PersistStatus.useValue( 3113cebe63S猫头猫 'lyric.showTranslation', 3213cebe63S猫头猫 false, 3313cebe63S猫头猫 ); 3413cebe63S猫头猫 const colors = useColors(); 355b5a8d79S猫头猫 const orientation = useOrientation(); 3613cebe63S猫头猫 3713cebe63S猫头猫 return ( 3813cebe63S猫头猫 <View style={styles.container}> 395b5a8d79S猫头猫 {orientation === 'vertical' ? <HeartIcon /> : null} 4013cebe63S猫头猫 <Icon 41*5589cdf3S猫头猫 name="font-size" 4213cebe63S猫头猫 size={iconSizeConst.normal} 4313cebe63S猫头猫 color="white" 4413cebe63S猫头猫 onPress={() => { 4513cebe63S猫头猫 showPanel('SetFontSize', { 4613cebe63S猫头猫 defaultSelect: lyricConfig?.detailFontSize ?? 1, 4713cebe63S猫头猫 onSelectChange(value) { 483a5e0c00S猫头猫 PersistStatus.set('lyric.detailFontSize', value); 4913cebe63S猫头猫 scrollToCurrentLrcItem(); 5013cebe63S猫头猫 }, 5113cebe63S猫头猫 }); 5213cebe63S猫头猫 }} 5313cebe63S猫头猫 /> 5413cebe63S猫头猫 <Icon 55*5589cdf3S猫头猫 name="arrows-left-right" 5613cebe63S猫头猫 size={iconSizeConst.normal} 5713cebe63S猫头猫 color="white" 5813cebe63S猫头猫 onPress={() => { 5913cebe63S猫头猫 const currentMusicItem = TrackPlayer.getCurrentMusic(); 6013cebe63S猫头猫 6113cebe63S猫头猫 if (currentMusicItem) { 6213cebe63S猫头猫 showPanel('SetLyricOffset', { 6313cebe63S猫头猫 musicItem: currentMusicItem, 6413cebe63S猫头猫 onSubmit(offset) { 6513cebe63S猫头猫 MediaExtra.update(currentMusicItem, { 6613cebe63S猫头猫 lyricOffset: offset, 6713cebe63S猫头猫 }); 6813cebe63S猫头猫 LyricManager.refreshLyric(); 6913cebe63S猫头猫 scrollToCurrentLrcItem(); 7013cebe63S猫头猫 hidePanel(); 7113cebe63S猫头猫 }, 7213cebe63S猫头猫 }); 7313cebe63S猫头猫 } 7413cebe63S猫头猫 }} 7513cebe63S猫头猫 /> 7613cebe63S猫头猫 7713cebe63S猫头猫 <Icon 78*5589cdf3S猫头猫 name="magnifying-glass" 7913cebe63S猫头猫 size={iconSizeConst.normal} 8013cebe63S猫头猫 color="white" 8113cebe63S猫头猫 onPress={() => { 8213cebe63S猫头猫 const currentMusic = TrackPlayer.getCurrentMusic(); 8313cebe63S猫头猫 if (!currentMusic) { 8413cebe63S猫头猫 return; 8513cebe63S猫头猫 } 8613cebe63S猫头猫 // if ( 8713cebe63S猫头猫 // Config.get('setting.basic.associateLyricType') === 8813cebe63S猫头猫 // 'input' 8913cebe63S猫头猫 // ) { 9013cebe63S猫头猫 // showPanel('AssociateLrc', { 9113cebe63S猫头猫 // musicItem: currentMusic, 9213cebe63S猫头猫 // }); 9313cebe63S猫头猫 // } else { 9413cebe63S猫头猫 showPanel('SearchLrc', { 9513cebe63S猫头猫 musicItem: currentMusic, 9613cebe63S猫头猫 }); 9713cebe63S猫头猫 // } 9813cebe63S猫头猫 }} 9913cebe63S猫头猫 /> 10013cebe63S猫头猫 <LyricIcon 10113cebe63S猫头猫 onPress={async () => { 10213cebe63S猫头猫 if (!lyricConfig?.showStatusBarLyric) { 10313cebe63S猫头猫 const hasPermission = 10413cebe63S猫头猫 await LyricUtil.checkSystemAlertPermission(); 10513cebe63S猫头猫 10613cebe63S猫头猫 if (hasPermission) { 10713cebe63S猫头猫 LyricUtil.showStatusBarLyric( 10813cebe63S猫头猫 LyricManager.getCurrentLyric()?.lrc ?? 10913cebe63S猫头猫 'MusicFree', 11013cebe63S猫头猫 Config.get('setting.lyric') ?? {}, 11113cebe63S猫头猫 ); 11213cebe63S猫头猫 Config.set( 11313cebe63S猫头猫 'setting.lyric.showStatusBarLyric', 11413cebe63S猫头猫 true, 11513cebe63S猫头猫 ); 11613cebe63S猫头猫 } else { 11713cebe63S猫头猫 LyricUtil.requestSystemAlertPermission().finally( 11813cebe63S猫头猫 () => { 11913cebe63S猫头猫 Toast.warn( 12013cebe63S猫头猫 '开启桌面歌词失败,无悬浮窗权限', 12113cebe63S猫头猫 ); 12213cebe63S猫头猫 }, 12313cebe63S猫头猫 ); 12413cebe63S猫头猫 } 12513cebe63S猫头猫 } else { 12613cebe63S猫头猫 LyricUtil.hideStatusBarLyric(); 12713cebe63S猫头猫 Config.set('setting.lyric.showStatusBarLyric', false); 12813cebe63S猫头猫 } 12913cebe63S猫头猫 }} 13013cebe63S猫头猫 width={iconSizeConst.normal} 13113cebe63S猫头猫 height={iconSizeConst.normal} 13213cebe63S猫头猫 color={ 13313cebe63S猫头猫 lyricConfig?.showStatusBarLyric ? colors.primary : 'white' 13413cebe63S猫头猫 } 13513cebe63S猫头猫 /> 13613cebe63S猫头猫 <TranslationIcon 13713cebe63S猫头猫 width={iconSizeConst.normal} 13813cebe63S猫头猫 height={iconSizeConst.normal} 13913cebe63S猫头猫 opacity={!hasTranslation ? 0.2 : showTranslation ? 1 : 0.5} 14013cebe63S猫头猫 color={ 14113cebe63S猫头猫 showTranslation && hasTranslation ? colors.primary : 'white' 14213cebe63S猫头猫 } 14313cebe63S猫头猫 // style={} 14413cebe63S猫头猫 onPress={() => { 14513cebe63S猫头猫 if (!hasTranslation) { 14613cebe63S猫头猫 Toast.warn('当前歌曲无翻译'); 14713cebe63S猫头猫 return; 14813cebe63S猫头猫 } 14913cebe63S猫头猫 15013cebe63S猫头猫 PersistStatus.set( 15113cebe63S猫头猫 'lyric.showTranslation', 15213cebe63S猫头猫 !showTranslation, 15313cebe63S猫头猫 ); 15413cebe63S猫头猫 scrollToCurrentLrcItem(); 15513cebe63S猫头猫 }} 15613cebe63S猫头猫 /> 15713cebe63S猫头猫 </View> 15813cebe63S猫头猫 ); 15913cebe63S猫头猫} 16013cebe63S猫头猫 16113cebe63S猫头猫const styles = StyleSheet.create({ 16213cebe63S猫头猫 container: { 16313cebe63S猫头猫 height: rpx(80), 16413cebe63S猫头猫 marginBottom: rpx(24), 16513cebe63S猫头猫 width: '100%', 16613cebe63S猫头猫 flexDirection: 'row', 16713cebe63S猫头猫 alignItems: 'center', 16813cebe63S猫头猫 justifyContent: 'space-around', 16913cebe63S猫头猫 }, 17013cebe63S猫头猫}); 171