Browse Source

Updated proxiwash to match v2 API

Arnaud Vergnet 3 years ago
parent
commit
23bc034b34

+ 22
- 16
src/components/Lists/Proxiwash/ProxiwashListItem.js View File

5
 import i18n from "i18n-js";
5
 import i18n from "i18n-js";
6
 import AprilFoolsManager from "../../../managers/AprilFoolsManager";
6
 import AprilFoolsManager from "../../../managers/AprilFoolsManager";
7
 import * as Animatable from "react-native-animatable";
7
 import * as Animatable from "react-native-animatable";
8
+import type {CustomTheme} from "../../../managers/ThemeManager";
8
 
9
 
9
 type Props = {
10
 type Props = {
10
     item: Object,
11
     item: Object,
12
+    theme: CustomTheme,
11
     onPress: Function,
13
     onPress: Function,
12
     isWatched: boolean,
14
     isWatched: boolean,
13
     isDryer: boolean,
15
     isDryer: boolean,
53
     }
55
     }
54
 
56
 
55
     updateStateStrings() {
57
     updateStateStrings() {
56
-        this.stateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.states.finished');
57
-        this.stateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.states.ready');
58
-        this.stateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.states.running');
59
-        this.stateStrings[ProxiwashConstants.machineStates.HS] = i18n.t('proxiwashScreen.states.broken');
60
-        this.stateStrings[ProxiwashConstants.machineStates.ERREUR] = i18n.t('proxiwashScreen.states.error');
58
+        this.stateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t('proxiwashScreen.states.ready');
59
+        this.stateStrings[ProxiwashConstants.machineStates.RUNNING] = i18n.t('proxiwashScreen.states.running');
60
+        this.stateStrings[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = i18n.t('proxiwashScreen.states.runningNotStarted');
61
+        this.stateStrings[ProxiwashConstants.machineStates.FINISHED] = i18n.t('proxiwashScreen.states.finished');
62
+        this.stateStrings[ProxiwashConstants.machineStates.UNAVAILABLE] = i18n.t('proxiwashScreen.states.broken');
63
+        this.stateStrings[ProxiwashConstants.machineStates.ERROR] = i18n.t('proxiwashScreen.states.error');
64
+        this.stateStrings[ProxiwashConstants.machineStates.UNKNOWN] = i18n.t('proxiwashScreen.states.unknown');
61
     }
65
     }
62
 
66
 
63
     updateStateColors() {
67
     updateStateColors() {
64
         const colors = this.props.theme.colors;
68
         const colors = this.props.theme.colors;
65
-        this.stateColors[ProxiwashConstants.machineStates.TERMINE] = colors.proxiwashFinishedColor;
66
-        this.stateColors[ProxiwashConstants.machineStates.DISPONIBLE] = colors.proxiwashReadyColor;
67
-        this.stateColors[ProxiwashConstants.machineStates["EN COURS"]] = colors.proxiwashRunningColor;
68
-        this.stateColors[ProxiwashConstants.machineStates.HS] = colors.proxiwashBrokenColor;
69
-        this.stateColors[ProxiwashConstants.machineStates.ERREUR] = colors.proxiwashErrorColor;
69
+        this.stateColors[ProxiwashConstants.machineStates.AVAILABLE] = colors.proxiwashReadyColor;
70
+        this.stateColors[ProxiwashConstants.machineStates.RUNNING] = colors.proxiwashRunningColor;
71
+        this.stateColors[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = colors.proxiwashRunningNotStartedColor;
72
+        this.stateColors[ProxiwashConstants.machineStates.FINISHED] = colors.proxiwashFinishedColor;
73
+        this.stateColors[ProxiwashConstants.machineStates.UNAVAILABLE] = colors.proxiwashBrokenColor;
74
+        this.stateColors[ProxiwashConstants.machineStates.ERROR] = colors.proxiwashErrorColor;
75
+        this.stateColors[ProxiwashConstants.machineStates.UNKNOWN] = colors.proxiwashUnknownColor;
70
     }
76
     }
71
 
77
 
72
     onListItemPress = () => this.props.onPress(this.title, this.props.item, this.props.isDryer);
78
     onListItemPress = () => this.props.onPress(this.title, this.props.item, this.props.isDryer);
75
         const props = this.props;
81
         const props = this.props;
76
         const colors = props.theme.colors;
82
         const colors = props.theme.colors;
77
         const machineState = props.item.state;
83
         const machineState = props.item.state;
78
-        const isRunning = ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates["EN COURS"];
79
-        const isReady = ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates.DISPONIBLE;
84
+        const isRunning = machineState === ProxiwashConstants.machineStates.RUNNING;
85
+        const isReady = machineState === ProxiwashConstants.machineStates.AVAILABLE;
80
         const description = isRunning ? props.item.startTime + '/' + props.item.endTime : '';
86
         const description = isRunning ? props.item.startTime + '/' + props.item.endTime : '';
81
         const stateIcon = ProxiwashConstants.stateIcons[machineState];
87
         const stateIcon = ProxiwashConstants.stateIcons[machineState];
82
-        const stateString = this.stateStrings[ProxiwashConstants.machineStates[machineState]];
88
+        const stateString = this.stateStrings[machineState];
83
         const progress = isRunning
89
         const progress = isRunning
84
             ? props.item.donePercent !== ''
90
             ? props.item.donePercent !== ''
85
-                ? parseInt(props.item.donePercent) / 100
91
+                ? parseFloat(props.item.donePercent) / 100
86
                 : 0
92
                 : 0
87
             : 1;
93
             : 1;
88
 
94
 
123
                                 height: props.height
129
                                 height: props.height
124
                             }}
130
                             }}
125
                             progress={progress}
131
                             progress={progress}
126
-                            color={this.stateColors[ProxiwashConstants.machineStates[machineState]]}
132
+                            color={this.stateColors[machineState]}
127
                         />
133
                         />
128
                         : null
134
                         : null
129
                 }
135
                 }
140
                         <View style={{flexDirection: 'row',}}>
146
                         <View style={{flexDirection: 'row',}}>
141
                             <View style={{justifyContent: 'center',}}>
147
                             <View style={{justifyContent: 'center',}}>
142
                                 <Text style={
148
                                 <Text style={
143
-                                    ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates.TERMINE ?
149
+                                    machineState === ProxiwashConstants.machineStates.FINISHED ?
144
                                         {fontWeight: 'bold',} : {}}
150
                                         {fontWeight: 'bold',} : {}}
145
                                 >
151
                                 >
146
                                     {stateString}
152
                                     {stateString}

+ 14
- 10
src/constants/ProxiwashConstants.js View File

1
 export default {
1
 export default {
2
     machineStates: {
2
     machineStates: {
3
-        "TERMINE": "0",
4
-        "DISPONIBLE": "1",
5
-        "EN COURS": "2",
6
-        "HS": "3",
7
-        "ERREUR": "4"
3
+        "AVAILABLE": 0,
4
+        "RUNNING": 1,
5
+        "RUNNING_NOT_STARTED": 2,
6
+        "FINISHED": 3,
7
+        "UNAVAILABLE": 4,
8
+        "ERROR": 5,
9
+        "UNKNOWN": 6,
8
     },
10
     },
9
     stateIcons: {
11
     stateIcons: {
10
-        "TERMINE": 'check-circle',
11
-        "DISPONIBLE": 'radiobox-blank',
12
-        "EN COURS": 'progress-check',
13
-        "HS": 'alert-octagram-outline',
14
-        "ERREUR": 'alert'
12
+        0: 'radiobox-blank',
13
+        1: 'progress-check',
14
+        2: 'alert-circle-outline',
15
+        3: 'check-circle',
16
+        4: 'alert-octagram-outline',
17
+        5: 'alert',
18
+        6: 'help-circle-outline',
15
     }
19
     }
16
 };
20
 };

+ 9
- 3
src/managers/ThemeManager.js View File

31
         proxiwashFinishedColor: string,
31
         proxiwashFinishedColor: string,
32
         proxiwashReadyColor: string,
32
         proxiwashReadyColor: string,
33
         proxiwashRunningColor: string,
33
         proxiwashRunningColor: string,
34
+        proxiwashRunningNotStartedColor: string,
34
         proxiwashRunningBgColor: string,
35
         proxiwashRunningBgColor: string,
35
         proxiwashBrokenColor: string,
36
         proxiwashBrokenColor: string,
36
         proxiwashErrorColor: string,
37
         proxiwashErrorColor: string,
38
+        proxiwashUnknownColor: string,
37
 
39
 
38
         // Screens
40
         // Screens
39
         planningColor: string,
41
         planningColor: string,
100
                 proxiwashFinishedColor: "#a5dc9d",
102
                 proxiwashFinishedColor: "#a5dc9d",
101
                 proxiwashReadyColor: "transparent",
103
                 proxiwashReadyColor: "transparent",
102
                 proxiwashRunningColor: "#a0ceff",
104
                 proxiwashRunningColor: "#a0ceff",
105
+                proxiwashRunningNotStartedColor: "#c9e0ff",
103
                 proxiwashRunningBgColor: "#c7e3ff",
106
                 proxiwashRunningBgColor: "#c7e3ff",
104
-                proxiwashBrokenColor: "#8e8e8e",
105
-                proxiwashErrorColor: "rgba(204,7,0,0.31)#e35f57",
107
+                proxiwashBrokenColor: "#ffa8a2",
108
+                proxiwashErrorColor: "#ffa8a2",
109
+                proxiwashUnknownColor: "#b6b6b6",
106
 
110
 
107
                 // Screens
111
                 // Screens
108
                 planningColor: '#d9b10a',
112
                 planningColor: '#d9b10a',
158
                 proxiwashFinishedColor: "#31682c",
162
                 proxiwashFinishedColor: "#31682c",
159
                 proxiwashReadyColor: "transparent",
163
                 proxiwashReadyColor: "transparent",
160
                 proxiwashRunningColor: "#213c79",
164
                 proxiwashRunningColor: "#213c79",
165
+                proxiwashRunningNotStartedColor: "#1e263e",
161
                 proxiwashRunningBgColor: "#1a2033",
166
                 proxiwashRunningBgColor: "#1a2033",
162
-                proxiwashBrokenColor: "#656565",
167
+                proxiwashBrokenColor: "#7e2e2f",
163
                 proxiwashErrorColor: "#7e2e2f",
168
                 proxiwashErrorColor: "#7e2e2f",
169
+                proxiwashUnknownColor: "#535353",
164
 
170
 
165
                 // Screens
171
                 // Screens
166
                 planningColor: '#d99e09',
172
                 planningColor: '#d99e09',

+ 13
- 10
src/screens/Proxiwash/ProxiwashScreen.js View File

20
 import {getCleanedMachineWatched, getMachineEndDate, isMachineWatched} from "../../utils/Proxiwash";
20
 import {getCleanedMachineWatched, getMachineEndDate, isMachineWatched} from "../../utils/Proxiwash";
21
 import {Modalize} from "react-native-modalize";
21
 import {Modalize} from "react-native-modalize";
22
 
22
 
23
-const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json";
23
+const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json";
24
 
24
 
25
 let modalStateStrings = {};
25
 let modalStateStrings = {};
26
 
26
 
34
     endTime: string,
34
     endTime: string,
35
     donePercent: string,
35
     donePercent: string,
36
     remainingTime: string,
36
     remainingTime: string,
37
+    program: string,
37
 }
38
 }
38
 
39
 
39
 type Props = {
40
 type Props = {
75
      */
76
      */
76
     constructor(props) {
77
     constructor(props) {
77
         super(props);
78
         super(props);
78
-        modalStateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.modal.finished');
79
-        modalStateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.modal.ready');
80
-        modalStateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.modal.running');
81
-        modalStateStrings[ProxiwashConstants.machineStates.HS] = i18n.t('proxiwashScreen.modal.broken');
82
-        modalStateStrings[ProxiwashConstants.machineStates.ERREUR] = i18n.t('proxiwashScreen.modal.error');
79
+        modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t('proxiwashScreen.modal.ready');
80
+        modalStateStrings[ProxiwashConstants.machineStates.RUNNING] = i18n.t('proxiwashScreen.modal.running');
81
+        modalStateStrings[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = i18n.t('proxiwashScreen.modal.runningNotStarted');
82
+        modalStateStrings[ProxiwashConstants.machineStates.FINISHED] = i18n.t('proxiwashScreen.modal.finished');
83
+        modalStateStrings[ProxiwashConstants.machineStates.UNAVAILABLE] = i18n.t('proxiwashScreen.modal.broken');
84
+        modalStateStrings[ProxiwashConstants.machineStates.ERROR] = i18n.t('proxiwashScreen.modal.error');
85
+        modalStateStrings[ProxiwashConstants.machineStates.UNKNOWN] = i18n.t('proxiwashScreen.modal.unknown');
83
     }
86
     }
84
 
87
 
85
     /**
88
     /**
264
             icon: '',
267
             icon: '',
265
             onPress: undefined
268
             onPress: undefined
266
         };
269
         };
267
-        let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
270
+        let message = modalStateStrings[item.state];
268
         const onPress = this.onSetupNotificationsPress.bind(this, item);
271
         const onPress = this.onSetupNotificationsPress.bind(this, item);
269
-        if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) {
272
+        if (item.state === ProxiwashConstants.machineStates.RUNNING) {
270
             let remainingTime = parseInt(item.remainingTime)
273
             let remainingTime = parseInt(item.remainingTime)
271
             if (remainingTime < 0)
274
             if (remainingTime < 0)
272
                 remainingTime = 0;
275
                 remainingTime = 0;
286
                     end: item.endTime,
289
                     end: item.endTime,
287
                     remaining: remainingTime
290
                     remaining: remainingTime
288
                 });
291
                 });
289
-        } else if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates.DISPONIBLE) {
292
+        } else if (item.state === ProxiwashConstants.machineStates.AVAILABLE) {
290
             if (isDryer)
293
             if (isDryer)
291
                 message += '\n' + i18n.t('proxiwashScreen.dryersTariff');
294
                 message += '\n' + i18n.t('proxiwashScreen.dryersTariff');
292
             else
295
             else
347
             data = this.fetchedData.washers;
350
             data = this.fetchedData.washers;
348
         let count = 0;
351
         let count = 0;
349
         for (let i = 0; i < data.length; i++) {
352
         for (let i = 0; i < data.length; i++) {
350
-            if (ProxiwashConstants.machineStates[data[i].state] === ProxiwashConstants.machineStates["DISPONIBLE"])
353
+            if (data[i].state === ProxiwashConstants.machineStates.AVAILABLE)
351
                 count += 1;
354
                 count += 1;
352
         }
355
         }
353
         return count;
356
         return count;

+ 5
- 1
translations/en.json View File

182
       "finished": "This machine is finished. If you started it, you can get back your laundry.",
182
       "finished": "This machine is finished. If you started it, you can get back your laundry.",
183
       "ready": "This machine is empty and ready to use.",
183
       "ready": "This machine is empty and ready to use.",
184
       "running": "This machine has been started at %{start} and will end at %{end}.\nRemaining time: %{remaining} min",
184
       "running": "This machine has been started at %{start} and will end at %{end}.\nRemaining time: %{remaining} min",
185
+      "runningNotStarted": "This machine is ready but not started. Please make sure you pressed the start button.",
185
       "broken": "This machine is broken and cannot be used. Thank you for your comprehension.",
186
       "broken": "This machine is broken and cannot be used. Thank you for your comprehension.",
186
       "error": "There has been an error and we are unable to get information from this machine. Sorry for the inconvenience.",
187
       "error": "There has been an error and we are unable to get information from this machine. Sorry for the inconvenience.",
188
+      "unknown": "This machine is in an unknown state. Sorry for the inconvenience.",
187
       "notificationErrorTitle": "Error",
189
       "notificationErrorTitle": "Error",
188
       "notificationErrorDescription": "Impossible to create notifications. Please make sure you enabled notifications then restart the app."
190
       "notificationErrorDescription": "Impossible to create notifications. Please make sure you enabled notifications then restart the app."
189
     },
191
     },
191
       "finished": "FINISHED",
193
       "finished": "FINISHED",
192
       "ready": "READY",
194
       "ready": "READY",
193
       "running": "RUNNING",
195
       "running": "RUNNING",
196
+      "runningNotStarted": "NOT STARTED",
194
       "broken": "BROKEN",
197
       "broken": "BROKEN",
195
-      "error": "ERROR"
198
+      "error": "ERROR",
199
+      "unknown": "UNKNOWN"
196
     },
200
     },
197
     "notifications": {
201
     "notifications": {
198
       "machineFinishedTitle": "Laundry Ready",
202
       "machineFinishedTitle": "Laundry Ready",

+ 5
- 1
translations/fr.json View File

182
       "finished": "Cette machine est terminée. Si vous l'avez démarrée, vous pouvez récupérer votre linge.",
182
       "finished": "Cette machine est terminée. Si vous l'avez démarrée, vous pouvez récupérer votre linge.",
183
       "ready": "Cette machine est vide et prête à être utilisée.",
183
       "ready": "Cette machine est vide et prête à être utilisée.",
184
       "running": "Cette machine a démarré à %{start} et terminera à %{end}.\nTemps restant : %{remaining} min",
184
       "running": "Cette machine a démarré à %{start} et terminera à %{end}.\nTemps restant : %{remaining} min",
185
+      "runningNotStarted": "Cette machine est prête mais n'est pas démarrée. Assurez vous de bien avoir appuyé sur le bouton start.",
185
       "broken": "Cette machine est hors service. Merci pour votre compréhension.",
186
       "broken": "Cette machine est hors service. Merci pour votre compréhension.",
186
       "error": "Il y a eu une erreur et il est impossible de récupérer les informations de cette machine. Veuillez nous excuser pour le gène occasionnée.",
187
       "error": "Il y a eu une erreur et il est impossible de récupérer les informations de cette machine. Veuillez nous excuser pour le gène occasionnée.",
188
+      "unknown": "Cette machine est dans un état inconnu. Veuillez nous excuser pour ce problème.",
187
       "notificationErrorTitle": "Erreur",
189
       "notificationErrorTitle": "Erreur",
188
       "notificationErrorDescription": "Impossible de créer les notifications. Merci de vérifier que vous avez activé les notifications puis redémarrez l'appli."
190
       "notificationErrorDescription": "Impossible de créer les notifications. Merci de vérifier que vous avez activé les notifications puis redémarrez l'appli."
189
     },
191
     },
191
       "finished": "TERMINÉ",
193
       "finished": "TERMINÉ",
192
       "ready": "DISPONIBLE",
194
       "ready": "DISPONIBLE",
193
       "running": "EN COURS",
195
       "running": "EN COURS",
196
+      "runningNotStarted": "NON DÉMARRÉE",
194
       "broken": "HORS SERVICE",
197
       "broken": "HORS SERVICE",
195
-      "error": "ERREUR"
198
+      "error": "ERREUR",
199
+      "unknown": "INCONNU"
196
     },
200
     },
197
     "notifications": {
201
     "notifications": {
198
       "machineFinishedTitle": "Linge prêt",
202
       "machineFinishedTitle": "Linge prêt",

Loading…
Cancel
Save