Use rn-push-notifications and set up recurring notification

This commit is contained in:
Julia Friesel
2018-08-27 14:31:28 +02:00
parent e64b46c41b
commit eb41ae354f
9 changed files with 172 additions and 121 deletions
+24 -19
View File
@@ -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)
})
}