2022-12-02 01:48:10 +00:00
|
|
|
import {useFocusEffect} from '@react-navigation/native'
|
|
|
|
import React, {useCallback, useMemo, useState} from 'react'
|
2022-11-10 02:15:27 +00:00
|
|
|
import {Dimensions, NativeModules, View} from 'react-native'
|
2022-11-07 23:58:16 +00:00
|
|
|
import {Button, Text, useTheme} from 'react-native-paper'
|
2022-11-05 01:40:06 +00:00
|
|
|
import {ProgressCircle} from 'react-native-svg-charts'
|
2022-12-29 00:57:19 +00:00
|
|
|
import AppFab from './AppFab'
|
2022-11-04 23:57:08 +00:00
|
|
|
import {MARGIN, PADDING} from './constants'
|
2022-11-03 07:04:15 +00:00
|
|
|
import {settingsRepo} from './db'
|
|
|
|
import DrawerHeader from './DrawerHeader'
|
|
|
|
import Settings from './settings'
|
2022-11-10 02:15:27 +00:00
|
|
|
import useTimer from './use-timer'
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-11-10 02:15:27 +00:00
|
|
|
export interface TickEvent {
|
2022-11-03 07:04:15 +00:00
|
|
|
minutes: string
|
|
|
|
seconds: string
|
|
|
|
}
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-11-03 07:04:15 +00:00
|
|
|
export default function TimerPage() {
|
2022-11-10 02:15:27 +00:00
|
|
|
const {minutes, seconds} = useTimer()
|
2022-11-03 07:04:15 +00:00
|
|
|
const [settings, setSettings] = useState<Settings>()
|
2022-11-07 23:58:16 +00:00
|
|
|
const {colors} = useTheme()
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-12-02 01:48:10 +00:00
|
|
|
useFocusEffect(
|
|
|
|
useCallback(() => {
|
|
|
|
settingsRepo.findOne({where: {}}).then(setSettings)
|
|
|
|
}, []),
|
|
|
|
)
|
2022-10-24 01:45:21 +00:00
|
|
|
|
|
|
|
const stop = () => {
|
2022-11-03 07:04:15 +00:00
|
|
|
NativeModules.AlarmModule.stop()
|
|
|
|
}
|
2022-10-24 01:45:21 +00:00
|
|
|
|
|
|
|
const add = async () => {
|
2022-12-02 01:48:10 +00:00
|
|
|
console.log(`${TimerPage.name}.add:`, settings)
|
2022-11-03 08:59:00 +00:00
|
|
|
const params = [settings.vibrate, settings.sound, settings.noSound]
|
|
|
|
NativeModules.AlarmModule.add(...params)
|
2022-11-03 07:04:15 +00:00
|
|
|
}
|
2022-10-24 01:45:21 +00:00
|
|
|
|
2022-11-05 01:40:06 +00:00
|
|
|
const progress = useMemo(() => {
|
|
|
|
return (Number(minutes) * 60 + Number(seconds)) / 210
|
|
|
|
}, [minutes, seconds])
|
|
|
|
|
|
|
|
const left = useMemo(() => {
|
2022-12-24 12:05:48 +00:00
|
|
|
return Dimensions.get('screen').width * 0.5 - 60
|
2022-11-05 01:40:06 +00:00
|
|
|
}, [])
|
|
|
|
|
2022-10-24 01:45:21 +00:00
|
|
|
return (
|
|
|
|
<>
|
|
|
|
<DrawerHeader name="Timer" />
|
2022-11-03 07:04:15 +00:00
|
|
|
<View style={{flexGrow: 1, padding: PADDING}}>
|
2022-10-24 01:45:21 +00:00
|
|
|
<View
|
|
|
|
style={{
|
|
|
|
flex: 1,
|
|
|
|
justifyContent: 'center',
|
|
|
|
alignItems: 'center',
|
|
|
|
}}>
|
2022-12-24 12:05:48 +00:00
|
|
|
<Text style={{fontSize: 70, position: 'absolute'}}>
|
|
|
|
{minutes}:{seconds}
|
|
|
|
</Text>
|
2022-11-05 01:40:06 +00:00
|
|
|
<ProgressCircle
|
2022-12-24 12:05:48 +00:00
|
|
|
style={{height: 300, width: 300, marginBottom: MARGIN}}
|
2022-11-05 01:40:06 +00:00
|
|
|
progress={progress}
|
|
|
|
strokeWidth={10}
|
2022-11-09 00:26:16 +00:00
|
|
|
progressColor={colors.text}
|
2022-11-08 02:50:14 +00:00
|
|
|
backgroundColor={colors.placeholder}
|
2022-11-05 01:40:06 +00:00
|
|
|
/>
|
2022-10-24 01:45:21 +00:00
|
|
|
</View>
|
2022-11-03 07:04:15 +00:00
|
|
|
</View>
|
2022-12-24 12:05:48 +00:00
|
|
|
<Button onPress={add} style={{position: 'absolute', top: '82%', left}}>
|
2022-11-05 01:40:06 +00:00
|
|
|
Add 1 min
|
|
|
|
</Button>
|
2022-12-29 00:57:19 +00:00
|
|
|
<AppFab icon="stop" onPress={stop} />
|
2022-10-24 01:45:21 +00:00
|
|
|
</>
|
2022-11-03 07:04:15 +00:00
|
|
|
)
|
2022-10-24 01:45:21 +00:00
|
|
|
}
|