diff --git a/components/settings/index.js b/components/settings/index.js index bfddbc7026af06dcc27415f631e5dd8c668bb429..b91acbc9aef59de4430bc8f67018556552640a13 100644 --- a/components/settings/index.js +++ b/components/settings/index.js @@ -13,6 +13,7 @@ import TempSlider from './temp-slider' import openImportDialogAndImport from './import-dialog' import openShareDialogAndExport from './export-dialog' import PasswordSetting from './password' +import UseCervixSetting from './use-cervix' export default class Settings extends Component { constructor(props) { @@ -24,6 +25,7 @@ export default class Settings extends Component { return ( <ScrollView> <TempReminderPicker/> + <UseCervixSetting/> <View style={styles.settingsSegment}> <AppText style={styles.settingsSegmentTitle}> {labels.tempScale.segmentTitle} diff --git a/components/settings/use-cervix.js b/components/settings/use-cervix.js new file mode 100644 index 0000000000000000000000000000000000000000..668a0e8268065f8bd5cfd187db8b6d9d2c500081 --- /dev/null +++ b/components/settings/use-cervix.js @@ -0,0 +1,48 @@ +import React, { Component } from 'react' +import { + View, + TouchableOpacity, + Switch +} from 'react-native' +import AppText from '../app-text' +import { + useCervixObservable, + saveUseCervix +} from '../../local-storage' +import styles from '../../styles/index' +import { settings as labels } from '../../i18n/en/settings' + +export default class UseCervixSetting extends Component { + constructor() { + super() + this.state = {useCervix: useCervixObservable.value} + } + + render() { + return ( + <TouchableOpacity + style={styles.settingsSegment} + > + <AppText style={styles.settingsSegmentTitle}> + {labels.useCervix.title} + </AppText> + <View style={{ flexDirection: 'row', alignItems: 'center' }}> + <View style={{ flex: 1 }}> + {this.state.useCervix ? + <AppText>{labels.useCervix.cervixModeOn}</AppText> + : + <AppText>{labels.useCervix.cervixModeOff}</AppText> + } + </View> + <Switch + value={this.state.useCervix} + onValueChange={bool => { + this.setState({ useCervix: bool }) + saveUseCervix(bool) + }} + /> + </View> + </TouchableOpacity> + ) + } +} diff --git a/i18n/en/settings.js b/i18n/en/settings.js index 7b23f67401b3347a8fbddf2e0b4253e84ecdb8a1..eef6615c83f7e59a6502eda61208ab1d828aa811 100644 --- a/i18n/en/settings.js +++ b/i18n/en/settings.js @@ -46,6 +46,11 @@ export const settings = { reminderText: 'Get a notification 3 days before your next period is likely to start.', notification: daysToEndOfPrediction => `Your next period is likely to start in 3 to ${daysToEndOfPrediction} days.` }, + useCervix: { + title: 'Secondary symptom', + cervixModeOn: 'Cervix values are being used for symptothermal fertility detection. You can switch here to use mucus values for symptothermal fertility detection', + cervixModeOff: 'By default, mucus values are being used for symptothermal fertility detection. You can switch here to use cervix values for symptothermal fertility detection' + }, passwordSettings: { title: 'App password', explainerDisabled: "Encrypt the app's database with a password. You need to enter the password every time the app is started.", diff --git a/lib/sympto-adapter.js b/lib/sympto-adapter.js index 821e7c5220b801008401618cd9b9f6adc3cd2c8a..628ea2b97137cd1c07aa87477af406637eb260ab 100644 --- a/lib/sympto-adapter.js +++ b/lib/sympto-adapter.js @@ -1,6 +1,7 @@ import getFertilityStatus from './sympto' import cycleModule from './cycle' import { fertilityStatus } from '../i18n/en/labels' +import { useCervixObservable } from '../local-storage' export function getFertilityStatusForDay(dateString) { const status = getCycleStatusForDay(dateString) @@ -48,6 +49,8 @@ export function getCycleStatusForDay(dateString, opts = {}) { } } + cycleInfo.secondarySymptom = useCervixObservable.value ? 'cervix' : 'mucus' + return getFertilityStatus(cycleInfo) } diff --git a/local-storage/index.js b/local-storage/index.js index 5f4af70e252bc350db736a5729fbb8279b611879..89b37d953a6d6433213faee5e8a4fffad31a31fa 100644 --- a/local-storage/index.js +++ b/local-storage/index.js @@ -44,6 +44,14 @@ export async function savePeriodReminder(reminder) { periodReminderObservable.set(reminder) } +export const useCervixObservable = Observable() +setObvWithInitValue('useCervix', useCervixObservable, false) + +export async function saveUseCervix(bool) { + await AsyncStorage.setItem('useCervix', JSON.stringify(bool)) + useCervixObservable.set(bool) +} + export const hasEncryptionObservable = Observable() setObvWithInitValue('hasEncryption', hasEncryptionObservable, false)