Use rn-push-notifications and set up recurring notification
This commit is contained in:
+24
-19
@@ -1,27 +1,32 @@
|
||||
import {tempReminderObservable} from '../local-storage'
|
||||
import { LocalTime, ChronoUnit } from 'js-joda'
|
||||
import {NotificationsAndroid} from 'react-native-notifications'
|
||||
import Notification from 'react-native-push-notification'
|
||||
import { LocalDate } from 'js-joda'
|
||||
import { settings as labels } from '../components/labels'
|
||||
import { getOrCreateCycleDay } from '../db'
|
||||
|
||||
let stopCheckingTheTime = () => {}
|
||||
|
||||
export default function setupNotifications() {
|
||||
tempReminderObservable(reminder => {
|
||||
stopCheckingTheTime()
|
||||
if (reminder.enabled) {
|
||||
stopCheckingTheTime = notifyAt(reminder.time)
|
||||
export default function setupNotifications(navigate) {
|
||||
Notification.configure({
|
||||
onNotification: () => {
|
||||
const todayDateString = LocalDate.now().toString()
|
||||
const cycleDay = getOrCreateCycleDay(todayDateString)
|
||||
navigate('TemperatureEditView', { cycleDay })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function notifyAt(time) {
|
||||
const id = setInterval(() => {
|
||||
const now = LocalTime.now().truncatedTo(ChronoUnit.MINUTES).toString()
|
||||
if (now === time) {
|
||||
NotificationsAndroid.localNotification({
|
||||
title: 'yo',
|
||||
body: 'much notification'
|
||||
tempReminderObservable(reminder => {
|
||||
Notification.cancelAllLocalNotifications()
|
||||
if (reminder.enabled) {
|
||||
const date = new Date()
|
||||
const [hours, minutes] = reminder.time.split(':')
|
||||
date.setHours(parseInt(hours))
|
||||
date.setMinutes(parseInt(minutes))
|
||||
date.setSeconds(0)
|
||||
Notification.localNotificationSchedule({
|
||||
message: labels.tempReminder.notification,
|
||||
date,
|
||||
vibrate: false,
|
||||
repeatType: 'day'
|
||||
})
|
||||
}
|
||||
}, 60 * 1000)
|
||||
return () => clearInterval(id)
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user