From 0b6b15e9a809476dda0367dcf9664f7bbe7284a2 Mon Sep 17 00:00:00 2001 From: lyswhut Date: Fri, 25 Mar 2022 20:49:33 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=88=86=E4=BA=AB=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- publish/changeLog.md | 4 ++ src/config/defaultSetting.js | 3 +- src/lang/en_us.json | 3 + src/lang/zh_cn.json | 3 + src/screens/Home/List/index.js | 21 ++++--- src/screens/Home/Setting/Basic/ShareType.js | 55 +++++++++++++++++++ src/screens/Home/Setting/Basic/index.js | 2 + .../Home/Setting/components/InputItem.js | 2 +- src/store/modules/common/action.js | 10 ++++ src/store/modules/common/getter.js | 2 + src/store/modules/common/reducer.js | 9 +++ 11 files changed, 105 insertions(+), 9 deletions(-) create mode 100644 src/screens/Home/Setting/Basic/ShareType.js diff --git a/publish/changeLog.md b/publish/changeLog.md index 15324a5..d993e50 100644 --- a/publish/changeLog.md +++ b/publish/changeLog.md @@ -1,3 +1,7 @@ +### 新增 + +- 新增设置-基本设置-分享设置,它用于控制歌曲菜单的分享行为,默认使用系统分享 + ### 变更 - 歌曲菜单的“复制歌曲名”改为“分享歌曲”,点击后可以选择第三方应用分享歌曲详情页链接 diff --git a/src/config/defaultSetting.js b/src/config/defaultSetting.js index 99a0640..49d7b0d 100644 --- a/src/config/defaultSetting.js +++ b/src/config/defaultSetting.js @@ -3,7 +3,7 @@ // const { isMac } = require('./utils') const defaultSetting = { - version: '1.16', + version: '1.17', player: { togglePlayMethod: 'listLoop', highQuality: false, @@ -100,6 +100,7 @@ const defaultSetting = { sourceId: 'kw', apiSource: 'temp', sourceNameType: 'alias', + shareType: 'system', // randomAnimate: true, ignoreVersion: null, isAgreePact: false, diff --git a/src/lang/en_us.json b/src/lang/en_us.json index 9270f8d..cbf780c 100644 --- a/src/lang/en_us.json +++ b/src/lang/en_us.json @@ -118,6 +118,9 @@ "setting_basic": "General", "setting_basic_animation": "Random pop-up animation", "setting_basic_lang": "Language", + "setting_basic_share_type": "Share", + "setting_basic_share_type_clipboard": "copy to clipboard", + "setting_basic_share_type_system": "Share using the system", "setting_basic_show_animation": "Show switching animation", "setting_basic_source": "Music source", "setting_basic_source_direct": "Direct API", diff --git a/src/lang/zh_cn.json b/src/lang/zh_cn.json index a876276..d59f50c 100644 --- a/src/lang/zh_cn.json +++ b/src/lang/zh_cn.json @@ -119,6 +119,9 @@ "setting_basic": "基本设置", "setting_basic_animation": "弹出层随机动画", "setting_basic_lang": "语言", + "setting_basic_share_type": "分享方式", + "setting_basic_share_type_clipboard": "复制到剪贴板", + "setting_basic_share_type_system": "使用系统分享", "setting_basic_show_animation": "显示切换动画", "setting_basic_source": "音乐来源", "setting_basic_source_direct": "试听接口(这是最后的选择...)", diff --git a/src/screens/Home/List/index.js b/src/screens/Home/List/index.js index ecf45d3..17987c5 100644 --- a/src/screens/Home/List/index.js +++ b/src/screens/Home/List/index.js @@ -10,7 +10,7 @@ import Button from '@/components/common/Button' import ExitMultipleModeBar from './components/ExitMultipleModeBar' import MyList from './components/MyList' import ListItem from './components/ListItem' -import { getListScrollPosition, saveListScrollPosition } from '@/utils/tools' +import { getListScrollPosition, saveListScrollPosition, clipboardWriteText, toast } from '@/utils/tools' import { shareText } from '@/utils/utils' import { useTranslation } from '@/plugins/i18n' import { LIST_ITEM_HEIGHT } from '@/config/constant' @@ -37,6 +37,7 @@ const List = () => { const activeListId = useGetter('common', 'prevSelectListId') const activeListIdRef = useRef(activeListId) const downloadFileName = useGetter('common', 'downloadFileName') + const shareType = useGetter('common', 'shareType') const [buttonPosition, setButtonPosition] = useState({ w: 0, h: 0, x: 0, y: 0 }) const selectedDataRef = useRef({ data: null, index: -1 }) const flatListRef = useRef() @@ -216,11 +217,17 @@ const List = () => { : setVisibleMusicAddModal(true) break case 'copyName': - shareText(t('share_card_title_music', { name: selectedDataRef.current.data.name }), t('share_title_music'), `${downloadFileName.replace('歌名', selectedDataRef.current.data.name) - .replace('歌手', selectedDataRef.current.data.singer).replace(/\s/g, '')} ${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`) - // clipboardWriteText(`${downloadFileName.replace('歌名', selectedDataRef.current.data.name) - // .replace('歌手', selectedDataRef.current.data.singer)} ${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`) - // toast(t('copy_name_tip')) + switch (shareType) { + case 'system': + shareText(t('share_card_title_music', { name: selectedDataRef.current.data.name }), t('share_title_music'), `${downloadFileName.replace('歌名', selectedDataRef.current.data.name) + .replace('歌手', selectedDataRef.current.data.singer).replace(/\s/g, '')}\n${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`) + break + case 'clipboard': + clipboardWriteText(`${downloadFileName.replace('歌名', selectedDataRef.current.data.name) + .replace('歌手', selectedDataRef.current.data.singer)} ${music[selectedDataRef.current.data.source].getMusicDetailPageUrl(selectedDataRef.current.data)}`) + toast(t('copy_name_tip')) + break + } break case 'changePosition': setVIsibleMusicPosition(true) @@ -236,7 +243,7 @@ const List = () => { default: break } - }, [downloadFileName, handleCancelMultiSelect, handlePlay, removeListItem, removeListMultiItem, setTempPlayList]) + }, [handlePlay, shareType, setTempPlayList, handleCancelMultiSelect, t, downloadFileName, removeListMultiItem, removeListItem]) const handleScroll = useCallback(({ nativeEvent }) => { saveListScrollPosition(currentListRef.current.id, nativeEvent.contentOffset.y) diff --git a/src/screens/Home/Setting/Basic/ShareType.js b/src/screens/Home/Setting/Basic/ShareType.js new file mode 100644 index 0000000..42dbc1b --- /dev/null +++ b/src/screens/Home/Setting/Basic/ShareType.js @@ -0,0 +1,55 @@ +import React, { memo, useMemo } from 'react' + +import { StyleSheet, View } 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 shareType = useGetter('common', 'shareType') + const isActive = useMemo(() => shareType == id, [shareType, id]) + return isActive +} + +const Item = ({ id, name, change }) => { + const isActive = useActive(id) + // const [toggleCheckBox, setToggleCheckBox] = useState(false) + return change(id)} need /> +} + +export default memo(() => { + const { t } = useTranslation() + const setShareType = useDispatch('common', 'setShareType') + const list = useMemo(() => [ + { + id: 'system', + name: t('setting_basic_share_type_system'), + }, + { + id: 'clipboard', + name: t('setting_basic_share_type_clipboard'), + }, + ], [t]) + + return ( + + + { + list.map(({ id, name }) => ) + } + + + ) +}) + +const styles = StyleSheet.create({ + list: { + flexGrow: 0, + flexShrink: 1, + flexDirection: 'row', + flexWrap: 'wrap', + }, +}) diff --git a/src/screens/Home/Setting/Basic/index.js b/src/screens/Home/Setting/Basic/index.js index d979ed4..8ecaf2c 100644 --- a/src/screens/Home/Setting/Basic/index.js +++ b/src/screens/Home/Setting/Basic/index.js @@ -5,6 +5,7 @@ import Theme from './Theme' import Source from './Source' import SourceName from './SourceName' import Language from './Language' +import ShareType from './ShareType' import { useTranslation } from '@/plugins/i18n' export default memo(() => { @@ -17,6 +18,7 @@ export default memo(() => { + ) }) diff --git a/src/screens/Home/Setting/components/InputItem.js b/src/screens/Home/Setting/components/InputItem.js index c29ff65..98e5d79 100644 --- a/src/screens/Home/Setting/components/InputItem.js +++ b/src/screens/Home/Setting/components/InputItem.js @@ -26,7 +26,7 @@ export default memo(({ value, label, onChange, ...props }) => { }, []) useEffect(() => { const handleKeyboardDidHide = () => { - if (!inputRef.current.isFocused()) return + if (!inputRef.current?.isFocused()) return onChange && onChange(textRef.current, value => { if (!isMountRef.current) return const newValue = String(value) diff --git a/src/store/modules/common/action.js b/src/store/modules/common/action.js index 018bd3d..fb4a70a 100644 --- a/src/store/modules/common/action.js +++ b/src/store/modules/common/action.js @@ -31,6 +31,7 @@ export const TYPES = { setTop: null, setIgnoreVersion: null, setVersionInfo: null, + setShareType: null, setTimeoutExit: null, setIsHandleAudioFocus: null, setAddMusicLocationType: null, @@ -398,3 +399,12 @@ export const setPlayerLandscapeStyle = style => async(dispatch, getState) => { const { common } = getState() await setData(settingKey, common.setting) } + +export const setShareType = type => async(dispatch, getState) => { + dispatch({ + type: TYPES.setShareType, + payload: type, + }) + const { common } = getState() + await setData(settingKey, common.setting) +} diff --git a/src/store/modules/common/getter.js b/src/store/modules/common/getter.js index eb2f343..d4a8977 100644 --- a/src/store/modules/common/getter.js +++ b/src/store/modules/common/getter.js @@ -71,3 +71,5 @@ export const supportQualitys = state => apiSourceInfo.find(s => s.id == state.co export const playerPortraitStyle = state => state.common.setting.player.portrait.style export const playerLandscapeStyle = state => state.common.setting.player.landscape.style + +export const shareType = state => state.common.setting.shareType diff --git a/src/store/modules/common/reducer.js b/src/store/modules/common/reducer.js index 9fcd64a..0dc72d0 100644 --- a/src/store/modules/common/reducer.js +++ b/src/store/modules/common/reducer.js @@ -455,6 +455,15 @@ const mutations = { }, } }, + [TYPES.setShareType](state, shareType) { + return { + ...state, + setting: { + ...state.setting, + shareType, + }, + } + }, } export default (state = initialState, action) =>