|
@@ -1,7 +1,7 @@
|
1
|
1
|
// @flow
|
2
|
2
|
|
3
|
3
|
import * as React from 'react';
|
4
|
|
-import {Alert, View} from 'react-native';
|
|
4
|
+import {Alert, View, Platform} from 'react-native';
|
5
|
5
|
import {Body, Card, CardItem, Left, Right, Text} from 'native-base';
|
6
|
6
|
import ThemeManager from '../utils/ThemeManager';
|
7
|
7
|
import i18n from "i18n-js";
|
|
@@ -10,6 +10,7 @@ import FetchedDataSectionList from "../components/FetchedDataSectionList";
|
10
|
10
|
import NotificationsManager from "../utils/NotificationsManager";
|
11
|
11
|
import PlatformTouchable from "react-native-platform-touchable";
|
12
|
12
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
|
13
|
+import * as Expo from "expo";
|
13
|
14
|
|
14
|
15
|
const DATA_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/dataProxiwash.json";
|
15
|
16
|
|
|
@@ -76,6 +77,24 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
76
|
77
|
};
|
77
|
78
|
}
|
78
|
79
|
|
|
80
|
+ componentDidMount() {
|
|
81
|
+ if (Platform.OS === 'android') {
|
|
82
|
+ Expo.Notifications.createChannelAndroidAsync('reminders', {
|
|
83
|
+ name: 'Reminders',
|
|
84
|
+ priority: 'max',
|
|
85
|
+ vibrate: [0, 250, 250, 250],
|
|
86
|
+ });
|
|
87
|
+ }
|
|
88
|
+ // Remove machine from watch list when receiving last notification
|
|
89
|
+ Expo.Notifications.addListener((notification) => {
|
|
90
|
+ if (notification.data !== undefined) {
|
|
91
|
+ if (this.isMachineWatched(notification.data.id) && notification.data.isMachineFinished === true) {
|
|
92
|
+ this.removeNotificationFromPrefs(this.getMachineIndexInWatchList(notification.data.id));
|
|
93
|
+ }
|
|
94
|
+ }
|
|
95
|
+ });
|
|
96
|
+ }
|
|
97
|
+
|
79
|
98
|
getHeaderTranslation() {
|
80
|
99
|
return i18n.t("screens.proxiwash");
|
81
|
100
|
}
|
|
@@ -128,7 +147,9 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
128
|
147
|
let endNotificationID = await NotificationsManager.scheduleNotification(
|
129
|
148
|
i18n.t('proxiwashScreen.notifications.machineFinishedTitle'),
|
130
|
149
|
i18n.t('proxiwashScreen.notifications.machineFinishedBody', {number: machineId}),
|
131
|
|
- new Date().getTime() + remainingTime * (60 * 1000) // Convert back to milliseconds
|
|
150
|
+ new Date().getTime() + remainingTime * (60 * 1000), // Convert back to milliseconds
|
|
151
|
+ {id: machineId, isMachineFinished: true},
|
|
152
|
+ 'reminders'
|
132
|
153
|
);
|
133
|
154
|
let reminderNotificationID = await ProxiwashScreen.setupReminderNotification(machineId, remainingTime);
|
134
|
155
|
this.saveNotificationToPrefs(machineId, endNotificationID, reminderNotificationID);
|
|
@@ -143,7 +164,9 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
143
|
164
|
reminderNotificationID = await NotificationsManager.scheduleNotification(
|
144
|
165
|
i18n.t('proxiwashScreen.notifications.machineRunningTitle', {time: reminderNotificationTime}),
|
145
|
166
|
i18n.t('proxiwashScreen.notifications.machineRunningBody', {number: machineId}),
|
146
|
|
- new Date().getTime() + (remainingTime - reminderNotificationTime) * (60 * 1000) // Convert back to milliseconds
|
|
167
|
+ new Date().getTime() + (remainingTime - reminderNotificationTime) * (60 * 1000), // Convert back to milliseconds
|
|
168
|
+ {id: machineId, isMachineFinished: false},
|
|
169
|
+ 'reminders'
|
147
|
170
|
);
|
148
|
171
|
}
|
149
|
172
|
return reminderNotificationID;
|
|
@@ -166,12 +189,9 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
166
|
189
|
* @param machineId The machine's ID
|
167
|
190
|
*/
|
168
|
191
|
disableNotification(machineId: string) {
|
169
|
|
- let data: Object = this.state.machinesWatched;
|
|
192
|
+ let data = this.state.machinesWatched;
|
170
|
193
|
if (data.length > 0) {
|
171
|
|
- let elem = this.state.machinesWatched.find(function (elem) {
|
172
|
|
- return elem.machineNumber === machineId
|
173
|
|
- });
|
174
|
|
- let arrayIndex = data.indexOf(elem);
|
|
194
|
+ let arrayIndex = this.getMachineIndexInWatchList(machineId);
|
175
|
195
|
if (arrayIndex !== -1) {
|
176
|
196
|
NotificationsManager.cancelScheduledNotification(data[arrayIndex].endNotificationID);
|
177
|
197
|
if (data[arrayIndex].reminderNotificationID !== null)
|
|
@@ -181,6 +201,13 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
181
|
201
|
}
|
182
|
202
|
}
|
183
|
203
|
|
|
204
|
+ getMachineIndexInWatchList(machineId: string) {
|
|
205
|
+ let elem = this.state.machinesWatched.find(function (elem) {
|
|
206
|
+ return elem.machineNumber === machineId
|
|
207
|
+ });
|
|
208
|
+ return this.state.machinesWatched.indexOf(elem);
|
|
209
|
+ }
|
|
210
|
+
|
184
|
211
|
saveNotificationToPrefs(machineId: string, endNotificationID: string, reminderNotificationID: string | null) {
|
185
|
212
|
let data = this.state.machinesWatched;
|
186
|
213
|
data.push({
|