import Button from '@components/Button'
import haptics from '@components/haptics'
import { MenuContainer, MenuRow } from '@components/Menu'
import { useActionSheet } from '@expo/react-native-action-sheet'
import { useNavigation } from '@react-navigation/native'
import { persistor } from '@root/store'
import {
getLocalActiveIndex,
getLocalInstances,
getRemoteUrl
} from '@utils/slices/instancesSlice'
import {
changeAnalytics,
changeBrowser,
changeLanguage,
changeTheme,
getSettingsAnalytics,
getSettingsBrowser,
getSettingsLanguage,
getSettingsTheme
} from '@utils/slices/settingsSlice'
import { StyleConstants } from '@utils/styles/constants'
import { useTheme } from '@utils/styles/ThemeManager'
import Constants from 'expo-constants'
import prettyBytes from 'pretty-bytes'
import React, { useEffect, useState } from 'react'
import { useTranslation } from 'react-i18next'
import { StyleSheet, Text } from 'react-native'
import { CacheManager } from 'react-native-expo-image-cache'
import { ScrollView } from 'react-native-gesture-handler'
import { useDispatch, useSelector } from 'react-redux'
const DevDebug: React.FC = () => {
const { showActionSheetWithOptions } = useActionSheet()
const localActiveIndex = useSelector(getLocalActiveIndex)
const localInstances = useSelector(getLocalInstances)
return (
{}}
/>
showActionSheetWithOptions(
{
options: localInstances
.map(instance => {
return instance.url + ': ' + instance.account.id
})
.concat(['Cancel']),
cancelButtonIndex: localInstances.length
},
buttonIndex => {}
)
}
/>
)
}
const ScreenMeSettings: React.FC = () => {
const { showActionSheetWithOptions } = useActionSheet()
const navigation = useNavigation()
const { t, i18n } = useTranslation('meSettings')
const { setTheme, theme } = useTheme()
const settingsLanguage = useSelector(getSettingsLanguage)
const settingsTheme = useSelector(getSettingsTheme)
const settingsBrowser = useSelector(getSettingsBrowser)
const settingsRemote = useSelector(getRemoteUrl)
const settingsAnalytics = useSelector(getSettingsAnalytics)
const dispatch = useDispatch()
const [cacheSize, setCacheSize] = useState()
useEffect(() => {
CacheManager.getCacheSize().then(size => setCacheSize(size))
}, [])
return (
showActionSheetWithOptions(
{
title: t('content.language.heading'),
options: [
t('content.language.options.zh'),
t('content.language.options.en'),
t('content.language.options.cancel')
],
cancelButtonIndex: 2
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Success')
dispatch(changeLanguage('zh-CN'))
i18n.changeLanguage('zh-CN')
break
case 1:
haptics('Success')
dispatch(changeLanguage('en-US'))
i18n.changeLanguage('en-US')
break
}
}
)
}
/>
showActionSheetWithOptions(
{
title: t('content.theme.heading'),
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:
haptics('Success')
dispatch(changeTheme('auto'))
break
case 1:
haptics('Success')
dispatch(changeTheme('light'))
setTheme('light')
break
case 2:
haptics('Success')
dispatch(changeTheme('dark'))
setTheme('dark')
break
}
}
)
}
/>
showActionSheetWithOptions(
{
title: t('content.browser.heading'),
options: [
t('content.browser.options.internal'),
t('content.browser.options.external'),
t('content.browser.options.cancel')
],
cancelButtonIndex: 2
},
buttonIndex => {
switch (buttonIndex) {
case 0:
haptics('Success')
dispatch(changeBrowser('internal'))
break
case 1:
haptics('Success')
dispatch(changeBrowser('external'))
break
}
}
)
}
/>
navigation.navigate('Screen-Me-Settings-UpdateRemote')}
/>
{
await CacheManager.clearCache()
haptics('Success')
setCacheSize(0)
}}
/>
dispatch(changeAnalytics(!settingsAnalytics))
}
/>
{t('content.version', { version: '1.0.0' })}
{__DEV__ || Constants.manifest.releaseChannel === 'testing' ? (
) : null}
)
}
const styles = StyleSheet.create({
version: {
textAlign: 'center',
...StyleConstants.FontStyle.S,
marginTop: StyleConstants.Spacing.M
}
})
export default ScreenMeSettings