Disable new record notifications by default
This commit is contained in:
parent
c636b3c802
commit
4967cbf728
2
App.tsx
2
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(`
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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<string>('');
|
||||
const [maxSets, setMaxSets] = useState<string>('3');
|
||||
const [seconds, setSeconds] = useState<string>('');
|
||||
const [alarm, setAlarm] = useState<boolean>(false);
|
||||
const [predictive, setPredictive] = useState<boolean>(false);
|
||||
const [alarm, setAlarm] = useState(false);
|
||||
const [predict, setPredict] = useState(false);
|
||||
const [sound, setSound] = useState<string>('');
|
||||
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: (
|
||||
<>
|
||||
<Text style={styles.text}>Predictive sets</Text>
|
||||
<Text style={styles.text}>Predict sets</Text>
|
||||
<MassiveSwitch
|
||||
style={[styles.text, {alignSelf: 'flex-start'}]}
|
||||
value={predictive}
|
||||
onValueChange={changePredictive}
|
||||
value={predict}
|
||||
onValueChange={changePredict}
|
||||
/>
|
||||
</>
|
||||
),
|
||||
},
|
||||
{
|
||||
name: 'Record notifications',
|
||||
element: (
|
||||
<>
|
||||
<Text style={styles.text}>Record notifications</Text>
|
||||
<MassiveSwitch
|
||||
style={[styles.text, {alignSelf: 'flex-start'}]}
|
||||
value={notify}
|
||||
onValueChange={changeNotify}
|
||||
/>
|
||||
</>
|
||||
),
|
||||
|
@ -184,11 +208,15 @@ export default function SettingsPage() {
|
|||
value={search}
|
||||
onChangeText={setSearch}
|
||||
/>
|
||||
<ScrollView>
|
||||
{items
|
||||
.filter(item => item.name.toLowerCase().includes(search.toLowerCase()))
|
||||
.filter(item =>
|
||||
item.name.toLowerCase().includes(search.toLowerCase()),
|
||||
)
|
||||
.map(item => (
|
||||
<React.Fragment key={item.name}>{item.element}</React.Fragment>
|
||||
))}
|
||||
</ScrollView>
|
||||
<ConfirmDialog
|
||||
title="Battery optimizations"
|
||||
show={battery}
|
||||
|
|
4
db.ts
4
db.ts
|
@ -47,3 +47,7 @@ export const createWorkouts = `
|
|||
export const addHidden = `
|
||||
ALTER TABLE sets ADD COLUMN hidden DEFAULT false;
|
||||
`;
|
||||
|
||||
export const addNotify = `
|
||||
ALTER TABLE settings ADD COLUMN notify DEFAULT false;
|
||||
`;
|
||||
|
|
|
@ -6,4 +6,5 @@ export default interface Settings {
|
|||
predict: number;
|
||||
sets: number;
|
||||
sound: string;
|
||||
notify: number;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user