Merge branch 'master' into 117-implement-pain
This commit is contained in:
+17
-16
@@ -10,6 +10,7 @@ import Chart from './chart/chart'
|
||||
import Settings from './settings'
|
||||
import Stats from './stats'
|
||||
import {headerTitles as titles} from './labels'
|
||||
import setupNotifications from '../lib/notifications'
|
||||
|
||||
const isSymptomView = name => Object.keys(symptomViews).indexOf(name) > -1
|
||||
|
||||
@@ -19,28 +20,28 @@ export default class App extends Component {
|
||||
this.state = {
|
||||
currentPage: 'Home'
|
||||
}
|
||||
|
||||
const handleBackButtonPress = function() {
|
||||
if (this.state.currentPage === 'Home') return false
|
||||
if (isSymptomView(this.state.currentPage)) {
|
||||
this.navigate('CycleDay', {cycleDay: this.state.currentProps.cycleDay})
|
||||
} else {
|
||||
this.navigate('Home')
|
||||
}
|
||||
return true
|
||||
}.bind(this)
|
||||
|
||||
this.backHandler = BackHandler.addEventListener('hardwareBackPress', handleBackButtonPress)
|
||||
this.backHandler = BackHandler.addEventListener('hardwareBackPress', this.handleBackButtonPress)
|
||||
setupNotifications(this.navigate)
|
||||
}
|
||||
|
||||
componentWillUnmount() {
|
||||
this.backHandler.remove()
|
||||
}
|
||||
|
||||
navigate(pageName, props) {
|
||||
navigate = (pageName, props) => {
|
||||
this.setState({currentPage: pageName, currentProps: props})
|
||||
}
|
||||
|
||||
handleBackButtonPress = () => {
|
||||
if (this.state.currentPage === 'Home') return false
|
||||
if (isSymptomView(this.state.currentPage)) {
|
||||
this.navigate('CycleDay', { cycleDay: this.state.currentProps.cycleDay })
|
||||
} else {
|
||||
this.navigate('Home')
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
render() {
|
||||
const page = {
|
||||
Home, Calendar, CycleDay, Chart, Settings, Stats, ...symptomViews
|
||||
@@ -51,14 +52,14 @@ export default class App extends Component {
|
||||
{this.state.currentPage != 'CycleDay' && <Header title={titles[this.state.currentPage]} />}
|
||||
|
||||
{React.createElement(page, {
|
||||
navigate: this.navigate.bind(this),
|
||||
navigate: this.navigate,
|
||||
...this.state.currentProps
|
||||
})}
|
||||
|
||||
{!isSymptomView(this.state.currentPage) &&
|
||||
<Menu navigate={this.navigate.bind(this)} />
|
||||
<Menu navigate={this.navigate} />
|
||||
}
|
||||
</View>
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ export default class CalendarView extends Component {
|
||||
bleedingDaysSortedByDate.removeListener(this.setStateWithCalFormattedDays)
|
||||
}
|
||||
|
||||
passDateToDayView(result) {
|
||||
passDateToDayView = (result) => {
|
||||
const cycleDay = getOrCreateCycleDay(result.dateString)
|
||||
const navigate = this.props.navigate
|
||||
navigate('CycleDay', { cycleDay })
|
||||
@@ -34,7 +34,7 @@ export default class CalendarView extends Component {
|
||||
render() {
|
||||
return (
|
||||
<CalendarList
|
||||
onDayPress={this.passDateToDayView.bind(this)}
|
||||
onDayPress={this.passDateToDayView}
|
||||
markedDates={this.state.bleedingDaysInCalFormat}
|
||||
markingType={'period'}
|
||||
/>
|
||||
|
||||
@@ -33,7 +33,7 @@ export default class CycleDayOverView extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
goToCycleDay(target) {
|
||||
goToCycleDay = (target) => {
|
||||
const localDate = LocalDate.parse(this.state.cycleDay.date)
|
||||
const targetDate = target === 'before' ?
|
||||
localDate.minusDays(1).toString() :
|
||||
@@ -57,7 +57,7 @@ export default class CycleDayOverView extends Component {
|
||||
isCycleDayOverView={true}
|
||||
cycleDayNumber={cycleDayNumber}
|
||||
date={cycleDay.date}
|
||||
goToCycleDay={this.goToCycleDay.bind(this)}
|
||||
goToCycleDay={this.goToCycleDay}
|
||||
/>
|
||||
<ScrollView>
|
||||
<View style={styles.symptomBoxesView}>
|
||||
|
||||
@@ -42,6 +42,12 @@ export const settings = {
|
||||
max: 'Max',
|
||||
loadError: 'Could not load saved temperature scale settings',
|
||||
saveError: 'Could not save temperature scale settings'
|
||||
},
|
||||
tempReminder: {
|
||||
title: 'Temperature reminder',
|
||||
noTimeSet: 'Set a time for a daily reminder to take your temperature',
|
||||
timeSet: time => `Daily reminder set for ${time}`,
|
||||
notification: 'Record your morning temperature'
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -8,7 +8,7 @@ import styles, { iconStyles } from '../styles'
|
||||
import Icon from 'react-native-vector-icons/MaterialCommunityIcons'
|
||||
|
||||
export default class Menu extends Component {
|
||||
makeMenuItem({ title, icon, onPress}, i) {
|
||||
makeMenuItem = ({ title, icon, onPress}, i) => {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
onPress={onPress}
|
||||
@@ -36,7 +36,7 @@ export default class Menu extends Component {
|
||||
{ title: 'Chart', icon: 'chart-line', onPress: () => this.goTo('Chart') },
|
||||
{ title: 'Stats', icon: 'chart-pie', onPress: () => this.goTo('Stats') },
|
||||
{ title: 'Settings', icon: 'settings', onPress: () => this.goTo('Settings') },
|
||||
].map(this.makeMenuItem.bind(this))}
|
||||
].map(this.makeMenuItem)}
|
||||
</View >
|
||||
)
|
||||
}
|
||||
|
||||
+111
-28
@@ -4,53 +4,66 @@ import {
|
||||
TouchableOpacity,
|
||||
ScrollView,
|
||||
Alert,
|
||||
Text
|
||||
Text,
|
||||
Switch
|
||||
} from 'react-native'
|
||||
import DateTimePicker from 'react-native-modal-datetime-picker-nevo'
|
||||
import Slider from '@ptomasroos/react-native-multi-slider'
|
||||
import Share from 'react-native-share'
|
||||
import { DocumentPicker, DocumentPickerUtil } from 'react-native-document-picker'
|
||||
import rnfs from 'react-native-fs'
|
||||
import styles, { secondaryColor } from '../styles/index'
|
||||
import config from '../config'
|
||||
import { settings as settingsLabels, shared as sharedLabels } from './labels'
|
||||
import { settings as labels, shared as sharedLabels } from './labels'
|
||||
import getDataAsCsvDataUri from '../lib/import-export/export-to-csv'
|
||||
import importCsv from '../lib/import-export/import-from-csv'
|
||||
import { scaleObservable, saveTempScale } from '../local-storage'
|
||||
import {
|
||||
scaleObservable,
|
||||
saveTempScale,
|
||||
tempReminderObservable,
|
||||
saveTempReminder
|
||||
} from '../local-storage'
|
||||
|
||||
export default class Settings extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = {}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<ScrollView>
|
||||
<TempReminderPicker/>
|
||||
<View style={styles.settingsSegment}>
|
||||
<Text style={styles.settingsSegmentTitle}>
|
||||
{settingsLabels.tempScale.segmentTitle}
|
||||
{labels.tempScale.segmentTitle}
|
||||
</Text>
|
||||
<Text>{settingsLabels.tempScale.segmentExplainer}</Text>
|
||||
<Text>{labels.tempScale.segmentExplainer}</Text>
|
||||
<TempSlider/>
|
||||
</View>
|
||||
<View style={styles.settingsSegment}>
|
||||
<Text style={styles.settingsSegmentTitle}>
|
||||
{settingsLabels.export.button}
|
||||
{labels.export.button}
|
||||
</Text>
|
||||
<Text>{settingsLabels.export.segmentExplainer}</Text>
|
||||
<Text>{labels.export.segmentExplainer}</Text>
|
||||
<TouchableOpacity
|
||||
onPress={openShareDialogAndExport}
|
||||
style={styles.settingsButton}>
|
||||
<Text style={styles.settingsButtonText}>
|
||||
{settingsLabels.export.button}
|
||||
{labels.export.button}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
<View style={styles.settingsSegment}>
|
||||
<Text style={styles.settingsSegmentTitle}>
|
||||
{settingsLabels.import.button}
|
||||
{labels.import.button}
|
||||
</Text>
|
||||
<Text>{settingsLabels.import.segmentExplainer}</Text>
|
||||
<Text>{labels.import.segmentExplainer}</Text>
|
||||
<TouchableOpacity
|
||||
onPress={openImportDialogAndImport}
|
||||
style={styles.settingsButton}>
|
||||
<Text style={styles.settingsButtonText}>
|
||||
{settingsLabels.import.button}
|
||||
{labels.import.button}
|
||||
</Text>
|
||||
</TouchableOpacity>
|
||||
</View>
|
||||
@@ -59,6 +72,66 @@ export default class Settings extends Component {
|
||||
}
|
||||
}
|
||||
|
||||
class TempReminderPicker extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
this.state = Object.assign({}, tempReminderObservable.value)
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<TouchableOpacity
|
||||
style={styles.settingsSegment}
|
||||
onPress={() => this.setState({ isTimePickerVisible: true })}
|
||||
>
|
||||
<Text style={styles.settingsSegmentTitle}>
|
||||
{labels.tempReminder.title}
|
||||
</Text>
|
||||
<View style={{ flexDirection: 'row', alignItems: 'center' }}>
|
||||
<View style={{ flex: 1 }}>
|
||||
{this.state.time && this.state.enabled ?
|
||||
<Text>{labels.tempReminder.timeSet(this.state.time)}</Text>
|
||||
:
|
||||
<Text>{labels.tempReminder.noTimeSet}</Text>
|
||||
}
|
||||
</View>
|
||||
<Switch
|
||||
value={this.state.enabled}
|
||||
onValueChange={switchOn => {
|
||||
this.setState({ enabled: switchOn })
|
||||
if (switchOn && !this.state.time) {
|
||||
this.setState({ isTimePickerVisible: true })
|
||||
}
|
||||
if (!switchOn) saveTempReminder({ enabled: false })
|
||||
}}
|
||||
onTintColor={secondaryColor}
|
||||
/>
|
||||
<DateTimePicker
|
||||
mode="time"
|
||||
isVisible={this.state.isTimePickerVisible}
|
||||
onConfirm={jsDate => {
|
||||
const time = padWithZeros(`${jsDate.getHours()}:${jsDate.getMinutes()}`)
|
||||
this.setState({
|
||||
time,
|
||||
isTimePickerVisible: false,
|
||||
enabled: true
|
||||
})
|
||||
saveTempReminder({
|
||||
time,
|
||||
enabled: true
|
||||
})
|
||||
}}
|
||||
onCancel={() => {
|
||||
this.setState({ isTimePickerVisible: false })
|
||||
if (!this.state.time) this.setState({enabled: false})
|
||||
}}
|
||||
/>
|
||||
</View>
|
||||
</TouchableOpacity>
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
class TempSlider extends Component {
|
||||
constructor(props) {
|
||||
super(props)
|
||||
@@ -80,15 +153,15 @@ class TempSlider extends Component {
|
||||
try {
|
||||
saveTempScale(this.state)
|
||||
} catch(err) {
|
||||
alertError(settingsLabels.tempScale.saveError)
|
||||
alertError(labels.tempScale.saveError)
|
||||
}
|
||||
}
|
||||
|
||||
render() {
|
||||
return (
|
||||
<View style={{alignItems: 'center'}}>
|
||||
<Text>{`${settingsLabels.tempScale.min} ${this.state.min}`}</Text>
|
||||
<Text>{`${settingsLabels.tempScale.max} ${this.state.max}`}</Text>
|
||||
<View style={{ alignItems: 'center' }}>
|
||||
<Text>{`${labels.tempScale.min} ${this.state.min}`}</Text>
|
||||
<Text>{`${labels.tempScale.max} ${this.state.max}`}</Text>
|
||||
<Slider
|
||||
values={[this.state.min, this.state.max]}
|
||||
min={config.temperatureScale.min}
|
||||
@@ -103,7 +176,7 @@ class TempSlider extends Component {
|
||||
backgroundColor: 'silver',
|
||||
}}
|
||||
trackStyle={{
|
||||
height:10,
|
||||
height: 10,
|
||||
}}
|
||||
markerStyle={{
|
||||
backgroundColor: secondaryColor,
|
||||
@@ -123,36 +196,36 @@ async function openShareDialogAndExport() {
|
||||
try {
|
||||
data = getDataAsCsvDataUri()
|
||||
if (!data) {
|
||||
return alertError(settingsLabels.errors.noData)
|
||||
return alertError(labels.errors.noData)
|
||||
}
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return alertError(settingsLabels.errors.couldNotConvert)
|
||||
return alertError(labels.errors.couldNotConvert)
|
||||
}
|
||||
|
||||
try {
|
||||
await Share.open({
|
||||
title: settingsLabels.export.title,
|
||||
title: labels.export.title,
|
||||
url: data,
|
||||
subject: settingsLabels.export.subject,
|
||||
subject: labels.export.subject,
|
||||
type: 'text/csv',
|
||||
showAppsToView: true
|
||||
})
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
return alertError(settingsLabels.export.errors.problemSharing)
|
||||
return alertError(labels.export.errors.problemSharing)
|
||||
}
|
||||
}
|
||||
|
||||
function openImportDialogAndImport() {
|
||||
Alert.alert(
|
||||
settingsLabels.import.title,
|
||||
settingsLabels.import.message,
|
||||
labels.import.title,
|
||||
labels.import.message,
|
||||
[{
|
||||
text: settingsLabels.import.replaceOption,
|
||||
text: labels.import.replaceOption,
|
||||
onPress: () => getFileContentAndImport({ deleteExisting: false })
|
||||
}, {
|
||||
text: settingsLabels.import.deleteOption,
|
||||
text: labels.import.deleteOption,
|
||||
onPress: () => getFileContentAndImport({ deleteExisting: true })
|
||||
}, {
|
||||
text: sharedLabels.cancel, style: 'cancel', onPress: () => { }
|
||||
@@ -180,12 +253,12 @@ async function getFileContentAndImport({ deleteExisting }) {
|
||||
try {
|
||||
fileContent = await rnfs.readFile(fileInfo.uri, 'utf8')
|
||||
} catch (err) {
|
||||
return importError(settingsLabels.import.errors.couldNotOpenFile)
|
||||
return importError(labels.import.errors.couldNotOpenFile)
|
||||
}
|
||||
|
||||
try {
|
||||
await importCsv(fileContent, deleteExisting)
|
||||
Alert.alert(sharedLabels.successTitle, settingsLabels.import.success.message)
|
||||
Alert.alert(sharedLabels.successTitle, labels.import.success.message)
|
||||
} catch(err) {
|
||||
importError(err.message)
|
||||
}
|
||||
@@ -196,6 +269,16 @@ function alertError(msg) {
|
||||
}
|
||||
|
||||
function importError(msg) {
|
||||
const postFixed = `${msg}\n\n${settingsLabels.import.errors.postFix}`
|
||||
const postFixed = `${msg}\n\n${labels.import.errors.postFix}`
|
||||
alertError(postFixed)
|
||||
}
|
||||
|
||||
function padWithZeros(time) {
|
||||
const vals = time.split(':')
|
||||
return vals.map(val => {
|
||||
if (parseInt(val) < 10) {
|
||||
val = `0${val}`
|
||||
}
|
||||
return val
|
||||
}).join(':')
|
||||
}
|
||||
Reference in New Issue
Block a user