2020-10-24 19:20:59 +02:00
|
|
|
import React, { useContext, useEffect, useState } from 'react';
|
2023-10-23 20:50:17 +02:00
|
|
|
import { ScrollView, TouchableWithoutFeedback, StyleSheet, Platform, Pressable, Text } from 'react-native';
|
|
|
|
import { openSettings } from 'react-native-permissions';
|
2020-12-25 17:09:53 +01:00
|
|
|
|
|
|
|
import navigationStyle from '../../components/navigationStyle';
|
2023-12-16 22:44:35 +01:00
|
|
|
import { BlueText, BlueSpacing20, BlueCard, BlueHeaderDefaultSub, BlueSpacing40 } from '../../BlueComponents';
|
2020-10-10 21:19:42 +02:00
|
|
|
import loc from '../../loc';
|
2020-10-24 19:20:59 +02:00
|
|
|
import { BlueStorageContext } from '../../blue_modules/storage-context';
|
2023-10-24 03:28:44 +02:00
|
|
|
import { useTheme } from '../../components/themes';
|
2023-12-16 22:44:35 +01:00
|
|
|
import ListItem from '../../components/ListItem';
|
2024-03-31 21:59:14 +02:00
|
|
|
import A from '../../blue_modules/analytics';
|
2024-04-18 03:05:48 +02:00
|
|
|
import { useSettings } from '../../components/Context/SettingsContext';
|
2024-04-25 03:32:37 +02:00
|
|
|
import { setBalanceDisplayAllowed } from '../../components/WidgetCommunication';
|
2021-05-07 17:55:17 +02:00
|
|
|
|
2020-10-10 21:19:42 +02:00
|
|
|
const SettingsPrivacy = () => {
|
|
|
|
const { colors } = useTheme();
|
2024-04-18 03:05:48 +02:00
|
|
|
const { isStorageEncrypted } = useContext(BlueStorageContext);
|
|
|
|
const {
|
|
|
|
isDoNotTrackEnabled,
|
|
|
|
setDoNotTrackStorage,
|
2024-04-18 19:48:22 +02:00
|
|
|
setIsPrivacyBlurEnabledState,
|
2024-04-18 03:05:48 +02:00
|
|
|
isWidgetBalanceDisplayAllowed,
|
|
|
|
setIsWidgetBalanceDisplayAllowedStorage,
|
|
|
|
isClipboardGetContentEnabled,
|
|
|
|
setIsClipboardGetContentEnabledStorage,
|
2024-04-18 19:48:22 +02:00
|
|
|
isQuickActionsEnabled,
|
|
|
|
setIsQuickActionsEnabledStorage,
|
2024-04-18 03:05:48 +02:00
|
|
|
} = useSettings();
|
2020-12-18 23:01:11 +01:00
|
|
|
const sections = Object.freeze({ ALL: 0, CLIPBOARDREAD: 1, QUICKACTION: 2, WIDGETS: 3 });
|
2020-10-10 21:19:42 +02:00
|
|
|
const [isLoading, setIsLoading] = useState(sections.ALL);
|
2020-12-18 23:01:11 +01:00
|
|
|
|
2020-10-10 21:19:42 +02:00
|
|
|
const [storageIsEncrypted, setStorageIsEncrypted] = useState(true);
|
2021-09-25 17:04:45 +02:00
|
|
|
const [isPrivacyBlurEnabledTapped, setIsPrivacyBlurEnabledTapped] = useState(0);
|
2023-10-23 20:50:17 +02:00
|
|
|
const styleHooks = StyleSheet.create({
|
|
|
|
widgetsHeader: {
|
|
|
|
color: colors.foregroundColor,
|
|
|
|
},
|
|
|
|
});
|
2020-10-10 21:19:42 +02:00
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
(async () => {
|
|
|
|
try {
|
2020-10-24 19:20:59 +02:00
|
|
|
setStorageIsEncrypted(await isStorageEncrypted());
|
2020-10-10 21:19:42 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
setIsLoading(false);
|
|
|
|
})();
|
2020-10-24 19:20:59 +02:00
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
2020-10-10 21:19:42 +02:00
|
|
|
}, []);
|
|
|
|
|
2021-05-07 17:55:17 +02:00
|
|
|
const onDoNotTrackValueChange = async value => {
|
|
|
|
setIsLoading(sections.ALL);
|
|
|
|
try {
|
2024-04-18 03:05:48 +02:00
|
|
|
setDoNotTrackStorage(value);
|
2024-04-07 02:13:12 +02:00
|
|
|
A.setOptOut(value);
|
2021-05-07 17:55:17 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
setIsLoading(false);
|
|
|
|
};
|
|
|
|
|
2020-10-10 21:19:42 +02:00
|
|
|
const onQuickActionsValueChange = async value => {
|
|
|
|
setIsLoading(sections.QUICKACTION);
|
|
|
|
try {
|
2024-04-18 19:48:22 +02:00
|
|
|
setIsQuickActionsEnabledStorage(value);
|
2020-10-10 21:19:42 +02:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
setIsLoading(false);
|
|
|
|
};
|
|
|
|
|
2020-12-18 23:01:11 +01:00
|
|
|
const onWidgetsTotalBalanceValueChange = async value => {
|
|
|
|
setIsLoading(sections.WIDGETS);
|
|
|
|
try {
|
2024-04-25 03:32:37 +02:00
|
|
|
await setBalanceDisplayAllowed(value);
|
2024-04-18 03:05:48 +02:00
|
|
|
setIsWidgetBalanceDisplayAllowedStorage(value);
|
2020-12-18 23:01:11 +01:00
|
|
|
} catch (e) {
|
|
|
|
console.log(e);
|
|
|
|
}
|
|
|
|
setIsLoading(false);
|
|
|
|
};
|
|
|
|
|
2020-10-10 21:19:42 +02:00
|
|
|
const stylesWithThemeHook = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
backgroundColor: colors.background,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
|
|
|
|
const openApplicationSettings = () => {
|
2023-10-23 20:50:17 +02:00
|
|
|
openSettings();
|
2020-10-10 21:19:42 +02:00
|
|
|
};
|
|
|
|
|
2021-09-25 17:04:45 +02:00
|
|
|
const onDisablePrivacyTapped = () => {
|
2024-04-18 19:48:22 +02:00
|
|
|
setIsPrivacyBlurEnabledState(!(isPrivacyBlurEnabledTapped >= 10));
|
2021-09-25 17:04:45 +02:00
|
|
|
setIsPrivacyBlurEnabledTapped(prev => prev + 1);
|
|
|
|
};
|
|
|
|
|
2020-10-10 21:19:42 +02:00
|
|
|
return (
|
2024-01-05 01:50:53 +01:00
|
|
|
<ScrollView style={[styles.root, stylesWithThemeHook.root]} contentInsetAdjustmentBehavior="automatic" automaticallyAdjustContentInsets>
|
2024-04-18 19:48:22 +02:00
|
|
|
{Platform.OS === 'android' ? <BlueHeaderDefaultSub leftText={loc.settings.general} /> : <></>}
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
2020-10-10 21:19:42 +02:00
|
|
|
hideChevron
|
|
|
|
title={loc.settings.privacy_read_clipboard}
|
|
|
|
Component={TouchableWithoutFeedback}
|
2024-04-18 03:05:48 +02:00
|
|
|
switch={{
|
|
|
|
onValueChange: setIsClipboardGetContentEnabledStorage,
|
|
|
|
value: isClipboardGetContentEnabled,
|
|
|
|
disabled: isLoading === sections.ALL,
|
|
|
|
testID: 'ClipboardSwitch',
|
|
|
|
}}
|
2020-10-10 21:19:42 +02:00
|
|
|
/>
|
|
|
|
<BlueCard>
|
2024-04-18 19:48:22 +02:00
|
|
|
<Pressable accessibilityRole="button" onPress={onDisablePrivacyTapped}>
|
|
|
|
<BlueText>{loc.settings.privacy_clipboard_explanation}</BlueText>
|
|
|
|
</Pressable>
|
2020-10-10 21:19:42 +02:00
|
|
|
</BlueCard>
|
|
|
|
<BlueSpacing20 />
|
|
|
|
{!storageIsEncrypted && (
|
|
|
|
<>
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
2020-10-10 21:19:42 +02:00
|
|
|
hideChevron
|
|
|
|
title={loc.settings.privacy_quickactions}
|
|
|
|
Component={TouchableWithoutFeedback}
|
2021-03-01 11:20:01 +01:00
|
|
|
switch={{
|
|
|
|
onValueChange: onQuickActionsValueChange,
|
|
|
|
value: isQuickActionsEnabled,
|
|
|
|
disabled: isLoading === sections.ALL,
|
2023-03-30 02:46:11 +02:00
|
|
|
testID: 'QuickActionsSwitch',
|
2021-03-01 11:20:01 +01:00
|
|
|
}}
|
2020-10-10 21:19:42 +02:00
|
|
|
/>
|
|
|
|
<BlueCard>
|
2020-11-22 09:04:04 +01:00
|
|
|
<BlueText>{loc.settings.privacy_quickactions_explanation}</BlueText>
|
2020-10-10 21:19:42 +02:00
|
|
|
</BlueCard>
|
|
|
|
</>
|
|
|
|
)}
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
2023-10-23 20:50:17 +02:00
|
|
|
hideChevron
|
|
|
|
title={loc.settings.privacy_do_not_track}
|
|
|
|
Component={TouchableWithoutFeedback}
|
2024-04-18 03:05:48 +02:00
|
|
|
switch={{ onValueChange: onDoNotTrackValueChange, value: isDoNotTrackEnabled, disabled: isLoading === sections.ALL }}
|
2023-10-23 20:50:17 +02:00
|
|
|
/>
|
|
|
|
<BlueCard>
|
|
|
|
<BlueText>{loc.settings.privacy_do_not_track_explanation}</BlueText>
|
|
|
|
</BlueCard>
|
2020-12-18 23:01:11 +01:00
|
|
|
{Platform.OS === 'ios' && !storageIsEncrypted && (
|
|
|
|
<>
|
2023-10-23 20:50:17 +02:00
|
|
|
<BlueSpacing40 />
|
|
|
|
<Text adjustsFontSizeToFit style={[styles.widgetsHeader, styleHooks.widgetsHeader]}>
|
|
|
|
{loc.settings.widgets}
|
|
|
|
</Text>
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem
|
2020-12-18 23:01:11 +01:00
|
|
|
hideChevron
|
|
|
|
title={loc.settings.total_balance}
|
|
|
|
Component={TouchableWithoutFeedback}
|
|
|
|
switch={{
|
|
|
|
onValueChange: onWidgetsTotalBalanceValueChange,
|
2024-04-18 03:05:48 +02:00
|
|
|
value: isWidgetBalanceDisplayAllowed,
|
2020-12-18 23:01:11 +01:00
|
|
|
disabled: isLoading === sections.ALL,
|
|
|
|
}}
|
|
|
|
/>
|
|
|
|
<BlueCard>
|
|
|
|
<BlueText>{loc.settings.total_balance_explanation}</BlueText>
|
|
|
|
</BlueCard>
|
|
|
|
</>
|
|
|
|
)}
|
2020-10-10 21:19:42 +02:00
|
|
|
<BlueSpacing20 />
|
2021-05-07 17:55:17 +02:00
|
|
|
|
|
|
|
<BlueSpacing20 />
|
2023-12-16 22:44:35 +01:00
|
|
|
<ListItem title={loc.settings.privacy_system_settings} chevron onPress={openApplicationSettings} testID="PrivacySystemSettings" />
|
2020-10-10 21:19:42 +02:00
|
|
|
<BlueSpacing20 />
|
|
|
|
</ScrollView>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
root: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2023-10-23 20:50:17 +02:00
|
|
|
widgetsHeader: {
|
|
|
|
fontWeight: 'bold',
|
|
|
|
fontSize: 30,
|
|
|
|
marginLeft: 17,
|
|
|
|
},
|
2020-10-10 21:19:42 +02:00
|
|
|
});
|
|
|
|
|
2023-10-23 20:50:17 +02:00
|
|
|
SettingsPrivacy.navigationOptions = navigationStyle({ headerLargeTitle: true }, opts => ({ ...opts, title: loc.settings.privacy }));
|
2020-10-10 21:19:42 +02:00
|
|
|
|
|
|
|
export default SettingsPrivacy;
|