forked from vergnet/application-amicale
add settings selection
This commit is contained in:
parent
3de49732b9
commit
f8f5749478
4 changed files with 122 additions and 5 deletions
|
@ -67,6 +67,7 @@ class ProxiwashListItem extends React.Component<PropsType> {
|
|||
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<PropsType> {
|
|||
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 {
|
||||
|
|
|
@ -107,6 +107,10 @@ export default class AsyncStorageManager {
|
|||
key: 'gameScores',
|
||||
default: '[]',
|
||||
},
|
||||
selectedWash: {
|
||||
key: 'selectedWash',
|
||||
default: 'washinsa',
|
||||
},
|
||||
};
|
||||
|
||||
#currentPreferences: {[key: string]: string};
|
||||
|
|
|
@ -52,6 +52,9 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
|
|||
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<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
|
||||
*
|
||||
|
@ -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
|
||||
*
|
||||
|
@ -288,6 +324,20 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
|
|||
<View style={{marginLeft: 30}}>
|
||||
{this.getProxiwashNotifPicker()}
|
||||
</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>
|
||||
</Card>
|
||||
<Card style={{margin: 5}}>
|
||||
|
|
|
@ -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<ProxiwashMachineType>,
|
||||
selectedWash: string,
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -87,6 +111,9 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
|
|||
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<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
|
||||
*
|
||||
|
@ -437,8 +487,19 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
|
|||
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 (
|
||||
<View style={{flex: 1}}>
|
||||
<View
|
||||
style={{
|
||||
flex: 1,
|
||||
}}>
|
||||
<View
|
||||
style={{
|
||||
position: 'absolute',
|
||||
|
@ -448,12 +509,13 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
|
|||
<WebSectionList
|
||||
createDataset={this.createDataset}
|
||||
navigation={navigation}
|
||||
fetchUrl={DATA_URL}
|
||||
fetchUrl={data.url}
|
||||
renderItem={this.getRenderItem}
|
||||
renderSectionHeader={this.getRenderSectionHeader}
|
||||
autoRefreshTime={REFRESH_TIME}
|
||||
refreshOnFocus
|
||||
updateData={state.machinesWatched.length}
|
||||
renderListHeaderComponent={this.getListHeader}
|
||||
/>
|
||||
</View>
|
||||
<MascotPopup
|
||||
|
|
Loading…
Reference in a new issue