2021-01-07 19:13:09 +01:00
|
|
|
import Button from '@components/Button'
|
2021-01-16 14:16:58 +01:00
|
|
|
import haptics from '@components/haptics'
|
2020-12-13 14:04:25 +01:00
|
|
|
import { MenuContainer, MenuRow } from '@components/Menu'
|
2021-01-13 01:03:46 +01:00
|
|
|
import { useActionSheet } from '@expo/react-native-action-sheet'
|
2021-01-07 19:13:09 +01:00
|
|
|
import { useNavigation } from '@react-navigation/native'
|
|
|
|
import { persistor } from '@root/store'
|
|
|
|
import {
|
|
|
|
getLocalActiveIndex,
|
|
|
|
getLocalInstances,
|
|
|
|
getRemoteUrl
|
2021-01-16 14:16:58 +01:00
|
|
|
} from '@utils/slices/instancesSlice'
|
2020-11-29 13:11:23 +01:00
|
|
|
import {
|
2020-12-29 16:19:04 +01:00
|
|
|
changeAnalytics,
|
2020-12-20 18:41:28 +01:00
|
|
|
changeBrowser,
|
2020-11-29 13:11:23 +01:00
|
|
|
changeLanguage,
|
2020-11-29 18:08:31 +01:00
|
|
|
changeTheme,
|
2020-12-29 16:19:04 +01:00
|
|
|
getSettingsAnalytics,
|
2020-12-20 18:41:28 +01:00
|
|
|
getSettingsBrowser,
|
2020-11-29 18:08:31 +01:00
|
|
|
getSettingsLanguage,
|
|
|
|
getSettingsTheme
|
2020-12-13 14:04:25 +01:00
|
|
|
} from '@utils/slices/settingsSlice'
|
|
|
|
import { StyleConstants } from '@utils/styles/constants'
|
|
|
|
import { useTheme } from '@utils/styles/ThemeManager'
|
2021-01-16 14:16:58 +01:00
|
|
|
import Constants from 'expo-constants'
|
2020-12-29 16:19:04 +01:00
|
|
|
import prettyBytes from 'pretty-bytes'
|
2021-01-07 19:13:09 +01:00
|
|
|
import React, { useEffect, useState } from 'react'
|
2020-12-29 16:19:04 +01:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-01-13 01:03:46 +01:00
|
|
|
import { StyleSheet, Text } from 'react-native'
|
2020-12-29 16:19:04 +01:00
|
|
|
import { CacheManager } from 'react-native-expo-image-cache'
|
2021-01-13 01:03:46 +01:00
|
|
|
import { ScrollView } from 'react-native-gesture-handler'
|
2020-12-29 16:19:04 +01:00
|
|
|
import { useDispatch, useSelector } from 'react-redux'
|
2020-11-28 17:07:30 +01:00
|
|
|
|
2021-01-07 19:13:09 +01:00
|
|
|
const DevDebug: React.FC = () => {
|
2021-01-13 01:03:46 +01:00
|
|
|
const { showActionSheetWithOptions } = useActionSheet()
|
2021-01-07 19:13:09 +01:00
|
|
|
const localActiveIndex = useSelector(getLocalActiveIndex)
|
|
|
|
const localInstances = useSelector(getLocalInstances)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<MenuContainer>
|
|
|
|
<MenuRow
|
|
|
|
title={'Local active index'}
|
|
|
|
content={typeof localActiveIndex + ' - ' + localActiveIndex}
|
|
|
|
onPress={() => {}}
|
|
|
|
/>
|
|
|
|
<MenuRow
|
|
|
|
title={'Saved local instances'}
|
|
|
|
content={localInstances.length.toString()}
|
|
|
|
iconBack='ChevronRight'
|
|
|
|
onPress={() =>
|
2021-01-13 01:03:46 +01:00
|
|
|
showActionSheetWithOptions(
|
2021-01-07 19:13:09 +01:00
|
|
|
{
|
|
|
|
options: localInstances
|
|
|
|
.map(instance => {
|
|
|
|
return instance.url + ': ' + instance.account.id
|
|
|
|
})
|
|
|
|
.concat(['Cancel']),
|
|
|
|
cancelButtonIndex: localInstances.length
|
|
|
|
},
|
|
|
|
buttonIndex => {}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
type='text'
|
|
|
|
content={'Purge secure storage'}
|
|
|
|
style={{
|
|
|
|
marginHorizontal: StyleConstants.Spacing.Global.PagePadding * 2,
|
|
|
|
marginBottom: StyleConstants.Spacing.Global.PagePadding * 2
|
|
|
|
}}
|
|
|
|
destructive
|
|
|
|
onPress={() => persistor.purge()}
|
|
|
|
/>
|
|
|
|
</MenuContainer>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
const ScreenMeSettings: React.FC = () => {
|
2021-01-13 01:03:46 +01:00
|
|
|
const { showActionSheetWithOptions } = useActionSheet()
|
2021-01-07 19:13:09 +01:00
|
|
|
const navigation = useNavigation()
|
2020-11-29 18:08:31 +01:00
|
|
|
const { t, i18n } = useTranslation('meSettings')
|
2020-12-01 00:44:28 +01:00
|
|
|
const { setTheme, theme } = useTheme()
|
2020-11-29 18:08:31 +01:00
|
|
|
const settingsLanguage = useSelector(getSettingsLanguage)
|
|
|
|
const settingsTheme = useSelector(getSettingsTheme)
|
2020-12-20 18:41:28 +01:00
|
|
|
const settingsBrowser = useSelector(getSettingsBrowser)
|
2021-01-07 19:13:09 +01:00
|
|
|
const settingsRemote = useSelector(getRemoteUrl)
|
2020-12-29 16:19:04 +01:00
|
|
|
const settingsAnalytics = useSelector(getSettingsAnalytics)
|
2020-11-29 13:11:23 +01:00
|
|
|
const dispatch = useDispatch()
|
|
|
|
|
2020-12-24 11:12:40 +01:00
|
|
|
const [cacheSize, setCacheSize] = useState<number>()
|
|
|
|
useEffect(() => {
|
2020-12-27 00:55:22 +01:00
|
|
|
CacheManager.getCacheSize().then(size => setCacheSize(size))
|
2020-12-24 11:12:40 +01:00
|
|
|
}, [])
|
|
|
|
|
2020-11-29 13:11:23 +01:00
|
|
|
return (
|
2021-01-13 01:03:46 +01:00
|
|
|
<ScrollView>
|
2020-12-18 23:58:53 +01:00
|
|
|
<MenuContainer>
|
2020-12-03 01:28:56 +01:00
|
|
|
<MenuRow
|
2020-12-01 00:44:28 +01:00
|
|
|
title={t('content.language.heading')}
|
|
|
|
content={t(`content.language.options.${settingsLanguage}`)}
|
2021-01-03 02:00:26 +01:00
|
|
|
iconBack='ChevronRight'
|
2020-12-01 00:44:28 +01:00
|
|
|
onPress={() =>
|
2021-01-13 01:03:46 +01:00
|
|
|
showActionSheetWithOptions(
|
2020-12-01 00:44:28 +01:00
|
|
|
{
|
2021-01-13 01:03:46 +01:00
|
|
|
title: t('content.language.heading'),
|
2020-12-01 00:44:28 +01:00
|
|
|
options: [
|
|
|
|
t('content.language.options.zh'),
|
|
|
|
t('content.language.options.en'),
|
|
|
|
t('content.language.options.cancel')
|
|
|
|
],
|
|
|
|
cancelButtonIndex: 2
|
|
|
|
},
|
|
|
|
buttonIndex => {
|
|
|
|
switch (buttonIndex) {
|
|
|
|
case 0:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2021-01-13 01:03:46 +01:00
|
|
|
dispatch(changeLanguage('zh-CN'))
|
|
|
|
i18n.changeLanguage('zh-CN')
|
2020-12-01 00:44:28 +01:00
|
|
|
break
|
|
|
|
case 1:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2021-01-13 01:03:46 +01:00
|
|
|
dispatch(changeLanguage('en-US'))
|
|
|
|
i18n.changeLanguage('en-US')
|
2020-12-01 00:44:28 +01:00
|
|
|
break
|
|
|
|
}
|
2020-11-29 13:11:23 +01:00
|
|
|
}
|
2020-12-01 00:44:28 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
2020-12-03 01:28:56 +01:00
|
|
|
<MenuRow
|
2020-12-01 00:44:28 +01:00
|
|
|
title={t('content.theme.heading')}
|
|
|
|
content={t(`content.theme.options.${settingsTheme}`)}
|
2021-01-03 02:00:26 +01:00
|
|
|
iconBack='ChevronRight'
|
2020-12-01 00:44:28 +01:00
|
|
|
onPress={() =>
|
2021-01-13 01:03:46 +01:00
|
|
|
showActionSheetWithOptions(
|
2020-12-01 00:44:28 +01:00
|
|
|
{
|
2021-01-13 01:03:46 +01:00
|
|
|
title: t('content.theme.heading'),
|
2020-12-01 00:44:28 +01:00
|
|
|
options: [
|
|
|
|
t('content.theme.options.auto'),
|
|
|
|
t('content.theme.options.light'),
|
|
|
|
t('content.theme.options.dark'),
|
|
|
|
t('content.theme.options.cancel')
|
|
|
|
],
|
|
|
|
cancelButtonIndex: 3
|
|
|
|
},
|
|
|
|
buttonIndex => {
|
|
|
|
switch (buttonIndex) {
|
|
|
|
case 0:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-01 00:44:28 +01:00
|
|
|
dispatch(changeTheme('auto'))
|
|
|
|
break
|
|
|
|
case 1:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-01 00:44:28 +01:00
|
|
|
dispatch(changeTheme('light'))
|
|
|
|
setTheme('light')
|
|
|
|
break
|
|
|
|
case 2:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-01 00:44:28 +01:00
|
|
|
dispatch(changeTheme('dark'))
|
|
|
|
setTheme('dark')
|
|
|
|
break
|
|
|
|
}
|
2020-11-29 18:08:31 +01:00
|
|
|
}
|
2020-12-01 00:44:28 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
2020-12-20 18:41:28 +01:00
|
|
|
<MenuRow
|
|
|
|
title={t('content.browser.heading')}
|
|
|
|
content={t(`content.browser.options.${settingsBrowser}`)}
|
2021-01-03 02:00:26 +01:00
|
|
|
iconBack='ChevronRight'
|
2020-12-20 18:41:28 +01:00
|
|
|
onPress={() =>
|
2021-01-13 01:03:46 +01:00
|
|
|
showActionSheetWithOptions(
|
2020-12-20 18:41:28 +01:00
|
|
|
{
|
2021-01-13 01:03:46 +01:00
|
|
|
title: t('content.browser.heading'),
|
2020-12-20 18:41:28 +01:00
|
|
|
options: [
|
|
|
|
t('content.browser.options.internal'),
|
|
|
|
t('content.browser.options.external'),
|
|
|
|
t('content.browser.options.cancel')
|
|
|
|
],
|
|
|
|
cancelButtonIndex: 2
|
|
|
|
},
|
|
|
|
buttonIndex => {
|
|
|
|
switch (buttonIndex) {
|
|
|
|
case 0:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-20 18:41:28 +01:00
|
|
|
dispatch(changeBrowser('internal'))
|
|
|
|
break
|
|
|
|
case 1:
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-20 18:41:28 +01:00
|
|
|
dispatch(changeBrowser('external'))
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
|
|
|
)
|
|
|
|
}
|
|
|
|
/>
|
2020-12-01 00:44:28 +01:00
|
|
|
</MenuContainer>
|
|
|
|
<MenuContainer>
|
2021-01-07 19:13:09 +01:00
|
|
|
<MenuRow
|
|
|
|
title={t('content.remote.heading')}
|
|
|
|
description={t('content.remote.description')}
|
|
|
|
content={settingsRemote}
|
|
|
|
iconBack='ChevronRight'
|
|
|
|
onPress={() => navigation.navigate('Screen-Me-Settings-UpdateRemote')}
|
|
|
|
/>
|
2020-12-24 11:12:40 +01:00
|
|
|
<MenuRow
|
|
|
|
title={t('content.cache.heading')}
|
2021-01-07 19:13:09 +01:00
|
|
|
content={
|
|
|
|
cacheSize ? prettyBytes(cacheSize) : t('content.cache.empty')
|
|
|
|
}
|
2021-01-03 02:00:26 +01:00
|
|
|
iconBack='ChevronRight'
|
2020-12-24 11:12:40 +01:00
|
|
|
onPress={async () => {
|
|
|
|
await CacheManager.clearCache()
|
2020-12-30 14:33:33 +01:00
|
|
|
haptics('Success')
|
2020-12-24 11:12:40 +01:00
|
|
|
setCacheSize(0)
|
|
|
|
}}
|
|
|
|
/>
|
2021-01-07 19:13:09 +01:00
|
|
|
</MenuContainer>
|
|
|
|
<MenuContainer>
|
2020-12-29 16:19:04 +01:00
|
|
|
<MenuRow
|
|
|
|
title={t('content.analytics.heading')}
|
|
|
|
description={t('content.analytics.description')}
|
|
|
|
switchValue={settingsAnalytics}
|
|
|
|
switchOnValueChange={() =>
|
|
|
|
dispatch(changeAnalytics(!settingsAnalytics))
|
|
|
|
}
|
|
|
|
/>
|
2020-12-03 01:28:56 +01:00
|
|
|
<MenuRow
|
2020-12-01 00:44:28 +01:00
|
|
|
title={t('content.copyrights.heading')}
|
2021-01-03 02:00:26 +01:00
|
|
|
iconBack='ChevronRight'
|
2020-12-03 01:28:56 +01:00
|
|
|
/>
|
2020-12-01 00:44:28 +01:00
|
|
|
<Text style={[styles.version, { color: theme.secondary }]}>
|
|
|
|
{t('content.version', { version: '1.0.0' })}
|
|
|
|
</Text>
|
|
|
|
</MenuContainer>
|
2021-01-07 19:13:09 +01:00
|
|
|
|
2021-01-16 14:16:58 +01:00
|
|
|
{__DEV__ || Constants.manifest.releaseChannel === 'testing' ? (
|
|
|
|
<DevDebug />
|
|
|
|
) : null}
|
2021-01-13 01:03:46 +01:00
|
|
|
</ScrollView>
|
2020-11-29 13:11:23 +01:00
|
|
|
)
|
2020-11-28 17:07:30 +01:00
|
|
|
}
|
|
|
|
|
2020-12-01 00:44:28 +01:00
|
|
|
const styles = StyleSheet.create({
|
|
|
|
version: {
|
|
|
|
textAlign: 'center',
|
2020-12-29 00:21:05 +01:00
|
|
|
...StyleConstants.FontStyle.S,
|
2020-12-01 00:44:28 +01:00
|
|
|
marginTop: StyleConstants.Spacing.M
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2020-11-28 17:07:30 +01:00
|
|
|
export default ScreenMeSettings
|