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,130 +1,137 @@
// @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;
constructor() { aprilFoolsEnabled: boolean;
let today = new Date();
this.aprilFoolsEnabled = (today.getDate() === 1 && today.getMonth() === 3); 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<ProxiwashMachineType> | 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 * Changes proxiwash washers order
* @returns {ThemeManager} *
*/ * @param washers
static getInstance(): AprilFoolsManager { */
return AprilFoolsManager.instance === null ? static getNewProxiwashWasherOrderedList(
AprilFoolsManager.instance = new AprilFoolsManager() : washers: Array<ProxiwashMachineType> | null,
AprilFoolsManager.instance; ) {
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 * Gets the new display number for the given machine number
* *
* @param menu * @param number
* @returns {Object} * @returns {string}
*/ */
static getFakeMenuItem(menu: Array<{dishes: Array<{name: string}>}>) { static getProxiwashMachineDisplayNumber(number: number): string {
menu[1]["dishes"].splice(4, 0, {name: "Coq au vin"}); return AprilFoolsManager.fakeMachineNumber[number];
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 * Gets the new and ugly april fools theme
* *
* @param dryers * @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 getNewProxiwashDryerOrderedList(dryers: Array<Machine> | null) { */
if (dryers != null) { static getAprilFoolsTheme(currentTheme: CustomThemeType): CustomThemeType {
let second = dryers[1]; return {
dryers.splice(1, 1); ...currentTheme,
dryers.push(second); colors: {
} ...currentTheme.colors,
} primary: '#00be45',
accent: '#00be45',
background: '#d02eee',
tabIcon: '#380d43',
card: '#eed639',
surface: '#eed639',
dividerBackground: '#c72ce4',
textDisabled: '#b9b9b9',
/** // Calendar/Agenda
* Changes proxiwash washers order agendaBackgroundColor: '#c72ce4',
* agendaDayTextColor: '#6d6d6d',
* @param washers },
*/ };
static getNewProxiwashWasherOrderedList(washers: Array<Machine> | 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);
}
}
/** isAprilFoolsEnabled(): boolean {
* Gets the new display number for the given machine number return this.aprilFoolsEnabled;
* }
* @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;
}
};

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,227 +10,223 @@ 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 = {
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 = { #currentPreferences: {[key: string]: string};
debugUnlocked: {
key: 'debugUnlocked', constructor() {
default: '0', this.#currentPreferences = {};
}, }
showIntro: {
key: 'showIntro', /**
default: '1', * Get this class instance or create one if none is found
}, * @returns {AsyncStorageManager}
updateNumber: { */
key: 'updateNumber', static getInstance(): AsyncStorageManager {
default: '0', if (AsyncStorageManager.instance == null)
}, AsyncStorageManager.instance = new AsyncStorageManager();
proxiwashNotifications: { return AsyncStorageManager.instance;
key: 'proxiwashNotifications', }
default: '5',
}, /**
nightModeFollowSystem: { * Saves the value associated to the given key to preferences.
key: 'nightModeFollowSystem', *
default: '1', * @param key
}, * @param value
nightMode: { */
key: 'nightMode', static set(key: string, value: number | string | boolean | {...} | []) {
default: '1', AsyncStorageManager.getInstance().setPreference(key, value);
}, }
defaultStartScreen: {
key: 'defaultStartScreen', /**
default: 'home', * Gets the string value of the given preference
}, *
servicesShowBanner: { * @param key
key: 'servicesShowBanner', * @returns {string}
default: '1', */
}, static getString(key: string): string {
proxiwashShowBanner: { return AsyncStorageManager.getInstance().getPreference(key);
key: 'proxiwashShowBanner', }
default: '1',
}, /**
homeShowBanner: { * Gets the boolean value of the given preference
key: 'homeShowBanner', *
default: '1', * @param key
}, * @returns {boolean}
eventsShowBanner: { */
key: 'eventsShowBanner', static getBool(key: string): boolean {
default: '1', const value = AsyncStorageManager.getString(key);
}, return value === '1' || value === 'true';
planexShowBanner: { }
key: 'planexShowBanner',
default: '1', /**
}, * Gets the number value of the given preference
loginShowBanner: { *
key: 'loginShowBanner', * @param key
default: '1', * @returns {number}
}, */
voteShowBanner: { static getNumber(key: string): number {
key: 'voteShowBanner', return parseFloat(AsyncStorageManager.getString(key));
default: '1', }
},
equipmentShowBanner: { /**
key: 'equipmentShowBanner', * Gets the object value of the given preference
default: '1', *
}, * @param key
gameStartShowBanner: { * @returns {{...}}
key: 'gameStartShowBanner', */
default: '1', // eslint-disable-next-line flowtype/no-weak-types
}, static getObject(key: string): any {
proxiwashWatchedMachines: { return JSON.parse(AsyncStorageManager.getString(key));
key: 'proxiwashWatchedMachines', }
default: '[]',
}, /**
showAprilFoolsStart: { * Set preferences object current values from AsyncStorage.
key: 'showAprilFoolsStart', * This function should be called at the app's start.
default: '1', *
}, * @return {Promise<void>}
planexCurrentGroup: { */
key: 'planexCurrentGroup', async loadPreferences() {
default: '', const prefKeys = [];
}, // Get all available keys
planexFavoriteGroups: { Object.keys(AsyncStorageManager.PREFERENCES).forEach((key: string) => {
key: 'planexFavoriteGroups', prefKeys.push(key);
default: '[]', });
}, // Get corresponding values
dashboardItems: { const resultArray = await AsyncStorage.multiGet(prefKeys);
key: 'dashboardItems', // Save those values for later use
default: JSON.stringify([ resultArray.forEach((item: [string, string | null]) => {
SERVICES_KEY.EMAIL, const key = item[0];
SERVICES_KEY.WASHERS, let val = item[1];
SERVICES_KEY.PROXIMO, if (val === null) val = AsyncStorageManager.PREFERENCES[key].default;
SERVICES_KEY.TUTOR_INSA, this.#currentPreferences[key] = val;
SERVICES_KEY.RU, });
]), }
},
gameScores: { /**
key: 'gameScores', * Saves the value associated to the given key to preferences.
default: '[]', * This updates the preferences object and saves it to AsyncStorage.
}, *
} * @param key
* @param value
#currentPreferences: {[key: string]: string}; */
setPreference(key: string, value: number | string | boolean | {...} | []) {
constructor() { if (AsyncStorageManager.PREFERENCES[key] != null) {
this.#currentPreferences = {}; let convertedValue;
} if (typeof value === 'string') convertedValue = value;
else if (typeof value === 'boolean' || typeof value === 'number')
/** convertedValue = value.toString();
* Get this class instance or create one if none is found else convertedValue = JSON.stringify(value);
* @returns {AsyncStorageManager} this.#currentPreferences[key] = convertedValue;
*/ AsyncStorage.setItem(key, convertedValue);
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<void>}
*/
async loadPreferences() {
let prefKeys = [];
// Get all available keys
for (let key in AsyncStorageManager.PREFERENCES) {
prefKeys.push(key);
}
// Get corresponding values
let resultArray: Array<Array<string>> = 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));
} }
}
/**
* 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];
}
} }

View file

@ -7,63 +7,68 @@ import i18n from 'i18n-js';
* Translations are hardcoded as toLocaleDateString does not work on current android JS engine * Translations are hardcoded as toLocaleDateString does not work on current android JS engine
*/ */
export default class DateManager { export default class DateManager {
static instance: DateManager | null = null; static instance: DateManager | null = null;
daysOfWeek = []; daysOfWeek = [];
monthsOfYear = [];
constructor() { monthsOfYear = [];
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"));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.january")); constructor() {
this.monthsOfYear.push(i18n.t("date.monthsOfYear.february")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.sunday')); // 0 represents sunday
this.monthsOfYear.push(i18n.t("date.monthsOfYear.march")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.monday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.april")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.tuesday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.may")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.wednesday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.june")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.thursday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.july")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.friday'));
this.monthsOfYear.push(i18n.t("date.monthsOfYear.august")); this.daysOfWeek.push(i18n.t('date.daysOfWeek.saturday'));
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"));
}
/** this.monthsOfYear.push(i18n.t('date.monthsOfYear.january'));
* Get this class instance or create one if none is found this.monthsOfYear.push(i18n.t('date.monthsOfYear.february'));
* @returns {DateManager} this.monthsOfYear.push(i18n.t('date.monthsOfYear.march'));
*/ this.monthsOfYear.push(i18n.t('date.monthsOfYear.april'));
static getInstance(): DateManager { this.monthsOfYear.push(i18n.t('date.monthsOfYear.may'));
return DateManager.instance === null ? this.monthsOfYear.push(i18n.t('date.monthsOfYear.june'));
DateManager.instance = new DateManager() : this.monthsOfYear.push(i18n.t('date.monthsOfYear.july'));
DateManager.instance; 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() { static isWeekend(date: Date): boolean {
return this.monthsOfYear; return date.getDay() === 6 || date.getDay() === 0;
} }
/** getMonthsOfYear(): Array<string> {
* Gets a translated string representing the given date. return this.monthsOfYear;
* }
* @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();
}
/**
* 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()}`;
}
} }

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([
i18n.locale = RNLocalize.findBestAvailableLanguage(["en", "fr"]).languageTag; 'en',
} 'fr',
]).languageTag;
}
} }

View file

@ -1,282 +1,288 @@
// @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,
accent: string, accent: string,
tabIcon: string, tabIcon: string,
card: string, card: string,
dividerBackground: string, dividerBackground: string,
ripple: string, ripple: string,
textDisabled: string, textDisabled: string,
icon: string, icon: string,
subtitle: string, subtitle: string,
success: string, success: string,
warning: string, warning: string,
danger: string, danger: string,
// Calendar/Agenda // Calendar/Agenda
agendaBackgroundColor: string, agendaBackgroundColor: string,
agendaDayTextColor: string, agendaDayTextColor: string,
// PROXIWASH // PROXIWASH
proxiwashFinishedColor: string, proxiwashFinishedColor: string,
proxiwashReadyColor: string, proxiwashReadyColor: string,
proxiwashRunningColor: string, proxiwashRunningColor: string,
proxiwashRunningNotStartedColor: string, proxiwashRunningNotStartedColor: string,
proxiwashRunningBgColor: string, proxiwashRunningBgColor: string,
proxiwashBrokenColor: string, proxiwashBrokenColor: string,
proxiwashErrorColor: string, proxiwashErrorColor: string,
proxiwashUnknownColor: string, proxiwashUnknownColor: string,
// Screens // Screens
planningColor: string, planningColor: string,
proximoColor: string, proximoColor: string,
proxiwashColor: string, proxiwashColor: string,
menuColor: string, menuColor: string,
tutorinsaColor: string, tutorinsaColor: string,
// Tetris // Tetris
tetrisBackground: string, tetrisBackground: string,
tetrisBorder: string, tetrisBorder: string,
tetrisScore: string, tetrisScore: string,
tetrisI: string, tetrisI: string,
tetrisO: string, tetrisO: string,
tetrisT: string, tetrisT: string,
tetrisS: string, tetrisS: string,
tetrisZ: string, tetrisZ: string,
tetrisJ: string, tetrisJ: string,
tetrisL: string, tetrisL: string,
gameGold: string, gameGold: string,
gameSilver: string, gameSilver: string,
gameBronze: string, gameBronze: string,
// 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: null | (() => void);
updateThemeCallback: Function;
constructor() { constructor() {
this.updateThemeCallback = null; this.updateThemeCallback = null;
} }
/** /**
* 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
agendaBackgroundColor: '#f3f3f4', agendaBackgroundColor: '#f3f3f4',
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',
proximoColor: '#ec5904', proximoColor: '#ec5904',
proxiwashColor: '#1fa5ee', proxiwashColor: '#1fa5ee',
menuColor: '#e91314', menuColor: '#e91314',
tutorinsaColor: '#f93943', tutorinsaColor: '#f93943',
// Tetris // Tetris
tetrisBackground: '#f0f0f0', tetrisBackground: '#f0f0f0',
tetrisScore: '#e2bd33', tetrisScore: '#e2bd33',
tetrisI: '#3cd9e6', tetrisI: '#3cd9e6',
tetrisO: '#ffdd00', tetrisO: '#ffdd00',
tetrisT: '#a716e5', tetrisT: '#a716e5',
tetrisS: '#09c528', tetrisS: '#09c528',
tetrisZ: '#ff0009', tetrisZ: '#ff0009',
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',
}, },
}; };
} }
/** /**
* 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',
proximoColor: '#ec5904', proximoColor: '#ec5904',
proxiwashColor: '#1fa5ee', proxiwashColor: '#1fa5ee',
menuColor: '#b81213', menuColor: '#b81213',
tutorinsaColor: '#f93943', tutorinsaColor: '#f93943',
// Tetris // Tetris
tetrisBackground: '#181818', tetrisBackground: '#181818',
tetrisScore: '#e2d707', tetrisScore: '#e2d707',
tetrisI: '#30b3be', tetrisI: '#30b3be',
tetrisO: '#c1a700', tetrisO: '#c1a700',
tetrisT: '#9114c7', tetrisT: '#9114c7',
tetrisS: '#08a121', tetrisS: '#08a121',
tetrisZ: '#b50008', tetrisZ: '#b50008',
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',
}, },
}; };
} }
/** /**
* Get this class instance or create one if none is found * Get this class instance or create one if none is found
* *
* @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;
} }
/** /**
* Gets night mode status. * Gets night mode status.
* If Follow System Preferences is enabled, will first use system theme. * If Follow System Preferences is enabled, will first use system theme.
* If disabled or not available, will use value stored din preferences * If disabled or not available, will use value stored din preferences
* *
* @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(); return ThemeManager.getWhiteTheme();
else }
return ThemeManager.getWhiteTheme();
}
/** /**
* Sets the function to be called when the theme is changed (allows for general reload of the app) * 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 * @param callback Function to call after theme change
*/ */
setUpdateThemeCallback(callback: () => void) { setUpdateThemeCallback(callback: () => void) {
this.updateThemeCallback = callback; this.updateThemeCallback = callback;
} }
/** /**
* Set night mode and save it to preferences * Set night mode and save it to preferences
* *
* @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();
}; }
}