Browse Source

add settings selection

docjyJ 3 years ago
parent
commit
f8f5749478

+ 2
- 1
src/components/Lists/Proxiwash/ProxiwashListItem.js View File

67
     this.updateStateStrings();
67
     this.updateStateStrings();
68
 
68
 
69
     let displayNumber = props.item.number;
69
     let displayNumber = props.item.number;
70
+    const displayMaxWeight = props.item.maxWeight;
70
     if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
71
     if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
71
       displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber(
72
       displayNumber = AprilFoolsManager.getProxiwashMachineDisplayNumber(
72
         parseInt(props.item.number, 10),
73
         parseInt(props.item.number, 10),
75
     this.title = props.isDryer
76
     this.title = props.isDryer
76
       ? i18n.t('screens.proxiwash.dryer')
77
       ? i18n.t('screens.proxiwash.dryer')
77
       : i18n.t('screens.proxiwash.washer');
78
       : i18n.t('screens.proxiwash.washer');
78
-    this.title += ` n°${displayNumber}`;
79
+    this.title += ` n°${displayNumber} - ${displayMaxWeight} kg`;
79
   }
80
   }
80
 
81
 
81
   shouldComponentUpdate(nextProps: PropsType): boolean {
82
   shouldComponentUpdate(nextProps: PropsType): boolean {

+ 4
- 0
src/managers/AsyncStorageManager.js View File

107
       key: 'gameScores',
107
       key: 'gameScores',
108
       default: '[]',
108
       default: '[]',
109
     },
109
     },
110
+    selectedWash: {
111
+      key: 'selectedWash',
112
+      default: 'washinsa',
113
+    },
110
   };
114
   };
111
 
115
 
112
   #currentPreferences: {[key: string]: string};
116
   #currentPreferences: {[key: string]: string};

+ 50
- 0
src/screens/Other/Settings/SettingsScreen.js View File

52
       startScreenPickerSelected: AsyncStorageManager.getString(
52
       startScreenPickerSelected: AsyncStorageManager.getString(
53
         AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
53
         AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
54
       ),
54
       ),
55
+      selectedWash: AsyncStorageManager.getString(
56
+        AsyncStorageManager.PREFERENCES.selectedWash.key,
57
+      ),
55
       isDebugUnlocked: AsyncStorageManager.getBool(
58
       isDebugUnlocked: AsyncStorageManager.getBool(
56
         AsyncStorageManager.PREFERENCES.debugUnlocked.key,
59
         AsyncStorageManager.PREFERENCES.debugUnlocked.key,
57
       ),
60
       ),
86
   };
89
   };
87
 
90
 
88
   /**
91
   /**
92
+   * Saves the value for the proxiwash reminder notification time
93
+   *
94
+   * @param value The value to store
95
+   */
96
+  onSelectWashValueChange = (value: string) => {
97
+    if (value != null) {
98
+      this.setState({selectedWash: value});
99
+      AsyncStorageManager.set(
100
+        AsyncStorageManager.PREFERENCES.selectedWash.key,
101
+        value,
102
+      );
103
+    }
104
+  };
105
+
106
+  /**
89
    * Returns a picker allowing the user to select the proxiwash reminder notification time
107
    * Returns a picker allowing the user to select the proxiwash reminder notification time
90
    *
108
    *
91
    * @returns {React.Node}
109
    * @returns {React.Node}
107
   }
125
   }
108
 
126
 
109
   /**
127
   /**
128
+   * Returns a picker allowing the user to select the wash
129
+   *
130
+   * @returns {React.Node}
131
+   */
132
+  getSelectWashPicker(): React.Node {
133
+    const {selectedWash} = this.state;
134
+    return (
135
+      <ToggleButton.Row
136
+        onValueChange={this.onSelectWashValueChange}
137
+        value={selectedWash}
138
+        style={{marginLeft: 'auto', marginRight: 'auto'}}>
139
+        <ToggleButton icon="school-outline" value="washinsa" />
140
+        <ToggleButton icon="domain" value="tripodeB" />
141
+      </ToggleButton.Row>
142
+    );
143
+  }
144
+
145
+  /**
110
    * Returns a picker allowing the user to select the start screen
146
    * Returns a picker allowing the user to select the start screen
111
    *
147
    *
112
    * @returns {React.Node}
148
    * @returns {React.Node}
288
             <View style={{marginLeft: 30}}>
324
             <View style={{marginLeft: 30}}>
289
               {this.getProxiwashNotifPicker()}
325
               {this.getProxiwashNotifPicker()}
290
             </View>
326
             </View>
327
+
328
+            <List.Item
329
+              title={i18n.t('screens.settings.proxiwashNotifReminder')}
330
+              description={i18n.t('screens.settings.proxiwashNotifReminderSub')}
331
+              left={(props: ListIconPropsType): React.Node => (
332
+                <List.Icon
333
+                  color={props.color}
334
+                  style={props.style}
335
+                  icon="washing-machine"
336
+                />
337
+              )}
338
+            />
339
+
340
+            <View style={{marginLeft: 30}}>{this.getSelectWashPicker()}</View>
291
           </List.Section>
341
           </List.Section>
292
         </Card>
342
         </Card>
293
         <Card style={{margin: 5}}>
343
         <Card style={{margin: 5}}>

+ 66
- 4
src/screens/Proxiwash/ProxiwashScreen.js View File

26
 import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
26
 import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
27
 import MascotPopup from '../../components/Mascot/MascotPopup';
27
 import MascotPopup from '../../components/Mascot/MascotPopup';
28
 import type {SectionListDataType} from '../../components/Screens/WebSectionList';
28
 import type {SectionListDataType} from '../../components/Screens/WebSectionList';
29
+import type {CardTitleIconPropsType} from '../../constants/PaperStyles';
29
 
30
 
30
-const DATA_URL =
31
-  'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json';
31
+type LaverieType = {
32
+  title: string,
33
+  subtitle: string,
34
+  icon: string,
35
+  url: string,
36
+};
37
+
38
+const DATA = {
39
+  washinsa: {
40
+    title: 'Laverie INSA',
41
+    subtitle: 'Ta laverie préférer !!',
42
+    icon: 'school-outline',
43
+    url:
44
+      'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/washinsa_data.json',
45
+  },
46
+  tripodeB: {
47
+    title: 'Laverie Tripode B',
48
+    subtitle: 'En vrai je sais pas trop quoi marqué.',
49
+    icon: 'domain',
50
+    url:
51
+      'https://etud.insa-toulouse.fr/~amicale_app/v2/washinsa/tripode_b_data.json',
52
+  },
53
+};
32
 
54
 
33
 const modalStateStrings = {};
55
 const modalStateStrings = {};
34
 
56
 
38
 export type ProxiwashMachineType = {
60
 export type ProxiwashMachineType = {
39
   number: string,
61
   number: string,
40
   state: string,
62
   state: string,
63
+  maxWeight: number,
41
   startTime: string,
64
   startTime: string,
42
   endTime: string,
65
   endTime: string,
43
   donePercent: string,
66
   donePercent: string,
53
 type StateType = {
76
 type StateType = {
54
   modalCurrentDisplayItem: React.Node,
77
   modalCurrentDisplayItem: React.Node,
55
   machinesWatched: Array<ProxiwashMachineType>,
78
   machinesWatched: Array<ProxiwashMachineType>,
79
+  selectedWash: string,
56
 };
80
 };
57
 
81
 
58
 /**
82
 /**
87
       machinesWatched: AsyncStorageManager.getObject(
111
       machinesWatched: AsyncStorageManager.getObject(
88
         AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key,
112
         AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key,
89
       ),
113
       ),
114
+      selectedWash: AsyncStorageManager.getString(
115
+        AsyncStorageManager.PREFERENCES.selectedWash.key,
116
+      ),
90
     };
117
     };
91
     modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t(
118
     modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t(
92
       'screens.proxiwash.modal.ready',
119
       'screens.proxiwash.modal.ready',
396
     }
423
     }
397
   };
424
   };
398
 
425
 
426
+  getListHeader = (): React.Node => {
427
+    const {selectedWash} = this.state;
428
+    let data: LaverieType;
429
+    switch (selectedWash) {
430
+      case 'tripodeB':
431
+        data = DATA.tripodeB;
432
+        break;
433
+      default:
434
+        data = DATA.washinsa;
435
+    }
436
+    return (
437
+      <Card>
438
+        <Card.Title
439
+          title={data.title}
440
+          subtitle={data.subtitle}
441
+          left={(iconProps: CardTitleIconPropsType): React.Node => (
442
+            <Avatar.Icon size={iconProps.size} icon={data.icon} />
443
+          )}
444
+        />
445
+      </Card>
446
+    );
447
+  };
448
+
399
   /**
449
   /**
400
    * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
450
    * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
401
    *
451
    *
437
   render(): React.Node {
487
   render(): React.Node {
438
     const {state} = this;
488
     const {state} = this;
439
     const {navigation} = this.props;
489
     const {navigation} = this.props;
490
+    let data: LaverieType;
491
+    switch (state.selectedWash) {
492
+      case 'tripodeB':
493
+        data = DATA.tripodeB;
494
+        break;
495
+      default:
496
+        data = DATA.washinsa;
497
+    }
440
     return (
498
     return (
441
-      <View style={{flex: 1}}>
499
+      <View
500
+        style={{
501
+          flex: 1,
502
+        }}>
442
         <View
503
         <View
443
           style={{
504
           style={{
444
             position: 'absolute',
505
             position: 'absolute',
448
           <WebSectionList
509
           <WebSectionList
449
             createDataset={this.createDataset}
510
             createDataset={this.createDataset}
450
             navigation={navigation}
511
             navigation={navigation}
451
-            fetchUrl={DATA_URL}
512
+            fetchUrl={data.url}
452
             renderItem={this.getRenderItem}
513
             renderItem={this.getRenderItem}
453
             renderSectionHeader={this.getRenderSectionHeader}
514
             renderSectionHeader={this.getRenderSectionHeader}
454
             autoRefreshTime={REFRESH_TIME}
515
             autoRefreshTime={REFRESH_TIME}
455
             refreshOnFocus
516
             refreshOnFocus
456
             updateData={state.machinesWatched.length}
517
             updateData={state.machinesWatched.length}
518
+            renderListHeaderComponent={this.getListHeader}
457
           />
519
           />
458
         </View>
520
         </View>
459
         <MascotPopup
521
         <MascotPopup

Loading…
Cancel
Save