|
@@ -83,6 +83,18 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
83
|
83
|
*/
|
84
|
84
|
componentDidMount() {
|
85
|
85
|
super.componentDidMount();
|
|
86
|
+ // Get latest watchlist from server
|
|
87
|
+ NotificationsManager.getMachineNotificationWatchlist((fetchedList) => {
|
|
88
|
+ this.setState({machinesWatched: fetchedList})
|
|
89
|
+ });
|
|
90
|
+
|
|
91
|
+ // Get updated watchlist after received notification
|
|
92
|
+ Expo.Notifications.addListener((notification) => {
|
|
93
|
+ NotificationsManager.getMachineNotificationWatchlist((fetchedList) => {
|
|
94
|
+ this.setState({machinesWatched: fetchedList})
|
|
95
|
+ });
|
|
96
|
+ });
|
|
97
|
+
|
86
|
98
|
if (Platform.OS === 'android') {
|
87
|
99
|
Expo.Notifications.createChannelAndroidAsync('reminders', {
|
88
|
100
|
name: 'Reminders',
|
|
@@ -137,7 +149,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
137
|
149
|
setupNotifications(machineId: string) {
|
138
|
150
|
if (!this.isMachineWatched(machineId)) {
|
139
|
151
|
NotificationsManager.setupMachineNotification(machineId, true);
|
140
|
|
- this.saveNotificationToPrefs(machineId);
|
|
152
|
+ this.saveNotificationToState(machineId);
|
141
|
153
|
} else
|
142
|
154
|
this.disableNotification(machineId);
|
143
|
155
|
}
|
|
@@ -154,7 +166,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
154
|
166
|
let arrayIndex = data.indexOf(machineId);
|
155
|
167
|
if (arrayIndex !== -1) {
|
156
|
168
|
NotificationsManager.setupMachineNotification(machineId, false);
|
157
|
|
- this.removeNotificationFromPrefs(arrayIndex);
|
|
169
|
+ this.removeNotificationFroState(arrayIndex);
|
158
|
170
|
}
|
159
|
171
|
}
|
160
|
172
|
}
|
|
@@ -164,10 +176,10 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
164
|
176
|
*
|
165
|
177
|
* @param machineId
|
166
|
178
|
*/
|
167
|
|
- saveNotificationToPrefs(machineId: string) {
|
|
179
|
+ saveNotificationToState(machineId: string) {
|
168
|
180
|
let data = this.state.machinesWatched;
|
169
|
181
|
data.push(machineId);
|
170
|
|
- this.updateNotificationPrefs(data);
|
|
182
|
+ this.updateNotificationState(data);
|
171
|
183
|
}
|
172
|
184
|
|
173
|
185
|
/**
|
|
@@ -175,10 +187,10 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
175
|
187
|
*
|
176
|
188
|
* @param index
|
177
|
189
|
*/
|
178
|
|
- removeNotificationFromPrefs(index: number) {
|
|
190
|
+ removeNotificationFroState(index: number) {
|
179
|
191
|
let data = this.state.machinesWatched;
|
180
|
192
|
data.splice(index, 1);
|
181
|
|
- this.updateNotificationPrefs(data);
|
|
193
|
+ this.updateNotificationState(data);
|
182
|
194
|
}
|
183
|
195
|
|
184
|
196
|
/**
|
|
@@ -186,7 +198,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
|
186
|
198
|
*
|
187
|
199
|
* @param data
|
188
|
200
|
*/
|
189
|
|
- updateNotificationPrefs(data: Array<Object>) {
|
|
201
|
+ updateNotificationState(data: Array<Object>) {
|
190
|
202
|
this.setState({machinesWatched: data});
|
191
|
203
|
// let prefKey = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.key;
|
192
|
204
|
// AsyncStorageManager.getInstance().savePref(prefKey, JSON.stringify(data));
|