~aleteoryx/muditaos

d0ac5f989ea9e718387533fdc4ddcf72188e41af — Paweł Joński 3 years ago c38aa53
[BH-1193] Snooze length UI sync

Snooze length UI sync
Rounding up the snooze length
M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp +2 -1
@@ 45,7 45,8 @@ namespace app::home_screen
        Empty,
        AlarmIcon,
        AlarmIconAndTime,
        SnoozeCountdown
        SnoozeIcon,
        SnoozeIconAndTime
    };

    class AbstractView

M products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +4 -4
@@ 14,6 14,7 @@
#include <boost/sml.hpp>
#include <time/time_conversion.hpp>

#include <chrono>
#include <random>

/// Uncomment to print state machine debug logs


@@ 274,8 275,7 @@ namespace app::home_screen
            auto entry = [](AbstractView &view, AbstractAlarmModel &alarmModel, AbstractPresenter &presenter) {
                presenter.spawnTimer();
                alarmModel.snooze();
                view.setHeaderViewMode(HeaderViewMode::SnoozeCountdown);
                view.setSnoozeTime(alarmModel.getTimeOfNextSnooze());
                view.setHeaderViewMode(HeaderViewMode::SnoozeIcon);
                const auto bottomDescription =
                    utils::time::getBottomDescription(alarmModel.getSnoozeDuration().count());
                view.setBottomDescription(bottomDescription);


@@ 289,9 289,9 @@ namespace app::home_screen
                            AbstractAlarmModel &alarmModel,
                            AbstractTemperatureModel &temperatureModel,
                            AbstractBatteryModel &batteryModel) {
                view.setHeaderViewMode(HeaderViewMode::SnoozeCountdown);
                view.setHeaderViewMode(HeaderViewMode::SnoozeIconAndTime);
                view.setSnoozeTime(Clock::to_time_t(alarmModel.getTimeOfNextSnooze()));
                view.setTemperature(temperatureModel.getTemperature());
                view.setSnoozeTime(alarmModel.getTimeOfNextSnooze());
                view.setBatteryLevelState(batteryModel.getLevelState());
            };
            auto exit = [](AbstractPresenter &presenter) { presenter.stopSnoozeTimer(); };

M products/BellHybrid/apps/application-bell-main/widgets/SnoozeTimer.cpp => products/BellHybrid/apps/application-bell-main/widgets/SnoozeTimer.cpp +8 -0
@@ 25,6 25,7 @@ namespace gui
        timeSpinner->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        timeSpinner->setMargins(Margins(0, 0, 10U, 0));
        timeSpinner->setEdges(RectangleEdge::None);
        timeSpinner->setFocusItem(nullptr);

        resizeItems();
    }


@@ 50,4 51,11 @@ namespace gui
        timeSpinner->setTimeFormat(fmt);
    }

    auto SnoozeTimer::setTimerVisible(bool visible) noexcept -> void
    {
        timeSpinner->setVisible(visible);
        timeSpinner->setFocusItem(nullptr);
        timeSpinner->informContentChanged();
    }

} /* namespace gui */

M products/BellHybrid/apps/application-bell-main/widgets/SnoozeTimer.hpp => products/BellHybrid/apps/application-bell-main/widgets/SnoozeTimer.hpp +1 -0
@@ 34,6 34,7 @@ namespace gui
        auto setTime(std::uint8_t mins, std::uint8_t secs) noexcept -> void;
        auto setTime(std::time_t time) noexcept -> void;
        auto setTimeFormat(utils::time::Locale::TimeFormat fmt) noexcept -> void;
        auto setTimerVisible(bool visible) noexcept -> void;

      private:
        TimeSetFmtSpinner *timeSpinner = nullptr;

M products/BellHybrid/apps/application-bell-main/windows/BellHomeScreenWindow.cpp => products/BellHybrid/apps/application-bell-main/windows/BellHomeScreenWindow.cpp +10 -1
@@ 104,6 104,7 @@ namespace gui
        snoozeTimer = new SnoozeTimer(body->firstBox);
        snoozeTimer->setMinimumSize(style::bell_base_layout::outer_layouts_w, style::bell_base_layout::outer_layouts_h);
        snoozeTimer->setVisible(false);
        snoozeTimer->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));

        time = new TimeSetFmtSpinner(body->centerBox);
        time->setMaximumSize(style::bell_base_layout::w, style::bell_base_layout::h);


@@ 176,12 177,20 @@ namespace gui
            snoozeTimer->setVisible(false);
            alarm->informContentChanged();
            break;
        case app::home_screen::HeaderViewMode::SnoozeCountdown:
        case app::home_screen::HeaderViewMode::SnoozeIconAndTime:
            alarm->setVisible(false);
            alarm->setAlarmTimeVisible(false);
            snoozeTimer->setVisible(true);
            snoozeTimer->setTimerVisible(true);
            snoozeTimer->informContentChanged();
            break;
        case app::home_screen::HeaderViewMode::SnoozeIcon:
            alarm->setVisible(false);
            alarm->setAlarmTimeVisible(false);
            snoozeTimer->setVisible(true);
            snoozeTimer->informContentChanged();
            snoozeTimer->setTimerVisible(false);
            break;
        }
    }


M products/BellHybrid/apps/common/include/common/models/AbstractAlarmModel.hpp => products/BellHybrid/apps/common/include/common/models/AbstractAlarmModel.hpp +2 -1
@@ 4,6 4,7 @@
#pragma once

#include <service-time/AlarmStatus.hpp>
#include <time/dateCommon.hpp>

#include <chrono>
#include <ctime>


@@ 30,7 31,7 @@ namespace app
        virtual void turnOff()                                 = 0;
        virtual void snooze()                                  = 0;
        virtual std::chrono::seconds getTimeToNextSnooze()     = 0;
        virtual std::time_t getTimeOfNextSnooze()              = 0;
        virtual TimePoint getTimeOfNextSnooze()                = 0;
        virtual alarms::AlarmStatus getAlarmStatus()           = 0;
        /// Command model to update its internal data
        virtual void update(AlarmModelReadyHandler callback = AlarmModelReadyHandler()) = 0;

M products/BellHybrid/apps/common/include/common/models/AlarmModel.hpp => products/BellHybrid/apps/common/include/common/models/AlarmModel.hpp +4 -1
@@ 38,7 38,7 @@ namespace app
        void turnOff() override;
        void snooze() override;
        std::chrono::seconds getTimeToNextSnooze() override;
        std::time_t getTimeOfNextSnooze() override;
        TimePoint getTimeOfNextSnooze() override;
        alarms::AlarmStatus getAlarmStatus() override;

      private:


@@ 55,6 55,9 @@ namespace app
        void disableSnooze(AlarmEventRecord &alarm);
        void updateCache(const SingleEventRecord &record, alarms::AlarmStatus status);

        // Adjust snooze time basing on current time. If less than 15 sec - round down, if higher - round up
        TimePoint calculateNextSnoozeTime(std::uint32_t desiredSnoozeTime);

        ApplicationCommon *app{};
        State state{State::Invalid};
        alarms::AlarmStatus alarmStatus{alarms::AlarmStatus::Invalid};

M products/BellHybrid/apps/common/src/AlarmModel.cpp => products/BellHybrid/apps/common/src/AlarmModel.cpp +19 -9
@@ 116,14 116,27 @@ namespace app
        }
        return alarmEventPtr->enabled;
    }

    TimePoint AlarmModel::calculateNextSnoozeTime(std::uint32_t desiredSnoozeTime)
    {
        const auto now     = TimePointNow();
        const auto seconds = std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count();
        if ((seconds % 60) <= 15) {
            return std::chrono::floor<std::chrono::minutes>(now) + std::chrono::minutes(desiredSnoozeTime);
        }
        else {
            return std::chrono::ceil<std::chrono::minutes>(now) + std::chrono::minutes(desiredSnoozeTime);
        }
    }

    std::chrono::seconds AlarmModel::getSnoozeDuration() const
    {
        const auto snoozeDurationStr =
            settings.getValue(bell::settings::Snooze::length, settings::SettingsScope::Global);
        const auto snoozeDuration = utils::getNumericValue<std::uint32_t>(snoozeDurationStr);

        return std::chrono::minutes{snoozeDuration};
    }

    bool AlarmModel::isSnoozeAllowed()
    {
        const auto snoozeActiveStr = settings.getValue(bell::settings::Snooze::active, settings::SettingsScope::Global);


@@ 139,12 152,13 @@ namespace app

    void AlarmModel::snooze()
    {
        snoozeCount++;
        const auto snoozeDurationStr =
            settings.getValue(bell::settings::Snooze::length, settings::SettingsScope::Global);
        const auto snoozeDuration = utils::getNumericValue<std::uint32_t>(snoozeDurationStr);

        snoozeCount++;
        nextSnoozeTime = std::chrono::ceil<std::chrono::minutes>(TimePointNow()) + std::chrono::minutes(snoozeDuration);
        nextSnoozeTime = calculateNextSnoozeTime(snoozeDuration);

        alarms::AlarmServiceAPI::requestSnoozeRingingAlarm(app, cachedRecord.parent->ID, nextSnoozeTime);
        alarmStatus = alarms::AlarmStatus::Snoozed;
    }


@@ 204,12 218,8 @@ namespace app
    {
        return alarmStatus;
    }
    std::time_t AlarmModel::getTimeOfNextSnooze()
    TimePoint AlarmModel::getTimeOfNextSnooze()
    {
        const auto snoozeDurationStr =
            settings.getValue(bell::settings::Snooze::length, settings::SettingsScope::Global);
        const auto snoozeDuration = utils::getNumericValue<std::uint32_t>(snoozeDurationStr);
        return Clock::to_time_t(std::chrono::floor<std::chrono::minutes>(TimePointNow()) +
                                std::chrono::minutes(snoozeDuration));
        return nextSnoozeTime;
    }
} // namespace app