add settings selection

This commit is contained in:
docjyJ 2020-09-05 11:01:31 +02:00
parent 3de49732b9
commit f8f5749478
4 changed files with 122 additions and 5 deletions

View file

@ -67,6 +67,7 @@ class ProxiwashListItem extends React.Component<PropsType> {
this.updateStateStrings(); this.updateStateStrings();
let displayNumber = props.item.number; let displayNumber = props.item.number;
const displayMaxWeight = props.item.maxWeight;
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber( displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber(
parseInt(props.item.number, 10), parseInt(props.item.number, 10),
@ -75,7 +76,7 @@ class ProxiwashListItem extends React.Component<PropsType> {
this.title = props.isDryer this.title = props.isDryer
? i18n.t('screens.proxiwash.dryer') ? i18n.t('screens.proxiwash.dryer')
: i18n.t('screens.proxiwash.washer'); : i18n.t('screens.proxiwash.washer');
this.title += `${displayNumber}`; this.title += `${displayNumber} - ${displayMaxWeight} kg`;
} }
shouldComponentUpdate(nextProps: PropsType): boolean { shouldComponentUpdate(nextProps: PropsType): boolean {

View file

@ -107,6 +107,10 @@ export default class AsyncStorageManager {
key: 'gameScores', key: 'gameScores',
default: '[]', default: '[]',
}, },
selectedWash: {
key: 'selectedWash',
default: 'washinsa',
},
}; };
#currentPreferences: {[key: string]: string}; #currentPreferences: {[key: string]: string};

View file

@ -52,6 +52,9 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
startScreenPickerSelected: AsyncStorageManager.getString( startScreenPickerSelected: AsyncStorageManager.getString(
AsyncStorageManager.PREFERENCES.defaultStartScreen.key, AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
), ),
selectedWash: AsyncStorageManager.getString(
AsyncStorageManager.PREFERENCES.selectedWash.key,
),
isDebugUnlocked: AsyncStorageManager.getBool( isDebugUnlocked: AsyncStorageManager.getBool(
AsyncStorageManager.PREFERENCES.debugUnlocked.key, AsyncStorageManager.PREFERENCES.debugUnlocked.key,
), ),
@ -85,6 +88,21 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
} }
}; };
/**
* 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 * Returns a picker allowing the user to select the proxiwash reminder notification time
* *
@ -106,6 +124,24 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
); );
} }
/**
* Returns a picker allowing the user to select the wash
*
* @returns {React.Node}
*/
getSelectWashPicker(): React.Node {
const {selectedWash} = this.state;
return (
<ToggleButton.Row
onValueChange={this.onSelectWashValueChange}
value={selectedWash}
style={{marginLeft: 'auto', marginRight: 'auto'}}>
<ToggleButton icon="school-outline" value="washinsa" />
<ToggleButton icon="domain" value="tripodeB" />
</ToggleButton.Row>
);
}
/** /**
* Returns a picker allowing the user to select the start screen * Returns a picker allowing the user to select the start screen
* *
@ -288,6 +324,20 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
<View style={{marginLeft: 30}}> <View style={{marginLeft: 30}}>
{this.getProxiwashNotifPicker()} {this.getProxiwashNotifPicker()}
</View> </View>
<List.Item
title={i18n.t('screens.settings.proxiwashNotifReminder')}
description={i18n.t('screens.settings.proxiwashNotifReminderSub')}
left={(props: ListIconPropsType): React.Node => (
<List.Icon
color={props.color}
style={props.style}
icon="washing-machine"
/>
)}
/>
<View style={{marginLeft: 30}}>{this.getSelectWashPicker()}</View>
</List.Section> </List.Section>
</Card> </Card>
<Card style={{margin: 5}}> <Card style={{margin: 5}}>

View file

@ -26,9 +26,31 @@ import {
import {MASCOT_STYLE} from '../../components/Mascot/Mascot'; import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
import MascotPopup from '../../components/Mascot/MascotPopup'; import MascotPopup from '../../components/Mascot/MascotPopup';
import type {SectionListDataType} from '../../components/Screens/WebSectionList'; import type {SectionListDataType} from '../../components/Screens/WebSectionList';
import type {CardTitleIconPropsType} from '../../constants/PaperStyles';
const DATA_URL = type LaverieType = {
'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json'; 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 = {}; const modalStateStrings = {};
@ -38,6 +60,7 @@ const LIST_ITEM_HEIGHT = 64;
export type ProxiwashMachineType = { export type ProxiwashMachineType = {
number: string, number: string,
state: string, state: string,
maxWeight: number,
startTime: string, startTime: string,
endTime: string, endTime: string,
donePercent: string, donePercent: string,
@ -53,6 +76,7 @@ type PropsType = {
type StateType = { type StateType = {
modalCurrentDisplayItem: React.Node, modalCurrentDisplayItem: React.Node,
machinesWatched: Array<ProxiwashMachineType>, machinesWatched: Array<ProxiwashMachineType>,
selectedWash: string,
}; };
/** /**
@ -87,6 +111,9 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
machinesWatched: AsyncStorageManager.getObject( machinesWatched: AsyncStorageManager.getObject(
AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key, AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key,
), ),
selectedWash: AsyncStorageManager.getString(
AsyncStorageManager.PREFERENCES.selectedWash.key,
),
}; };
modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t( modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t(
'screens.proxiwash.modal.ready', 'screens.proxiwash.modal.ready',
@ -396,6 +423,29 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
} }
}; };
getListHeader = (): React.Node => {
const {selectedWash} = this.state;
let data: LaverieType;
switch (selectedWash) {
case 'tripodeB':
data = DATA.tripodeB;
break;
default:
data = DATA.washinsa;
}
return (
<Card>
<Card.Title
title={data.title}
subtitle={data.subtitle}
left={(iconProps: CardTitleIconPropsType): React.Node => (
<Avatar.Icon size={iconProps.size} icon={data.icon} />
)}
/>
</Card>
);
};
/** /**
* Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences * 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<PropsType, StateType> {
render(): React.Node { render(): React.Node {
const {state} = this; const {state} = this;
const {navigation} = this.props; const {navigation} = this.props;
let data: LaverieType;
switch (state.selectedWash) {
case 'tripodeB':
data = DATA.tripodeB;
break;
default:
data = DATA.washinsa;
}
return ( return (
<View style={{flex: 1}}> <View
style={{
flex: 1,
}}>
<View <View
style={{ style={{
position: 'absolute', position: 'absolute',
@ -448,12 +509,13 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
<WebSectionList <WebSectionList
createDataset={this.createDataset} createDataset={this.createDataset}
navigation={navigation} navigation={navigation}
fetchUrl={DATA_URL} fetchUrl={data.url}
renderItem={this.getRenderItem} renderItem={this.getRenderItem}
renderSectionHeader={this.getRenderSectionHeader} renderSectionHeader={this.getRenderSectionHeader}
autoRefreshTime={REFRESH_TIME} autoRefreshTime={REFRESH_TIME}
refreshOnFocus refreshOnFocus
updateData={state.machinesWatched.length} updateData={state.machinesWatched.length}
renderListHeaderComponent={this.getListHeader}
/> />
</View> </View>
<MascotPopup <MascotPopup