Added debug screen, fixed ios icon size

This commit is contained in:
keplyx 2019-08-26 12:49:26 +02:00
parent c8bab93868
commit 528867ab3c
9 changed files with 196 additions and 35 deletions

View file

@ -10,7 +10,7 @@
"android",
"web"
],
"version": "0.0.14",
"version": "0.0.15",
"orientation": "portrait",
"primaryColor": "#be1522",
"icon": "./assets/android.icon.png",
@ -36,7 +36,7 @@
},
"android": {
"package": "fr.amicaleinsat.application",
"versionCode": 2,
"versionCode": 3,
"icon": "./assets/android.icon.png",
"adaptiveIcon": {
"foregroundImage": "./assets/android.adaptive-icon.png",

Binary file not shown.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 87 KiB

View file

@ -9,6 +9,7 @@ import AboutDependenciesScreen from '../screens/About/AboutDependenciesScreen';
import ProxiwashAboutScreen from '../screens/ProxiwashAboutScreen';
import ProximoAboutScreen from '../screens/Proximo/ProximoAboutScreen';
import SelfMenuScreen from '../screens/SelfMenuScreen';
import DebugScreen from '../screens/DebugScreen';
import {fromRight} from "react-navigation-transitions";
/**
@ -25,6 +26,7 @@ export default createAppContainer(
SelfMenuScreen: {screen: SelfMenuScreen},
ProxiwashAboutScreen: {screen: ProxiwashAboutScreen},
ProximoAboutScreen: {screen: ProximoAboutScreen},
DebugScreen: {screen: DebugScreen},
},
{
initialRouteName: "Main",

View file

@ -1,13 +1,14 @@
// @flow
import * as React from 'react';
import {Alert, FlatList, Linking, Platform} from 'react-native';
import {FlatList, Linking, Platform, View} from 'react-native';
import {Body, Card, CardItem, Container, Content, H1, Left, Right, Text, Thumbnail} from 'native-base';
import CustomHeader from "../../components/CustomHeader";
import i18n from "i18n-js";
import appJson from '../../app';
import packageJson from '../../package';
import CustomMaterialIcon from "../../components/CustomMaterialIcon";
import AsyncStorageManager from "../../utils/AsyncStorageManager";
const links = {
appstore: 'https://qwant.com',
@ -27,6 +28,10 @@ type Props = {
navigation: Object,
};
type State = {
isDebugUnlocked: boolean,
};
/**
* Opens a link in the device's browser
* @param link The link to open
@ -38,7 +43,13 @@ function openWebLink(link) {
/**
* Class defining an about screen. This screen shows the user information about the app and it's author.
*/
export default class AboutScreen extends React.Component<Props> {
export default class AboutScreen extends React.Component<Props, State> {
debugTapCounter = 0;
state = {
isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
};
/**
* Data to be displayed in the app card
@ -80,6 +91,13 @@ export default class AboutScreen extends React.Component<Props> {
text: i18n.t('aboutScreen.license'),
showChevron: true
},
{
onPressCallback: () => this.props.navigation.navigate('DebugScreen'),
icon: 'bug-check',
text: i18n.t('aboutScreen.debug'),
showChevron: true,
showOnlyDebug: true
},
];
/**
@ -87,7 +105,7 @@ export default class AboutScreen extends React.Component<Props> {
*/
authorData: Array<Object> = [
{
onPressCallback: () => Alert.alert('Coucou', 'Whaou'),
onPressCallback: () => this.tryUnlockDebugMode(),
icon: 'account-circle',
text: 'Arnaud VERGNET',
showChevron: false
@ -137,9 +155,12 @@ export default class AboutScreen extends React.Component<Props> {
* @param icon The icon name to use from MaterialCommunityIcons
* @param text The text to show
* @param showChevron Whether to show a chevron indicating this button will change screen
* @param showOnlyInDebug Should we show te current item only in debug mode?
* @returns {React.Node}
*/
static getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean) {
getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean, showOnlyInDebug: boolean) {
let shouldShow = !showOnlyInDebug || (showOnlyInDebug && this.state.isDebugUnlocked);
if (shouldShow) {
return (
<CardItem button
onPress={onPressCallback}>
@ -157,6 +178,25 @@ export default class AboutScreen extends React.Component<Props> {
}
</CardItem>)
;
} else {
return <View/>
}
}
tryUnlockDebugMode() {
this.debugTapCounter = this.debugTapCounter + 1;
console.log(this.debugTapCounter);
if (this.debugTapCounter >= 4) {
this.unlockDebugMode();
}
}
unlockDebugMode() {
console.log('unlocked');
this.setState({isDebugUnlocked: true});
let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
AsyncStorageManager.getInstance().savePref(key, '1');
}
render() {
@ -168,9 +208,9 @@ export default class AboutScreen extends React.Component<Props> {
<Card>
<CardItem>
<Left>
<Thumbnail square source={require('../../assets/amicale.png')}/>
<Thumbnail square source={require('../../assets/icon.png')}/>
<Body>
<H1>Amicale INSA Toulouse</H1>
<H1>CAMPUS - Amicale INSAT</H1>
<Text note>
v.{appJson.expo.version}
</Text>
@ -179,9 +219,10 @@ export default class AboutScreen extends React.Component<Props> {
</CardItem>
<FlatList
data={this.appData}
extraData={this.state}
keyExtractor={(item) => item.icon}
renderItem={({item}) =>
AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
/>
</Card>
@ -192,9 +233,10 @@ export default class AboutScreen extends React.Component<Props> {
</CardItem>
<FlatList
data={this.authorData}
extraData={this.state}
keyExtractor={(item) => item.icon}
renderItem={({item}) =>
AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
/>
</Card>
@ -205,9 +247,10 @@ export default class AboutScreen extends React.Component<Props> {
</CardItem>
<FlatList
data={this.technoData}
extraData={this.state}
keyExtractor={(item) => item.icon}
renderItem={({item}) =>
AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
}
/>
</Card>

99
screens/DebugScreen.js Normal file
View file

@ -0,0 +1,99 @@
// @flow
import * as React from 'react';
import {Body, Card, CardItem, Container, Content, Left, List, ListItem, Right, Text,} from "native-base";
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";
import {Alert, Platform, Clipboard} from "react-native";
import AsyncStorageManager from "../utils/AsyncStorageManager";
import NotificationsManager from "../utils/NotificationsManager";
type Props = {
navigation: Object,
};
/**
* Class defining the Debug screen. This screen allows the user to get detailed information on the app/device.
*/
export default class DebugScreen extends React.Component<Props> {
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();
}
static getGeneralItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
return (
<CardItem
button
onPress={onPressCallback}
>
<Left>
<CustomMaterialIcon icon={icon}/>
</Left>
<Body>
<Text>
{title}
</Text>
<Text note>
{subtitle}
</Text>
</Body>
<Right/>
</CardItem>
);
}
getRightButton() {
return (
<Touchable
style={{padding: 6}}
onPress={() => this.props.navigation.navigate('AboutScreen')}>
<CustomMaterialIcon
color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
icon="information"/>
</Touchable>
);
}
render() {
const nav = this.props.navigation;
return (
<Container>
<CustomHeader navigation={nav} title={i18n.t('screens.debug')} hasBackButton={true}
rightButton={this.getRightButton()}/>
<Content padder>
<Card>
<CardItem header>
<Text>
Notifications
</Text>
</CardItem>
<List>
{DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')}
{DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(),'bell-ring', 'Force Expo token update', '')}
</List>
</Card>
</Content>
</Container>
);
}
}

View file

@ -6,7 +6,8 @@
"proximo": "Proximo",
"menuSelf": "RU Menu",
"settings": "Settings",
"about": "About"
"about": "About",
"debug": "Debug"
},
"intro": {
"slide1": {
@ -15,7 +16,7 @@
},
"slide2": {
"title": "Stay up to date",
"text": "CAMPUS will soon allow you to be aware of any event occuring on the campus, from pancake sales to Enfoiros concerts!"
"text": "CAMPUS will soon allow you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!"
},
"slide3": {
"title": "Never forget your laundry",
@ -23,7 +24,7 @@
},
"slide4": {
"title": "Proximo",
"text": "Are you short on pasta? Or you maybe you feel a little peckish, then lookup the stock for your insa shop in real time"
"text": "Are you short on pasta? Or you maybe you feel a little peckish, then look up your INSA shop's stock in real time"
},
"slide5": {
"title": "Planex",
@ -31,7 +32,7 @@
},
"slide6": {
"title": "Still in development",
"text": "New features coming soon, do not hesitate to give us feedback to improve the app"
"text": "New features are coming soon, do not hesitate to give us feedback to improve the app"
}
},
"settingsScreen": {
@ -66,6 +67,7 @@
"bugs": "Report Bugs",
"changelog": "Changelog",
"license": "License",
"debug": "Debug",
"author": "Author",
"mail": "Send an email",
"technologies": "Technologies",

View file

@ -6,7 +6,8 @@
"proximo": "Proximo",
"menuSelf": "Menu Ru",
"settings": "Paramètres",
"about": "À Propos"
"about": "À Propos",
"debug": "Debug"
},
"intro": {
"slide1": {
@ -66,6 +67,7 @@
"bugs": "Rapporter des Bugs",
"changelog": "Historique des modifications",
"license": "Licence",
"debug": "Debug",
"author": "Auteur",
"mail": "Envoyer un mail",
"technologies": "Technologies",
@ -127,7 +129,7 @@
"states": {
"finished": "TERMINE",
"ready": "DISPONIBLE",
"running": "En COURS",
"running": "EN COURS",
"broken": "HORS SERVICE",
"error": "ERREUR"
},

View file

@ -48,6 +48,11 @@ export default class AsyncStorageManager {
key: 'expoToken',
default: '',
current: '',
},
debugUnlocked: {
key: 'debugUnlocked',
default: '0',
current: '',
}
};

View file

@ -95,12 +95,20 @@ export default class NotificationsManager {
static async initExpoToken() {
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (token === '') {
await NotificationsManager.askPermissions();
let expoToken = await Notifications.getExpoPushTokenAsync();
// Save token for instant use later on
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
}
}
static async forceExpoTokenUpdate() {
await NotificationsManager.askPermissions();
let expoToken = await Notifications.getExpoPushTokenAsync();
// Save token for instant use later on
AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
}
static getMachineNotificationWatchlist(callback: Function) {
let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
if (token === '') {