Browse Source

Added setting to set proxiwash reminder notification

keplyx 2 years ago
parent
commit
f2cd3bec0d

+ 3
- 4
App.js View File

@@ -35,8 +35,7 @@ export default class App extends React.Component {
35 35
     }
36 36
 
37 37
     updateTheme() {
38
-        console.log('update theme called');
39
-        // Change not propagating, need to restart the app
38
+        // console.log('update theme called');
40 39
         this.setState({
41 40
             currentTheme: ThemeManager.getInstance().getCurrentTheme()
42 41
         });
@@ -47,8 +46,8 @@ export default class App extends React.Component {
47 46
         if (this.state.isLoading) {
48 47
             return <View/>;
49 48
         }
50
-        console.log('rendering');
51
-        console.log(this.state.currentTheme.variables.containerBgColor);
49
+        // console.log('rendering');
50
+        // console.log(this.state.currentTheme.variables.containerBgColor);
52 51
         return (
53 52
             <Root>
54 53
                 <StyleProvider style={this.state.currentTheme}>

+ 2
- 2
app.json View File

@@ -1,6 +1,6 @@
1 1
 {
2 2
   "expo": {
3
-    "name": "Application Amicale",
3
+    "name": "Amicale INSAT",
4 4
     "slug": "application-amicale",
5 5
     "privacy": "public",
6 6
     "sdkVersion": "33.0.0",
@@ -15,7 +15,7 @@
15 15
     "primaryColor": "#e42612",
16 16
     "splash": {
17 17
       "image": "./assets/splash.png",
18
-      "resizeMode": "contain",
18
+      "resizeMode": "cover",
19 19
       "backgroundColor": "#fff"
20 20
     },
21 21
     "updates": {

+ 1
- 1
native-base-theme/variables/platformDark.js View File

@@ -118,7 +118,7 @@ export default {
118 118
     containerBgColor: "#333333",
119 119
 
120 120
     //Date Picker
121
-    datePickerTextColor: "#000",
121
+    datePickerTextColor: "#fff",
122 122
     datePickerBg: "transparent",
123 123
 
124 124
     // Font

+ 19
- 0
package-lock.json View File

@@ -1782,6 +1782,11 @@
1782 1782
         }
1783 1783
       }
1784 1784
     },
1785
+    "base-64": {
1786
+      "version": "0.1.0",
1787
+      "resolved": "https://registry.npmjs.org/base-64/-/base-64-0.1.0.tgz",
1788
+      "integrity": "sha1-eAqZyE59YAJgNhURxId2E78k9rs="
1789
+    },
1785 1790
     "base64-js": {
1786 1791
       "version": "1.3.0",
1787 1792
       "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.3.0.tgz",
@@ -6253,6 +6258,15 @@
6253 6258
         }
6254 6259
       }
6255 6260
     },
6261
+    "react-native-fs": {
6262
+      "version": "2.13.3",
6263
+      "resolved": "https://registry.npmjs.org/react-native-fs/-/react-native-fs-2.13.3.tgz",
6264
+      "integrity": "sha512-B62LSSAEYQGItg7KVTzTVVCxezOYFBYp4DMVFbdoZUd1mZVFdqR2sy1HY1mye1VI/Lf3IbxSyZEQ0GmrrdwLjg==",
6265
+      "requires": {
6266
+        "base-64": "^0.1.0",
6267
+        "utf8": "^2.1.1"
6268
+      }
6269
+    },
6256 6270
     "react-native-gesture-handler": {
6257 6271
       "version": "1.2.1",
6258 6272
       "resolved": "https://registry.npmjs.org/react-native-gesture-handler/-/react-native-gesture-handler-1.2.1.tgz",
@@ -8374,6 +8388,11 @@
8374 8388
       "resolved": "https://registry.npmjs.org/use/-/use-3.1.1.tgz",
8375 8389
       "integrity": "sha512-cwESVXlO3url9YWlFW/TA9cshCEhtu7IKJ/p5soJ/gGpj7vbvFrAY/eIioQ6Dw23KjZhYgiIo8HOs1nQ2vr/oQ=="
8376 8390
     },
8391
+    "utf8": {
8392
+      "version": "2.1.2",
8393
+      "resolved": "https://registry.npmjs.org/utf8/-/utf8-2.1.2.tgz",
8394
+      "integrity": "sha1-H6DZJw6b6FDZsFAn9jUZv0ZFfZY="
8395
+    },
8377 8396
     "util-deprecate": {
8378 8397
       "version": "1.0.2",
8379 8398
       "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz",

+ 1
- 0
package.json View File

@@ -22,6 +22,7 @@
22 22
     "react-dom": "^16.8.6",
23 23
     "react-i18next": "latest",
24 24
     "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
25
+    "react-native-fs": "^2.13.3",
25 26
     "react-native-paper": "latest",
26 27
     "react-native-platform-touchable": "latest",
27 28
     "react-native-settings-page": "latest",

+ 20
- 5
screens/Proximo/ProximoMainScreen.js View File

@@ -1,6 +1,6 @@
1 1
 import React from 'react';
2
-import {StyleSheet, RefreshControl, FlatList} from 'react-native';
3
-import {Container, Text, Content, ListItem, Left, Right, Body, Badge, Icon, Toast} from 'native-base';
2
+import {RefreshControl, SectionList} from 'react-native';
3
+import {Container, Text, Content, ListItem, Left, Right, Body, Badge, Icon, Toast, H2} from 'native-base';
4 4
 import CustomHeader from "../../components/CustomHeader";
5 5
 import i18n from "i18n-js";
6 6
 import CustomMaterialIcon from "../../components/CustomMaterialIcon";
@@ -82,12 +82,24 @@ export default class ProximoMainScreen extends React.Component {
82 82
 
83 83
     render() {
84 84
         const nav = this.props.navigation;
85
+        const data = [
86
+            {
87
+                title: i18n.t('proximoScreen.listTitle'),
88
+                data: this.state.data,
89
+                extraData: this.state,
90
+            }
91
+        ];
92
+        const loadingData = [
93
+            {
94
+                title: i18n.t('proximoScreen.loading'),
95
+                data: []
96
+            }
97
+        ];
85 98
         return (
86 99
             <Container>
87 100
                 <CustomHeader navigation={nav} title={'Proximo'}/>
88
-                <FlatList
89
-                    data={this.state.data}
90
-                    extraData={this.state}
101
+                <SectionList
102
+                    sections={this.state.firstLoading ? loadingData : data}
91 103
                     keyExtractor={(item, index) => item.type}
92 104
                     refreshControl={
93 105
                         <RefreshControl
@@ -96,6 +108,9 @@ export default class ProximoMainScreen extends React.Component {
96 108
                         />
97 109
                     }
98 110
                     style={{minHeight: 300, width: '100%'}}
111
+                    renderSectionHeader={({section: {title}}) => (
112
+                        <H2 style={{textAlign: 'center', paddingVertical: 10}}>{title}</H2>
113
+                    )}
99 114
                     renderItem={({item}) =>
100 115
                         <ListItem
101 116
                             button

+ 21
- 10
screens/ProxiwashScreen.js View File

@@ -11,7 +11,7 @@ import CustomMaterialIcon from "../components/CustomMaterialIcon";
11 11
 const DATA_URL = "https://etud.insa-toulouse.fr/~vergnet/appli-amicale/dataProxiwash.json";
12 12
 const WATCHED_MACHINES_PREFKEY = "proxiwash.watchedMachines";
13 13
 
14
-const remainderNotifTime = 5;
14
+let reminderNotifTime = 5;
15 15
 
16 16
 const MACHINE_STATES = {
17 17
     TERMINE: "0",
@@ -72,9 +72,12 @@ export default class ProxiwashScreen extends React.Component {
72 72
         let dataString = await AsyncStorage.getItem(WATCHED_MACHINES_PREFKEY);
73 73
         if (dataString === null)
74 74
             dataString = '[]';
75
-        this.setState({machinesWatched: JSON.parse(dataString)});
75
+        this.setState({
76
+            machinesWatched: JSON.parse(dataString)
77
+        });
76 78
     }
77 79
 
80
+
78 81
     componentDidMount() {
79 82
         this._onRefresh();
80 83
     }
@@ -112,16 +115,24 @@ export default class ProxiwashScreen extends React.Component {
112 115
                 i18n.t('proxiwashScreen.notifications.machineFinishedBody', {number: number}),
113 116
                 new Date().getTime() + remainingTime * (60 * 1000) // Convert back to milliseconds
114 117
             );
115
-            let remainderNotifID = undefined;
116
-            if (remainingTime > remainderNotifTime) {
117
-                remainderNotifID = await NotificationsManager.scheduleNotification(
118
-                    i18n.t('proxiwashScreen.notifications.machineRunningTitle', {time: remainderNotifTime}),
118
+            let reminderNotifID = undefined;
119
+            let val = await AsyncStorage.getItem('proxiwashNotifKey');
120
+            if (val === null)
121
+                val = "5";
122
+            if (val !== "never")
123
+                reminderNotifTime = parseInt(val);
124
+            else
125
+                reminderNotifTime = -1;
126
+            console.log(reminderNotifTime);
127
+            if (remainingTime > reminderNotifTime && reminderNotifTime > 0) {
128
+                reminderNotifID = await NotificationsManager.scheduleNotification(
129
+                    i18n.t('proxiwashScreen.notifications.machineRunningTitle', {time: reminderNotifTime}),
119 130
                     i18n.t('proxiwashScreen.notifications.machineRunningBody', {number: number}),
120
-                    new Date().getTime() + (remainingTime - remainderNotifTime) * (60 * 1000) // Convert back to milliseconds
131
+                    new Date().getTime() + (remainingTime - reminderNotifTime) * (60 * 1000) // Convert back to milliseconds
121 132
                 );
122 133
             }
123 134
             let data = this.state.machinesWatched;
124
-            data.push({machineNumber: number, endNotifID: endNotifID, remainderNotifID: remainderNotifID});
135
+            data.push({machineNumber: number, endNotifID: endNotifID, reminderNotifID: reminderNotifID});
125 136
             this.setState({machinesWatched: data});
126 137
             AsyncStorage.setItem(WATCHED_MACHINES_PREFKEY, JSON.stringify(data));
127 138
         } else
@@ -136,8 +147,8 @@ export default class ProxiwashScreen extends React.Component {
136 147
             });
137 148
             let arrayIndex = data.indexOf(elem);
138 149
             NotificationsManager.cancelScheduledNoification(data[arrayIndex].endNotifID);
139
-            if (data[arrayIndex].remainderNotifID !== undefined)
140
-                NotificationsManager.cancelScheduledNoification(data[arrayIndex].remainderNotifID);
150
+            if (data[arrayIndex].reminderNotifID !== undefined)
151
+                NotificationsManager.cancelScheduledNoification(data[arrayIndex].reminderNotifID);
141 152
             data.splice(arrayIndex, 1);
142 153
             this.setState({machinesWatched: data});
143 154
             AsyncStorage.setItem(WATCHED_MACHINES_PREFKEY, JSON.stringify(data));

+ 123
- 22
screens/SettingsScreen.js View File

@@ -1,22 +1,74 @@
1 1
 import React from 'react';
2
-import {Container, Content, Left, ListItem, Right, Text, List, CheckBox, Button} from "native-base";
2
+import {
3
+    Container,
4
+    Content,
5
+    Left,
6
+    ListItem,
7
+    Right,
8
+    Text,
9
+    List,
10
+    CheckBox,
11
+    Body,
12
+    CardItem,
13
+    Card,
14
+    Picker,
15
+} from "native-base";
3 16
 import CustomHeader from "../components/CustomHeader";
4 17
 import ThemeManager from '../utils/ThemeManager';
5 18
 import i18n from "i18n-js";
6 19
 import {NavigationActions, StackActions} from "react-navigation";
7 20
 import CustomMaterialIcon from "../components/CustomMaterialIcon";
21
+import {AsyncStorage} from 'react-native'
8 22
 
9
-
10
-const nightModeKey = 'nightMode';
23
+const proxiwashNotifKey = "proxiwashNotifKey";
11 24
 
12 25
 export default class SettingsScreen extends React.Component {
13 26
     state = {
14 27
         nightMode: ThemeManager.getInstance().getNightMode(),
28
+        proxiwashNotifPickerSelected: "5"
15 29
     };
16 30
 
31
+    async componentWillMount() {
32
+        let val = await AsyncStorage.getItem(proxiwashNotifKey);
33
+        if (val === null)
34
+            val = "5";
35
+        this.setState({
36
+            proxiwashNotifPickerSelected: val,
37
+        });
38
+    }
39
+
40
+
41
+    onProxiwashNotidPickerValueChange(value) {
42
+        AsyncStorage.setItem(proxiwashNotifKey, value);
43
+        this.setState({
44
+            proxiwashNotifPickerSelected: value
45
+        });
46
+    }
47
+
48
+    getproxiwashNotifPicker() {
49
+        return (
50
+            <Picker
51
+                note
52
+                mode="dropdown"
53
+                style={{width: 120}}
54
+                selectedValue={this.state.proxiwashNotifPickerSelected}
55
+                onValueChange={(value) => this.onProxiwashNotidPickerValueChange(value)}
56
+            >
57
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.never')} value="never"/>
58
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.1')} value="1"/>
59
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.2')} value="2"/>
60
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.3')} value="3"/>
61
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.5')} value="5"/>
62
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.10')} value="10"/>
63
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.20')} value="20"/>
64
+                <Picker.Item label={i18n.t('settingsScreen.proxiwashNotifReminderPicker.30')} value="30"/>
65
+            </Picker>
66
+        );
67
+    }
68
+
17 69
     toggleNightMode() {
18
-        this.setState({nightMode: !this.state.nightMode});
19 70
         ThemeManager.getInstance().setNightmode(!this.state.nightMode);
71
+        this.setState({nightMode: !this.state.nightMode});
20 72
         // Alert.alert(i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.restart'));
21 73
         this.resetStack();
22 74
     }
@@ -25,35 +77,84 @@ export default class SettingsScreen extends React.Component {
25 77
         const resetAction = StackActions.reset({
26 78
             index: 0,
27 79
             key: null,
28
-            actions: [NavigationActions.navigate({ routeName: 'Main' })],
80
+            actions: [NavigationActions.navigate({routeName: 'Main'})],
29 81
         });
30 82
         this.props.navigation.dispatch(resetAction);
31 83
         this.props.navigation.navigate('Settings');
32 84
     }
33 85
 
86
+    getToggleItem(onPressCallback, icon, text, subtitle) {
87
+        return (
88
+            <ListItem
89
+                button
90
+                thumbnail
91
+                onPress={onPressCallback}
92
+            >
93
+                <Left>
94
+                    <CustomMaterialIcon icon={icon}/>
95
+                </Left>
96
+                <Body>
97
+                    <Text>
98
+                        {text}
99
+                    </Text>
100
+                    <Text note>
101
+                        {subtitle}
102
+                    </Text>
103
+                </Body>
104
+                <Right style={{flex: 1}}>
105
+                    <CheckBox checked={this.state.nightMode}
106
+                              onPress={() => this.toggleNightMode()}/>
107
+                </Right>
108
+            </ListItem>
109
+        );
110
+    }
111
+
112
+    getGeneralItem(control, icon, text, subtitle) {
113
+        return (
114
+            <ListItem
115
+                thumbnail
116
+            >
117
+                <Left>
118
+                    <CustomMaterialIcon icon={icon}/>
119
+                </Left>
120
+                <Body>
121
+                    <Text>
122
+                        {text}
123
+                    </Text>
124
+                    <Text note>
125
+                        {subtitle}
126
+                    </Text>
127
+                </Body>
128
+
129
+                <Right style={{flex: 1}}>
130
+                    {control}
131
+                </Right>
132
+            </ListItem>
133
+        );
134
+    }
135
+
34 136
     render() {
35 137
         const nav = this.props.navigation;
36 138
         return (
37 139
             <Container>
38 140
                 <CustomHeader navigation={nav} title={i18n.t('screens.settings')}/>
39 141
                 <Content>
40
-                    <List>
41
-                        <ListItem
42
-                            button
43
-                            onPress={() => this.toggleNightMode()}
44
-                        >
45
-                            <Left>
46
-                                <CustomMaterialIcon icon={'theme-light-dark'} />
47
-                                <Text>
48
-                                    {i18n.t('settingsScreen.nightMode')}
49
-                                </Text>
50
-                            </Left>
51
-                            <Right style={{flex: 1}}>
52
-                                <CheckBox checked={this.state.nightMode}
53
-                                          onPress={() => this.toggleNightMode()}/>
54
-                            </Right>
55
-                        </ListItem>
56
-                    </List>
142
+                    <Card>
143
+                        <CardItem header>
144
+                            <Text>{i18n.t('settingsScreen.appearanceCard')}</Text>
145
+                        </CardItem>
146
+                        <List>
147
+                            {this.getToggleItem(() => this.toggleNightMode(), 'theme-light-dark', i18n.t('settingsScreen.nightMode'), i18n.t('settingsScreen.nightModeSub'))}
148
+                        </List>
149
+                    </Card>
150
+                    <Card>
151
+                        <CardItem header>
152
+                            <Text>Proxiwash</Text>
153
+                        </CardItem>
154
+                        <List>
155
+                            {this.getGeneralItem(this.getproxiwashNotifPicker(), 'washing-machine', i18n.t('settingsScreen.proxiwashNotifReminder'), i18n.t('settingsScreen.proxiwashNotifReminderSub'))}
156
+                        </List>
157
+                    </Card>
57 158
                 </Content>
58 159
             </Container>
59 160
 

+ 17
- 2
translations/en.json View File

@@ -6,8 +6,21 @@
6 6
     "about": "About"
7 7
   },
8 8
   "settingsScreen": {
9
+    "appearanceCard": "Appearance",
9 10
     "nightMode": "Night Mode",
10
-    "restart": "Restart the app to apply changes"
11
+    "nightModeSub": "Switch the app to a dark or light theme",
12
+    "proxiwashNotifReminder": "Machine running reminder",
13
+    "proxiwashNotifReminderSub": "Choose when to send a notification to remind you a machine is running with your laundry",
14
+    "proxiwashNotifReminderPicker": {
15
+      "never": "Never",
16
+      "1": "1 min",
17
+      "2": "2 min",
18
+      "3": "3 min",
19
+      "5": "5 min",
20
+      "10": "10 min",
21
+      "20": "20 min",
22
+      "30": "30 min"
23
+    }
11 24
   },
12 25
   "aboutScreen": {
13 26
     "appstore": "See on the Appstore",
@@ -27,7 +40,9 @@
27 40
     "articles": "Articles",
28 41
     "sortName": "Sort by name",
29 42
     "sortPrice": "Sort by price",
30
-    "listUpdated": "Article list updated!"
43
+    "listUpdated": "Article list updated!",
44
+    "loading": "Loading...",
45
+    "listTitle": "Choose a category"
31 46
   },
32 47
   "proxiwashScreen": {
33 48
     "dryer": "Dryer",

+ 17
- 2
translations/fr.json View File

@@ -6,8 +6,21 @@
6 6
     "about": "À Propos"
7 7
   },
8 8
   "settingsScreen": {
9
+    "appearanceCard": "Apparence",
9 10
     "nightMode": "Mode Nuit",
10
-    "restart": "Redémarrez l'application pour appliquer les changements"
11
+    "nightModeSub": "Passer l'application dans un thème sombre ou clair",
12
+    "proxiwashNotifReminder": "Rappel de machine en cours",
13
+    "proxiwashNotifReminderSub": "Choississez quand envoyer une notification pour vous rappeler qu'une machine avec votre linge est en cours",
14
+    "proxiwashNotifReminderPicker": {
15
+      "never": "Jamais",
16
+      "1": "1 min",
17
+      "2": "2 min",
18
+      "3": "3 min",
19
+      "5": "5 min",
20
+      "10": "10 min",
21
+      "20": "20 min",
22
+      "30": "30 min"
23
+    }
11 24
   },
12 25
   "aboutScreen": {
13 26
     "appstore": "Voir sur l'Appstore",
@@ -27,7 +40,9 @@
27 40
     "articles": "Articles",
28 41
     "sortName": "Trier par nom",
29 42
     "sortPrice": "Trier par prix",
30
-    "listUpdated": "Liste des articles mise à jour !"
43
+    "listUpdated": "Liste des articles mise à jour !",
44
+    "loading": "Chargement...",
45
+    "listTitle": "Choisissez une catégorie"
31 46
   },
32 47
   "proxiwashScreen": {
33 48
     "dryer": "Sèche Linge",

+ 0
- 2
utils/ThemeManager.js View File

@@ -23,8 +23,6 @@ export default class ThemeManager {
23 23
 
24 24
     setUpdateThemeCallback(callback) {
25 25
         this.updateThemeCallback = callback;
26
-        console.log(this.updateThemeCallback);
27
-
28 26
     }
29 27
 
30 28
     async getDataFromPreferences() {

Loading…
Cancel
Save