From 23bc034b34011f06efff91ba646aa38f341dae09 Mon Sep 17 00:00:00 2001 From: Arnaud Vergnet Date: Wed, 24 Jun 2020 19:22:27 +0200 Subject: [PATCH] Updated proxiwash to match v2 API --- .../Lists/Proxiwash/ProxiwashListItem.js | 38 +++++++++++-------- src/constants/ProxiwashConstants.js | 24 +++++++----- src/managers/ThemeManager.js | 12 ++++-- src/screens/Proxiwash/ProxiwashScreen.js | 23 ++++++----- translations/en.json | 6 ++- translations/fr.json | 6 ++- 6 files changed, 68 insertions(+), 41 deletions(-) diff --git a/src/components/Lists/Proxiwash/ProxiwashListItem.js b/src/components/Lists/Proxiwash/ProxiwashListItem.js index 7740ed9..394e537 100644 --- a/src/components/Lists/Proxiwash/ProxiwashListItem.js +++ b/src/components/Lists/Proxiwash/ProxiwashListItem.js @@ -5,9 +5,11 @@ import ProxiwashConstants from "../../../constants/ProxiwashConstants"; import i18n from "i18n-js"; import AprilFoolsManager from "../../../managers/AprilFoolsManager"; import * as Animatable from "react-native-animatable"; +import type {CustomTheme} from "../../../managers/ThemeManager"; type Props = { item: Object, + theme: CustomTheme, onPress: Function, isWatched: boolean, isDryer: boolean, @@ -53,20 +55,24 @@ class ProxiwashListItem extends React.Component { } updateStateStrings() { - this.stateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.states.finished'); - this.stateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.states.ready'); - this.stateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.states.running'); - this.stateStrings[ProxiwashConstants.machineStates.HS] = i18n.t('proxiwashScreen.states.broken'); - this.stateStrings[ProxiwashConstants.machineStates.ERREUR] = i18n.t('proxiwashScreen.states.error'); + this.stateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t('proxiwashScreen.states.ready'); + this.stateStrings[ProxiwashConstants.machineStates.RUNNING] = i18n.t('proxiwashScreen.states.running'); + this.stateStrings[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = i18n.t('proxiwashScreen.states.runningNotStarted'); + this.stateStrings[ProxiwashConstants.machineStates.FINISHED] = i18n.t('proxiwashScreen.states.finished'); + this.stateStrings[ProxiwashConstants.machineStates.UNAVAILABLE] = i18n.t('proxiwashScreen.states.broken'); + this.stateStrings[ProxiwashConstants.machineStates.ERROR] = i18n.t('proxiwashScreen.states.error'); + this.stateStrings[ProxiwashConstants.machineStates.UNKNOWN] = i18n.t('proxiwashScreen.states.unknown'); } updateStateColors() { const colors = this.props.theme.colors; - this.stateColors[ProxiwashConstants.machineStates.TERMINE] = colors.proxiwashFinishedColor; - this.stateColors[ProxiwashConstants.machineStates.DISPONIBLE] = colors.proxiwashReadyColor; - this.stateColors[ProxiwashConstants.machineStates["EN COURS"]] = colors.proxiwashRunningColor; - this.stateColors[ProxiwashConstants.machineStates.HS] = colors.proxiwashBrokenColor; - this.stateColors[ProxiwashConstants.machineStates.ERREUR] = colors.proxiwashErrorColor; + this.stateColors[ProxiwashConstants.machineStates.AVAILABLE] = colors.proxiwashReadyColor; + this.stateColors[ProxiwashConstants.machineStates.RUNNING] = colors.proxiwashRunningColor; + this.stateColors[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = colors.proxiwashRunningNotStartedColor; + this.stateColors[ProxiwashConstants.machineStates.FINISHED] = colors.proxiwashFinishedColor; + this.stateColors[ProxiwashConstants.machineStates.UNAVAILABLE] = colors.proxiwashBrokenColor; + this.stateColors[ProxiwashConstants.machineStates.ERROR] = colors.proxiwashErrorColor; + this.stateColors[ProxiwashConstants.machineStates.UNKNOWN] = colors.proxiwashUnknownColor; } onListItemPress = () => this.props.onPress(this.title, this.props.item, this.props.isDryer); @@ -75,14 +81,14 @@ class ProxiwashListItem extends React.Component { const props = this.props; const colors = props.theme.colors; const machineState = props.item.state; - const isRunning = ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates["EN COURS"]; - const isReady = ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates.DISPONIBLE; + const isRunning = machineState === ProxiwashConstants.machineStates.RUNNING; + const isReady = machineState === ProxiwashConstants.machineStates.AVAILABLE; const description = isRunning ? props.item.startTime + '/' + props.item.endTime : ''; const stateIcon = ProxiwashConstants.stateIcons[machineState]; - const stateString = this.stateStrings[ProxiwashConstants.machineStates[machineState]]; + const stateString = this.stateStrings[machineState]; const progress = isRunning ? props.item.donePercent !== '' - ? parseInt(props.item.donePercent) / 100 + ? parseFloat(props.item.donePercent) / 100 : 0 : 1; @@ -123,7 +129,7 @@ class ProxiwashListItem extends React.Component { height: props.height }} progress={progress} - color={this.stateColors[ProxiwashConstants.machineStates[machineState]]} + color={this.stateColors[machineState]} /> : null } @@ -140,7 +146,7 @@ class ProxiwashListItem extends React.Component { {stateString} diff --git a/src/constants/ProxiwashConstants.js b/src/constants/ProxiwashConstants.js index 799e956..5a07206 100644 --- a/src/constants/ProxiwashConstants.js +++ b/src/constants/ProxiwashConstants.js @@ -1,16 +1,20 @@ export default { machineStates: { - "TERMINE": "0", - "DISPONIBLE": "1", - "EN COURS": "2", - "HS": "3", - "ERREUR": "4" + "AVAILABLE": 0, + "RUNNING": 1, + "RUNNING_NOT_STARTED": 2, + "FINISHED": 3, + "UNAVAILABLE": 4, + "ERROR": 5, + "UNKNOWN": 6, }, stateIcons: { - "TERMINE": 'check-circle', - "DISPONIBLE": 'radiobox-blank', - "EN COURS": 'progress-check', - "HS": 'alert-octagram-outline', - "ERREUR": 'alert' + 0: 'radiobox-blank', + 1: 'progress-check', + 2: 'alert-circle-outline', + 3: 'check-circle', + 4: 'alert-octagram-outline', + 5: 'alert', + 6: 'help-circle-outline', } }; diff --git a/src/managers/ThemeManager.js b/src/managers/ThemeManager.js index 9c087c4..7edb06a 100644 --- a/src/managers/ThemeManager.js +++ b/src/managers/ThemeManager.js @@ -31,9 +31,11 @@ export type CustomTheme = { proxiwashFinishedColor: string, proxiwashReadyColor: string, proxiwashRunningColor: string, + proxiwashRunningNotStartedColor: string, proxiwashRunningBgColor: string, proxiwashBrokenColor: string, proxiwashErrorColor: string, + proxiwashUnknownColor: string, // Screens planningColor: string, @@ -100,9 +102,11 @@ export default class ThemeManager { proxiwashFinishedColor: "#a5dc9d", proxiwashReadyColor: "transparent", proxiwashRunningColor: "#a0ceff", + proxiwashRunningNotStartedColor: "#c9e0ff", proxiwashRunningBgColor: "#c7e3ff", - proxiwashBrokenColor: "#8e8e8e", - proxiwashErrorColor: "rgba(204,7,0,0.31)#e35f57", + proxiwashBrokenColor: "#ffa8a2", + proxiwashErrorColor: "#ffa8a2", + proxiwashUnknownColor: "#b6b6b6", // Screens planningColor: '#d9b10a', @@ -158,9 +162,11 @@ export default class ThemeManager { proxiwashFinishedColor: "#31682c", proxiwashReadyColor: "transparent", proxiwashRunningColor: "#213c79", + proxiwashRunningNotStartedColor: "#1e263e", proxiwashRunningBgColor: "#1a2033", - proxiwashBrokenColor: "#656565", + proxiwashBrokenColor: "#7e2e2f", proxiwashErrorColor: "#7e2e2f", + proxiwashUnknownColor: "#535353", // Screens planningColor: '#d99e09', diff --git a/src/screens/Proxiwash/ProxiwashScreen.js b/src/screens/Proxiwash/ProxiwashScreen.js index 1f2f3f3..0c2acf6 100644 --- a/src/screens/Proxiwash/ProxiwashScreen.js +++ b/src/screens/Proxiwash/ProxiwashScreen.js @@ -20,7 +20,7 @@ import {StackNavigationProp} from "@react-navigation/stack"; import {getCleanedMachineWatched, getMachineEndDate, isMachineWatched} from "../../utils/Proxiwash"; import {Modalize} from "react-native-modalize"; -const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json"; +const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json"; let modalStateStrings = {}; @@ -34,6 +34,7 @@ export type Machine = { endTime: string, donePercent: string, remainingTime: string, + program: string, } type Props = { @@ -75,11 +76,13 @@ class ProxiwashScreen extends React.Component { */ constructor(props) { super(props); - modalStateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.modal.finished'); - modalStateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.modal.ready'); - modalStateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.modal.running'); - modalStateStrings[ProxiwashConstants.machineStates.HS] = i18n.t('proxiwashScreen.modal.broken'); - modalStateStrings[ProxiwashConstants.machineStates.ERREUR] = i18n.t('proxiwashScreen.modal.error'); + modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t('proxiwashScreen.modal.ready'); + modalStateStrings[ProxiwashConstants.machineStates.RUNNING] = i18n.t('proxiwashScreen.modal.running'); + modalStateStrings[ProxiwashConstants.machineStates.RUNNING_NOT_STARTED] = i18n.t('proxiwashScreen.modal.runningNotStarted'); + modalStateStrings[ProxiwashConstants.machineStates.FINISHED] = i18n.t('proxiwashScreen.modal.finished'); + modalStateStrings[ProxiwashConstants.machineStates.UNAVAILABLE] = i18n.t('proxiwashScreen.modal.broken'); + modalStateStrings[ProxiwashConstants.machineStates.ERROR] = i18n.t('proxiwashScreen.modal.error'); + modalStateStrings[ProxiwashConstants.machineStates.UNKNOWN] = i18n.t('proxiwashScreen.modal.unknown'); } /** @@ -264,9 +267,9 @@ class ProxiwashScreen extends React.Component { icon: '', onPress: undefined }; - let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]]; + let message = modalStateStrings[item.state]; const onPress = this.onSetupNotificationsPress.bind(this, item); - if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) { + if (item.state === ProxiwashConstants.machineStates.RUNNING) { let remainingTime = parseInt(item.remainingTime) if (remainingTime < 0) remainingTime = 0; @@ -286,7 +289,7 @@ class ProxiwashScreen extends React.Component { end: item.endTime, remaining: remainingTime }); - } else if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates.DISPONIBLE) { + } else if (item.state === ProxiwashConstants.machineStates.AVAILABLE) { if (isDryer) message += '\n' + i18n.t('proxiwashScreen.dryersTariff'); else @@ -347,7 +350,7 @@ class ProxiwashScreen extends React.Component { data = this.fetchedData.washers; let count = 0; for (let i = 0; i < data.length; i++) { - if (ProxiwashConstants.machineStates[data[i].state] === ProxiwashConstants.machineStates["DISPONIBLE"]) + if (data[i].state === ProxiwashConstants.machineStates.AVAILABLE) count += 1; } return count; diff --git a/translations/en.json b/translations/en.json index f434ac5..473a347 100644 --- a/translations/en.json +++ b/translations/en.json @@ -182,8 +182,10 @@ "finished": "This machine is finished. If you started it, you can get back your laundry.", "ready": "This machine is empty and ready to use.", "running": "This machine has been started at %{start} and will end at %{end}.\nRemaining time: %{remaining} min", + "runningNotStarted": "This machine is ready but not started. Please make sure you pressed the start button.", "broken": "This machine is broken and cannot be used. Thank you for your comprehension.", "error": "There has been an error and we are unable to get information from this machine. Sorry for the inconvenience.", + "unknown": "This machine is in an unknown state. Sorry for the inconvenience.", "notificationErrorTitle": "Error", "notificationErrorDescription": "Impossible to create notifications. Please make sure you enabled notifications then restart the app." }, @@ -191,8 +193,10 @@ "finished": "FINISHED", "ready": "READY", "running": "RUNNING", + "runningNotStarted": "NOT STARTED", "broken": "BROKEN", - "error": "ERROR" + "error": "ERROR", + "unknown": "UNKNOWN" }, "notifications": { "machineFinishedTitle": "Laundry Ready", diff --git a/translations/fr.json b/translations/fr.json index 149ae00..b17d12b 100644 --- a/translations/fr.json +++ b/translations/fr.json @@ -182,8 +182,10 @@ "finished": "Cette machine est terminée. Si vous l'avez démarrée, vous pouvez récupérer votre linge.", "ready": "Cette machine est vide et prête à être utilisée.", "running": "Cette machine a démarré à %{start} et terminera à %{end}.\nTemps restant : %{remaining} min", + "runningNotStarted": "Cette machine est prête mais n'est pas démarrée. Assurez vous de bien avoir appuyé sur le bouton start.", "broken": "Cette machine est hors service. Merci pour votre compréhension.", "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.", + "unknown": "Cette machine est dans un état inconnu. Veuillez nous excuser pour ce problème.", "notificationErrorTitle": "Erreur", "notificationErrorDescription": "Impossible de créer les notifications. Merci de vérifier que vous avez activé les notifications puis redémarrez l'appli." }, @@ -191,8 +193,10 @@ "finished": "TERMINÉ", "ready": "DISPONIBLE", "running": "EN COURS", + "runningNotStarted": "NON DÉMARRÉE", "broken": "HORS SERVICE", - "error": "ERREUR" + "error": "ERREUR", + "unknown": "INCONNU" }, "notifications": { "machineFinishedTitle": "Linge prêt",