~aleteoryx/muditaos

6ca2d383075d930d44434802cd4f205e0a5d1ad2 — Mateusz Piesta 4 years ago ca38dff
[BH-875] Snooze settings model fix

Fixed bug in GenericSpinner.
Added proper error handling.
M module-apps/apps-common/widgets/spinners/GenericSpinner.hpp => module-apps/apps-common/widgets/spinners/GenericSpinner.hpp +2 -2
@@ 74,13 74,13 @@ namespace gui

    template <typename ValuePolicy> bool GenericSpinner<ValuePolicy>::isPreviousEvent(const InputEvent &inputEvent)
    {
        return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_UP)) ||
        return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_DOWN)) ||
               (orientation == Orientation::Horizontal && inputEvent.is(KeyCode::KEY_LEFT));
    }

    template <typename ValuePolicy> bool GenericSpinner<ValuePolicy>::isNextEvent(const InputEvent &inputEvent)
    {
        return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_DOWN)) ||
        return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_UP)) ||
               (orientation == Orientation::Horizontal && inputEvent.is(KeyCode::KEY_RIGHT));
    }


M products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.cpp => products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeSettingsModel.cpp +25 -9
@@ 6,6 6,26 @@
#include <apps-common/ApplicationCommon.hpp>
#include <db/SystemSettings.hpp>

namespace
{
    template <typename T> std::optional<T> get_helper(settings::Settings &settings, const std::string &str)
    {
        const auto retStr = settings.getValue(str, settings::SettingsScope::Global);
        if (retStr.empty()) {
            LOG_ERROR("%s does not exist", str.c_str());
            return {};
        }
        else {
            if constexpr (std::is_integral_v<T>) {
                return utils::toNumeric(retStr);
            }
            else {
                return retStr;
            }
        }
    }
} // namespace

namespace app::bell_settings
{
    void SnoozeOnOffModel::setValue(bool value)


@@ 16,8 36,7 @@ namespace app::bell_settings

    bool SnoozeOnOffModel::getValue() const
    {
        const auto str = settings.getValue(bell::settings::Snooze::active, settings::SettingsScope::Global);
        return std::stoi(str);
        return get_helper<bool>(settings, bell::settings::Snooze::active).value_or(false);
    }

    void SnoozeLengthModel::setValue(std::uint8_t value)


@@ 28,8 47,7 @@ namespace app::bell_settings

    std::uint8_t SnoozeLengthModel::getValue() const
    {
        const auto str = settings.getValue(bell::settings::Snooze::length, settings::SettingsScope::Global);
        return std::stoi(str);
        return get_helper<std::uint8_t>(settings, bell::settings::Snooze::length).value_or(0);
    }

    void SnoozeChimeIntervalModel::setValue(std::uint8_t value)


@@ 40,8 58,7 @@ namespace app::bell_settings

    std::uint8_t SnoozeChimeIntervalModel::getValue() const
    {
        const auto str = settings.getValue(bell::settings::Snooze::interval, settings::SettingsScope::Global);
        return std::stoi(str);
        return get_helper<std::uint8_t>(settings, bell::settings::Snooze::interval).value_or(0);
    }

    void SnoozeChimeToneModel::setValue(UTF8 value)


@@ 51,7 68,7 @@ namespace app::bell_settings

    UTF8 SnoozeChimeToneModel::getValue() const
    {
        return settings.getValue(bell::settings::Snooze::tone, settings::SettingsScope::Global);
        return get_helper<UTF8>(settings, bell::settings::Snooze::tone).value_or("");
    }

    void SnoozeChimeVolumeModel::setValue(std::uint8_t value)


@@ 62,7 79,6 @@ namespace app::bell_settings

    std::uint8_t SnoozeChimeVolumeModel::getValue() const
    {
        const auto str = settings.getValue(bell::settings::Snooze::volume, settings::SettingsScope::Global);
        return std::stoi(str);
        return get_helper<std::uint8_t>(settings, bell::settings::Snooze::volume).value_or(0);
    }
} // namespace app::bell_settings