|
@@ -7,6 +7,7 @@ import i18n from "i18n-js";
|
7
|
7
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
8
|
8
|
import NotificationsManager from "../utils/NotificationsManager";
|
9
|
9
|
import {Card, List, Switch, ToggleButton} from 'react-native-paper';
|
|
10
|
+import {Appearance} from "react-native-appearance";
|
10
|
11
|
|
11
|
12
|
type Props = {
|
12
|
13
|
navigation: Object,
|
|
@@ -14,6 +15,7 @@ type Props = {
|
14
|
15
|
|
15
|
16
|
type State = {
|
16
|
17
|
nightMode: boolean,
|
|
18
|
+ nightModeFollowSystem: boolean,
|
17
|
19
|
proxiwashNotifPickerSelected: string,
|
18
|
20
|
startScreenPickerSelected: string,
|
19
|
21
|
};
|
|
@@ -24,6 +26,8 @@ type State = {
|
24
|
26
|
export default class SettingsScreen extends React.Component<Props, State> {
|
25
|
27
|
state = {
|
26
|
28
|
nightMode: ThemeManager.getNightMode(),
|
|
29
|
+ nightModeFollowSystem: AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' &&
|
|
30
|
+ Appearance.getColorScheme() !== 'no-preference',
|
27
|
31
|
proxiwashNotifPickerSelected: AsyncStorageManager.getInstance().preferences.proxiwashNotifications.current,
|
28
|
32
|
startScreenPickerSelected: AsyncStorageManager.getInstance().preferences.defaultStartScreen.current,
|
29
|
33
|
};
|
|
@@ -31,12 +35,14 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
31
|
35
|
onProxiwashNotifPickerValueChange: Function;
|
32
|
36
|
onStartScreenPickerValueChange: Function;
|
33
|
37
|
onToggleNightMode: Function;
|
|
38
|
+ onToggleNightModeFollowSystem: Function;
|
34
|
39
|
|
35
|
40
|
constructor() {
|
36
|
41
|
super();
|
37
|
42
|
this.onProxiwashNotifPickerValueChange = this.onProxiwashNotifPickerValueChange.bind(this);
|
38
|
43
|
this.onStartScreenPickerValueChange = this.onStartScreenPickerValueChange.bind(this);
|
39
|
44
|
this.onToggleNightMode = this.onToggleNightMode.bind(this);
|
|
45
|
+ this.onToggleNightModeFollowSystem = this.onToggleNightModeFollowSystem.bind(this);
|
40
|
46
|
}
|
41
|
47
|
|
42
|
48
|
/**
|
|
@@ -119,6 +125,18 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
119
|
125
|
this.setState({nightMode: !this.state.nightMode});
|
120
|
126
|
}
|
121
|
127
|
|
|
128
|
+ onToggleNightModeFollowSystem() {
|
|
129
|
+ const value = !this.state.nightModeFollowSystem;
|
|
130
|
+ this.setState({nightModeFollowSystem: value});
|
|
131
|
+ let key = AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.key;
|
|
132
|
+ AsyncStorageManager.getInstance().savePref(key, value ? '1' : '0');
|
|
133
|
+ if (value) {
|
|
134
|
+ const nightMode = Appearance.getColorScheme() === 'dark';
|
|
135
|
+ ThemeManager.getInstance().setNightMode(nightMode);
|
|
136
|
+ this.setState({nightMode: nightMode});
|
|
137
|
+ }
|
|
138
|
+ }
|
|
139
|
+
|
122
|
140
|
/**
|
123
|
141
|
* Get a list item using a checkbox control
|
124
|
142
|
*
|
|
@@ -128,7 +146,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
128
|
146
|
* @param subtitle The text to display as this list item subtitle
|
129
|
147
|
* @returns {React.Node}
|
130
|
148
|
*/
|
131
|
|
- getToggleItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
|
|
149
|
+ getToggleItem(onPressCallback: Function, icon: string, title: string, subtitle: string, state: boolean) {
|
132
|
150
|
return (
|
133
|
151
|
<List.Item
|
134
|
152
|
title={title}
|
|
@@ -136,7 +154,7 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
136
|
154
|
left={props => <List.Icon {...props} icon={icon}/>}
|
137
|
155
|
right={props =>
|
138
|
156
|
<Switch
|
139
|
|
- value={this.state.nightMode}
|
|
157
|
+ value={state}
|
140
|
158
|
onValueChange={onPressCallback}
|
141
|
159
|
/>}
|
142
|
160
|
/>
|
|
@@ -149,14 +167,27 @@ export default class SettingsScreen extends React.Component<Props, State> {
|
149
|
167
|
<Card style={{margin: 5}}>
|
150
|
168
|
<Card.Title title={i18n.t('settingsScreen.generalCard')}/>
|
151
|
169
|
<List.Section>
|
152
|
|
- {this.getToggleItem(
|
153
|
|
- this.onToggleNightMode,
|
|
170
|
+ {Appearance.getColorScheme() !== 'no-preference' ? this.getToggleItem(
|
|
171
|
+ this.onToggleNightModeFollowSystem,
|
154
|
172
|
'theme-light-dark',
|
155
|
|
- i18n.t('settingsScreen.nightMode'),
|
|
173
|
+ i18n.t('settingsScreen.nightModeAuto'),
|
156
|
174
|
this.state.nightMode ?
|
157
|
175
|
i18n.t('settingsScreen.nightModeSubOn') :
|
158
|
|
- i18n.t('settingsScreen.nightModeSubOff')
|
159
|
|
- )}
|
|
176
|
+ i18n.t('settingsScreen.nightModeSubOff'),
|
|
177
|
+ this.state.nightModeFollowSystem
|
|
178
|
+ ) : null}
|
|
179
|
+ {
|
|
180
|
+ Appearance.getColorScheme() === 'no-preference' || !this.state.nightModeFollowSystem ?
|
|
181
|
+ this.getToggleItem(
|
|
182
|
+ this.onToggleNightMode,
|
|
183
|
+ 'theme-light-dark',
|
|
184
|
+ i18n.t('settingsScreen.nightMode'),
|
|
185
|
+ this.state.nightMode ?
|
|
186
|
+ i18n.t('settingsScreen.nightModeSubOn') :
|
|
187
|
+ i18n.t('settingsScreen.nightModeSubOff'),
|
|
188
|
+ this.state.nightMode
|
|
189
|
+ ) : null
|
|
190
|
+ }
|
160
|
191
|
<List.Accordion
|
161
|
192
|
title={i18n.t('settingsScreen.startScreen')}
|
162
|
193
|
description={i18n.t('settingsScreen.startScreenSub')}
|