2019-08-26 12:49:26 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2020-03-06 23:15:01 +01:00
|
|
|
import {Alert, Clipboard, ScrollView, View} from "react-native";
|
2020-03-08 14:22:03 +01:00
|
|
|
import AsyncStorageManager from "../../utils/AsyncStorageManager";
|
|
|
|
import NotificationsManager from "../../utils/NotificationsManager";
|
|
|
|
import CustomModal from "../../components/CustomModal";
|
2020-03-09 23:15:13 +01:00
|
|
|
import {Button, Card, List, Subheading, TextInput, Title, withTheme} from 'react-native-paper';
|
2019-08-26 12:49:26 +02:00
|
|
|
|
|
|
|
type Props = {
|
|
|
|
navigation: Object,
|
|
|
|
};
|
|
|
|
|
2019-09-20 11:05:34 +02:00
|
|
|
type State = {
|
|
|
|
modalCurrentDisplayItem: Object,
|
|
|
|
currentPreferences: Object,
|
|
|
|
}
|
|
|
|
|
2019-08-26 12:49:26 +02:00
|
|
|
/**
|
|
|
|
* Class defining the Debug screen. This screen allows the user to get detailed information on the app/device.
|
|
|
|
*/
|
2020-03-09 23:15:13 +01:00
|
|
|
class DebugScreen extends React.Component<Props, State> {
|
2019-09-20 11:05:34 +02:00
|
|
|
|
2020-03-08 14:19:47 +01:00
|
|
|
modalRef: Object;
|
2019-09-20 11:05:34 +02:00
|
|
|
modalInputValue = '';
|
|
|
|
state = {
|
|
|
|
modalCurrentDisplayItem: {},
|
|
|
|
currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences))
|
|
|
|
};
|
2019-08-26 12:49:26 +02:00
|
|
|
|
2020-03-08 14:19:47 +01:00
|
|
|
onModalRef: Function;
|
|
|
|
|
2020-03-09 23:15:13 +01:00
|
|
|
colors: Object;
|
|
|
|
|
|
|
|
constructor(props) {
|
2020-01-31 16:51:43 +01:00
|
|
|
super(props);
|
2020-03-08 14:19:47 +01:00
|
|
|
this.onModalRef = this.onModalRef.bind(this);
|
2020-03-09 23:15:13 +01:00
|
|
|
this.colors = props.theme.colors;
|
2019-08-26 12:49:26 +02:00
|
|
|
}
|
|
|
|
|
2019-09-20 11:05:34 +02:00
|
|
|
static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) {
|
2020-03-06 23:15:01 +01:00
|
|
|
if (icon !== undefined) {
|
|
|
|
return (
|
|
|
|
<List.Item
|
|
|
|
title={title}
|
|
|
|
description={subtitle}
|
|
|
|
left={() => <List.Icon icon={icon}/>}
|
|
|
|
onPress={onPressCallback}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return (
|
|
|
|
<List.Item
|
|
|
|
title={title}
|
|
|
|
description={subtitle}
|
|
|
|
onPress={onPressCallback}
|
|
|
|
/>
|
|
|
|
);
|
|
|
|
}
|
2019-08-26 12:49:26 +02:00
|
|
|
}
|
|
|
|
|
2020-01-31 16:51:43 +01:00
|
|
|
alertCurrentExpoToken() {
|
|
|
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
|
|
|
Alert.alert(
|
|
|
|
'Expo Token',
|
|
|
|
token,
|
|
|
|
[
|
|
|
|
{text: 'Copy', onPress: () => Clipboard.setString(token)},
|
|
|
|
{text: 'OK'}
|
|
|
|
]
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async forceExpoTokenUpdate() {
|
|
|
|
await NotificationsManager.forceExpoTokenUpdate();
|
|
|
|
this.alertCurrentExpoToken();
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:05:34 +02:00
|
|
|
showEditModal(item: Object) {
|
|
|
|
this.setState({
|
|
|
|
modalCurrentDisplayItem: item
|
|
|
|
});
|
2020-03-08 14:19:47 +01:00
|
|
|
if (this.modalRef) {
|
|
|
|
this.modalRef.open();
|
2019-09-20 11:05:34 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getModalContent() {
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
flex: 1,
|
|
|
|
padding: 20
|
|
|
|
}}>
|
2020-03-06 23:15:01 +01:00
|
|
|
<Title>{this.state.modalCurrentDisplayItem.key}</Title>
|
|
|
|
<Subheading>Default: {this.state.modalCurrentDisplayItem.default}</Subheading>
|
|
|
|
<Subheading>Current: {this.state.modalCurrentDisplayItem.current}</Subheading>
|
|
|
|
<TextInput
|
|
|
|
label='New Value'
|
|
|
|
onChangeText={(text) => this.modalInputValue = text}
|
|
|
|
/>
|
2019-09-20 11:05:34 +02:00
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginTop: 10,
|
|
|
|
}}>
|
2020-03-06 23:15:01 +01:00
|
|
|
<Button
|
|
|
|
mode="contained"
|
|
|
|
dark={true}
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.success}
|
2020-03-06 23:15:01 +01:00
|
|
|
onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.modalInputValue)}>
|
|
|
|
Save new value
|
2019-09-20 11:05:34 +02:00
|
|
|
</Button>
|
|
|
|
<Button
|
2020-03-06 23:15:01 +01:00
|
|
|
mode="contained"
|
|
|
|
dark={true}
|
2020-03-09 23:15:13 +01:00
|
|
|
color={this.colors.danger}
|
2019-09-20 11:05:34 +02:00
|
|
|
onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.state.modalCurrentDisplayItem.default)}>
|
2020-03-06 23:15:01 +01:00
|
|
|
Reset to default
|
2019-09-20 11:05:34 +02:00
|
|
|
</Button>
|
|
|
|
</View>
|
|
|
|
|
|
|
|
</View>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
saveNewPrefs(key: string, value: string) {
|
|
|
|
this.setState((prevState) => {
|
|
|
|
let currentPreferences = {...prevState.currentPreferences};
|
|
|
|
currentPreferences[key].current = value;
|
|
|
|
return {currentPreferences};
|
|
|
|
});
|
|
|
|
AsyncStorageManager.getInstance().savePref(key, value);
|
|
|
|
}
|
|
|
|
|
2020-03-08 14:19:47 +01:00
|
|
|
onModalRef(ref: Object) {
|
|
|
|
this.modalRef = ref;
|
|
|
|
}
|
|
|
|
|
2019-08-26 12:49:26 +02:00
|
|
|
render() {
|
|
|
|
return (
|
2020-03-06 23:15:01 +01:00
|
|
|
<View>
|
2020-03-08 14:19:47 +01:00
|
|
|
<CustomModal onRef={this.onModalRef}>
|
2019-09-20 11:05:34 +02:00
|
|
|
{this.getModalContent()}
|
2020-03-08 14:19:47 +01:00
|
|
|
</CustomModal>
|
2020-03-06 23:15:01 +01:00
|
|
|
<ScrollView style={{padding: 5}}>
|
|
|
|
<Card style={{margin: 5}}>
|
|
|
|
<Card.Title
|
|
|
|
title={'Notifications'}
|
|
|
|
/>
|
|
|
|
<Card.Content>
|
2019-08-26 12:49:26 +02:00
|
|
|
{DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')}
|
2019-09-20 11:05:34 +02:00
|
|
|
{DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(), 'bell-ring', 'Force Expo token update', '')}
|
2020-03-06 23:15:01 +01:00
|
|
|
</Card.Content>
|
2019-09-20 11:05:34 +02:00
|
|
|
</Card>
|
2020-03-06 23:15:01 +01:00
|
|
|
<Card style={{margin: 5}}>
|
|
|
|
<Card.Title
|
|
|
|
title={'Preferences'}
|
|
|
|
/>
|
|
|
|
<Card.Content>
|
2019-09-20 11:05:34 +02:00
|
|
|
{Object.values(this.state.currentPreferences).map((object) =>
|
|
|
|
<View>
|
|
|
|
{DebugScreen.getGeneralItem(() => this.showEditModal(object), undefined, object.key, 'Click to edit')}
|
|
|
|
</View>
|
|
|
|
)}
|
2020-03-06 23:15:01 +01:00
|
|
|
</Card.Content>
|
2019-08-26 12:49:26 +02:00
|
|
|
</Card>
|
2020-03-06 23:15:01 +01:00
|
|
|
</ScrollView>
|
|
|
|
</View>
|
2019-08-26 12:49:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2020-03-09 23:15:13 +01:00
|
|
|
|
|
|
|
export default withTheme(DebugScreen);
|