Browse Source

Fixed crash on nightmode change, sync reminder notification with server

keplyx 2 years ago
parent
commit
f228ed0cee
4 changed files with 38 additions and 4 deletions
  1. 1
    1
      App.js
  2. BIN
      assets/drawer-cover.png
  3. 5
    3
      screens/SettingsScreen.js
  4. 32
    0
      utils/NotificationsManager.js

+ 1
- 1
App.js View File

@@ -85,7 +85,7 @@ export default class App extends React.Component<Props, State> {
85 85
         if (this.state.isLoading) {
86 86
             return (
87 87
                 <AppLoading
88
-                    startAsync={this.loadAssetsAsync}
88
+                    startAsync={() => this.loadAssetsAsync()}
89 89
                     onFinish={() => this.onLoadFinished()}
90 90
                     onError={console.warn}
91 91
                 />

BIN
assets/drawer-cover.png View File


+ 5
- 3
screens/SettingsScreen.js View File

@@ -23,6 +23,7 @@ import CustomMaterialIcon from "../components/CustomMaterialIcon";
23 23
 import AsyncStorageManager from "../utils/AsyncStorageManager";
24 24
 import Touchable from "react-native-platform-touchable";
25 25
 import {Platform} from "react-native";
26
+import NotificationsManager from "../utils/NotificationsManager";
26 27
 
27 28
 type Props = {
28 29
     navigation: Object,
@@ -53,6 +54,10 @@ export default class SettingsScreen extends React.Component<Props, State> {
53 54
         this.setState({
54 55
             proxiwashNotifPickerSelected: value
55 56
         });
57
+        let intVal = 0;
58
+        if (value !== 'never')
59
+            intVal = parseInt(value);
60
+        NotificationsManager.setMachineReminderNotificationTime(intVal);
56 61
     }
57 62
 
58 63
     /**
@@ -70,9 +75,6 @@ export default class SettingsScreen extends React.Component<Props, State> {
70 75
                 onValueChange={(value) => this.onProxiwashNotifPickerValueChange(value)}
71 76
             >
72 77
                 <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
73
-                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
74
-                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
75
-                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
76 78
                 <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
77 79
                 <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
78 80
                 <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>

+ 32
- 0
utils/NotificationsManager.js View File

@@ -159,4 +159,36 @@ export default class NotificationsManager {
159 159
                 console.log(error);
160 160
             });
161 161
     }
162
+
163
+    /**
164
+     * Send the selected reminder time for notifications to the server
165
+     * @param time
166
+     */
167
+    static setMachineReminderNotificationTime(time: number) {
168
+        console.log(time);
169
+        let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
170
+        if (token === '') {
171
+            throw Error('Expo token not available');
172
+        }
173
+        let data = {
174
+            function: 'set_machine_reminder',
175
+            token: token,
176
+            time: time,
177
+        };
178
+        fetch(EXPO_TOKEN_SERVER, {
179
+            method: 'POST',
180
+            headers: new Headers({
181
+                Accept: 'application/json',
182
+                'Content-Type': 'application/json',
183
+            }),
184
+            body: JSON.stringify(data) // <-- Post parameters
185
+        })
186
+            .then((response) => response.text())
187
+            .then((responseText) => {
188
+                console.log(responseText);
189
+            })
190
+            .catch((error) => {
191
+                console.log(error);
192
+            });
193
+    }
162 194
 }

Loading…
Cancel
Save