From 4a792563da5a05e3fa17f073d295ea69bd8fdc5c Mon Sep 17 00:00:00 2001 From: ChunjianLee Date: Thu, 21 Oct 2021 14:16:46 +0800 Subject: [PATCH] [BH-453] Add Meditation Timer application Add Meditation Timer application implementation provided by ATEL. --- image/assets/lang/English.json | 10 + products/BellHybrid/BellHybridMain.cpp | 3 + products/BellHybrid/CMakeLists.txt | 1 + products/BellHybrid/apps/CMakeLists.txt | 1 + .../apps/application-bell-main/CMakeLists.txt | 1 + .../windows/BellMainMenuWindow.cpp | 23 +-- .../ApplicationBellMeditationTimer.cpp | 89 +++++++++ .../CMakeLists.txt | 48 +++++ .../data/MeditationCommon.hpp | 10 + .../data/MeditationStyle.hpp | 84 ++++++++ .../ApplicationBellMeditationTimer.hpp | 55 +++++ .../presenter/IntervalChimePresenter.cpp | 86 ++++++++ .../presenter/IntervalChimePresenter.hpp | 54 +++++ .../presenter/MeditationProgressPresenter.cpp | 92 +++++++++ .../presenter/MeditationProgressPresenter.hpp | 84 ++++++++ .../presenter/MeditationTimerPresenter.cpp | 62 ++++++ .../presenter/MeditationTimerPresenter.hpp | 59 ++++++ .../presenter/ReadyGoingPresenter.cpp | 16 ++ .../presenter/ReadyGoingPresenter.hpp | 39 ++++ .../presenter/SessionEndedPresenter.cpp | 17 ++ .../presenter/SessionEndedPresenter.hpp | 39 ++++ .../windows/IntervalChimeWindow.cpp | 83 ++++++++ .../windows/IntervalChimeWindow.hpp | 36 ++++ .../windows/MeditationRunningWindow.cpp | 188 ++++++++++++++++++ .../windows/MeditationRunningWindow.hpp | 48 +++++ .../windows/MeditationTimerWindow.cpp | 86 ++++++++ .../windows/MeditationTimerWindow.hpp | 36 ++++ .../windows/ReadyGoingWindow.cpp | 51 +++++ .../windows/ReadyGoingWindow.hpp | 29 +++ .../windows/SessionEndWindow.cpp | 32 +++ .../windows/SessionEndWindow.hpp | 26 +++ .../windows/SessionPausedWindow.cpp | 45 +++++ .../windows/SessionPausedWindow.hpp | 25 +++ 33 files changed, 1537 insertions(+), 21 deletions(-) create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/ApplicationBellMeditationTimer.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/CMakeLists.txt create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/ApplicationBellMeditationTimer.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationTimerPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationTimerPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/ReadyGoingPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/ReadyGoingPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/SessionEndedPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/presenter/SessionEndedPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/IntervalChimeWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/IntervalChimeWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationRunningWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationTimerWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/MeditationTimerWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/ReadyGoingWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/ReadyGoingWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/SessionEndWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/SessionEndWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/SessionPausedWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-meditation-timer/windows/SessionPausedWindow.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index b3b10f446d2a44d33077a95fc488be65f9894156..616aa04cb91603e2699896ea9b03623f2527ad88 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -596,6 +596,16 @@ "app_bellmain_background_sounds": "Library", "app_bellmain_settings": "Settings", "app_bellmain_main_window_title": "Bell Hybrid+", + "app_bell_meditation_timer": "Meditation", + "app_bell_meditation_interval_chime": "Interval chime", + "app_bell_meditation_progress": "Meditation timer", + "app_bell_meditation_interval_none": "None", + "app_bell_meditation_interval_every_x_minutes": "every %0", + "app_bell_meditation_put_down_and_wait": "Put down Bell Harmony
and wait for the gong
", + "app_bell_meditation_thank_you_for_session": "Thank you for
the session
", + "app_bell_meditation_minute": "minute", + "app_bell_meditation_minutes": "minutes", + "app_bell_meditation_paused": "Paused", "app_bell_onboarding_welcome_message": "Mudita Harmony", "app_bell_onboarding_info_rotate": "Rotate to select", "app_bell_onboarding_info_light_click": "Light click to continue", diff --git a/products/BellHybrid/BellHybridMain.cpp b/products/BellHybrid/BellHybridMain.cpp index c5f7b934bfaf987b88a9663e66c3bad5fd93e242..e867e8b1a9eaa515f7b0053424635aa0a00f6a18 100644 --- a/products/BellHybrid/BellHybridMain.cpp +++ b/products/BellHybrid/BellHybridMain.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -104,6 +105,8 @@ int main() app::CreateLauncher(app::applicationBellOnBoardingName)); applications.push_back( app::CreateLauncher(app::applicationBellBackgroundSoundsName)); + applications.push_back( + app::CreateLauncher(app::applicationBellMeditationTimerName)); // start application manager return sysmgr->RunSystemService( std::make_shared( diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 8027d7b4861cb1683851ef27298a860ca033f4f4..fc347b50240215baccbd5087b235633b9021c14f 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -44,6 +44,7 @@ target_link_libraries(BellHybrid bell::app-bedtime bell::app-common bell::app-main + bell::app-meditation-timer bell::app-powernap bell::app-settings bell::db diff --git a/products/BellHybrid/apps/CMakeLists.txt b/products/BellHybrid/apps/CMakeLists.txt index f013279035bfb1c309733a5d3cbdfca33ec46d2d..3737400351d938044d7c43e1cde2a199234d6e2c 100644 --- a/products/BellHybrid/apps/CMakeLists.txt +++ b/products/BellHybrid/apps/CMakeLists.txt @@ -25,6 +25,7 @@ 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-meditation-timer) add_subdirectory(application-bell-settings) add_subdirectory(application-bell-powernap) add_subdirectory(common) diff --git a/products/BellHybrid/apps/application-bell-main/CMakeLists.txt b/products/BellHybrid/apps/application-bell-main/CMakeLists.txt index bf326545e232a69fe0c91ec26346847eed5668b5..5b212f2bb061c5e1db624f3bb8251540c7a8d95d 100644 --- a/products/BellHybrid/apps/application-bell-main/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-main/CMakeLists.txt @@ -58,6 +58,7 @@ target_link_libraries(application-bell-main bell::app-onboarding bell::app-background-sounds bell::app-bedtime + bell::app-meditation-timer bell::app-settings bell::app-powernap bell::keymap diff --git a/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp b/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp index 2da0ed75c8bdad7301ff9ace462a0441e69a1b0b..4224a81fbc4fe59ccafe6f66e393f39303c0594e 100644 --- a/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp +++ b/products/BellHybrid/apps/application-bell-main/windows/BellMainMenuWindow.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -28,26 +29,6 @@ namespace gui { std::list menuOptionList; - auto addWinMenu = [&](const UTF8 &name, const std::string &window) { - menuOptionList.emplace_back(std::make_unique( - name, - [=](gui::Item &item) { - if (window.empty()) { - return false; - } - application->switchWindow( - window, - gui::ShowMode::GUI_SHOW_INIT, - std::make_unique(gui::DialogMetadata{name, "search_big", " "})); - return true; - }, - [=](gui::Item &item) { - // put focus change callback here - return true; - }, - this)); - }; - auto addAppMenu = [&](const UTF8 &name, const std::string &appName) { menuOptionList.emplace_back(std::make_unique( name, @@ -70,7 +51,7 @@ namespace gui addAppMenu(utils::translate("app_bellmain_power_nap"), app::applicationBellPowerNapName); 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); + addAppMenu(utils::translate("app_bellmain_meditation_timer"), app::applicationBellMeditationTimerName); addAppMenu(utils::translate("app_bellmain_bedtime"), app::applicationBellBedtimeName); addAppMenu(utils::translate("app_bellmain_settings"), app::applicationBellSettingsName); diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/ApplicationBellMeditationTimer.cpp b/products/BellHybrid/apps/application-bell-meditation-timer/ApplicationBellMeditationTimer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1177c0344b3c74a5151bfe5e73abcaa14d2b3112 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/ApplicationBellMeditationTimer.cpp @@ -0,0 +1,89 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ApplicationBellMeditationTimer.hpp" +#include "windows/IntervalChimeWindow.hpp" +#include "windows/MeditationRunningWindow.hpp" +#include "windows/MeditationTimerWindow.hpp" +#include "windows/ReadyGoingWindow.hpp" +#include "windows/SessionEndWindow.hpp" +#include "windows/SessionPausedWindow.hpp" + +#include + +namespace app +{ + ApplicationBellMeditationTimer::ApplicationBellMeditationTimer(std::string name, + std::string parent, + StatusIndicators statusIndicators, + StartInBackground startInBackground) + : Application(std::move(name), std::move(parent), statusIndicators, startInBackground) + {} + + ApplicationBellMeditationTimer::~ApplicationBellMeditationTimer() = default; + + sys::ReturnCodes ApplicationBellMeditationTimer::InitHandler() + { + auto ret = Application::InitHandler(); + if (ret != sys::ReturnCodes::Success) { + return ret; + } + + createUserInterface(); + + return sys::ReturnCodes::Success; + } + + void ApplicationBellMeditationTimer::createUserInterface() + { + windowsFactory.attach(gui::name::window::main_window, [this](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app, settings.get()); + return std::make_unique(app, std::move(presenter)); + }); + windowsFactory.attach( + gui::name::window::intervalChime, [this](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app, settings.get()); + return std::make_unique(app, std::move(presenter)); + }); + windowsFactory.attach(gui::name::window::readyGoing, [](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app); + return std::make_unique(app, std::move(presenter)); + }); + windowsFactory.attach(gui::name::window::meditationProgress, + [this](ApplicationCommon *app, const std::string &name) { + auto timeModel = std::make_unique(); + auto presenter = std::make_unique( + app, settings.get(), std::move(timeModel)); + return std::make_unique(app, std::move(presenter)); + }); + windowsFactory.attach(gui::name::window::sessionPaused, [](ApplicationCommon *app, const std::string &name) { + return std::make_unique(app); + }); + windowsFactory.attach(gui::name::window::sessionEnded, [](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app); + return std::make_unique(app, std::move(presenter)); + }); + + attachPopups({gui::popup::ID::AlarmActivated, + gui::popup::ID::AlarmDeactivated, + gui::popup::ID::PowerOff, + gui::popup::ID::Reboot, + gui::popup::ID::BedtimeNotification}); + } + + sys::MessagePointer ApplicationBellMeditationTimer::DataReceivedHandler(sys::DataMessage *msgl, + sys::ResponseMessage *resp) + { + auto retMsg = Application::DataReceivedHandler(msgl); + if (auto response = dynamic_cast(retMsg.get()); + response != nullptr && response->retCode == sys::ReturnCodes::Success) { + return retMsg; + } + + return handleAsyncResponse(resp); + } + + // Empty: do not start idleTimer on application run + void ApplicationBellMeditationTimer::onStart() + {} +} // namespace app diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/CMakeLists.txt b/products/BellHybrid/apps/application-bell-meditation-timer/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..e19453f645cbe463f5cdede5dd3256b16386b495 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/CMakeLists.txt @@ -0,0 +1,48 @@ +add_library(application-bell-meditation-timer STATIC) +add_library(bell::app-meditation-timer ALIAS application-bell-meditation-timer) + +target_include_directories(application-bell-meditation-timer + PRIVATE + $ + PUBLIC + $ +) + +target_sources(application-bell-meditation-timer + PRIVATE + ApplicationBellMeditationTimer.cpp + presenter/IntervalChimePresenter.cpp + presenter/MeditationProgressPresenter.cpp + presenter/MeditationTimerPresenter.cpp + presenter/ReadyGoingPresenter.cpp + presenter/SessionEndedPresenter.cpp + windows/IntervalChimeWindow.cpp + windows/MeditationRunningWindow.cpp + windows/MeditationTimerWindow.cpp + windows/ReadyGoingWindow.cpp + windows/SessionEndWindow.cpp + windows/SessionPausedWindow.cpp + PUBLIC + include/application-bell-meditation-timer/ApplicationBellMeditationTimer.hpp +) + +target_link_libraries(application-bell-meditation-timer + PRIVATE + app + bell::app-common + bell::app-main + bellgui + service-appmgr + service-time + PUBLIC + apps-common + module-gui +) diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp new file mode 100644 index 0000000000000000000000000000000000000000..83c1fb9912032b691e5b4b2db3a1b3eaab243589 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationCommon.hpp @@ -0,0 +1,10 @@ +// 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 app::meditation +{ + constexpr auto meditationDBRecordName = "MeditationTimer"; + constexpr auto intervalDBRecordName = "IntervalChime"; +} // namespace app::meditation diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp new file mode 100644 index 0000000000000000000000000000000000000000..bce53b345ebfb2b118cfe2b0419e212dcf143070 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/data/MeditationStyle.hpp @@ -0,0 +1,84 @@ +// 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 app::meditationStyle +{ + namespace itStyle + { + namespace icon + { + constexpr inline auto imageLogo = "bell_big_logo"; + constexpr inline auto imagePause = "big_pause"; + constexpr inline auto imageTopMargin = 112; + constexpr inline auto imageBottomMargin = 30; + } // namespace icon + + namespace text + { + constexpr inline auto font = style::window::font::verybiglight; + } // namespace text + } // namespace itStyle + + namespace icStyle + { + namespace text + { + constexpr inline auto font = style::window::font::supersizemelight; + } // namespace text + + namespace minute + { + constexpr inline auto font = style::window::font::largelight; + } // namespace minute + + namespace list + { + constexpr inline auto timeUnitSingular = "common_minute_lower"; + constexpr inline auto timeUnitPlural = "common_minutes_lower"; + } // namespace list + } // namespace icStyle + + namespace mrStyle + { + namespace title + { + constexpr inline auto font = style::window::font::verybiglight; + } // namespace title + + namespace progress + { + constexpr inline auto progressMarginTop = 40; + constexpr inline auto progressMarginLeft = 60; + constexpr inline auto boxesCount = 16; + } // namespace progress + + namespace timer + { + constexpr inline auto timerMarginBottom = 20; + constexpr inline auto font = style::window::font::largelight; + } // namespace timer + } // namespace mrStyle + + namespace mtStyle + { + namespace text + { + constexpr inline auto font = style::window::font::supersizemelight; + } // namespace text + + namespace minute + { + constexpr inline auto font = style::window::font::largelight; + } // namespace minute + + namespace list + { + constexpr inline auto timeUnitSingular = "common_minute_lower"; + constexpr inline auto timeUnitPlural = "common_minutes_lower"; + } // namespace list + } // namespace mtStyle +} // namespace app::meditationStyle diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/ApplicationBellMeditationTimer.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/ApplicationBellMeditationTimer.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0bfd406abe69c7bc3398c5a08710a2680415d733 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/include/application-bell-meditation-timer/ApplicationBellMeditationTimer.hpp @@ -0,0 +1,55 @@ +// 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::name::window +{ + inline constexpr auto intervalChime = "IntervalChimeWindow"; + inline constexpr auto meditationProgress = "MeditationProgressWindow"; + inline constexpr auto meditationTimer = "MeditationTimerWindow"; + inline constexpr auto readyGoing = "ReadyGoingWindow"; + inline constexpr auto sessionEnded = "SessionEndedWindow"; + inline constexpr auto sessionPaused = "SensionPausedWindow"; +} // namespace gui::name::window + +namespace app +{ + inline constexpr auto applicationBellMeditationTimerName = "ApplicationBellMeditationTimer"; + + class ApplicationBellMeditationTimer : public Application + { + public: + ApplicationBellMeditationTimer(std::string name = applicationBellMeditationTimerName, + std::string parent = "", + StatusIndicators statusIndicators = StatusIndicators{}, + StartInBackground startInBackground = {false}); + ~ApplicationBellMeditationTimer(); + + sys::ReturnCodes InitHandler() override; + + void createUserInterface() override; + void destroyUserInterface() override + {} + + sys::MessagePointer DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) override; + + sys::ReturnCodes SwitchPowerModeHandler(const sys::ServicePowerMode mode) override final + { + return sys::ReturnCodes::Success; + } + + private: + void onStart() override; + }; + + template <> struct ManifestTraits + { + static auto GetManifest() -> manager::ApplicationManifest + { + return {{manager::actions::Launch}}; + } + }; +} // namespace app diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.cpp b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..71cf4a0df421c9d3f810433c48ed6d3fef842a9a --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.cpp @@ -0,0 +1,86 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ApplicationBellMeditationTimer.hpp" +#include "IntervalChimePresenter.hpp" +#include "MeditationCommon.hpp" +#include "MeditationStyle.hpp" + +#include + +namespace app::meditation +{ + IntervalChimePresenter::IntervalChimePresenter(app::ApplicationCommon *app, settings::Settings *settings) + : app{app}, settings{settings} + { + initIntervalOptions(); + } + + std::vector IntervalChimePresenter::getIntervals() const + { + std::vector intervalNames; + for (auto const &option : intervalOptions) { + intervalNames.push_back(option.second); + } + return intervalNames; + } + + std::string IntervalChimePresenter::getCurrentInterval() const + { + // Always set interval as none + for (auto const &option : intervalOptions) { + if (option.first == std::chrono::minutes{0}) { + return option.second; + } + } + return intervalOptions.at(0).second; + } + + std::string IntervalChimePresenter::getTimeUnitName(std::string value) + { + using namespace app::meditationStyle::mtStyle::list; + for (auto const &option : intervalOptions) { + if (option.second == value) { + if (option.first == std::chrono::minutes{0}) { + return ""; + } + if (option.first == std::chrono::minutes{1}) { + return utils::translate(timeUnitSingular); + } + return utils::translate(timeUnitPlural); + } + } + return ""; + } + + void IntervalChimePresenter::activate(std::string value) + { + for (auto const &option : intervalOptions) { + if (option.second == value) { + settings->setValue( + intervalDBRecordName, utils::to_string(option.first.count()), settings::SettingsScope::AppLocal); + app->switchWindow(gui::name::window::readyGoing); + break; + } + } + } + + void IntervalChimePresenter::initIntervalOptions() + { + intervalOptions.push_back({std::chrono::minutes{0}, utils::translate("app_bell_meditation_interval_none")}); + intervalOptions.push_back({std::chrono::minutes{1}, getIntervalString(1)}); + intervalOptions.push_back({std::chrono::minutes{2}, getIntervalString(2)}); + intervalOptions.push_back({std::chrono::minutes{5}, getIntervalString(5)}); + intervalOptions.push_back({std::chrono::minutes{10}, getIntervalString(10)}); + intervalOptions.push_back({std::chrono::minutes{15}, getIntervalString(15)}); + intervalOptions.push_back({std::chrono::minutes{30}, getIntervalString(30)}); + } + + std::string IntervalChimePresenter::getIntervalString(std::uint32_t value) + { + const std::string toReplace = "%0"; + std::string temp = utils::translate("app_bell_meditation_interval_every_x_minutes"); + temp.replace(temp.find(toReplace), toReplace.size(), std::to_string(value)); + return temp; + } +} // namespace app::meditation diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..adf11c471e049becef2e660845122ba163603a80 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/IntervalChimePresenter.hpp @@ -0,0 +1,54 @@ +// 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 app::meditation +{ + class IntervalChimeContract + { + public: + class View + { + public: + virtual ~View() = default; + }; + + class Presenter : public BasePresenter + { + public: + virtual ~Presenter() noexcept = default; + virtual std::vector getIntervals() const = 0; + virtual std::string getCurrentInterval() const = 0; + virtual std::string getTimeUnitName(std::string value) = 0; + virtual void activate(std::string value) = 0; + }; + }; + + class IntervalChimePresenter : public IntervalChimeContract::Presenter + { + public: + IntervalChimePresenter(app::ApplicationCommon *app, settings::Settings *settings); + + std::vector getIntervals() const override; + std::string getCurrentInterval() const override; + std::string getTimeUnitName(std::string value) override; + void activate(std::string value) override; + + private: + app::ApplicationCommon *app = nullptr; + settings::Settings *settings = nullptr; + std::vector> intervalOptions; + + void initIntervalOptions(); + std::string getIntervalString(std::uint32_t value); + }; +} // namespace app::meditation diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d9c829d47ead744f890c3d4d76891cc12d09f77a --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.cpp @@ -0,0 +1,92 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ApplicationBellMeditationTimer.hpp" +#include "MeditationCommon.hpp" +#include "MeditationProgressPresenter.hpp" + +#include +#include +#include + +namespace +{ + constexpr std::chrono::minutes emptyValue{0}; +} // namespace + +namespace app::meditation +{ + MeditationProgressPresenter ::MeditationProgressPresenter(app::ApplicationCommon *app, + settings::Settings *settings, + std::unique_ptr timeModel) + : app{app}, settings{settings}, timeModel{std::move(timeModel)} + { + duration = std::chrono::minutes{ + utils::getNumericValue(settings->getValue(meditationDBRecordName, settings::SettingsScope::AppLocal))}; + interval = std::chrono::minutes{ + utils::getNumericValue(settings->getValue(intervalDBRecordName, settings::SettingsScope::AppLocal))}; + } + + void MeditationProgressPresenter::setTimer(std::unique_ptr &&_timer) + { + timer = std::move(_timer); + timer->registerOnFinishedCallback([this]() { onProgressFinished(); }); + if (interval != emptyValue) { + timer->registerOnIntervalCallback([this]() { onIntervalReached(); }); + } + } + + void MeditationProgressPresenter::handleUpdateTimeEvent() + { + getView()->setTime(timeModel->getCurrentTime()); + } + + void MeditationProgressPresenter::start() + { + timer->reset(std::chrono::seconds(duration), std::chrono::seconds(interval)); + timer->start(); + } + + void MeditationProgressPresenter::stop() + { + timer->stop(); + } + + void MeditationProgressPresenter::pause() + { + timer->stop(); + app->switchWindow(gui::name::window::sessionPaused); + } + + void MeditationProgressPresenter::resume() + { + timer->start(); + } + + void MeditationProgressPresenter::abandon() + { + timer->stop(); + app::manager::Controller::sendAction( + app, + app::manager::actions::Launch, + std::make_unique(app::applicationBellMeditationTimerName)); + } + + void MeditationProgressPresenter::finish() + { + timer->stop(); + app->switchWindow(gui::name::window::sessionEnded); + } + + void MeditationProgressPresenter::onProgressFinished() + { + getView()->progressFinished(); + } + + void MeditationProgressPresenter::onIntervalReached() + { + if (interval != emptyValue) { + getView()->intervalReached(); + } + } +} // namespace app::meditation diff --git a/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..cf9a2e6d9896320086eed4ae37430e7282c2d5f0 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-meditation-timer/presenter/MeditationProgressPresenter.hpp @@ -0,0 +1,84 @@ +// 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 +#include