Browse Source

add settings selection

docjyJ 1 year ago
parent
commit
f8f5749478

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

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

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

@@ -107,6 +107,10 @@ export default class AsyncStorageManager {
107 107
       key: 'gameScores',
108 108
       default: '[]',
109 109
     },
110
+    selectedWash: {
111
+      key: 'selectedWash',
112
+      default: 'washinsa',
113
+    },
110 114
   };
111 115
 
112 116
   #currentPreferences: {[key: string]: string};

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

@@ -52,6 +52,9 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
52 52
       startScreenPickerSelected: AsyncStorageManager.getString(
53 53
         AsyncStorageManager.PREFERENCES.defaultStartScreen.key,
54 54
       ),
55
+      selectedWash: AsyncStorageManager.getString(
56
+        AsyncStorageManager.PREFERENCES.selectedWash.key,
57
+      ),
55 58
       isDebugUnlocked: AsyncStorageManager.getBool(
56 59
         AsyncStorageManager.PREFERENCES.debugUnlocked.key,
57 60
       ),
@@ -86,6 +89,21 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
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 107
    * Returns a picker allowing the user to select the proxiwash reminder notification time
90 108
    *
91 109
    * @returns {React.Node}
@@ -107,6 +125,24 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
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 146
    * Returns a picker allowing the user to select the start screen
111 147
    *
112 148
    * @returns {React.Node}
@@ -288,6 +324,20 @@ class SettingsScreen extends React.Component<PropsType, StateType> {
288 324
             <View style={{marginLeft: 30}}>
289 325
               {this.getProxiwashNotifPicker()}
290 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 341
           </List.Section>
292 342
         </Card>
293 343
         <Card style={{margin: 5}}>

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

@@ -26,9 +26,31 @@ import {
26 26
 import {MASCOT_STYLE} from '../../components/Mascot/Mascot';
27 27
 import MascotPopup from '../../components/Mascot/MascotPopup';
28 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 55
 const modalStateStrings = {};
34 56
 
@@ -38,6 +60,7 @@ const LIST_ITEM_HEIGHT = 64;
38 60
 export type ProxiwashMachineType = {
39 61
   number: string,
40 62
   state: string,
63
+  maxWeight: number,
41 64
   startTime: string,
42 65
   endTime: string,
43 66
   donePercent: string,
@@ -53,6 +76,7 @@ type PropsType = {
53 76
 type StateType = {
54 77
   modalCurrentDisplayItem: React.Node,
55 78
   machinesWatched: Array<ProxiwashMachineType>,
79
+  selectedWash: string,
56 80
 };
57 81
 
58 82
 /**
@@ -87,6 +111,9 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
87 111
       machinesWatched: AsyncStorageManager.getObject(
88 112
         AsyncStorageManager.PREFERENCES.proxiwashWatchedMachines.key,
89 113
       ),
114
+      selectedWash: AsyncStorageManager.getString(
115
+        AsyncStorageManager.PREFERENCES.selectedWash.key,
116
+      ),
90 117
     };
91 118
     modalStateStrings[ProxiwashConstants.machineStates.AVAILABLE] = i18n.t(
92 119
       'screens.proxiwash.modal.ready',
@@ -396,6 +423,29 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
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 450
    * Adds the given notifications associated to a machine ID to the watchlist, and saves the array to the preferences
401 451
    *
@@ -437,8 +487,19 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
437 487
   render(): React.Node {
438 488
     const {state} = this;
439 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 498
     return (
441
-      <View style={{flex: 1}}>
499
+      <View
500
+        style={{
501
+          flex: 1,
502
+        }}>
442 503
         <View
443 504
           style={{
444 505
             position: 'absolute',
@@ -448,12 +509,13 @@ class ProxiwashScreen extends React.Component<PropsType, StateType> {
448 509
           <WebSectionList
449 510
             createDataset={this.createDataset}
450 511
             navigation={navigation}
451
-            fetchUrl={DATA_URL}
512
+            fetchUrl={data.url}
452 513
             renderItem={this.getRenderItem}
453 514
             renderSectionHeader={this.getRenderSectionHeader}
454 515
             autoRefreshTime={REFRESH_TIME}
455 516
             refreshOnFocus
456 517
             updateData={state.machinesWatched.length}
518
+            renderListHeaderComponent={this.getListHeader}
457 519
           />
458 520
         </View>
459 521
         <MascotPopup

Loading…
Cancel
Save