2019-08-26 12:49:26 +02:00
|
|
|
// @flow
|
|
|
|
|
|
|
|
import * as React from 'react';
|
2019-09-20 11:05:34 +02:00
|
|
|
import {
|
|
|
|
Body,
|
|
|
|
Card,
|
|
|
|
CardItem,
|
|
|
|
Container,
|
|
|
|
Content,
|
|
|
|
H1,
|
|
|
|
H3,
|
|
|
|
Left,
|
|
|
|
List,
|
|
|
|
ListItem,
|
|
|
|
Right,
|
|
|
|
Text,
|
|
|
|
Form,
|
|
|
|
Item,
|
|
|
|
Label,
|
|
|
|
Input,
|
|
|
|
Button
|
|
|
|
} from "native-base";
|
2019-08-26 12:49:26 +02:00
|
|
|
import CustomHeader from "../components/CustomHeader";
|
|
|
|
import ThemeManager from '../utils/ThemeManager';
|
|
|
|
import i18n from "i18n-js";
|
|
|
|
import CustomMaterialIcon from "../components/CustomMaterialIcon";
|
|
|
|
import Touchable from "react-native-platform-touchable";
|
2019-09-20 11:05:34 +02:00
|
|
|
import {Alert, View, Clipboard, Image} from "react-native";
|
2019-08-26 12:49:26 +02:00
|
|
|
import AsyncStorageManager from "../utils/AsyncStorageManager";
|
|
|
|
import NotificationsManager from "../utils/NotificationsManager";
|
2020-01-26 17:51:15 +01:00
|
|
|
import {Modalize} from "react-native-modalize";
|
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.
|
|
|
|
*/
|
2019-09-20 11:05:34 +02:00
|
|
|
export default class DebugScreen extends React.Component<Props, State> {
|
|
|
|
|
|
|
|
modalRef: { current: null | Modalize };
|
|
|
|
modalInputValue = '';
|
|
|
|
|
|
|
|
constructor(props: any) {
|
|
|
|
super(props);
|
|
|
|
this.modalRef = React.createRef();
|
|
|
|
}
|
|
|
|
|
|
|
|
state = {
|
|
|
|
modalCurrentDisplayItem: {},
|
|
|
|
currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences))
|
|
|
|
};
|
2019-08-26 12:49:26 +02:00
|
|
|
|
|
|
|
alertCurrentExpoToken() {
|
|
|
|
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
|
|
|
|
console.log(token);
|
|
|
|
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
|
|
|
static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) {
|
2019-08-26 12:49:26 +02:00
|
|
|
return (
|
2019-09-20 11:05:34 +02:00
|
|
|
<ListItem
|
2019-08-26 12:49:26 +02:00
|
|
|
button
|
2019-09-20 11:05:34 +02:00
|
|
|
thumbnail
|
2019-08-26 12:49:26 +02:00
|
|
|
onPress={onPressCallback}
|
|
|
|
>
|
2019-09-20 11:05:34 +02:00
|
|
|
{icon !== undefined ?
|
|
|
|
<Left>
|
|
|
|
<CustomMaterialIcon icon={icon}/>
|
|
|
|
</Left>
|
|
|
|
: <View/>
|
|
|
|
}
|
2019-08-26 12:49:26 +02:00
|
|
|
<Body>
|
|
|
|
<Text>
|
|
|
|
{title}
|
|
|
|
</Text>
|
|
|
|
<Text note>
|
|
|
|
{subtitle}
|
|
|
|
</Text>
|
|
|
|
</Body>
|
|
|
|
<Right/>
|
2019-09-20 11:05:34 +02:00
|
|
|
</ListItem>
|
2019-08-26 12:49:26 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-09-20 11:05:34 +02:00
|
|
|
showEditModal(item: Object) {
|
|
|
|
this.setState({
|
|
|
|
modalCurrentDisplayItem: item
|
|
|
|
});
|
|
|
|
if (this.modalRef.current) {
|
|
|
|
this.modalRef.current.open();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
getModalContent() {
|
|
|
|
return (
|
|
|
|
<View style={{
|
|
|
|
flex: 1,
|
|
|
|
padding: 20
|
|
|
|
}}>
|
|
|
|
<H1>{this.state.modalCurrentDisplayItem.key}</H1>
|
|
|
|
<H3>Default: {this.state.modalCurrentDisplayItem.default}</H3>
|
|
|
|
<H3>Current: {this.state.modalCurrentDisplayItem.current}</H3>
|
|
|
|
<Form>
|
|
|
|
<Item floatingLabel>
|
|
|
|
<Label>New Value</Label>
|
|
|
|
<Input onChangeText={(text) => this.modalInputValue = text}/>
|
|
|
|
</Item>
|
|
|
|
</Form>
|
|
|
|
<View style={{
|
|
|
|
flexDirection: 'row',
|
|
|
|
marginTop: 10,
|
|
|
|
}}>
|
|
|
|
<Button success
|
|
|
|
onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.modalInputValue)}>
|
|
|
|
<Text>Save new value</Text>
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.state.modalCurrentDisplayItem.default)}>
|
|
|
|
<Text>Reset to default</Text>
|
|
|
|
</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);
|
|
|
|
}
|
|
|
|
|
2019-08-26 12:49:26 +02:00
|
|
|
render() {
|
|
|
|
const nav = this.props.navigation;
|
|
|
|
return (
|
|
|
|
<Container>
|
2019-09-20 11:05:34 +02:00
|
|
|
<Modalize
|
|
|
|
ref={this.modalRef}
|
|
|
|
adjustToContentHeight
|
|
|
|
modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor}}>
|
|
|
|
{this.getModalContent()}
|
|
|
|
</Modalize>
|
2019-08-27 19:25:09 +02:00
|
|
|
<CustomHeader navigation={nav} title={i18n.t('screens.debug')} hasBackButton={true}/>
|
2019-08-26 12:49:26 +02:00
|
|
|
<Content padder>
|
|
|
|
<Card>
|
|
|
|
<CardItem header>
|
|
|
|
<Text>
|
|
|
|
Notifications
|
|
|
|
</Text>
|
|
|
|
</CardItem>
|
|
|
|
<List>
|
|
|
|
{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', '')}
|
|
|
|
</List>
|
|
|
|
</Card>
|
|
|
|
<Card>
|
|
|
|
<CardItem header>
|
|
|
|
<Text>
|
|
|
|
Preferences
|
|
|
|
</Text>
|
|
|
|
</CardItem>
|
|
|
|
<List>
|
|
|
|
{Object.values(this.state.currentPreferences).map((object) =>
|
|
|
|
<View>
|
|
|
|
{DebugScreen.getGeneralItem(() => this.showEditModal(object), undefined, object.key, 'Click to edit')}
|
|
|
|
</View>
|
|
|
|
)}
|
2019-08-26 12:49:26 +02:00
|
|
|
</List>
|
|
|
|
</Card>
|
|
|
|
</Content>
|
|
|
|
</Container>
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|