Browse Source

Added debug screen, fixed ios icon size

keplyx 4 years ago
parent
commit
528867ab3c

+ 2
- 2
app.json View File

@@ -10,7 +10,7 @@
10 10
       "android",
11 11
       "web"
12 12
     ],
13
-    "version": "0.0.14",
13
+    "version": "0.0.15",
14 14
     "orientation": "portrait",
15 15
     "primaryColor": "#be1522",
16 16
     "icon": "./assets/android.icon.png",
@@ -36,7 +36,7 @@
36 36
     },
37 37
     "android": {
38 38
       "package": "fr.amicaleinsat.application",
39
-      "versionCode": 2,
39
+      "versionCode": 3,
40 40
       "icon": "./assets/android.icon.png",
41 41
       "adaptiveIcon": {
42 42
         "foregroundImage": "./assets/android.adaptive-icon.png",

BIN
assets/ios.icon.png View File


+ 2
- 0
navigation/AppNavigator.js View File

@@ -9,6 +9,7 @@ import AboutDependenciesScreen from '../screens/About/AboutDependenciesScreen';
9 9
 import ProxiwashAboutScreen from '../screens/ProxiwashAboutScreen';
10 10
 import ProximoAboutScreen from '../screens/Proximo/ProximoAboutScreen';
11 11
 import SelfMenuScreen from '../screens/SelfMenuScreen';
12
+import DebugScreen from '../screens/DebugScreen';
12 13
 import {fromRight} from "react-navigation-transitions";
13 14
 
14 15
 /**
@@ -25,6 +26,7 @@ export default createAppContainer(
25 26
             SelfMenuScreen: {screen: SelfMenuScreen},
26 27
             ProxiwashAboutScreen: {screen: ProxiwashAboutScreen},
27 28
             ProximoAboutScreen: {screen: ProximoAboutScreen},
29
+            DebugScreen: {screen: DebugScreen},
28 30
         },
29 31
         {
30 32
             initialRouteName: "Main",

+ 69
- 26
screens/About/AboutScreen.js View File

@@ -1,13 +1,14 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Alert, FlatList, Linking, Platform} from 'react-native';
4
+import {FlatList, Linking, Platform, View} from 'react-native';
5 5
 import {Body, Card, CardItem, Container, Content, H1, Left, Right, Text, Thumbnail} from 'native-base';
6 6
 import CustomHeader from "../../components/CustomHeader";
7 7
 import i18n from "i18n-js";
8 8
 import appJson from '../../app';
9 9
 import packageJson from '../../package';
10 10
 import CustomMaterialIcon from "../../components/CustomMaterialIcon";
11
+import AsyncStorageManager from "../../utils/AsyncStorageManager";
11 12
 
12 13
 const links = {
13 14
     appstore: 'https://qwant.com',
@@ -27,6 +28,10 @@ type Props = {
27 28
     navigation: Object,
28 29
 };
29 30
 
31
+type State = {
32
+    isDebugUnlocked: boolean,
33
+};
34
+
30 35
 /**
31 36
  * Opens a link in the device's browser
32 37
  * @param link The link to open
@@ -38,7 +43,13 @@ function openWebLink(link) {
38 43
 /**
39 44
  * Class defining an about screen. This screen shows the user information about the app and it's author.
40 45
  */
41
-export default class AboutScreen extends React.Component<Props> {
46
+export default class AboutScreen extends React.Component<Props, State> {
47
+
48
+    debugTapCounter = 0;
49
+
50
+    state = {
51
+        isDebugUnlocked: AsyncStorageManager.getInstance().preferences.debugUnlocked.current === '1'
52
+    };
42 53
 
43 54
     /**
44 55
      * Data to be displayed in the app card
@@ -80,6 +91,13 @@ export default class AboutScreen extends React.Component<Props> {
80 91
             text: i18n.t('aboutScreen.license'),
81 92
             showChevron: true
82 93
         },
94
+        {
95
+            onPressCallback: () => this.props.navigation.navigate('DebugScreen'),
96
+            icon: 'bug-check',
97
+            text: i18n.t('aboutScreen.debug'),
98
+            showChevron: true,
99
+            showOnlyDebug: true
100
+        },
83 101
     ];
84 102
 
85 103
     /**
@@ -87,7 +105,7 @@ export default class AboutScreen extends React.Component<Props> {
87 105
      */
88 106
     authorData: Array<Object> = [
89 107
         {
90
-            onPressCallback: () => Alert.alert('Coucou', 'Whaou'),
108
+            onPressCallback: () => this.tryUnlockDebugMode(),
91 109
             icon: 'account-circle',
92 110
             text: 'Arnaud VERGNET',
93 111
             showChevron: false
@@ -137,26 +155,48 @@ export default class AboutScreen extends React.Component<Props> {
137 155
      * @param icon The icon name to use from MaterialCommunityIcons
138 156
      * @param text The text to show
139 157
      * @param showChevron Whether to show a chevron indicating this button will change screen
158
+     * @param showOnlyInDebug Should we show te current item only in debug mode?
140 159
      * @returns {React.Node}
141 160
      */
142
-    static getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean) {
143
-        return (
144
-            <CardItem button
145
-                      onPress={onPressCallback}>
146
-                <Left>
147
-                    <CustomMaterialIcon icon={icon}/>
148
-                    <Text>{text}</Text>
149
-                </Left>
150
-                {showChevron ?
151
-                    <Right>
152
-                        <CustomMaterialIcon icon="chevron-right"
153
-                                            fontSize={20}/>
154
-                    </Right>
155
-                    :
156
-                    <Right/>
157
-                }
158
-            </CardItem>)
159
-            ;
161
+    getCardItem(onPressCallback: Function, icon: string, text: string, showChevron: boolean, showOnlyInDebug: boolean) {
162
+        let shouldShow = !showOnlyInDebug || (showOnlyInDebug && this.state.isDebugUnlocked);
163
+        if (shouldShow) {
164
+            return (
165
+                <CardItem button
166
+                          onPress={onPressCallback}>
167
+                    <Left>
168
+                        <CustomMaterialIcon icon={icon}/>
169
+                        <Text>{text}</Text>
170
+                    </Left>
171
+                    {showChevron ?
172
+                        <Right>
173
+                            <CustomMaterialIcon icon="chevron-right"
174
+                                                fontSize={20}/>
175
+                        </Right>
176
+                        :
177
+                        <Right/>
178
+                    }
179
+                </CardItem>)
180
+                ;
181
+        } else {
182
+            return <View/>
183
+        }
184
+
185
+    }
186
+
187
+    tryUnlockDebugMode() {
188
+        this.debugTapCounter = this.debugTapCounter + 1;
189
+        console.log(this.debugTapCounter);
190
+        if (this.debugTapCounter >= 4) {
191
+            this.unlockDebugMode();
192
+        }
193
+    }
194
+
195
+    unlockDebugMode() {
196
+        console.log('unlocked');
197
+        this.setState({isDebugUnlocked: true});
198
+        let key = AsyncStorageManager.getInstance().preferences.debugUnlocked.key;
199
+        AsyncStorageManager.getInstance().savePref(key, '1');
160 200
     }
161 201
 
162 202
     render() {
@@ -168,9 +208,9 @@ export default class AboutScreen extends React.Component<Props> {
168 208
                     <Card>
169 209
                         <CardItem>
170 210
                             <Left>
171
-                                <Thumbnail square source={require('../../assets/amicale.png')}/>
211
+                                <Thumbnail square source={require('../../assets/icon.png')}/>
172 212
                                 <Body>
173
-                                    <H1>Amicale INSA Toulouse</H1>
213
+                                    <H1>CAMPUS - Amicale INSAT</H1>
174 214
                                     <Text note>
175 215
                                         v.{appJson.expo.version}
176 216
                                     </Text>
@@ -179,9 +219,10 @@ export default class AboutScreen extends React.Component<Props> {
179 219
                         </CardItem>
180 220
                         <FlatList
181 221
                             data={this.appData}
222
+                            extraData={this.state}
182 223
                             keyExtractor={(item) => item.icon}
183 224
                             renderItem={({item}) =>
184
-                                AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
225
+                                this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
185 226
                             }
186 227
                         />
187 228
                     </Card>
@@ -192,9 +233,10 @@ export default class AboutScreen extends React.Component<Props> {
192 233
                         </CardItem>
193 234
                         <FlatList
194 235
                             data={this.authorData}
236
+                            extraData={this.state}
195 237
                             keyExtractor={(item) => item.icon}
196 238
                             renderItem={({item}) =>
197
-                                AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
239
+                                this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
198 240
                             }
199 241
                         />
200 242
                     </Card>
@@ -205,9 +247,10 @@ export default class AboutScreen extends React.Component<Props> {
205 247
                         </CardItem>
206 248
                         <FlatList
207 249
                             data={this.technoData}
250
+                            extraData={this.state}
208 251
                             keyExtractor={(item) => item.icon}
209 252
                             renderItem={({item}) =>
210
-                                AboutScreen.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron)
253
+                                this.getCardItem(item.onPressCallback, item.icon, item.text, item.showChevron, item.showOnlyDebug)
211 254
                             }
212 255
                         />
213 256
                     </Card>

+ 99
- 0
screens/DebugScreen.js View File

@@ -0,0 +1,99 @@
1
+// @flow
2
+
3
+import * as React from 'react';
4
+import {Body, Card, CardItem, Container, Content, Left, List, ListItem, Right, Text,} from "native-base";
5
+import CustomHeader from "../components/CustomHeader";
6
+import ThemeManager from '../utils/ThemeManager';
7
+import i18n from "i18n-js";
8
+import CustomMaterialIcon from "../components/CustomMaterialIcon";
9
+import Touchable from "react-native-platform-touchable";
10
+import {Alert, Platform, Clipboard} from "react-native";
11
+import AsyncStorageManager from "../utils/AsyncStorageManager";
12
+import NotificationsManager from "../utils/NotificationsManager";
13
+
14
+type Props = {
15
+    navigation: Object,
16
+};
17
+
18
+/**
19
+ * Class defining the Debug screen. This screen allows the user to get detailed information on the app/device.
20
+ */
21
+export default class DebugScreen extends React.Component<Props> {
22
+
23
+    alertCurrentExpoToken() {
24
+        let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
25
+        console.log(token);
26
+        Alert.alert(
27
+            'Expo Token',
28
+            token,
29
+            [
30
+                {text: 'Copy', onPress: () => Clipboard.setString(token)},
31
+                {text: 'OK'}
32
+            ]
33
+        );
34
+    }
35
+
36
+    async forceExpoTokenUpdate() {
37
+        await NotificationsManager.forceExpoTokenUpdate();
38
+        this.alertCurrentExpoToken();
39
+    }
40
+
41
+
42
+    static getGeneralItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
43
+        return (
44
+            <CardItem
45
+                button
46
+                onPress={onPressCallback}
47
+            >
48
+                <Left>
49
+                    <CustomMaterialIcon icon={icon}/>
50
+                </Left>
51
+                <Body>
52
+                    <Text>
53
+                        {title}
54
+                    </Text>
55
+                    <Text note>
56
+                        {subtitle}
57
+                    </Text>
58
+                </Body>
59
+                <Right/>
60
+            </CardItem>
61
+        );
62
+    }
63
+
64
+    getRightButton() {
65
+        return (
66
+            <Touchable
67
+                style={{padding: 6}}
68
+                onPress={() => this.props.navigation.navigate('AboutScreen')}>
69
+                <CustomMaterialIcon
70
+                    color={Platform.OS === 'ios' ? ThemeManager.getCurrentThemeVariables().brandPrimary : "#fff"}
71
+                    icon="information"/>
72
+            </Touchable>
73
+        );
74
+    }
75
+
76
+    render() {
77
+        const nav = this.props.navigation;
78
+        return (
79
+            <Container>
80
+                <CustomHeader navigation={nav} title={i18n.t('screens.debug')} hasBackButton={true}
81
+                              rightButton={this.getRightButton()}/>
82
+                <Content padder>
83
+                    <Card>
84
+                        <CardItem header>
85
+                            <Text>
86
+                                Notifications
87
+                            </Text>
88
+                        </CardItem>
89
+                        <List>
90
+                            {DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')}
91
+                            {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(),'bell-ring', 'Force Expo token update', '')}
92
+                        </List>
93
+                    </Card>
94
+                </Content>
95
+            </Container>
96
+
97
+        );
98
+    }
99
+}

+ 7
- 5
translations/en.json View File

@@ -6,7 +6,8 @@
6 6
     "proximo": "Proximo",
7 7
     "menuSelf": "RU Menu",
8 8
     "settings": "Settings",
9
-    "about": "About"
9
+    "about": "About",
10
+    "debug": "Debug"
10 11
   },
11 12
   "intro": {
12 13
     "slide1": {
@@ -15,15 +16,15 @@
15 16
     },
16 17
     "slide2": {
17 18
       "title": "Stay up to date",
18
-      "text": "CAMPUS will soon allow you to be aware of any event occuring on the campus, from pancake sales to Enfoiros concerts!"
19
+      "text": "CAMPUS will soon allow you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!"
19 20
     },
20 21
     "slide3": {
21 22
       "title": "Never forget your laundry",
22
-      "text": "CAMPUS will inform you on the availability of washing machines and will remind you just before yours finishes !"
23
+      "text": "CAMPUS will inform you on the availability of washing machines and will remind you just before yours finishes!"
23 24
     },
24 25
     "slide4": {
25 26
       "title": "Proximo",
26
-      "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"
27
+      "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"
27 28
     },
28 29
     "slide5": {
29 30
       "title": "Planex",
@@ -31,7 +32,7 @@
31 32
     },
32 33
     "slide6": {
33 34
       "title": "Still in development",
34
-      "text": "New features coming soon, do not hesitate to give us feedback to improve the app"
35
+      "text": "New features are coming soon, do not hesitate to give us feedback to improve the app"
35 36
     }
36 37
   },
37 38
   "settingsScreen": {
@@ -66,6 +67,7 @@
66 67
     "bugs": "Report Bugs",
67 68
     "changelog": "Changelog",
68 69
     "license": "License",
70
+    "debug": "Debug",
69 71
     "author": "Author",
70 72
     "mail": "Send an email",
71 73
     "technologies": "Technologies",

+ 4
- 2
translations/fr.json View File

@@ -6,7 +6,8 @@
6 6
     "proximo": "Proximo",
7 7
     "menuSelf": "Menu Ru",
8 8
     "settings": "Paramètres",
9
-    "about": "À Propos"
9
+    "about": "À Propos",
10
+    "debug": "Debug"
10 11
   },
11 12
   "intro": {
12 13
     "slide1": {
@@ -66,6 +67,7 @@
66 67
     "bugs": "Rapporter des Bugs",
67 68
     "changelog": "Historique des modifications",
68 69
     "license": "Licence",
70
+    "debug": "Debug",
69 71
     "author": "Auteur",
70 72
     "mail": "Envoyer un mail",
71 73
     "technologies": "Technologies",
@@ -127,7 +129,7 @@
127 129
     "states": {
128 130
       "finished": "TERMINE",
129 131
       "ready": "DISPONIBLE",
130
-      "running": "En COURS",
132
+      "running": "EN COURS",
131 133
       "broken": "HORS SERVICE",
132 134
       "error": "ERREUR"
133 135
     },

+ 5
- 0
utils/AsyncStorageManager.js View File

@@ -48,6 +48,11 @@ export default class AsyncStorageManager {
48 48
             key: 'expoToken',
49 49
             default: '',
50 50
             current: '',
51
+        },
52
+        debugUnlocked: {
53
+            key: 'debugUnlocked',
54
+            default: '0',
55
+            current: '',
51 56
         }
52 57
     };
53 58
 

+ 8
- 0
utils/NotificationsManager.js View File

@@ -95,12 +95,20 @@ export default class NotificationsManager {
95 95
     static async initExpoToken() {
96 96
         let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
97 97
         if (token === '') {
98
+            await NotificationsManager.askPermissions();
98 99
             let expoToken = await Notifications.getExpoPushTokenAsync();
99 100
             // Save token for instant use later on
100 101
             AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
101 102
         }
102 103
     }
103 104
 
105
+    static async forceExpoTokenUpdate() {
106
+        await NotificationsManager.askPermissions();
107
+        let expoToken = await Notifications.getExpoPushTokenAsync();
108
+        // Save token for instant use later on
109
+        AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.expoToken.key, expoToken);
110
+    }
111
+
104 112
     static getMachineNotificationWatchlist(callback: Function) {
105 113
         let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
106 114
         if (token === '') {

Loading…
Cancel
Save