From f8f5749478fd9632822f21dc24f1329b26050da8 Mon Sep 17 00:00:00 2001 From: docjyJ Date: Sat, 5 Sep 2020 11:01:31 +0200 Subject: [PATCH] add settings selection --- .../Lists/Proxiwash/ProxiwashListItem.js | 3 +- src/managers/AsyncStorageManager.js | 4 ++ src/screens/Other/Settings/SettingsScreen.js | 50 +++++++++++++ src/screens/Proxiwash/ProxiwashScreen.js | 70 +++++++++++++++++-- 4 files changed, 122 insertions(+), 5 deletions(-) diff --git a/src/components/Lists/Proxiwash/ProxiwashListItem.js b/src/components/Lists/Proxiwash/ProxiwashListItem.js index cc7a0a8..60fc01f 100644 --- a/src/components/Lists/Proxiwash/ProxiwashListItem.js +++ b/src/components/Lists/Proxiwash/ProxiwashListItem.js @@ -67,6 +67,7 @@ class ProxiwashListItem extends React.Component { this.updateStateStrings(); let displayNumber = props.item.number; + const displayMaxWeight = props.item.maxWeight; if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber( parseInt(props.item.number, 10), @@ -75,7 +76,7 @@ class ProxiwashListItem extends React.Component { this.title = props.isDryer ? i18n.t('screens.proxiwash.dryer') : i18n.t('screens.proxiwash.washer'); - this.title += ` n°${displayNumber}`; + this.title += ` n°${displayNumber} - ${displayMaxWeight} kg`; } shouldComponentUpdate(nextProps: PropsType): boolean { diff --git a/src/managers/AsyncStorageManager.js b/src/managers/AsyncStorageManager.js index f5bc046..2c6b6c3 100644 --- a/src/managers/AsyncStorageManager.js +++ b/src/managers/AsyncStorageManager.js @@ -107,6 +107,10 @@ export default class AsyncStorageManager { key: 'gameScores', default: '[]', }, + selectedWash: { + key: 'selectedWash', + default: 'washinsa', + }, }; #currentPreferences: {[key: string]: string}; diff --git a/src/screens/Other/Settings/SettingsScreen.js b/src/screens/Other/Settings/SettingsScreen.js index 9f687a0..35705b3 100644 --- a/src/screens/Other/Settings/SettingsScreen.js +++ b/src/screens/Other/Settings/SettingsScreen.js @@ -52,6 +52,9 @@ class SettingsScreen extends React.Component { startScreenPickerSelected: AsyncStorageManager.getString( AsyncStorageManager.PREFERENCES.defaultStartScreen.key, ), + selectedWash: AsyncStorageManager.getString( + AsyncStorageManager.PREFERENCES.selectedWash.key, + ), isDebugUnlocked: AsyncStorageManager.getBool( AsyncStorageManager.PREFERENCES.debugUnlocked.key, ), @@ -85,6 +88,21 @@ class SettingsScreen extends React.Component { } }; + /** + * Saves the value for the proxiwash reminder notification time + * + * @param value The value to store + */ + onSelectWashValueChange = (value: string) => { + if (value != null) { + this.setState({selectedWash: value}); + AsyncStorageManager.set( + AsyncStorageManager.PREFERENCES.selectedWash.key, + value, + ); + } + }; + /** * Returns a picker allowing the user to select the proxiwash reminder notification time * @@ -106,6 +124,24 @@ class SettingsScreen extends React.Component { ); } + /** + * Returns a picker allowing the user to select the wash + * + * @returns {React.Node} + */ + getSelectWashPicker(): React.Node { + const {selectedWash} = this.state; + return ( + + + + + ); + } + /** * Returns a picker allowing the user to select the start screen * @@ -288,6 +324,20 @@ class SettingsScreen extends React.Component { {this.getProxiwashNotifPicker()} + + ( + + )} + /> + + {this.getSelectWashPicker()} diff --git a/src/screens/Proxiwash/ProxiwashScreen.js b/src/screens/Proxiwash/ProxiwashScreen.js index a6f21c1..5c1694e 100644 --- a/src/screens/Proxiwash/ProxiwashScreen.js +++ b/src/screens/Proxiwash/ProxiwashScreen.js @@ -26,9 +26,31 @@ import { import {MASCOT_STYLE} from '../../components/Mascot/Mascot'; import MascotPopup from '../../components/Mascot/MascotPopup'; import type {SectionListDataType} from '../../components/Screens/WebSectionList'; +import type {CardTitleIconPropsType} from '../../constants/PaperStyles'; -const DATA_URL = - 'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json'; +type LaverieType = { + title: string, + subtitle: string, + icon: string, + url: string, +}; + +const DATA = { + washinsa: { + title: 'Laverie INSA', + subtitle: 'Ta laverie préférer !!', + icon: 'school-outline', + url: + 'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json', + }, + tripodeB: { + title: 'Laverie Tripode B', + subtitle: 'En vrai je sais pas trop quoi marqué.', + icon: 'domain', + url: + 'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/tripode_b_data.json', + }, +}; const modalStateStrings = {}; @@ -38,6 +60,7 @@ const LIST_ITEM_HEIGHT = 64; export type ProxiwashMachineType = { number: string, state: string, + maxWeight: number, startTime: string, endTime: string, donePercent: string, @@ -53,6 +76,7 @@ type PropsType = { type StateType = { modalCurrentDisplayItem: React.Node, machinesWatched: Array, + selectedWash: string, }; /** @@ -87,6 +111,9 @@ class ProxiwashScreen extends React.Component { machinesWatched: AsyncStorageManager.getObject( AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key, ), + selectedWash: AsyncStorageManager.getString( + AsyncStorageManager.PREFERENCES.selectedWash.key, + ), }; modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t( 'screens.proxiwash.modal.ready', @@ -396,6 +423,29 @@ class ProxiwashScreen extends React.Component { } }; + getListHeader = (): React.Node => { + const {selectedWash} = this.state; + let data: LaverieType; + switch (selectedWash) { + case 'tripodeB': + data = DATA.tripodeB; + break; + default: + data = DATA.washinsa; + } + return ( + + ( + + )} + /> + + ); + }; + /** * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences * @@ -437,8 +487,19 @@ class ProxiwashScreen extends React.Component { render(): React.Node { const {state} = this; const {navigation} = this.props; + let data: LaverieType; + switch (state.selectedWash) { + case 'tripodeB': + data = DATA.tripodeB; + break; + default: + data = DATA.washinsa; + } return ( - + {