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'
|
2023-02-08 19:22:20 +01:00
|
|
|
import { GLOBAL } from '@utils/storage'
|
2022-12-28 23:41:36 +01:00
|
|
|
import { useGlobalStorage } from '@utils/storage/actions'
|
2022-12-19 22:36:30 +01:00
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2022-10-11 22:28:59 +02:00
|
|
|
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'
|
2022-10-11 22:28:59 +02:00
|
|
|
import { Linking, Platform } from 'react-native'
|
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
|
|
|
|
2022-12-28 23:41:36 +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) {
|
2023-01-29 19:02:47 +01:00
|
|
|
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')}
|
2022-12-28 23:41:36 +01:00
|
|
|
content={t(`screenTabs:me.fontSize.sizes.${mapFontsizeToName(fontSize || 0)}`)}
|
2023-01-25 00:15:46 +01:00
|
|
|
iconBack='chevron-right'
|
2022-05-28 22:18:03 +02:00
|
|
|
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[
|
2022-12-28 23:41:36 +01:00
|
|
|
Platform.OS === 'ios'
|
2023-03-14 01:39:54 +01:00
|
|
|
? Localization.locale.replace(new RegExp(/.*-.*(-.*)/, 'i'), '').toLowerCase()
|
2022-12-28 23:41:36 +01:00
|
|
|
: i18n.language.toLowerCase()
|
2022-11-17 20:02:56 +01:00
|
|
|
]
|
|
|
|
}
|
2023-01-25 00:15:46 +01:00
|
|
|
iconBack='chevron-right'
|
2022-10-11 22:28:59 +02:00
|
|
|
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')}
|
2022-12-28 23:41:36 +01:00
|
|
|
content={t(`screenTabs:me.settings.theme.options.${theme || 'auto'}`)}
|
2023-01-25 00:15:46 +01:00
|
|
|
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'),
|
2022-11-30 22:42:42 +01:00
|
|
|
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:
|
2022-12-28 23:41:36 +01:00
|
|
|
haptics('Light')
|
|
|
|
setTheme('auto')
|
2021-01-27 00:35:34 +01:00
|
|
|
break
|
|
|
|
case 1:
|
2022-12-28 23:41:36 +01:00
|
|
|
haptics('Light')
|
|
|
|
setTheme('light')
|
2021-01-27 00:35:34 +01:00
|
|
|
break
|
|
|
|
case 2:
|
2022-12-28 23:41:36 +01:00
|
|
|
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')}
|
2022-12-28 23:41:36 +01:00
|
|
|
content={t(`screenTabs:me.settings.darkTheme.options.${themeDark || 'lighter'}`)}
|
2023-01-25 00:15:46 +01:00
|
|
|
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'),
|
2022-11-30 22:42:42 +01:00
|
|
|
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:
|
2022-12-28 23:41:36 +01:00
|
|
|
haptics('Light')
|
|
|
|
setThemeDark('lighter')
|
2022-02-12 14:51:01 +01:00
|
|
|
break
|
|
|
|
case 1:
|
2022-12-28 23:41:36 +01:00
|
|
|
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')}
|
2022-12-28 23:41:36 +01:00
|
|
|
content={t(`screenTabs:me.settings.browser.options.${browser || 'internal'}`)}
|
2023-01-25 00:15:46 +01:00
|
|
|
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'),
|
2022-11-30 22:42:42 +01:00
|
|
|
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:
|
2022-12-28 23:41:36 +01:00
|
|
|
haptics('Light')
|
|
|
|
setBrowser('internal')
|
2021-01-27 00:35:34 +01:00
|
|
|
break
|
|
|
|
case 1:
|
2022-12-28 23:41:36 +01:00
|
|
|
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}
|
2022-12-28 23:41:36 +01:00
|
|
|
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}
|
2023-01-29 19:02:47 +01:00
|
|
|
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
|