2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-06-28 13:47:52 +02:00
|
|
|
import {
|
2019-08-06 13:28:11 +02:00
|
|
|
Body,
|
|
|
|
Card,
|
|
|
|
CardItem,
|
|
|
|
CheckBox,
|
2019-06-28 13:47:52 +02:00
|
|
|
Container,
|
|
|
|
Content,
|
|
|
|
Left,
|
2019-08-06 13:28:11 +02:00
|
|
|
List,
|
2019-06-28 13:47:52 +02:00
|
|
|
ListItem,
|
2019-08-06 13:28:11 +02:00
|
|
|
Picker,
|
2019-06-28 13:47:52 +02:00
|
|
|
Right,
|
|
|
|
Text,
|
|
|
|
} from "native-base";
|
2019-06-25 22:20:24 +02:00
|
|
|
import CustomHeader from "../components/CustomHeader";
|
|
|
|
import ThemeManager from '../utils/ThemeManager';
|
|
|
|
import i18n from "i18n-js";
|
2019-06-28 11:35:15 +02:00
|
|
|
import {NavigationActions, StackActions} from "react-navigation";
|
|
|
|
import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
2019-07-31 14:22:36 +02:00
|
|
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
2019-08-07 11:10:17 +02:00
|
|
|
import Touchable from "react-native-platform-touchable";
|
|
|
|
import {Platform} from "react-native";
|
2019-08-21 17:07:27 +02:00
|
|
|
import NotificationsManager from "../utils/NotificationsManager";
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
};
|
|
|
|
|
|
|
|
type State = {
|
|
|
|
nightMode: boolean,
|
|
|
|
proxiwashNotifPickerSelected: string,
|
2019-09-12 23:02:28 +02:00
|
|
|
startScreenPickerSelected: string,
|
2019-06-29 13:37:21 +02:00
|
|
|
};
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Class defining the Settings screen. This screen shows controls to modify app preferences.
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
export default class SettingsScreen extends React.Component<Props, State> {
|
2019-06-25 22:20:24 +02:00
|
|
|
state = {
|
2019-07-31 14:22:36 +02:00
|
|
|
nightMode: ThemeManager.getNightMode(),
|
|
|
|
proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
|
2019-09-12 23:02:28 +02:00
|
|
|
startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
|
2019-06-25 22:20:24 +02:00
|
|
|
};
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Save the value for the proxiwash reminder notification time
|
|
|
|
*
|
|
|
|
* @param value The value to store
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
onProxiwashNotifPickerValueChange(value: string) {
|
2019-07-31 14:22:36 +02:00
|
|
|
let key = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.key;
|
|
|
|
AsyncStorageManager.getInstance().savePref(key, value);
|
2019-06-28 13:47:52 +02:00
|
|
|
this.setState({
|
|
|
|
proxiwashNotifPickerSelected: value
|
|
|
|
});
|
2019-08-21 17:07:27 +02:00
|
|
|
let intVal = 0;
|
|
|
|
if (value !== 'never')
|
|
|
|
intVal = parseInt(value);
|
|
|
|
NotificationsManager.setMachineReminderNotificationTime(intVal);
|
2019-06-28 13:47:52 +02:00
|
|
|
}
|
|
|
|
|
2019-09-12 23:02:28 +02:00
|
|
|
/**
|
|
|
|
* Save the value for the proxiwash reminder notification time
|
|
|
|
*
|
|
|
|
* @param value The value to store
|
|
|
|
*/
|
|
|
|
onStartScreenPickerValueChange(value: string) {
|
|
|
|
let key = AsyncStorageManager.getInstance().preferences.defaultStartScreen.key;
|
|
|
|
AsyncStorageManager.getInstance().savePref(key, value);
|
|
|
|
this.setState({
|
|
|
|
startScreenPickerSelected: value
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Returns a picker allowing the user to select the proxiwash reminder notification time
|
|
|
|
*
|
|
|
|
* @returns {React.Node}
|
|
|
|
*/
|
2019-06-29 13:37:21 +02:00
|
|
|
getProxiwashNotifPicker() {
|
2019-06-28 13:47:52 +02:00
|
|
|
return (
|
|
|
|
<Picker
|
|
|
|
note
|
|
|
|
mode="dropdown"
|
|
|
|
style={{width: 120}}
|
|
|
|
selectedValue={this.state.proxiwashNotifPickerSelected}
|
2019-06-29 13:37:21 +02:00
|
|
|
onValueChange={(value) => this.onProxiwashNotifPickerValueChange(value)}
|
2019-06-28 13:47:52 +02:00
|
|
|
>
|
|
|
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
|
|
|
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
|
|
|
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
|
|
|
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
|
|
|
|
<Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.30')} value="30"/>
|
|
|
|
</Picker>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-12 23:02:28 +02:00
|
|
|
/**
|
|
|
|
* Returns a picker allowing the user to select the start screen
|
|
|
|
*
|
|
|
|
* @returns {React.Node}
|
|
|
|
*/
|
|
|
|
getStartScreenPicker() {
|
|
|
|
return (
|
|
|
|
<Picker
|
|
|
|
note
|
|
|
|
mode="dropdown"
|
|
|
|
style={{width: 120}}
|
|
|
|
selectedValue={this.state.startScreenPickerSelected}
|
|
|
|
onValueChange={(value) => this.onStartScreenPickerValueChange(value)}
|
|
|
|
>
|
|
|
|
<Picker.Item label={i18n.t('screens.home')} value="Home"/>
|
|
|
|
<Picker.Item label={i18n.t('screens.planning')} value="Planning"/>
|
|
|
|
<Picker.Item label={i18n.t('screens.proxiwash')} value="Proxiwash"/>
|
|
|
|
<Picker.Item label={i18n.t('screens.proximo')} value="Proximo"/>
|
|
|
|
<Picker.Item label={'Planex'} value="Planex"/>
|
|
|
|
</Picker>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Toggle night mode and save it to preferences
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
toggleNightMode() {
|
2019-06-29 13:37:21 +02:00
|
|
|
ThemeManager.getInstance().setNightMode(!this.state.nightMode);
|
2019-06-28 13:47:52 +02:00
|
|
|
this.setState({nightMode: !this.state.nightMode});
|
2019-06-28 11:35:15 +02:00
|
|
|
this.resetStack();
|
|
|
|
}
|
2019-06-25 22:20:24 +02:00
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Reset react navigation stack to allow for a theme reset
|
|
|
|
*/
|
2019-06-28 11:35:15 +02:00
|
|
|
resetStack() {
|
|
|
|
const resetAction = StackActions.reset({
|
|
|
|
index: 0,
|
|
|
|
key: null,
|
2019-06-28 13:47:52 +02:00
|
|
|
actions: [NavigationActions.navigate({routeName: 'Main'})],
|
2019-06-28 11:35:15 +02:00
|
|
|
});
|
|
|
|
this.props.navigation.dispatch(resetAction);
|
2019-08-07 11:33:45 +02:00
|
|
|
// this.props.navigation.navigate('SettingsScreen');
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Get a list item using a checkbox control
|
|
|
|
*
|
|
|
|
* @param onPressCallback The callback when the checkbox state changes
|
|
|
|
* @param icon The icon name to display on the list item
|
|
|
|
* @param title The text to display as this list item title
|
|
|
|
* @param subtitle The text to display as this list item subtitle
|
|
|
|
* @returns {React.Node}
|
|
|
|
*/
|
|
|
|
getToggleItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
|
2019-06-28 13:47:52 +02:00
|
|
|
return (
|
|
|
|
<ListItem
|
|
|
|
button
|
|
|
|
thumbnail
|
|
|
|
onPress={onPressCallback}
|
|
|
|
>
|
|
|
|
<Left>
|
|
|
|
<CustomMaterialIcon icon={icon}/>
|
|
|
|
</Left>
|
|
|
|
<Body>
|
|
|
|
<Text>
|
2019-06-29 15:43:57 +02:00
|
|
|
{title}
|
2019-06-28 13:47:52 +02:00
|
|
|
</Text>
|
|
|
|
<Text note>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
</Body>
|
2019-09-12 23:02:28 +02:00
|
|
|
<Right>
|
2019-09-17 11:53:47 +02:00
|
|
|
<CheckBox
|
|
|
|
checked={this.state.nightMode}
|
|
|
|
onPress={() => this.toggleNightMode()}
|
|
|
|
style={{marginRight: 20}}/>
|
2019-06-28 13:47:52 +02:00
|
|
|
</Right>
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-29 15:43:57 +02:00
|
|
|
/**
|
|
|
|
* Get a list item using the specified control
|
|
|
|
*
|
|
|
|
* @param control The custom control to use
|
|
|
|
* @param icon The icon name to display on the list item
|
|
|
|
* @param title The text to display as this list item title
|
|
|
|
* @param subtitle The text to display as this list item subtitle
|
|
|
|
* @returns {React.Node}
|
|
|
|
*/
|
|
|
|
static getGeneralItem(control: React.Node, icon: string, title: string, subtitle: string) {
|
2019-06-28 13:47:52 +02:00
|
|
|
return (
|
|
|
|
<ListItem
|
|
|
|
thumbnail
|
|
|
|
>
|
|
|
|
<Left>
|
|
|
|
<CustomMaterialIcon icon={icon}/>
|
|
|
|
</Left>
|
|
|
|
<Body>
|
|
|
|
<Text>
|
2019-06-29 15:43:57 +02:00
|
|
|
{title}
|
2019-06-28 13:47:52 +02:00
|
|
|
</Text>
|
|
|
|
<Text note>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
</Body>
|
|
|
|
|
2019-09-12 23:02:28 +02:00
|
|
|
<Right>
|
2019-06-28 13:47:52 +02:00
|
|
|
{control}
|
|
|
|
</Right>
|
|
|
|
</ListItem>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-08-07 11:10:17 +02:00
|
|
|
getRightButton() {
|
|
|
|
return (
|
|
|
|
<Touchable
|
|
|
|
style={{padding: 6}}
|
|
|
|
onPress={() => this.props.navigation.navigate('AboutScreen')}>
|
|
|
|
<CustomMaterialIcon
|
|
|
|
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
|
|
|
|
icon="information"/>
|
|
|
|
</Touchable>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-06-25 22:20:24 +02:00
|
|
|
render() {
|
|
|
|
const nav = this.props.navigation;
|
|
|
|
return (
|
|
|
|
<Container>
|
2019-08-07 11:10:17 +02:00
|
|
|
<CustomHeader navigation={nav} title={i18n.t('screens.settings')} hasBackButton={true}
|
2019-09-17 11:53:47 +02:00
|
|
|
rightButton={this.getRightButton()}/>
|
2019-07-25 17:52:16 +02:00
|
|
|
<Content padder>
|
2019-06-28 13:47:52 +02:00
|
|
|
<Card>
|
|
|
|
<CardItem header>
|
2019-09-12 23:02:28 +02:00
|
|
|
<Text>{i18n.t('settingsScreen.generalCard')}</Text>
|
2019-06-28 13:47:52 +02:00
|
|
|
</CardItem>
|
|
|
|
<List>
|
|
|
|
{this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
|
2019-09-12 23:02:28 +02:00
|
|
|
{SettingsScreen.getGeneralItem(this.getStartScreenPicker(), 'power', i18n.t('settingsScreen.startScreen'), i18n.t('settingsScreen.startScreenSub'))}
|
2019-06-28 13:47:52 +02:00
|
|
|
</List>
|
|
|
|
</Card>
|
|
|
|
<Card>
|
|
|
|
<CardItem header>
|
|
|
|
<Text>Proxiwash</Text>
|
|
|
|
</CardItem>
|
|
|
|
<List>
|
2019-06-29 13:37:21 +02:00
|
|
|
{SettingsScreen.getGeneralItem(this.getProxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))}
|
2019-06-28 13:47:52 +02:00
|
|
|
</List>
|
|
|
|
</Card>
|
2019-06-25 22:20:24 +02:00
|
|
|
</Content>
|
|
|
|
</Container>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|