From 2b42e8e31dd11e45651a656a48d4c2a3d36bb6fe Mon Sep 17 00:00:00 2001 From: Tigran Soghbatyan Date: Thu, 23 Sep 2021 16:37:58 +0200 Subject: [PATCH] [BH-773] Add bedtime reminder application Add bedtime time and on/off UI setup app Add bedtime event notification window Add bedtime audio assets Implement bedtime notification TimeService backend Add bedtime unittests --- image/assets/lang/English.json | 2 + image/assets/lang/Polski.json | 2 + module-apps/apps-common/popups/Popups.cpp | 2 + module-apps/apps-common/popups/Popups.hpp | 4 +- .../include/service-time/AlarmHandler.hpp | 3 +- products/BellHybrid/BellHybridMain.cpp | 2 + products/BellHybrid/CMakeLists.txt | 1 + .../BellHybrid/alarms/BellAlarmHandler.cpp | 15 +++- products/BellHybrid/alarms/CMakeLists.txt | 4 + .../alarms/include/AlarmSoundPaths.hpp | 1 + .../alarms/include/BellAlarmHandler.hpp | 8 ++ .../BedtimeReminderPopupRequestParams.hpp | 16 ++++ .../BellHybrid/alarms/src/AlarmSoundPaths.cpp | 6 ++ .../NotifyGUIBedtimeReminderAction.cpp | 21 +++++ .../NotifyGUIBedtimeReminderAction.hpp | 23 +++++ .../alarms/src/actions/PlayAudioActions.cpp | 10 +++ .../alarms/src/actions/PlayAudioActions.hpp | 11 +++ products/BellHybrid/apps/Application.cpp | 8 ++ products/BellHybrid/apps/CMakeLists.txt | 1 + .../ApplicationBellAlarm.cpp | 3 +- .../ApplicationBellBackgroundSounds.cpp | 3 +- .../ApplicationBellBedtime.cpp | 60 ++++++++++++++ .../application-bell-bedtime/CMakeLists.txt | 38 +++++++++ .../data/BellBedtimeStyle.hpp | 21 +++++ .../ApplicationBellBedtime.hpp | 48 +++++++++++ .../models/BedtimeListItemProvider.cpp | 71 ++++++++++++++++ .../models/BedtimeListItemProvider.hpp | 31 +++++++ .../presenter/BellBedtimeWindowPresenter.cpp | 33 ++++++++ .../presenter/BellBedtimeWindowPresenter.hpp | 58 +++++++++++++ .../windows/BellBedtimeWindow.cpp | 83 +++++++++++++++++++ .../windows/BellBedtimeWindow.hpp | 31 +++++++ .../ApplicationBellMain.cpp | 5 +- .../apps/application-bell-main/CMakeLists.txt | 1 + .../ApplicationBellMain.hpp | 1 + .../windows/BellMainMenuWindow.cpp | 3 +- .../ApplicationBellPowerNap.cpp | 3 +- .../ApplicationBellSettings.cpp | 3 +- .../application-bell-settings/CMakeLists.txt | 2 - .../data/BellSettingsStyle.hpp | 10 +++ .../alarm_settings/AlarmSettingsModel.hpp | 2 +- .../alarm_settings/PrewakeUpSettingsModel.hpp | 2 +- .../alarm_settings/SnoozeSettingsModel.hpp | 2 +- .../BellHybrid/apps/common/CMakeLists.txt | 14 +++- .../BellFinishedCallbackWindowSwitchData.hpp | 37 +++++++++ .../common/models/AbstractBedtimeModel.hpp | 18 ++++ .../include/common/models/BedtimeModel.hpp | 59 +++++++++++++ .../include/common}/models/SettingsModel.hpp | 3 +- .../popups/BedtimeNotificationWindow.hpp | 35 ++++++++ .../widgets/BellSideListItemWithCallbacks.hpp | 2 + .../include/common/widgets/ListItems.hpp | 16 ++++ .../windows/BellFinishedCallbackWindow.hpp | 30 +++++++ .../src/BellSideListItemWithCallbacks.cpp | 11 ++- .../apps/common/src/models/BedtimeModel.cpp | 63 ++++++++++++++ .../src}/models/SettingsModel.cpp | 7 +- .../src/popups/BedtimeNotificationWindow.cpp | 78 +++++++++++++++++ .../apps/common/src/widgets/ListItems.cpp | 20 +++++ .../windows/BellFinishedCallbackWindow.cpp | 60 ++++++++++++++ .../services/appmgr/ApplicationManager.cpp | 1 + .../include/appmgr/messages/AlarmMessage.hpp | 14 ++++ .../services/db/include/db/SystemSettings.hpp | 5 ++ .../services/time/AlarmOperations.cpp | 62 +++++++++++++- .../BellHybrid/services/time/CMakeLists.txt | 2 + .../time/include/time/AlarmOperations.hpp | 27 +++++- .../time/tests/test-BellAlarmOperations.cpp | 54 +++++++++++- 64 files changed, 1242 insertions(+), 30 deletions(-) create mode 100644 products/BellHybrid/alarms/include/popups/BedtimeReminderPopupRequestParams.hpp create mode 100644 products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.cpp create mode 100644 products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.hpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/CMakeLists.txt create mode 100644 products/BellHybrid/apps/application-bell-bedtime/data/BellBedtimeStyle.hpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/include/application-bell-bedtime/ApplicationBellBedtime.hpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.hpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.hpp create mode 100644 products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp create mode 100644 products/BellHybrid/apps/common/include/common/models/AbstractBedtimeModel.hpp create mode 100644 products/BellHybrid/apps/common/include/common/models/BedtimeModel.hpp rename products/BellHybrid/apps/{application-bell-settings => common/include/common}/models/SettingsModel.hpp (86%) create mode 100644 products/BellHybrid/apps/common/include/common/popups/BedtimeNotificationWindow.hpp create mode 100644 products/BellHybrid/apps/common/include/common/windows/BellFinishedCallbackWindow.hpp create mode 100644 products/BellHybrid/apps/common/src/models/BedtimeModel.cpp rename products/BellHybrid/apps/{application-bell-settings => common/src}/models/SettingsModel.cpp (85%) create mode 100644 products/BellHybrid/apps/common/src/popups/BedtimeNotificationWindow.cpp create mode 100644 products/BellHybrid/apps/common/src/windows/BellFinishedCallbackWindow.cpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 6bcb0216804e8d8ad7631587911d4b7244d6f78d..d06cfa99d90e50b45b41d848c6c7076763a4be9b 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -575,6 +575,8 @@ "app_bell_settings_time_units_finished_message": "Time and units are set.", "app_bellmain_alarm": "Alarm", "app_bellmain_bedtime": "Bedtime", + "app_bell_bedtime_set_finished": "Bedtime reminder\nis set", + "app_bell_bedtime_notification": "It is Your bedtime", "app_bellmain_power_nap": "Power nap", "app_bellmain_meditation_timer": "Meditation timer", "app_bellmain_background_sounds": "Background sounds", diff --git a/image/assets/lang/Polski.json b/image/assets/lang/Polski.json index d6c238ba45d5588514ef3670a15f8c3958a6f284..6b4622baa705e787864e7c9db3cd49f97531520e 100644 --- a/image/assets/lang/Polski.json +++ b/image/assets/lang/Polski.json @@ -590,6 +590,8 @@ "app_bell_settings_time_units_finished_message": "Czas i jednostki ustawione.", "app_bellmain_alarm": "Alarm", "app_bellmain_bedtime": "Pora snu", + "app_bell_bedtime_set_finished": "Pora snu\nustawiona", + "app_bell_bedtime_notification": "Pora na sen", "app_bellmain_power_nap": "Drzemka", "app_bellmain_meditation_timer": "Medytacja", "app_bellmain_background_sounds": "Dźwięki otoczenia", diff --git a/module-apps/apps-common/popups/Popups.cpp b/module-apps/apps-common/popups/Popups.cpp index 87a506779d1828aad293c79e217a3073d394777f..5f97395bd136f3ff0e268d938079b3438a90d27d 100644 --- a/module-apps/apps-common/popups/Popups.cpp +++ b/module-apps/apps-common/popups/Popups.cpp @@ -42,6 +42,8 @@ namespace gui::popup return gui::popup::window::power_off_window; case ID::Reboot: return gui::popup::window::reboot_window; + case ID::BedtimeNotification: + return gui::popup::window::bedtime_notification_window; } return {}; diff --git a/module-apps/apps-common/popups/Popups.hpp b/module-apps/apps-common/popups/Popups.hpp index 35df85d89258da0c8fd2f5ff2ca0ba913a261241..13bbdddc62ee9219821f630875bbd58cac6f9138 100644 --- a/module-apps/apps-common/popups/Popups.hpp +++ b/module-apps/apps-common/popups/Popups.hpp @@ -27,7 +27,8 @@ namespace gui AlarmDeactivated, Alarm, PowerOff, - Reboot + Reboot, + BedtimeNotification, }; namespace window @@ -50,6 +51,7 @@ namespace gui inline constexpr auto alarm_deactivated_window = "AlarmDeactivatedPopup"; inline constexpr auto alarm_window = "AlarmPopup"; inline constexpr auto reboot_window = "RebootPopup"; + inline constexpr auto bedtime_notification_window = "BedtimeNotificationPopup"; } // namespace window std::string resolveWindowName(ID id); diff --git a/module-services/service-time/include/service-time/AlarmHandler.hpp b/module-services/service-time/include/service-time/AlarmHandler.hpp index 574668118179528971e5ae3fee158bfa103fc164..6b1127bdaa2d26c455d48bbe11df6df79473d919 100644 --- a/module-services/service-time/include/service-time/AlarmHandler.hpp +++ b/module-services/service-time/include/service-time/AlarmHandler.hpp @@ -15,6 +15,7 @@ namespace alarms PreWakeUpChime, PreWakeUpFrontlight, SnoozeChime, + BedtimeReminder, None }; @@ -23,7 +24,7 @@ namespace alarms public: virtual ~AlarmHandler() = default; - virtual auto handle(const AlarmEventRecord &record) -> bool = 0; + virtual auto handle(const AlarmEventRecord &record) -> bool = 0; virtual auto handleOff(const AlarmEventRecord &record) -> bool = 0; }; } // namespace alarms diff --git a/products/BellHybrid/BellHybridMain.cpp b/products/BellHybrid/BellHybridMain.cpp index b7b68cf57972545cd268153b15d83daaea531008..a4f2b1acb61c9d846d076ebb481e5c3a9c007399 100644 --- a/products/BellHybrid/BellHybridMain.cpp +++ b/products/BellHybrid/BellHybridMain.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -97,6 +98,7 @@ int main() app::CreateLauncher(app::applicationBellName, app::Closeable::False)); applications.push_back(app::CreateLauncher(app::applicationBellSettingsName)); applications.push_back(app::CreateLauncher(app::applicationBellAlarmName)); + applications.push_back(app::CreateLauncher(app::applicationBellBedtimeName)); applications.push_back(app::CreateLauncher(app::applicationBellPowerNapName)); applications.push_back( app::CreateLauncher(app::applicationBellOnBoardingName)); diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 29593ed5333994c80669a8dd888bfc1a22c8c1ba..48f76c9d64c8d6dab855ebd90058ac788051e082 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -41,6 +41,7 @@ target_link_libraries(BellHybrid bell::app-alarm bell::app-onboarding bell::app-background-sounds + bell::app-bedtime bell::app-common bell::app-main bell::app-powernap diff --git a/products/BellHybrid/alarms/BellAlarmHandler.cpp b/products/BellHybrid/alarms/BellAlarmHandler.cpp index ade5e06503b15f011cd70e244bcab3610757f5a1..070f815a00c9f4f2711ee91f0bc672f42c3dd6c5 100644 --- a/products/BellHybrid/alarms/BellAlarmHandler.cpp +++ b/products/BellHybrid/alarms/BellAlarmHandler.cpp @@ -5,6 +5,7 @@ #include "src/actions/PlayAudioActions.hpp" #include "src/actions/NotifyGUIAction.hpp" #include "src/actions/FrontlightAction.hpp" +#include "src/actions/NotifyGUIBedtimeReminderAction.hpp" namespace alarms { @@ -32,8 +33,7 @@ namespace alarms } BellAlarmClockHandler::BellAlarmClockHandler(sys::Service *service) : BellAlarmHandler{getActions(service)} - { - } + {} auto BellAlarmClockHandler::getActions(sys::Service *service) -> Actions { @@ -63,4 +63,15 @@ namespace alarms actions.emplace_back(createSnoozeChimeAction(*service)); return actions; } + + BedtimeReminderHandler::BedtimeReminderHandler(sys::Service *service) : BellAlarmHandler{getActions(service)} + {} + + auto BedtimeReminderHandler::getActions(sys::Service *service) -> Actions + { + Actions actions; + actions.emplace_back(createBedtimeChimeAction(*service)); + actions.emplace_back(std::make_unique(*service)); + return actions; + } } // namespace alarms diff --git a/products/BellHybrid/alarms/CMakeLists.txt b/products/BellHybrid/alarms/CMakeLists.txt index 8bbcf2d664c2210f1a8c5564c989fd8695412a3b..90dbc7eba5c2841dbfc4ab613e51555a08e4ab7f 100644 --- a/products/BellHybrid/alarms/CMakeLists.txt +++ b/products/BellHybrid/alarms/CMakeLists.txt @@ -7,6 +7,7 @@ target_sources(alarms src/AlarmSoundPaths.cpp src/actions/PlayAudioActions.cpp src/actions/NotifyGUIAction.cpp + src/actions/NotifyGUIBedtimeReminderAction.cpp src/actions/FrontlightAction.cpp include/AbstractAlarmAction.hpp @@ -14,10 +15,12 @@ target_sources(alarms src/actions/PlayAudioActions.hpp src/actions/FrontlightAction.hpp src/actions/NotifyGUIAction.hpp + src/actions/NotifyGUIBedtimeReminderAction.hpp PUBLIC include/AlarmSoundPaths.hpp include/popups/AlarmActivatedPopupRequestParams.hpp include/popups/AlarmDeactivatedPopupRequestParams.hpp + include/popups/BedtimeReminderPopupRequestParams.hpp ) target_include_directories(alarms @@ -33,6 +36,7 @@ target_link_libraries(alarms module-audio module-vfs bell::db + bell::appmgr bell::app-common apps-common PUBLIC diff --git a/products/BellHybrid/alarms/include/AlarmSoundPaths.hpp b/products/BellHybrid/alarms/include/AlarmSoundPaths.hpp index 5ddfc6b88afdfeef1d97df3be446954af8f225b9..74139e0151a5f1ac3e69ac4c19894e1992d90080 100644 --- a/products/BellHybrid/alarms/include/AlarmSoundPaths.hpp +++ b/products/BellHybrid/alarms/include/AlarmSoundPaths.hpp @@ -11,4 +11,5 @@ namespace alarms::paths std::filesystem::path getMusicDir() noexcept; std::filesystem::path getPreWakeUpChimesDir() noexcept; std::filesystem::path getSnoozeChimesDir() noexcept; + std::filesystem::path getBedtimeReminderChimesDir() noexcept; } // namespace alarms::paths diff --git a/products/BellHybrid/alarms/include/BellAlarmHandler.hpp b/products/BellHybrid/alarms/include/BellAlarmHandler.hpp index 1ee8ae7b3ecadee28f962a623f4ef2c306f527f3..6c6519380fd70a929a3fcb4194ff6a4f963a6de2 100644 --- a/products/BellHybrid/alarms/include/BellAlarmHandler.hpp +++ b/products/BellHybrid/alarms/include/BellAlarmHandler.hpp @@ -49,4 +49,12 @@ namespace alarms private: static auto getActions(sys::Service *service) -> Actions; }; + class BedtimeReminderHandler : public BellAlarmHandler + { + public: + explicit BedtimeReminderHandler(sys::Service *service); + + private: + static auto getActions(sys::Service *service) -> Actions; + }; } // namespace alarms diff --git a/products/BellHybrid/alarms/include/popups/BedtimeReminderPopupRequestParams.hpp b/products/BellHybrid/alarms/include/popups/BedtimeReminderPopupRequestParams.hpp new file mode 100644 index 0000000000000000000000000000000000000000..22a592e4e13298d7b1ccb6f5a07d61f187efc726 --- /dev/null +++ b/products/BellHybrid/alarms/include/popups/BedtimeReminderPopupRequestParams.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace gui +{ + class BedtimeReminderPopupRequestParams : public PopupRequestParams + { + public: + BedtimeReminderPopupRequestParams() : PopupRequestParams{gui::popup::ID::BedtimeNotification} + {} + }; +} // namespace gui diff --git a/products/BellHybrid/alarms/src/AlarmSoundPaths.cpp b/products/BellHybrid/alarms/src/AlarmSoundPaths.cpp index 07b9a029ce1d2f4f7ef6b28f4f25579a65bf061f..72a922b89a53f1f8e9bb383a8b1ea0448399046c 100644 --- a/products/BellHybrid/alarms/src/AlarmSoundPaths.cpp +++ b/products/BellHybrid/alarms/src/AlarmSoundPaths.cpp @@ -21,8 +21,14 @@ namespace alarms::paths { return purefs::dir::getCurrentOSPath() / "assets/audio/bell/prewakeup"; } + std::filesystem::path getSnoozeChimesDir() noexcept { return purefs::dir::getCurrentOSPath() / "assets/audio/bell/chimes"; } + + std::filesystem::path getBedtimeReminderChimesDir() noexcept + { + return purefs::dir::getCurrentOSPath() / "assets/audio/bell/evening_reminder"; + } } // namespace alarms::paths diff --git a/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.cpp b/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6045756c3c4c1e1214ed0fa90660223e237a137c --- /dev/null +++ b/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "NotifyGUIBedtimeReminderAction.hpp" + +#include +#include + +namespace alarms +{ + NotifyGUIBedtimeReminderAction::NotifyGUIBedtimeReminderAction(sys::Service &service) : service{service} + {} + bool NotifyGUIBedtimeReminderAction::execute() + { + return service.bus.sendUnicast(std::make_shared(), service::name::appmgr); + } + bool NotifyGUIBedtimeReminderAction::turnOff() + { + return true; + } +} // namespace alarms diff --git a/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.hpp b/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0684cfdf76961de5c36385d751d7792531b60c4c --- /dev/null +++ b/products/BellHybrid/alarms/src/actions/NotifyGUIBedtimeReminderAction.hpp @@ -0,0 +1,23 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "AbstractAlarmAction.hpp" + +#include + +namespace alarms +{ + class NotifyGUIBedtimeReminderAction : public AbstractAlarmAction + { + public: + explicit NotifyGUIBedtimeReminderAction(sys::Service &service); + bool execute() override; + bool turnOff() override; + + private: + sys::Service &service; + }; + +} // namespace alarms diff --git a/products/BellHybrid/alarms/src/actions/PlayAudioActions.cpp b/products/BellHybrid/alarms/src/actions/PlayAudioActions.cpp index 2e0a562f3e1109ce80917c5ee20ef669ed475844..534c8d336cb8ce7a043c49e707b144cc9ee7c928 100644 --- a/products/BellHybrid/alarms/src/actions/PlayAudioActions.cpp +++ b/products/BellHybrid/alarms/src/actions/PlayAudioActions.cpp @@ -65,6 +65,11 @@ namespace alarms return play(tonePath, ringingDuration); } + bool PlayBedtimeToneAction::execute() + { + return play(paths::getBedtimeReminderChimesDir() / bedtimeNotificationAudoFile, InfiniteDuration); + } + std::unique_ptr createPreWakeUpChimeAction(sys::Service &service) { return std::make_unique( @@ -76,6 +81,11 @@ namespace alarms return std::make_unique(service, paths::getSnoozeChimesDir(), bell::settings::Snooze::tone); } + std::unique_ptr createBedtimeChimeAction(sys::Service &service) + { + return std::make_unique(service); + } + PlayChimeAction::PlayChimeAction(sys::Service &service, const std::filesystem::path &tonesDirPath, std::string_view toneSetting) diff --git a/products/BellHybrid/alarms/src/actions/PlayAudioActions.hpp b/products/BellHybrid/alarms/src/actions/PlayAudioActions.hpp index 1d34eb64e5c3adddd0f2d48d128789aebddb693c..1a36d756487178c61831ed72bac052209949c71a 100644 --- a/products/BellHybrid/alarms/src/actions/PlayAudioActions.hpp +++ b/products/BellHybrid/alarms/src/actions/PlayAudioActions.hpp @@ -45,6 +45,15 @@ namespace alarms settings::Settings settings; }; + class PlayBedtimeToneAction : public PlayToneAction + { + static auto constexpr bedtimeNotificationAudoFile = "Evening_Horizon.mp3"; + + public: + using PlayToneAction::PlayToneAction; + bool execute() override; + }; + class PlayChimeAction : public PlayAudioAction { public: @@ -61,4 +70,6 @@ namespace alarms std::unique_ptr createPreWakeUpChimeAction(sys::Service &service); std::unique_ptr createSnoozeChimeAction(sys::Service &service); + std::unique_ptr createBedtimeChimeAction(sys::Service &service); + } // namespace alarms diff --git a/products/BellHybrid/apps/Application.cpp b/products/BellHybrid/apps/Application.cpp index 1972de6624f21a6be07a47058aa32688aed1330b..987383eefca9bbc9999b06ba9afc1c6c896e56a7 100644 --- a/products/BellHybrid/apps/Application.cpp +++ b/products/BellHybrid/apps/Application.cpp @@ -15,6 +15,7 @@ #include #include #include +#include namespace app { @@ -58,6 +59,13 @@ namespace app return std::make_unique(app, std::make_unique(app)); }); + break; + case ID::BedtimeNotification: + windowsFactory.attach(window::bedtime_notification_window, + [](app::ApplicationCommon *app, const std::string &name) { + return std::make_unique(app); + }); + break; default: break; } diff --git a/products/BellHybrid/apps/CMakeLists.txt b/products/BellHybrid/apps/CMakeLists.txt index 4a906208192142d93e8238458f603554a53703c8..f013279035bfb1c309733a5d3cbdfca33ec46d2d 100644 --- a/products/BellHybrid/apps/CMakeLists.txt +++ b/products/BellHybrid/apps/CMakeLists.txt @@ -24,6 +24,7 @@ add_subdirectory(application-bell-main) add_subdirectory(application-bell-onboarding) add_subdirectory(application-bell-background-sounds) add_subdirectory(application-bell-alarm) +add_subdirectory(application-bell-bedtime) add_subdirectory(application-bell-settings) add_subdirectory(application-bell-powernap) add_subdirectory(common) diff --git a/products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp b/products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp index aa16bc4aeef84098db45ed51c46de074154b4d11..bf0bba1e2679fdebab60193ee80fc35cce0900f1 100644 --- a/products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp +++ b/products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp @@ -65,7 +65,8 @@ namespace app attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, gui::popup::ID::PowerOff, - gui::popup::ID::Reboot}); + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); } sys::MessagePointer ApplicationBellAlarm::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp b/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp index d6be7c09c60b2b3a6eeffc70fc0d991265782f69..299b624fcc74c8d42810b48ce012ce0b1f121b1c 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp @@ -77,7 +77,8 @@ namespace app attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, gui::popup::ID::PowerOff, - gui::popup::ID::Reboot}); + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); } sys::MessagePointer ApplicationBellBackgroundSounds::DataReceivedHandler(sys::DataMessage *msgl, diff --git a/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp b/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp new file mode 100644 index 0000000000000000000000000000000000000000..138cd5597db95fb792d22df49fad29b041676190 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp @@ -0,0 +1,60 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ApplicationBellBedtime.hpp" +#include "presenter/BellBedtimeWindowPresenter.hpp" +#include "windows/BellBedtimeWindow.hpp" +#include "common/models/BedtimeModel.hpp" +#include "models/BedtimeListItemProvider.hpp" + +#include +namespace app +{ + ApplicationBellBedtime::ApplicationBellBedtime(std::string name, + std::string parent, + StatusIndicators statusIndicators, + StartInBackground startInBackground) + : Application(name, parent, statusIndicators, startInBackground) + {} + + sys::ReturnCodes ApplicationBellBedtime::InitHandler() + { + auto ret = Application::InitHandler(); + if (ret != sys::ReturnCodes::Success) { + return ret; + } + + createUserInterface(); + + return sys::ReturnCodes::Success; + } + + void ApplicationBellBedtime::createUserInterface() + { + windowsFactory.attach(gui::name::window::main_window, [this](ApplicationCommon *app, const std::string &) { + auto bedtimeModel = std::make_unique(app); + auto provider = std::make_shared(std::move(bedtimeModel)); + auto presenter = std::make_unique(provider); + return std::make_unique(app, std::move(presenter)); + }); + + windowsFactory.attach(gui::BellFinishedCallbackWindow::defaultName, + [](ApplicationCommon *app, const std::string &name) { + return std::make_unique(app); + }); + + attachPopups({gui::popup::ID::AlarmActivated, + gui::popup::ID::AlarmDeactivated, + gui::popup::ID::PowerOff, + gui::popup::ID::Reboot}); + } + + sys::MessagePointer ApplicationBellBedtime::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) + { + auto retMsg = Application::DataReceivedHandler(msgl); + if (dynamic_cast(retMsg.get())->retCode == sys::ReturnCodes::Success) { + return retMsg; + } + return handleAsyncResponse(resp); + } +} // namespace app diff --git a/products/BellHybrid/apps/application-bell-bedtime/CMakeLists.txt b/products/BellHybrid/apps/application-bell-bedtime/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..0dcedb351c4ea64fb352fe798e937c7b6c450a69 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/CMakeLists.txt @@ -0,0 +1,38 @@ +add_library(application-bell-bedtime) +add_library(bell::app-bedtime ALIAS application-bell-bedtime) + +target_sources(application-bell-bedtime + PRIVATE + ApplicationBellBedtime.cpp + models/BedtimeListItemProvider.cpp + presenter/BellBedtimeWindowPresenter.cpp + windows/BellBedtimeWindow.cpp + PRIVATE + data/BellBedtimeStyle.hpp + models/BedtimeListItemProvider.hpp + presenter/BellBedtimeWindowPresenter.hpp + windows/BellBedtimeWindow.hpp + PUBLIC + include/application-bell-bedtime/ApplicationBellBedtime.hpp +) + +target_include_directories(application-bell-bedtime + PRIVATE + $ + $ + PUBLIC + $ +) + +target_link_libraries(application-bell-bedtime + PRIVATE + app + bellgui + bell::app-common + bell::db + date::date + service-appmgr + PUBLIC + module-gui + bell::app-common +) diff --git a/products/BellHybrid/apps/application-bell-bedtime/data/BellBedtimeStyle.hpp b/products/BellHybrid/apps/application-bell-bedtime/data/BellBedtimeStyle.hpp new file mode 100644 index 0000000000000000000000000000000000000000..20977c0bc503cc7c4cebab10091a17c1d2c14f76 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/data/BellBedtimeStyle.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +namespace gui +{ + namespace bell_bedtime_style + { + namespace time_set_fmt_spinner + { + inline constexpr auto focusFont = style::window::font::supersizeme; + inline constexpr auto noFocusFont = style::window::font::supersizemelight; + } // namespace time_set_fmt_spinner + + namespace top_text + { + inline constexpr auto font = style::window::font::largelight; + } + } // namespace bell_bedtime_style +} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-bedtime/include/application-bell-bedtime/ApplicationBellBedtime.hpp b/products/BellHybrid/apps/application-bell-bedtime/include/application-bell-bedtime/ApplicationBellBedtime.hpp new file mode 100644 index 0000000000000000000000000000000000000000..2175ba21f29f673e51dc0beeceba7670524dce50 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/include/application-bell-bedtime/ApplicationBellBedtime.hpp @@ -0,0 +1,48 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +namespace gui::window::name +{ + inline constexpr auto bellBedtime = "BellBedtime"; + inline constexpr auto bellBedtimeOnOff = "bellBedtimeOnff"; + +} // namespace gui::window::name + +namespace app +{ + inline constexpr auto applicationBellBedtimeName = "ApplicationBellBedtime"; + + class ApplicationBellBedtime : public Application + { + public: + explicit ApplicationBellBedtime(std::string name = applicationBellBedtimeName, + std::string parent = "", + StatusIndicators statusIndicators = StatusIndicators{}, + StartInBackground startInBackground = {false}); + + auto InitHandler() -> sys::ReturnCodes override; + + void createUserInterface() override; + void destroyUserInterface() override + {} + + sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; + + auto SwitchPowerModeHandler(const sys::ServicePowerMode mode) -> sys::ReturnCodes override final + { + return sys::ReturnCodes::Success; + } + }; + + template <> struct ManifestTraits + { + static auto GetManifest() -> manager::ApplicationManifest + { + return {{manager::actions::Launch}}; + } + }; +} // namespace app diff --git a/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp b/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4d8c99aa8fa818030eb0e75ce7da29033a4e8d17 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.cpp @@ -0,0 +1,71 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BedtimeListItemProvider.hpp" +#include "common/widgets/ListItems.hpp" +#include "data/BellBedtimeStyle.hpp" + +#include +#include +#include + +namespace app::bell_bedtime +{ + using namespace gui; + + BedtimeListItemProvider::BedtimeListItemProvider(std::unique_ptr &&model) + : model{std::move(model)} + { + buildListItems(); + } + + void BedtimeListItemProvider::buildListItems() + { + constexpr auto itemCount = 2U; + internalData.reserve(itemCount); + + auto onOff = new OnOffListItem(model.get()->getBedtimeOnOff(), utils::translate("app_bellmain_bedtime")); + onOff->onProceed = [onOff, this]() { + if (not onOff->isActive()) { + this->onExit(false); + } + }; + internalData.emplace_back(onOff); + internalData.emplace_back(new TimeListItem(model.get()->getBedtimeTime(), + stm::api::timeFormat(), + bell_bedtime_style::time_set_fmt_spinner::focusFont, + bell_bedtime_style::time_set_fmt_spinner::noFocusFont, + utils::translate("app_bellmain_bedtime"))); + + for (auto item : internalData) { + item->deleteByList = false; + } + } + + auto BedtimeListItemProvider::requestRecords(uint32_t offset, uint32_t limit) -> void + { + setupModel(offset, limit); + list->onProviderDataUpdate(); + } + + auto BedtimeListItemProvider::getItem(Order order) -> ListItem * + { + return getRecord(order); + } + + auto BedtimeListItemProvider::requestRecordsCount() -> unsigned int + { + return internalData.size(); + } + + auto BedtimeListItemProvider::getMinimalItemSpaceRequired() const -> unsigned int + { + return style::sidelistview::list_item::w; + } + + auto BedtimeListItemProvider::getListItems() -> std::vector + { + return internalData; + } + +} // namespace app::bell_bedtime diff --git a/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.hpp b/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.hpp new file mode 100644 index 0000000000000000000000000000000000000000..35c04e3dfec3bbedbdc049a9383dde0dbb70627c --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/models/BedtimeListItemProvider.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include + +namespace app::bell_bedtime +{ + class BedtimeListItemProvider : public app::InternalModel, + public gui::ListItemProvider + { + public: + explicit BedtimeListItemProvider(std::unique_ptr &&model); + auto getListItems() -> std::vector; + auto requestRecords(uint32_t offset, uint32_t limit) -> void override; + [[nodiscard]] auto getItem(gui::Order order) -> gui::ListItem * override; + [[nodiscard]] auto requestRecordsCount() -> unsigned int override; + [[nodiscard]] auto getMinimalItemSpaceRequired() const -> unsigned int override; + + std::function onExit; + + private: + void buildListItems(); + + std::unique_ptr model; + }; + +} // namespace app::bell_bedtime diff --git a/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7fdacfb965c0f790bde6cf7499916aefc5247b7a --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellBedtimeWindowPresenter.hpp" +#include "models/BedtimeListItemProvider.hpp" + +namespace app::bell_bedtime +{ + BellBedtimeWindowPresenter::BellBedtimeWindowPresenter(std::shared_ptr provider) + : provider{provider} + { + provider->onExit = [this](bool showSuccessWindow) { getView()->exit(showSuccessWindow); }; + } + + void BellBedtimeWindowPresenter::saveData() + { + for (const auto &item : provider->getListItems()) { + item->getValue(); + } + } + + void BellBedtimeWindowPresenter::loadData() + { + for (const auto &item : provider->getListItems()) { + item->setValue(); + } + } + + auto BellBedtimeWindowPresenter::getPagesProvider() const -> std::shared_ptr + { + return provider; + } +} // namespace app::bell_bedtime diff --git a/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8f5be981ae3d0e0d15b0b36479f602a8f851e3aa --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/presenter/BellBedtimeWindowPresenter.hpp @@ -0,0 +1,58 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include "common/models/AbstractBedtimeModel.hpp" + +namespace app +{ + class ApplicationCommon; +} + +namespace settings +{ + class Settings; +} + +namespace gui +{ + class AppWindow; + class ListItemProvider; +} // namespace gui + +namespace app::bell_bedtime +{ + class BedtimeListItemProvider; + + class View + { + public: + virtual ~View() noexcept = default; + virtual void exit(bool showSuccessWindow) = 0; + }; + + class AbstractBedtimePresenter : public BasePresenter + { + public: + virtual ~AbstractBedtimePresenter() noexcept = default; + virtual auto getPagesProvider() const -> std::shared_ptr = 0; + virtual void saveData() = 0; + virtual void loadData() = 0; + }; + + class BellBedtimeWindowPresenter : public AbstractBedtimePresenter + { + private: + std::shared_ptr provider; + std::unique_ptr settings; + + public: + explicit BellBedtimeWindowPresenter(std::shared_ptr provider); + auto getPagesProvider() const -> std::shared_ptr override; + void saveData() override; + void loadData() override; + }; +} // namespace app::bell_bedtime diff --git a/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4988ef0e03cc76565f21eb2dacd46699aba58f3c --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp @@ -0,0 +1,83 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellBedtimeWindow.hpp" + +#include +#include + +#include +#include + +#include +#include +#include + +#include +#include +#include "service-appmgr/Controller.hpp" // for Controller + +namespace gui +{ + BellBedtimeWindow::BellBedtimeWindow( + app::ApplicationCommon *app, + std::unique_ptr &&windowPresenter, + std::string name) + : AppWindow(app, std::move(name)), presenter{std::move(windowPresenter)} + { + presenter->attach(this); + buildInterface(); + } + + void BellBedtimeWindow::buildInterface() + { + AppWindow::buildInterface(); + + statusBar->setVisible(false); + header->setTitleVisibility(true); + bottomBar->setVisible(false); + + listView = new SideListView( + this, 0U, 0U, this->getWidth(), this->getHeight(), presenter->getPagesProvider(), PageBarType::None); + listView->setEdges(RectangleEdge::None); + + listView->rebuildList(listview::RebuildType::Full); + + presenter->loadData(); + + setFocusItem(listView); + } + + bool BellBedtimeWindow::onInput(const InputEvent &inputEvent) + { + if (listView->onInput(inputEvent)) { + return true; + } + if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) { + exit(true); + return true; + } + return AppWindow::onInput(inputEvent); + } + + void BellBedtimeWindow::rebuild() + { + erase(); + buildInterface(); + } + + void BellBedtimeWindow::exit(bool showSuccessWindow) + { + presenter->saveData(); + if (showSuccessWindow) { + application->switchWindow(BellFinishedCallbackWindow::defaultName, + BellFinishedCallbackWindowSwitchData::Factory::create( + "circle_success", + utils::translate("app_bell_bedtime_set_finished"), + [this]() { app::manager::Controller::switchBack(application); })); + } + else { + application->returnToPreviousWindow(); + } + } +} /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.hpp b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..7a1f6b3983b1cb5dbe4ddbbc5617b79f16605fd2 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "ApplicationBellBedtime.hpp" +#include "presenter/BellBedtimeWindowPresenter.hpp" + +#include + +namespace gui +{ + class SideListView; + + class BellBedtimeWindow : public AppWindow, public app::bell_bedtime::View + { + public: + BellBedtimeWindow(app::ApplicationCommon *app, + std::unique_ptr &&windowPresenter, + std::string name = window::name::bellBedtime); + + void buildInterface() override; + auto onInput(const InputEvent &inputEvent) -> bool override; + void rebuild() override; + void exit(bool showSuccessWindow) override; + + private: + SideListView *listView{}; + std::unique_ptr presenter; + }; +} /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp index c35d5e7d73a4c036941861e8b5de31c6a993b3de..07f942eec6d888fa5d397c96cef4d9ca584cc9dc 100644 --- a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +++ b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp @@ -15,6 +15,8 @@ #include #include #include +#include +#include namespace app { @@ -72,7 +74,8 @@ namespace app attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, gui::popup::ID::PowerOff, - gui::popup::ID::Reboot}); + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); } sys::MessagePointer ApplicationBellMain::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/products/BellHybrid/apps/application-bell-main/CMakeLists.txt b/products/BellHybrid/apps/application-bell-main/CMakeLists.txt index a619fb8707248ac9c9b75fb7f34ea5c0ed507fbf..d9775ecd1545525eb46ce731cba3c6fc2ab29f3d 100644 --- a/products/BellHybrid/apps/application-bell-main/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-main/CMakeLists.txt @@ -53,6 +53,7 @@ target_link_libraries(application-bell-main bell::app-alarm bell::app-onboarding bell::app-background-sounds + bell::app-bedtime bell::app-settings bell::app-powernap bell::keymap diff --git a/products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp b/products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp index bc6547e794705708a85c208c82a6aea3edd730b2..4d641e466b86a62e0760a62cfdfe2e285efc5e6e 100644 --- a/products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp +++ b/products/BellHybrid/apps/application-bell-main/include/application-bell-main/ApplicationBellMain.hpp @@ -4,6 +4,7 @@ #pragma once #include +#include namespace gui::window::name { diff --git a/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp b/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp index c5867f5c7d1ce95eb8c09555244e19beb698dec2..2da0ed75c8bdad7301ff9ace462a0441e69a1b0b 100644 --- a/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp +++ b/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -70,7 +71,7 @@ namespace gui addAppMenu(utils::translate("app_bellmain_background_sounds"), app::applicationBellBackgroundSoundsName); // for demo only - to be replaced by call o final window addWinMenu(utils::translate("app_bellmain_meditation_timer"), gui::window::name::bell_main_menu_dialog); - addWinMenu(utils::translate("app_bellmain_bedtime"), gui::window::name::bell_main_menu_dialog); + addAppMenu(utils::translate("app_bellmain_bedtime"), app::applicationBellBedtimeName); addAppMenu(utils::translate("app_bellmain_settings"), app::applicationBellSettingsName); diff --git a/products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp b/products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp index 4270b51c599c8b46fa2b9b94f7ea1142d43bd341..3957eefea460871c244b573805fcbb25c696e703 100644 --- a/products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp +++ b/products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp @@ -56,7 +56,8 @@ namespace app attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, gui::popup::ID::PowerOff, - gui::popup::ID::Reboot}); + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); } sys::MessagePointer ApplicationBellPowerNap::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index 3c6fd7c4ac22c80a9d8709b99df97edcedbf1604..2fade5f32b3a200d04435ce7afeaaa996f56f6aa 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -205,7 +205,8 @@ namespace app attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, gui::popup::ID::PowerOff, - gui::popup::ID::Reboot}); + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); } sys::MessagePointer ApplicationBellSettings::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt index 9c6fac8d8d531cd0e6f1b2a49f5993a9af62b48d..46ac046c0b5d4ad7be62ba335f9d99ca93a61ecd 100644 --- a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt @@ -23,7 +23,6 @@ target_sources(application-bell-settings PRIVATE ApplicationBellSettings.cpp models/FrontlightModel.cpp - models/SettingsModel.cpp models/TemperatureUnitModel.cpp models/TimeUnitsModel.cpp models/advanced/AboutYourBellModel.cpp @@ -61,7 +60,6 @@ target_sources(application-bell-settings windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp windows/alarm_settings/BellSettingsPrewakeUpWindow.cpp - models/SettingsModel.hpp models/advanced/AboutYourBellModel.hpp models/alarm_settings/AbstractAlarmSettingsModel.hpp models/alarm_settings/AbstractPrewakeUpSettingsModel.hpp diff --git a/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp b/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp index d64021d30a18a0613fee055c9b95257be589f57c..5c7c067867ceebdf2e54c08c1e350be66cd1546e 100644 --- a/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp +++ b/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp @@ -49,5 +49,15 @@ namespace gui inline constexpr auto value_height = 33; } // namespace list_item } // namespace about_your_bell_window + namespace bedtime_settings_window + { + inline constexpr auto options_list_margin_x = 100U; + inline constexpr auto options_list_margin_y = 110U; + inline constexpr auto default_body_width = 400U; + } // namespace bedtime_settings_window + namespace bedtime_settings_chime_tone + { + inline constexpr auto font_center = "gt_pressura_light_46"; + } } // namespace bell_settings_style } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.hpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.hpp index 2c9a7b6e37eee0ea371b3d310259f5899e3dd44a..758293c384b8acc73aaf8d58a5a1c82615e71cd5 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.hpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsModel.hpp @@ -4,7 +4,7 @@ #pragma once #include "AbstractAlarmSettingsModel.hpp" -#include +#include namespace app::bell_settings { diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.hpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.hpp index 2e4c0ace927fedb66c6d7a9ffd081e9e8c6f4bdd..f095c74df7e732eff6359899d057c82a392a908c 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.hpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpSettingsModel.hpp @@ -4,7 +4,7 @@ #pragma once #include "AbstractPrewakeUpSettingsModel.hpp" -#include +#include namespace app::bell_settings { diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.hpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.hpp index 03a9bee6a4cde603fe55c4735ea6d97f1e0620a5..e211ff4e7a62e5fff37a9725978dd8219b6b7330 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.hpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.hpp @@ -4,7 +4,7 @@ #pragma once #include "AbstractSnoozeSettingsModel.hpp" -#include +#include namespace app::bell_settings { diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index 002cce1bfbdd8277ca5befa49055b0b9f7fb0685..bae69d126c122fe88e387ccefbb952f75ec72f42 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -16,15 +16,21 @@ target_sources(application-bell-common src/TimeModel.cpp src/SoundsRepository.cpp src/windows/BellFinishedWindow.cpp + src/windows/BellFinishedCallbackWindow.cpp src/windows/BellTurnOffWindow.cpp src/windows/BellWelcomeWindow.cpp src/BellSideListItemWithCallbacks.cpp src/TimeUtils.cpp - src/popups/presenter/AlarmActivatedPresenter.cpp + src/TimeUtils.cpp + src/models/SettingsModel.cpp + src/models/BedtimeModel.cpp src/popups/AlarmActivatedWindow.cpp + src/popups/AlarmActivatedWindow.cpp + src/popups/BedtimeNotificationWindow.cpp src/popups/AlarmDeactivatedWindow.cpp src/popups/BellTurnOffOptionWindow.cpp src/popups/BellRebootWindow.cpp + src/popups/presenter/AlarmActivatedPresenter.cpp src/widgets/ListItems.cpp src/widgets/BellStatusClock.cpp @@ -35,18 +41,24 @@ target_sources(application-bell-common include/common/SoundsRepository.hpp include/common/BellPowerOffPresenter.hpp include/common/windows/BellFinishedWindow.hpp + include/common/windows/BellFinishedCallbackWindow.hpp include/common/windows/BellTurnOffWindow.hpp include/common/windows/BellWelcomeWindow.hpp include/common/TimeUtils.hpp + include/common/data/BellFinishedCallbackWindowSwitchData.hpp include/common/models/AbstractAlarmModel.hpp + include/common/models/AbstractBedtimeModel.hpp include/common/models/AbstractSettingsModel.hpp include/common/models/AbstractAudioModel.hpp include/common/models/AlarmModel.hpp + include/common/models/SettingsModel.hpp + include/common/models/BedtimeModel.hpp include/common/models/TimeModel.hpp include/common/models/AudioModel.hpp include/common/popups/presenter/AlarmActivatedPresenter.hpp include/common/popups/AlarmActivatedWindow.hpp include/common/popups/AlarmDeactivatedWindow.hpp + include/common/popups/BedtimeNotificationWindow.hpp include/common/popups/BellTurnOffOptionWindow.hpp include/common/popups/BellRebootWindow.hpp include/common/widgets/BellSideListItemWithCallbacks.hpp diff --git a/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp b/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp new file mode 100644 index 0000000000000000000000000000000000000000..73595d642f4b5f00f4485fd2837280f43e26da42 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include // for function +#include +#include + +namespace gui +{ + struct BellFinishedCallbackWindowSwitchData : public gui::SwitchData + { + public: + struct Factory + { + static std::unique_ptr create(const UTF8 &icon, + const UTF8 &text, + std::function finishCallback) + { + return std::unique_ptr( + new BellFinishedCallbackWindowSwitchData(icon, text, finishCallback)); + } + }; + + UTF8 icon{}; + UTF8 text{}; + std::function finishCallback; + + private: + BellFinishedCallbackWindowSwitchData() = default; + + BellFinishedCallbackWindowSwitchData(const UTF8 &icon, const UTF8 &text, std::function finishCallback) + : icon{icon}, text{text}, finishCallback{finishCallback} + {} + }; +} // namespace gui diff --git a/products/BellHybrid/apps/common/include/common/models/AbstractBedtimeModel.hpp b/products/BellHybrid/apps/common/include/common/models/AbstractBedtimeModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f4108abf66ce677ceaf23f5c0f2593a5ab12f4af --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/models/AbstractBedtimeModel.hpp @@ -0,0 +1,18 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "common/models/AbstractSettingsModel.hpp" +#include + +namespace app +{ + class AbstractBedtimeModel + { + public: + virtual ~AbstractBedtimeModel() = default; + virtual auto getBedtimeOnOff() -> gui::AbstractSettingsModel & = 0; + virtual auto getBedtimeTime() -> gui::AbstractSettingsModel & = 0; + }; +} // namespace app diff --git a/products/BellHybrid/apps/common/include/common/models/BedtimeModel.hpp b/products/BellHybrid/apps/common/include/common/models/BedtimeModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..4d0844eb860244ba4aad53a7599bfd7d46414123 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/models/BedtimeModel.hpp @@ -0,0 +1,59 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "AbstractBedtimeModel.hpp" +#include "SettingsModel.hpp" +#include +#include + +namespace app::bell_bedtime +{ + inline constexpr auto DEFAULT_BEDTIME_TIME = "21:00"; + class BedtimeOnOffModel : public gui::SettingsModel + { + public: + using SettingsModel::SettingsModel; + + void setValue(bool value) override; + auto getValue() const -> bool override; + }; + + class BedtimeTimeModel : public gui::SettingsModel + { + auto writeString(std::string str) -> void; + auto readString() const -> std::string; + auto getTmFromString(const std::string &str, std::tm &tm) const -> bool; + + public: + using SettingsModel::SettingsModel; + + void setValue(time_t value) override; + auto getValue() const -> time_t override; + }; + + class BedtimeModel : public AbstractBedtimeModel + { + public: + BedtimeModel() = delete; + + explicit BedtimeModel(sys::Service *app) + { + bedtimeOnOff = std::make_unique(app); + bedtimeTime = std::make_unique(app); + } + gui::AbstractSettingsModel &getBedtimeOnOff() override + { + return *bedtimeOnOff; + } + gui::AbstractSettingsModel &getBedtimeTime() override + { + return *bedtimeTime; + } + + private: + std::unique_ptr> bedtimeOnOff; + std::unique_ptr> bedtimeTime; + }; +} // namespace app::bell_bedtime diff --git a/products/BellHybrid/apps/application-bell-settings/models/SettingsModel.hpp b/products/BellHybrid/apps/common/include/common/models/SettingsModel.hpp similarity index 86% rename from products/BellHybrid/apps/application-bell-settings/models/SettingsModel.hpp rename to products/BellHybrid/apps/common/include/common/models/SettingsModel.hpp index cbf161037ae454aac8c76623064d532a3456abfa..1802035ae1fac3527dd31f33dcdf9f5c3391efe8 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/SettingsModel.hpp +++ b/products/BellHybrid/apps/common/include/common/models/SettingsModel.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace app { @@ -17,7 +18,7 @@ namespace gui template class SettingsModel : public AbstractSettingsModel { public: - explicit SettingsModel(app::ApplicationCommon *app); + explicit SettingsModel(sys::Service *app); protected: mutable settings::Settings settings; diff --git a/products/BellHybrid/apps/common/include/common/popups/BedtimeNotificationWindow.hpp b/products/BellHybrid/apps/common/include/common/popups/BedtimeNotificationWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8eb7dc1bc72aa91951da652409183c28cbec09e5 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/popups/BedtimeNotificationWindow.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include + +namespace app +{ + class ApplicationCommon; +} +namespace gui +{ + class Icon; + + class BedtimeNotificationWindow : public WindowWithTimer, public app::AsyncCallbackReceiver + { + private: + static constexpr auto bedtimeNotificationIcon = "big_bedtime_W_G"; + static constexpr auto bedtimeNotificationText = "app_bell_bedtime_notification"; + static constexpr auto bedtimeNotificationTimout = std::chrono::seconds{6}; + + app::ApplicationCommon *app; + Icon *icon = nullptr; + void onClose(CloseReason reason) override; + bool onInput(const InputEvent &inputEvent) override; + void returnToPreviousWindow(); + void buildInterface() override; + + public: + explicit BedtimeNotificationWindow(app::ApplicationCommon *app); + void onBeforeShow(ShowMode mode, SwitchData *data) override; + }; +} /* namespace gui */ diff --git a/products/BellHybrid/apps/common/include/common/widgets/BellSideListItemWithCallbacks.hpp b/products/BellHybrid/apps/common/include/common/widgets/BellSideListItemWithCallbacks.hpp index 65be67a46d67945eaf0df634d6097096bf172382..454bdf37052da6b66a68e467b7e5d1305c00e476 100644 --- a/products/BellHybrid/apps/common/include/common/widgets/BellSideListItemWithCallbacks.hpp +++ b/products/BellHybrid/apps/common/include/common/widgets/BellSideListItemWithCallbacks.hpp @@ -19,6 +19,8 @@ namespace gui std::function onEnter; std::function onExit; + std::function onProceed; + protected: void OnFocusChangedCallback(); }; diff --git a/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp b/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp index 8e82ab1c0277eda237b8dac0b302e6ad2d9e7475..87ca1fc99ddb5901852141516365ababed997112 100644 --- a/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp +++ b/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp @@ -8,7 +8,10 @@ #include #include +#include + #include +#include