Application Android et IOS pour l'amicale des élèves
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

SettingsScreen.js 5.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import React from 'react';
  2. import {
  3. Container,
  4. Content,
  5. Left,
  6. ListItem,
  7. Right,
  8. Text,
  9. List,
  10. CheckBox,
  11. Body,
  12. CardItem,
  13. Card,
  14. Picker,
  15. } from "native-base";
  16. import CustomHeader from "../components/CustomHeader";
  17. import ThemeManager from '../utils/ThemeManager';
  18. import i18n from "i18n-js";
  19. import {NavigationActions, StackActions} from "react-navigation";
  20. import CustomMaterialIcon from "../components/CustomMaterialIcon";
  21. import {AsyncStorage} from 'react-native'
  22. const proxiwashNotifKey = "proxiwashNotifKey";
  23. export default class SettingsScreen extends React.Component {
  24. state = {
  25. nightMode: ThemeManager.getInstance().getNightMode(),
  26. proxiwashNotifPickerSelected: "5"
  27. };
  28. async componentWillMount() {
  29. let val = await AsyncStorage.getItem(proxiwashNotifKey);
  30. if (val === null)
  31. val = "5";
  32. this.setState({
  33. proxiwashNotifPickerSelected: val,
  34. });
  35. }
  36. onProxiwashNotidPickerValueChange(value) {
  37. AsyncStorage.setItem(proxiwashNotifKey, value);
  38. this.setState({
  39. proxiwashNotifPickerSelected: value
  40. });
  41. }
  42. getproxiwashNotifPicker() {
  43. return (
  44. <Picker
  45. note
  46. mode="dropdown"
  47. style={{width: 120}}
  48. selectedValue={this.state.proxiwashNotifPickerSelected}
  49. onValueChange={(value) => this.onProxiwashNotidPickerValueChange(value)}
  50. >
  51. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
  52. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
  53. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
  54. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
  55. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
  56. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
  57. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
  58. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.30')} value="30"/>
  59. </Picker>
  60. );
  61. }
  62. toggleNightMode() {
  63. ThemeManager.getInstance().setNightmode(!this.state.nightMode);
  64. this.setState({nightMode: !this.state.nightMode});
  65. // Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
  66. this.resetStack();
  67. }
  68. resetStack() {
  69. const resetAction = StackActions.reset({
  70. index: 0,
  71. key: null,
  72. actions: [NavigationActions.navigate({routeName: 'Main'})],
  73. });
  74. this.props.navigation.dispatch(resetAction);
  75. this.props.navigation.navigate('Settings');
  76. }
  77. getToggleItem(onPressCallback, icon, text, subtitle) {
  78. return (
  79. <ListItem
  80. button
  81. thumbnail
  82. onPress={onPressCallback}
  83. >
  84. <Left>
  85. <CustomMaterialIcon icon={icon}/>
  86. </Left>
  87. <Body>
  88. <Text>
  89. {text}
  90. </Text>
  91. <Text note>
  92. {subtitle}
  93. </Text>
  94. </Body>
  95. <Right style={{flex: 1}}>
  96. <CheckBox checked={this.state.nightMode}
  97. onPress={() => this.toggleNightMode()}/>
  98. </Right>
  99. </ListItem>
  100. );
  101. }
  102. getGeneralItem(control, icon, text, subtitle) {
  103. return (
  104. <ListItem
  105. thumbnail
  106. >
  107. <Left>
  108. <CustomMaterialIcon icon={icon}/>
  109. </Left>
  110. <Body>
  111. <Text>
  112. {text}
  113. </Text>
  114. <Text note>
  115. {subtitle}
  116. </Text>
  117. </Body>
  118. <Right style={{flex: 1}}>
  119. {control}
  120. </Right>
  121. </ListItem>
  122. );
  123. }
  124. render() {
  125. const nav = this.props.navigation;
  126. return (
  127. <Container>
  128. <CustomHeader navigation={nav} title={i18n.t('screens.settings')}/>
  129. <Content>
  130. <Card>
  131. <CardItem header>
  132. <Text>{i18n.t('settingsScreen.appearanceCard')}</Text>
  133. </CardItem>
  134. <List>
  135. {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
  136. </List>
  137. </Card>
  138. <Card>
  139. <CardItem header>
  140. <Text>Proxiwash</Text>
  141. </CardItem>
  142. <List>
  143. {this.getGeneralItem(this.getproxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))}
  144. </List>
  145. </Card>
  146. </Content>
  147. </Container>
  148. );
  149. }
  150. }