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,9 +5,11 @@ import ProxiwashConstants from "../../../constants/ProxiwashConstants";
5 5
 import i18n from "i18n-js";
6 6
 import AprilFoolsManager from "../../../managers/AprilFoolsManager";
7 7
 import * as Animatable from "react-native-animatable";
8
+import type {CustomTheme} from "../../../managers/ThemeManager";
8 9
 
9 10
 type Props = {
10 11
     item: Object,
12
+    theme: CustomTheme,
11 13
     onPress: Function,
12 14
     isWatched: boolean,
13 15
     isDryer: boolean,
@@ -53,20 +55,24 @@ class ProxiwashListItem extends React.Component<Props> {
53 55
     }
54 56
 
55 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 67
     updateStateColors() {
64 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 78
     onListItemPress = () => this.props.onPress(this.title, this.props.item, this.props.isDryer);
@@ -75,14 +81,14 @@ class ProxiwashListItem extends React.Component<Props> {
75 81
         const props = this.props;
76 82
         const colors = props.theme.colors;
77 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 86
         const description = isRunning ? props.item.startTime + '/' + props.item.endTime : '';
81 87
         const stateIcon = ProxiwashConstants.stateIcons[machineState];
82
-        const stateString = this.stateStrings[ProxiwashConstants.machineStates[machineState]];
88
+        const stateString = this.stateStrings[machineState];
83 89
         const progress = isRunning
84 90
             ? props.item.donePercent !== ''
85
-                ? parseInt(props.item.donePercent) / 100
91
+                ? parseFloat(props.item.donePercent) / 100
86 92
                 : 0
87 93
             : 1;
88 94
 
@@ -123,7 +129,7 @@ class ProxiwashListItem extends React.Component<Props> {
123 129
                                 height: props.height
124 130
                             }}
125 131
                             progress={progress}
126
-                            color={this.stateColors[ProxiwashConstants.machineStates[machineState]]}
132
+                            color={this.stateColors[machineState]}
127 133
                         />
128 134
                         : null
129 135
                 }
@@ -140,7 +146,7 @@ class ProxiwashListItem extends React.Component<Props> {
140 146
                         <View style={{flexDirection: 'row',}}>
141 147
                             <View style={{justifyContent: 'center',}}>
142 148
                                 <Text style={
143
-                                    ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates.TERMINE ?
149
+                                    machineState === ProxiwashConstants.machineStates.FINISHED ?
144 150
                                         {fontWeight: 'bold',} : {}}
145 151
                                 >
146 152
                                     {stateString}

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

@@ -1,16 +1,20 @@
1 1
 export default {
2 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 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,9 +31,11 @@ export type CustomTheme = {
31 31
         proxiwashFinishedColor: string,
32 32
         proxiwashReadyColor: string,
33 33
         proxiwashRunningColor: string,
34
+        proxiwashRunningNotStartedColor: string,
34 35
         proxiwashRunningBgColor: string,
35 36
         proxiwashBrokenColor: string,
36 37
         proxiwashErrorColor: string,
38
+        proxiwashUnknownColor: string,
37 39
 
38 40
         // Screens
39 41
         planningColor: string,
@@ -100,9 +102,11 @@ export default class ThemeManager {
100 102
                 proxiwashFinishedColor: "#a5dc9d",
101 103
                 proxiwashReadyColor: "transparent",
102 104
                 proxiwashRunningColor: "#a0ceff",
105
+                proxiwashRunningNotStartedColor: "#c9e0ff",
103 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 111
                 // Screens
108 112
                 planningColor: '#d9b10a',
@@ -158,9 +162,11 @@ export default class ThemeManager {
158 162
                 proxiwashFinishedColor: "#31682c",
159 163
                 proxiwashReadyColor: "transparent",
160 164
                 proxiwashRunningColor: "#213c79",
165
+                proxiwashRunningNotStartedColor: "#1e263e",
161 166
                 proxiwashRunningBgColor: "#1a2033",
162
-                proxiwashBrokenColor: "#656565",
167
+                proxiwashBrokenColor: "#7e2e2f",
163 168
                 proxiwashErrorColor: "#7e2e2f",
169
+                proxiwashUnknownColor: "#535353",
164 170
 
165 171
                 // Screens
166 172
                 planningColor: '#d99e09',

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

@@ -20,7 +20,7 @@ import {StackNavigationProp} from "@react-navigation/stack";
20 20
 import {getCleanedMachineWatched, getMachineEndDate, isMachineWatched} from "../../utils/Proxiwash";
21 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 25
 let modalStateStrings = {};
26 26
 
@@ -34,6 +34,7 @@ export type Machine = {
34 34
     endTime: string,
35 35
     donePercent: string,
36 36
     remainingTime: string,
37
+    program: string,
37 38
 }
38 39
 
39 40
 type Props = {
@@ -75,11 +76,13 @@ class ProxiwashScreen extends React.Component<Props, State> {
75 76
      */
76 77
     constructor(props) {
77 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,9 +267,9 @@ class ProxiwashScreen extends React.Component<Props, State> {
264 267
             icon: '',
265 268
             onPress: undefined
266 269
         };
267
-        let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
270
+        let message = modalStateStrings[item.state];
268 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 273
             let remainingTime = parseInt(item.remainingTime)
271 274
             if (remainingTime < 0)
272 275
                 remainingTime = 0;
@@ -286,7 +289,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
286 289
                     end: item.endTime,
287 290
                     remaining: remainingTime
288 291
                 });
289
-        } else if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates.DISPONIBLE) {
292
+        } else if (item.state === ProxiwashConstants.machineStates.AVAILABLE) {
290 293
             if (isDryer)
291 294
                 message += '\n' + i18n.t('proxiwashScreen.dryersTariff');
292 295
             else
@@ -347,7 +350,7 @@ class ProxiwashScreen extends React.Component<Props, State> {
347 350
             data = this.fetchedData.washers;
348 351
         let count = 0;
349 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 354
                 count += 1;
352 355
         }
353 356
         return count;

+ 5
- 1
translations/en.json View File

@@ -182,8 +182,10 @@
182 182
       "finished": "This machine is finished. If you started it, you can get back your laundry.",
183 183
       "ready": "This machine is empty and ready to use.",
184 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 186
       "broken": "This machine is broken and cannot be used. Thank you for your comprehension.",
186 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 189
       "notificationErrorTitle": "Error",
188 190
       "notificationErrorDescription": "Impossible to create notifications. Please make sure you enabled notifications then restart the app."
189 191
     },
@@ -191,8 +193,10 @@
191 193
       "finished": "FINISHED",
192 194
       "ready": "READY",
193 195
       "running": "RUNNING",
196
+      "runningNotStarted": "NOT STARTED",
194 197
       "broken": "BROKEN",
195
-      "error": "ERROR"
198
+      "error": "ERROR",
199
+      "unknown": "UNKNOWN"
196 200
     },
197 201
     "notifications": {
198 202
       "machineFinishedTitle": "Laundry Ready",

+ 5
- 1
translations/fr.json View File

@@ -182,8 +182,10 @@
182 182
       "finished": "Cette machine est terminée. Si vous l'avez démarrée, vous pouvez récupérer votre linge.",
183 183
       "ready": "Cette machine est vide et prête à être utilisée.",
184 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 186
       "broken": "Cette machine est hors service. Merci pour votre compréhension.",
186 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 189
       "notificationErrorTitle": "Erreur",
188 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,8 +193,10 @@
191 193
       "finished": "TERMINÉ",
192 194
       "ready": "DISPONIBLE",
193 195
       "running": "EN COURS",
196
+      "runningNotStarted": "NON DÉMARRÉE",
194 197
       "broken": "HORS SERVICE",
195
-      "error": "ERREUR"
198
+      "error": "ERREUR",
199
+      "unknown": "INCONNU"
196 200
     },
197 201
     "notifications": {
198 202
       "machineFinishedTitle": "Linge prêt",

Loading…
Cancel
Save