From 4967cbf728af7bb01214b5c40741cf56b9fc1c8d Mon Sep 17 00:00:00 2001 From: Brandon Presley Date: Sat, 27 Aug 2022 18:08:23 +1200 Subject: [PATCH] Disable new record notifications by default --- App.tsx | 2 ++ EditSet.tsx | 5 +++- SettingsPage.tsx | 72 +++++++++++++++++++++++++++++++++--------------- db.ts | 4 +++ settings.ts | 1 + 5 files changed, 61 insertions(+), 23 deletions(-) diff --git a/App.tsx b/App.tsx index b87d7bf..15722b4 100644 --- a/App.tsx +++ b/App.tsx @@ -16,6 +16,7 @@ import {SQLiteDatabase} from 'react-native-sqlite-storage'; import Ionicon from 'react-native-vector-icons/Ionicons'; import { addHidden, + addNotify, addSound, createPlans, createSets, @@ -72,6 +73,7 @@ const App = () => { await _db.executeSql(addSound).catch(() => null); await _db.executeSql(createWorkouts); await _db.executeSql(addHidden).catch(() => null); + await _db.executeSql(addNotify).catch(() => null); const [result] = await _db.executeSql(`SELECT * FROM settings LIMIT 1`); if (result.rows.length === 0) return _db.executeSql(` diff --git a/EditSet.tsx b/EditSet.tsx index 8f4d0bf..9103d7d 100644 --- a/EditSet.tsx +++ b/EditSet.tsx @@ -5,7 +5,7 @@ import { useRoute, } from '@react-navigation/native'; import React, {useCallback, useContext} from 'react'; -import {NativeModules, View} from 'react-native'; +import {NativeModules, PermissionsAndroid, View} from 'react-native'; import {IconButton} from 'react-native-paper'; import {DatabaseContext, SnackbarContext} from './App'; import {HomePageParams} from './HomePage'; @@ -64,6 +64,9 @@ export default function EditSet() { `; startTimer(); await db.executeSql(insert, [name, reps, weight, unit]); + const [result] = await db.executeSql(`SELECT * FROM settings LIMIT 1`); + const settings: Settings = result.rows.item(0); + if (settings.notify === 0) return navigation.goBack(); if ( weight > params.set.weight || (reps > params.set.reps && weight === params.set.weight) diff --git a/SettingsPage.tsx b/SettingsPage.tsx index abf3cb2..6b0b8d8 100644 --- a/SettingsPage.tsx +++ b/SettingsPage.tsx @@ -5,7 +5,7 @@ import React, { useEffect, useState, } from 'react'; -import {NativeModules, StyleSheet, Text, View} from 'react-native'; +import {NativeModules, ScrollView, StyleSheet, Text, View} from 'react-native'; import DocumentPicker from 'react-native-document-picker'; import {Button, Searchbar} from 'react-native-paper'; import {DatabaseContext, SnackbarContext} from './App'; @@ -19,9 +19,10 @@ export default function SettingsPage() { const [minutes, setMinutes] = useState(''); const [maxSets, setMaxSets] = useState('3'); const [seconds, setSeconds] = useState(''); - const [alarm, setAlarm] = useState(false); - const [predictive, setPredictive] = useState(false); + const [alarm, setAlarm] = useState(false); + const [predict, setPredict] = useState(false); const [sound, setSound] = useState(''); + const [notify, setNotify] = useState(false); const [battery, setBattery] = useState(false); const [ignoring, setIgnoring] = useState(false); const [search, setSearch] = useState(''); @@ -35,7 +36,7 @@ export default function SettingsPage() { setMinutes(settings.minutes.toString()); setSeconds(settings.seconds.toString()); setAlarm(!!settings.alarm); - setPredictive(!!settings.predict); + setPredict(!!settings.predict); setMaxSets(settings.sets.toString()); setVibrate(!!settings.vibrate); setSound(settings.sound); @@ -48,32 +49,34 @@ export default function SettingsPage() { useEffect(() => { db.executeSql( - `UPDATE settings SET vibrate=?,minutes=?,sets=?,seconds=?,alarm=?,predict=?,sound=?`, - [vibrate, minutes, maxSets, seconds, alarm, predictive, sound], + `UPDATE settings SET vibrate=?,minutes=?,sets=?,seconds=?,alarm=?,predict=?,sound=?,notify=?`, + [vibrate, minutes, maxSets, seconds, alarm, predict, sound, notify], ); - }, [vibrate, minutes, maxSets, seconds, alarm, predictive, sound, db]); + }, [vibrate, minutes, maxSets, seconds, alarm, predict, sound, notify, db]); const changeAlarmEnabled = useCallback( (enabled: boolean) => { setAlarm(enabled); + toast('Time your rest duration after each set.', 4000); if (enabled && !ignoring) setBattery(true); }, - [setBattery, ignoring], + [setBattery, ignoring, toast], ); - const changePredictive = useCallback( + const changePredict = useCallback( (enabled: boolean) => { - setPredictive(enabled); - toast('Predictive sets guess whats next based on todays plan.', 7000); + setPredict(enabled); + toast('Predict your next set based on todays plan.', 4000); }, - [setPredictive, toast], + [setPredict, toast], ); const changeVibrate = useCallback( (value: boolean) => { setVibrate(value); + toast('When a timer completes, vibrate your phone.', 4000); }, - [setVibrate], + [setVibrate, toast], ); const changeSound = useCallback(async () => { @@ -84,6 +87,14 @@ export default function SettingsPage() { if (fileCopyUri) setSound(fileCopyUri); }, []); + const changeNotify = useCallback( + (value: boolean) => { + setNotify(value); + toast('If a set is a new record, show a notification.', 4000); + }, + [toast], + ); + const items: {name: string; element: ReactNode}[] = [ { name: 'Sets per workout', @@ -153,14 +164,27 @@ export default function SettingsPage() { ), }, { - name: 'Predictive sets', + name: 'Predict sets', element: ( <> - Predictive sets + Predict sets + + ), + }, + { + name: 'Record notifications', + element: ( + <> + Record notifications + ), @@ -184,11 +208,15 @@ export default function SettingsPage() { value={search} onChangeText={setSearch} /> - {items - .filter(item => item.name.toLowerCase().includes(search.toLowerCase())) - .map(item => ( - {item.element} - ))} + + {items + .filter(item => + item.name.toLowerCase().includes(search.toLowerCase()), + ) + .map(item => ( + {item.element} + ))} +