123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163 |
- import React from 'react';
- import {
- Container,
- Content,
- Left,
- ListItem,
- Right,
- Text,
- List,
- CheckBox,
- Body,
- CardItem,
- Card,
- Picker,
- } from "native-base";
- import CustomHeader from "../components/CustomHeader";
- import ThemeManager from '../utils/ThemeManager';
- import i18n from "i18n-js";
- import {NavigationActions, StackActions} from "react-navigation";
- import CustomMaterialIcon from "../components/CustomMaterialIcon";
- import {AsyncStorage} from 'react-native'
-
- const proxiwashNotifKey = "proxiwashNotifKey";
-
- export default class SettingsScreen extends React.Component {
- state = {
- nightMode: ThemeManager.getInstance().getNightMode(),
- proxiwashNotifPickerSelected: "5"
- };
-
- async componentWillMount() {
- let val = await AsyncStorage.getItem(proxiwashNotifKey);
- if (val === null)
- val = "5";
- this.setState({
- proxiwashNotifPickerSelected: val,
- });
- }
-
-
- onProxiwashNotidPickerValueChange(value) {
- AsyncStorage.setItem(proxiwashNotifKey, value);
- this.setState({
- proxiwashNotifPickerSelected: value
- });
- }
-
- getproxiwashNotifPicker() {
- return (
- <Picker
- note
- mode="dropdown"
- style={{width: 120}}
- selectedValue={this.state.proxiwashNotifPickerSelected}
- onValueChange={(value) => this.onProxiwashNotidPickerValueChange(value)}
- >
- <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
- <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
- <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
- <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
- <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>
- );
- }
-
- toggleNightMode() {
- ThemeManager.getInstance().setNightmode(!this.state.nightMode);
- this.setState({nightMode: !this.state.nightMode});
- // Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
- this.resetStack();
- }
-
- resetStack() {
- const resetAction = StackActions.reset({
- index: 0,
- key: null,
- actions: [NavigationActions.navigate({routeName: 'Main'})],
- });
- this.props.navigation.dispatch(resetAction);
- this.props.navigation.navigate('Settings');
- }
-
- getToggleItem(onPressCallback, icon, text, subtitle) {
- return (
- <ListItem
- button
- thumbnail
- onPress={onPressCallback}
- >
- <Left>
- <CustomMaterialIcon icon={icon}/>
- </Left>
- <Body>
- <Text>
- {text}
- </Text>
- <Text note>
- {subtitle}
- </Text>
- </Body>
- <Right style={{flex: 1}}>
- <CheckBox checked={this.state.nightMode}
- onPress={() => this.toggleNightMode()}/>
- </Right>
- </ListItem>
- );
- }
-
- getGeneralItem(control, icon, text, subtitle) {
- return (
- <ListItem
- thumbnail
- >
- <Left>
- <CustomMaterialIcon icon={icon}/>
- </Left>
- <Body>
- <Text>
- {text}
- </Text>
- <Text note>
- {subtitle}
- </Text>
- </Body>
-
- <Right style={{flex: 1}}>
- {control}
- </Right>
- </ListItem>
- );
- }
-
- render() {
- const nav = this.props.navigation;
- return (
- <Container>
- <CustomHeader navigation={nav} title={i18n.t('screens.settings')}/>
- <Content>
- <Card>
- <CardItem header>
- <Text>{i18n.t('settingsScreen.appearanceCard')}</Text>
- </CardItem>
- <List>
- {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
- </List>
- </Card>
- <Card>
- <CardItem header>
- <Text>Proxiwash</Text>
- </CardItem>
- <List>
- {this.getGeneralItem(this.getproxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))}
- </List>
- </Card>
- </Content>
- </Container>
-
- );
- }
- }
|