mirror of
https://github.com/ikun0014/lx-music-mobile.git
synced 2025-05-23 22:37:41 +08:00
fix bug
This commit is contained in:
parent
c5c780b95b
commit
e25aaa0370
@ -9,6 +9,7 @@ import MusicDownloadModal, { type MusicDownloadModalType } from '@/screens/Home/
|
|||||||
import MultipleModeBar, { type MultipleModeBarType, type SelectMode } from './MultipleModeBar'
|
import MultipleModeBar, { type MultipleModeBarType, type SelectMode } from './MultipleModeBar'
|
||||||
import { handleDislikeMusic, handlePlay, handlePlayLater, handleShare } from './listAction'
|
import { handleDislikeMusic, handlePlay, handlePlayLater, handleShare } from './listAction'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
|
import { handelDownload } from '@/screens/Home/Views/Mylist/MusicList/listAction'
|
||||||
|
|
||||||
export interface OnlineListProps {
|
export interface OnlineListProps {
|
||||||
onRefresh: ListProps['onRefresh']
|
onRefresh: ListProps['onRefresh']
|
||||||
@ -105,13 +106,15 @@ export default forwardRef<OnlineListType, OnlineListProps>(({
|
|||||||
</View>
|
</View>
|
||||||
<ListMusicAdd ref={listMusicAddRef} onAdded={() => { hancelExitSelect() }} />
|
<ListMusicAdd ref={listMusicAddRef} onAdded={() => { hancelExitSelect() }} />
|
||||||
<ListMusicMultiAdd ref={listMusicMultiAddRef} onAdded={() => { hancelExitSelect() }} />
|
<ListMusicMultiAdd ref={listMusicMultiAddRef} onAdded={() => { hancelExitSelect() }} />
|
||||||
|
<MusicDownloadModal ref={musicDownloadModalRef}
|
||||||
|
onDownloadInfo={(info) => { handelDownload(info.musicInfo, "128k") }} />
|
||||||
<ListMenu
|
<ListMenu
|
||||||
ref={listMenuRef}
|
ref={listMenuRef}
|
||||||
onPlay={info => { handlePlay(info.musicInfo) }}
|
onPlay={info => { handlePlay(info.musicInfo) }}
|
||||||
onPlayLater={info => { hancelExitSelect(); handlePlayLater(info.musicInfo, info.selectedList, hancelExitSelect) }}
|
onPlayLater={info => { hancelExitSelect(); handlePlayLater(info.musicInfo, info.selectedList, hancelExitSelect) }}
|
||||||
onCopyName={info => { handleShare(info.musicInfo) }}
|
onCopyName={info => { handleShare(info.musicInfo) }}
|
||||||
onAdd={handleAddMusic}
|
onAdd={handleAddMusic}
|
||||||
onDownload={info => { handleShare(info.musicInfo) }}
|
onDownload={info => musicDownloadModalRef.current?.show(info)}
|
||||||
onDislikeMusic={info => { void handleDislikeMusic(info.musicInfo) }}
|
onDislikeMusic={info => { void handleDislikeMusic(info.musicInfo) }}
|
||||||
/>
|
/>
|
||||||
{/* <LoadingMask ref={loadingMaskRef} /> */}
|
{/* <LoadingMask ref={loadingMaskRef} /> */}
|
||||||
|
@ -211,7 +211,7 @@ export const getOnlineOtherSourcePicByLocal = async(musicInfo: LX.Music.MusicInf
|
|||||||
export const getPlayQuality = (highQuality: boolean, musicInfo: LX.Music.MusicInfoOnline): LX.Quality => {
|
export const getPlayQuality = (highQuality: boolean, musicInfo: LX.Music.MusicInfoOnline): LX.Quality => {
|
||||||
let type: LX.Quality = '128k'
|
let type: LX.Quality = '128k'
|
||||||
let list = global.lx.qualityList[musicInfo.source]
|
let list = global.lx.qualityList[musicInfo.source]
|
||||||
if (highQuality && musicInfo.meta._qualitys['320k'] && list && list.includes('320k')) type = '320k'
|
if (highQuality && musicInfo.meta._qualitys['flac24bit'] && list && list.includes('flac24bit')) type = 'flac24bit'
|
||||||
return type
|
return type
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,20 +1,19 @@
|
|||||||
import { useState, useRef, useImperativeHandle, forwardRef, useMemo } from 'react'
|
import { useState, useRef, useImperativeHandle, forwardRef, useMemo, useEffect } from 'react'
|
||||||
import { View } from 'react-native'
|
import { View } from 'react-native'
|
||||||
|
|
||||||
import ConfirmAlert, { type ConfirmAlertType } from '@/components/common/ConfirmAlert'
|
import ConfirmAlert, { type ConfirmAlertType } from '@/components/common/ConfirmAlert'
|
||||||
import Text from '@/components/common/Text'
|
import Text from '@/components/common/Text'
|
||||||
import { createStyle } from '@/utils/tools'
|
import { createStyle } from '@/utils/tools'
|
||||||
import CheckBox from '@/components/common/CheckBox'
|
import CheckBox from '@/components/common/CheckBox'
|
||||||
import { useSettingValue } from '@/store/setting/hook'
|
|
||||||
import { updateSetting } from '@/core/common'
|
|
||||||
import { handelDownload } from './listAction'
|
import { handelDownload } from './listAction'
|
||||||
|
import log from '@/plugins/sync/log'
|
||||||
|
import { getOtherSource } from '@/core/music/utils'
|
||||||
|
|
||||||
interface TitleType {
|
interface TitleType {
|
||||||
updateTitle: (musicInfo: SelectInfo['musicInfo']) => void
|
updateTitle: (musicInfo: SelectInfo['musicInfo']) => void
|
||||||
}
|
}
|
||||||
const Title = forwardRef<TitleType, {}>((props, ref) => {
|
const Title = forwardRef<TitleType, {}>((props, ref) => {
|
||||||
const [title, setTitle] = useState('')
|
const [title, setTitle] = useState('')
|
||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
updateTitle(musicInfo) {
|
updateTitle(musicInfo) {
|
||||||
setTitle(global.i18n.t('download_music_title', { name: musicInfo.name }))
|
setTitle(global.i18n.t('download_music_title', { name: musicInfo.name }))
|
||||||
@ -46,7 +45,7 @@ interface MusicDownloadModalProps {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface MusicDownloadModalType {
|
export interface MusicDownloadModalType {
|
||||||
show: (listInfo: SelectInfo) => void
|
show: (listInfo: any) => void
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -55,9 +54,108 @@ export default forwardRef<MusicDownloadModalType, MusicDownloadModalProps>(({ on
|
|||||||
const titleRef = useRef<TitleType>(null)
|
const titleRef = useRef<TitleType>(null)
|
||||||
const inputRef = useRef<PositionInputType>(null)
|
const inputRef = useRef<PositionInputType>(null)
|
||||||
const selectedInfo = useRef<SelectInfo>(initSelectInfo as SelectInfo)
|
const selectedInfo = useRef<SelectInfo>(initSelectInfo as SelectInfo)
|
||||||
const [selectedQuality, setSselectedQuality] = useState<LX.Quality>("128k");
|
const [selectedQuality, setSelectedQuality] = useState<LX.Quality>("128k");
|
||||||
|
const [playQualityList, setPlayQualityList] = useState<MusicOption[]>([]);
|
||||||
const [visible, setVisible] = useState(false)
|
const [visible, setVisible] = useState(false)
|
||||||
|
|
||||||
|
interface QualityMap {
|
||||||
|
[key: string]: MusicOption;
|
||||||
|
}
|
||||||
|
|
||||||
|
// const playQualityList = useMemo(() => {
|
||||||
|
// return [
|
||||||
|
// {
|
||||||
|
// id: "128k",
|
||||||
|
// name: "标准音质(3.78MB)",
|
||||||
|
// }, {
|
||||||
|
// id: "320k",
|
||||||
|
// name: "高品音质(9.46MB)",
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// id: "flac",
|
||||||
|
// name: "无损音质(30.54MB)",
|
||||||
|
// }, {
|
||||||
|
// id: "flac24bit",
|
||||||
|
// name: "Hi-Res音质(49MB)",
|
||||||
|
// }
|
||||||
|
// ] as MusicOption[]
|
||||||
|
// //return ['128k', '320k', 'flac', 'flac24bit'] as LX.Quality[]
|
||||||
|
// }, [])
|
||||||
|
|
||||||
|
// const keyMap = ;
|
||||||
|
|
||||||
|
|
||||||
|
const keyValueArray = [
|
||||||
|
{ key: '128k', value: '标准音质' },
|
||||||
|
{ key: '320k', value: '高品音质' },
|
||||||
|
{ key: 'flac', value: '无损音质' },
|
||||||
|
{ key: 'flac', value: 'Hi-Res音质' },
|
||||||
|
{ key: 'flac24bit', value: 'value3' },
|
||||||
|
// 其他键值对...
|
||||||
|
];
|
||||||
|
|
||||||
|
const calcQualitys = () => {
|
||||||
|
const map = new Map();
|
||||||
|
map.set("128k", "标准音质");
|
||||||
|
map.set("320k", "高品音质");
|
||||||
|
map.set("flac", "无损音质");
|
||||||
|
map.set("flac24bit", "Hi-Res音质");
|
||||||
|
|
||||||
|
const qualitys = selectedInfo.current?.musicInfo.meta.qualitys;
|
||||||
|
let qualityMap: QualityMap = {};
|
||||||
|
for (let index = 0; index < qualitys.length; index++) {
|
||||||
|
const element = qualitys[index];
|
||||||
|
const temp: MusicOption = {
|
||||||
|
id: element.type,
|
||||||
|
name: map.has(element.type) ? map.get(element.type) : "未知",
|
||||||
|
size: element.size,
|
||||||
|
key: element.type,
|
||||||
|
}
|
||||||
|
qualityMap[element.type] = temp;
|
||||||
|
}
|
||||||
|
console.log(Object.values(qualityMap));
|
||||||
|
console.log(222);
|
||||||
|
|
||||||
|
if (Object.values(qualityMap).length == map.size) {
|
||||||
|
console.log(333);
|
||||||
|
setPlayQualityList(Object.values(qualityMap));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
getOtherSource(selectedInfo.current?.musicInfo, true).then(res => {
|
||||||
|
console.log(res);
|
||||||
|
if (res.length == 0) {
|
||||||
|
setPlayQualityList(Object.values(qualityMap));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let index = 0; index < res.length; index++) {
|
||||||
|
const element = res[index];
|
||||||
|
let qualitys = element.meta.qualitys
|
||||||
|
for (let index = 0; index < qualitys.length; index++) {
|
||||||
|
const element = qualitys[index];
|
||||||
|
if (element.type in qualityMap) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const tem: MusicOption = {
|
||||||
|
id: element.type,
|
||||||
|
name: map.has(element.type) ? map.get(element.type) : "未知",
|
||||||
|
size: element.size,
|
||||||
|
key: element.type,
|
||||||
|
}
|
||||||
|
qualityMap[element.type] = tem;
|
||||||
|
if (Object.values(qualityMap).length == map.size) {
|
||||||
|
setPlayQualityList(Object.values(qualityMap));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}).catch(err => {
|
||||||
|
|
||||||
|
})
|
||||||
|
// setPlayQualityList(Object.values(qualityMap));
|
||||||
|
}
|
||||||
|
|
||||||
const handleShow = () => {
|
const handleShow = () => {
|
||||||
alertRef.current?.setVisible(true)
|
alertRef.current?.setVisible(true)
|
||||||
requestAnimationFrame(() => {
|
requestAnimationFrame(() => {
|
||||||
@ -70,8 +168,7 @@ export default forwardRef<MusicDownloadModalType, MusicDownloadModalProps>(({ on
|
|||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
show(listInfo) {
|
show(listInfo) {
|
||||||
selectedInfo.current = listInfo
|
selectedInfo.current = listInfo
|
||||||
console.log(selectedInfo);
|
calcQualitys();
|
||||||
|
|
||||||
if (visible) handleShow()
|
if (visible) handleShow()
|
||||||
else {
|
else {
|
||||||
setVisible(true)
|
setVisible(true)
|
||||||
@ -83,15 +180,17 @@ export default forwardRef<MusicDownloadModalType, MusicDownloadModalProps>(({ on
|
|||||||
}))
|
}))
|
||||||
|
|
||||||
const handleDownloadMusic = () => {
|
const handleDownloadMusic = () => {
|
||||||
|
setSelectedQuality("128k");
|
||||||
alertRef.current?.setVisible(false)
|
alertRef.current?.setVisible(false)
|
||||||
// onDownloadInfo(selectedInfo.current, selectedQuality)
|
|
||||||
handelDownload(selectedInfo.current?.musicInfo, selectedQuality);
|
handelDownload(selectedInfo.current?.musicInfo, selectedQuality);
|
||||||
}
|
}
|
||||||
|
|
||||||
const playQualityList = useMemo(() => {
|
interface MusicOption {
|
||||||
return ['128k', '320k', 'flac', 'flac24bit'] as LX.Quality[]
|
id: LX.Quality;
|
||||||
}, [])
|
name: string;
|
||||||
|
size?: string | null;
|
||||||
|
key?: string
|
||||||
|
}
|
||||||
|
|
||||||
const useActive = (id: LX.Quality) => {
|
const useActive = (id: LX.Quality) => {
|
||||||
const isActive = useMemo(() => selectedQuality == id, [selectedQuality, id])
|
const isActive = useMemo(() => selectedQuality == id, [selectedQuality, id])
|
||||||
@ -103,7 +202,7 @@ export default forwardRef<MusicDownloadModalType, MusicDownloadModalProps>(({ on
|
|||||||
name: string
|
name: string
|
||||||
}) => {
|
}) => {
|
||||||
const isActive = useActive(id)
|
const isActive = useActive(id)
|
||||||
return <CheckBox marginRight={8} check={isActive} label={name} onChange={() => { setSselectedQuality(id) }} need />
|
return <CheckBox marginRight={8} check={isActive} label={name} onChange={() => { setSelectedQuality(id) }} need />
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -117,7 +216,7 @@ export default forwardRef<MusicDownloadModalType, MusicDownloadModalProps>(({ on
|
|||||||
<Title ref={titleRef} />
|
<Title ref={titleRef} />
|
||||||
<View style={styles.list}>
|
<View style={styles.list}>
|
||||||
{
|
{
|
||||||
playQualityList.map((q) => <Item name={q} id={q} key={q} />)
|
playQualityList.map((item) => <Item name={item.name + "" + "(" + item.size + ")"} id={item.id} key={item.key} />)
|
||||||
}
|
}
|
||||||
</View>
|
</View>
|
||||||
</View>
|
</View>
|
||||||
@ -139,7 +238,7 @@ const styles = createStyle({
|
|||||||
borderRadius: 4,
|
borderRadius: 4,
|
||||||
},
|
},
|
||||||
list: {
|
list: {
|
||||||
flexDirection: 'row',
|
flexDirection: 'column',
|
||||||
flexWrap: 'wrap',
|
flexWrap: 'nowrap',
|
||||||
},
|
},
|
||||||
})
|
})
|
@ -152,7 +152,7 @@ export default () => {
|
|||||||
<MusicPositionModal ref={musicPositionModalRef}
|
<MusicPositionModal ref={musicPositionModalRef}
|
||||||
onUpdatePosition={(info, postion) => { handleUpdateMusicPosition(postion, info.listId, info.musicInfo, info.selectedList, hancelExitSelect) }} />
|
onUpdatePosition={(info, postion) => { handleUpdateMusicPosition(postion, info.listId, info.musicInfo, info.selectedList, hancelExitSelect) }} />
|
||||||
<MusicDownloadModal ref={musicDownloadModalRef}
|
<MusicDownloadModal ref={musicDownloadModalRef}
|
||||||
onDownloadInfo={(info) => { handelDownload(info.musicInfo) }} />
|
onDownloadInfo={(info) => { handelDownload(info.musicInfo, "128k") }} />
|
||||||
<ListMenu
|
<ListMenu
|
||||||
ref={listMenuRef}
|
ref={listMenuRef}
|
||||||
onPlay={info => { handlePlay(info.listId, info.index) }}
|
onPlay={info => { handlePlay(info.listId, info.index) }}
|
||||||
|
@ -45,6 +45,7 @@ const diffCurrentMusicInfo = (curMusicInfo: LX.Music.MusicInfo | LX.Download.Lis
|
|||||||
// export const handelDownload = (musicInfo: LX.Music.MusicInfoOnline) => {
|
// export const handelDownload = (musicInfo: LX.Music.MusicInfoOnline) => {
|
||||||
export const handelDownload = (musicInfo: any, quality: LX.Quality) => {
|
export const handelDownload = (musicInfo: any, quality: LX.Quality) => {
|
||||||
return requestStoragePermission().then(async () => {
|
return requestStoragePermission().then(async () => {
|
||||||
|
console.log(quality);
|
||||||
try {
|
try {
|
||||||
getMusicUrl({
|
getMusicUrl({
|
||||||
musicInfo, quality, isRefresh: true, onToggleSource(mInfo) {
|
musicInfo, quality, isRefresh: true, onToggleSource(mInfo) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user