Application Android et IOS pour l'amicale des élèves https://play.google.com/store/apps/details?id=fr.amicaleinsat.application
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 6.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. // @flow
  2. import * as React from 'react';
  3. import {
  4. Body,
  5. Card,
  6. CardItem,
  7. CheckBox,
  8. Container,
  9. Content,
  10. Left,
  11. List,
  12. ListItem,
  13. Picker,
  14. Right,
  15. Text,
  16. } from "native-base";
  17. import CustomHeader from "../components/CustomHeader";
  18. import ThemeManager from '../utils/ThemeManager';
  19. import i18n from "i18n-js";
  20. import {NavigationActions, StackActions} from "react-navigation";
  21. import CustomMaterialIcon from "../components/CustomMaterialIcon";
  22. import AsyncStorageManager from "../utils/AsyncStorageManager";
  23. type Props = {
  24. navigation: Object,
  25. };
  26. type State = {
  27. nightMode: boolean,
  28. proxiwashNotifPickerSelected: string,
  29. };
  30. /**
  31. * Class defining the Settings screen. This screen shows controls to modify app preferences.
  32. */
  33. export default class SettingsScreen extends React.Component<Props, State> {
  34. state = {
  35. nightMode: ThemeManager.getNightMode(),
  36. proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
  37. };
  38. /**
  39. * Save the value for the proxiwash reminder notification time
  40. *
  41. * @param value The value to store
  42. */
  43. onProxiwashNotifPickerValueChange(value: string) {
  44. let key = AsyncStorageManager.getInstance().preferences.proxiwashNotifications.key;
  45. AsyncStorageManager.getInstance().savePref(key, value);
  46. this.setState({
  47. proxiwashNotifPickerSelected: value
  48. });
  49. }
  50. /**
  51. * Returns a picker allowing the user to select the proxiwash reminder notification time
  52. *
  53. * @returns {React.Node}
  54. */
  55. getProxiwashNotifPicker() {
  56. return (
  57. <Picker
  58. note
  59. mode="dropdown"
  60. style={{width: 120}}
  61. selectedValue={this.state.proxiwashNotifPickerSelected}
  62. onValueChange={(value) => this.onProxiwashNotifPickerValueChange(value)}
  63. >
  64. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
  65. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
  66. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
  67. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
  68. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
  69. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
  70. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
  71. <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.30')} value="30"/>
  72. </Picker>
  73. );
  74. }
  75. /**
  76. * Toggle night mode and save it to preferences
  77. */
  78. toggleNightMode() {
  79. ThemeManager.getInstance().setNightMode(!this.state.nightMode);
  80. this.setState({nightMode: !this.state.nightMode});
  81. // Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
  82. this.resetStack();
  83. }
  84. /**
  85. * Reset react navigation stack to allow for a theme reset
  86. */
  87. resetStack() {
  88. const resetAction = StackActions.reset({
  89. index: 0,
  90. key: null,
  91. actions: [NavigationActions.navigate({routeName: 'Main'})],
  92. });
  93. this.props.navigation.dispatch(resetAction);
  94. this.props.navigation.navigate('Settings');
  95. }
  96. /**
  97. * Get a list item using a checkbox control
  98. *
  99. * @param onPressCallback The callback when the checkbox state changes
  100. * @param icon The icon name to display on the list item
  101. * @param title The text to display as this list item title
  102. * @param subtitle The text to display as this list item subtitle
  103. * @returns {React.Node}
  104. */
  105. getToggleItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
  106. return (
  107. <ListItem
  108. button
  109. thumbnail
  110. onPress={onPressCallback}
  111. >
  112. <Left>
  113. <CustomMaterialIcon icon={icon}/>
  114. </Left>
  115. <Body>
  116. <Text>
  117. {title}
  118. </Text>
  119. <Text note>
  120. {subtitle}
  121. </Text>
  122. </Body>
  123. <Right style={{flex: 1}}>
  124. <CheckBox checked={this.state.nightMode}
  125. onPress={() => this.toggleNightMode()}/>
  126. </Right>
  127. </ListItem>
  128. );
  129. }
  130. /**
  131. * Get a list item using the specified control
  132. *
  133. * @param control The custom control to use
  134. * @param icon The icon name to display on the list item
  135. * @param title The text to display as this list item title
  136. * @param subtitle The text to display as this list item subtitle
  137. * @returns {React.Node}
  138. */
  139. static getGeneralItem(control: React.Node, icon: string, title: string, subtitle: string) {
  140. return (
  141. <ListItem
  142. thumbnail
  143. >
  144. <Left>
  145. <CustomMaterialIcon icon={icon}/>
  146. </Left>
  147. <Body>
  148. <Text>
  149. {title}
  150. </Text>
  151. <Text note>
  152. {subtitle}
  153. </Text>
  154. </Body>
  155. <Right style={{flex: 1}}>
  156. {control}
  157. </Right>
  158. </ListItem>
  159. );
  160. }
  161. render() {
  162. const nav = this.props.navigation;
  163. return (
  164. <Container>
  165. <CustomHeader navigation={nav} title={i18n.t('screens.settings')}/>
  166. <Content padder>
  167. <Card>
  168. <CardItem header>
  169. <Text>{i18n.t('settingsScreen.appearanceCard')}</Text>
  170. </CardItem>
  171. <List>
  172. {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
  173. </List>
  174. </Card>
  175. <Card>
  176. <CardItem header>
  177. <Text>Proxiwash</Text>
  178. </CardItem>
  179. <List>
  180. {SettingsScreen.getGeneralItem(this.getProxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))}
  181. </List>
  182. </Card>
  183. </Content>
  184. </Container>
  185. );
  186. }
  187. }