From 9c3fac6ae0492c2a9c1657223f1c93d6f84bc5b3 Mon Sep 17 00:00:00 2001 From: mkamonMdt Date: Sat, 23 Oct 2021 15:47:08 +0200 Subject: [PATCH] [BH-1080] Fix Bgsounds timeout and volume The following commit provides a fix for: * BH-1080: bug appeard only in case off timer's auto turn off set to off. THe OnStopCallback passed to async stop request was not processed due to recieving Failed RetCode, which is expected in singleShot mode. Since there is no need for calling BGSoundsPlayer::stop on timeout in singleShot mode, the check was transfered to presenter's onFinished method. * BH-1079: user could set Volume to 0. System-wdie min volume is 0 so there was presenter-level check added to restrict minimal Volume value to 1. --- .../ApplicationBellBackgroundSounds.cpp | 2 +- .../presenter/BGSoundsProgressPresenter.cpp | 5 +++++ .../presenter/BGSoundsVolumePresenter.cpp | 15 +++++++++++++++ .../presenter/BGSoundsVolumePresenter.hpp | 13 +++++++++++++ .../widgets/BGSoundsPlayer.cpp | 4 ++++ .../widgets/BGSoundsPlayer.hpp | 2 ++ .../windows/BGSoundsVolumeWindow.cpp | 9 +++++++-- .../windows/BGSoundsVolumeWindow.hpp | 2 ++ 8 files changed, 49 insertions(+), 3 deletions(-) diff --git a/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp b/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp index 616f9f571617dab7feec06c049495573c0f2b692..b3b656c75a405b65d1a3eb2c1d9bcb5d3b33b0dd 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp @@ -72,7 +72,7 @@ namespace app }); windowsFactory.attach(gui::popup::window::volume_window, [](ApplicationCommon *app, const std::string &name) { - auto presenter = std::make_unique(); + auto presenter = std::make_unique(*app); return std::make_unique(app, std::move(presenter)); }); diff --git a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp index 595f92d91522a608590ded26059bebf7ab8b31e8..6c81b66e4bc7c982596f7b0355d17097bcd4dc63 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsProgressPresenter.cpp @@ -55,6 +55,11 @@ namespace app::bgSounds } void BGSoundsProgressPresenter::onFinished() { + if (player.getCurrentMode() == AbstractBGSoundsPlayer::PlaybackMode::SingleShot) { + getView()->onFinished(); + return; + } + auto onStopCallback = [this](audio::RetCode retCode) { if (retCode == audio::RetCode::Success) { getView()->onFinished(); diff --git a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp index c9c98a3fc8407d9d74f2886950e29c0ed160ede8..59e28804f271bb7669c189a87f595d489e1217ac 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp @@ -2,9 +2,13 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "BGSoundsVolumePresenter.hpp" +#include namespace app::bgSounds { + BGSoundsVolumePresenter::BGSoundsVolumePresenter(app::ApplicationCommon &app) : app{app} + {} + VolumeData BGSoundsVolumePresenter::getVolumeData() { return volumeData; @@ -15,4 +19,15 @@ namespace app::bgSounds return audio::defaultVolume; } + void BGSoundsVolumePresenter::increaseVolume() + { + app.increaseCurrentVolume(); + } + + void BGSoundsVolumePresenter::decreaseVolume() + { + if (getView()->getCurrentVolume() != minVolume) { + app.decreaseCurrentVolume(); + } + } } // namespace app::bgSounds diff --git a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp index 8a370f2b473e26ca5187b07690022c782cd5322d..e22864d6c23546f7c065d36645a14ae47aba2eb2 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp @@ -6,6 +6,10 @@ #include #include +namespace app +{ + class ApplicationCommon; +} namespace app::bgSounds { constexpr audio::Volume minVolume = 1u; @@ -23,17 +27,21 @@ namespace app::bgSounds { public: virtual ~View() = default; + virtual audio::Volume getCurrentVolume() const noexcept = 0; }; class Presenter : public BasePresenter { public: virtual VolumeData getVolumeData() = 0; virtual audio::Volume getDefaultVolume() = 0; + virtual void increaseVolume() = 0; + virtual void decreaseVolume() = 0; }; }; class BGSoundsVolumePresenter : public BGSoundsVolumeContract::Presenter { + app::ApplicationCommon &app; constexpr static struct VolumeData volumeData { bgSounds::minVolume, audio::maxVolume, audio::defaultVolumeStep @@ -41,5 +49,10 @@ namespace app::bgSounds VolumeData getVolumeData() override; audio::Volume getDefaultVolume() override; + void increaseVolume() override; + void decreaseVolume() override; + + public: + explicit BGSoundsVolumePresenter(app::ApplicationCommon &app); }; } // namespace app::bgSounds diff --git a/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.cpp b/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.cpp index 9d3ad9c8453dfcae438991c191b9b68d97f28a35..224c708797d7195c7ab2549826ae5a809f4181e6 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.cpp @@ -98,4 +98,8 @@ namespace app::bgSounds } return sys::msgHandled(); } + AbstractBGSoundsPlayer::PlaybackMode BGSoundsPlayer::getCurrentMode() const noexcept + { + return playbackMode; + } } // namespace app::bgSounds diff --git a/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.hpp b/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.hpp index cc5f19ae851085f28c230a0792426910649526a9..c97e362c64c18d09e807c5ba3cce8b5bdbbf52d8 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.hpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/widgets/BGSoundsPlayer.hpp @@ -28,6 +28,7 @@ namespace app::bgSounds virtual void stop(OnStateChangeCallback callback) = 0; virtual void pause(OnStateChangeCallback callback) = 0; virtual void resume(OnStateChangeCallback callback) = 0; + virtual PlaybackMode getCurrentMode() const noexcept = 0; }; class BGSoundsPlayer : public AbstractBGSoundsPlayer, public app::AsyncCallbackReceiver @@ -41,6 +42,7 @@ namespace app::bgSounds void stop(OnStateChangeCallback callback) override; void pause(OnStateChangeCallback callback) override; void resume(OnStateChangeCallback callback) override; + PlaybackMode getCurrentMode() const noexcept override; public: explicit BGSoundsPlayer(app::ApplicationCommon *app); diff --git a/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp b/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp index 732225dd72480e6bded8350487ec1f3875d76a08..4c9e6eb8f1a9b5e25e260085e75eaa7bfa2b3ace 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp @@ -57,11 +57,11 @@ namespace gui resetTimer(); if (inputEvent.isShortRelease(KeyCode::KEY_DOWN)) { - application->decreaseCurrentVolume(); + presenter->decreaseVolume(); return true; } else if (inputEvent.isShortRelease(KeyCode::KEY_UP)) { - application->increaseCurrentVolume(); + presenter->increaseVolume(); return true; } return WindowWithTimer::onInput(inputEvent); @@ -83,4 +83,9 @@ namespace gui body->setArrowVisible(BellBaseLayout::Arrow::Right, not isMax); } } + + audio::Volume BGSoundsVolumeWindow::getCurrentVolume() const noexcept + { + return spinner->getCurrentValue(); + } } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp b/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp index 03e2b9a6b399da85f7ac4e3665a84d30cf737805..9a8debbba089d6e5952115769dab0ddf75bf6d62 100644 --- a/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp +++ b/products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp @@ -26,6 +26,8 @@ namespace gui bool onInput(const gui::InputEvent &inputEvent) override; void onBeforeShow(ShowMode mode, SwitchData *data); + audio::Volume getCurrentVolume() const noexcept override; + public: BGSoundsVolumeWindow(app::ApplicationCommon *app, std::unique_ptr &&windowPresenter);