From 0d63700892aee74c2895e84facc34b1a162d8bf9 Mon Sep 17 00:00:00 2001 From: Dawid Wojtas Date: Tue, 16 Jul 2024 15:19:58 +0200 Subject: [PATCH] [BH-2031] Add relaxation fade option in settings It adds a new option in settings menu that configures the fade effect in the relaxation app. --- image/system_a/data/lang/Deutsch.json | 2 + image/system_a/data/lang/English.json | 2 + image/system_a/data/lang/Espanol.json | 2 + image/system_a/data/lang/Francais.json | 2 + image/system_a/data/lang/Polski.json | 2 + .../ApplicationBellRelaxation.cpp | 4 +- .../ApplicationBellRelaxation.hpp | 2 + .../widgets/RelaxationPlayer.cpp | 10 ++- .../widgets/RelaxationPlayer.hpp | 6 +- .../ApplicationBellSettings.cpp | 12 ++++ .../application-bell-settings/CMakeLists.txt | 3 + .../data/BellSettingsStyle.hpp | 4 +- .../ApplicationBellSettings.hpp | 1 + .../models/RelaxationListItemProvider.cpp | 65 ++++++++++++++++++ .../models/RelaxationListItemProvider.hpp | 30 +++++++++ .../presenter/RelaxationWindowPresenter.cpp | 33 ++++++++++ .../presenter/RelaxationWindowPresenter.hpp | 46 +++++++++++++ .../alarm_settings/SnoozePresenter.hpp | 38 ++++++----- .../windows/BellSettingsRelaxationWindow.cpp | 66 +++++++++++++++++++ .../windows/BellSettingsRelaxationWindow.hpp | 31 +++++++++ .../windows/BellSettingsWindow.cpp | 3 + .../BellSettingsAlarmSettingsSnoozeWindow.hpp | 2 +- .../BellHybrid/apps/common/CMakeLists.txt | 3 + .../models/AbstractRelaxationFadeModel.hpp | 16 +++++ .../common/models/RelaxationFadeModel.hpp | 39 +++++++++++ .../common/src/models/RelaxationFadeModel.cpp | 21 ++++++ .../services/db/include/db/SystemSettings.hpp | 5 ++ 27 files changed, 427 insertions(+), 23 deletions(-) create mode 100644 products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.hpp create mode 100644 products/BellHybrid/apps/common/include/common/models/AbstractRelaxationFadeModel.hpp create mode 100644 products/BellHybrid/apps/common/include/common/models/RelaxationFadeModel.hpp create mode 100644 products/BellHybrid/apps/common/src/models/RelaxationFadeModel.cpp diff --git a/image/system_a/data/lang/Deutsch.json b/image/system_a/data/lang/Deutsch.json index 97f2469b71215ccd22ea3b59432d6b376f794e2c..d77ac1357ccdb7c1445f8c676509faa1be9b15df 100644 --- a/image/system_a/data/lang/Deutsch.json +++ b/image/system_a/data/lang/Deutsch.json @@ -140,6 +140,8 @@ "app_bell_settings_alarm_settings_sounds": "T\u00f6ne", "app_bell_settings_alarm_settings_title": "Alarmeinstellungen", "app_bell_settings_alarm_settings_volume": "Alarmlautst\u00e4rke", + "app_bell_settings_relaxation_fade": "Entspannung", + "app_bell_settings_relaxation_fade_message": "Erh\u00f6ht allm\u00e4hlich Erholungslautst\u00e4rke", "app_bell_settings_bedtime_chime": "Schlafenszeit", "app_bell_settings_bedtime_settings_tone": "Schlafenszeitton", "app_bell_settings_bedtime_settings_volume": "Schlafenszeit Lautst\u00e4rke", diff --git a/image/system_a/data/lang/English.json b/image/system_a/data/lang/English.json index a046ded3fcef3e538651944bf19d03aede6c2c43..dc4e57fe61a4b6058facb0ab745edac673f2c3ae 100644 --- a/image/system_a/data/lang/English.json +++ b/image/system_a/data/lang/English.json @@ -142,6 +142,8 @@ "app_bell_settings_alarm_settings_sounds": "Sounds", "app_bell_settings_alarm_settings_title": "Alarm settings", "app_bell_settings_alarm_settings_volume": "Main alarm volume", + "app_bell_settings_relaxation_fade": "Relaxation", + "app_bell_settings_relaxation_fade_message": "Gradually raise the relaxation volume", "app_bell_settings_bedtime_chime": "Bedtime", "app_bell_settings_bedtime_settings_tone": "Bedtime chime", "app_bell_settings_bedtime_settings_volume": "Bedtime volume", diff --git a/image/system_a/data/lang/Espanol.json b/image/system_a/data/lang/Espanol.json index 3dfb8fc08c11461937b4f92bff7673319b344d89..1ccee9d5c74eea462cc3094eb9a087bd5b264afb 100644 --- a/image/system_a/data/lang/Espanol.json +++ b/image/system_a/data/lang/Espanol.json @@ -139,6 +139,8 @@ "app_bell_settings_alarm_settings_sounds": "Sonidos", "app_bell_settings_alarm_settings_title": "Ajustes de alarma", "app_bell_settings_alarm_settings_volume": "Volumen de alarma", + "app_bell_settings_relaxation_fade": "Relajaci\u00f3n", + "app_bell_settings_relaxation_fade_message": "Aumentar la relajaci\u00f3n gradualmente", "app_bell_settings_bedtime_chime": "Hora de dormir", "app_bell_settings_bedtime_settings_tone": "Alarma de dormir", "app_bell_settings_bedtime_settings_volume": "Volumen para la hora de dormir", diff --git a/image/system_a/data/lang/Francais.json b/image/system_a/data/lang/Francais.json index f4271e9d7f98bc4c6d47deb95abcdb80132b805b..da051f07a50578d7837f78ee4a01db042d0f0e5c 100644 --- a/image/system_a/data/lang/Francais.json +++ b/image/system_a/data/lang/Francais.json @@ -141,6 +141,8 @@ "app_bell_settings_alarm_settings_sounds": "Sons", "app_bell_settings_alarm_settings_title": "Alarme", "app_bell_settings_alarm_settings_volume": "Volume", + "app_bell_settings_relaxation_fade": "Bruits de fond", + "app_bell_settings_relaxation_fade_message": "Hausse graduelle du vol. de d\u00e9tente", "app_bell_settings_bedtime_chime": "Heure du coucher", "app_bell_settings_bedtime_settings_tone": "Son pr\u00e9-sommeil", "app_bell_settings_bedtime_settings_volume": "Volume de l'heure du coucher", diff --git a/image/system_a/data/lang/Polski.json b/image/system_a/data/lang/Polski.json index efb347404b676742573411d4eb99671b7f3b6787..943a5ab1773586e935e12da94cca1f243ea0ecf5 100644 --- a/image/system_a/data/lang/Polski.json +++ b/image/system_a/data/lang/Polski.json @@ -140,6 +140,8 @@ "app_bell_settings_alarm_settings_sounds": "D\u017awi\u0119ki", "app_bell_settings_alarm_settings_title": "Ustawienia alarmu", "app_bell_settings_alarm_settings_volume": "G\u0142o\u015bno\u015b\u0107 alarmu", + "app_bell_settings_relaxation_fade": "Relaks", + "app_bell_settings_relaxation_fade_message": "Powoli podno\u015b g\u0142o\u015bno\u015b\u0107 relaksacji", "app_bell_settings_bedtime_chime": "Pora snu", "app_bell_settings_bedtime_settings_tone": "D\u017awi\u0119k pory snu", "app_bell_settings_bedtime_settings_volume": "G\u0142o\u015bno\u015b\u0107 pory snu", diff --git a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp index cc159d1be45081dc9a5b64560e5321663a833e40..2800de0816a6b548fc3dd903107d196e1b877333 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -71,7 +72,8 @@ namespace app batteryModel = std::make_unique(this); lowBatteryInfoModel = std::make_unique(); - player = std::make_unique(*audioModel); + fadeModel = std::make_unique(this); + player = std::make_unique(*fadeModel, *audioModel); relaxationRebuildTimerHandle = sys::TimerFactory::createSingleShotTimer( this, relaxationRebuildTimer, relaxationRebuildTimerInterval, [this](sys::Timer &) { const auto mainWindow = getWindow(gui::name::window::main_window); diff --git a/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp b/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp index 12f823991aeb7ac8d993062e9c829dc7f0900f7d..04138efd75d3485f41901535979cace65bfd1952 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -52,6 +53,7 @@ namespace app private: std::unique_ptr audioModel; + std::unique_ptr fadeModel; std::unique_ptr batteryModel; std::unique_ptr lowBatteryInfoModel; std::unique_ptr player; diff --git a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.cpp b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.cpp index 1a76438edea9405e65e44247c750fa1fb4db966b..8abb081193188c5cf5415a2234ae9cceaa9b503f 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.cpp @@ -11,7 +11,8 @@ namespace app::relaxation return playbackMode; } - RelaxationPlayer::RelaxationPlayer(AbstractAudioModel &audioModel) : audioModel{audioModel} + RelaxationPlayer::RelaxationPlayer(AbstractRelaxationFadeModel &fadeModel, AbstractAudioModel &audioModel) + : fadeModel{fadeModel}, audioModel{audioModel} {} void RelaxationPlayer::start(const std::string &filePath, @@ -42,11 +43,16 @@ namespace app::relaxation } }; - auto fadeParams = audio::FadeParams{.mode = audio::Fade::InOut, .playbackDuration = playbackDuration}; + auto fadeParams = audio::FadeParams{.mode = getFadeMode(), .playbackDuration = playbackDuration}; audioModel.setPlaybackFinishedCb(std::move(onPlayerFinished)); audioModel.play(filePath, Type::Multimedia, std::move(stateChangeCallback), std::move(fadeParams)); } + audio::Fade RelaxationPlayer::getFadeMode() const + { + return fadeModel.getFade().getValue() ? audio::Fade::InOut : audio::Fade::Disable; + } + void RelaxationPlayer::stop(AbstractAudioModel::OnStateChangeCallback &&callback) { paused = false; diff --git a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.hpp b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.hpp index a48e2d630d4769a3e7eb314222dbc802f1087e83..fb7be1567db8b3bfc339b10ec0dc80550ebe23ea 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.hpp @@ -4,6 +4,7 @@ #pragma once #include +#include namespace app { @@ -36,13 +37,14 @@ namespace app::relaxation virtual void pause(AbstractAudioModel::OnStateChangeCallback &&callback) = 0; virtual void resume(AbstractAudioModel::OnStateChangeCallback &&callback) = 0; virtual PlaybackMode getCurrentMode() const noexcept = 0; + virtual audio::Fade getFadeMode() const = 0; virtual bool isPaused() = 0; }; class RelaxationPlayer : public AbstractRelaxationPlayer { public: - explicit RelaxationPlayer(AbstractAudioModel &audioModel); + RelaxationPlayer(AbstractRelaxationFadeModel &fadeModel, AbstractAudioModel &audioModel); private: void start(const std::string &filePath, @@ -54,8 +56,10 @@ namespace app::relaxation void pause(AbstractAudioModel::OnStateChangeCallback &&callback) override; void resume(AbstractAudioModel::OnStateChangeCallback &&callback) override; PlaybackMode getCurrentMode() const noexcept override; + audio::Fade getFadeMode() const override; bool isPaused() override; + AbstractRelaxationFadeModel &fadeModel; AbstractAudioModel &audioModel; std::string recentFilePath; PlaybackMode playbackMode = PlaybackMode::SingleShot; diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index e8d3da0995d3452e47ff55922d629e580bb09ca7..7fc71f81467a10e7adfb7273955930cb7f8a2b96 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -7,6 +7,7 @@ #include "models/TemperatureUnitModel.hpp" #include "models/AboutYourBellModel.hpp" #include "models/AudioErrorModel.hpp" +#include "models/RelaxationListItemProvider.hpp" #include "models/alarm_settings/AlarmSettingsListItemProvider.hpp" #include "models/alarm_settings/PrewakeUpListItemProvider.hpp" #include "models/alarm_settings/BedtimeSettingsListItemProvider.hpp" @@ -30,6 +31,7 @@ #include "windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp" #include "windows/alarm_settings/BellSettingsPrewakeUpWindow.hpp" #include "windows/BellSettingsBedtimeToneWindow.hpp" +#include "windows/BellSettingsRelaxationWindow.hpp" #include "windows/BellSettingsHomeViewWindow.hpp" #include "windows/BellSettingsTimeUnitsWindow.hpp" #include "windows/BellSettingsWindow.hpp" @@ -39,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -105,6 +108,15 @@ namespace app return std::make_unique(app, std::move(presenter), name); }); + windowsFactory.attach(gui::window::name::bellSettingsRelaxation, + [](ApplicationCommon *app, [[maybe_unused]] const std::string &name) { + auto fadeModel = std::make_unique(app); + auto provider = + std::make_shared(std::move(fadeModel)); + auto presenter = std::make_unique(provider); + return std::make_unique(app, std::move(presenter)); + }); + windowsFactory.attach( gui::BellSettingsFrontlightWindow::name, [](ApplicationCommon *app, const std::string &name) { auto model = std::make_unique(app); diff --git a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt index 06a7b05f4fe0c897d3d59baaf046c20dea164b2f..6b258355e9e5c3978a30306a0d2db09c34436cd2 100644 --- a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt @@ -28,6 +28,7 @@ target_sources(application-bell-settings models/FrontlightListItemProvider.cpp models/FrontlightModel.cpp models/AudioErrorModel.cpp + models/RelaxationListItemProvider.cpp models/alarm_settings/AlarmSettingsListItemProvider.cpp models/alarm_settings/AlarmSettingsModel.cpp models/alarm_settings/BedtimeSettingsListItemProvider.cpp @@ -46,6 +47,7 @@ target_sources(application-bell-settings presenter/LayoutWindowPresenter.cpp presenter/ShortcutsWindowPresenter.cpp presenter/UpdateInstructionWindowPresenter.cpp + presenter/RelaxationWindowPresenter.cpp presenter/alarm_settings/AlarmSettingsPresenter.cpp presenter/alarm_settings/PrewakeUpPresenter.cpp presenter/alarm_settings/SnoozePresenter.cpp @@ -67,6 +69,7 @@ target_sources(application-bell-settings windows/BellSettingsLayoutWindow.cpp windows/BellSettingsFrontlightWindow.cpp windows/BellSettingsFactoryResetWindow.cpp + windows/BellSettingsRelaxationWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp diff --git a/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp b/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp index 9472049c0a5de99a850ea980aab0dd7cd1961c1d..cbe7be7329cff8a715136382293de0a162f0b655 100644 --- a/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp +++ b/products/BellHybrid/apps/application-bell-settings/data/BellSettingsStyle.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -54,12 +54,14 @@ 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 = style::window::font::largelight; diff --git a/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp index 654c48eb4cfdaf7ecebe474966e867b74f6dac3f..ee7bd85d97f18c48e9448137e8034c8ee563705b 100644 --- a/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp +++ b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp @@ -16,6 +16,7 @@ namespace gui::window::name inline constexpr auto bellSettingsLanguage = "BellSettingsLanguage"; inline constexpr auto bellSettingsLayout = "BellSettingsLayout"; inline constexpr auto bellSettingsBedtimeTone = "BellSettingsBedtimeTone"; + inline constexpr auto bellSettingsRelaxation = "BellSettingsRelaxation"; inline constexpr auto bellSettingsShortcuts = "BellSettingsShortcuts"; inline constexpr auto bellSettingsUpdateInstruction = "BellSettingsUpdateInstruction"; } // namespace gui::window::name diff --git a/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f504e3a30c75caae70112ee22252acc28741d9b8 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.cpp @@ -0,0 +1,65 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "RelaxationListItemProvider.hpp" +#include "common/widgets/ListItems.hpp" +#include "data/BellSettingsStyle.hpp" + +#include + +namespace app::bell_settings +{ + using namespace gui; + + RelaxationListItemProvider::RelaxationListItemProvider(std::unique_ptr &&model) + : model{std::move(model)} + { + buildListItems(); + } + + void RelaxationListItemProvider::buildListItems() + { + constexpr auto itemCount = 1U; + internalData.reserve(itemCount); + + auto onOff = new OnOffListItem(model->getFade(), utils::translate("app_bell_settings_relaxation_fade_message")); + onOff->onProceed = [onOff, this]() { + if (not onOff->isActive()) { + this->onExit(); + return true; + } + return false; + }; + internalData.emplace_back(onOff); + + for (auto item : internalData) { + item->deleteByList = false; + } + } + + auto RelaxationListItemProvider::requestRecords(std::uint32_t offset, std::uint32_t limit) -> void + { + setupModel(offset, limit); + list->onProviderDataUpdate(); + } + + auto RelaxationListItemProvider::getItem(Order order) -> ListItem * + { + return getRecord(order); + } + + auto RelaxationListItemProvider::requestRecordsCount() -> unsigned int + { + return internalData.size(); + } + + auto RelaxationListItemProvider::getMinimalItemSpaceRequired() const -> unsigned int + { + return style::sidelistview::list_item::w; + } + + auto RelaxationListItemProvider::getListItems() -> std::vector + { + return internalData; + } +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.hpp b/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0343f39ea0e9ccb17684693e3433afc4b2000e69 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/models/RelaxationListItemProvider.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2017-2024, 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_settings +{ + class RelaxationListItemProvider : public app::InternalModel, + public gui::ListItemProvider + { + public: + explicit RelaxationListItemProvider(std::unique_ptr &&model); + auto getListItems() -> std::vector; + auto requestRecords(std::uint32_t offset, std::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: + auto buildListItems() -> void; + + std::unique_ptr model; + }; +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d71a58d2eab1c64007730b48ea17939720d5ca0 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.cpp @@ -0,0 +1,33 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "RelaxationWindowPresenter.hpp" +#include "models/RelaxationListItemProvider.hpp" + +namespace app::bell_settings +{ + RelaxationWindowPresenter::RelaxationWindowPresenter(std::shared_ptr provider) + : provider{provider} + { + provider->onExit = [this]() { getView()->exit(); }; + } + + void RelaxationWindowPresenter::saveData() + { + for (const auto &item : provider->getListItems()) { + item->getValue(); + } + } + + void RelaxationWindowPresenter::loadData() + { + for (const auto &item : provider->getListItems()) { + item->setValue(); + } + } + + auto RelaxationWindowPresenter::getPagesProvider() const -> std::shared_ptr + { + return provider; + } +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..67fd3adfbe833c9cd64a1341ed41553623ae5942 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/RelaxationWindowPresenter.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include + +namespace gui +{ + class ListItemProvider; +} // namespace gui + +namespace app::bell_settings +{ + class RelaxationListItemProvider; + + class View + { + public: + virtual ~View() noexcept = default; + virtual void exit() = 0; + }; + + class AbstractRelaxationPresenter : public BasePresenter + { + public: + virtual ~AbstractRelaxationPresenter() noexcept = default; + virtual auto getPagesProvider() const -> std::shared_ptr = 0; + virtual void saveData() = 0; + virtual void loadData() = 0; + }; + + class RelaxationWindowPresenter : public AbstractRelaxationPresenter + { + private: + std::shared_ptr provider; + + public: + explicit RelaxationWindowPresenter(std::shared_ptr provider); + auto getPagesProvider() const -> std::shared_ptr override; + void saveData() override; + void loadData() override; + }; +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp index d064d65bbfbd3c9fafbb47201548657c96d7753e..df6a47916236121a6770c8584f0bee2368f03d3b 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp @@ -19,28 +19,32 @@ namespace app::bell_settings { class SnoozeListItemProvider; - class View + class SnoozeWindowContract { public: - virtual ~View() noexcept = default; - virtual auto exit() -> void = 0; - virtual auto deepRefresh() -> void = 0; - virtual auto handleError() -> void = 0; - virtual auto handleDeletedFile() -> void = 0; - }; + class View + { + public: + virtual ~View() noexcept = default; + virtual auto exit() -> void = 0; + virtual auto deepRefresh() -> void = 0; + virtual auto handleError() -> void = 0; + virtual auto handleDeletedFile() -> void = 0; + }; - class AbstractSnoozePresenter : public BasePresenter - { - public: - virtual ~AbstractSnoozePresenter() = default; - virtual auto getPagesProvider() const -> std::shared_ptr = 0; - virtual auto saveData() -> void = 0; - virtual auto loadData() -> void = 0; - virtual auto eraseProviderData() -> void = 0; - virtual auto exitWithoutSave() -> void = 0; + class AbstractSnoozePresenter : public BasePresenter + { + public: + virtual ~AbstractSnoozePresenter() = default; + virtual auto getPagesProvider() const -> std::shared_ptr = 0; + virtual auto saveData() -> void = 0; + virtual auto loadData() -> void = 0; + virtual auto eraseProviderData() -> void = 0; + virtual auto exitWithoutSave() -> void = 0; + }; }; - class SnoozePresenter : public AbstractSnoozePresenter + class SnoozePresenter : public SnoozeWindowContract::AbstractSnoozePresenter { public: SnoozePresenter(ApplicationCommon *app, diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5ec1efe98c21a2cd6f5e065098a40a3a06c40c11 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.cpp @@ -0,0 +1,66 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellSettingsRelaxationWindow.hpp" + +#include +#include +#include + +namespace gui +{ + BellSettingsRelaxationWindow::BellSettingsRelaxationWindow( + app::ApplicationCommon *app, + std::unique_ptr &&windowPresenter, + std::string name) + : AppWindow(app, std::move(name)), presenter{std::move(windowPresenter)} + { + presenter->attach(this); + buildInterface(); + } + + void BellSettingsRelaxationWindow::buildInterface() + { + AppWindow::buildInterface(); + + statusBar->setVisible(false); + header->setTitleVisibility(true); + navBar->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 BellSettingsRelaxationWindow::onInput(const InputEvent &inputEvent) + { + if (listView->onInput(inputEvent)) { + return true; + } + if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) { + exit(); + return true; + } + return AppWindow::onInput(inputEvent); + } + + void BellSettingsRelaxationWindow::rebuild() + { + erase(); + buildInterface(); + } + + void BellSettingsRelaxationWindow::exit() + { + presenter->saveData(); + application->switchWindow( + window::bell_finished::defaultName, + BellFinishedWindowData::Factory::create("circle_success_big", name::window::main_window)); + } +} /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..dc071d4108b782be80eb2598aeaad415cedc00ec --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsRelaxationWindow.hpp @@ -0,0 +1,31 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "ApplicationBellSettings.hpp" +#include "presenter/RelaxationWindowPresenter.hpp" + +#include + +namespace gui +{ + class SideListView; + + class BellSettingsRelaxationWindow : public AppWindow, public app::bell_settings::View + { + public: + BellSettingsRelaxationWindow(app::ApplicationCommon *app, + std::unique_ptr &&windowPresenter, + std::string name = window::name::bellSettingsRelaxation); + + void buildInterface() override; + auto onInput(const InputEvent &inputEvent) -> bool override; + void rebuild() override; + void exit() override; + + private: + SideListView *listView{}; + std::unique_ptr presenter; + }; +} /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp index 4c89a7f5ae0740e4782da30557ae4762964df888..e25afc61b51c8aeaa0d3798444b2fc3db2f62509 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp @@ -58,6 +58,9 @@ namespace gui addWinSettings(utils::translate("app_bell_settings_alarm_settings"), BellSettingsAlarmSettingsMenuWindow::name, defaultCallback); + addWinSettings(utils::translate("app_bell_settings_relaxation_fade"), + window::name::bellSettingsRelaxation, + defaultCallback); addWinSettings(utils::translate("app_bell_settings_bedtime_chime"), window::name::bellSettingsBedtimeTone, defaultCallback); diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp index f839f99836276efce7ecfa9732bdc7e6f5f85428..924d9481cf2f5d2b7022c866366b11e17c16ca65 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp @@ -12,7 +12,7 @@ namespace gui { class SideListView; - class BellSettingsAlarmSettingsSnoozeWindow : public AppWindow, app::bell_settings::View + class BellSettingsAlarmSettingsSnoozeWindow : public AppWindow, app::bell_settings::SnoozeWindowContract::View { public: static constexpr auto name = "BellSettingsAlarmSettingsSnooze"; diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index 7db95a396021ceedca94b7c89c3bd82508e9e8e2..c5b362ce96e8f49857d8c791187e746dce37b665 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -43,6 +43,7 @@ target_sources(application-bell-common src/models/LowBatteryInfoModel.cpp src/models/SongsModel.cpp src/models/PreWakeUpModel.cpp + src/models/RelaxationFadeModel.cpp src/popups/AlarmActivatedWindow.cpp src/popups/AlarmActivatedWindow.cpp @@ -115,6 +116,7 @@ target_sources(application-bell-common include/common/data/BatteryStatusSwitchData.hpp include/common/models/AbstractAlarmModel.hpp + include/common/models/AbstractRelaxationFadeModel.hpp include/common/models/AbstractBedtimeModel.hpp include/common/models/AbstractSettingsModel.hpp include/common/models/AbstractAudioModel.hpp @@ -122,6 +124,7 @@ target_sources(application-bell-common include/common/models/SettingsModel.hpp include/common/models/BedtimeModel.hpp include/common/models/BatteryModel.hpp + include/common/models/RelaxationFadeModel.hpp include/common/models/BatteryLevelNotificationModel.hpp include/common/models/TimeModel.hpp include/common/models/UserSessionModel.hpp diff --git a/products/BellHybrid/apps/common/include/common/models/AbstractRelaxationFadeModel.hpp b/products/BellHybrid/apps/common/include/common/models/AbstractRelaxationFadeModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..05e92df8634d1728731a1f432e4ca66a8723c917 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/models/AbstractRelaxationFadeModel.hpp @@ -0,0 +1,16 @@ +// Copyright (c) 2017-2024, 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" + +namespace app +{ + class AbstractRelaxationFadeModel + { + public: + virtual ~AbstractRelaxationFadeModel() = default; + virtual auto getFade() -> gui::AbstractSettingsModel & = 0; + }; +} // namespace app diff --git a/products/BellHybrid/apps/common/include/common/models/RelaxationFadeModel.hpp b/products/BellHybrid/apps/common/include/common/models/RelaxationFadeModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f2ac6b18a522d8e6133a4d6626ab56286f29349c --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/models/RelaxationFadeModel.hpp @@ -0,0 +1,39 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "AbstractRelaxationFadeModel.hpp" +#include "SettingsModel.hpp" +#include + +namespace app +{ + class RelaxationFadeSettings : public gui::SettingsModel + { + public: + using SettingsModel::SettingsModel; + + auto setValue(bool value) -> void override; + auto getValue() const -> bool override; + }; + + class RelaxationFadeModel : public AbstractRelaxationFadeModel + { + public: + RelaxationFadeModel() = delete; + + RelaxationFadeModel(ApplicationCommon *app) + { + fade = std::make_unique(app); + } + + gui::AbstractSettingsModel &getFade() override + { + return *fade; + } + + private: + std::unique_ptr> fade; + }; +} // namespace app diff --git a/products/BellHybrid/apps/common/src/models/RelaxationFadeModel.cpp b/products/BellHybrid/apps/common/src/models/RelaxationFadeModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a28b2a698ba249fd15eedb9b88725ffa87dae537 --- /dev/null +++ b/products/BellHybrid/apps/common/src/models/RelaxationFadeModel.cpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "models/RelaxationFadeModel.hpp" +#include +#include + +namespace app +{ + auto RelaxationFadeSettings::setValue(bool value) -> void + { + const auto valStr = std::to_string(value); + settings.setValue(bell::settings::Relaxation::fadeActive, valStr, settings::SettingsScope::Global); + } + + auto RelaxationFadeSettings::getValue() const -> bool + { + const auto str = settings.getValue(bell::settings::Relaxation::fadeActive, settings::SettingsScope::Global); + return utils::toNumeric(str); + } +} // namespace app diff --git a/products/BellHybrid/services/db/include/db/SystemSettings.hpp b/products/BellHybrid/services/db/include/db/SystemSettings.hpp index f1cd06a1b28ea9e3c59897463c1ab82b2106db77..fc6715ce9ee4dd8fbf7ed43bf5e69623ac92fd3b 100644 --- a/products/BellHybrid/services/db/include/db/SystemSettings.hpp +++ b/products/BellHybrid/services/db/include/db/SystemSettings.hpp @@ -47,6 +47,11 @@ namespace bell::settings inline constexpr auto duration = "bedtime_duration"; } // namespace Bedtime + namespace Relaxation + { + inline constexpr auto fadeActive = "relaxation_fade_active"; + } + namespace Layout { inline constexpr auto layout = "layout";