Updated proxiwash to match v2 API

This commit is contained in:
Arnaud Vergnet 2020-06-24 19:22:27 +02:00
parent b1e3fe6658
commit 23bc034b34
6 changed files with 68 additions and 41 deletions

View file

@ -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<Props> {
}
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<Props> {
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<Props> {
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<Props> {
<View style={{flexDirection: 'row',}}>
<View style={{justifyContent: 'center',}}>
<Text style={
ProxiwashConstants.machineStates[machineState] === ProxiwashConstants.machineStates.TERMINE ?
machineState === ProxiwashConstants.machineStates.FINISHED ?
{fontWeight: 'bold',} : {}}
>
{stateString}

View file

@ -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',
}
};

View file

@ -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',

View file

@ -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<Props, State> {
*/
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<Props, State> {
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<Props, State> {
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<Props, State> {
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;

View file

@ -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",

View file

@ -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",