// @flow import * as 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"; type Props = { navigation: Object, }; type State = { nightMode: boolean, proxiwashNotifPickerSelected: string, }; 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, }); } onProxiwashNotifPickerValueChange(value: string) { AsyncStorage.setItem(proxiwashNotifKey, value); this.setState({ proxiwashNotifPickerSelected: value }); } getProxiwashNotifPicker() { return ( this.onProxiwashNotifPickerValueChange(value)} > ); } 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: Function, icon: string, text: string, subtitle: string) { return ( {text} {subtitle} this.toggleNightMode()}/> ); } static getGeneralItem(control: React.Node, icon: string, text: string, subtitle: string) { return ( {text} {subtitle} {control} ); } render() { const nav = this.props.navigation; return ( {i18n.t('settingsScreen.appearanceCard')} {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))} Proxiwash {SettingsScreen.getGeneralItem(this.getProxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))} ); } }