新增“添加歌曲到列表时的位置”设置

This commit is contained in:
lyswhut 2021-06-11 15:17:17 +08:00
parent 86d4984442
commit 2bad0b0ef5
13 changed files with 135 additions and 11 deletions

View File

@ -1,4 +1,8 @@
### 新增 ### 新增
- 新增“其他应用播放声音时,自动暂停播放”设置,默认开启 - 新增“其他应用播放声音时,自动暂停播放”设置,默认开启
- 新增“添加歌曲到列表时的位置”设置,可选项为列表的“顶部”与“底部”
### 变更
- 添加歌曲到列表时从原来的底部改为顶部,若想要恢复原来的行为则可以去更改“添加歌曲到列表时的位置”设置项

View File

@ -3,7 +3,7 @@
// const { isMac } = require('./utils') // const { isMac } = require('./utils')
const defaultSetting = { const defaultSetting = {
version: '1.4', version: '1.5',
player: { player: {
togglePlayMethod: 'listLoop', togglePlayMethod: 'listLoop',
highQuality: false, highQuality: false,
@ -17,6 +17,7 @@ const defaultSetting = {
isShowSource: true, isShowSource: true,
prevSelectListId: 'default', prevSelectListId: 'default',
isSaveScrollLocation: true, isSaveScrollLocation: true,
addMusicLocationType: 'top',
}, },
download: { download: {
enable: false, enable: false,

View File

@ -89,6 +89,9 @@
"setting_basic_sourcename_real": "Original", "setting_basic_sourcename_real": "Original",
"setting_basic_sourcename_title": "Select the name of music source", "setting_basic_sourcename_title": "Select the name of music source",
"setting_basic_theme": "Theme", "setting_basic_theme": "Theme",
"setting_list": "List settings",
"setting_list_add_music_location_type_bottom": "Bottom",
"setting_list_add_music_location_type_top": "Top",
"setting_other": "Other", "setting_other": "Other",
"setting_other_cache": "Cache management (including the cache of songs, lyrics, error logs, etc., it is not recommended to clean up if there is no problem related to song playback)", "setting_other_cache": "Cache management (including the cache of songs, lyrics, error logs, etc., it is not recommended to clean up if there is no problem related to song playback)",
"setting_other_cache_clear_btn": "Clear Cache", "setting_other_cache_clear_btn": "Clear Cache",

View File

@ -89,6 +89,10 @@
"setting_basic_sourcename_real": "原名", "setting_basic_sourcename_real": "原名",
"setting_basic_sourcename_title": "选择音源名字类型", "setting_basic_sourcename_title": "选择音源名字类型",
"setting_basic_theme": "主题颜色", "setting_basic_theme": "主题颜色",
"setting_list": "列表设置",
"setting_list_add_music_location_type": "添加歌曲到列表时的位置",
"setting_list_add_music_location_type_bottom": "底部",
"setting_list_add_music_location_type_top": "顶部",
"setting_other": "其他", "setting_other": "其他",
"setting_other_cache": "缓存管理(包括歌曲、歌词、错误日志等缓存,没有歌曲播放相关的问题不建议清理)", "setting_other_cache": "缓存管理(包括歌曲、歌词、错误日志等缓存,没有歌曲播放相关的问题不建议清理)",
"setting_other_cache_clear_btn": "清理缓存", "setting_other_cache_clear_btn": "清理缓存",

View File

@ -48,7 +48,7 @@ const styles = StyleSheet.create({
list: { list: {
flexGrow: 0, flexGrow: 0,
flexShrink: 1, flexShrink: 1,
flexDirection: 'row', // flexDirection: 'row',
flexWrap: 'wrap', // flexWrap: 'wrap',
}, },
}) })

View File

@ -0,0 +1,43 @@
import React, { memo, useMemo } from 'react'
import { View, StyleSheet } from 'react-native'
import { useGetter, useDispatch } from '@/store'
import SubTitle from '../components/SubTitle'
import { useTranslation } from '@/plugins/i18n'
import CheckBox from '@/components/common/CheckBox'
const useActive = id => {
const addMusicLocationType = useGetter('common', 'addMusicLocationType')
const isActive = useMemo(() => addMusicLocationType == id, [addMusicLocationType, id])
return isActive
}
const Item = ({ id, name, change }) => {
const isActive = useActive(id)
// const [toggleCheckBox, setToggleCheckBox] = useState(false)
return <CheckBox marginBottom={3} check={isActive} label={name} onChange={() => change(id)} need />
}
export default memo(() => {
const { t } = useTranslation()
const setAddMusicLocationType = useDispatch('common', 'setAddMusicLocationType')
return (
<SubTitle title={t('setting_list_add_music_location_type')}>
<View style={styles.list}>
<Item id="top" change={setAddMusicLocationType} name={t('setting_list_add_music_location_type_top')} />
<Item id="bottom" change={setAddMusicLocationType} name={t('setting_list_add_music_location_type_bottom')} />
</View>
</SubTitle>
)
})
const styles = StyleSheet.create({
list: {
flexDirection: 'row',
flexWrap: 'wrap',
},
})

View File

@ -0,0 +1,15 @@
import React, { memo } from 'react'
import Section from '../components/Section'
import AddMusicLocationType from './AddMusicLocationType'
import { useTranslation } from '@/plugins/i18n'
export default memo(() => {
const { t } = useTranslation()
return (
<Section title={t('setting_list')}>
<AddMusicLocationType />
</Section>
)
})

View File

@ -8,6 +8,7 @@ import {
import Basic from './Basic' import Basic from './Basic'
import Player from './Player' import Player from './Player'
import List from './List'
import Backup from './Backup' import Backup from './Backup'
import Other from './Other' import Other from './Other'
import Version from './Version' import Version from './Version'
@ -28,6 +29,7 @@ export default () => {
<View style={styles.content}> <View style={styles.content}>
<Basic /> <Basic />
<Player /> <Player />
<List />
<Backup /> <Backup />
<Other /> <Other />
<Version /> <Version />

View File

@ -33,6 +33,7 @@ export const TYPES = {
setVersionInfo: null, setVersionInfo: null,
setTimeoutExit: null, setTimeoutExit: null,
setIsHandleAudioFocus: null, setIsHandleAudioFocus: null,
setAddMusicLocationType: null,
} }
for (const key of Object.keys(TYPES)) { for (const key of Object.keys(TYPES)) {
TYPES[key] = `common__${key}` TYPES[key] = `common__${key}`
@ -270,3 +271,12 @@ export const setIsHandleAudioFocus = flag => async(dispatch, getState) => {
await setData(settingKey, common.setting) await setData(settingKey, common.setting)
} }
export const setAddMusicLocationType = type => async(dispatch, getState) => {
dispatch({
type: TYPES.setAddMusicLocationType,
payload: type,
})
const { common } = getState()
await setData(settingKey, common.setting)
}

View File

@ -33,6 +33,7 @@ export const themeList = createSelector(themes, themes => Object.values(themes))
export const versionInfo = state => state.common.versionInfo export const versionInfo = state => state.common.versionInfo
export const prevSelectListId = state => state.common.setting.list.prevSelectListId export const prevSelectListId = state => state.common.setting.list.prevSelectListId
export const addMusicLocationType = state => state.common.setting.list.addMusicLocationType
export const togglePlayMethod = state => state.common.setting.player.togglePlayMethod export const togglePlayMethod = state => state.common.setting.player.togglePlayMethod

View File

@ -100,6 +100,18 @@ const mutations = {
}, },
} }
}, },
[TYPES.setAddMusicLocationType](state, type) {
return {
...state,
setting: {
...state.setting,
list: {
...state.setting.list,
addMusicLocationType: type,
},
},
}
},
[TYPES.setAgreePact](state, isAgreePact) { [TYPES.setAgreePact](state, isAgreePact) {
return { return {
...state, ...state,

View File

@ -99,11 +99,13 @@ export const setList = ({ id, list, name, location, source, sourceListId }) => a
} }
export const listAdd = ({ musicInfo, id }) => (dispatch, getState) => { export const listAdd = ({ musicInfo, id }) => (dispatch, getState) => {
const addMusicLocationType = getState().common.setting.list.addMusicLocationType
dispatch({ dispatch({
type: TYPES.listAdd, type: TYPES.listAdd,
payload: { payload: {
musicInfo, musicInfo,
id, id,
addMusicLocationType,
}, },
}) })
dispatch(playerAction.checkPlayList([id])) dispatch(playerAction.checkPlayList([id]))
@ -111,18 +113,20 @@ export const listAdd = ({ musicInfo, id }) => (dispatch, getState) => {
} }
export const listMove = ({ fromId, musicInfo, toId }) => (dispatch, getState) => { export const listMove = ({ fromId, musicInfo, toId }) => (dispatch, getState) => {
const addMusicLocationType = getState().common.setting.list.addMusicLocationType
dispatch({ dispatch({
type: TYPES.listMove, type: TYPES.listMove,
payload: { fromId, musicInfo, toId }, payload: { fromId, musicInfo, toId, addMusicLocationType },
}) })
dispatch(playerAction.checkPlayList([fromId, musicInfo])) dispatch(playerAction.checkPlayList([fromId, musicInfo]))
saveList([global.allList[fromId], global.allList[toId]]) saveList([global.allList[fromId], global.allList[toId]])
} }
export const listAddMultiple = ({ id, list }) => (dispatch, getState) => { export const listAddMultiple = ({ id, list }) => (dispatch, getState) => {
const addMusicLocationType = getState().common.setting.list.addMusicLocationType
dispatch({ dispatch({
type: TYPES.listAddMultiple, type: TYPES.listAddMultiple,
payload: { id, list }, payload: { id, list, addMusicLocationType },
}) })
dispatch(playerAction.checkPlayList([id])) dispatch(playerAction.checkPlayList([id]))
saveList(global.allList[id]) saveList(global.allList[id])

View File

@ -113,14 +113,22 @@ const mutations = {
allListUpdate(newList) allListUpdate(newList)
return { ...state, userList: [...state.userList, newList] } return { ...state, userList: [...state.userList, newList] }
}, */ }, */
[TYPES.listAdd](state, { id, musicInfo }) { [TYPES.listAdd](state, { id, musicInfo, addMusicLocationType }) {
const targetList = allList[id] const targetList = allList[id]
if (!targetList) return state if (!targetList) return state
if (targetList.list.some(s => s.songmid === musicInfo.songmid)) return state if (targetList.list.some(s => s.songmid === musicInfo.songmid)) return state
targetList.list = [...targetList.list, musicInfo] switch (addMusicLocationType) {
case 'top':
targetList.list = [musicInfo, ...targetList.list]
break
case 'bottom':
default:
targetList.list = [...targetList.list, musicInfo]
break
}
return updateStateList({ ...state }, [id]) return updateStateList({ ...state }, [id])
}, },
[TYPES.listMove](state, { fromId, musicInfo, toId }) { [TYPES.listMove](state, { fromId, musicInfo, toId, addMusicLocationType }) {
const fromList = allList[fromId] const fromList = allList[fromId]
const toList = allList[toId] const toList = allList[toId]
if (!fromList || !toList) return state if (!fromList || !toList) return state
@ -129,14 +137,31 @@ const mutations = {
fromList.list = newFromList fromList.list = newFromList
const index = toList.list.findIndex(s => s.songmid === musicInfo.songmid) const index = toList.list.findIndex(s => s.songmid === musicInfo.songmid)
if (index < 0) { if (index < 0) {
toList.list = [...toList.list, musicInfo] switch (addMusicLocationType) {
case 'top':
toList.list = [musicInfo, ...toList.list]
break
case 'bottom':
default:
toList.list = [...toList.list, musicInfo]
break
}
} }
return updateStateList({ ...state }, [fromId, toId]) return updateStateList({ ...state }, [fromId, toId])
}, },
[TYPES.listAddMultiple](state, { id, list }) { [TYPES.listAddMultiple](state, { id, list, addMusicLocationType }) {
const targetList = allList[id] const targetList = allList[id]
if (!targetList) return state if (!targetList) return state
const newList = [...targetList.list, ...list] let newList
switch (addMusicLocationType) {
case 'top':
newList = [...list, ...targetList.list]
break
case 'bottom':
default:
newList = [...targetList.list, ...list]
break
}
const map = {} const map = {}
const ids = [] const ids = []
for (const item of newList) { for (const item of newList) {