Improve constants to match linter

This commit is contained in:
Arnaud Vergnet 2020-08-05 00:06:05 +02:00
parent 7ac62b99f4
commit 7107a8eadf
5 changed files with 654 additions and 638 deletions

View file

@ -1,33 +1,35 @@
// @flow // @flow
import type {Machine} from "../screens/Proxiwash/ProxiwashScreen"; import type {ProxiwashMachineType} from '../screens/Proxiwash/ProxiwashScreen';
import type {CustomThemeType} from './ThemeManager';
/** /**
* Singleton class used to manage april fools * Singleton class used to manage april fools
*/ */
export default class AprilFoolsManager { export default class AprilFoolsManager {
static instance: AprilFoolsManager | null = null; static instance: AprilFoolsManager | null = null;
static fakeMachineNumber = [ static fakeMachineNumber = [
"", '',
"cos(ln(1))", 'cos(ln(1))',
"0,5⁻¹", '0,5⁻¹',
"567/189", '567/189',
"√2×√8", '√2×√8',
"√50×sin(9π/4)", '√50×sin(9π/4)',
"⌈π+e⌉", '⌈π+e⌉',
"div(rot(B))+7", 'div(rot(B))+7',
"4×cosh(0)+4", '4×cosh(0)+4',
"8-(-i)²", '8-(-i)²',
"|5√2+5√2i|", '|5√2+5√2i|',
"1×10¹+1×10⁰", '1×10¹+1×10⁰',
"Re(√192e^(iπ/6))", 'Re(√192e^(iπ/6))',
]; ];
aprilFoolsEnabled: boolean; aprilFoolsEnabled: boolean;
constructor() { constructor() {
let today = new Date(); const today = new Date();
this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3); this.aprilFoolsEnabled = today.getDate() === 1 && today.getMonth() === 3;
} }
/** /**
@ -35,9 +37,9 @@ export default class AprilFoolsManager {
* @returns {ThemeManager} * @returns {ThemeManager}
*/ */
static getInstance(): AprilFoolsManager { static getInstance(): AprilFoolsManager {
return AprilFoolsManager.instance === null ? if (AprilFoolsManager.instance == null)
AprilFoolsManager.instance = new AprilFoolsManager() : AprilFoolsManager.instance = new AprilFoolsManager();
AprilFoolsManager.instance; return AprilFoolsManager.instance;
} }
/** /**
@ -46,12 +48,14 @@ export default class AprilFoolsManager {
* @param menu * @param menu
* @returns {Object} * @returns {Object}
*/ */
static getFakeMenuItem(menu: Array<{dishes: Array<{name: string}>}>) { static getFakeMenuItem(
menu[1]["dishes"].splice(4, 0, {name: "Coq au vin"}); menu: Array<{dishes: Array<{name: string}>}>,
menu[1]["dishes"].splice(2, 0, {name: "Bat'Soupe"}); ): Array<{dishes: Array<{name: string}>}> {
menu[1]["dishes"].splice(1, 0, {name: "Pave de loup"}); menu[1].dishes.splice(4, 0, {name: 'Coq au vin'});
menu[1]["dishes"].splice(0, 0, {name: "Béranger à point"}); menu[1].dishes.splice(2, 0, {name: "Bat'Soupe"});
menu[1]["dishes"].splice(0, 0, {name: "Pieds d'Arnaud"}); menu[1].dishes.splice(1, 0, {name: 'Pave de loup'});
menu[1].dishes.splice(0, 0, {name: 'Béranger à point'});
menu[1].dishes.splice(0, 0, {name: "Pieds d'Arnaud"});
return menu; return menu;
} }
@ -60,9 +64,11 @@ export default class AprilFoolsManager {
* *
* @param dryers * @param dryers
*/ */
static getNewProxiwashDryerOrderedList(dryers: Array<Machine> | null) { static getNewProxiwashDryerOrderedList(
dryers: Array<ProxiwashMachineType> | null,
) {
if (dryers != null) { if (dryers != null) {
let second = dryers[1]; const second = dryers[1];
dryers.splice(1, 1); dryers.splice(1, 1);
dryers.push(second); dryers.push(second);
} }
@ -73,12 +79,14 @@ export default class AprilFoolsManager {
* *
* @param washers * @param washers
*/ */
static getNewProxiwashWasherOrderedList(washers: Array<Machine> | null) { static getNewProxiwashWasherOrderedList(
washers: Array<ProxiwashMachineType> | null,
) {
if (washers != null) { if (washers != null) {
let first = washers[0]; const first = washers[0];
let second = washers[1]; const second = washers[1];
let fifth = washers[4]; const fifth = washers[4];
let ninth = washers[8]; const ninth = washers[8];
washers.splice(8, 1, second); washers.splice(8, 1, second);
washers.splice(4, 1, ninth); washers.splice(4, 1, ninth);
washers.splice(1, 1, first); washers.splice(1, 1, first);
@ -92,7 +100,7 @@ export default class AprilFoolsManager {
* @param number * @param number
* @returns {string} * @returns {string}
*/ */
static getProxiwashMachineDisplayNumber(number: number) { static getProxiwashMachineDisplayNumber(number: number): string {
return AprilFoolsManager.fakeMachineNumber[number]; return AprilFoolsManager.fakeMachineNumber[number];
} }
@ -102,7 +110,7 @@ export default class AprilFoolsManager {
* @param currentTheme * @param currentTheme
* @returns {{colors: {textDisabled: string, agendaDayTextColor: string, surface: string, background: string, dividerBackground: string, accent: string, agendaBackgroundColor: string, tabIcon: string, card: string, primary: string}}} * @returns {{colors: {textDisabled: string, agendaDayTextColor: string, surface: string, background: string, dividerBackground: string, accent: string, agendaBackgroundColor: string, tabIcon: string, card: string, primary: string}}}
*/ */
static getAprilFoolsTheme(currentTheme: Object) { static getAprilFoolsTheme(currentTheme: CustomThemeType): CustomThemeType {
return { return {
...currentTheme, ...currentTheme,
colors: { colors: {
@ -110,9 +118,9 @@ export default class AprilFoolsManager {
primary: '#00be45', primary: '#00be45',
accent: '#00be45', accent: '#00be45',
background: '#d02eee', background: '#d02eee',
tabIcon: "#380d43", tabIcon: '#380d43',
card: "#eed639", card: '#eed639',
surface: "#eed639", surface: '#eed639',
dividerBackground: '#c72ce4', dividerBackground: '#c72ce4',
textDisabled: '#b9b9b9', textDisabled: '#b9b9b9',
@ -123,8 +131,7 @@ export default class AprilFoolsManager {
}; };
} }
isAprilFoolsEnabled() { isAprilFoolsEnabled(): boolean {
return this.aprilFoolsEnabled; return this.aprilFoolsEnabled;
} }
}
};

View file

@ -1,7 +1,7 @@
// @flow // @flow
import AsyncStorage from '@react-native-community/async-storage'; import AsyncStorage from '@react-native-community/async-storage';
import {SERVICES_KEY} from "./ServicesManager"; import {SERVICES_KEY} from './ServicesManager';
/** /**
* Singleton used to manage preferences. * Singleton used to manage preferences.
@ -10,7 +10,6 @@ import {SERVICES_KEY} from "./ServicesManager";
*/ */
export default class AsyncStorageManager { export default class AsyncStorageManager {
static instance: AsyncStorageManager | null = null; static instance: AsyncStorageManager | null = null;
static PREFERENCES = { static PREFERENCES = {
@ -108,7 +107,7 @@ export default class AsyncStorageManager {
key: 'gameScores', key: 'gameScores',
default: '[]', default: '[]',
}, },
} };
#currentPreferences: {[key: string]: string}; #currentPreferences: {[key: string]: string};
@ -121,9 +120,61 @@ export default class AsyncStorageManager {
* @returns {AsyncStorageManager} * @returns {AsyncStorageManager}
*/ */
static getInstance(): AsyncStorageManager { static getInstance(): AsyncStorageManager {
return AsyncStorageManager.instance === null ? if (AsyncStorageManager.instance == null)
AsyncStorageManager.instance = new AsyncStorageManager() : AsyncStorageManager.instance = new AsyncStorageManager();
AsyncStorageManager.instance; return AsyncStorageManager.instance;
}
/**
* Saves the value associated to the given key to preferences.
*
* @param key
* @param value
*/
static set(key: string, value: number | string | boolean | {...} | []) {
AsyncStorageManager.getInstance().setPreference(key, value);
}
/**
* Gets the string value of the given preference
*
* @param key
* @returns {string}
*/
static getString(key: string): string {
return AsyncStorageManager.getInstance().getPreference(key);
}
/**
* Gets the boolean value of the given preference
*
* @param key
* @returns {boolean}
*/
static getBool(key: string): boolean {
const value = AsyncStorageManager.getString(key);
return value === '1' || value === 'true';
}
/**
* Gets the number value of the given preference
*
* @param key
* @returns {number}
*/
static getNumber(key: string): number {
return parseFloat(AsyncStorageManager.getString(key));
}
/**
* Gets the object value of the given preference
*
* @param key
* @returns {{...}}
*/
// eslint-disable-next-line flowtype/no-weak-types
static getObject(key: string): any {
return JSON.parse(AsyncStorageManager.getString(key));
} }
/** /**
@ -133,21 +184,20 @@ export default class AsyncStorageManager {
* @return {Promise<void>} * @return {Promise<void>}
*/ */
async loadPreferences() { async loadPreferences() {
let prefKeys = []; const prefKeys = [];
// Get all available keys // Get all available keys
for (let key in AsyncStorageManager.PREFERENCES) { Object.keys(AsyncStorageManager.PREFERENCES).forEach((key: string) => {
prefKeys.push(key); prefKeys.push(key);
} });
// Get corresponding values // Get corresponding values
let resultArray: Array<Array<string>> = await AsyncStorage.multiGet(prefKeys); const resultArray = await AsyncStorage.multiGet(prefKeys);
// Save those values for later use // Save those values for later use
for (let i = 0; i < resultArray.length; i++) { resultArray.forEach((item: [string, string | null]) => {
let key: string = resultArray[i][0]; const key = item[0];
let val: string | null = resultArray[i][1]; let val = item[1];
if (val === null) if (val === null) val = AsyncStorageManager.PREFERENCES[key].default;
val = AsyncStorageManager.PREFERENCES[key].default;
this.#currentPreferences[key] = val; this.#currentPreferences[key] = val;
} });
} }
/** /**
@ -157,15 +207,13 @@ export default class AsyncStorageManager {
* @param key * @param key
* @param value * @param value
*/ */
setPreference(key: string, value: any) { setPreference(key: string, value: number | string | boolean | {...} | []) {
if (AsyncStorageManager.PREFERENCES[key] != null) { if (AsyncStorageManager.PREFERENCES[key] != null) {
let convertedValue = ""; let convertedValue;
if (typeof value === "string") if (typeof value === 'string') convertedValue = value;
convertedValue = value; else if (typeof value === 'boolean' || typeof value === 'number')
else if (typeof value === "boolean" || typeof value === "number")
convertedValue = value.toString(); convertedValue = value.toString();
else else convertedValue = JSON.stringify(value);
convertedValue = JSON.stringify(value);
this.#currentPreferences[key] = convertedValue; this.#currentPreferences[key] = convertedValue;
AsyncStorage.setItem(key, convertedValue); AsyncStorage.setItem(key, convertedValue);
} }
@ -178,59 +226,7 @@ export default class AsyncStorageManager {
* @param key * @param key
* @returns {string|null} * @returns {string|null}
*/ */
getPreference(key: string) { getPreference(key: string): string | null {
return this.#currentPreferences[key]; return this.#currentPreferences[key];
} }
/**
* aves the value associated to the given key to preferences.
*
* @param key
* @param value
*/
static set(key: string, value: any) {
AsyncStorageManager.getInstance().setPreference(key, value);
}
/**
* Gets the string value of the given preference
*
* @param key
* @returns {boolean}
*/
static getString(key: string) {
return AsyncStorageManager.getInstance().getPreference(key);
}
/**
* Gets the boolean value of the given preference
*
* @param key
* @returns {boolean}
*/
static getBool(key: string) {
const value = AsyncStorageManager.getString(key);
return value === "1" || value === "true";
}
/**
* Gets the number value of the given preference
*
* @param key
* @returns {boolean}
*/
static getNumber(key: string) {
return parseFloat(AsyncStorageManager.getString(key));
}
/**
* Gets the object value of the given preference
*
* @param key
* @returns {boolean}
*/
static getObject(key: string) {
return JSON.parse(AsyncStorageManager.getString(key));
}
} }

View file

@ -10,29 +10,30 @@ export default class DateManager {
static instance: DateManager | null = null; static instance: DateManager | null = null;
daysOfWeek = []; daysOfWeek = [];
monthsOfYear = []; monthsOfYear = [];
constructor() { constructor() {
this.daysOfWeek.push(i18n.t("date.daysOfWeek.sunday")); // 0 represents sunday this.daysOfWeek.push(i18n.t('date.daysOfWeek.sunday')); // 0 represents sunday
this.daysOfWeek.push(i18n.t("date.daysOfWeek.monday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.monday'));
this.daysOfWeek.push(i18n.t("date.daysOfWeek.tuesday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.tuesday'));
this.daysOfWeek.push(i18n.t("date.daysOfWeek.wednesday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.wednesday'));
this.daysOfWeek.push(i18n.t("date.daysOfWeek.thursday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.thursday'));
this.daysOfWeek.push(i18n.t("date.daysOfWeek.friday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.friday'));
this.daysOfWeek.push(i18n.t("date.daysOfWeek.saturday")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.saturday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.january")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.january'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.february")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.february'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.march")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.march'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.april")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.april'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.may")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.may'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.june")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.june'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.july")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.july'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.august")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.august'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.september")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.september'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.october")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.october'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.november")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.november'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.december")); this.monthsOfYear.push(i18n.t('date.monthsOfYear.december'));
} }
/** /**
@ -40,16 +41,15 @@ export default class DateManager {
* @returns {DateManager} * @returns {DateManager}
*/ */
static getInstance(): DateManager { static getInstance(): DateManager {
return DateManager.instance === null ? if (DateManager.instance == null) DateManager.instance = new DateManager();
DateManager.instance = new DateManager() : return DateManager.instance;
DateManager.instance;
} }
static isWeekend(date: Date) { static isWeekend(date: Date): boolean {
return date.getDay() === 6 || date.getDay() === 0; return date.getDay() === 6 || date.getDay() === 0;
} }
getMonthsOfYear() { getMonthsOfYear(): Array<string> {
return this.monthsOfYear; return this.monthsOfYear;
} }
@ -59,11 +59,16 @@ export default class DateManager {
* @param dateString The date with the format YYYY-MM-DD * @param dateString The date with the format YYYY-MM-DD
* @return {string} The translated string * @return {string} The translated string
*/ */
getTranslatedDate(dateString: string) { getTranslatedDate(dateString: string): string {
let dateArray = dateString.split('-'); const dateArray = dateString.split('-');
let date = new Date(); const date = new Date();
date.setFullYear(parseInt(dateArray[0]), parseInt(dateArray[1]) - 1, parseInt(dateArray[2])); date.setFullYear(
return this.daysOfWeek[date.getDay()] + " " + date.getDate() + " " + this.monthsOfYear[date.getMonth()] + " " + date.getFullYear(); parseInt(dateArray[0], 10),
parseInt(dateArray[1], 10) - 1,
parseInt(dateArray[2], 10),
);
return `${this.daysOfWeek[date.getDay()]} ${date.getDate()} ${
this.monthsOfYear[date.getMonth()]
} ${date.getFullYear()}`;
} }
} }

View file

@ -1,22 +1,24 @@
// @flow // @flow
import i18n from 'i18n-js'; import i18n from 'i18n-js';
import * as RNLocalize from "react-native-localize"; import * as RNLocalize from 'react-native-localize';
import en from '../../locales/en'; import en from '../../locales/en.json';
import fr from '../../locales/fr.json'; import fr from '../../locales/fr.json';
/** /**
* Static class used to manage locales * Static class used to manage locales
*/ */
export default class LocaleManager { export default class LocaleManager {
/** /**
* Initialize translations using language files * Initialize translations using language files
*/ */
static initTranslations() { static initTranslations() {
i18n.fallbacks = true; i18n.fallbacks = true;
i18n.translations = {fr, en}; i18n.translations = {fr, en};
i18n.locale = RNLocalize.findBestAvailableLanguage(["en", "fr"]).languageTag; i18n.locale = RNLocalize.findBestAvailableLanguage([
'en',
'fr',
]).languageTag;
} }
} }

View file

@ -1,13 +1,13 @@
// @flow // @flow
import AsyncStorageManager from "./AsyncStorageManager";
import {DarkTheme, DefaultTheme} from 'react-native-paper'; import {DarkTheme, DefaultTheme} from 'react-native-paper';
import AprilFoolsManager from "./AprilFoolsManager";
import {Appearance} from 'react-native-appearance'; import {Appearance} from 'react-native-appearance';
import AsyncStorageManager from './AsyncStorageManager';
import AprilFoolsManager from './AprilFoolsManager';
const colorScheme = Appearance.getColorScheme(); const colorScheme = Appearance.getColorScheme();
export type CustomTheme = { export type CustomThemeType = {
...DefaultTheme, ...DefaultTheme,
colors: { colors: {
primary: string, primary: string,
@ -63,15 +63,15 @@ export type CustomTheme = {
// Mascot Popup // Mascot Popup
mascotMessageArrow: string, mascotMessageArrow: string,
}, },
} };
/** /**
* Singleton class used to manage themes * Singleton class used to manage themes
*/ */
export default class ThemeManager { export default class ThemeManager {
static instance: ThemeManager | null = null; static instance: ThemeManager | null = null;
updateThemeCallback: Function;
updateThemeCallback: null | (() => void);
constructor() { constructor() {
this.updateThemeCallback = null; this.updateThemeCallback = null;
@ -80,25 +80,25 @@ export default class ThemeManager {
/** /**
* Gets the light theme * Gets the light theme
* *
* @return {CustomTheme} Object containing theme variables * @return {CustomThemeType} Object containing theme variables
* */ * */
static getWhiteTheme(): CustomTheme { static getWhiteTheme(): CustomThemeType {
return { return {
...DefaultTheme, ...DefaultTheme,
colors: { colors: {
...DefaultTheme.colors, ...DefaultTheme.colors,
primary: '#be1522', primary: '#be1522',
accent: '#be1522', accent: '#be1522',
tabIcon: "#929292", tabIcon: '#929292',
card: "#fff", card: '#fff',
dividerBackground: '#e2e2e2', dividerBackground: '#e2e2e2',
ripple: "rgba(0,0,0,0.2)", ripple: 'rgba(0,0,0,0.2)',
textDisabled: '#c1c1c1', textDisabled: '#c1c1c1',
icon: '#5d5d5d', icon: '#5d5d5d',
subtitle: '#707070', subtitle: '#707070',
success: "#5cb85c", success: '#5cb85c',
warning: "#f0ad4e", warning: '#f0ad4e',
danger: "#d9534f", danger: '#d9534f',
cc: 'dst', cc: 'dst',
// Calendar/Agenda // Calendar/Agenda
@ -106,14 +106,14 @@ export default class ThemeManager {
agendaDayTextColor: '#636363', agendaDayTextColor: '#636363',
// PROXIWASH // PROXIWASH
proxiwashFinishedColor: "#a5dc9d", proxiwashFinishedColor: '#a5dc9d',
proxiwashReadyColor: "transparent", proxiwashReadyColor: 'transparent',
proxiwashRunningColor: "#a0ceff", proxiwashRunningColor: '#a0ceff',
proxiwashRunningNotStartedColor: "#c9e0ff", proxiwashRunningNotStartedColor: '#c9e0ff',
proxiwashRunningBgColor: "#c7e3ff", proxiwashRunningBgColor: '#c7e3ff',
proxiwashBrokenColor: "#ffa8a2", proxiwashBrokenColor: '#ffa8a2',
proxiwashErrorColor: "#ffa8a2", proxiwashErrorColor: '#ffa8a2',
proxiwashUnknownColor: "#b6b6b6", proxiwashUnknownColor: '#b6b6b6',
// Screens // Screens
planningColor: '#d9b10a', planningColor: '#d9b10a',
@ -133,12 +133,12 @@ export default class ThemeManager {
tetrisJ: '#2a67e3', tetrisJ: '#2a67e3',
tetrisL: '#da742d', tetrisL: '#da742d',
gameGold: "#ffd610", gameGold: '#ffd610',
gameSilver: "#7b7b7b", gameSilver: '#7b7b7b',
gameBronze: "#a15218", gameBronze: '#a15218',
// Mascot Popup // Mascot Popup
mascotMessageArrow: "#dedede", mascotMessageArrow: '#dedede',
}, },
}; };
} }
@ -146,40 +146,40 @@ export default class ThemeManager {
/** /**
* Gets the dark theme * Gets the dark theme
* *
* @return {CustomTheme} Object containing theme variables * @return {CustomThemeType} Object containing theme variables
* */ * */
static getDarkTheme(): CustomTheme { static getDarkTheme(): CustomThemeType {
return { return {
...DarkTheme, ...DarkTheme,
colors: { colors: {
...DarkTheme.colors, ...DarkTheme.colors,
primary: '#be1522', primary: '#be1522',
accent: '#be1522', accent: '#be1522',
tabBackground: "#181818", tabBackground: '#181818',
tabIcon: "#6d6d6d", tabIcon: '#6d6d6d',
card: "rgb(18,18,18)", card: 'rgb(18,18,18)',
dividerBackground: '#222222', dividerBackground: '#222222',
ripple: "rgba(255,255,255,0.2)", ripple: 'rgba(255,255,255,0.2)',
textDisabled: '#5b5b5b', textDisabled: '#5b5b5b',
icon: '#b3b3b3', icon: '#b3b3b3',
subtitle: '#aaaaaa', subtitle: '#aaaaaa',
success: "#5cb85c", success: '#5cb85c',
warning: "#f0ad4e", warning: '#f0ad4e',
danger: "#d9534f", danger: '#d9534f',
// Calendar/Agenda // Calendar/Agenda
agendaBackgroundColor: '#171717', agendaBackgroundColor: '#171717',
agendaDayTextColor: '#6d6d6d', agendaDayTextColor: '#6d6d6d',
// PROXIWASH // PROXIWASH
proxiwashFinishedColor: "#31682c", proxiwashFinishedColor: '#31682c',
proxiwashReadyColor: "transparent", proxiwashReadyColor: 'transparent',
proxiwashRunningColor: "#213c79", proxiwashRunningColor: '#213c79',
proxiwashRunningNotStartedColor: "#1e263e", proxiwashRunningNotStartedColor: '#1e263e',
proxiwashRunningBgColor: "#1a2033", proxiwashRunningBgColor: '#1a2033',
proxiwashBrokenColor: "#7e2e2f", proxiwashBrokenColor: '#7e2e2f',
proxiwashErrorColor: "#7e2e2f", proxiwashErrorColor: '#7e2e2f',
proxiwashUnknownColor: "#535353", proxiwashUnknownColor: '#535353',
// Screens // Screens
planningColor: '#d99e09', planningColor: '#d99e09',
@ -199,12 +199,12 @@ export default class ThemeManager {
tetrisJ: '#0f37b9', tetrisJ: '#0f37b9',
tetrisL: '#b96226', tetrisL: '#b96226',
gameGold: "#ffd610", gameGold: '#ffd610',
gameSilver: "#7b7b7b", gameSilver: '#7b7b7b',
gameBronze: "#a15218", gameBronze: '#a15218',
// Mascot Popup // Mascot Popup
mascotMessageArrow: "#323232", mascotMessageArrow: '#323232',
}, },
}; };
} }
@ -215,9 +215,9 @@ export default class ThemeManager {
* @returns {ThemeManager} * @returns {ThemeManager}
*/ */
static getInstance(): ThemeManager { static getInstance(): ThemeManager {
return ThemeManager.instance === null ? if (ThemeManager.instance == null)
ThemeManager.instance = new ThemeManager() : ThemeManager.instance = new ThemeManager();
ThemeManager.instance; return ThemeManager.instance;
} }
/** /**
@ -228,34 +228,39 @@ export default class ThemeManager {
* @returns {boolean} Night mode state * @returns {boolean} Night mode state
*/ */
static getNightMode(): boolean { static getNightMode(): boolean {
return (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightMode.key) && return (
(!AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key) (AsyncStorageManager.getBool(
|| colorScheme === 'no-preference')) || AsyncStorageManager.PREFERENCES.nightMode.key,
(AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key) ) &&
&& colorScheme === 'dark'); (!AsyncStorageManager.getBool(
AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
) ||
colorScheme === 'no-preference')) ||
(AsyncStorageManager.getBool(
AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key,
) &&
colorScheme === 'dark')
);
} }
/** /**
* Get the current theme based on night mode and events * Get the current theme based on night mode and events
* *
* @returns {CustomTheme} The current theme * @returns {CustomThemeType} The current theme
*/ */
static getCurrentTheme(): CustomTheme { static getCurrentTheme(): CustomThemeType {
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme()); return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme());
else return ThemeManager.getBaseTheme();
return ThemeManager.getBaseTheme()
} }
/** /**
* Get the theme based on night mode * Get the theme based on night mode
* *
* @return {CustomTheme} The theme * @return {CustomThemeType} The theme
*/ */
static getBaseTheme(): CustomTheme { static getBaseTheme(): CustomThemeType {
if (ThemeManager.getNightMode()) if (ThemeManager.getNightMode()) return ThemeManager.getDarkTheme();
return ThemeManager.getDarkTheme();
else
return ThemeManager.getWhiteTheme(); return ThemeManager.getWhiteTheme();
} }
@ -274,9 +279,10 @@ export default class ThemeManager {
* @param isNightMode True to enable night mode, false to disable * @param isNightMode True to enable night mode, false to disable
*/ */
setNightMode(isNightMode: boolean) { setNightMode(isNightMode: boolean) {
AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightMode.key, isNightMode); AsyncStorageManager.set(
if (this.updateThemeCallback != null) AsyncStorageManager.PREFERENCES.nightMode.key,
this.updateThemeCallback(); isNightMode,
);
if (this.updateThemeCallback != null) this.updateThemeCallback();
}
} }
};