2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-08-06 13:28:11 +02:00
|
|
|
import {Alert, Platform, View} from 'react-native';
|
2019-06-27 19:33:22 +02:00
|
|
|
import i18n from "i18n-js";
|
2020-04-02 10:07:20 +02:00
|
|
|
import WebSectionList from "../../components/Lists/WebSectionList";
|
2020-03-30 15:28:08 +02:00
|
|
|
import * as Notifications from "../../utils/Notifications";
|
|
|
|
import AsyncStorageManager from "../../managers/AsyncStorageManager";
|
2019-08-04 14:28:41 +02:00
|
|
|
import * as Expo from "expo";
|
2020-03-09 23:15:13 +01:00
|
|
|
import {Avatar, Banner, Button, Card, Text, withTheme} from 'react-native-paper';
|
2020-04-02 10:07:20 +02:00
|
|
|
import HeaderButton from "../../components/Custom/HeaderButton";
|
|
|
|
import ProxiwashListItem from "../../components/Lists/ProxiwashListItem";
|
2020-03-07 11:49:32 +01:00
|
|
|
import ProxiwashConstants from "../../constants/ProxiwashConstants";
|
2020-04-02 10:07:20 +02:00
|
|
|
import CustomModal from "../../components/Custom/CustomModal";
|
2020-03-30 15:28:08 +02:00
|
|
|
import AprilFoolsManager from "../../managers/AprilFoolsManager";
|
2019-06-27 19:33:22 +02:00
|
|
|
|
2020-02-23 17:21:34 +01:00
|
|
|
const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/washinsa/washinsa.json";
|
2019-06-27 19:33:22 +02:00
|
|
|
|
|
|
|
let stateStrings = {};
|
2019-07-30 20:40:17 +02:00
|
|
|
let modalStateStrings = {};
|
2019-07-28 00:32:49 +02:00
|
|
|
let stateIcons = {};
|
2019-06-27 19:33:22 +02:00
|
|
|
|
2019-10-09 19:58:22 +02:00
|
|
|
const REFRESH_TIME = 1000 * 10; // Refresh every 10 seconds
|
2019-06-29 13:37:21 +02:00
|
|
|
|
2020-03-05 19:54:56 +01:00
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
2020-03-09 23:15:13 +01:00
|
|
|
theme: Object,
|
2020-03-05 19:54:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
refreshing: boolean,
|
|
|
|
firstLoading: boolean,
|
2020-03-08 11:27:05 +01:00
|
|
|
modalCurrentDisplayItem: React.Node,
|
2020-03-05 19:54:56 +01:00
|
|
|
machinesWatched: Array<string>,
|
2020-03-08 00:05:41 +01:00
|
|
|
bannerVisible: boolean,
|
2020-03-05 19:54:56 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Class defining the app's proxiwash screen. This screen shows information about washing machines and
|
|
|
|
* dryers, taken from a scrapper reading proxiwash website
|
|
|
|
*/
|
2020-03-09 23:15:13 +01:00
|
|
|
class ProxiwashScreen extends React.Component<Props, State> {
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2020-03-08 14:19:47 +01:00
|
|
|
modalRef: Object;
|
2020-03-08 11:27:05 +01:00
|
|
|
|
2020-02-23 18:15:30 +01:00
|
|
|
onAboutPress: Function;
|
2020-03-05 19:54:56 +01:00
|
|
|
getRenderItem: Function;
|
2020-03-07 09:15:25 +01:00
|
|
|
getRenderSectionHeader: Function;
|
2020-03-05 19:54:56 +01:00
|
|
|
createDataset: Function;
|
2020-03-08 00:05:41 +01:00
|
|
|
onHideBanner: Function;
|
2020-03-08 14:19:47 +01:00
|
|
|
onModalRef: Function;
|
2020-03-05 19:54:56 +01:00
|
|
|
|
2020-03-08 00:20:26 +01:00
|
|
|
fetchedData: Object;
|
2020-03-09 23:15:13 +01:00
|
|
|
colors: Object;
|
2020-03-08 00:20:26 +01:00
|
|
|
|
2020-03-05 19:54:56 +01:00
|
|
|
state = {
|
|
|
|
refreshing: false,
|
|
|
|
firstLoading: true,
|
|
|
|
fetchedData: {},
|
|
|
|
machinesWatched: [],
|
2020-03-08 11:27:05 +01:00
|
|
|
modalCurrentDisplayItem: null,
|
2020-03-08 00:05:41 +01:00
|
|
|
bannerVisible: AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.current === '1',
|
2020-03-05 19:54:56 +01:00
|
|
|
};
|
2020-02-23 18:15:30 +01:00
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Creates machine state parameters using current theme and translations
|
|
|
|
*/
|
2020-03-09 23:15:13 +01:00
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
2020-03-07 11:49:32 +01:00
|
|
|
stateStrings[ProxiwashConstants.machineStates.TERMINE] = i18n.t('proxiwashScreen.states.finished');
|
|
|
|
stateStrings[ProxiwashConstants.machineStates.DISPONIBLE] = i18n.t('proxiwashScreen.states.ready');
|
|
|
|
stateStrings[ProxiwashConstants.machineStates["EN COURS"]] = i18n.t('proxiwashScreen.states.running');
|
|
|
|
stateStrings[ProxiwashConstants.machineStates.HS] = i18n.t('proxiwashScreen.states.broken');
|
|
|
|
stateStrings[ProxiwashConstants.machineStates.ERREUR] = i18n.t('proxiwashScreen.states.error');
|
|
|
|
|
|
|
|
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');
|
|
|
|
|
|
|
|
stateIcons[ProxiwashConstants.machineStates.TERMINE] = 'check-circle';
|
|
|
|
stateIcons[ProxiwashConstants.machineStates.DISPONIBLE] = 'radiobox-blank';
|
|
|
|
stateIcons[ProxiwashConstants.machineStates["EN COURS"]] = 'progress-check';
|
|
|
|
stateIcons[ProxiwashConstants.machineStates.HS] = 'alert-octagram-outline';
|
|
|
|
stateIcons[ProxiwashConstants.machineStates.ERREUR] = 'alert';
|
2019-07-31 14:22:36 +02:00
|
|
|
|
2019-08-13 12:20:03 +02:00
|
|
|
// let dataString = AsyncStorageManager.getInstance().preferences.proxiwashWatchedMachines.current;
|
2020-02-23 18:15:30 +01:00
|
|
|
this.onAboutPress = this.onAboutPress.bind(this);
|
2020-03-05 19:54:56 +01:00
|
|
|
this.getRenderItem = this.getRenderItem.bind(this);
|
2020-03-07 09:15:25 +01:00
|
|
|
this.getRenderSectionHeader = this.getRenderSectionHeader.bind(this);
|
2020-03-05 19:54:56 +01:00
|
|
|
this.createDataset = this.createDataset.bind(this);
|
2020-03-08 00:05:41 +01:00
|
|
|
this.onHideBanner = this.onHideBanner.bind(this);
|
2020-03-08 14:19:47 +01:00
|
|
|
this.onModalRef = this.onModalRef.bind(this);
|
2020-03-09 23:15:13 +01:00
|
|
|
this.colors = props.theme.colors;
|
2020-03-08 00:05:41 +01:00
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Callback used when closing the banner.
|
|
|
|
* This hides the banner and saves to preferences to prevent it from reopening
|
|
|
|
*/
|
2020-03-08 00:05:41 +01:00
|
|
|
onHideBanner() {
|
|
|
|
this.setState({bannerVisible: false});
|
|
|
|
AsyncStorageManager.getInstance().savePref(
|
|
|
|
AsyncStorageManager.getInstance().preferences.proxiwashShowBanner.key,
|
|
|
|
'0'
|
|
|
|
);
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
/**
|
|
|
|
* Setup notification channel for android and add listeners to detect notifications fired
|
|
|
|
*/
|
2019-08-04 14:28:41 +02:00
|
|
|
componentDidMount() {
|
2020-03-29 15:59:25 +02:00
|
|
|
const rightButton = this.getAboutButton.bind(this);
|
2020-03-06 09:12:56 +01:00
|
|
|
this.props.navigation.setOptions({
|
|
|
|
headerRight: rightButton,
|
|
|
|
});
|
2019-09-12 23:23:36 +02:00
|
|
|
if (AsyncStorageManager.getInstance().preferences.expoToken.current !== '') {
|
|
|
|
// Get latest watchlist from server
|
2020-03-30 15:28:08 +02:00
|
|
|
Notifications.getMachineNotificationWatchlist((fetchedList) => {
|
2019-08-13 12:53:21 +02:00
|
|
|
this.setState({machinesWatched: fetchedList})
|
|
|
|
});
|
2019-09-12 23:23:36 +02:00
|
|
|
// Get updated watchlist after received notification
|
2020-01-31 16:51:43 +01:00
|
|
|
Expo.Notifications.addListener(() => {
|
2020-03-30 15:28:08 +02:00
|
|
|
Notifications.getMachineNotificationWatchlist((fetchedList) => {
|
2019-09-12 23:23:36 +02:00
|
|
|
this.setState({machinesWatched: fetchedList})
|
|
|
|
});
|
2019-08-04 14:28:41 +02:00
|
|
|
});
|
2019-09-12 23:23:36 +02:00
|
|
|
if (Platform.OS === 'android') {
|
|
|
|
Expo.Notifications.createChannelAndroidAsync('reminders', {
|
|
|
|
name: 'Reminders',
|
|
|
|
priority: 'max',
|
|
|
|
vibrate: [0, 250, 250, 250],
|
|
|
|
});
|
|
|
|
}
|
2019-08-04 14:28:41 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Callback used when pressing the about button.
|
|
|
|
* This will open the ProxiwashAboutScreen.
|
|
|
|
*/
|
|
|
|
onAboutPress() {
|
|
|
|
this.props.navigation.navigate('ProxiwashAboutScreen');
|
2019-07-31 14:22:36 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets the about header button
|
|
|
|
*
|
|
|
|
* @return {*}
|
|
|
|
*/
|
|
|
|
getAboutButton() {
|
|
|
|
return <HeaderButton icon={'information'} onPress={this.onAboutPress}/>;
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Extracts the key for the given item
|
|
|
|
*
|
|
|
|
* @param item The item to extract the key from
|
|
|
|
* @return {*} The extracted key
|
|
|
|
*/
|
|
|
|
getKeyExtractor(item: Object) {
|
|
|
|
return item !== undefined ? item.number : undefined;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Setups notifications for the machine with the given ID.
|
2019-06-29 15:43:57 +02:00
|
|
|
* One notification will be sent at the end of the program.
|
|
|
|
* Another will be send a few minutes before the end, based on the value of reminderNotifTime
|
|
|
|
*
|
|
|
|
* @param machineId The machine's ID
|
|
|
|
* @returns {Promise<void>}
|
|
|
|
*/
|
2019-08-13 12:20:03 +02:00
|
|
|
setupNotifications(machineId: string) {
|
2019-09-12 23:23:36 +02:00
|
|
|
if (AsyncStorageManager.getInstance().preferences.expoToken.current !== '') {
|
|
|
|
if (!this.isMachineWatched(machineId)) {
|
2020-03-30 15:28:08 +02:00
|
|
|
Notifications.setupMachineNotification(machineId, true);
|
2019-09-12 23:23:36 +02:00
|
|
|
this.saveNotificationToState(machineId);
|
|
|
|
} else
|
|
|
|
this.disableNotification(machineId);
|
|
|
|
} else {
|
|
|
|
this.showNotificationsDisabledWarning();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Shows a warning telling the user notifications are disabled for the app
|
|
|
|
*/
|
2019-09-12 23:23:36 +02:00
|
|
|
showNotificationsDisabledWarning() {
|
|
|
|
Alert.alert(
|
|
|
|
i18n.t("proxiwashScreen.modal.notificationErrorTitle"),
|
|
|
|
i18n.t("proxiwashScreen.modal.notificationErrorDescription"),
|
|
|
|
);
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Stops scheduled notifications for the machine of the given ID.
|
2019-06-29 15:43:57 +02:00
|
|
|
* This will also remove the notification if it was already shown.
|
|
|
|
*
|
|
|
|
* @param machineId The machine's ID
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
disableNotification(machineId: string) {
|
2019-08-04 14:28:41 +02:00
|
|
|
let data = this.state.machinesWatched;
|
2019-06-27 19:33:22 +02:00
|
|
|
if (data.length > 0) {
|
2019-08-13 12:20:03 +02:00
|
|
|
let arrayIndex = data.indexOf(machineId);
|
2019-07-31 14:22:36 +02:00
|
|
|
if (arrayIndex !== -1) {
|
2020-03-30 15:28:08 +02:00
|
|
|
Notifications.setupMachineNotification(machineId, false);
|
2019-08-13 12:53:21 +02:00
|
|
|
this.removeNotificationFroState(arrayIndex);
|
2019-07-31 14:22:36 +02:00
|
|
|
}
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
|
2019-08-06 13:28:11 +02:00
|
|
|
*
|
|
|
|
* @param machineId
|
|
|
|
*/
|
2019-08-13 12:53:21 +02:00
|
|
|
saveNotificationToState(machineId: string) {
|
2019-07-31 14:22:36 +02:00
|
|
|
let data = this.state.machinesWatched;
|
2019-08-13 12:20:03 +02:00
|
|
|
data.push(machineId);
|
2019-08-13 12:53:21 +02:00
|
|
|
this.updateNotificationState(data);
|
2019-07-31 14:22:36 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Removes the given index from the watchlist array and saves it to preferences
|
2019-08-06 13:28:11 +02:00
|
|
|
*
|
|
|
|
* @param index
|
|
|
|
*/
|
2019-08-13 12:53:21 +02:00
|
|
|
removeNotificationFroState(index: number) {
|
2019-07-31 14:22:36 +02:00
|
|
|
let data = this.state.machinesWatched;
|
|
|
|
data.splice(index, 1);
|
2019-08-13 12:53:21 +02:00
|
|
|
this.updateNotificationState(data);
|
2019-07-31 14:22:36 +02:00
|
|
|
}
|
|
|
|
|
2019-08-06 13:28:11 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Sets the given data as the watchlist
|
2019-08-06 13:28:11 +02:00
|
|
|
*
|
|
|
|
* @param data
|
|
|
|
*/
|
2019-08-13 12:53:21 +02:00
|
|
|
updateNotificationState(data: Array<Object>) {
|
2019-07-31 14:22:36 +02:00
|
|
|
this.setState({machinesWatched: data});
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Checks whether the machine of the given ID has scheduled notifications
|
|
|
|
*
|
|
|
|
* @param machineID The machine's ID
|
|
|
|
* @returns {boolean}
|
|
|
|
*/
|
|
|
|
isMachineWatched(machineID: string) {
|
2019-08-13 12:20:03 +02:00
|
|
|
return this.state.machinesWatched.indexOf(machineID) !== -1;
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Creates the dataset to be used by the flatlist
|
|
|
|
*
|
|
|
|
* @param fetchedData
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2019-07-26 14:14:01 +02:00
|
|
|
createDataset(fetchedData: Object) {
|
2020-03-10 16:01:24 +01:00
|
|
|
let data = fetchedData;
|
|
|
|
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) {
|
|
|
|
data = JSON.parse(JSON.stringify(fetchedData)); // Deep copy
|
|
|
|
AprilFoolsManager.getNewProxiwashDryerOrderedList(data.dryers);
|
|
|
|
AprilFoolsManager.getNewProxiwashWasherOrderedList(data.washers);
|
|
|
|
}
|
2020-03-08 00:20:26 +01:00
|
|
|
this.fetchedData = fetchedData;
|
2020-03-10 16:01:24 +01:00
|
|
|
|
2019-07-26 14:14:01 +02:00
|
|
|
return [
|
2019-08-08 13:57:03 +02:00
|
|
|
{
|
|
|
|
title: i18n.t('proxiwashScreen.dryers'),
|
|
|
|
icon: 'tumble-dryer',
|
2020-03-10 16:01:24 +01:00
|
|
|
data: data.dryers === undefined ? [] : data.dryers,
|
2020-03-29 15:59:25 +02:00
|
|
|
keyExtractor: this.getKeyExtractor
|
2019-08-08 13:57:03 +02:00
|
|
|
},
|
2020-03-05 19:54:56 +01:00
|
|
|
{
|
|
|
|
title: i18n.t('proxiwashScreen.washers'),
|
|
|
|
icon: 'washing-machine',
|
2020-03-10 16:01:24 +01:00
|
|
|
data: data.washers === undefined ? [] : data.washers,
|
2020-03-29 15:59:25 +02:00
|
|
|
keyExtractor: this.getKeyExtractor
|
2020-03-05 19:54:56 +01:00
|
|
|
},
|
2019-07-26 14:14:01 +02:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Shows a modal for the given item
|
|
|
|
*
|
|
|
|
* @param title The title to use
|
|
|
|
* @param item The item to display information for in the modal
|
|
|
|
* @param isDryer True if the given item is a dryer
|
|
|
|
*/
|
2020-03-08 11:27:05 +01:00
|
|
|
showModal(title: string, item: Object, isDryer: boolean) {
|
|
|
|
this.setState({
|
|
|
|
modalCurrentDisplayItem: this.getModalContent(title, item, isDryer)
|
|
|
|
});
|
2020-03-08 14:19:47 +01:00
|
|
|
if (this.modalRef) {
|
|
|
|
this.modalRef.open();
|
2020-03-08 11:27:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Callback used when the user clicks on enable notifications for a machine
|
|
|
|
*
|
|
|
|
* @param machineId The machine's id to set notifications for
|
|
|
|
*/
|
2020-03-08 11:27:05 +01:00
|
|
|
onSetupNotificationsPress(machineId: string) {
|
2020-03-08 14:19:47 +01:00
|
|
|
if (this.modalRef) {
|
|
|
|
this.modalRef.close();
|
2020-03-08 11:27:05 +01:00
|
|
|
}
|
|
|
|
this.setupNotifications(machineId)
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Generates the modal content.
|
|
|
|
* This shows information for the given machine.
|
|
|
|
*
|
|
|
|
* @param title The title to use
|
|
|
|
* @param item The item to display information for in the modal
|
|
|
|
* @param isDryer True if the given item is a dryer
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2020-03-08 11:27:05 +01:00
|
|
|
getModalContent(title: string, item: Object, isDryer: boolean) {
|
|
|
|
let button = {
|
|
|
|
text: i18n.t("proxiwashScreen.modal.ok"),
|
|
|
|
icon: '',
|
|
|
|
onPress: undefined
|
|
|
|
};
|
2020-03-07 11:49:32 +01:00
|
|
|
let message = modalStateStrings[ProxiwashConstants.machineStates[item.state]];
|
2020-03-08 11:27:05 +01:00
|
|
|
const onPress = this.onSetupNotificationsPress.bind(this, item.number);
|
2020-03-07 11:49:32 +01:00
|
|
|
if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"]) {
|
2020-03-08 11:27:05 +01:00
|
|
|
button =
|
2019-07-30 20:40:17 +02:00
|
|
|
{
|
|
|
|
text: this.isMachineWatched(item.number) ?
|
|
|
|
i18n.t("proxiwashScreen.modal.disableNotifications") :
|
|
|
|
i18n.t("proxiwashScreen.modal.enableNotifications"),
|
2020-03-08 11:27:05 +01:00
|
|
|
icon: '',
|
2020-02-23 21:47:36 +01:00
|
|
|
onPress: onPress
|
2019-07-30 20:40:17 +02:00
|
|
|
}
|
2020-03-08 11:27:05 +01:00
|
|
|
;
|
2019-07-30 20:40:17 +02:00
|
|
|
message = i18n.t('proxiwashScreen.modal.running',
|
|
|
|
{
|
|
|
|
start: item.startTime,
|
|
|
|
end: item.endTime,
|
2019-08-23 14:13:22 +02:00
|
|
|
remaining: item.remainingTime
|
2019-07-30 20:40:17 +02:00
|
|
|
});
|
2020-03-07 11:49:32 +01:00
|
|
|
} else if (ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates.DISPONIBLE) {
|
2019-08-09 10:54:05 +02:00
|
|
|
if (isDryer)
|
|
|
|
message += '\n' + i18n.t('proxiwashScreen.dryersTariff');
|
|
|
|
else
|
|
|
|
message += '\n' + i18n.t('proxiwashScreen.washersTariff');
|
2019-07-30 20:40:17 +02:00
|
|
|
}
|
2020-03-08 11:27:05 +01:00
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
flex: 1,
|
|
|
|
padding: 20
|
|
|
|
}}>
|
|
|
|
<Card.Title
|
|
|
|
title={title}
|
|
|
|
left={() => <Avatar.Icon
|
|
|
|
icon={isDryer ? 'tumble-dryer' : 'washing-machine'}
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.text}
|
2020-03-08 11:27:05 +01:00
|
|
|
style={{backgroundColor: 'transparent'}}/>}
|
|
|
|
|
|
|
|
/>
|
|
|
|
<Card.Content>
|
|
|
|
<Text>{message}</Text>
|
|
|
|
</Card.Content>
|
|
|
|
|
|
|
|
{button.onPress !== undefined ?
|
|
|
|
<Card.Actions>
|
|
|
|
<Button
|
|
|
|
icon={button.icon}
|
|
|
|
mode="contained"
|
|
|
|
onPress={button.onPress}
|
|
|
|
style={{marginLeft: 'auto', marginRight: 'auto'}}
|
|
|
|
>
|
|
|
|
{button.text}
|
|
|
|
</Button>
|
|
|
|
</Card.Actions> : null}
|
|
|
|
</View>
|
2019-07-30 20:40:17 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Callback used when receiving modal ref
|
|
|
|
*
|
|
|
|
* @param ref
|
|
|
|
*/
|
2020-03-08 14:19:47 +01:00
|
|
|
onModalRef(ref: Object) {
|
|
|
|
this.modalRef = ref;
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets the number of machines available
|
|
|
|
*
|
|
|
|
* @param isDryer True if we are only checking for dryer, false for washers
|
|
|
|
* @return {number} The number of machines available
|
|
|
|
*/
|
2020-03-08 00:20:26 +01:00
|
|
|
getMachineAvailableNumber(isDryer: boolean) {
|
|
|
|
let data;
|
|
|
|
if (isDryer)
|
|
|
|
data = this.fetchedData.dryers;
|
|
|
|
else
|
|
|
|
data = this.fetchedData.washers;
|
|
|
|
let count = 0;
|
|
|
|
for (let i = 0; i < data.length; i++) {
|
|
|
|
if (ProxiwashConstants.machineStates[data[i].state] === ProxiwashConstants.machineStates["DISPONIBLE"])
|
|
|
|
count += 1;
|
|
|
|
}
|
|
|
|
return count;
|
|
|
|
}
|
|
|
|
|
2020-03-29 15:59:25 +02:00
|
|
|
/**
|
|
|
|
* Gets the section render item
|
|
|
|
*
|
|
|
|
* @param section The section to render
|
|
|
|
* @return {*}
|
|
|
|
*/
|
2020-03-07 09:15:25 +01:00
|
|
|
getRenderSectionHeader({section}: Object) {
|
2020-03-08 15:33:29 +01:00
|
|
|
const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
2020-03-10 15:33:01 +01:00
|
|
|
const nbAvailable = this.getMachineAvailableNumber(isDryer);
|
|
|
|
const subtitle = nbAvailable + ' ' + ((nbAvailable <= 1) ? i18n.t('proxiwashScreen.numAvailable')
|
|
|
|
: i18n.t('proxiwashScreen.numAvailablePlural'));
|
2020-03-07 09:15:25 +01:00
|
|
|
return (
|
2020-03-10 15:33:01 +01:00
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
2020-03-08 15:33:29 +01:00
|
|
|
marginLeft: 5,
|
|
|
|
marginRight: 5,
|
2020-03-08 00:05:41 +01:00
|
|
|
marginBottom: 10,
|
|
|
|
marginTop: 20,
|
2020-03-07 09:15:25 +01:00
|
|
|
}}>
|
2020-03-10 15:33:01 +01:00
|
|
|
<Avatar.Icon
|
|
|
|
icon={isDryer ? 'tumble-dryer' : 'washing-machine'}
|
|
|
|
color={this.colors.primary}
|
|
|
|
style={{backgroundColor: 'transparent'}}
|
2020-03-08 00:05:41 +01:00
|
|
|
/>
|
2020-03-10 15:33:01 +01:00
|
|
|
<View style={{
|
|
|
|
justifyContent: 'center',
|
|
|
|
}}>
|
|
|
|
<Text style={{
|
|
|
|
fontSize: 20,
|
|
|
|
fontWeight: 'bold',
|
|
|
|
}}>
|
|
|
|
{section.title}
|
|
|
|
</Text>
|
|
|
|
|
|
|
|
<Text style={{
|
|
|
|
color: this.colors.subtitle,
|
|
|
|
}}>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</View>
|
2020-03-05 19:54:56 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
2020-03-29 15:59:25 +02:00
|
|
|
* Gets the list item to be rendered
|
2019-06-29 15:43:57 +02:00
|
|
|
*
|
2019-07-26 14:14:01 +02:00
|
|
|
* @param item The object containing the item's FetchedData
|
2019-06-29 15:43:57 +02:00
|
|
|
* @param section The object describing the current SectionList section
|
|
|
|
* @returns {React.Node}
|
|
|
|
*/
|
2020-03-05 21:48:37 +01:00
|
|
|
getRenderItem({item, section}: Object) {
|
2020-03-07 11:49:32 +01:00
|
|
|
const isMachineRunning = ProxiwashConstants.machineStates[item.state] === ProxiwashConstants.machineStates["EN COURS"];
|
2020-03-10 16:01:24 +01:00
|
|
|
let displayNumber = item.number;
|
|
|
|
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
|
|
|
|
displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber(parseInt(item.number));
|
|
|
|
const machineName = (section.title === i18n.t('proxiwashScreen.dryers') ?
|
|
|
|
i18n.t('proxiwashScreen.dryer') :
|
|
|
|
i18n.t('proxiwashScreen.washer')) + ' n°' + displayNumber;
|
2020-03-07 11:49:32 +01:00
|
|
|
const isDryer = section.title === i18n.t('proxiwashScreen.dryers');
|
2020-03-08 11:27:05 +01:00
|
|
|
const onPress = this.showModal.bind(this, machineName, item, isDryer);
|
2020-03-06 23:15:01 +01:00
|
|
|
let width = item.donePercent !== '' ? (parseInt(item.donePercent)).toString() + '%' : 0;
|
2020-03-07 11:49:32 +01:00
|
|
|
if (ProxiwashConstants.machineStates[item.state] === '0')
|
2020-03-06 23:15:01 +01:00
|
|
|
width = '100%';
|
2019-06-27 19:33:22 +02:00
|
|
|
return (
|
2020-03-07 11:49:32 +01:00
|
|
|
<ProxiwashListItem
|
|
|
|
title={machineName}
|
|
|
|
description={isMachineRunning ? item.startTime + '/' + item.endTime : ''}
|
|
|
|
onPress={onPress}
|
|
|
|
progress={width}
|
|
|
|
state={item.state}
|
|
|
|
isWatched={this.isMachineWatched(item.number)}
|
|
|
|
isDryer={isDryer}
|
|
|
|
statusText={stateStrings[ProxiwashConstants.machineStates[item.state]]}
|
|
|
|
statusIcon={stateIcons[ProxiwashConstants.machineStates[item.state]]}
|
|
|
|
/>
|
2020-03-06 23:15:01 +01:00
|
|
|
);
|
2019-06-27 19:33:22 +02:00
|
|
|
}
|
2020-03-09 23:15:13 +01:00
|
|
|
|
|
|
|
render() {
|
|
|
|
const nav = this.props.navigation;
|
|
|
|
return (
|
|
|
|
<View>
|
|
|
|
<Banner
|
|
|
|
visible={this.state.bannerVisible}
|
|
|
|
actions={[
|
|
|
|
{
|
|
|
|
label: 'OK',
|
|
|
|
onPress: this.onHideBanner,
|
|
|
|
},
|
|
|
|
]}
|
|
|
|
icon={() => <Avatar.Icon
|
|
|
|
icon={'information'}
|
|
|
|
size={40}
|
|
|
|
/>}
|
|
|
|
>
|
|
|
|
{i18n.t('proxiwashScreen.enableNotificationsTip')}
|
|
|
|
</Banner>
|
|
|
|
<CustomModal onRef={this.onModalRef}>
|
|
|
|
{this.state.modalCurrentDisplayItem}
|
|
|
|
</CustomModal>
|
|
|
|
<WebSectionList
|
|
|
|
createDataset={this.createDataset}
|
|
|
|
navigation={nav}
|
|
|
|
fetchUrl={DATA_URL}
|
|
|
|
renderItem={this.getRenderItem}
|
|
|
|
renderSectionHeader={this.getRenderSectionHeader}
|
|
|
|
autoRefreshTime={REFRESH_TIME}
|
2020-03-10 16:43:52 +01:00
|
|
|
refreshOnFocus={true}
|
|
|
|
updateData={this.state.machinesWatched.length}/>
|
2020-03-09 23:15:13 +01:00
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
2020-03-09 23:15:13 +01:00
|
|
|
|
|
|
|
export default withTheme(ProxiwashScreen);
|