diff --git a/src/managers/AprilFoolsManager.js b/src/managers/AprilFoolsManager.js index ed41fdd..1afc9a5 100644 --- a/src/managers/AprilFoolsManager.js +++ b/src/managers/AprilFoolsManager.js @@ -1,130 +1,137 @@ // @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 */ export default class AprilFoolsManager { + static instance: AprilFoolsManager | null = null; - static instance: AprilFoolsManager | null = null; - static fakeMachineNumber = [ - "", - "cos(ln(1))", - "0,5⁻¹", - "567/189", - "√2×√8", - "√50×sin(9π/4)", - "⌈π+e⌉", - "div(rot(B))+7", - "4×cosh(0)+4", - "8-(-i)²", - "|5√2+5√2i|", - "1×10¹+1×10⁰", - "Re(√192e^(iπ/6))", - ]; - aprilFoolsEnabled: boolean; + static fakeMachineNumber = [ + '', + 'cos(ln(1))', + '0,5⁻¹', + '567/189', + '√2×√8', + '√50×sin(9π/4)', + '⌈π+e⌉', + 'div(rot(B))+7', + '4×cosh(0)+4', + '8-(-i)²', + '|5√2+5√2i|', + '1×10¹+1×10⁰', + 'Re(√192e^(iπ/6))', + ]; - constructor() { - let today = new Date(); - this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3); + aprilFoolsEnabled: boolean; + + constructor() { + const today = new Date(); + this.aprilFoolsEnabled = today.getDate() === 1 && today.getMonth() === 3; + } + + /** + * Get this class instance or create one if none is found + * @returns {ThemeManager} + */ + static getInstance(): AprilFoolsManager { + if (AprilFoolsManager.instance == null) + AprilFoolsManager.instance = new AprilFoolsManager(); + return AprilFoolsManager.instance; + } + + /** + * Adds fake menu entries + * + * @param menu + * @returns {Object} + */ + static getFakeMenuItem( + menu: Array<{dishes: Array<{name: string}>}>, + ): Array<{dishes: Array<{name: string}>}> { + menu[1].dishes.splice(4, 0, {name: 'Coq au vin'}); + menu[1].dishes.splice(2, 0, {name: "Bat'Soupe"}); + 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; + } + + /** + * Changes proxiwash dryers order + * + * @param dryers + */ + static getNewProxiwashDryerOrderedList( + dryers: Array | null, + ) { + if (dryers != null) { + const second = dryers[1]; + dryers.splice(1, 1); + dryers.push(second); } + } - /** - * Get this class instance or create one if none is found - * @returns {ThemeManager} - */ - static getInstance(): AprilFoolsManager { - return AprilFoolsManager.instance === null ? - AprilFoolsManager.instance = new AprilFoolsManager() : - AprilFoolsManager.instance; + /** + * Changes proxiwash washers order + * + * @param washers + */ + static getNewProxiwashWasherOrderedList( + washers: Array | null, + ) { + if (washers != null) { + const first = washers[0]; + const second = washers[1]; + const fifth = washers[4]; + const ninth = washers[8]; + washers.splice(8, 1, second); + washers.splice(4, 1, ninth); + washers.splice(1, 1, first); + washers.splice(0, 1, fifth); } + } - /** - * Adds fake menu entries - * - * @param menu - * @returns {Object} - */ - static getFakeMenuItem(menu: Array<{dishes: Array<{name: string}>}>) { - menu[1]["dishes"].splice(4, 0, {name: "Coq au vin"}); - menu[1]["dishes"].splice(2, 0, {name: "Bat'Soupe"}); - 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; - } + /** + * Gets the new display number for the given machine number + * + * @param number + * @returns {string} + */ + static getProxiwashMachineDisplayNumber(number: number): string { + return AprilFoolsManager.fakeMachineNumber[number]; + } - /** - * Changes proxiwash dryers order - * - * @param dryers - */ - static getNewProxiwashDryerOrderedList(dryers: Array | null) { - if (dryers != null) { - let second = dryers[1]; - dryers.splice(1, 1); - dryers.push(second); - } - } + /** + * Gets the new and ugly april fools theme + * + * @param currentTheme + * @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: CustomThemeType): CustomThemeType { + return { + ...currentTheme, + colors: { + ...currentTheme.colors, + primary: '#00be45', + accent: '#00be45', + background: '#d02eee', + tabIcon: '#380d43', + card: '#eed639', + surface: '#eed639', + dividerBackground: '#c72ce4', + textDisabled: '#b9b9b9', - /** - * Changes proxiwash washers order - * - * @param washers - */ - static getNewProxiwashWasherOrderedList(washers: Array | null) { - if (washers != null) { - let first = washers[0]; - let second = washers[1]; - let fifth = washers[4]; - let ninth = washers[8]; - washers.splice(8, 1, second); - washers.splice(4, 1, ninth); - washers.splice(1, 1, first); - washers.splice(0, 1, fifth); - } - } + // Calendar/Agenda + agendaBackgroundColor: '#c72ce4', + agendaDayTextColor: '#6d6d6d', + }, + }; + } - /** - * Gets the new display number for the given machine number - * - * @param number - * @returns {string} - */ - static getProxiwashMachineDisplayNumber(number: number) { - return AprilFoolsManager.fakeMachineNumber[number]; - } - - /** - * Gets the new and ugly april fools theme - * - * @param currentTheme - * @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) { - return { - ...currentTheme, - colors: { - ...currentTheme.colors, - primary: '#00be45', - accent: '#00be45', - background: '#d02eee', - tabIcon: "#380d43", - card: "#eed639", - surface: "#eed639", - dividerBackground: '#c72ce4', - textDisabled: '#b9b9b9', - - // Calendar/Agenda - agendaBackgroundColor: '#c72ce4', - agendaDayTextColor: '#6d6d6d', - }, - }; - } - - isAprilFoolsEnabled() { - return this.aprilFoolsEnabled; - } - -}; + isAprilFoolsEnabled(): boolean { + return this.aprilFoolsEnabled; + } +} diff --git a/src/managers/AsyncStorageManager.js b/src/managers/AsyncStorageManager.js index 4a8eaa2..3b85edb 100644 --- a/src/managers/AsyncStorageManager.js +++ b/src/managers/AsyncStorageManager.js @@ -1,7 +1,7 @@ // @flow import AsyncStorage from '@react-native-community/async-storage'; -import {SERVICES_KEY} from "./ServicesManager"; +import {SERVICES_KEY} from './ServicesManager'; /** * Singleton used to manage preferences. @@ -10,227 +10,223 @@ import {SERVICES_KEY} from "./ServicesManager"; */ export default class AsyncStorageManager { + static instance: AsyncStorageManager | null = null; - static instance: AsyncStorageManager | null = null; + static PREFERENCES = { + debugUnlocked: { + key: 'debugUnlocked', + default: '0', + }, + showIntro: { + key: 'showIntro', + default: '1', + }, + updateNumber: { + key: 'updateNumber', + default: '0', + }, + proxiwashNotifications: { + key: 'proxiwashNotifications', + default: '5', + }, + nightModeFollowSystem: { + key: 'nightModeFollowSystem', + default: '1', + }, + nightMode: { + key: 'nightMode', + default: '1', + }, + defaultStartScreen: { + key: 'defaultStartScreen', + default: 'home', + }, + servicesShowBanner: { + key: 'servicesShowBanner', + default: '1', + }, + proxiwashShowBanner: { + key: 'proxiwashShowBanner', + default: '1', + }, + homeShowBanner: { + key: 'homeShowBanner', + default: '1', + }, + eventsShowBanner: { + key: 'eventsShowBanner', + default: '1', + }, + planexShowBanner: { + key: 'planexShowBanner', + default: '1', + }, + loginShowBanner: { + key: 'loginShowBanner', + default: '1', + }, + voteShowBanner: { + key: 'voteShowBanner', + default: '1', + }, + equipmentShowBanner: { + key: 'equipmentShowBanner', + default: '1', + }, + gameStartShowBanner: { + key: 'gameStartShowBanner', + default: '1', + }, + proxiwashWatchedMachines: { + key: 'proxiwashWatchedMachines', + default: '[]', + }, + showAprilFoolsStart: { + key: 'showAprilFoolsStart', + default: '1', + }, + planexCurrentGroup: { + key: 'planexCurrentGroup', + default: '', + }, + planexFavoriteGroups: { + key: 'planexFavoriteGroups', + default: '[]', + }, + dashboardItems: { + key: 'dashboardItems', + default: JSON.stringify([ + SERVICES_KEY.EMAIL, + SERVICES_KEY.WASHERS, + SERVICES_KEY.PROXIMO, + SERVICES_KEY.TUTOR_INSA, + SERVICES_KEY.RU, + ]), + }, + gameScores: { + key: 'gameScores', + default: '[]', + }, + }; - static PREFERENCES = { - debugUnlocked: { - key: 'debugUnlocked', - default: '0', - }, - showIntro: { - key: 'showIntro', - default: '1', - }, - updateNumber: { - key: 'updateNumber', - default: '0', - }, - proxiwashNotifications: { - key: 'proxiwashNotifications', - default: '5', - }, - nightModeFollowSystem: { - key: 'nightModeFollowSystem', - default: '1', - }, - nightMode: { - key: 'nightMode', - default: '1', - }, - defaultStartScreen: { - key: 'defaultStartScreen', - default: 'home', - }, - servicesShowBanner: { - key: 'servicesShowBanner', - default: '1', - }, - proxiwashShowBanner: { - key: 'proxiwashShowBanner', - default: '1', - }, - homeShowBanner: { - key: 'homeShowBanner', - default: '1', - }, - eventsShowBanner: { - key: 'eventsShowBanner', - default: '1', - }, - planexShowBanner: { - key: 'planexShowBanner', - default: '1', - }, - loginShowBanner: { - key: 'loginShowBanner', - default: '1', - }, - voteShowBanner: { - key: 'voteShowBanner', - default: '1', - }, - equipmentShowBanner: { - key: 'equipmentShowBanner', - default: '1', - }, - gameStartShowBanner: { - key: 'gameStartShowBanner', - default: '1', - }, - proxiwashWatchedMachines: { - key: 'proxiwashWatchedMachines', - default: '[]', - }, - showAprilFoolsStart: { - key: 'showAprilFoolsStart', - default: '1', - }, - planexCurrentGroup: { - key: 'planexCurrentGroup', - default: '', - }, - planexFavoriteGroups: { - key: 'planexFavoriteGroups', - default: '[]', - }, - dashboardItems: { - key: 'dashboardItems', - default: JSON.stringify([ - SERVICES_KEY.EMAIL, - SERVICES_KEY.WASHERS, - SERVICES_KEY.PROXIMO, - SERVICES_KEY.TUTOR_INSA, - SERVICES_KEY.RU, - ]), - }, - gameScores: { - key: 'gameScores', - default: '[]', - }, - } - - #currentPreferences: {[key: string]: string}; - - constructor() { - this.#currentPreferences = {}; - } - - /** - * Get this class instance or create one if none is found - * @returns {AsyncStorageManager} - */ - static getInstance(): AsyncStorageManager { - return AsyncStorageManager.instance === null ? - AsyncStorageManager.instance = new AsyncStorageManager() : - AsyncStorageManager.instance; - } - - /** - * Set preferences object current values from AsyncStorage. - * This function should be called at the app's start. - * - * @return {Promise} - */ - async loadPreferences() { - let prefKeys = []; - // Get all available keys - for (let key in AsyncStorageManager.PREFERENCES) { - prefKeys.push(key); - } - // Get corresponding values - let resultArray: Array> = await AsyncStorage.multiGet(prefKeys); - // Save those values for later use - for (let i = 0; i < resultArray.length; i++) { - let key: string = resultArray[i][0]; - let val: string | null = resultArray[i][1]; - if (val === null) - val = AsyncStorageManager.PREFERENCES[key].default; - this.#currentPreferences[key] = val; - } - } - - /** - * Saves the value associated to the given key to preferences. - * This updates the preferences object and saves it to AsyncStorage. - * - * @param key - * @param value - */ - setPreference(key: string, value: any) { - if (AsyncStorageManager.PREFERENCES[key] != null) { - let convertedValue = ""; - if (typeof value === "string") - convertedValue = value; - else if (typeof value === "boolean" || typeof value === "number") - convertedValue = value.toString(); - else - convertedValue = JSON.stringify(value); - this.#currentPreferences[key] = convertedValue; - AsyncStorage.setItem(key, convertedValue); - } - } - - /** - * Gets the value at the given key. - * If the key is not available, returns null - * - * @param key - * @returns {string|null} - */ - getPreference(key: string) { - 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)); + #currentPreferences: {[key: string]: string}; + + constructor() { + this.#currentPreferences = {}; + } + + /** + * Get this class instance or create one if none is found + * @returns {AsyncStorageManager} + */ + static getInstance(): AsyncStorageManager { + if (AsyncStorageManager.instance == null) + AsyncStorageManager.instance = new AsyncStorageManager(); + 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)); + } + + /** + * Set preferences object current values from AsyncStorage. + * This function should be called at the app's start. + * + * @return {Promise} + */ + async loadPreferences() { + const prefKeys = []; + // Get all available keys + Object.keys(AsyncStorageManager.PREFERENCES).forEach((key: string) => { + prefKeys.push(key); + }); + // Get corresponding values + const resultArray = await AsyncStorage.multiGet(prefKeys); + // Save those values for later use + resultArray.forEach((item: [string, string | null]) => { + const key = item[0]; + let val = item[1]; + if (val === null) val = AsyncStorageManager.PREFERENCES[key].default; + this.#currentPreferences[key] = val; + }); + } + + /** + * Saves the value associated to the given key to preferences. + * This updates the preferences object and saves it to AsyncStorage. + * + * @param key + * @param value + */ + setPreference(key: string, value: number | string | boolean | {...} | []) { + if (AsyncStorageManager.PREFERENCES[key] != null) { + let convertedValue; + if (typeof value === 'string') convertedValue = value; + else if (typeof value === 'boolean' || typeof value === 'number') + convertedValue = value.toString(); + else convertedValue = JSON.stringify(value); + this.#currentPreferences[key] = convertedValue; + AsyncStorage.setItem(key, convertedValue); } + } + /** + * Gets the value at the given key. + * If the key is not available, returns null + * + * @param key + * @returns {string|null} + */ + getPreference(key: string): string | null { + return this.#currentPreferences[key]; + } } diff --git a/src/managers/DateManager.js b/src/managers/DateManager.js index 9fb4e08..f15346f 100644 --- a/src/managers/DateManager.js +++ b/src/managers/DateManager.js @@ -7,63 +7,68 @@ import i18n from 'i18n-js'; * Translations are hardcoded as toLocaleDateString does not work on current android JS engine */ export default class DateManager { - static instance: DateManager | null = null; + static instance: DateManager | null = null; - daysOfWeek = []; - monthsOfYear = []; + daysOfWeek = []; - constructor() { - 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.tuesday")); - this.daysOfWeek.push(i18n.t("date.daysOfWeek.wednesday")); - this.daysOfWeek.push(i18n.t("date.daysOfWeek.thursday")); - this.daysOfWeek.push(i18n.t("date.daysOfWeek.friday")); - this.daysOfWeek.push(i18n.t("date.daysOfWeek.saturday")); + monthsOfYear = []; - this.monthsOfYear.push(i18n.t("date.monthsOfYear.january")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.february")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.march")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.april")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.may")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.june")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.july")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.august")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.september")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.october")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.november")); - this.monthsOfYear.push(i18n.t("date.monthsOfYear.december")); - } + constructor() { + 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.tuesday')); + this.daysOfWeek.push(i18n.t('date.daysOfWeek.wednesday')); + this.daysOfWeek.push(i18n.t('date.daysOfWeek.thursday')); + this.daysOfWeek.push(i18n.t('date.daysOfWeek.friday')); + this.daysOfWeek.push(i18n.t('date.daysOfWeek.saturday')); - /** - * Get this class instance or create one if none is found - * @returns {DateManager} - */ - static getInstance(): DateManager { - return DateManager.instance === null ? - DateManager.instance = new DateManager() : - DateManager.instance; - } + this.monthsOfYear.push(i18n.t('date.monthsOfYear.january')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.february')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.march')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.april')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.may')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.june')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.july')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.august')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.september')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.october')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.november')); + this.monthsOfYear.push(i18n.t('date.monthsOfYear.december')); + } - static isWeekend(date: Date) { - return date.getDay() === 6 || date.getDay() === 0; - } + /** + * Get this class instance or create one if none is found + * @returns {DateManager} + */ + static getInstance(): DateManager { + if (DateManager.instance == null) DateManager.instance = new DateManager(); + return DateManager.instance; + } - getMonthsOfYear() { - return this.monthsOfYear; - } + static isWeekend(date: Date): boolean { + return date.getDay() === 6 || date.getDay() === 0; + } - /** - * Gets a translated string representing the given date. - * - * @param dateString The date with the format YYYY-MM-DD - * @return {string} The translated string - */ - getTranslatedDate(dateString: string) { - let dateArray = dateString.split('-'); - let date = new Date(); - date.setFullYear(parseInt(dateArray[0]), parseInt(dateArray[1]) - 1, parseInt(dateArray[2])); - return this.daysOfWeek[date.getDay()] + " " + date.getDate() + " " + this.monthsOfYear[date.getMonth()] + " " + date.getFullYear(); - } + getMonthsOfYear(): Array { + return this.monthsOfYear; + } + /** + * Gets a translated string representing the given date. + * + * @param dateString The date with the format YYYY-MM-DD + * @return {string} The translated string + */ + getTranslatedDate(dateString: string): string { + const dateArray = dateString.split('-'); + const date = new Date(); + date.setFullYear( + 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()}`; + } } diff --git a/src/managers/LocaleManager.js b/src/managers/LocaleManager.js index fa9a0fe..72c677b 100644 --- a/src/managers/LocaleManager.js +++ b/src/managers/LocaleManager.js @@ -1,22 +1,24 @@ // @flow 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'; /** * Static class used to manage locales */ export default class LocaleManager { - - /** - * Initialize translations using language files - */ - static initTranslations() { - i18n.fallbacks = true; - i18n.translations = {fr, en}; - i18n.locale = RNLocalize.findBestAvailableLanguage(["en", "fr"]).languageTag; - } + /** + * Initialize translations using language files + */ + static initTranslations() { + i18n.fallbacks = true; + i18n.translations = {fr, en}; + i18n.locale = RNLocalize.findBestAvailableLanguage([ + 'en', + 'fr', + ]).languageTag; + } } diff --git a/src/managers/ThemeManager.js b/src/managers/ThemeManager.js index 487c153..b93a2a0 100644 --- a/src/managers/ThemeManager.js +++ b/src/managers/ThemeManager.js @@ -1,282 +1,288 @@ // @flow -import AsyncStorageManager from "./AsyncStorageManager"; import {DarkTheme, DefaultTheme} from 'react-native-paper'; -import AprilFoolsManager from "./AprilFoolsManager"; import {Appearance} from 'react-native-appearance'; +import AsyncStorageManager from './AsyncStorageManager'; +import AprilFoolsManager from './AprilFoolsManager'; const colorScheme = Appearance.getColorScheme(); -export type CustomTheme = { - ...DefaultTheme, - colors: { - primary: string, - accent: string, - tabIcon: string, - card: string, - dividerBackground: string, - ripple: string, - textDisabled: string, - icon: string, - subtitle: string, - success: string, - warning: string, - danger: string, +export type CustomThemeType = { + ...DefaultTheme, + colors: { + primary: string, + accent: string, + tabIcon: string, + card: string, + dividerBackground: string, + ripple: string, + textDisabled: string, + icon: string, + subtitle: string, + success: string, + warning: string, + danger: string, - // Calendar/Agenda - agendaBackgroundColor: string, - agendaDayTextColor: string, + // Calendar/Agenda + agendaBackgroundColor: string, + agendaDayTextColor: string, - // PROXIWASH - proxiwashFinishedColor: string, - proxiwashReadyColor: string, - proxiwashRunningColor: string, - proxiwashRunningNotStartedColor: string, - proxiwashRunningBgColor: string, - proxiwashBrokenColor: string, - proxiwashErrorColor: string, - proxiwashUnknownColor: string, + // PROXIWASH + proxiwashFinishedColor: string, + proxiwashReadyColor: string, + proxiwashRunningColor: string, + proxiwashRunningNotStartedColor: string, + proxiwashRunningBgColor: string, + proxiwashBrokenColor: string, + proxiwashErrorColor: string, + proxiwashUnknownColor: string, - // Screens - planningColor: string, - proximoColor: string, - proxiwashColor: string, - menuColor: string, - tutorinsaColor: string, + // Screens + planningColor: string, + proximoColor: string, + proxiwashColor: string, + menuColor: string, + tutorinsaColor: string, - // Tetris - tetrisBackground: string, - tetrisBorder: string, - tetrisScore: string, - tetrisI: string, - tetrisO: string, - tetrisT: string, - tetrisS: string, - tetrisZ: string, - tetrisJ: string, - tetrisL: string, + // Tetris + tetrisBackground: string, + tetrisBorder: string, + tetrisScore: string, + tetrisI: string, + tetrisO: string, + tetrisT: string, + tetrisS: string, + tetrisZ: string, + tetrisJ: string, + tetrisL: string, - gameGold: string, - gameSilver: string, - gameBronze: string, + gameGold: string, + gameSilver: string, + gameBronze: string, - // Mascot Popup - mascotMessageArrow: string, - }, -} + // Mascot Popup + mascotMessageArrow: string, + }, +}; /** * Singleton class used to manage themes */ export default class ThemeManager { + static instance: ThemeManager | null = null; - static instance: ThemeManager | null = null; - updateThemeCallback: Function; + updateThemeCallback: null | (() => void); - constructor() { - this.updateThemeCallback = null; - } + constructor() { + this.updateThemeCallback = null; + } - /** - * Gets the light theme - * - * @return {CustomTheme} Object containing theme variables - * */ - static getWhiteTheme(): CustomTheme { - return { - ...DefaultTheme, - colors: { - ...DefaultTheme.colors, - primary: '#be1522', - accent: '#be1522', - tabIcon: "#929292", - card: "#fff", - dividerBackground: '#e2e2e2', - ripple: "rgba(0,0,0,0.2)", - textDisabled: '#c1c1c1', - icon: '#5d5d5d', - subtitle: '#707070', - success: "#5cb85c", - warning: "#f0ad4e", - danger: "#d9534f", - cc: 'dst', + /** + * Gets the light theme + * + * @return {CustomThemeType} Object containing theme variables + * */ + static getWhiteTheme(): CustomThemeType { + return { + ...DefaultTheme, + colors: { + ...DefaultTheme.colors, + primary: '#be1522', + accent: '#be1522', + tabIcon: '#929292', + card: '#fff', + dividerBackground: '#e2e2e2', + ripple: 'rgba(0,0,0,0.2)', + textDisabled: '#c1c1c1', + icon: '#5d5d5d', + subtitle: '#707070', + success: '#5cb85c', + warning: '#f0ad4e', + danger: '#d9534f', + cc: 'dst', - // Calendar/Agenda - agendaBackgroundColor: '#f3f3f4', - agendaDayTextColor: '#636363', + // Calendar/Agenda + agendaBackgroundColor: '#f3f3f4', + agendaDayTextColor: '#636363', - // PROXIWASH - proxiwashFinishedColor: "#a5dc9d", - proxiwashReadyColor: "transparent", - proxiwashRunningColor: "#a0ceff", - proxiwashRunningNotStartedColor: "#c9e0ff", - proxiwashRunningBgColor: "#c7e3ff", - proxiwashBrokenColor: "#ffa8a2", - proxiwashErrorColor: "#ffa8a2", - proxiwashUnknownColor: "#b6b6b6", + // PROXIWASH + proxiwashFinishedColor: '#a5dc9d', + proxiwashReadyColor: 'transparent', + proxiwashRunningColor: '#a0ceff', + proxiwashRunningNotStartedColor: '#c9e0ff', + proxiwashRunningBgColor: '#c7e3ff', + proxiwashBrokenColor: '#ffa8a2', + proxiwashErrorColor: '#ffa8a2', + proxiwashUnknownColor: '#b6b6b6', - // Screens - planningColor: '#d9b10a', - proximoColor: '#ec5904', - proxiwashColor: '#1fa5ee', - menuColor: '#e91314', - tutorinsaColor: '#f93943', + // Screens + planningColor: '#d9b10a', + proximoColor: '#ec5904', + proxiwashColor: '#1fa5ee', + menuColor: '#e91314', + tutorinsaColor: '#f93943', - // Tetris - tetrisBackground: '#f0f0f0', - tetrisScore: '#e2bd33', - tetrisI: '#3cd9e6', - tetrisO: '#ffdd00', - tetrisT: '#a716e5', - tetrisS: '#09c528', - tetrisZ: '#ff0009', - tetrisJ: '#2a67e3', - tetrisL: '#da742d', + // Tetris + tetrisBackground: '#f0f0f0', + tetrisScore: '#e2bd33', + tetrisI: '#3cd9e6', + tetrisO: '#ffdd00', + tetrisT: '#a716e5', + tetrisS: '#09c528', + tetrisZ: '#ff0009', + tetrisJ: '#2a67e3', + tetrisL: '#da742d', - gameGold: "#ffd610", - gameSilver: "#7b7b7b", - gameBronze: "#a15218", + gameGold: '#ffd610', + gameSilver: '#7b7b7b', + gameBronze: '#a15218', - // Mascot Popup - mascotMessageArrow: "#dedede", - }, - }; - } + // Mascot Popup + mascotMessageArrow: '#dedede', + }, + }; + } - /** - * Gets the dark theme - * - * @return {CustomTheme} Object containing theme variables - * */ - static getDarkTheme(): CustomTheme { - return { - ...DarkTheme, - colors: { - ...DarkTheme.colors, - primary: '#be1522', - accent: '#be1522', - tabBackground: "#181818", - tabIcon: "#6d6d6d", - card: "rgb(18,18,18)", - dividerBackground: '#222222', - ripple: "rgba(255,255,255,0.2)", - textDisabled: '#5b5b5b', - icon: '#b3b3b3', - subtitle: '#aaaaaa', - success: "#5cb85c", - warning: "#f0ad4e", - danger: "#d9534f", + /** + * Gets the dark theme + * + * @return {CustomThemeType} Object containing theme variables + * */ + static getDarkTheme(): CustomThemeType { + return { + ...DarkTheme, + colors: { + ...DarkTheme.colors, + primary: '#be1522', + accent: '#be1522', + tabBackground: '#181818', + tabIcon: '#6d6d6d', + card: 'rgb(18,18,18)', + dividerBackground: '#222222', + ripple: 'rgba(255,255,255,0.2)', + textDisabled: '#5b5b5b', + icon: '#b3b3b3', + subtitle: '#aaaaaa', + success: '#5cb85c', + warning: '#f0ad4e', + danger: '#d9534f', - // Calendar/Agenda - agendaBackgroundColor: '#171717', - agendaDayTextColor: '#6d6d6d', + // Calendar/Agenda + agendaBackgroundColor: '#171717', + agendaDayTextColor: '#6d6d6d', - // PROXIWASH - proxiwashFinishedColor: "#31682c", - proxiwashReadyColor: "transparent", - proxiwashRunningColor: "#213c79", - proxiwashRunningNotStartedColor: "#1e263e", - proxiwashRunningBgColor: "#1a2033", - proxiwashBrokenColor: "#7e2e2f", - proxiwashErrorColor: "#7e2e2f", - proxiwashUnknownColor: "#535353", + // PROXIWASH + proxiwashFinishedColor: '#31682c', + proxiwashReadyColor: 'transparent', + proxiwashRunningColor: '#213c79', + proxiwashRunningNotStartedColor: '#1e263e', + proxiwashRunningBgColor: '#1a2033', + proxiwashBrokenColor: '#7e2e2f', + proxiwashErrorColor: '#7e2e2f', + proxiwashUnknownColor: '#535353', - // Screens - planningColor: '#d99e09', - proximoColor: '#ec5904', - proxiwashColor: '#1fa5ee', - menuColor: '#b81213', - tutorinsaColor: '#f93943', + // Screens + planningColor: '#d99e09', + proximoColor: '#ec5904', + proxiwashColor: '#1fa5ee', + menuColor: '#b81213', + tutorinsaColor: '#f93943', - // Tetris - tetrisBackground: '#181818', - tetrisScore: '#e2d707', - tetrisI: '#30b3be', - tetrisO: '#c1a700', - tetrisT: '#9114c7', - tetrisS: '#08a121', - tetrisZ: '#b50008', - tetrisJ: '#0f37b9', - tetrisL: '#b96226', + // Tetris + tetrisBackground: '#181818', + tetrisScore: '#e2d707', + tetrisI: '#30b3be', + tetrisO: '#c1a700', + tetrisT: '#9114c7', + tetrisS: '#08a121', + tetrisZ: '#b50008', + tetrisJ: '#0f37b9', + tetrisL: '#b96226', - gameGold: "#ffd610", - gameSilver: "#7b7b7b", - gameBronze: "#a15218", + gameGold: '#ffd610', + gameSilver: '#7b7b7b', + gameBronze: '#a15218', - // Mascot Popup - mascotMessageArrow: "#323232", - }, - }; - } + // Mascot Popup + mascotMessageArrow: '#323232', + }, + }; + } - /** - * Get this class instance or create one if none is found - * - * @returns {ThemeManager} - */ - static getInstance(): ThemeManager { - return ThemeManager.instance === null ? - ThemeManager.instance = new ThemeManager() : - ThemeManager.instance; - } + /** + * Get this class instance or create one if none is found + * + * @returns {ThemeManager} + */ + static getInstance(): ThemeManager { + if (ThemeManager.instance == null) + ThemeManager.instance = new ThemeManager(); + return ThemeManager.instance; + } - /** - * Gets night mode status. - * If Follow System Preferences is enabled, will first use system theme. - * If disabled or not available, will use value stored din preferences - * - * @returns {boolean} Night mode state - */ - static getNightMode(): boolean { - return (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightMode.key) && - (!AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key) - || colorScheme === 'no-preference')) || - (AsyncStorageManager.getBool(AsyncStorageManager.PREFERENCES.nightModeFollowSystem.key) - && colorScheme === 'dark'); - } + /** + * Gets night mode status. + * If Follow System Preferences is enabled, will first use system theme. + * If disabled or not available, will use value stored din preferences + * + * @returns {boolean} Night mode state + */ + static getNightMode(): boolean { + return ( + (AsyncStorageManager.getBool( + AsyncStorageManager.PREFERENCES.nightMode.key, + ) && + (!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 - * - * @returns {CustomTheme} The current theme - */ - static getCurrentTheme(): CustomTheme { - if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) - return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme()); - else - return ThemeManager.getBaseTheme() - } + /** + * Get the current theme based on night mode and events + * + * @returns {CustomThemeType} The current theme + */ + static getCurrentTheme(): CustomThemeType { + if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) + return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme()); + return ThemeManager.getBaseTheme(); + } - /** - * Get the theme based on night mode - * - * @return {CustomTheme} The theme - */ - static getBaseTheme(): CustomTheme { - if (ThemeManager.getNightMode()) - return ThemeManager.getDarkTheme(); - else - return ThemeManager.getWhiteTheme(); - } + /** + * Get the theme based on night mode + * + * @return {CustomThemeType} The theme + */ + static getBaseTheme(): CustomThemeType { + if (ThemeManager.getNightMode()) return ThemeManager.getDarkTheme(); + return ThemeManager.getWhiteTheme(); + } - /** - * Sets the function to be called when the theme is changed (allows for general reload of the app) - * - * @param callback Function to call after theme change - */ - setUpdateThemeCallback(callback: () => void) { - this.updateThemeCallback = callback; - } + /** + * Sets the function to be called when the theme is changed (allows for general reload of the app) + * + * @param callback Function to call after theme change + */ + setUpdateThemeCallback(callback: () => void) { + this.updateThemeCallback = callback; + } - /** - * Set night mode and save it to preferences - * - * @param isNightMode True to enable night mode, false to disable - */ - setNightMode(isNightMode: boolean) { - AsyncStorageManager.set(AsyncStorageManager.PREFERENCES.nightMode.key, isNightMode); - if (this.updateThemeCallback != null) - this.updateThemeCallback(); - } - -}; + /** + * Set night mode and save it to preferences + * + * @param isNightMode True to enable night mode, false to disable + */ + setNightMode(isNightMode: boolean) { + AsyncStorageManager.set( + AsyncStorageManager.PREFERENCES.nightMode.key, + isNightMode, + ); + if (this.updateThemeCallback != null) this.updateThemeCallback(); + } +}