2019-06-29 13:37:21 +02:00
|
|
|
// @flow
|
|
|
|
|
2019-07-31 14:22:36 +02:00
|
|
|
import AsyncStorageManager from "./AsyncStorageManager";
|
2020-03-06 23:15:01 +01:00
|
|
|
import {DarkTheme, DefaultTheme} from 'react-native-paper';
|
2020-03-11 19:55:48 +01:00
|
|
|
import AprilFoolsManager from "./AprilFoolsManager";
|
2020-03-10 21:35:31 +01:00
|
|
|
import {Appearance} from 'react-native-appearance';
|
2020-03-08 19:50:17 +01:00
|
|
|
|
|
|
|
const colorScheme = Appearance.getColorScheme();
|
2020-03-08 12:50:18 +01:00
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* Singleton class used to manage themes
|
|
|
|
*/
|
2019-06-25 22:20:24 +02:00
|
|
|
export default class ThemeManager {
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
static instance: ThemeManager | null = null;
|
|
|
|
updateThemeCallback: Function;
|
2019-06-25 22:20:24 +02:00
|
|
|
|
|
|
|
constructor() {
|
2019-06-29 13:37:21 +02:00
|
|
|
this.updateThemeCallback = null;
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-06 23:15:01 +01:00
|
|
|
static getWhiteTheme() {
|
|
|
|
return {
|
|
|
|
...DefaultTheme,
|
|
|
|
colors: {
|
|
|
|
...DefaultTheme.colors,
|
|
|
|
primary: '#be1522',
|
|
|
|
accent: '#be1522',
|
2020-03-08 11:17:47 +01:00
|
|
|
tabIcon: "#929292",
|
2020-03-06 23:15:01 +01:00
|
|
|
card: "rgb(255, 255, 255)",
|
|
|
|
dividerBackground: '#e2e2e2',
|
|
|
|
textDisabled: '#c1c1c1',
|
|
|
|
icon: '#5d5d5d',
|
2020-03-10 15:33:01 +01:00
|
|
|
subtitle: '#707070',
|
2020-03-06 23:15:01 +01:00
|
|
|
success: "#5cb85c",
|
|
|
|
warning: "#f0ad4e",
|
|
|
|
danger: "#d9534f",
|
|
|
|
|
|
|
|
// Calendar/Agenda
|
|
|
|
agendaBackgroundColor: '#f3f3f4',
|
|
|
|
agendaDayTextColor: '#636363',
|
|
|
|
|
|
|
|
// PROXIWASH
|
2020-03-08 00:05:41 +01:00
|
|
|
proxiwashFinishedColor: "#a5dc9d",
|
2020-03-06 23:15:01 +01:00
|
|
|
proxiwashReadyColor: "transparent",
|
2020-03-08 00:05:41 +01:00
|
|
|
proxiwashRunningColor: "#a0ceff",
|
|
|
|
proxiwashRunningBgColor: "#c7e3ff",
|
|
|
|
proxiwashBrokenColor: "#8e8e8e",
|
|
|
|
proxiwashErrorColor: "rgba(204,7,0,0.31)#e35f57",
|
2020-03-06 23:15:01 +01:00
|
|
|
|
|
|
|
// Screens
|
|
|
|
planningColor: '#d9b10a',
|
|
|
|
proximoColor: '#ec5904',
|
|
|
|
proxiwashColor: '#1fa5ee',
|
|
|
|
menuColor: '#e91314',
|
|
|
|
tutorinsaColor: '#f93943',
|
2020-03-15 20:34:20 +01:00
|
|
|
|
|
|
|
// Tetris
|
|
|
|
tetrisBackground:'#d1d1d1',
|
|
|
|
tetrisBorder:'#afafaf',
|
|
|
|
tetrisI : '#42f1ff',
|
|
|
|
tetrisO : '#ffdd00',
|
|
|
|
tetrisT : '#ba19ff',
|
|
|
|
tetrisS : '#0bff34',
|
|
|
|
tetrisZ : '#ff0009',
|
|
|
|
tetrisJ : '#134cff',
|
|
|
|
tetrisL : '#ff8834',
|
2020-03-06 23:15:01 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
static getDarkTheme() {
|
|
|
|
return {
|
|
|
|
...DarkTheme,
|
|
|
|
colors: {
|
|
|
|
...DarkTheme.colors,
|
|
|
|
primary: '#be1522',
|
|
|
|
accent: '#be1522',
|
2020-03-08 11:17:47 +01:00
|
|
|
tabBackground: "#181818",
|
|
|
|
tabIcon: "#6d6d6d",
|
2020-03-06 23:15:01 +01:00
|
|
|
card: "rgb(18, 18, 18)",
|
|
|
|
dividerBackground: '#222222',
|
|
|
|
textDisabled: '#5b5b5b',
|
|
|
|
icon: '#b3b3b3',
|
2020-03-10 15:33:01 +01:00
|
|
|
subtitle: '#aaaaaa',
|
2020-03-06 23:15:01 +01:00
|
|
|
success: "#5cb85c",
|
|
|
|
warning: "#f0ad4e",
|
|
|
|
danger: "#d9534f",
|
|
|
|
|
|
|
|
// Calendar/Agenda
|
|
|
|
agendaBackgroundColor: '#171717',
|
|
|
|
agendaDayTextColor: '#6d6d6d',
|
|
|
|
|
|
|
|
// PROXIWASH
|
2020-03-08 00:05:41 +01:00
|
|
|
proxiwashFinishedColor: "#31682c",
|
2020-03-06 23:15:01 +01:00
|
|
|
proxiwashReadyColor: "transparent",
|
2020-03-08 00:05:41 +01:00
|
|
|
proxiwashRunningColor: "#213c79",
|
|
|
|
proxiwashRunningBgColor: "#1a2033",
|
|
|
|
proxiwashBrokenColor: "#656565",
|
|
|
|
proxiwashErrorColor: "#7e2e2f",
|
2020-03-06 23:15:01 +01:00
|
|
|
|
|
|
|
// Screens
|
|
|
|
planningColor: '#d99e09',
|
|
|
|
proximoColor: '#ec5904',
|
|
|
|
proxiwashColor: '#1fa5ee',
|
|
|
|
menuColor: '#b81213',
|
|
|
|
tutorinsaColor: '#f93943',
|
2020-03-15 20:34:20 +01:00
|
|
|
|
|
|
|
// Tetris
|
|
|
|
tetrisBackground:'#2c2c2c',
|
|
|
|
tetrisBorder:'#1b1b1b',
|
|
|
|
tetrisI : '#30b3be',
|
|
|
|
tetrisO : '#c1a700',
|
|
|
|
tetrisT : '#9114c7',
|
|
|
|
tetrisS : '#08a121',
|
|
|
|
tetrisZ : '#b50008',
|
|
|
|
tetrisJ : '#0f37b9',
|
|
|
|
tetrisL : '#b96226',
|
2020-03-06 23:15:01 +01:00
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* 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;
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* @returns {boolean} Night mode state
|
|
|
|
*/
|
2019-07-31 14:22:36 +02:00
|
|
|
static getNightMode(): boolean {
|
2020-03-10 21:35:31 +01:00
|
|
|
return (AsyncStorageManager.getInstance().preferences.nightMode.current === '1' &&
|
|
|
|
(AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current !== '1' ||
|
|
|
|
colorScheme === 'no-preference')) ||
|
|
|
|
(AsyncStorageManager.getInstance().preferences.nightModeFollowSystem.current === '1' && colorScheme === 'dark');
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2019-06-29 13:37:21 +02:00
|
|
|
/**
|
|
|
|
* Get the current theme based on night mode
|
|
|
|
* @returns {Object}
|
|
|
|
*/
|
2019-07-31 14:22:36 +02:00
|
|
|
static getCurrentTheme(): Object {
|
2020-03-11 19:55:48 +01:00
|
|
|
if (AprilFoolsManager.getInstance().isAprilFoolsEnabled())
|
|
|
|
return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getWhiteTheme());
|
|
|
|
else
|
|
|
|
return ThemeManager.getBaseTheme()
|
|
|
|
}
|
|
|
|
|
|
|
|
static getBaseTheme() {
|
2019-07-31 14:22:36 +02:00
|
|
|
if (ThemeManager.getNightMode())
|
2020-03-06 23:15:01 +01:00
|
|
|
return ThemeManager.getDarkTheme();
|
2019-06-25 22:20:24 +02:00
|
|
|
else
|
2020-03-06 23:15:01 +01:00
|
|
|
return ThemeManager.getWhiteTheme();
|
2019-06-25 22:20:24 +02:00
|
|
|
}
|
|
|
|
|
2020-03-06 23:15:01 +01:00
|
|
|
/**
|
|
|
|
* Set 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: ?Function) {
|
|
|
|
this.updateThemeCallback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set night mode and save it to preferences
|
|
|
|
*
|
|
|
|
* @param isNightMode Whether to enable night mode
|
|
|
|
*/
|
|
|
|
setNightMode(isNightMode: boolean) {
|
|
|
|
let nightModeKey = AsyncStorageManager.getInstance().preferences.nightMode.key;
|
|
|
|
AsyncStorageManager.getInstance().savePref(nightModeKey, isNightMode ? '1' : '0');
|
|
|
|
if (this.updateThemeCallback !== null)
|
|
|
|
this.updateThemeCallback();
|
2019-06-28 11:35:15 +02:00
|
|
|
}
|
|
|
|
|
2019-06-25 22:20:24 +02:00
|
|
|
};
|