From 863d805d24b913f8559694d0f185504292d11b02 Mon Sep 17 00:00:00 2001 From: Jakub Pyszczak Date: Wed, 24 Mar 2021 13:47:49 +0100 Subject: [PATCH] [EGD-6304] Popup overall fixes Removed duplicated mode observer from application that was introduced during the rebase in this commit 1860bf210f5f128ee8cf780c0cb332abc918dbd1. Fixed mute logic according to the design. Fixed switching back to the meditation window. --- module-apps/Application.cpp | 22 ++++------- .../windows/MeditationTimerWindow.cpp | 37 ++++++++++--------- module-audio/Audio/Audio.cpp | 2 + module-audio/Audio/Audio.hpp | 12 ++++++ .../service-audio/ServiceAudio.cpp | 37 +++++++++---------- .../service-audio/AudioMessage.hpp | 13 +++++-- .../service-audio/ServiceAudio.hpp | 3 +- 7 files changed, 69 insertions(+), 57 deletions(-) diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index b1ae98ae689da119e93dc20f230c26746303e4d7..4a9c44bd763e9185fe730e830efa0c36b0fa933c 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -101,17 +101,6 @@ namespace app std::chrono::milliseconds{key_timer_ms}, [this](sys::Timer &) { longPressTimerCallback(); }); - phoneModeObserver->connect(this); - phoneModeObserver->subscribe( - [=](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) { - using namespace gui::popup; - if (getCurrentWindow()->getName() == window::phone_modes_window) { - updateWindow(window::phone_modes_window, std::make_unique(phoneMode)); - } - else { - switchWindow(window::phone_modes_window, std::make_unique(phoneMode)); - } - }); connect(typeid(AppRefreshMessage), [this](sys::Message *msg) -> sys::MessagePointer { return handleAppRefresh(msg); }); connect(sevm::BatteryStatusChangeMessage(), [&](sys::Message *) { return handleBatteryStatusChange(); }); @@ -121,7 +110,6 @@ namespace app [&](sys::Message *msg) -> sys::MessagePointer { return handleUpdateWindow(msg); }); // handle phone mode changes - bus.channels.push_back(sys::BusChannel::PhoneModeChanges); phoneModeObserver->connect(this); phoneModeObserver->subscribe( [&](sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode) { @@ -552,7 +540,7 @@ namespace app { using namespace gui::popup; const auto msg = static_cast(msgl); - if (!msg->muted) { + if (msg->showPopup == AudioKeyPressedResponse::ShowPopup::True) { LOG_INFO("Playback: %s, volume: %s", audio::str(msg->context.second).c_str(), std::to_string(msg->volume).c_str()); @@ -691,7 +679,13 @@ namespace app return; } - refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + using namespace gui::popup; + if (getCurrentWindow()->getName() == window::phone_modes_window) { + updateWindow(window::phone_modes_window, std::make_unique(mode)); + } + else { + switchWindow(window::phone_modes_window, std::make_unique(mode)); + } } void Application::attachPopups(const std::vector &popupsList) diff --git a/module-apps/application-meditation/windows/MeditationTimerWindow.cpp b/module-apps/application-meditation/windows/MeditationTimerWindow.cpp index 9cb56e656186c430635190cb4ea349fafef14058..d16d41c4c50aa7ac582cabdf4e6f5353c094930f 100644 --- a/module-apps/application-meditation/windows/MeditationTimerWindow.cpp +++ b/module-apps/application-meditation/windows/MeditationTimerWindow.cpp @@ -59,27 +59,28 @@ void MeditationTimerWindow::destroyInterface() void MeditationTimerWindow::onBeforeShow(ShowMode mode, SwitchData *data) { auto timerData = dynamic_cast(data); - assert(timerData); - setVisiblePreparation(); - meditationTime = timerData->getMeditationTime(); - meditationIntervalPeriod = timerData->getMeditationIntervals(); - - auto onPreparation = [&]() -> void { - setVisibleRunning(); - auto onMeditationEnd = [&]() -> void { - setVisibleMeditationEnd(); + if (timerData != nullptr) { + setVisiblePreparation(); + meditationTime = timerData->getMeditationTime(); + meditationIntervalPeriod = timerData->getMeditationIntervals(); + + auto onPreparation = [&]() -> void { + setVisibleRunning(); + auto onMeditationEnd = [&]() -> void { + setVisibleMeditationEnd(); + application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); + }; + timer->registerTimeoutCallback(onMeditationEnd); + timer->reset(meditationTime, meditationIntervalPeriod); + timer->start(); application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); }; - timer->registerTimeoutCallback(onMeditationEnd); - timer->reset(meditationTime, meditationIntervalPeriod); - timer->start(); - application->refreshWindow(RefreshModes::GUI_REFRESH_FAST); - }; - timer->registerTimeoutCallback(onPreparation); - timer->setCounterVisible(timerData->isCounterEnabled()); - timer->reset(timerData->getPreparationTime()); - timer->start(); + timer->registerTimeoutCallback(onPreparation); + timer->setCounterVisible(timerData->isCounterEnabled()); + timer->reset(timerData->getPreparationTime()); + timer->start(); + } } auto MeditationTimerWindow::onInput(const InputEvent &inputEvent) -> bool diff --git a/module-audio/Audio/Audio.cpp b/module-audio/Audio/Audio.cpp index 7acc778e597f54b0573d83a47a5f6a4d51547f4f..05aab6e740fd4ae6f15f868d48b64241f703575f 100644 --- a/module-audio/Audio/Audio.cpp +++ b/module-audio/Audio/Audio.cpp @@ -124,6 +124,7 @@ namespace audio LOG_ERROR("Operation STOP failure: %s", audio::str(retStop).c_str()); } + muted = Muted::False; auto ret = Operation::Create(Operation::Type::Idle); if (ret) { currentState = State::Idle; @@ -154,6 +155,7 @@ namespace audio audio::RetCode Audio::Mute() { + muted = Muted::True; return SetOutputVolume(0); } diff --git a/module-audio/Audio/Audio.hpp b/module-audio/Audio/Audio.hpp index a110c6ab03f683e0bf3c6adc676baeb2bf9f4f6d..c6608ca306ae7cfc88555f0b0016ddfc0a0e544e 100644 --- a/module-audio/Audio/Audio.hpp +++ b/module-audio/Audio/Audio.hpp @@ -19,6 +19,12 @@ namespace audio class Audio { + enum class Muted : bool + { + True, + False + }; + public: enum class State { @@ -61,6 +67,11 @@ namespace audio return currentOperation->GetInputGain(); } + [[nodiscard]] auto IsMuted() const noexcept + { + return muted == Muted::True; + } + const Operation &GetCurrentOperation() const { // currentOperation always exists - null pattern design @@ -103,6 +114,7 @@ namespace audio private: void UpdateProfiles(); + Muted muted = Muted::False; AudioSinkState audioSinkState; std::shared_ptr btData; diff --git a/module-services/service-audio/ServiceAudio.cpp b/module-services/service-audio/ServiceAudio.cpp index 038694c14df762e3cb44a50b172c6fa8bb83440c..3297fc5a315a3f6c2199f735dcbbe4d9032f9827 100644 --- a/module-services/service-audio/ServiceAudio.cpp +++ b/module-services/service-audio/ServiceAudio.cpp @@ -410,8 +410,7 @@ std::unique_ptr ServiceAudio::HandleSendEvent(std::shared_ } std::unique_ptr ServiceAudio::HandleStop(const std::vector &stopTypes, - const Token &token, - bool &muted) + const Token &token) { std::vector> retCodes; @@ -439,7 +438,6 @@ std::unique_ptr ServiceAudio::HandleStop(const std::vector for (auto &input : audioMux.GetAllInputs()) { const auto ¤tOperation = input.audio->GetCurrentOperation(); if (std::find(stopTypes.begin(), stopTypes.end(), currentOperation.GetPlaybackType()) != stopTypes.end()) { - muted = true; auto t = input.token; retCodes.emplace_back(t, stopInput(&input)); } @@ -464,19 +462,15 @@ std::unique_ptr ServiceAudio::HandleStop(const std::vector return std::make_unique(audio::RetCode::Success, token); } -std::unique_ptr ServiceAudio::HandleStop(const std::vector &stopTypes, - const Token &token) -{ - bool muted = false; - return HandleStop(stopTypes, token, muted); -} - void ServiceAudio::HandleNotification(const AudioNotificationMessage::Type &type, const Token &token) { if (type == AudioNotificationMessage::Type::EndOfFile) { auto input = audioMux.GetInput(token); if (input && ShouldLoop((*input)->audio->GetCurrentOperationPlaybackType())) { (*input)->audio->Start(); + if ((*input)->audio->IsMuted()) { + (*input)->audio->Mute(); + } } else { auto newMsg = std::make_shared(token); @@ -492,9 +486,6 @@ void ServiceAudio::HandleNotification(const AudioNotificationMessage::Type &type auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr { - - // mute if 0 and return with parameter shouldn't popup - bool muted = false; auto context = getCurrentContext(); const auto currentVolume = @@ -503,13 +494,13 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr(audio::RetCode::Success, 0, muted, context); - } + MuteCurrentOperation(); + return std::make_unique( + audio::RetCode::Success, 0, AudioKeyPressedResponse::ShowPopup::False, context); } else { - return std::make_unique(audio::RetCode::Success, currentVolume, muted, context); + return std::make_unique( + audio::RetCode::Success, currentVolume, AudioKeyPressedResponse::ShowPopup::False, context); } } @@ -524,7 +515,8 @@ auto ServiceAudio::HandleKeyPressed(const int step) -> std::unique_ptr(audio::RetCode::Success, newVolume, muted, context); + return std::make_unique( + audio::RetCode::Success, newVolume, AudioKeyPressedResponse::ShowPopup::True, context); } void ServiceAudio::HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode, @@ -547,6 +539,13 @@ void ServiceAudio::HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode, } } +void ServiceAudio::MuteCurrentOperation() +{ + for (auto &input : audioMux.GetAllInputs()) { + input.audio->Mute(); + } +} + bool ServiceAudio::IsBusy() { for (auto &input : audioMux.GetAllInputs()) { diff --git a/module-services/service-audio/service-audio/AudioMessage.hpp b/module-services/service-audio/service-audio/AudioMessage.hpp index e5cb9d0880312c812924cf8c334cb4bb80bb5e89..ac6919085ed332a1b0c2bbd251adcdf77535498a 100644 --- a/module-services/service-audio/service-audio/AudioMessage.hpp +++ b/module-services/service-audio/service-audio/AudioMessage.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -262,14 +262,19 @@ class AudioKeyPressedRequest : public AudioMessage class AudioKeyPressedResponse : public sys::DataMessage { public: + enum class ShowPopup : bool + { + True, + False + }; AudioKeyPressedResponse(audio::RetCode retCode, const audio::Volume &volume, - const bool muted, + const ShowPopup showPopup, const std::pair &context) - : sys::DataMessage(MessageType::AudioMessage), volume(volume), muted(muted), context(context) + : sys::DataMessage(MessageType::AudioMessage), volume(volume), showPopup(showPopup), context(context) {} const audio::Volume volume{}; - const bool muted = false; + const ShowPopup showPopup = ShowPopup::False; std::pair context; }; diff --git a/module-services/service-audio/service-audio/ServiceAudio.hpp b/module-services/service-audio/service-audio/ServiceAudio.hpp index 0fdf35185cf6d306ecf54f953fe0fcac832346ab..1f33e960dc97beb768febeb9e136bb4f0fb07612 100644 --- a/module-services/service-audio/service-audio/ServiceAudio.hpp +++ b/module-services/service-audio/service-audio/ServiceAudio.hpp @@ -72,8 +72,6 @@ class ServiceAudio : public sys::Service const std::string = "", const audio::PlaybackType &playbackType = audio::PlaybackType::None) -> std::unique_ptr; - auto HandleStop(const std::vector &stopTypes, const audio::Token &token, bool &muted) - -> std::unique_ptr; auto HandleStop(const std::vector &stopTypes, const audio::Token &token) -> std::unique_ptr; auto HandleSendEvent(std::shared_ptr evt) -> std::unique_ptr; @@ -84,6 +82,7 @@ class ServiceAudio : public sys::Service void HandleNotification(const AudioNotificationMessage::Type &type, const audio::Token &token); auto HandleKeyPressed(const int step) -> std::unique_ptr; void HandlePhoneModeChange(sys::phone_modes::PhoneMode phoneMode, sys::phone_modes::Tethering tetheringMode); + void MuteCurrentOperation(); void VibrationUpdate(const audio::PlaybackType &type = audio::PlaybackType::None, std::optional input = std::nullopt); auto GetVibrationType(const audio::PlaybackType &type) -> VibrationType;