From 9e90c9d8f31f25792abdfd4e00ad37f182c3c971 Mon Sep 17 00:00:00 2001 From: keplyx Date: Sun, 8 Mar 2020 12:50:18 +0100 Subject: [PATCH 1/4] Added basic april fools functionality --- screens/PlanningScreen.js | 3 ++ screens/SelfMenuScreen.js | 29 +++++++++++--------- utils/AprilFoolsManager.js | 56 ++++++++++++++++++++++++++++++++++++++ utils/ThemeManager.js | 31 ++++++++++++++++++++- 4 files changed, 105 insertions(+), 14 deletions(-) create mode 100644 utils/AprilFoolsManager.js diff --git a/screens/PlanningScreen.js b/screens/PlanningScreen.js index c61b97a..9efb51e 100644 --- a/screens/PlanningScreen.js +++ b/screens/PlanningScreen.js @@ -8,6 +8,7 @@ import WebDataManager from "../utils/WebDataManager"; import PlanningEventManager from '../utils/PlanningEventManager'; import {Avatar, Divider, List} from 'react-native-paper'; import CustomAgenda from "../components/CustomAgenda"; +import AprilFoolsManager from "../utils/AprilFoolsManager"; LocaleConfig.locales['fr'] = { monthNames: ['Janvier', 'Février', 'Mars', 'Avril', 'Mai', 'Juin', 'Juillet', 'Août', 'Septembre', 'Octobre', 'Novembre', 'Décembre'], @@ -209,6 +210,8 @@ export default class PlanningScreen extends React.Component { this.pushEventInOrder(agendaItems, eventList[i], PlanningEventManager.getEventStartDate(eventList[i])); } } + if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) + agendaItems["2020-04-01"].push(AprilFoolsManager.getFakeEvent()); this.setState({agendaItems: agendaItems}) } diff --git a/screens/SelfMenuScreen.js b/screens/SelfMenuScreen.js index 690a1cd..478803c 100644 --- a/screens/SelfMenuScreen.js +++ b/screens/SelfMenuScreen.js @@ -5,7 +5,8 @@ import {View} from 'react-native'; import ThemeManager from "../utils/ThemeManager"; import i18n from "i18n-js"; import WebSectionList from "../components/WebSectionList"; -import {Card, Text, Title} from 'react-native-paper'; +import {Card, Text} from 'react-native-paper'; +import AprilFoolsManager from "../utils/AprilFoolsManager"; const DATA_URL = "https://etud.insa-toulouse.fr/~amicale_app/menu/menu_data.json"; @@ -72,6 +73,8 @@ export default class SelfMenuScreen extends React.Component { } ]; } + if (AprilFoolsManager.getInstance().isAprilFoolsEnabled() && fetchedData.length > 0) + fetchedData[0].meal[0].foodcategory = AprilFoolsManager.getFakeMenuItem(fetchedData[0].meal[0].foodcategory); // fetched data is an array here for (let i = 0; i < fetchedData.length; i++) { result.push( @@ -125,18 +128,18 @@ export default class SelfMenuScreen extends React.Component { flex: 0, margin: 10, }}> - - + + {item.dishes.map((object) => diff --git a/utils/AprilFoolsManager.js b/utils/AprilFoolsManager.js new file mode 100644 index 0000000..058738f --- /dev/null +++ b/utils/AprilFoolsManager.js @@ -0,0 +1,56 @@ +// @flow + +/** + * Singleton class used to manage themes + */ +export default class AprilFoolsManager { + + static instance: AprilFoolsManager | null = null; + + aprilFoolsEnabled: boolean; + + constructor() { + let 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 { + return AprilFoolsManager.instance === null ? + AprilFoolsManager.instance = new AprilFoolsManager() : + AprilFoolsManager.instance; + } + + static getFakeEvent() { + return { + category_id: 1, + club: "Coucou", + date_begin: "2020-04-01 20:30:00", + date_end: "2020-04-01 23:59:00", + description: "Trop génial", + id: "-1", + logo: null, + title: "Super event trop whoaou", + url: null + }; + } + + static getFakeMenuItem(menu: Object) { + if (menu[1]["dishes"].length >= 3) { + menu[1]["dishes"].splice(0, 0, {name: "Truc à la con"}); + menu[1]["dishes"].splice(2, 0, {name: "Autre truc à la con"}); + } else { + menu[1]["dishes"].push({name: "Truc à la con"}); + menu[1]["dishes"].push({name: "Autre truc à la con"}); + } + return menu; + } + + isAprilFoolsEnabled() { + return this.aprilFoolsEnabled; + } + +}; diff --git a/utils/ThemeManager.js b/utils/ThemeManager.js index f7e22b5..024e8c4 100644 --- a/utils/ThemeManager.js +++ b/utils/ThemeManager.js @@ -1,8 +1,9 @@ // @flow import AsyncStorageManager from "./AsyncStorageManager"; -// import {DarkTheme as NavDarkTheme, DefaultTheme as NavDefaultTheme} from '@react-navigation/native'; import {DarkTheme, DefaultTheme} from 'react-native-paper'; +import AprilFoolsManager from "./AprilFoolsManager"; + /** * Singleton class used to manage themes */ @@ -92,6 +93,27 @@ export default class ThemeManager { }; } + static getAprilFoolsTheme() { + return { + ...ThemeManager.getBaseTheme(), + colors: { + ...ThemeManager.getBaseTheme().colors, + primary: '#bebe03', + accent: '#bebe03', + background: '#5b3e02', + tabBackground: "#5b3e02", + card: "#5b3e02", + surface: "#5b3e02", + dividerBackground: '#362201', + textDisabled: '#b9b9b9', + + // Calendar/Agenda + agendaBackgroundColor: '#5b3e02', + agendaDayTextColor: '#6d6d6d', + }, + }; + } + /** * Get this class instance or create one if none is found * @returns {ThemeManager} @@ -114,6 +136,13 @@ export default class ThemeManager { * @returns {Object} */ static getCurrentTheme(): Object { + if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) + return ThemeManager.getAprilFoolsTheme(); + else + ThemeManager.getBaseTheme() + } + + static getBaseTheme() { if (ThemeManager.getNightMode()) return ThemeManager.getDarkTheme(); else From c555aabd5a93526efeb9e6a471b800c8b53a7207 Mon Sep 17 00:00:00 2001 From: keplyx Date: Sun, 8 Mar 2020 13:21:14 +0100 Subject: [PATCH 2/4] Show intro slider on first start for april fools --- App.js | 17 +++++++++++++---- components/CustomIntroSlider.js | 22 +++++++++++++++++++--- translations/en.json | 4 ++++ translations/fr.json | 4 ++++ utils/AsyncStorageManager.js | 5 +++++ 5 files changed, 45 insertions(+), 7 deletions(-) diff --git a/App.js b/App.js index c491d35..0e2e740 100644 --- a/App.js +++ b/App.js @@ -12,6 +12,7 @@ import {createStackNavigator} from '@react-navigation/stack'; import DrawerNavigator from './navigation/DrawerNavigator'; import NotificationsManager from "./utils/NotificationsManager"; import {Provider as PaperProvider} from 'react-native-paper'; +import AprilFoolsManager from "./utils/AprilFoolsManager"; type Props = {}; @@ -19,6 +20,7 @@ type State = { isLoading: boolean, showIntro: boolean, showUpdate: boolean, + showAprilFools: boolean, currentTheme: ?Object, }; @@ -30,6 +32,7 @@ export default class App extends React.Component { isLoading: true, showIntro: true, showUpdate: true, + showAprilFools: false, currentTheme: null, }; @@ -68,9 +71,11 @@ export default class App extends React.Component { this.setState({ showIntro: false, showUpdate: false, + showAprilFools: false, }); AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showIntro.key, '0'); AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showUpdate5.key, '0'); + AsyncStorageManager.getInstance().savePref(AsyncStorageManager.getInstance().preferences.showAprilFoolsStart.key, '0'); } async componentDidMount() { @@ -96,7 +101,8 @@ export default class App extends React.Component { isLoading: false, currentTheme: ThemeManager.getCurrentTheme(), showIntro: AsyncStorageManager.getInstance().preferences.showIntro.current === '1', - showUpdate: AsyncStorageManager.getInstance().preferences.showUpdate5.current === '1' + showUpdate: AsyncStorageManager.getInstance().preferences.showUpdate5.current === '1', + showAprilFools: AprilFoolsManager.getInstance().isAprilFoolsEnabled() && AsyncStorageManager.getInstance().preferences.showAprilFoolsStart.current === '1', }); // Status bar goes dark if set too fast setTimeout(this.setupStatusBar, 1000); @@ -109,9 +115,12 @@ export default class App extends React.Component { render() { if (this.state.isLoading) { return null; - } else if (this.state.showIntro || this.state.showUpdate) { - return ; + } else if (this.state.showIntro || this.state.showUpdate || this.state.showAprilFools) { + return ; } else { return ( diff --git a/components/CustomIntroSlider.js b/components/CustomIntroSlider.js index bde99f9..9ca2e50 100644 --- a/components/CustomIntroSlider.js +++ b/components/CustomIntroSlider.js @@ -39,13 +39,15 @@ const styles = StyleSheet.create({ type Props = { onDone: Function, - isUpdate: boolean + isUpdate: boolean, + isAprilFools: boolean, }; export default class CustomIntroSlider extends React.Component { introSlides: Array; updateSlides: Array; + aprilFoolsSlides: Array; constructor() { super(); @@ -108,7 +110,16 @@ export default class CustomIntroSlider extends React.Component { icon: 'email', colors: ['#e01928', '#be1522'], }, - ] + ]; + this.aprilFoolsSlides = [ + { + key: '1', + title: i18n.t('intro.aprilFoolsSlide.title'), + text: i18n.t('intro.aprilFoolsSlide.text'), + icon: 'information', + colors: ['#e01928', '#be1522'], + }, + ]; } @@ -144,10 +155,15 @@ export default class CustomIntroSlider extends React.Component { } render() { + let slides = this.introSlides; + if (this.props.isUpdate) + slides = this.updateSlides; + else if (this.props.isAprilFools) + slides = this.aprilFoolsSlides; return ( Date: Sun, 8 Mar 2020 13:26:14 +0100 Subject: [PATCH 3/4] Fixed crash --- utils/ThemeManager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/ThemeManager.js b/utils/ThemeManager.js index 024e8c4..cdd972f 100644 --- a/utils/ThemeManager.js +++ b/utils/ThemeManager.js @@ -139,7 +139,7 @@ export default class ThemeManager { if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) return ThemeManager.getAprilFoolsTheme(); else - ThemeManager.getBaseTheme() + return ThemeManager.getBaseTheme() } static getBaseTheme() { From bcdd1f9875cb80373fff2cfe73a77fe52172c0a8 Mon Sep 17 00:00:00 2001 From: keplyx Date: Sun, 8 Mar 2020 13:29:43 +0100 Subject: [PATCH 4/4] Moved custom theme in AprilFoolsManager.js --- utils/AprilFoolsManager.js | 21 +++++++++++++++++++++ utils/ThemeManager.js | 23 +---------------------- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/utils/AprilFoolsManager.js b/utils/AprilFoolsManager.js index 058738f..c664210 100644 --- a/utils/AprilFoolsManager.js +++ b/utils/AprilFoolsManager.js @@ -49,6 +49,27 @@ export default class AprilFoolsManager { return menu; } + static getAprilFoolsTheme(currentTheme : Object) { + return { + ...currentTheme, + colors: { + ...currentTheme.colors, + primary: '#bebe03', + accent: '#bebe03', + background: '#5b3e02', + tabBackground: "#5b3e02", + card: "#5b3e02", + surface: "#5b3e02", + dividerBackground: '#362201', + textDisabled: '#b9b9b9', + + // Calendar/Agenda + agendaBackgroundColor: '#5b3e02', + agendaDayTextColor: '#6d6d6d', + }, + }; + } + isAprilFoolsEnabled() { return this.aprilFoolsEnabled; } diff --git a/utils/ThemeManager.js b/utils/ThemeManager.js index cdd972f..90ce5eb 100644 --- a/utils/ThemeManager.js +++ b/utils/ThemeManager.js @@ -93,27 +93,6 @@ export default class ThemeManager { }; } - static getAprilFoolsTheme() { - return { - ...ThemeManager.getBaseTheme(), - colors: { - ...ThemeManager.getBaseTheme().colors, - primary: '#bebe03', - accent: '#bebe03', - background: '#5b3e02', - tabBackground: "#5b3e02", - card: "#5b3e02", - surface: "#5b3e02", - dividerBackground: '#362201', - textDisabled: '#b9b9b9', - - // Calendar/Agenda - agendaBackgroundColor: '#5b3e02', - agendaDayTextColor: '#6d6d6d', - }, - }; - } - /** * Get this class instance or create one if none is found * @returns {ThemeManager} @@ -137,7 +116,7 @@ export default class ThemeManager { */ static getCurrentTheme(): Object { if (AprilFoolsManager.getInstance().isAprilFoolsEnabled()) - return ThemeManager.getAprilFoolsTheme(); + return AprilFoolsManager.getAprilFoolsTheme(ThemeManager.getBaseTheme()); else return ThemeManager.getBaseTheme() }