~aleteoryx/muditaos

6146ddb822f4e3f0aa42ccb31c2db0f279d13d3a — mkamonMdt 4 years ago f5afc7d
[BH-914] Add BGSounds volume change functionality

The commit provides an implementation to changing
volume in Background Sounds application. The
implementation attaches the  app-scoped window
to the existing pop-up mechanism.
M products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp => products/BellHybrid/apps/application-bell-background-sounds/ApplicationBellBackgroundSounds.cpp +2 -1
@@ 65,7 65,8 @@ namespace app
        windowsFactory.attach(gui::window::name::bgSoundsPaused, [](ApplicationCommon *app, const std::string &name) {
            return std::make_unique<gui::BGSoundsPausedWindow>(app);
        });
        windowsFactory.attach(gui::window::name::bgSoundsVolume, [](ApplicationCommon *app, const std::string &name) {

        windowsFactory.attach(gui::popup::window::volume_window, [](ApplicationCommon *app, const std::string &name) {
            auto presenter = std::make_unique<bgSounds::BGSoundsVolumePresenter>();
            return std::make_unique<gui::BGSoundsVolumeWindow>(app, std::move(presenter));
        });

M products/BellHybrid/apps/application-bell-background-sounds/data/BGSoundsCommon.hpp => products/BellHybrid/apps/application-bell-background-sounds/data/BGSoundsCommon.hpp +1 -0
@@ 6,4 6,5 @@
namespace app::bgSounds
{
    constexpr auto timerValueDBRecordName = "BGSoundsTimerValue";
    constexpr auto soundsVolumeDBRecordName = "BGSoundsVolume";
}

M products/BellHybrid/apps/application-bell-background-sounds/include/application-bell-background-sounds/ApplicationBellBackgroundSounds.hpp => products/BellHybrid/apps/application-bell-background-sounds/include/application-bell-background-sounds/ApplicationBellBackgroundSounds.hpp +0 -1
@@ 10,7 10,6 @@ namespace gui::window::name
    inline constexpr auto bgSoundsPaused      = "BGSoundsPausedWindow";
    inline constexpr auto bgSoundsProgress    = "BGSoundsProgressWindow";
    inline constexpr auto bgSoundsTimerSelect = "BGSoundsTimerSelectWindow";
    inline constexpr auto bgSoundsVolume      = "BGSoundsVolumeWindow";
} // namespace gui::window::name
namespace app
{

M products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp => products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.cpp +2 -8
@@ 5,20 5,14 @@

namespace app::bgSounds
{
    BGSoundsVolumePresenter::BGSoundsVolumePresenter()
    {}

    VolumeData BGSoundsVolumePresenter::getVolumeData()
    {
        return volumeData;
    }

    unsigned int BGSoundsVolumePresenter::getCurrentVolume()
    audio::Volume BGSoundsVolumePresenter::getDefaultVolume()
    {
        return currentVolume;
        return audio::defaultVolume;
    }

    void BGSoundsVolumePresenter::onVolumeChanged(unsigned int volume)
    {}

} // namespace app::bgSounds

M products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp => products/BellHybrid/apps/application-bell-background-sounds/presenter/BGSoundsVolumePresenter.hpp +9 -14
@@ 4,14 4,15 @@
#pragma once

#include <apps-common/BasePresenter.hpp>
#include <module-audio/Audio/AudioCommon.hpp>

namespace app::bgSounds
{
    using VolumeData = struct VolumeData
    {
        unsigned int min;
        unsigned int max;
        unsigned int step;
        audio::Volume min;
        audio::Volume max;
        audio::Volume step;
    };

    class BGSoundsVolumeContract


@@ 25,25 26,19 @@ namespace app::bgSounds
        class Presenter : public BasePresenter<BGSoundsVolumeContract::View>
        {
          public:
            virtual VolumeData getVolumeData()                = 0;
            virtual unsigned int getCurrentVolume()           = 0;
            virtual void onVolumeChanged(unsigned int volume) = 0;
            virtual VolumeData getVolumeData()       = 0;
            virtual audio::Volume getDefaultVolume() = 0;
        };
    };

    class BGSoundsVolumePresenter : public BGSoundsVolumeContract::Presenter
    {
        struct VolumeData volumeData
        constexpr static struct VolumeData volumeData
        {
            0U, 10U, 1U
            audio::minVolume, audio::maxVolume, audio::defaultVolumeStep
        };
        unsigned int currentVolume = 5U;

        VolumeData getVolumeData() override;
        unsigned int getCurrentVolume() override;
        void onVolumeChanged(unsigned int volume) override;

      public:
        BGSoundsVolumePresenter();
        audio::Volume getDefaultVolume() override;
    };
} // namespace app::bgSounds

M products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsProgressWindow.cpp => products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsProgressWindow.cpp +8 -0
@@ 117,6 117,14 @@ namespace gui
                presenter->pause();
                return true;
            }
            else if (inputEvent.is(KeyCode::KEY_DOWN)) {
                application->decreaseCurrentVolume();
                return true;
            }
            else if (inputEvent.is(KeyCode::KEY_UP)) {
                application->increaseCurrentVolume();
                return true;
            }
        }
        return AppWindow::onInput(inputEvent);
    }

M products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp => products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.cpp +29 -11
@@ 5,12 5,13 @@
#include <ApplicationBellBackgroundSounds.hpp>
#include <apps-common/widgets/BellBaseLayout.hpp>
#include <data/BGSoundsStyle.hpp>
#include <popups/data/PopupData.hpp>

namespace gui
{
    BGSoundsVolumeWindow::BGSoundsVolumeWindow(
        app::ApplicationCommon *app, std::unique_ptr<app::bgSounds::BGSoundsVolumeContract::Presenter> &&presenter)
        : WindowWithTimer(app, gui::window::name::bgSoundsVolume), presenter{std::move(presenter)}
        : WindowWithTimer(app, gui::popup::window::volume_window), presenter{std::move(presenter)}
    {
        buildInterface();
        this->presenter->attach(this);


@@ 36,12 37,15 @@ namespace gui
        topMessage->drawUnderline(false);

        auto data = presenter->getVolumeData();
        spinner   = new UIntegerSpinner({data.min, data.max, data.step}, Boundaries::Fixed);
        spinner   = new UIntegerSpinner({static_cast<UIntegerSpinner::Type>(data.min),
                                       static_cast<UIntegerSpinner::Type>(data.max),
                                       static_cast<UIntegerSpinner::Type>(data.step)},
                                      Boundaries::Fixed);
        spinner->setMaximumSize(style::bell_base_layout::w, style::bell_base_layout::center_layout_h);
        spinner->setFont(bgSoundsStyle::valumeValueFont);
        spinner->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        spinner->setFocusEdges(RectangleEdge::None);
        spinner->setCurrentValue(presenter->getCurrentVolume());
        spinner->setCurrentValue(static_cast<UIntegerSpinner::Type>(presenter->getDefaultVolume()));
        body->getCenterBox()->addWidget(spinner);

        setFocusItem(spinner);


@@ 51,18 55,32 @@ namespace gui
    bool BGSoundsVolumeWindow::onInput(const gui::InputEvent &inputEvent)
    {
        resetTimer();
        if (spinner->onInput(inputEvent)) {
            auto currentVolume = spinner->getCurrentValue();
            presenter->onVolumeChanged(currentVolume);

            auto isMax = currentVolume == presenter->getVolumeData().max;
            auto isMin = currentVolume == presenter->getVolumeData().min;
            body->setArrowVisible(BellBaseLayout::Arrow::Left, isMin);
            body->setArrowVisible(BellBaseLayout::Arrow::Right, isMax);

        if (inputEvent.isShortRelease(KeyCode::KEY_DOWN)) {
            application->decreaseCurrentVolume();
            return true;
        }
        else if (inputEvent.isShortRelease(KeyCode::KEY_UP)) {
            application->increaseCurrentVolume();
            return true;
        }
        return WindowWithTimer::onInput(inputEvent);
    }

    void BGSoundsVolumeWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        WindowWithTimer::onBeforeShow(mode, data);
        const auto popupData = dynamic_cast<VolumePopupData *>(data);
        if (popupData) {
            volume       = popupData->getVolume();
            audioContext = popupData->getAudioContext();
            spinner->setCurrentValue(static_cast<UIntegerSpinner::Type>(volume));
            auto currentVolume = spinner->getCurrentValue();

            auto isMax = currentVolume == presenter->getVolumeData().max;
            auto isMin = currentVolume == presenter->getVolumeData().min;
            body->setArrowVisible(BellBaseLayout::Arrow::Left, not isMin);
            body->setArrowVisible(BellBaseLayout::Arrow::Right, not isMax);
        }
    }
} // namespace gui

M products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp => products/BellHybrid/apps/application-bell-background-sounds/windows/BGSoundsVolumeWindow.hpp +5 -0
@@ 8,18 8,23 @@
#include <apps-common/popups/WindowWithTimer.hpp>
#include <apps-common/widgets/spinners/Spinners.hpp>

#include <module-audio/Audio/AudioCommon.hpp>
#include <module-audio/Audio/Profiles/Profile.hpp>
namespace gui
{
    class BellBaseLayout;
    class BGSoundsVolumeWindow : public WindowWithTimer, public app::bgSounds::BGSoundsVolumeContract::View
    {
        std::unique_ptr<app::bgSounds::BGSoundsVolumeContract::Presenter> presenter;
        audio::Volume volume = 0;
        audio::Context audioContext;

        BellBaseLayout *body{};
        UIntegerSpinner *spinner = nullptr;

        void buildInterface() override;
        bool onInput(const gui::InputEvent &inputEvent) override;
        void onBeforeShow(ShowMode mode, SwitchData *data);

      public:
        BGSoundsVolumeWindow(app::ApplicationCommon *app,