Browse Source

Added ability to edit preferences from debug menu

keplyx 2 years ago
parent
commit
00daef7a0e
4 changed files with 158 additions and 13 deletions
  1. 17
    2
      components/CustomIntroSlider.js
  2. 122
    10
      screens/DebugScreen.js
  3. 10
    1
      translations/en.json
  4. 9
    0
      translations/fr.json

+ 17
- 2
components/CustomIntroSlider.js View File

@@ -89,6 +89,13 @@ export default class CustomIntroSlider extends React.Component<Props> {
89 89
                 key: '6',
90 90
                 title: i18n.t('intro.slide6.title'),
91 91
                 text: i18n.t('intro.slide6.text'),
92
+                icon: 'silverware-fork-knife',
93
+                colors: ['#ec1213', '#ff372f'],
94
+            },
95
+            {
96
+                key: '7',
97
+                title: i18n.t('intro.slide7.title'),
98
+                text: i18n.t('intro.slide7.text'),
92 99
                 icon: 'cogs',
93 100
                 colors: ['#37c13e', '#26852b'],
94 101
             },
@@ -135,8 +142,16 @@ export default class CustomIntroSlider extends React.Component<Props> {
135 142
 
136 143
     render() {
137 144
         return (
138
-            <AppIntroSlider renderItem={({item, dimensions}) => CustomIntroSlider.getIntroRenderItem(item, dimensions)}
139
-                            slides={this.props.isUpdate ? this.updateSlides : this.introSlides} onDone={() => this.props.onDone()} bottomButton showSkipButton/>
145
+            <AppIntroSlider
146
+                renderItem={({item, dimensions}) => CustomIntroSlider.getIntroRenderItem(item, dimensions)}
147
+                slides={this.props.isUpdate ? this.updateSlides : this.introSlides}
148
+                onDone={() => this.props.onDone()}
149
+                bottomButton
150
+                showSkipButton
151
+                skipLabel={i18n.t('intro.buttons.skip')}
152
+                doneLabel={i18n.t('intro.buttons.done')}
153
+                nextLabel={i18n.t('intro.buttons.next')}
154
+            />
140 155
         );
141 156
     }
142 157
 

+ 122
- 10
screens/DebugScreen.js View File

@@ -1,24 +1,61 @@
1 1
 // @flow
2 2
 
3 3
 import * as React from 'react';
4
-import {Body, Card, CardItem, Container, Content, Left, List, ListItem, Right, Text,} from "native-base";
4
+import {
5
+    Body,
6
+    Card,
7
+    CardItem,
8
+    Container,
9
+    Content,
10
+    H1,
11
+    H3,
12
+    Left,
13
+    List,
14
+    ListItem,
15
+    Right,
16
+    Text,
17
+    Form,
18
+    Item,
19
+    Label,
20
+    Input,
21
+    Button
22
+} from "native-base";
5 23
 import CustomHeader from "../components/CustomHeader";
6 24
 import ThemeManager from '../utils/ThemeManager';
7 25
 import i18n from "i18n-js";
8 26
 import CustomMaterialIcon from "../components/CustomMaterialIcon";
9 27
 import Touchable from "react-native-platform-touchable";
10
-import {Alert, Platform, Clipboard} from "react-native";
28
+import {Alert, View, Clipboard, Image} from "react-native";
11 29
 import AsyncStorageManager from "../utils/AsyncStorageManager";
12 30
 import NotificationsManager from "../utils/NotificationsManager";
31
+import Modalize from "react-native-modalize";
13 32
 
14 33
 type Props = {
15 34
     navigation: Object,
16 35
 };
17 36
 
37
+type State = {
38
+    modalCurrentDisplayItem: Object,
39
+    currentPreferences: Object,
40
+}
41
+
18 42
 /**
19 43
  * Class defining the Debug screen. This screen allows the user to get detailed information on the app/device.
20 44
  */
21
-export default class DebugScreen extends React.Component<Props> {
45
+export default class DebugScreen extends React.Component<Props, State> {
46
+
47
+    modalRef: { current: null | Modalize };
48
+    modalInputValue = '';
49
+
50
+    constructor(props: any) {
51
+        super(props);
52
+        this.modalRef = React.createRef();
53
+    }
54
+
55
+    state = {
56
+        modalCurrentDisplayItem: {},
57
+        currentPreferences: JSON.parse(JSON.stringify(AsyncStorageManager.getInstance().preferences))
58
+    };
22 59
 
23 60
     alertCurrentExpoToken() {
24 61
         let token = AsyncStorageManager.getInstance().preferences.expoToken.current;
@@ -39,15 +76,19 @@ export default class DebugScreen extends React.Component<Props> {
39 76
     }
40 77
 
41 78
 
42
-    static getGeneralItem(onPressCallback: Function, icon: string, title: string, subtitle: string) {
79
+    static getGeneralItem(onPressCallback: Function, icon: ?string, title: string, subtitle: string) {
43 80
         return (
44
-            <CardItem
81
+            <ListItem
45 82
                 button
83
+                thumbnail
46 84
                 onPress={onPressCallback}
47 85
             >
48
-                <Left>
49
-                    <CustomMaterialIcon icon={icon}/>
50
-                </Left>
86
+                {icon !== undefined ?
87
+                    <Left>
88
+                        <CustomMaterialIcon icon={icon}/>
89
+                    </Left>
90
+                    : <View/>
91
+                }
51 92
                 <Body>
52 93
                     <Text>
53 94
                         {title}
@@ -57,14 +98,71 @@ export default class DebugScreen extends React.Component<Props> {
57 98
                     </Text>
58 99
                 </Body>
59 100
                 <Right/>
60
-            </CardItem>
101
+            </ListItem>
61 102
         );
62 103
     }
63 104
 
105
+    showEditModal(item: Object) {
106
+        this.setState({
107
+            modalCurrentDisplayItem: item
108
+        });
109
+        if (this.modalRef.current) {
110
+            this.modalRef.current.open();
111
+        }
112
+    }
113
+
114
+    getModalContent() {
115
+        return (
116
+            <View style={{
117
+                flex: 1,
118
+                padding: 20
119
+            }}>
120
+                <H1>{this.state.modalCurrentDisplayItem.key}</H1>
121
+                <H3>Default: {this.state.modalCurrentDisplayItem.default}</H3>
122
+                <H3>Current: {this.state.modalCurrentDisplayItem.current}</H3>
123
+                <Form>
124
+                    <Item floatingLabel>
125
+                        <Label>New Value</Label>
126
+                        <Input onChangeText={(text) => this.modalInputValue = text}/>
127
+                    </Item>
128
+                </Form>
129
+                <View style={{
130
+                    flexDirection: 'row',
131
+                    marginTop: 10,
132
+                }}>
133
+                    <Button success
134
+                            onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.modalInputValue)}>
135
+                        <Text>Save new value</Text>
136
+                    </Button>
137
+                    <Button
138
+                        onPress={() => this.saveNewPrefs(this.state.modalCurrentDisplayItem.key, this.state.modalCurrentDisplayItem.default)}>
139
+                        <Text>Reset to default</Text>
140
+                    </Button>
141
+                </View>
142
+
143
+            </View>
144
+        );
145
+    }
146
+
147
+    saveNewPrefs(key: string, value: string) {
148
+        this.setState((prevState) => {
149
+            let currentPreferences = {...prevState.currentPreferences};
150
+            currentPreferences[key].current = value;
151
+            return {currentPreferences};
152
+        });
153
+        AsyncStorageManager.getInstance().savePref(key, value);
154
+    }
155
+
64 156
     render() {
65 157
         const nav = this.props.navigation;
66 158
         return (
67 159
             <Container>
160
+                <Modalize
161
+                    ref={this.modalRef}
162
+                    adjustToContentHeight
163
+                    modalStyle={{backgroundColor: ThemeManager.getCurrentThemeVariables().containerBgColor}}>
164
+                    {this.getModalContent()}
165
+                </Modalize>
68 166
                 <CustomHeader navigation={nav} title={i18n.t('screens.debug')} hasBackButton={true}/>
69 167
                 <Content padder>
70 168
                     <Card>
@@ -75,7 +173,21 @@ export default class DebugScreen extends React.Component<Props> {
75 173
                         </CardItem>
76 174
                         <List>
77 175
                             {DebugScreen.getGeneralItem(() => this.alertCurrentExpoToken(), 'bell', 'Get current Expo Token', '')}
78
-                            {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(),'bell-ring', 'Force Expo token update', '')}
176
+                            {DebugScreen.getGeneralItem(() => this.forceExpoTokenUpdate(), 'bell-ring', 'Force Expo token update', '')}
177
+                        </List>
178
+                    </Card>
179
+                    <Card>
180
+                        <CardItem header>
181
+                            <Text>
182
+                                Preferences
183
+                            </Text>
184
+                        </CardItem>
185
+                        <List>
186
+                            {Object.values(this.state.currentPreferences).map((object) =>
187
+                                <View>
188
+                                    {DebugScreen.getGeneralItem(() => this.showEditModal(object), undefined, object.key, 'Click to edit')}
189
+                                </View>
190
+                            )}
79 191
                         </List>
80 192
                     </Card>
81 193
                 </Content>

+ 10
- 1
translations/en.json View File

@@ -16,7 +16,7 @@
16 16
     },
17 17
     "slide2": {
18 18
       "title": "Stay up to date",
19
-      "text": "CAMPUS will soon allow you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!"
19
+      "text": "CAMPUS allows you to be aware of any event occurring on the campus, from pancake sales to Enfoiros concerts!"
20 20
     },
21 21
     "slide3": {
22 22
       "title": "Never forget your laundry",
@@ -31,12 +31,21 @@
31 31
       "text": "Lookup your timetable on CAMPUS"
32 32
     },
33 33
     "slide6": {
34
+      "title": "RU Menu",
35
+      "text": "For the hungry, check this week's menu!"
36
+    },
37
+    "slide7": {
34 38
       "title": "More to come...",
35 39
       "text": "New features are coming soon, do not hesitate to give us feedback to improve the app"
36 40
     },
37 41
     "updateSlide": {
38 42
       "title": "New in this update!",
39 43
       "text": "The RU menu is now working!\nAvailable in the left side menu!"
44
+    },
45
+    "buttons": {
46
+      "next": "Next",
47
+      "skip": "Skip",
48
+      "done": "Done"
40 49
     }
41 50
   },
42 51
   "settingsScreen": {

+ 9
- 0
translations/fr.json View File

@@ -31,12 +31,21 @@
31 31
       "text": "Consultez votre emploi du temps sur CAMPUS"
32 32
     },
33 33
     "slide6": {
34
+      "title": "Menu du RU",
35
+      "text": "Pour ceux qui ont faim, vérifiez le menu du RU de la semaine!"
36
+    },
37
+    "slide7": {
34 38
       "title": "Plus à venir...",
35 39
       "text": "D'autres fonctionnalités arrivent bientôt, n'hésitez pas à nous donner votre avis pour améliorer l'appli"
36 40
     },
37 41
     "updateSlide": {
38 42
       "title": "Nouveau dans cette mise à jour !",
39 43
       "text": "Le menu du RU marche enfin !\nAccessible depuis le menu à gauche"
44
+    },
45
+    "buttons": {
46
+      "next": "Suivant",
47
+      "skip": "Passer",
48
+      "done": "Commencer"
40 49
     }
41 50
   },
42 51
   "settingsScreen": {

Loading…
Cancel
Save