tooot/src/screens/Tabs/Me/Settings/App.tsx

191 lines
6.3 KiB
TypeScript
Raw Normal View History

2021-01-27 00:35:34 +01:00
import haptics from '@components/haptics'
import { MenuContainer, MenuRow } from '@components/Menu'
import { useActionSheet } from '@expo/react-native-action-sheet'
2023-01-29 15:32:40 +01:00
import { LOCALES } from '@i18n/locales'
2021-02-20 19:12:44 +01:00
import { useNavigation } from '@react-navigation/native'
2023-01-29 15:32:40 +01:00
import { connectVerify } from '@utils/api/helpers/connect'
import { androidActionSheetStyles } from '@utils/helpers/androidActionSheetStyles'
import { useGlobalStorage } from '@utils/storage/actions'
2022-12-19 22:36:30 +01:00
import { useTheme } from '@utils/styles/ThemeManager'
import * as Localization from 'expo-localization'
2023-01-29 15:32:40 +01:00
import React, { useEffect, useState } from 'react'
2021-01-27 00:35:34 +01:00
import { useTranslation } from 'react-i18next'
import { Linking, Platform } from 'react-native'
import { GLOBAL } from '../../../../App'
2021-05-09 21:59:03 +02:00
import { mapFontsizeToName } from '../SettingsFontsize'
2021-01-27 00:35:34 +01:00
const SettingsApp: React.FC = () => {
2021-08-29 15:25:38 +02:00
const navigation = useNavigation<any>()
2021-01-27 00:35:34 +01:00
const { showActionSheetWithOptions } = useActionSheet()
2022-12-19 22:36:30 +01:00
const { colors } = useTheme()
2022-12-23 15:53:40 +01:00
const { t, i18n } = useTranslation(['common', 'screenTabs'])
2021-01-27 00:35:34 +01:00
const [fontSize] = useGlobalStorage.number('app.font_size')
const [theme, setTheme] = useGlobalStorage.string('app.theme')
const [themeDark, setThemeDark] = useGlobalStorage.string('app.theme.dark')
const [browser, setBrowser] = useGlobalStorage.string('app.browser')
const [autoplayGifv, setAutoplayGifv] = useGlobalStorage.boolean('app.auto_play_gifv')
2021-02-08 23:47:20 +01:00
2023-01-29 15:32:40 +01:00
const [connect, setConnect] = useGlobalStorage.boolean('app.connect')
const [showConnect, setShowConnect] = useState(connect)
useEffect(() => {
connectVerify()
.then(() => {
setShowConnect(true)
})
.catch(() => {
if (connect) {
GLOBAL.connect = false
2023-01-29 15:32:40 +01:00
setConnect(false)
} else {
setShowConnect(false)
}
})
}, [])
2023-01-31 15:19:18 +01:00
const [clearingCache, setClearingCache] = useState(false)
2021-01-27 00:35:34 +01:00
return (
<MenuContainer>
2021-05-09 21:59:03 +02:00
<MenuRow
2022-12-23 18:19:14 +01:00
title={t('screenTabs:me.stacks.fontSize.name')}
content={t(`screenTabs:me.fontSize.sizes.${mapFontsizeToName(fontSize || 0)}`)}
iconBack='chevron-right'
onPress={() => navigation.navigate('Tab-Me-Settings-Fontsize')}
2021-05-09 21:59:03 +02:00
/>
2021-01-27 00:35:34 +01:00
<MenuRow
2022-12-23 18:19:14 +01:00
title={t('screenTabs:me.stacks.language.name')}
2022-11-17 20:02:56 +01:00
content={
// @ts-ignore
LOCALES[
Platform.OS === 'ios'
? Localization.locale.replace(new RegExp(/.*-.*(-.*)/, 'i'), '')
: i18n.language.toLowerCase()
2022-11-17 20:02:56 +01:00
]
}
iconBack='chevron-right'
onPress={() =>
Platform.OS === 'ios'
? Linking.openSettings()
: navigation.navigate('Tab-Me-Settings-Language')
}
2021-01-27 00:35:34 +01:00
/>
<MenuRow
2022-12-23 15:53:40 +01:00
title={t('screenTabs:me.settings.theme.heading')}
content={t(`screenTabs:me.settings.theme.options.${theme || 'auto'}`)}
iconBack='chevron-right'
2021-01-27 00:35:34 +01:00
onPress={() =>
showActionSheetWithOptions(
{
2022-12-23 15:53:40 +01:00
title: t('screenTabs:me.settings.theme.heading'),
2021-01-27 00:35:34 +01:00
options: [
2022-12-23 15:53:40 +01:00
t('screenTabs:me.settings.theme.options.auto'),
t('screenTabs:me.settings.theme.options.light'),
t('screenTabs:me.settings.theme.options.dark'),
t('common:buttons.cancel')
2021-01-27 00:35:34 +01:00
],
2022-12-19 22:36:30 +01:00
cancelButtonIndex: 3,
...androidActionSheetStyles(colors)
2021-01-27 00:35:34 +01:00
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Light')
setTheme('auto')
2021-01-27 00:35:34 +01:00
break
case 1:
haptics('Light')
setTheme('light')
2021-01-27 00:35:34 +01:00
break
case 2:
haptics('Light')
setTheme('dark')
2022-02-12 14:51:01 +01:00
break
}
}
)
}
/>
<MenuRow
2022-12-23 15:53:40 +01:00
title={t('screenTabs:me.settings.darkTheme.heading')}
content={t(`screenTabs:me.settings.darkTheme.options.${themeDark || 'lighter'}`)}
iconBack='chevron-right'
2022-02-12 14:51:01 +01:00
onPress={() =>
showActionSheetWithOptions(
{
2022-12-23 15:53:40 +01:00
title: t('screenTabs:me.settings.darkTheme.heading'),
2022-02-12 14:51:01 +01:00
options: [
2022-12-23 15:53:40 +01:00
t('screenTabs:me.settings.darkTheme.options.lighter'),
t('screenTabs:me.settings.darkTheme.options.darker'),
t('common:buttons.cancel')
2022-02-12 14:51:01 +01:00
],
2022-12-19 22:36:30 +01:00
cancelButtonIndex: 2,
...androidActionSheetStyles(colors)
2022-02-12 14:51:01 +01:00
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Light')
setThemeDark('lighter')
2022-02-12 14:51:01 +01:00
break
case 1:
haptics('Light')
setThemeDark('darker')
2021-01-27 00:35:34 +01:00
break
}
}
)
}
/>
<MenuRow
2022-12-23 15:53:40 +01:00
title={t('screenTabs:me.settings.browser.heading')}
content={t(`screenTabs:me.settings.browser.options.${browser || 'internal'}`)}
iconBack='chevron-right'
2021-01-27 00:35:34 +01:00
onPress={() =>
showActionSheetWithOptions(
{
2022-12-23 15:53:40 +01:00
title: t('screenTabs:me.settings.browser.heading'),
2021-01-27 00:35:34 +01:00
options: [
2022-12-23 15:53:40 +01:00
t('screenTabs:me.settings.browser.options.internal'),
t('screenTabs:me.settings.browser.options.external'),
t('common:buttons.cancel')
2021-01-27 00:35:34 +01:00
],
2022-12-19 22:36:30 +01:00
cancelButtonIndex: 2,
...androidActionSheetStyles(colors)
2021-01-27 00:35:34 +01:00
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Light')
setBrowser('internal')
2021-01-27 00:35:34 +01:00
break
case 1:
haptics('Light')
setBrowser('external')
2021-01-27 00:35:34 +01:00
break
}
}
)
}
/>
2022-05-13 00:04:15 +02:00
<MenuRow
2022-12-23 18:19:14 +01:00
title={t('screenTabs:me.settings.autoplayGifv.heading')}
2023-02-03 00:59:39 +01:00
switchValue={autoplayGifv || false}
switchOnValueChange={() => setAutoplayGifv(!autoplayGifv)}
2022-05-13 00:04:15 +02:00
/>
2023-01-29 15:32:40 +01:00
{showConnect ? (
<MenuRow
title='使用代理'
switchValue={connect || false}
switchOnValueChange={() => {
GLOBAL.connect = !connect
setConnect(!connect)
}}
2023-01-29 15:32:40 +01:00
/>
) : null}
2021-01-27 00:35:34 +01:00
</MenuContainer>
)
}
export default SettingsApp