forked from vergnet/application-amicale
Improve Settings screen components to match linter
This commit is contained in:
parent
0a64f5fcd7
commit
a3299c19f7
3 changed files with 425 additions and 337 deletions
|
@ -131,7 +131,11 @@ export default class AsyncStorageManager {
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
static set(key: string, value: number | string | boolean | {...} | []) {
|
static set(
|
||||||
|
key: string,
|
||||||
|
// eslint-disable-next-line flowtype/no-weak-types
|
||||||
|
value: number | string | boolean | {...} | Array<any>,
|
||||||
|
) {
|
||||||
AsyncStorageManager.getInstance().setPreference(key, value);
|
AsyncStorageManager.getInstance().setPreference(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -142,7 +146,8 @@ export default class AsyncStorageManager {
|
||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
static getString(key: string): string {
|
static getString(key: string): string {
|
||||||
return AsyncStorageManager.getInstance().getPreference(key);
|
const value = AsyncStorageManager.getInstance().getPreference(key);
|
||||||
|
return value != null ? value : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -207,7 +212,11 @@ export default class AsyncStorageManager {
|
||||||
* @param key
|
* @param key
|
||||||
* @param value
|
* @param value
|
||||||
*/
|
*/
|
||||||
setPreference(key: string, value: number | string | boolean | {...} | []) {
|
setPreference(
|
||||||
|
key: string,
|
||||||
|
// eslint-disable-next-line flowtype/no-weak-types
|
||||||
|
value: number | string | boolean | {...} | Array<any>,
|
||||||
|
) {
|
||||||
if (AsyncStorageManager.PREFERENCES[key] != null) {
|
if (AsyncStorageManager.PREFERENCES[key] != null) {
|
||||||
let convertedValue;
|
let convertedValue;
|
||||||
if (typeof value === 'string') convertedValue = value;
|
if (typeof value === 'string') convertedValue = value;
|
||||||
|
|
|
@ -1,116 +1,139 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {Avatar, Button, Card, Paragraph, withTheme} from "react-native-paper";
|
import {Avatar, Button, Card, Paragraph, withTheme} from 'react-native-paper';
|
||||||
import i18n from "i18n-js";
|
import i18n from 'i18n-js';
|
||||||
import {Linking} from "react-native";
|
import {Linking} from 'react-native';
|
||||||
import type {CustomTheme} from "../../managers/ThemeManager";
|
import type {CustomThemeType} from '../../managers/ThemeManager';
|
||||||
import CollapsibleScrollView from "../../components/Collapsible/CollapsibleScrollView";
|
import CollapsibleScrollView from '../../components/Collapsible/CollapsibleScrollView';
|
||||||
|
|
||||||
type Props = {
|
type PropsType = {
|
||||||
theme: CustomTheme
|
theme: CustomThemeType,
|
||||||
};
|
};
|
||||||
|
|
||||||
const links = {
|
const links = {
|
||||||
bugsMail: `mailto:app@amicale-insat.fr?subject=[BUG] Application CAMPUS
|
bugsMail: `mailto:app@amicale-insat.fr?subject=[BUG] Application CAMPUS
|
||||||
&body=Coucou Arnaud ça bug c'est nul,\n\n
|
&body=Coucou Arnaud ça bug c'est nul,\n\n
|
||||||
Informations sur ton système si tu sais (iOS ou Android, modèle du tel, version):\n\n\n
|
Informations sur ton système si tu sais (iOS ou Android, modèle du tel, version):\n\n\n
|
||||||
Nature du problème :\n\n\n
|
Nature du problème :\n\n\n
|
||||||
Étapes pour reproduire ce pb :\n\n\n\n
|
Étapes pour reproduire ce pb :\n\n\n\n
|
||||||
Stp corrige le pb, bien cordialement.`,
|
Stp corrige le pb, bien cordialement.`,
|
||||||
bugsGit: 'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/issues/new',
|
bugsGit:
|
||||||
facebook: "https://www.facebook.com/campus.insat",
|
'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/issues/new',
|
||||||
feedbackMail: `mailto:app@amicale-insat.fr?subject=[FEEDBACK] Application CAMPUS
|
facebook: 'https://www.facebook.com/campus.insat',
|
||||||
|
feedbackMail: `mailto:app@amicale-insat.fr?subject=[FEEDBACK] Application CAMPUS
|
||||||
&body=Coucou Arnaud j'ai du feedback\n\n\n\nBien cordialement.`,
|
&body=Coucou Arnaud j'ai du feedback\n\n\n\nBien cordialement.`,
|
||||||
feedbackGit: "https://git.etud.insa-toulouse.fr/vergnet/application-amicale/issues/new",
|
feedbackGit:
|
||||||
}
|
'https://git.etud.insa-toulouse.fr/vergnet/application-amicale/issues/new',
|
||||||
|
};
|
||||||
|
|
||||||
class FeedbackScreen extends React.Component<Props> {
|
class FeedbackScreen extends React.Component<PropsType> {
|
||||||
|
/**
|
||||||
|
* Gets link buttons
|
||||||
|
*
|
||||||
|
* @param isBug True if buttons should redirect to bug report methods
|
||||||
|
* @returns {*}
|
||||||
|
*/
|
||||||
|
static getButtons(isBug: boolean): React.Node {
|
||||||
|
return (
|
||||||
|
<Card.Actions
|
||||||
|
style={{
|
||||||
|
flex: 1,
|
||||||
|
flexWrap: 'wrap',
|
||||||
|
}}>
|
||||||
|
<Button
|
||||||
|
icon="email"
|
||||||
|
mode="contained"
|
||||||
|
style={{
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginTop: 5,
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
Linking.openURL(isBug ? links.bugsMail : links.feedbackMail);
|
||||||
|
}}>
|
||||||
|
MAIL
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon="git"
|
||||||
|
mode="contained"
|
||||||
|
color="#609927"
|
||||||
|
style={{
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginTop: 5,
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
Linking.openURL(isBug ? links.bugsGit : links.feedbackGit);
|
||||||
|
}}>
|
||||||
|
GITEA
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
icon="facebook"
|
||||||
|
mode="contained"
|
||||||
|
color="#2e88fe"
|
||||||
|
style={{
|
||||||
|
marginLeft: 'auto',
|
||||||
|
marginTop: 5,
|
||||||
|
}}
|
||||||
|
onPress={() => {
|
||||||
|
Linking.openURL(links.facebook);
|
||||||
|
}}>
|
||||||
|
Facebook
|
||||||
|
</Button>
|
||||||
|
</Card.Actions>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
render(): React.Node {
|
||||||
* Gets link buttons
|
const {theme} = this.props;
|
||||||
*
|
return (
|
||||||
* @param isBug True if buttons should redirect to bug report methods
|
<CollapsibleScrollView style={{padding: 5}}>
|
||||||
* @returns {*}
|
<Card>
|
||||||
*/
|
<Card.Title
|
||||||
getButtons(isBug: boolean) {
|
title={i18n.t('screens.feedback.bugs')}
|
||||||
return (
|
subtitle={i18n.t('screens.feedback.bugsSubtitle')}
|
||||||
<Card.Actions style={{
|
left={({
|
||||||
flex: 1,
|
size,
|
||||||
flexWrap: 'wrap',
|
color,
|
||||||
}}>
|
}: {
|
||||||
<Button
|
size: number,
|
||||||
icon="email"
|
color: number,
|
||||||
mode={"contained"}
|
}): React.Node => (
|
||||||
style={{
|
<Avatar.Icon size={size} color={color} icon="bug" />
|
||||||
marginLeft: 'auto',
|
)}
|
||||||
marginTop: 5,
|
/>
|
||||||
}}
|
<Card.Content>
|
||||||
onPress={() => Linking.openURL(isBug ? links.bugsMail : links.feedbackMail)}>
|
<Paragraph>{i18n.t('screens.feedback.bugsDescription')}</Paragraph>
|
||||||
MAIL
|
<Paragraph style={{color: theme.colors.primary}}>
|
||||||
</Button>
|
{i18n.t('screens.feedback.contactMeans')}
|
||||||
<Button
|
</Paragraph>
|
||||||
icon="git"
|
</Card.Content>
|
||||||
mode={"contained"}
|
{FeedbackScreen.getButtons(true)}
|
||||||
color={"#609927"}
|
</Card>
|
||||||
style={{
|
|
||||||
marginLeft: 'auto',
|
|
||||||
marginTop: 5,
|
|
||||||
}}
|
|
||||||
onPress={() => Linking.openURL(isBug ? links.bugsGit : links.feedbackGit)}>
|
|
||||||
GITEA
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
icon="facebook"
|
|
||||||
mode={"contained"}
|
|
||||||
color={"#2e88fe"}
|
|
||||||
style={{
|
|
||||||
marginLeft: 'auto',
|
|
||||||
marginTop: 5,
|
|
||||||
}}
|
|
||||||
onPress={() => Linking.openURL(links.facebook)}>
|
|
||||||
Facebook
|
|
||||||
</Button>
|
|
||||||
</Card.Actions>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
render() {
|
<Card style={{marginTop: 20, marginBottom: 10}}>
|
||||||
return (
|
<Card.Title
|
||||||
<CollapsibleScrollView style={{padding: 5}}>
|
title={i18n.t('screens.feedback.title')}
|
||||||
<Card>
|
subtitle={i18n.t('screens.feedback.feedbackSubtitle')}
|
||||||
<Card.Title
|
left={({
|
||||||
title={i18n.t('screens.feedback.bugs')}
|
size,
|
||||||
subtitle={i18n.t('screens.feedback.bugsSubtitle')}
|
color,
|
||||||
left={(props) => <Avatar.Icon {...props} icon="bug"/>}
|
}: {
|
||||||
/>
|
size: number,
|
||||||
<Card.Content>
|
color: number,
|
||||||
<Paragraph>
|
}): React.Node => (
|
||||||
{i18n.t('screens.feedback.bugsDescription')}
|
<Avatar.Icon size={size} color={color} icon="comment" />
|
||||||
</Paragraph>
|
)}
|
||||||
<Paragraph style={{color: this.props.theme.colors.primary}}>
|
/>
|
||||||
{i18n.t('screens.feedback.contactMeans')}
|
<Card.Content>
|
||||||
</Paragraph>
|
<Paragraph>
|
||||||
</Card.Content>
|
{i18n.t('screens.feedback.feedbackDescription')}
|
||||||
{this.getButtons(true)}
|
</Paragraph>
|
||||||
</Card>
|
</Card.Content>
|
||||||
|
{FeedbackScreen.getButtons(false)}
|
||||||
<Card style={{marginTop: 20, marginBottom: 10}}>
|
</Card>
|
||||||
<Card.Title
|
</CollapsibleScrollView>
|
||||||
title={i18n.t('screens.feedback.title')}
|
);
|
||||||
subtitle={i18n.t('screens.feedback.feedbackSubtitle')}
|
}
|
||||||
left={(props) => <Avatar.Icon {...props} icon="comment"/>}
|
|
||||||
/>
|
|
||||||
<Card.Content>
|
|
||||||
<Paragraph>
|
|
||||||
{i18n.t('screens.feedback.feedbackDescription')}
|
|
||||||
</Paragraph>
|
|
||||||
</Card.Content>
|
|
||||||
{this.getButtons(false)}
|
|
||||||
</Card>
|
|
||||||
</CollapsibleScrollView>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withTheme(FeedbackScreen);
|
export default withTheme(FeedbackScreen);
|
||||||
|
|
|
@ -1,267 +1,323 @@
|
||||||
// @flow
|
// @flow
|
||||||
|
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import {View} from "react-native";
|
import {View} from 'react-native';
|
||||||
import type {CustomTheme} from "../../../managers/ThemeManager";
|
import i18n from 'i18n-js';
|
||||||
import ThemeManager from '../../../managers/ThemeManager';
|
|
||||||
import i18n from "i18n-js";
|
|
||||||
import AsyncStorageManager from "../../../managers/AsyncStorageManager";
|
|
||||||
import {Card, List, Switch, ToggleButton, withTheme} from 'react-native-paper';
|
import {Card, List, Switch, ToggleButton, withTheme} from 'react-native-paper';
|
||||||
import {Appearance} from "react-native-appearance";
|
import {Appearance} from 'react-native-appearance';
|
||||||
import CustomSlider from "../../../components/Overrides/CustomSlider";
|
import {StackNavigationProp} from '@react-navigation/stack';
|
||||||
import {StackNavigationProp} from "@react-navigation/stack";
|
import type {CustomThemeType} from '../../../managers/ThemeManager';
|
||||||
import CollapsibleScrollView from "../../../components/Collapsible/CollapsibleScrollView";
|
import ThemeManager from '../../../managers/ThemeManager';
|
||||||
|
import AsyncStorageManager from '../../../managers/AsyncStorageManager';
|
||||||
|
import CustomSlider from '../../../components/Overrides/CustomSlider';
|
||||||
|
import CollapsibleScrollView from '../../../components/Collapsible/CollapsibleScrollView';
|
||||||
|
|
||||||
type Props = {
|
type PropsType = {
|
||||||
navigation: StackNavigationProp,
|
navigation: StackNavigationProp,
|
||||||
theme: CustomTheme,
|
theme: CustomThemeType,
|
||||||
};
|
};
|
||||||
|
|
||||||
type State = {
|
type StateType = {
|
||||||
nightMode: boolean,
|
nightMode: boolean,
|
||||||
nightModeFollowSystem: boolean,
|
nightModeFollowSystem: boolean,
|
||||||
notificationReminderSelected: number,
|
startScreenPickerSelected: string,
|
||||||
startScreenPickerSelected: string,
|
isDebugUnlocked: boolean,
|
||||||
isDebugUnlocked: boolean,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class defining the Settings screen. This screen shows controls to modify app preferences.
|
* Class defining the Settings screen. This screen shows controls to modify app preferences.
|
||||||
*/
|
*/
|
||||||
class SettingsScreen extends React.Component<Props, State> {
|
class SettingsScreen extends React.Component<PropsType, StateType> {
|
||||||
|
savedNotificationReminder: number;
|
||||||
|
|
||||||
savedNotificationReminder: number;
|
/**
|
||||||
|
* Loads user preferences into state
|
||||||
|
*/
|
||||||
|
constructor() {
|
||||||
|
super();
|
||||||
|
const notifReminder = AsyncStorageManager.getString(
|
||||||
|
AsyncStorageManager.PREFERENCES.proxiwashNotifications.key,
|
||||||
|
);
|
||||||
|
this.savedNotificationReminder = parseInt(notifReminder, 10);
|
||||||
|
if (Number.isNaN(this.savedNotificationReminder))
|
||||||
|
this.savedNotificationReminder = 0;
|
||||||
|
|
||||||
/**
|
this.state = {
|
||||||
* Loads user preferences into state
|
nightMode: ThemeManager.getNightMode(),
|
||||||
*/
|
nightModeFollowSystem:
|
||||||
constructor() {
|
AsyncStorageManager.getBool(
|
||||||
super();
|
AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
|
||||||
let notifReminder = AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.proxiwashNotifications.key);
|
) && Appearance.getColorScheme() !== 'no-preference',
|
||||||
this.savedNotificationReminder = parseInt(notifReminder);
|
startScreenPickerSelected: AsyncStorageManager.getString(
|
||||||
if (isNaN(this.savedNotificationReminder))
|
AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
|
||||||
this.savedNotificationReminder = 0;
|
),
|
||||||
|
isDebugUnlocked: AsyncStorageManager.getBool(
|
||||||
this.state = {
|
AsyncStorageManager.PREFERENCES.debugUnlocked.key,
|
||||||
nightMode: ThemeManager.getNightMode(),
|
),
|
||||||
nightModeFollowSystem: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
|
|
||||||
&& Appearance.getColorScheme() !== 'no-preference',
|
|
||||||
notificationReminderSelected: this.savedNotificationReminder,
|
|
||||||
startScreenPickerSelected: AsyncStorageManager.getString(AsyncStorageManager.PREFERENCES.defaultStartScreen.key),
|
|
||||||
isDebugUnlocked: AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.debugUnlocked.key)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unlocks debug mode and saves its state to user preferences
|
|
||||||
*/
|
|
||||||
unlockDebugMode = () => {
|
|
||||||
this.setState({isDebugUnlocked: true});
|
|
||||||
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.debugUnlocked.key, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Saves the value for the proxiwash reminder notification time
|
|
||||||
*
|
|
||||||
* @param value The value to store
|
|
||||||
*/
|
|
||||||
onProxiwashNotifPickerValueChange = (value: number) => {
|
|
||||||
this.setState({notificationReminderSelected: value});
|
|
||||||
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.proxiwashNotifications.key, value);
|
|
||||||
};
|
};
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves the value for the proxiwash reminder notification time
|
* Saves the value for the proxiwash reminder notification time
|
||||||
*
|
*
|
||||||
* @param value The value to store
|
* @param value The value to store
|
||||||
*/
|
*/
|
||||||
onStartScreenPickerValueChange = (value: string) => {
|
onProxiwashNotifPickerValueChange = (value: number) => {
|
||||||
if (value != null) {
|
AsyncStorageManager.set(
|
||||||
this.setState({startScreenPickerSelected: value});
|
AsyncStorageManager.PREFERENCES.proxiwashNotifications.key,
|
||||||
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.defaultStartScreen.key, value);
|
value,
|
||||||
}
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a picker allowing the user to select the proxiwash reminder notification time
|
* Saves the value for the proxiwash reminder notification time
|
||||||
*
|
*
|
||||||
* @returns {React.Node}
|
* @param value The value to store
|
||||||
*/
|
*/
|
||||||
getProxiwashNotifPicker() {
|
onStartScreenPickerValueChange = (value: string) => {
|
||||||
return (
|
if (value != null) {
|
||||||
<CustomSlider
|
this.setState({startScreenPickerSelected: value});
|
||||||
style={{flex: 1, marginHorizontal: 10, height: 50}}
|
AsyncStorageManager.set(
|
||||||
minimumValue={0}
|
AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
|
||||||
maximumValue={10}
|
value,
|
||||||
step={1}
|
);
|
||||||
value={this.savedNotificationReminder}
|
|
||||||
onValueChange={this.onProxiwashNotifPickerValueChange}
|
|
||||||
thumbTintColor={this.props.theme.colors.primary}
|
|
||||||
minimumTrackTintColor={this.props.theme.colors.primary}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a picker allowing the user to select the start screen
|
* Returns a picker allowing the user to select the proxiwash reminder notification time
|
||||||
*
|
*
|
||||||
* @returns {React.Node}
|
* @returns {React.Node}
|
||||||
*/
|
*/
|
||||||
getStartScreenPicker() {
|
getProxiwashNotifPicker(): React.Node {
|
||||||
return (
|
const {theme} = this.props;
|
||||||
<ToggleButton.Row
|
return (
|
||||||
onValueChange={this.onStartScreenPickerValueChange}
|
<CustomSlider
|
||||||
value={this.state.startScreenPickerSelected}
|
style={{flex: 1, marginHorizontal: 10, height: 50}}
|
||||||
style={{marginLeft: 'auto', marginRight: 'auto'}}
|
minimumValue={0}
|
||||||
>
|
maximumValue={10}
|
||||||
<ToggleButton icon="account-circle" value="services"/>
|
step={1}
|
||||||
<ToggleButton icon="tshirt-crew" value="proxiwash"/>
|
value={this.savedNotificationReminder}
|
||||||
<ToggleButton icon="triangle" value="home"/>
|
onValueChange={this.onProxiwashNotifPickerValueChange}
|
||||||
<ToggleButton icon="calendar-range" value="planning"/>
|
thumbTintColor={theme.colors.primary}
|
||||||
<ToggleButton icon="clock" value="planex"/>
|
minimumTrackTintColor={theme.colors.primary}
|
||||||
</ToggleButton.Row>
|
/>
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a picker allowing the user to select the start screen
|
||||||
|
*
|
||||||
|
* @returns {React.Node}
|
||||||
|
*/
|
||||||
|
getStartScreenPicker(): React.Node {
|
||||||
|
const {startScreenPickerSelected} = this.state;
|
||||||
|
return (
|
||||||
|
<ToggleButton.Row
|
||||||
|
onValueChange={this.onStartScreenPickerValueChange}
|
||||||
|
value={startScreenPickerSelected}
|
||||||
|
style={{marginLeft: 'auto', marginRight: 'auto'}}>
|
||||||
|
<ToggleButton icon="account-circle" value="services" />
|
||||||
|
<ToggleButton icon="tshirt-crew" value="proxiwash" />
|
||||||
|
<ToggleButton icon="triangle" value="home" />
|
||||||
|
<ToggleButton icon="calendar-range" value="planning" />
|
||||||
|
<ToggleButton icon="clock" value="planex" />
|
||||||
|
</ToggleButton.Row>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Toggles night mode and saves it to preferences
|
||||||
|
*/
|
||||||
|
onToggleNightMode = () => {
|
||||||
|
const {nightMode} = this.state;
|
||||||
|
ThemeManager.getInstance().setNightMode(!nightMode);
|
||||||
|
this.setState({nightMode: !nightMode});
|
||||||
|
};
|
||||||
|
|
||||||
|
onToggleNightModeFollowSystem = () => {
|
||||||
|
const {nightModeFollowSystem} = this.state;
|
||||||
|
const value = !nightModeFollowSystem;
|
||||||
|
this.setState({nightModeFollowSystem: value});
|
||||||
|
AsyncStorageManager.set(
|
||||||
|
AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
|
||||||
|
value,
|
||||||
|
);
|
||||||
|
if (value) {
|
||||||
|
const nightMode = Appearance.getColorScheme() === 'dark';
|
||||||
|
ThemeManager.getInstance().setNightMode(nightMode);
|
||||||
|
this.setState({nightMode});
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggles night mode and saves it to preferences
|
* Gets a list item using a checkbox control
|
||||||
*/
|
*
|
||||||
onToggleNightMode = () => {
|
* @param onPressCallback The callback when the checkbox state changes
|
||||||
ThemeManager.getInstance().setNightMode(!this.state.nightMode);
|
* @param icon The icon name to display on the list item
|
||||||
this.setState({nightMode: !this.state.nightMode});
|
* @param title The text to display as this list item title
|
||||||
};
|
* @param subtitle The text to display as this list item subtitle
|
||||||
|
* @param state The current state of the switch
|
||||||
|
* @returns {React.Node}
|
||||||
|
*/
|
||||||
|
static getToggleItem(
|
||||||
|
onPressCallback: () => void,
|
||||||
|
icon: string,
|
||||||
|
title: string,
|
||||||
|
subtitle: string,
|
||||||
|
state: boolean,
|
||||||
|
): React.Node {
|
||||||
|
return (
|
||||||
|
<List.Item
|
||||||
|
title={title}
|
||||||
|
description={subtitle}
|
||||||
|
left={({size, color}: {size: number, color: number}): React.Node => (
|
||||||
|
<List.Icon size={size} color={color} icon={icon} />
|
||||||
|
)}
|
||||||
|
right={(): React.Node => (
|
||||||
|
<Switch value={state} onValueChange={onPressCallback} />
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
onToggleNightModeFollowSystem = () => {
|
getNavigateItem(
|
||||||
const value = !this.state.nightModeFollowSystem;
|
route: string,
|
||||||
this.setState({nightModeFollowSystem: value});
|
icon: string,
|
||||||
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key, value);
|
title: string,
|
||||||
if (value) {
|
subtitle: string,
|
||||||
const nightMode = Appearance.getColorScheme() === 'dark';
|
onLongPress?: () => void,
|
||||||
ThemeManager.getInstance().setNightMode(nightMode);
|
): React.Node {
|
||||||
this.setState({nightMode: nightMode});
|
const {navigation} = this.props;
|
||||||
}
|
return (
|
||||||
};
|
<List.Item
|
||||||
|
title={title}
|
||||||
|
description={subtitle}
|
||||||
|
onPress={() => {
|
||||||
|
navigation.navigate(route);
|
||||||
|
}}
|
||||||
|
left={({size, color}: {size: number, color: number}): React.Node => (
|
||||||
|
<List.Icon size={size} color={color} icon={icon} />
|
||||||
|
)}
|
||||||
|
right={({size, color}: {size: number, color: number}): React.Node => (
|
||||||
|
<List.Icon size={size} color={color} icon="chevron-right" />
|
||||||
|
)}
|
||||||
|
onLongPress={onLongPress}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets a list item using a checkbox control
|
* Unlocks debug mode and saves its state to user preferences
|
||||||
*
|
*/
|
||||||
* @param onPressCallback The callback when the checkbox state changes
|
unlockDebugMode = () => {
|
||||||
* @param icon The icon name to display on the list item
|
this.setState({isDebugUnlocked: true});
|
||||||
* @param title The text to display as this list item title
|
AsyncStorageManager.set(
|
||||||
* @param subtitle The text to display as this list item subtitle
|
AsyncStorageManager.PREFERENCES.debugUnlocked.key,
|
||||||
* @param state The current state of the switch
|
true,
|
||||||
* @returns {React.Node}
|
);
|
||||||
*/
|
};
|
||||||
getToggleItem(onPressCallback: Function, icon: string, title: string, subtitle: string, state: boolean) {
|
|
||||||
return (
|
render(): React.Node {
|
||||||
|
const {nightModeFollowSystem, nightMode, isDebugUnlocked} = this.state;
|
||||||
|
return (
|
||||||
|
<CollapsibleScrollView>
|
||||||
|
<Card style={{margin: 5}}>
|
||||||
|
<Card.Title title={i18n.t('screens.settings.generalCard')} />
|
||||||
|
<List.Section>
|
||||||
|
{Appearance.getColorScheme() !== 'no-preference'
|
||||||
|
? SettingsScreen.getToggleItem(
|
||||||
|
this.onToggleNightModeFollowSystem,
|
||||||
|
'theme-light-dark',
|
||||||
|
i18n.t('screens.settings.nightModeAuto'),
|
||||||
|
i18n.t('screens.settings.nightModeAutoSub'),
|
||||||
|
nightModeFollowSystem,
|
||||||
|
)
|
||||||
|
: null}
|
||||||
|
{Appearance.getColorScheme() === 'no-preference' ||
|
||||||
|
!nightModeFollowSystem
|
||||||
|
? SettingsScreen.getToggleItem(
|
||||||
|
this.onToggleNightMode,
|
||||||
|
'theme-light-dark',
|
||||||
|
i18n.t('screens.settings.nightMode'),
|
||||||
|
nightMode
|
||||||
|
? i18n.t('screens.settings.nightModeSubOn')
|
||||||
|
: i18n.t('screens.settings.nightModeSubOff'),
|
||||||
|
nightMode,
|
||||||
|
)
|
||||||
|
: null}
|
||||||
<List.Item
|
<List.Item
|
||||||
title={title}
|
title={i18n.t('screens.settings.startScreen')}
|
||||||
description={subtitle}
|
description={i18n.t('screens.settings.startScreenSub')}
|
||||||
left={props => <List.Icon {...props} icon={icon}/>}
|
left={({
|
||||||
right={() =>
|
size,
|
||||||
<Switch
|
color,
|
||||||
value={state}
|
}: {
|
||||||
onValueChange={onPressCallback}
|
size: number,
|
||||||
/>}
|
color: number,
|
||||||
|
}): React.Node => (
|
||||||
|
<List.Icon size={size} color={color} icon="power" />
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
{this.getStartScreenPicker()}
|
||||||
}
|
{this.getNavigateItem(
|
||||||
|
'dashboard-edit',
|
||||||
getNavigateItem(route: string, icon: string, title: string, subtitle: string, onLongPress?: () => void) {
|
'view-dashboard',
|
||||||
return (
|
i18n.t('screens.settings.dashboard'),
|
||||||
|
i18n.t('screens.settings.dashboardSub'),
|
||||||
|
)}
|
||||||
|
</List.Section>
|
||||||
|
</Card>
|
||||||
|
<Card style={{margin: 5}}>
|
||||||
|
<Card.Title title="Proxiwash" />
|
||||||
|
<List.Section>
|
||||||
<List.Item
|
<List.Item
|
||||||
title={title}
|
title={i18n.t('screens.settings.proxiwashNotifReminder')}
|
||||||
description={subtitle}
|
description={i18n.t('screens.settings.proxiwashNotifReminderSub')}
|
||||||
onPress={() => this.props.navigation.navigate(route)}
|
left={({
|
||||||
left={props => <List.Icon {...props} icon={icon}/>}
|
size,
|
||||||
right={props => <List.Icon {...props} icon={"chevron-right"}/>}
|
color,
|
||||||
onLongPress={onLongPress}
|
}: {
|
||||||
|
size: number,
|
||||||
|
color: number,
|
||||||
|
}): React.Node => (
|
||||||
|
<List.Icon size={size} color={color} icon="washing-machine" />
|
||||||
|
)}
|
||||||
/>
|
/>
|
||||||
);
|
<View style={{marginLeft: 30}}>
|
||||||
}
|
{this.getProxiwashNotifPicker()}
|
||||||
|
</View>
|
||||||
render() {
|
</List.Section>
|
||||||
return (
|
</Card>
|
||||||
<CollapsibleScrollView>
|
<Card style={{margin: 5}}>
|
||||||
<Card style={{margin: 5}}>
|
<Card.Title title={i18n.t('screens.settings.information')} />
|
||||||
<Card.Title title={i18n.t('screens.settings.generalCard')}/>
|
<List.Section>
|
||||||
<List.Section>
|
{isDebugUnlocked
|
||||||
{Appearance.getColorScheme() !== 'no-preference' ? this.getToggleItem(
|
? this.getNavigateItem(
|
||||||
this.onToggleNightModeFollowSystem,
|
'debug',
|
||||||
'theme-light-dark',
|
'bug-check',
|
||||||
i18n.t('screens.settings.nightModeAuto'),
|
i18n.t('screens.debug.title'),
|
||||||
i18n.t('screens.settings.nightModeAutoSub'),
|
'',
|
||||||
this.state.nightModeFollowSystem
|
)
|
||||||
) : null}
|
: null}
|
||||||
{
|
{this.getNavigateItem(
|
||||||
Appearance.getColorScheme() === 'no-preference' || !this.state.nightModeFollowSystem ?
|
'about',
|
||||||
this.getToggleItem(
|
'information',
|
||||||
this.onToggleNightMode,
|
i18n.t('screens.about.title'),
|
||||||
'theme-light-dark',
|
i18n.t('screens.about.buttonDesc'),
|
||||||
i18n.t('screens.settings.nightMode'),
|
this.unlockDebugMode,
|
||||||
this.state.nightMode ?
|
)}
|
||||||
i18n.t('screens.settings.nightModeSubOn') :
|
{this.getNavigateItem(
|
||||||
i18n.t('screens.settings.nightModeSubOff'),
|
'feedback',
|
||||||
this.state.nightMode
|
'comment-quote',
|
||||||
) : null
|
i18n.t('screens.feedback.homeButtonTitle'),
|
||||||
}
|
i18n.t('screens.feedback.homeButtonSubtitle'),
|
||||||
<List.Item
|
)}
|
||||||
title={i18n.t('screens.settings.startScreen')}
|
</List.Section>
|
||||||
description={i18n.t('screens.settings.startScreenSub')}
|
</Card>
|
||||||
left={props => <List.Icon {...props} icon="power"/>}
|
</CollapsibleScrollView>
|
||||||
/>
|
);
|
||||||
{this.getStartScreenPicker()}
|
}
|
||||||
{this.getNavigateItem(
|
|
||||||
"dashboard-edit",
|
|
||||||
"view-dashboard",
|
|
||||||
i18n.t('screens.settings.dashboard'),
|
|
||||||
i18n.t('screens.settings.dashboardSub')
|
|
||||||
)}
|
|
||||||
</List.Section>
|
|
||||||
</Card>
|
|
||||||
<Card style={{margin: 5}}>
|
|
||||||
<Card.Title title="Proxiwash"/>
|
|
||||||
<List.Section>
|
|
||||||
<List.Item
|
|
||||||
title={i18n.t('screens.settings.proxiwashNotifReminder')}
|
|
||||||
description={i18n.t('screens.settings.proxiwashNotifReminderSub')}
|
|
||||||
left={props => <List.Icon {...props} icon="washing-machine"/>}
|
|
||||||
opened={true}
|
|
||||||
/>
|
|
||||||
<View style={{marginLeft: 30}}>
|
|
||||||
{this.getProxiwashNotifPicker()}
|
|
||||||
</View>
|
|
||||||
</List.Section>
|
|
||||||
</Card>
|
|
||||||
<Card style={{margin: 5}}>
|
|
||||||
<Card.Title title={i18n.t('screens.settings.information')}/>
|
|
||||||
<List.Section>
|
|
||||||
{this.state.isDebugUnlocked
|
|
||||||
? this.getNavigateItem(
|
|
||||||
"debug",
|
|
||||||
"bug-check",
|
|
||||||
i18n.t('screens.debug.title'),
|
|
||||||
""
|
|
||||||
)
|
|
||||||
: null}
|
|
||||||
{this.getNavigateItem(
|
|
||||||
"about",
|
|
||||||
"information",
|
|
||||||
i18n.t('screens.about.title'),
|
|
||||||
i18n.t('screens.about.buttonDesc'),
|
|
||||||
this.unlockDebugMode,
|
|
||||||
)}
|
|
||||||
{this.getNavigateItem(
|
|
||||||
"feedback",
|
|
||||||
"comment-quote",
|
|
||||||
i18n.t('screens.feedback.homeButtonTitle'),
|
|
||||||
i18n.t('screens.feedback.homeButtonSubtitle'),
|
|
||||||
)}
|
|
||||||
</List.Section>
|
|
||||||
</Card>
|
|
||||||
</CollapsibleScrollView>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export default withTheme(SettingsScreen);
|
export default withTheme(SettingsScreen);
|
||||||
|
|
Loading…
Reference in a new issue