~aleteoryx/muditaos

993c2c4f3f8922ccc748a1e7328a68c54c2240cf — rrandomsky 2 years ago 89829b9
[BH-1843] Add progress bar for volume adjustment windows

A progress bar has been added for all volume control windows.
M harmony_changelog.md => harmony_changelog.md +1 -0
@@ 12,6 12,7 @@
* Added date format setting
* Added colors of noise to Relaxation
* Added gradual alarm volume increase
* Added progress bar for all volume control windows

### Changed / Improved
* Optimize the way Relaxation is loading music files

M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp +7 -4
@@ 11,6 11,7 @@
#include <ApplicationCommon.hpp>
#include <common/widgets/list_items/Fraction.hpp>
#include <common/widgets/list_items/Numeric.hpp>
#include <common/widgets/list_items/NumericWithBar.hpp>
#include <common/LanguageUtils.hpp>
#include <apps-common/InternalModel.hpp>
#include <apps-common/widgets/spinners/Spinners.hpp>


@@ 75,10 76,12 @@ namespace app::meditation
                                                     utils::translate("app_bell_meditation_start_delay"),
                                                     utils::translate("common_second_lower")};

        auto chimeVolume = new list_items::Numeric{
            list_items::Numeric::spinner_type::range{AbstractAudioModel::minVolume, AbstractAudioModel::maxVolume, 1},
            chimeVolumeModel,
            utils::translate("app_bell_meditation_chime_volume")};
        auto chimeVolume =
            new list_items::NumericWithBar{list_items::NumericWithBar::spinner_type::range{
                                               AbstractAudioModel::minVolume, AbstractAudioModel::maxVolume, 1},
                                           chimeVolumeModel,
                                           AbstractAudioModel::maxVolume,
                                           utils::translate("app_bell_meditation_chime_volume")};

        listItemsProvider =
            std::make_shared<BellListItemProvider>(BellListItemProvider::Items{startDelay, chimeInterval, chimeVolume});

M products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp => products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp +9 -2
@@ 33,12 33,19 @@ namespace gui::relaxationStyle

    namespace relStyle
    {
        namespace progress
        namespace progressTime
        {
            inline constexpr auto radius                   = 192U;
            inline constexpr auto penWidth                 = 3U;
            inline constexpr auto verticalDeviationDegrees = 38U;
        } // namespace progress
        } // namespace progressTime

        namespace progressVolume
        {
            inline constexpr auto radius                   = 192U;
            inline constexpr auto penWidth                 = 3U;
            inline constexpr auto verticalDeviationDegrees = 38U + 30U;
        } // namespace progressVolume

        namespace timer
        {

M products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp => products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp +4 -4
@@ 43,10 43,10 @@ namespace gui
    void RelaxationRunningProgressWindow::buildLayout()
    {
        using namespace gui::relaxationStyle;
        const auto progressArcRadius = relStyle::progress::radius;
        const auto progressArcWidth  = relStyle::progress::penWidth;
        const auto arcStartAngle     = -90 - relStyle::progress::verticalDeviationDegrees;
        const auto arcSweepAngle     = 360 - (2 * relStyle::progress::verticalDeviationDegrees);
        const auto progressArcRadius = relStyle::progressTime::radius;
        const auto progressArcWidth  = relStyle::progressTime::penWidth;
        const auto arcStartAngle     = -90 - relStyle::progressTime::verticalDeviationDegrees;
        const auto arcSweepAngle     = 360 - (2 * relStyle::progressTime::verticalDeviationDegrees);
        const auto arcProgressSteps  = 1000;

        Arc::ShapeParams arcParams;

M products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationVolumeWindow.cpp => products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationVolumeWindow.cpp +22 -1
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "RelaxationVolumeWindow.hpp"


@@ 7,6 7,7 @@

#include <apps-common/widgets/BellBaseLayout.hpp>
#include <popups/data/PopupData.hpp>
#include <apps-common/widgets/ProgressTimerWithBarGraphAndCounter.hpp>

namespace gui
{


@@ 36,6 37,25 @@ namespace gui
        topMessage->setText(utils::translate("app_settings_volume"));
        topMessage->drawUnderline(false);

        using namespace gui::relaxationStyle;
        const auto progressArcRadius = relStyle::progressVolume::radius;
        const auto progressArcWidth  = relStyle::progressVolume::penWidth;
        const auto arcStartAngle     = -90 - relStyle::progressVolume::verticalDeviationDegrees;
        const auto arcSweepAngle     = 360 - (2 * (relStyle::progressVolume::verticalDeviationDegrees));
        const auto arcProgressSteps  = app::AbstractAudioModel::maxVolume;

        Arc::ShapeParams arcParams;
        arcParams.setCenterPoint(Point(getWidth() / 2, getHeight() / 2))
            .setRadius(progressArcRadius)
            .setStartAngle(arcStartAngle)
            .setSweepAngle(arcSweepAngle)
            .setPenWidth(progressArcWidth)
            .setBorderColor(ColorFullBlack);

        progress = new ArcProgressBar(this, arcParams, ArcProgressBar::ProgressDirection::CounterClockwise);
        progress->setMaximum(arcProgressSteps);
        progress->setValue(presenter->getVolume());

        auto data = presenter->getVolumeData();
        spinner   = new U8IntegerSpinner({static_cast<U8IntegerSpinner::value_type>(data.min),
                                        static_cast<U8IntegerSpinner::value_type>(data.max),


@@ 65,6 85,7 @@ namespace gui
        auto data              = presenter->getVolumeData();
        const auto ret         = body->onInput(inputEvent);
        const auto selectedVal = spinner->value();
        progress->setValue(presenter->getVolume());
        body->setMinMaxArrowsVisibility(selectedVal == data.min, selectedVal == data.max);
        return ret;
    }

M products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationVolumeWindow.hpp => products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationVolumeWindow.hpp +5 -3
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 8,6 8,7 @@
#include <apps-common/popups/WindowWithTimer.hpp>
#include <apps-common/widgets/spinners/Spinners.hpp>
#include <common/models/AbstractAudioModel.hpp>
#include <apps-common/widgets/BarGraph.hpp>

namespace gui
{


@@ 21,8 22,9 @@ namespace gui
      private:
        std::unique_ptr<app::relaxation::AbstractRelaxationVolumePresenter> presenter;

        BellBaseLayout *body      = nullptr;
        U8IntegerSpinner *spinner = nullptr;
        BellBaseLayout *body          = nullptr;
        U8IntegerSpinner *spinner     = nullptr;
        gui::ArcProgressBar *progress = nullptr;

        void buildInterface() override;
        bool onInput(const gui::InputEvent &inputEvent) override;

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp +6 -4
@@ 8,6 8,7 @@
#include <common/widgets/ListItems.hpp>
#include <common/widgets/list_items/Text.hpp>
#include <common/widgets/list_items/Numeric.hpp>
#include <common/widgets/list_items/NumericWithBar.hpp>
#include <apps-common/ApplicationCommon.hpp>

namespace app::bell_settings


@@ 52,10 53,11 @@ namespace app::bell_settings
        constexpr auto volumeStep = 1U;
        constexpr auto volumeMin  = AbstractAudioModel::minVolume;
        constexpr auto volumeMax  = AbstractAudioModel::maxVolume;
        auto alarmVolume =
            new list_items::Numeric(list_items::Numeric::spinner_type::range{volumeMin, volumeMax, volumeStep},
                                    settingsModel.getAlarmVolume(),
                                    utils::translate("app_bell_settings_alarm_settings_volume"));
        auto alarmVolume          = new list_items::NumericWithBar(
            list_items::NumericWithBar::spinner_type::range{volumeMin, volumeMax, volumeStep},
            settingsModel.getAlarmVolume(),
            volumeMax,
            utils::translate("app_bell_settings_alarm_settings_volume"));
        alarmVolume->set_on_value_change_cb([this](const auto &val) {
            if (onVolumeChange) {
                onVolumeChange(val);

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp +6 -5
@@ 4,7 4,7 @@
#include "BedtimeSettingsListItemProvider.hpp"
#include "BellSettingsStyle.hpp"
#include "common/models/AbstractAudioModel.hpp"
#include <common/widgets/list_items/Numeric.hpp>
#include <common/widgets/list_items/NumericWithBar.hpp>
#include <common/widgets/list_items/Text.hpp>
#include <apps-common/ApplicationCommon.hpp>
#include <gui/widgets/ListViewEngine.hpp>


@@ 47,10 47,11 @@ namespace app::bell_settings
        constexpr auto volumeStep = 1U;
        constexpr auto volumeMin  = AbstractAudioModel::minVolume;
        constexpr auto volumeMax  = AbstractAudioModel::maxVolume;
        auto volume =
            new list_items::Numeric(list_items::Numeric::spinner_type::range{volumeMin, volumeMax, volumeStep},
                                    model->getBedtimeVolume(),
                                    utils::translate("app_bell_settings_bedtime_settings_volume"));
        auto volume               = new list_items::NumericWithBar(
            list_items::NumericWithBar::spinner_type::range{volumeMin, volumeMax, volumeStep},
            model->getBedtimeVolume(),
            volumeMax,
            utils::translate("app_bell_settings_bedtime_settings_volume"));
        volume->set_on_value_change_cb([this](const auto &val) {
            if (onVolumeChange) {
                onVolumeChange(val);

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp +6 -4
@@ 6,6 6,7 @@
#include <common/models/FrontlightModel.hpp>
#include <common/widgets/list_items/NumberWithSuffix.hpp>
#include <common/widgets/list_items/Numeric.hpp>
#include <common/widgets/list_items/NumericWithBar.hpp>
#include <common/widgets/ListItems.hpp>
#include <common/widgets/list_items/Text.hpp>
#include <apps-common/ApplicationCommon.hpp>


@@ 73,10 74,11 @@ namespace app::bell_settings
        constexpr auto volumeStep = 1U;
        constexpr auto volumeMin  = AbstractAudioModel::minVolume;
        constexpr auto volumeMax  = AbstractAudioModel::maxVolume;
        auto volume =
            new list_items::Numeric(list_items::Numeric::spinner_type::range{volumeMin, volumeMax, volumeStep},
                                    settingsModel.getChimeVolume(),
                                    utils::translate("app_bell_settings_alarm_settings_prewake_up_chime_volume"));
        auto volume               = new list_items::NumericWithBar(
            list_items::NumericWithBar::spinner_type::range{volumeMin, volumeMax, volumeStep},
            settingsModel.getChimeVolume(),
            volumeMax,
            utils::translate("app_bell_settings_alarm_settings_prewake_up_chime_volume"));
        volume->set_on_value_change_cb([this](const auto &val) {
            if (onVolumeChange) {
                onVolumeChange(val);

M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp +6 -4
@@ 5,6 5,7 @@
#include "common/models/AbstractAudioModel.hpp"
#include <common/widgets/list_items/NumberWithSuffix.hpp>
#include <common/widgets/list_items/Numeric.hpp>
#include <common/widgets/list_items/NumericWithBar.hpp>
#include <common/widgets/list_items/Text.hpp>
#include <common/widgets/ListItems.hpp>
#include <common/LanguageUtils.hpp>


@@ 145,10 146,11 @@ namespace app::bell_settings
        constexpr auto volumeStep = 1U;
        constexpr auto volumeMin  = AbstractAudioModel::minVolume;
        constexpr auto volumeMax  = AbstractAudioModel::maxVolume;
        auto snoozeChimeVolume =
            new list_items::Numeric(list_items::Numeric::spinner_type::range{volumeMin, volumeMax, volumeStep},
                                    model.getSnoozeChimeVolume(),
                                    utils::translate("app_bell_settings_alarm_settings_snooze_chime_volume"));
        auto snoozeChimeVolume    = new list_items::NumericWithBar(
            list_items::NumericWithBar::spinner_type::range{volumeMin, volumeMax, volumeStep},
            model.getSnoozeChimeVolume(),
            volumeMax,
            utils::translate("app_bell_settings_alarm_settings_snooze_chime_volume"));
        snoozeChimeVolume->set_on_value_change_cb([this](const auto &val) {
            if (onVolumeChange) {
                onVolumeChange(val);

A products/BellHybrid/apps/common/include/common/data/ListItemBarStyle.hpp => products/BellHybrid/apps/common/include/common/data/ListItemBarStyle.hpp +21 -0
@@ 0,0 1,21 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

namespace listItemBarStyle
{
    namespace window
    {
        constexpr inline auto windowWidth  = 600;
        constexpr inline auto windowHeight = 480;
    } // namespace window

    namespace progress
    {
        constexpr inline auto radius                   = 192U;
        constexpr inline auto penWidth                 = 3U;
        constexpr inline auto verticalDeviationDegrees = 38U + 30U;
    } // namespace progress

} // namespace listItemBarStyle

A products/BellHybrid/apps/common/include/common/widgets/list_items/NumericWithBar.hpp => products/BellHybrid/apps/common/include/common/widgets/list_items/NumericWithBar.hpp +26 -0
@@ 0,0 1,26 @@
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once

#include "details.hpp"
#include <i18n/i18n.hpp>
#include <utility>

namespace app::list_items
{
    class NumericWithBar : public details::ListItemBaseWithBar<gui::U8IntegerSpinner>
    {
        gui::ArcProgressBar *progress = nullptr;

      public:
        NumericWithBar(gui::U8IntegerSpinner::range &&range,
                       gui::AbstractSettingsModel<gui::U8IntegerSpinner::value_type> &model,
                       const std::uint8_t barSteps,
                       const std::string &topDescription    = "",
                       const std::string &bottomDescription = "")
            : details::ListItemBaseWithBar<gui::U8IntegerSpinner>(
                  std::move(range), model, barSteps, topDescription, bottomDescription)
        {}
    };
} // namespace app::list_items

M products/BellHybrid/apps/common/include/common/widgets/list_items/details.hpp => products/BellHybrid/apps/common/include/common/widgets/list_items/details.hpp +55 -7
@@ 1,4 1,4 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#pragma once


@@ 9,6 9,9 @@

#include <apps-common/widgets/spinners/Spinners.hpp>
#include <apps-common/widgets/TimeSetFmtSpinner.hpp>
#include <apps-common/widgets/ProgressTimerWithBarGraphAndCounter.hpp>
#include <apps-common/widgets/BarGraph.hpp>
#include "common/data/ListItemBarStyle.hpp"

namespace app::list_items
{


@@ 17,6 20,7 @@ namespace app::list_items
        template <typename SpinnerType>
        class ListItemBase : public gui::BellSideListItemWithCallbacks
        {

          public:
            using spinner_type = SpinnerType;
            using value_type   = typename SpinnerType::value_type;


@@ 29,7 33,7 @@ namespace app::list_items
            void set_value(const value_type &value)
            {
                spinner->set_value(value);
                control_visibility();
                controlVisibility();
            }

            void set_range(const typename spinner_type::range &range)


@@ 70,7 74,7 @@ namespace app::list_items
                }

                spinner->onValueChanged = [this](const auto &val) {
                    control_visibility();
                    controlVisibility();
                    if (onValueChangeCb) {
                        onValueChangeCb(val);
                    }


@@ 79,7 83,7 @@ namespace app::list_items
                getValue = [this]() { this->model.setValue(this->spinner->value()); };
                setValue = [this]() {
                    this->spinner->set_value(this->model.getValue());
                    control_visibility();
                    controlVisibility();
                };

                inputCallback = [this, &bottomDescription](Item &, const gui::InputEvent &event) {


@@ 88,13 92,12 @@ namespace app::list_items

                focusChangedCallback = [this, &bottomDescription](Item &) {
                    OnFocusChangedCallback();
                    control_visibility();
                    controlVisibility();
                    return true;
                };
            }

          private:
            void control_visibility()
            virtual void controlVisibility()
            {
                body->setMinMaxArrowsVisibility(spinner->is_min(), spinner->is_max());
                if (not this->bottomDescription.empty()) {


@@ 107,6 110,51 @@ namespace app::list_items
            std::string bottomDescription;
            std::function<void(const value_type &)> onValueChangeCb;
        };

        template <typename SpinnerType>
        class ListItemBaseWithBar : public ListItemBase<SpinnerType>
        {
          public:
            using spinner_type = SpinnerType;
            using value_type   = typename SpinnerType::value_type;

          protected:
            explicit ListItemBaseWithBar(typename SpinnerType::range &&range,
                                         gui::AbstractSettingsModel<value_type> &model,
                                         const std::uint8_t barSteps,
                                         const std::string &topDescription    = "",
                                         const std::string &bottomDescription = "")
                : ListItemBase<SpinnerType>(std::move(range), model, topDescription, bottomDescription)
            {
                using namespace listItemBarStyle;
                const auto progressArcRadius = progress::radius;
                const auto progressArcWidth  = progress::penWidth;
                const auto arcStartAngle     = -90 - progress::verticalDeviationDegrees;
                const auto arcSweepAngle     = 360 - (2 * (progress::verticalDeviationDegrees));

                gui::Arc::ShapeParams arcParams;
                arcParams.setCenterPoint(gui::Point(window::windowWidth / 2, window::windowHeight / 2))
                    .setRadius(progressArcRadius)
                    .setStartAngle(arcStartAngle)
                    .setSweepAngle(arcSweepAngle)
                    .setPenWidth(progressArcWidth)
                    .setBorderColor(gui::ColorFullBlack);

                progress =
                    new gui::ArcProgressBar(this, arcParams, gui::ArcProgressBar::ProgressDirection::CounterClockwise);
                progress->setMaximum(barSteps);
                progress->setValue(static_cast<unsigned int>(this->spinner->value()));
            }

            gui::ArcProgressBar *progress = nullptr;
            void controlVisibility() override
            {
                ListItemBase<SpinnerType>::controlVisibility();
                if (progress && this->spinner) {
                    progress->setValue(static_cast<unsigned int>(this->spinner->value()));
                }
            }
        };
    } // namespace details

} // namespace app::list_items