import React, { useContext, useEffect, useState } from 'react'; import { ScrollView, TouchableWithoutFeedback, StyleSheet, Linking, Platform } from 'react-native'; import { useTheme } from '@react-navigation/native'; import navigationStyle from '../../components/navigationStyle'; import { BlueText, BlueSpacing20, BlueListItem, BlueCard, BlueHeaderDefaultSub } from '../../BlueComponents'; import loc from '../../loc'; import DeviceQuickActions from '../../class/quick-actions'; import BlueClipboard from '../../blue_modules/clipboard'; import { BlueStorageContext } from '../../blue_modules/storage-context'; import WidgetCommunication from '../../blue_modules/WidgetCommunication'; const A = require('../../blue_modules/analytics'); const SettingsPrivacy = () => { const { colors } = useTheme(); const { isStorageEncrypted, setDoNotTrack, isDoNotTrackEnabled } = useContext(BlueStorageContext); const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 }); const [isLoading, setIsLoading] = useState(sections.ALL); const [isReadClipboardAllowed, setIsReadClipboardAllowed] = useState(false); const [doNotTrackSwitchValue, setDoNotTrackSwitchValue] = useState(false); const [isDisplayWidgetBalanceAllowed, setIsDisplayWidgetBalanceAllowed] = useState(false); const [isQuickActionsEnabled, setIsQuickActionsEnabled] = useState(false); const [storageIsEncrypted, setStorageIsEncrypted] = useState(true); useEffect(() => { (async () => { try { setDoNotTrackSwitchValue(await isDoNotTrackEnabled()); setIsReadClipboardAllowed(await BlueClipboard.isReadClipboardAllowed()); setStorageIsEncrypted(await isStorageEncrypted()); setIsQuickActionsEnabled(await DeviceQuickActions.getEnabled()); setIsDisplayWidgetBalanceAllowed(await WidgetCommunication.isBalanceDisplayAllowed()); } catch (e) { console.log(e); } setIsLoading(false); })(); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); const onValueChange = async value => { setIsLoading(sections.CLIPBOARDREAD); try { await BlueClipboard.setReadClipboardAllowed(value); setIsReadClipboardAllowed(value); } catch (e) { console.log(e); } setIsLoading(false); }; const onDoNotTrackValueChange = async value => { setIsLoading(sections.ALL); try { setDoNotTrackSwitchValue(value); A.setOptOut(value); await setDoNotTrack(value); } catch (e) { console.log(e); } setIsLoading(false); }; const onQuickActionsValueChange = async value => { setIsLoading(sections.QUICKACTION); try { await DeviceQuickActions.setEnabled(value); setIsQuickActionsEnabled(value); } catch (e) { console.log(e); } setIsLoading(false); }; const onWidgetsTotalBalanceValueChange = async value => { setIsLoading(sections.WIDGETS); try { await WidgetCommunication.setBalanceDisplayAllowed(value); setIsDisplayWidgetBalanceAllowed(value); } catch (e) { console.log(e); } setIsLoading(false); }; const stylesWithThemeHook = StyleSheet.create({ root: { backgroundColor: colors.background, }, }); const openApplicationSettings = () => { Linking.openSettings(); }; return ( {loc.settings.privacy_clipboard_explanation} {!storageIsEncrypted && ( <> {loc.settings.privacy_quickactions_explanation} )} {Platform.OS === 'ios' && !storageIsEncrypted && ( <> {loc.settings.total_balance_explanation} )} {loc.settings.privacy_do_not_track_explanation} ); }; const styles = StyleSheet.create({ root: { flex: 1, }, }); SettingsPrivacy.navigationOptions = navigationStyle({}, opts => ({ ...opts, title: loc.settings.privacy })); export default SettingsPrivacy;