diff --git a/App.tsx b/App.tsx index 5e30811..e87a205 100644 --- a/App.tsx +++ b/App.tsx @@ -1,4 +1,5 @@ -import AsyncStorage from '@react-native-async-storage/async-storage'; +import {useAsyncStorage} from '@react-native-async-storage/async-storage'; +import Ionicon from 'react-native-vector-icons/Ionicons'; import {createMaterialTopTabNavigator} from '@react-navigation/material-top-tabs'; import { DarkTheme, @@ -7,6 +8,11 @@ import { } from '@react-navigation/native'; import React, {useEffect} from 'react'; import {StatusBar, useColorScheme} from 'react-native'; +import { + DarkTheme as DarkThemePaper, + DefaultTheme as DefaultThemePaper, + Provider, +} from 'react-native-paper'; import {setupSchema} from './db'; import Exercises from './Exercises'; import Home from './Home'; @@ -25,23 +31,38 @@ setupSchema(); const App = () => { const dark = useColorScheme() === 'dark'; + const {getItem: getMinutes, setItem: setMinutes} = useAsyncStorage('minutes'); + const {getItem: getSeconds, setItem: setSeconds} = useAsyncStorage('seconds'); + const {getItem: getAlarmEnabled, setItem: setAlarmEnabled} = + useAsyncStorage('alarmEnabled'); + + const defaults = async () => { + const minutes = await getMinutes(); + if (minutes === null) await setMinutes('3'); + const seconds = await getSeconds(); + if (seconds === null) await setSeconds('30'); + const alarmEnabled = await getAlarmEnabled(); + if (alarmEnabled === null) await setAlarmEnabled('false'); + }; useEffect(() => { - AsyncStorage.getItem('minutes').then(async minutes => { - if (!minutes) await AsyncStorage.setItem('minutes', '3'); - }); + defaults(); }, []); return ( - - - - - - - - - + }}> + + + + + + + + + + ); }; diff --git a/BatteryDialog.tsx b/BatteryDialog.tsx new file mode 100644 index 0000000..00e8564 --- /dev/null +++ b/BatteryDialog.tsx @@ -0,0 +1,33 @@ +import React from 'react'; +import {NativeModules, Text} from 'react-native'; +import {Button, Dialog, Portal} from 'react-native-paper'; + +export default function BatteryDialog({ + show, + setShow, +}: { + show: boolean; + setShow: (show: boolean) => void; +}) { + const ok = () => { + NativeModules.AlarmModule.openBatteryOptimizations(); + setShow(false); + }; + + return ( + + setShow(false)}> + Battery optimizations + + + Disable battery optimizations for Massive to use rest timers. Settings -> Apps -> Massive -> Battery -> Unrestricted. + + + + + + + + + ); +} diff --git a/EditPlan.tsx b/EditPlan.tsx index 1c04ae4..2ab948e 100644 --- a/EditPlan.tsx +++ b/EditPlan.tsx @@ -1,6 +1,6 @@ import React, {useEffect, useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; -import {Button, Modal, Portal, TextInput} from 'react-native-paper'; +import {Button, Dialog, Modal, Portal, TextInput} from 'react-native-paper'; import DayMenu from './DayMenu'; import WorkoutMenu from './WorkoutMenu'; import {getDb} from './db'; @@ -85,12 +85,9 @@ export default function EditPlan({ return ( - setShow(false)}> - {id ? `Edit "${days}"` : 'Add a plan'} - + setShow(false)}> + {id ? `Edit "${days}"` : 'Add a plan'} + {days.split(',').map((day, index) => ( ))} - - + + - {id && ( - - )} - - + + ); } - -const styles = StyleSheet.create({ - modal: { - backgroundColor: 'black', - padding: 20, - }, - text: { - marginBottom: 10, - }, - bottom: { - flexDirection: 'row', - marginTop: 10, - }, - title: { - fontSize: 20, - marginBottom: 10, - }, -}); diff --git a/EditSet.tsx b/EditSet.tsx index 9e03ff7..0181d18 100644 --- a/EditSet.tsx +++ b/EditSet.tsx @@ -1,6 +1,6 @@ import React, {useEffect, useRef, useState} from 'react'; import {StyleSheet, Text, View} from 'react-native'; -import {Button, Modal, Portal, TextInput} from 'react-native-paper'; +import {Button, Dialog, Modal, Portal, TextInput} from 'react-native-paper'; import {getDb} from './db'; import Set from './set'; import {format} from 'date-fns'; @@ -62,75 +62,62 @@ export default function EditSet({ return ( - setShow(false)}> - {id ? `Edit "${name}"` : 'Add a set'} - repsRef.current?.focus()} - /> - weightRef.current?.focus()} - /> - - - {format(created, 'PPPP p')} - - + setShow(false)}> + {id ? `Edit "${name}"` : 'Add a set'} + + repsRef.current?.focus()} + /> + weightRef.current?.focus()} + /> + + + {format(created, 'PPPP p')} + + - {id && ( - - )} - - + + + ); } const styles = StyleSheet.create({ - modal: { - backgroundColor: 'black', - padding: 20, - }, text: { marginBottom: 10, }, - bottom: { - flexDirection: 'row', - }, title: { fontSize: 20, marginBottom: 10, diff --git a/Home.tsx b/Home.tsx index e752470..0a6dd07 100644 --- a/Home.tsx +++ b/Home.tsx @@ -86,15 +86,13 @@ export default function Home() { refreshing={refreshing} onRefresh={refresh} /> - - setId(undefined)} - id={id} - show={showEdit} - setShow={setShowEdit} - onSave={save} - /> - + setId(undefined)} + id={id} + show={showEdit} + setShow={setShowEdit} + onSave={save} + /> (''); const [alarmEnabled, setAlarmEnabled] = useState(true); const [snackbar, setSnackbar] = useState(''); + const [showBattery, setShowBattery] = useState(false); useEffect(() => { (async () => { @@ -43,6 +45,16 @@ export default function Settings({ NativeModules.ImportModule.sets(); }; + const changeAlarmEnabled = (enabled: boolean) => { + if (!enabled) return setAlarmEnabled(enabled); + NativeModules.AlarmModule.ignoringBatteryOptimizations( + (ignoring: boolean) => { + if (ignoring) return setAlarmEnabled(true); + setShowBattery(true); + }, + ); + }; + return (