Browse Source

Improve constants to match linter

Arnaud Vergnet 1 year ago
parent
commit
7107a8eadf

+ 117
- 110
src/managers/AprilFoolsManager.js View File

@@ -1,130 +1,137 @@
1 1
 // @flow
2 2
 
3
-import type {Machine} from "../screens/Proxiwash/ProxiwashScreen";
3
+import type {ProxiwashMachineType} from '../screens/Proxiwash/ProxiwashScreen';
4
+import type {CustomThemeType} from './ThemeManager';
4 5
 
5 6
 /**
6 7
  * Singleton class used to manage april fools
7 8
  */
8 9
 export default class AprilFoolsManager {
10
+  static instance: AprilFoolsManager | null = null;
9 11
 
10
-    static instance: AprilFoolsManager | null = null;
11
-    static fakeMachineNumber = [
12
-        "",
13
-        "cos(ln(1))",
14
-        "0,5⁻¹",
15
-        "567/189",
16
-        "√2×√8",
17
-        "√50×sin(9π/4)",
18
-        "⌈π+e⌉",
19
-        "div(rot(B))+7",
20
-        "4×cosh(0)+4",
21
-        "8-(-i)²",
22
-        "|5√2+5√2i|",
23
-        "1×10¹+1×10⁰",
24
-        "Re(√192e^(iπ/6))",
25
-    ];
26
-    aprilFoolsEnabled: boolean;
12
+  static fakeMachineNumber = [
13
+    '',
14
+    'cos(ln(1))',
15
+    '0,5⁻¹',
16
+    '567/189',
17
+    '√2×√8',
18
+    '√50×sin(9π/4)',
19
+    '⌈π+e⌉',
20
+    'div(rot(B))+7',
21
+    '4×cosh(0)+4',
22
+    '8-(-i)²',
23
+    '|5√2+5√2i|',
24
+    '1×10¹+1×10⁰',
25
+    'Re(√192e^(iπ/6))',
26
+  ];
27 27
 
28
-    constructor() {
29
-        let today = new Date();
30
-        this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3);
31
-    }
28
+  aprilFoolsEnabled: boolean;
32 29
 
33
-    /**
34
-     * Get this class instance or create one if none is found
35
-     * @returns {ThemeManager}
36
-     */
37
-    static getInstance(): AprilFoolsManager {
38
-        return AprilFoolsManager.instance === null ?
39
-            AprilFoolsManager.instance = new AprilFoolsManager() :
40
-            AprilFoolsManager.instance;
41
-    }
30
+  constructor() {
31
+    const today = new Date();
32
+    this.aprilFoolsEnabled = today.getDate() === 1 && today.getMonth() === 3;
33
+  }
42 34
 
43
-    /**
44
-     * Adds fake menu entries
45
-     *
46
-     * @param menu
47
-     * @returns {Object}
48
-     */
49
-    static getFakeMenuItem(menu: Array<{dishes: Array<{name: string}>}>) {
50
-        menu[1]["dishes"].splice(4, 0, {name: "Coq au vin"});
51
-        menu[1]["dishes"].splice(2, 0, {name: "Bat'Soupe"});
52
-        menu[1]["dishes"].splice(1, 0, {name: "Pave de loup"});
53
-        menu[1]["dishes"].splice(0, 0, {name: "Béranger à point"});
54
-        menu[1]["dishes"].splice(0, 0, {name: "Pieds d'Arnaud"});
55
-        return menu;
56
-    }
35
+  /**
36
+   * Get this class instance or create one if none is found
37
+   * @returns {ThemeManager}
38
+   */
39
+  static getInstance(): AprilFoolsManager {
40
+    if (AprilFoolsManager.instance == null)
41
+      AprilFoolsManager.instance = new AprilFoolsManager();
42
+    return AprilFoolsManager.instance;
43
+  }
57 44
 
58
-    /**
59
-     * Changes proxiwash dryers order
60
-     *
61
-     * @param dryers
62
-     */
63
-    static getNewProxiwashDryerOrderedList(dryers: Array<Machine> | null) {
64
-        if (dryers != null) {
65
-            let second = dryers[1];
66
-            dryers.splice(1, 1);
67
-            dryers.push(second);
68
-        }
69
-    }
45
+  /**
46
+   * Adds fake menu entries
47
+   *
48
+   * @param menu
49
+   * @returns {Object}
50
+   */
51
+  static getFakeMenuItem(
52
+    menu: Array<{dishes: Array<{name: string}>}>,
53
+  ): Array<{dishes: Array<{name: string}>}> {
54
+    menu[1].dishes.splice(4, 0, {name: 'Coq au vin'});
55
+    menu[1].dishes.splice(2, 0, {name: "Bat'Soupe"});
56
+    menu[1].dishes.splice(1, 0, {name: 'Pave de loup'});
57
+    menu[1].dishes.splice(0, 0, {name: 'Béranger à point'});
58
+    menu[1].dishes.splice(0, 0, {name: "Pieds d'Arnaud"});
59
+    return menu;
60
+  }
70 61
 
71
-    /**
72
-     * Changes proxiwash washers order
73
-     *
74
-     * @param washers
75
-     */
76
-    static getNewProxiwashWasherOrderedList(washers: Array<Machine> | null) {
77
-        if (washers != null) {
78
-            let first = washers[0];
79
-            let second = washers[1];
80
-            let fifth = washers[4];
81
-            let ninth = washers[8];
82
-            washers.splice(8, 1, second);
83
-            washers.splice(4, 1, ninth);
84
-            washers.splice(1, 1, first);
85
-            washers.splice(0, 1, fifth);
86
-        }
62
+  /**
63
+   * Changes proxiwash dryers order
64
+   *
65
+   * @param dryers
66
+   */
67
+  static getNewProxiwashDryerOrderedList(
68
+    dryers: Array<ProxiwashMachineType> | null,
69
+  ) {
70
+    if (dryers != null) {
71
+      const second = dryers[1];
72
+      dryers.splice(1, 1);
73
+      dryers.push(second);
87 74
     }
75
+  }
88 76
 
89
-    /**
90
-     * Gets the new display number for the given machine number
91
-     *
92
-     * @param number
93
-     * @returns {string}
94
-     */
95
-    static getProxiwashMachineDisplayNumber(number: number) {
96
-        return AprilFoolsManager.fakeMachineNumber[number];
77
+  /**
78
+   * Changes proxiwash washers order
79
+   *
80
+   * @param washers
81
+   */
82
+  static getNewProxiwashWasherOrderedList(
83
+    washers: Array<ProxiwashMachineType> | null,
84
+  ) {
85
+    if (washers != null) {
86
+      const first = washers[0];
87
+      const second = washers[1];
88
+      const fifth = washers[4];
89
+      const ninth = washers[8];
90
+      washers.splice(8, 1, second);
91
+      washers.splice(4, 1, ninth);
92
+      washers.splice(1, 1, first);
93
+      washers.splice(0, 1, fifth);
97 94
     }
95
+  }
98 96
 
99
-    /**
100
-     * Gets the new and ugly april fools theme
101
-     *
102
-     * @param currentTheme
103
-     * @returns {{colors: {textDisabled: string, agendaDayTextColor: string, surface: string, background: string, dividerBackground: string, accent: string, agendaBackgroundColor: string, tabIcon: string, card: string, primary: string}}}
104
-     */
105
-    static getAprilFoolsTheme(currentTheme: Object) {
106
-        return {
107
-            ...currentTheme,
108
-            colors: {
109
-                ...currentTheme.colors,
110
-                primary: '#00be45',
111
-                accent: '#00be45',
112
-                background: '#d02eee',
113
-                tabIcon: "#380d43",
114
-                card: "#eed639",
115
-                surface: "#eed639",
116
-                dividerBackground: '#c72ce4',
117
-                textDisabled: '#b9b9b9',
97
+  /**
98
+   * Gets the new display number for the given machine number
99
+   *
100
+   * @param number
101
+   * @returns {string}
102
+   */
103
+  static getProxiwashMachineDisplayNumber(number: number): string {
104
+    return AprilFoolsManager.fakeMachineNumber[number];
105
+  }
118 106
 
119
-                // Calendar/Agenda
120
-                agendaBackgroundColor: '#c72ce4',
121
-                agendaDayTextColor: '#6d6d6d',
122
-            },
123
-        };
124
-    }
107
+  /**
108
+   * Gets the new and ugly april fools theme
109
+   *
110
+   * @param currentTheme
111
+   * @returns {{colors: {textDisabled: string, agendaDayTextColor: string, surface: string, background: string, dividerBackground: string, accent: string, agendaBackgroundColor: string, tabIcon: string, card: string, primary: string}}}
112
+   */
113
+  static getAprilFoolsTheme(currentTheme: CustomThemeType): CustomThemeType {
114
+    return {
115
+      ...currentTheme,
116
+      colors: {
117
+        ...currentTheme.colors,
118
+        primary: '#00be45',
119
+        accent: '#00be45',
120
+        background: '#d02eee',
121
+        tabIcon: '#380d43',
122
+        card: '#eed639',
123
+        surface: '#eed639',
124
+        dividerBackground: '#c72ce4',
125
+        textDisabled: '#b9b9b9',
125 126
 
126
-    isAprilFoolsEnabled() {
127
-        return this.aprilFoolsEnabled;
128
-    }
127
+        // Calendar/Agenda
128
+        agendaBackgroundColor: '#c72ce4',
129
+        agendaDayTextColor: '#6d6d6d',
130
+      },
131
+    };
132
+  }
129 133
 
130
-};
134
+  isAprilFoolsEnabled(): boolean {
135
+    return this.aprilFoolsEnabled;
136
+  }
137
+}

+ 219
- 223
src/managers/AsyncStorageManager.js View File

@@ -1,7 +1,7 @@
1 1
 // @flow
2 2
 
3 3
 import AsyncStorage from '@react-native-community/async-storage';
4
-import {SERVICES_KEY} from "./ServicesManager";
4
+import {SERVICES_KEY} from './ServicesManager';
5 5
 
6 6
 /**
7 7
  * Singleton used to manage preferences.
@@ -10,227 +10,223 @@ import {SERVICES_KEY} from "./ServicesManager";
10 10
  */
11 11
 
12 12
 export default class AsyncStorageManager {
13
-
14
-    static instance: AsyncStorageManager | null = null;
15
-
16
-    static PREFERENCES = {
17
-        debugUnlocked: {
18
-            key: 'debugUnlocked',
19
-            default: '0',
20
-        },
21
-        showIntro: {
22
-            key: 'showIntro',
23
-            default: '1',
24
-        },
25
-        updateNumber: {
26
-            key: 'updateNumber',
27
-            default: '0',
28
-        },
29
-        proxiwashNotifications: {
30
-            key: 'proxiwashNotifications',
31
-            default: '5',
32
-        },
33
-        nightModeFollowSystem: {
34
-            key: 'nightModeFollowSystem',
35
-            default: '1',
36
-        },
37
-        nightMode: {
38
-            key: 'nightMode',
39
-            default: '1',
40
-        },
41
-        defaultStartScreen: {
42
-            key: 'defaultStartScreen',
43
-            default: 'home',
44
-        },
45
-        servicesShowBanner: {
46
-            key: 'servicesShowBanner',
47
-            default: '1',
48
-        },
49
-        proxiwashShowBanner: {
50
-            key: 'proxiwashShowBanner',
51
-            default: '1',
52
-        },
53
-        homeShowBanner: {
54
-            key: 'homeShowBanner',
55
-            default: '1',
56
-        },
57
-        eventsShowBanner: {
58
-            key: 'eventsShowBanner',
59
-            default: '1',
60
-        },
61
-        planexShowBanner: {
62
-            key: 'planexShowBanner',
63
-            default: '1',
64
-        },
65
-        loginShowBanner: {
66
-            key: 'loginShowBanner',
67
-            default: '1',
68
-        },
69
-        voteShowBanner: {
70
-            key: 'voteShowBanner',
71
-            default: '1',
72
-        },
73
-        equipmentShowBanner: {
74
-            key: 'equipmentShowBanner',
75
-            default: '1',
76
-        },
77
-        gameStartShowBanner: {
78
-            key: 'gameStartShowBanner',
79
-            default: '1',
80
-        },
81
-        proxiwashWatchedMachines: {
82
-            key: 'proxiwashWatchedMachines',
83
-            default: '[]',
84
-        },
85
-        showAprilFoolsStart: {
86
-            key: 'showAprilFoolsStart',
87
-            default: '1',
88
-        },
89
-        planexCurrentGroup: {
90
-            key: 'planexCurrentGroup',
91
-            default: '',
92
-        },
93
-        planexFavoriteGroups: {
94
-            key: 'planexFavoriteGroups',
95
-            default: '[]',
96
-        },
97
-        dashboardItems: {
98
-            key: 'dashboardItems',
99
-            default: JSON.stringify([
100
-                SERVICES_KEY.EMAIL,
101
-                SERVICES_KEY.WASHERS,
102
-                SERVICES_KEY.PROXIMO,
103
-                SERVICES_KEY.TUTOR_INSA,
104
-                SERVICES_KEY.RU,
105
-            ]),
106
-        },
107
-        gameScores: {
108
-            key: 'gameScores',
109
-            default: '[]',
110
-        },
111
-    }
112
-
113
-    #currentPreferences: {[key: string]: string};
114
-
115
-    constructor() {
116
-        this.#currentPreferences = {};
117
-    }
118
-
119
-    /**
120
-     * Get this class instance or create one if none is found
121
-     * @returns {AsyncStorageManager}
122
-     */
123
-    static getInstance(): AsyncStorageManager {
124
-        return AsyncStorageManager.instance === null ?
125
-            AsyncStorageManager.instance = new AsyncStorageManager() :
126
-            AsyncStorageManager.instance;
127
-    }
128
-
129
-    /**
130
-     * Set preferences object current values from AsyncStorage.
131
-     * This function should be called at the app's start.
132
-     *
133
-     * @return {Promise<void>}
134
-     */
135
-    async loadPreferences() {
136
-        let prefKeys = [];
137
-        // Get all available keys
138
-        for (let key in AsyncStorageManager.PREFERENCES) {
139
-            prefKeys.push(key);
140
-        }
141
-        // Get corresponding values
142
-        let resultArray: Array<Array<string>> = await AsyncStorage.multiGet(prefKeys);
143
-        // Save those values for later use
144
-        for (let i = 0; i < resultArray.length; i++) {
145
-            let key: string = resultArray[i][0];
146
-            let val: string | null = resultArray[i][1];
147
-            if (val === null)
148
-                val = AsyncStorageManager.PREFERENCES[key].default;
149
-            this.#currentPreferences[key] = val;
150
-        }
151
-    }
152
-
153
-    /**
154
-     * Saves the value associated to the given key to preferences.
155
-     * This updates the preferences object and saves it to AsyncStorage.
156
-     *
157
-     * @param key
158
-     * @param value
159
-     */
160
-    setPreference(key: string, value: any) {
161
-        if (AsyncStorageManager.PREFERENCES[key] != null) {
162
-            let convertedValue = "";
163
-            if (typeof value === "string")
164
-                convertedValue = value;
165
-            else if (typeof value === "boolean" || typeof value === "number")
166
-                convertedValue = value.toString();
167
-            else
168
-                convertedValue = JSON.stringify(value);
169
-            this.#currentPreferences[key] = convertedValue;
170
-            AsyncStorage.setItem(key, convertedValue);
171
-        }
172
-    }
173
-
174
-    /**
175
-     * Gets the value at the given key.
176
-     * If the key is not available, returns null
177
-     *
178
-     * @param key
179
-     * @returns {string|null}
180
-     */
181
-    getPreference(key: string) {
182
-        return this.#currentPreferences[key];
183
-    }
184
-
185
-    /**
186
-     * aves the value associated to the given key to preferences.
187
-     *
188
-     * @param key
189
-     * @param value
190
-     */
191
-    static set(key: string, value: any) {
192
-        AsyncStorageManager.getInstance().setPreference(key, value);
193
-    }
194
-
195
-    /**
196
-     * Gets the string value of the given preference
197
-     *
198
-     * @param key
199
-     * @returns {boolean}
200
-     */
201
-    static getString(key: string) {
202
-        return AsyncStorageManager.getInstance().getPreference(key);
203
-    }
204
-
205
-    /**
206
-     * Gets the boolean value of the given preference
207
-     *
208
-     * @param key
209
-     * @returns {boolean}
210
-     */
211
-    static getBool(key: string) {
212
-        const value = AsyncStorageManager.getString(key);
213
-        return value === "1" || value === "true";
214
-    }
215
-
216
-    /**
217
-     * Gets the number value of the given preference
218
-     *
219
-     * @param key
220
-     * @returns {boolean}
221
-     */
222
-    static getNumber(key: string) {
223
-        return parseFloat(AsyncStorageManager.getString(key));
13
+  static instance: AsyncStorageManager | null = null;
14
+
15
+  static PREFERENCES = {
16
+    debugUnlocked: {
17
+      key: 'debugUnlocked',
18
+      default: '0',
19
+    },
20
+    showIntro: {
21
+      key: 'showIntro',
22
+      default: '1',
23
+    },
24
+    updateNumber: {
25
+      key: 'updateNumber',
26
+      default: '0',
27
+    },
28
+    proxiwashNotifications: {
29
+      key: 'proxiwashNotifications',
30
+      default: '5',
31
+    },
32
+    nightModeFollowSystem: {
33
+      key: 'nightModeFollowSystem',
34
+      default: '1',
35
+    },
36
+    nightMode: {
37
+      key: 'nightMode',
38
+      default: '1',
39
+    },
40
+    defaultStartScreen: {
41
+      key: 'defaultStartScreen',
42
+      default: 'home',
43
+    },
44
+    servicesShowBanner: {
45
+      key: 'servicesShowBanner',
46
+      default: '1',
47
+    },
48
+    proxiwashShowBanner: {
49
+      key: 'proxiwashShowBanner',
50
+      default: '1',
51
+    },
52
+    homeShowBanner: {
53
+      key: 'homeShowBanner',
54
+      default: '1',
55
+    },
56
+    eventsShowBanner: {
57
+      key: 'eventsShowBanner',
58
+      default: '1',
59
+    },
60
+    planexShowBanner: {
61
+      key: 'planexShowBanner',
62
+      default: '1',
63
+    },
64
+    loginShowBanner: {
65
+      key: 'loginShowBanner',
66
+      default: '1',
67
+    },
68
+    voteShowBanner: {
69
+      key: 'voteShowBanner',
70
+      default: '1',
71
+    },
72
+    equipmentShowBanner: {
73
+      key: 'equipmentShowBanner',
74
+      default: '1',
75
+    },
76
+    gameStartShowBanner: {
77
+      key: 'gameStartShowBanner',
78
+      default: '1',
79
+    },
80
+    proxiwashWatchedMachines: {
81
+      key: 'proxiwashWatchedMachines',
82
+      default: '[]',
83
+    },
84
+    showAprilFoolsStart: {
85
+      key: 'showAprilFoolsStart',
86
+      default: '1',
87
+    },
88
+    planexCurrentGroup: {
89
+      key: 'planexCurrentGroup',
90
+      default: '',
91
+    },
92
+    planexFavoriteGroups: {
93
+      key: 'planexFavoriteGroups',
94
+      default: '[]',
95
+    },
96
+    dashboardItems: {
97
+      key: 'dashboardItems',
98
+      default: JSON.stringify([
99
+        SERVICES_KEY.EMAIL,
100
+        SERVICES_KEY.WASHERS,
101
+        SERVICES_KEY.PROXIMO,
102
+        SERVICES_KEY.TUTOR_INSA,
103
+        SERVICES_KEY.RU,
104
+      ]),
105
+    },
106
+    gameScores: {
107
+      key: 'gameScores',
108
+      default: '[]',
109
+    },
110
+  };
111
+
112
+  #currentPreferences: {[key: string]: string};
113
+
114
+  constructor() {
115
+    this.#currentPreferences = {};
116
+  }
117
+
118
+  /**
119
+   * Get this class instance or create one if none is found
120
+   * @returns {AsyncStorageManager}
121
+   */
122
+  static getInstance(): AsyncStorageManager {
123
+    if (AsyncStorageManager.instance == null)
124
+      AsyncStorageManager.instance = new AsyncStorageManager();
125
+    return AsyncStorageManager.instance;
126
+  }
127
+
128
+  /**
129
+   * Saves the value associated to the given key to preferences.
130
+   *
131
+   * @param key
132
+   * @param value
133
+   */
134
+  static set(key: string, value: number | string | boolean | {...} | []) {
135
+    AsyncStorageManager.getInstance().setPreference(key, value);
136
+  }
137
+
138
+  /**
139
+   * Gets the string value of the given preference
140
+   *
141
+   * @param key
142
+   * @returns {string}
143
+   */
144
+  static getString(key: string): string {
145
+    return AsyncStorageManager.getInstance().getPreference(key);
146
+  }
147
+
148
+  /**
149
+   * Gets the boolean value of the given preference
150
+   *
151
+   * @param key
152
+   * @returns {boolean}
153
+   */
154
+  static getBool(key: string): boolean {
155
+    const value = AsyncStorageManager.getString(key);
156
+    return value === '1' || value === 'true';
157
+  }
158
+
159
+  /**
160
+   * Gets the number value of the given preference
161
+   *
162
+   * @param key
163
+   * @returns {number}
164
+   */
165
+  static getNumber(key: string): number {
166
+    return parseFloat(AsyncStorageManager.getString(key));
167
+  }
168
+
169
+  /**
170
+   * Gets the object value of the given preference
171
+   *
172
+   * @param key
173
+   * @returns {{...}}
174
+   */
175
+  // eslint-disable-next-line flowtype/no-weak-types
176
+  static getObject(key: string): any {
177
+    return JSON.parse(AsyncStorageManager.getString(key));
178
+  }
179
+
180
+  /**
181
+   * Set preferences object current values from AsyncStorage.
182
+   * This function should be called at the app's start.
183
+   *
184
+   * @return {Promise<void>}
185
+   */
186
+  async loadPreferences() {
187
+    const prefKeys = [];
188
+    // Get all available keys
189
+    Object.keys(AsyncStorageManager.PREFERENCES).forEach((key: string) => {
190
+      prefKeys.push(key);
191
+    });
192
+    // Get corresponding values
193
+    const resultArray = await AsyncStorage.multiGet(prefKeys);
194
+    // Save those values for later use
195
+    resultArray.forEach((item: [string, string | null]) => {
196
+      const key = item[0];
197
+      let val = item[1];
198
+      if (val === null) val = AsyncStorageManager.PREFERENCES[key].default;
199
+      this.#currentPreferences[key] = val;
200
+    });
201
+  }
202
+
203
+  /**
204
+   * Saves the value associated to the given key to preferences.
205
+   * This updates the preferences object and saves it to AsyncStorage.
206
+   *
207
+   * @param key
208
+   * @param value
209
+   */
210
+  setPreference(key: string, value: number | string | boolean | {...} | []) {
211
+    if (AsyncStorageManager.PREFERENCES[key] != null) {
212
+      let convertedValue;
213
+      if (typeof value === 'string') convertedValue = value;
214
+      else if (typeof value === 'boolean' || typeof value === 'number')
215
+        convertedValue = value.toString();
216
+      else convertedValue = JSON.stringify(value);
217
+      this.#currentPreferences[key] = convertedValue;
218
+      AsyncStorage.setItem(key, convertedValue);
224 219
     }
225
-
226
-    /**
227
-     * Gets the object value of the given preference
228
-     *
229
-     * @param key
230
-     * @returns {boolean}
231
-     */
232
-    static getObject(key: string) {
233
-        return JSON.parse(AsyncStorageManager.getString(key));
234
-    }
235
-
220
+  }
221
+
222
+  /**
223
+   * Gets the value at the given key.
224
+   * If the key is not available, returns null
225
+   *
226
+   * @param key
227
+   * @returns {string|null}
228
+   */
229
+  getPreference(key: string): string | null {
230
+    return this.#currentPreferences[key];
231
+  }
236 232
 }

+ 56
- 51
src/managers/DateManager.js View File

@@ -7,63 +7,68 @@ import i18n from 'i18n-js';
7 7
  * Translations are hardcoded as toLocaleDateString does not work on current android JS engine
8 8
  */
9 9
 export default class DateManager {
10
-    static instance: DateManager | null = null;
10
+  static instance: DateManager | null = null;
11 11
 
12
-    daysOfWeek = [];
13
-    monthsOfYear = [];
12
+  daysOfWeek = [];
14 13
 
15
-    constructor() {
16
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.sunday")); // 0 represents sunday
17
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.monday"));
18
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.tuesday"));
19
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.wednesday"));
20
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.thursday"));
21
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.friday"));
22
-        this.daysOfWeek.push(i18n.t("date.daysOfWeek.saturday"));
14
+  monthsOfYear = [];
23 15
 
24
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.january"));
25
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.february"));
26
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.march"));
27
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.april"));
28
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.may"));
29
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.june"));
30
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.july"));
31
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.august"));
32
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.september"));
33
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.october"));
34
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.november"));
35
-        this.monthsOfYear.push(i18n.t("date.monthsOfYear.december"));
36
-    }
16
+  constructor() {
17
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.sunday')); // 0 represents sunday
18
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.monday'));
19
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.tuesday'));
20
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.wednesday'));
21
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.thursday'));
22
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.friday'));
23
+    this.daysOfWeek.push(i18n.t('date.daysOfWeek.saturday'));
37 24
 
38
-    /**
39
-     * Get this class instance or create one if none is found
40
-     * @returns {DateManager}
41
-     */
42
-    static getInstance(): DateManager {
43
-        return DateManager.instance === null ?
44
-            DateManager.instance = new DateManager() :
45
-            DateManager.instance;
46
-    }
25
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.january'));
26
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.february'));
27
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.march'));
28
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.april'));
29
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.may'));
30
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.june'));
31
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.july'));
32
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.august'));
33
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.september'));
34
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.october'));
35
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.november'));
36
+    this.monthsOfYear.push(i18n.t('date.monthsOfYear.december'));
37
+  }
47 38
 
48
-    static isWeekend(date: Date) {
49
-        return date.getDay() === 6 || date.getDay() === 0;
50
-    }
39
+  /**
40
+   * Get this class instance or create one if none is found
41
+   * @returns {DateManager}
42
+   */
43
+  static getInstance(): DateManager {
44
+    if (DateManager.instance == null) DateManager.instance = new DateManager();
45
+    return DateManager.instance;
46
+  }
51 47
 
52
-    getMonthsOfYear() {
53
-        return this.monthsOfYear;
54
-    }
48
+  static isWeekend(date: Date): boolean {
49
+    return date.getDay() === 6 || date.getDay() === 0;
50
+  }
55 51
 
56
-    /**
57
-     * Gets a translated string representing the given date.
58
-     *
59
-     * @param dateString The date with the format YYYY-MM-DD
60
-     * @return {string} The translated string
61
-     */
62
-    getTranslatedDate(dateString: string) {
63
-        let dateArray = dateString.split('-');
64
-        let date = new Date();
65
-        date.setFullYear(parseInt(dateArray[0]), parseInt(dateArray[1]) - 1, parseInt(dateArray[2]));
66
-        return this.daysOfWeek[date.getDay()] + " " + date.getDate() + " " + this.monthsOfYear[date.getMonth()] + " " + date.getFullYear();
67
-    }
52
+  getMonthsOfYear(): Array<string> {
53
+    return this.monthsOfYear;
54
+  }
68 55
 
56
+  /**
57
+   * Gets a translated string representing the given date.
58
+   *
59
+   * @param dateString The date with the format YYYY-MM-DD
60
+   * @return {string} The translated string
61
+   */
62
+  getTranslatedDate(dateString: string): string {
63
+    const dateArray = dateString.split('-');
64
+    const date = new Date();
65
+    date.setFullYear(
66
+      parseInt(dateArray[0], 10),
67
+      parseInt(dateArray[1], 10) - 1,
68
+      parseInt(dateArray[2], 10),
69
+    );
70
+    return `${this.daysOfWeek[date.getDay()]} ${date.getDate()} ${
71
+      this.monthsOfYear[date.getMonth()]
72
+    } ${date.getFullYear()}`;
73
+  }
69 74
 }

+ 13
- 11
src/managers/LocaleManager.js View File

@@ -1,22 +1,24 @@
1 1
 // @flow
2 2
 
3 3
 import i18n from 'i18n-js';
4
-import * as RNLocalize from "react-native-localize";
4
+import * as RNLocalize from 'react-native-localize';
5 5
 
6
-import en from '../../locales/en';
6
+import en from '../../locales/en.json';
7 7
 import fr from '../../locales/fr.json';
8 8
 
9 9
 /**
10 10
  * Static class used to manage locales
11 11
  */
12 12
 export default class LocaleManager {
13
-
14
-    /**
15
-     * Initialize translations using language files
16
-     */
17
-    static initTranslations() {
18
-        i18n.fallbacks = true;
19
-        i18n.translations = {fr, en};
20
-        i18n.locale = RNLocalize.findBestAvailableLanguage(["en", "fr"]).languageTag;
21
-    }
13
+  /**
14
+   * Initialize translations using language files
15
+   */
16
+  static initTranslations() {
17
+    i18n.fallbacks = true;
18
+    i18n.translations = {fr, en};
19
+    i18n.locale = RNLocalize.findBestAvailableLanguage([
20
+      'en',
21
+      'fr',
22
+    ]).languageTag;
23
+  }
22 24
 }

+ 268
- 262
src/managers/ThemeManager.js View File

@@ -1,282 +1,288 @@
1 1
 // @flow
2 2
 
3
-import AsyncStorageManager from "./AsyncStorageManager";
4 3
 import {DarkTheme, DefaultTheme} from 'react-native-paper';
5
-import AprilFoolsManager from "./AprilFoolsManager";
6 4
 import {Appearance} from 'react-native-appearance';
5
+import AsyncStorageManager from './AsyncStorageManager';
6
+import AprilFoolsManager from './AprilFoolsManager';
7 7
 
8 8
 const colorScheme = Appearance.getColorScheme();
9 9
 
10
-export type CustomTheme = {
11
-    ...DefaultTheme,
12
-    colors: {
13
-        primary: string,
14
-        accent: string,
15
-        tabIcon: string,
16
-        card: string,
17
-        dividerBackground: string,
18
-        ripple: string,
19
-        textDisabled: string,
20
-        icon: string,
21
-        subtitle: string,
22
-        success: string,
23
-        warning: string,
24
-        danger: string,
10
+export type CustomThemeType = {
11
+  ...DefaultTheme,
12
+  colors: {
13
+    primary: string,
14
+    accent: string,
15
+    tabIcon: string,
16
+    card: string,
17
+    dividerBackground: string,
18
+    ripple: string,
19
+    textDisabled: string,
20
+    icon: string,
21
+    subtitle: string,
22
+    success: string,
23
+    warning: string,
24
+    danger: string,
25
+
26
+    // Calendar/Agenda
27
+    agendaBackgroundColor: string,
28
+    agendaDayTextColor: string,
29
+
30
+    // PROXIWASH
31
+    proxiwashFinishedColor: string,
32
+    proxiwashReadyColor: string,
33
+    proxiwashRunningColor: string,
34
+    proxiwashRunningNotStartedColor: string,
35
+    proxiwashRunningBgColor: string,
36
+    proxiwashBrokenColor: string,
37
+    proxiwashErrorColor: string,
38
+    proxiwashUnknownColor: string,
39
+
40
+    // Screens
41
+    planningColor: string,
42
+    proximoColor: string,
43
+    proxiwashColor: string,
44
+    menuColor: string,
45
+    tutorinsaColor: string,
46
+
47
+    // Tetris
48
+    tetrisBackground: string,
49
+    tetrisBorder: string,
50
+    tetrisScore: string,
51
+    tetrisI: string,
52
+    tetrisO: string,
53
+    tetrisT: string,
54
+    tetrisS: string,
55
+    tetrisZ: string,
56
+    tetrisJ: string,
57
+    tetrisL: string,
58
+
59
+    gameGold: string,
60
+    gameSilver: string,
61
+    gameBronze: string,
62
+
63
+    // Mascot Popup
64
+    mascotMessageArrow: string,
65
+  },
66
+};
67
+
68
+/**
69
+ * Singleton class used to manage themes
70
+ */
71
+export default class ThemeManager {
72
+  static instance: ThemeManager | null = null;
73
+
74
+  updateThemeCallback: null | (() => void);
75
+
76
+  constructor() {
77
+    this.updateThemeCallback = null;
78
+  }
79
+
80
+  /**
81
+   * Gets the light theme
82
+   *
83
+   * @return {CustomThemeType} Object containing theme variables
84
+   * */
85
+  static getWhiteTheme(): CustomThemeType {
86
+    return {
87
+      ...DefaultTheme,
88
+      colors: {
89
+        ...DefaultTheme.colors,
90
+        primary: '#be1522',
91
+        accent: '#be1522',
92
+        tabIcon: '#929292',
93
+        card: '#fff',
94
+        dividerBackground: '#e2e2e2',
95
+        ripple: 'rgba(0,0,0,0.2)',
96
+        textDisabled: '#c1c1c1',
97
+        icon: '#5d5d5d',
98
+        subtitle: '#707070',
99
+        success: '#5cb85c',
100
+        warning: '#f0ad4e',
101
+        danger: '#d9534f',
102
+        cc: 'dst',
25 103
 
26 104
         // Calendar/Agenda
27
-        agendaBackgroundColor: string,
28
-        agendaDayTextColor: string,
105
+        agendaBackgroundColor: '#f3f3f4',
106
+        agendaDayTextColor: '#636363',
29 107
 
30 108
         // PROXIWASH
31
-        proxiwashFinishedColor: string,
32
-        proxiwashReadyColor: string,
33
-        proxiwashRunningColor: string,
34
-        proxiwashRunningNotStartedColor: string,
35
-        proxiwashRunningBgColor: string,
36
-        proxiwashBrokenColor: string,
37
-        proxiwashErrorColor: string,
38
-        proxiwashUnknownColor: string,
109
+        proxiwashFinishedColor: '#a5dc9d',
110
+        proxiwashReadyColor: 'transparent',
111
+        proxiwashRunningColor: '#a0ceff',
112
+        proxiwashRunningNotStartedColor: '#c9e0ff',
113
+        proxiwashRunningBgColor: '#c7e3ff',
114
+        proxiwashBrokenColor: '#ffa8a2',
115
+        proxiwashErrorColor: '#ffa8a2',
116
+        proxiwashUnknownColor: '#b6b6b6',
39 117
 
40 118
         // Screens
41
-        planningColor: string,
42
-        proximoColor: string,
43
-        proxiwashColor: string,
44
-        menuColor: string,
45
-        tutorinsaColor: string,
119
+        planningColor: '#d9b10a',
120
+        proximoColor: '#ec5904',
121
+        proxiwashColor: '#1fa5ee',
122
+        menuColor: '#e91314',
123
+        tutorinsaColor: '#f93943',
46 124
 
47 125
         // Tetris
48
-        tetrisBackground: string,
49
-        tetrisBorder: string,
50
-        tetrisScore: string,
51
-        tetrisI: string,
52
-        tetrisO: string,
53
-        tetrisT: string,
54
-        tetrisS: string,
55
-        tetrisZ: string,
56
-        tetrisJ: string,
57
-        tetrisL: string,
58
-
59
-        gameGold: string,
60
-        gameSilver: string,
61
-        gameBronze: string,
126
+        tetrisBackground: '#f0f0f0',
127
+        tetrisScore: '#e2bd33',
128
+        tetrisI: '#3cd9e6',
129
+        tetrisO: '#ffdd00',
130
+        tetrisT: '#a716e5',
131
+        tetrisS: '#09c528',
132
+        tetrisZ: '#ff0009',
133
+        tetrisJ: '#2a67e3',
134
+        tetrisL: '#da742d',
135
+
136
+        gameGold: '#ffd610',
137
+        gameSilver: '#7b7b7b',
138
+        gameBronze: '#a15218',
62 139
 
63 140
         // Mascot Popup
64
-        mascotMessageArrow: string,
65
-    },
66
-}
141
+        mascotMessageArrow: '#dedede',
142
+      },
143
+    };
144
+  }
145
+
146
+  /**
147
+   * Gets the dark theme
148
+   *
149
+   * @return {CustomThemeType} Object containing theme variables
150
+   * */
151
+  static getDarkTheme(): CustomThemeType {
152
+    return {
153
+      ...DarkTheme,
154
+      colors: {
155
+        ...DarkTheme.colors,
156
+        primary: '#be1522',
157
+        accent: '#be1522',
158
+        tabBackground: '#181818',
159
+        tabIcon: '#6d6d6d',
160
+        card: 'rgb(18,18,18)',
161
+        dividerBackground: '#222222',
162
+        ripple: 'rgba(255,255,255,0.2)',
163
+        textDisabled: '#5b5b5b',
164
+        icon: '#b3b3b3',
165
+        subtitle: '#aaaaaa',
166
+        success: '#5cb85c',
167
+        warning: '#f0ad4e',
168
+        danger: '#d9534f',
67 169
 
68
-/**
69
- * Singleton class used to manage themes
70
- */
71
-export default class ThemeManager {
170
+        // Calendar/Agenda
171
+        agendaBackgroundColor: '#171717',
172
+        agendaDayTextColor: '#6d6d6d',
72 173
 
73
-    static instance: ThemeManager | null = null;
74
-    updateThemeCallback: Function;
75
-
76
-    constructor() {
77
-        this.updateThemeCallback = null;
78
-    }
79
-
80
-    /**
81
-     * Gets the light theme
82
-     *
83
-     * @return {CustomTheme} Object containing theme variables
84
-     * */
85
-    static getWhiteTheme(): CustomTheme {
86
-        return {
87
-            ...DefaultTheme,
88
-            colors: {
89
-                ...DefaultTheme.colors,
90
-                primary: '#be1522',
91
-                accent: '#be1522',
92
-                tabIcon: "#929292",
93
-                card: "#fff",
94
-                dividerBackground: '#e2e2e2',
95
-                ripple: "rgba(0,0,0,0.2)",
96
-                textDisabled: '#c1c1c1',
97
-                icon: '#5d5d5d',
98
-                subtitle: '#707070',
99
-                success: "#5cb85c",
100
-                warning: "#f0ad4e",
101
-                danger: "#d9534f",
102
-                cc: 'dst',
103
-
104
-                // Calendar/Agenda
105
-                agendaBackgroundColor: '#f3f3f4',
106
-                agendaDayTextColor: '#636363',
107
-
108
-                // PROXIWASH
109
-                proxiwashFinishedColor: "#a5dc9d",
110
-                proxiwashReadyColor: "transparent",
111
-                proxiwashRunningColor: "#a0ceff",
112
-                proxiwashRunningNotStartedColor: "#c9e0ff",
113
-                proxiwashRunningBgColor: "#c7e3ff",
114
-                proxiwashBrokenColor: "#ffa8a2",
115
-                proxiwashErrorColor: "#ffa8a2",
116
-                proxiwashUnknownColor: "#b6b6b6",
117
-
118
-                // Screens
119
-                planningColor: '#d9b10a',
120
-                proximoColor: '#ec5904',
121
-                proxiwashColor: '#1fa5ee',
122
-                menuColor: '#e91314',
123
-                tutorinsaColor: '#f93943',
124
-
125
-                // Tetris
126
-                tetrisBackground: '#f0f0f0',
127
-                tetrisScore: '#e2bd33',
128
-                tetrisI: '#3cd9e6',
129
-                tetrisO: '#ffdd00',
130
-                tetrisT: '#a716e5',
131
-                tetrisS: '#09c528',
132
-                tetrisZ: '#ff0009',
133
-                tetrisJ: '#2a67e3',
134
-                tetrisL: '#da742d',
135
-
136
-                gameGold: "#ffd610",
137
-                gameSilver: "#7b7b7b",
138
-                gameBronze: "#a15218",
139
-
140
-                // Mascot Popup
141
-                mascotMessageArrow: "#dedede",
142
-            },
143
-        };
144
-    }
145
-
146
-    /**
147
-     * Gets the dark theme
148
-     *
149
-     * @return {CustomTheme} Object containing theme variables
150
-     * */
151
-    static getDarkTheme(): CustomTheme {
152
-        return {
153
-            ...DarkTheme,
154
-            colors: {
155
-                ...DarkTheme.colors,
156
-                primary: '#be1522',
157
-                accent: '#be1522',
158
-                tabBackground: "#181818",
159
-                tabIcon: "#6d6d6d",
160
-                card: "rgb(18,18,18)",
161
-                dividerBackground: '#222222',
162
-                ripple: "rgba(255,255,255,0.2)",
163
-                textDisabled: '#5b5b5b',
164
-                icon: '#b3b3b3',
165
-                subtitle: '#aaaaaa',
166
-                success: "#5cb85c",
167
-                warning: "#f0ad4e",
168
-                danger: "#d9534f",
169
-
170
-                // Calendar/Agenda
171
-                agendaBackgroundColor: '#171717',
172
-                agendaDayTextColor: '#6d6d6d',
173
-
174
-                // PROXIWASH
175
-                proxiwashFinishedColor: "#31682c",
176
-                proxiwashReadyColor: "transparent",
177
-                proxiwashRunningColor: "#213c79",
178
-                proxiwashRunningNotStartedColor: "#1e263e",
179
-                proxiwashRunningBgColor: "#1a2033",
180
-                proxiwashBrokenColor: "#7e2e2f",
181
-                proxiwashErrorColor: "#7e2e2f",
182
-                proxiwashUnknownColor: "#535353",
183
-
184
-                // Screens
185
-                planningColor: '#d99e09',
186
-                proximoColor: '#ec5904',
187
-                proxiwashColor: '#1fa5ee',
188
-                menuColor: '#b81213',
189
-                tutorinsaColor: '#f93943',
190
-
191
-                // Tetris
192
-                tetrisBackground: '#181818',
193
-                tetrisScore: '#e2d707',
194
-                tetrisI: '#30b3be',
195
-                tetrisO: '#c1a700',
196
-                tetrisT: '#9114c7',
197
-                tetrisS: '#08a121',
198
-                tetrisZ: '#b50008',
199
-                tetrisJ: '#0f37b9',
200
-                tetrisL: '#b96226',
201
-
202
-                gameGold: "#ffd610",
203
-                gameSilver: "#7b7b7b",
204
-                gameBronze: "#a15218",
205
-
206
-                // Mascot Popup
207
-                mascotMessageArrow: "#323232",
208
-            },
209
-        };
210
-    }
211
-
212
-    /**
213
-     * Get this class instance or create one if none is found
214
-     *
215
-     * @returns {ThemeManager}
216
-     */
217
-    static getInstance(): ThemeManager {
218
-        return ThemeManager.instance === null ?
219
-            ThemeManager.instance = new ThemeManager() :
220
-            ThemeManager.instance;
221
-    }
222
-
223
-    /**
224
-     * Gets night mode status.
225
-     * If Follow System Preferences is enabled, will first use system theme.
226
-     * If disabled or not available, will use value stored din preferences
227
-     *
228
-     * @returns {boolean} Night mode state
229
-     */
230
-    static getNightMode(): boolean {
231
-        return (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightMode.key) &&
232
-            (!AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
233
-                || colorScheme === 'no-preference')) ||
234
-            (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key)
235
-                && colorScheme === 'dark');
236
-    }
237
-
238
-    /**
239
-     * Get the current theme based on night mode and events
240
-     *
241
-     * @returns {CustomTheme} The current theme
242
-     */
243
-    static getCurrentTheme(): CustomTheme {
244
-        if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
245
-            return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme());
246
-        else
247
-            return ThemeManager.getBaseTheme()
248
-    }
249
-
250
-    /**
251
-     * Get the theme based on night mode
252
-     *
253
-     * @return {CustomTheme} The theme
254
-     */
255
-    static getBaseTheme(): CustomTheme {
256
-        if (ThemeManager.getNightMode())
257
-            return ThemeManager.getDarkTheme();
258
-        else
259
-            return ThemeManager.getWhiteTheme();
260
-    }
261
-
262
-    /**
263
-     * Sets the function to be called when the theme is changed (allows for general reload of the app)
264
-     *
265
-     * @param callback Function to call after theme change
266
-     */
267
-    setUpdateThemeCallback(callback: () => void) {
268
-        this.updateThemeCallback = callback;
269
-    }
270
-
271
-    /**
272
-     * Set night mode and save it to preferences
273
-     *
274
-     * @param isNightMode True to enable night mode, false to disable
275
-     */
276
-    setNightMode(isNightMode: boolean) {
277
-        AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightMode.key, isNightMode);
278
-        if (this.updateThemeCallback != null)
279
-            this.updateThemeCallback();
280
-    }
174
+        // PROXIWASH
175
+        proxiwashFinishedColor: '#31682c',
176
+        proxiwashReadyColor: 'transparent',
177
+        proxiwashRunningColor: '#213c79',
178
+        proxiwashRunningNotStartedColor: '#1e263e',
179
+        proxiwashRunningBgColor: '#1a2033',
180
+        proxiwashBrokenColor: '#7e2e2f',
181
+        proxiwashErrorColor: '#7e2e2f',
182
+        proxiwashUnknownColor: '#535353',
281 183
 
282
-};
184
+        // Screens
185
+        planningColor: '#d99e09',
186
+        proximoColor: '#ec5904',
187
+        proxiwashColor: '#1fa5ee',
188
+        menuColor: '#b81213',
189
+        tutorinsaColor: '#f93943',
190
+
191
+        // Tetris
192
+        tetrisBackground: '#181818',
193
+        tetrisScore: '#e2d707',
194
+        tetrisI: '#30b3be',
195
+        tetrisO: '#c1a700',
196
+        tetrisT: '#9114c7',
197
+        tetrisS: '#08a121',
198
+        tetrisZ: '#b50008',
199
+        tetrisJ: '#0f37b9',
200
+        tetrisL: '#b96226',
201
+
202
+        gameGold: '#ffd610',
203
+        gameSilver: '#7b7b7b',
204
+        gameBronze: '#a15218',
205
+
206
+        // Mascot Popup
207
+        mascotMessageArrow: '#323232',
208
+      },
209
+    };
210
+  }
211
+
212
+  /**
213
+   * Get this class instance or create one if none is found
214
+   *
215
+   * @returns {ThemeManager}
216
+   */
217
+  static getInstance(): ThemeManager {
218
+    if (ThemeManager.instance == null)
219
+      ThemeManager.instance = new ThemeManager();
220
+    return ThemeManager.instance;
221
+  }
222
+
223
+  /**
224
+   * Gets night mode status.
225
+   * If Follow System Preferences is enabled, will first use system theme.
226
+   * If disabled or not available, will use value stored din preferences
227
+   *
228
+   * @returns {boolean} Night mode state
229
+   */
230
+  static getNightMode(): boolean {
231
+    return (
232
+      (AsyncStorageManager.getBool(
233
+        AsyncStorageManager.PREFERENCES.nightMode.key,
234
+      ) &&
235
+        (!AsyncStorageManager.getBool(
236
+          AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
237
+        ) ||
238
+          colorScheme === 'no-preference')) ||
239
+      (AsyncStorageManager.getBool(
240
+        AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
241
+      ) &&
242
+        colorScheme === 'dark')
243
+    );
244
+  }
245
+
246
+  /**
247
+   * Get the current theme based on night mode and events
248
+   *
249
+   * @returns {CustomThemeType} The current theme
250
+   */
251
+  static getCurrentTheme(): CustomThemeType {
252
+    if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
253
+      return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme());
254
+    return ThemeManager.getBaseTheme();
255
+  }
256
+
257
+  /**
258
+   * Get the theme based on night mode
259
+   *
260
+   * @return {CustomThemeType} The theme
261
+   */
262
+  static getBaseTheme(): CustomThemeType {
263
+    if (ThemeManager.getNightMode()) return ThemeManager.getDarkTheme();
264
+    return ThemeManager.getWhiteTheme();
265
+  }
266
+
267
+  /**
268
+   * Sets the function to be called when the theme is changed (allows for general reload of the app)
269
+   *
270
+   * @param callback Function to call after theme change
271
+   */
272
+  setUpdateThemeCallback(callback: () => void) {
273
+    this.updateThemeCallback = callback;
274
+  }
275
+
276
+  /**
277
+   * Set night mode and save it to preferences
278
+   *
279
+   * @param isNightMode True to enable night mode, false to disable
280
+   */
281
+  setNightMode(isNightMode: boolean) {
282
+    AsyncStorageManager.set(
283
+      AsyncStorageManager.PREFERENCES.nightMode.key,
284
+      isNightMode,
285
+    );
286
+    if (this.updateThemeCallback != null) this.updateThemeCallback();
287
+  }
288
+}

Loading…
Cancel
Save