Browse Source

Use machine remaining time from server instead of calculating it again

keplyx 4 years ago
parent
commit
3ba3d332f8
2 changed files with 4 additions and 26 deletions
  1. 1
    1
      app.json
  2. 3
    25
      screens/ProxiwashScreen.js

+ 1
- 1
app.json View File

@@ -10,7 +10,7 @@
10 10
       "android",
11 11
       "web"
12 12
     ],
13
-    "version": "0.0.12",
13
+    "version": "0.0.13",
14 14
     "orientation": "portrait",
15 15
     "primaryColor": "#be1522",
16 16
     "icon": "./assets/android.icon.png",

+ 3
- 25
screens/ProxiwashScreen.js View File

@@ -121,24 +121,6 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
121 121
     }
122 122
 
123 123
     /**
124
-     * Get the time remaining based on start/end time and done percent
125
-     *
126
-     * @param startString The string representing the start time. Format: hh:mm
127
-     * @param endString The string representing the end time. Format: hh:mm
128
-     * @param percentDone The percentage done
129
-     * @returns {number} How many minutes are remaining for this machine
130
-     */
131
-    static getRemainingTime(startString: string, endString: string, percentDone: string): number {
132
-        let startArray = startString.split(':');
133
-        let endArray = endString.split(':');
134
-        let startDate = new Date().setHours(parseInt(startArray[0]), parseInt(startArray[1]), 0, 0);
135
-        let endDate = new Date().setHours(parseInt(endArray[0]), parseInt(endArray[1]), 0, 0);
136
-        // Convert milliseconds into minutes
137
-        let time: string = (((100 - parseFloat(percentDone)) / 100) * (endDate - startDate) / (60 * 1000)).toFixed(0);
138
-        return parseInt(time);
139
-    }
140
-
141
-    /**
142 124
      * Setup notifications for the machine with the given ID.
143 125
      * One notification will be sent at the end of the program.
144 126
      * Another will be send a few minutes before the end, based on the value of reminderNotifTime
@@ -243,10 +225,9 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
243 225
      *
244 226
      * @param title
245 227
      * @param item
246
-     * @param remainingTime
247 228
      * @param isDryer
248 229
      */
249
-    showAlert(title: string, item: Object, remainingTime: number, isDryer: boolean) {
230
+    showAlert(title: string, item: Object, isDryer: boolean) {
250 231
         let buttons = [{text: i18n.t("proxiwashScreen.modal.ok")}];
251 232
         let message = modalStateStrings[MACHINE_STATES[item.state]];
252 233
         if (MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"]) {
@@ -265,7 +246,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
265 246
                 {
266 247
                     start: item.startTime,
267 248
                     end: item.endTime,
268
-                    remaining: remainingTime
249
+                    remaining: item.remainingTime
269 250
                 });
270 251
         } else if (MACHINE_STATES[item.state] === MACHINE_STATES.DISPONIBLE) {
271 252
             if (isDryer)
@@ -304,9 +285,6 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
304 285
         let isMachineRunning = MACHINE_STATES[item.state] === MACHINE_STATES["EN COURS"];
305 286
         let machineName = (section.title === i18n.t('proxiwashScreen.dryers') ? i18n.t('proxiwashScreen.dryer') : i18n.t('proxiwashScreen.washer')) + ' n°' + item.number;
306 287
         let isDryer = section.title === i18n.t('proxiwashScreen.dryers');
307
-        let remainingTime = 0;
308
-        if (isMachineRunning)
309
-            remainingTime = ProxiwashScreen.getRemainingTime(item.startTime, item.endTime, item.donePercent);
310 288
         return (
311 289
             <Card style={{
312 290
                 flex: 0,
@@ -331,7 +309,7 @@ export default class ProxiwashScreen extends FetchedDataSectionList {
331 309
                         backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor
332 310
                     }}/>
333 311
                     <PlatformTouchable
334
-                        onPress={() => this.showAlert(machineName, item, remainingTime, isDryer)}
312
+                        onPress={() => this.showAlert(machineName, item, isDryer)}
335 313
                         style={{
336 314
                             height: 64,
337 315
                             position: 'absolute',

Loading…
Cancel
Save