~aleteoryx/muditaos

8550b2b9eda6ebf16981d726c371ae9a09290347 — Paweł Joński 4 years ago d6ef922
[BH-992] Correct clock widget in powernap

Correct clock widget in powernap application
M products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp => products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp +8 -5
@@ 9,6 9,7 @@
#include "windows/PowerNapMainWindow.hpp"
#include "windows/PowerNapProgressWindow.hpp"
#include "windows/PowerNapSessionEndedWindow.hpp"
#include <common/models/TimeModel.hpp>
#include <service-audio/AudioMessage.hpp>

namespace app


@@ 39,11 40,13 @@ namespace app
            auto presenter = std::make_unique<powernap::PowerNapMainWindowPresenter>(app, settings.get());
            return std::make_unique<gui::PowerNapMainWindow>(app, std::move(presenter));
        });
        windowsFactory.attach(
            gui::window::name::powernapProgress, [this](ApplicationCommon *app, const std::string &name) {
                auto presenter = std::make_unique<powernap::PowerNapProgressPresenter>(app, settings.get(), *alarm);
                return std::make_unique<gui::PowerNapProgressWindow>(app, std::move(presenter));
            });
        windowsFactory.attach(gui::window::name::powernapProgress,
                              [this](ApplicationCommon *app, const std::string &name) {
                                  auto timeModel = std::make_unique<app::TimeModel>();
                                  auto presenter = std::make_unique<powernap::PowerNapProgressPresenter>(
                                      app, settings.get(), *alarm, std::move(timeModel));
                                  return std::make_unique<gui::PowerNapProgressWindow>(app, std::move(presenter));
                              });
        windowsFactory.attach(gui::window::name::powernapSessionEnded,
                              [](ApplicationCommon *app, const std::string &name) {
                                  auto presenter = std::make_unique<powernap::PowerNapSessionEndPresenter>(app);

M products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp => products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp +3 -1
@@ 8,7 8,9 @@
namespace gui::powerNapStyle
{
    inline constexpr auto descriptionFont = style::window::font::largelight;
    inline constexpr auto napPeriodFont   = style::window::font::supersizemelight;
    inline constexpr auto napTimerFont    = style::window::font::verybig;
    inline constexpr auto napPeriodFont   = style::window::font::supersizeme;
    inline constexpr auto clockFont       = style::window::font::verybiglight;
    namespace listItem
    {
        inline constexpr auto timeUnitSingular = "common_minute_lower";

M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp +9 -2
@@ 7,6 7,7 @@
#include "widgets/PowerNapAlarm.hpp"

#include <apps-common/widgets/ProgressTimer.hpp>
#include <common/models/TimeModel.hpp>
#include <service-db/Settings.hpp>
#include <Timers/TimerFactory.hpp>
#include <Utils.hpp>


@@ 22,8 23,9 @@ namespace app::powernap
{
    PowerNapProgressPresenter::PowerNapProgressPresenter(app::ApplicationCommon *app,
                                                         settings::Settings *settings,
                                                         PowerNapAlarm &alarm)
        : app{app}, settings{settings}, alarm{alarm},
                                                         PowerNapAlarm &alarm,
                                                         std::unique_ptr<AbstractTimeModel> timeModel)
        : app{app}, settings{settings}, alarm{alarm}, timeModel{std::move(timeModel)},
          napAlarmTimer{sys::TimerFactory::createSingleShotTimer(
              app, powernapAlarmTimerName, powernapAlarmTimeout, [this](sys::Timer &) { onNapAlarmFinished(); })}



@@ 59,4 61,9 @@ namespace app::powernap
        getView()->napEnded();
    }

    void PowerNapProgressPresenter::handleUpdateTimeEvent()
    {
        getView()->setTime(timeModel->getCurrentTime());
    }

} // namespace app::powernap

M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp +14 -4
@@ 5,10 5,12 @@

#include <apps-common/BasePresenter.hpp>
#include <apps-common/widgets/TimerWithCallbacks.hpp>
#include <time/time_locale.hpp>
#include <Timers/TimerHandle.hpp>
#include <memory>
namespace app
{
    class AbstractTimeModel;
    class ApplicationCommon;
} // namespace app
namespace gui


@@ 30,15 32,18 @@ namespace app::powernap
        {
          public:
            ~View() = default;
            virtual void napEnded() = 0;
            virtual void napEnded()                                         = 0;
            virtual void setTime(std::time_t newTime)                       = 0;
            virtual void setTimeFormat(utils::time::Locale::TimeFormat fmt) = 0;
        };

        class Presenter : public BasePresenter<PowerNapProgressContract::View>
        {
          public:
            virtual void activate()                                                = 0;
            virtual void endNap()                                                  = 0;
            virtual void activate()                                                 = 0;
            virtual void endNap()                                                   = 0;
            virtual void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&timer) = 0;
            virtual void handleUpdateTimeEvent()                                    = 0;
        };
    };



@@ 48,16 53,21 @@ namespace app::powernap
        settings::Settings *settings = nullptr;
        PowerNapAlarm &alarm;
        std::unique_ptr<app::TimerWithCallbacks> timer;
        std::unique_ptr<AbstractTimeModel> timeModel;
        sys::TimerHandle napAlarmTimer;

        void activate() override;
        void endNap() override;
        void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer) override;
        void handleUpdateTimeEvent() override;

        void onNapFinished();
        void onNapAlarmFinished();

      public:
        PowerNapProgressPresenter(app::ApplicationCommon *app, settings::Settings *settings, PowerNapAlarm &alarm);
        PowerNapProgressPresenter(app::ApplicationCommon *app,
                                  settings::Settings *settings,
                                  PowerNapAlarm &alarm,
                                  std::unique_ptr<AbstractTimeModel> timeModel);
    };
} // namespace app::powernap

M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp +27 -1
@@ 11,6 11,7 @@
#include <apps-common/GuiTimer.hpp>
#include <Text.hpp>

#include <time/dateCommon.hpp>
namespace
{
    void decorateProgressItem(gui::Rect *item, gui::Alignment::Vertical alignment)


@@ 41,7 42,7 @@ namespace
        using namespace gui::powerNapStyle;
        auto timer = new gui::Text(
            parent, 0, 0, bell_base_layout::w, bell_base_layout::outer_layouts_h - progress::bottomDescTopMargin);
        timer->setFont(descriptionFont);
        timer->setFont(napTimerFont);
        timer->setMargins(gui::Margins(0, progress::bottomDescTopMargin, 0, 0));
        decorateProgressItem(timer, gui::Alignment::Vertical::Top);
        return timer;


@@ 74,6 75,7 @@ namespace gui
    }
    void PowerNapProgressWindow::buildLayout()
    {
        statusBar->setVisible(false);
        auto body = new gui::BellBaseLayout(this, 0, 0, style::bell_base_layout::w, style::bell_base_layout::h, false);
        auto vBox =
            new VBox(body->getCenterBox(), 0, 0, style::bell_base_layout::w, style::bell_base_layout::center_layout_h);


@@ 82,6 84,11 @@ namespace gui
        progressBar = createProgress(vBox);
        timerText   = createTimer(body->lastBox);

        time = new BellStatusClock(body->firstBox);
        time->setMaximumSize(body->firstBox->getWidth(), body->firstBox->getHeight());
        time->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
        body->firstBox->resizeItems();

        dimensionChangedCallback = [&](Item &, const BoundingBox &newDim) -> bool {
            body->setArea({0, 0, newDim.w, newDim.h});
            return true;


@@ 110,4 117,23 @@ namespace gui
    {
        application->switchWindow(gui::window::name::powernapSessionEnded, std::make_unique<gui::PowerNapSwitchData>());
    }

    void PowerNapProgressWindow::setTime(std::time_t newTime)
    {
        time->setTime(newTime);
        time->setTimeFormatSpinnerVisibility(true);
    }

    void PowerNapProgressWindow::setTimeFormat(utils::time::Locale::TimeFormat fmt)
    {
        time->setTimeFormat(fmt);
    }

    bool PowerNapProgressWindow::updateTime()
    {
        if (presenter) {
            presenter->handleUpdateTimeEvent();
        }
        return true;
    }
} // namespace gui

M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.hpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.hpp +6 -0
@@ 4,6 4,7 @@
#pragma once

#include "presenter/PowerNapProgressPresenter.hpp"
#include <common/widgets/BellStatusClock.hpp>
#include <AppWindow.hpp>

namespace gui


@@ 15,11 16,16 @@ namespace gui
        std::shared_ptr<app::powernap::PowerNapProgressContract::Presenter> presenter;
        gui::HBarGraph *progressBar = nullptr;
        gui::Text *timerText        = nullptr;
        gui::BellStatusClock *time  = nullptr;

        void buildInterface() override;
        void onBeforeShow(ShowMode mode, SwitchData *data) override;
        auto onInput(const InputEvent &inputEvent) -> bool override;

        void setTime(std::time_t newTime);
        void setTimeFormat(utils::time::Locale::TimeFormat fmt);
        bool updateTime() override;

        void buildLayout();
        void configureTimer();


M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp +1 -0
@@ 28,6 28,7 @@ namespace gui

    void PowerNapSessionEndedWindow::buildLayout()
    {
        statusBar->setVisible(false);
        auto body = new VBox(this, 0, 0, style::window_width, style::window_height);
        body->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));


M products/BellHybrid/apps/common/CMakeLists.txt => products/BellHybrid/apps/common/CMakeLists.txt +2 -0
@@ 24,6 24,7 @@ target_sources(application-bell-common
        src/popups/BellTurnOffOptionWindow.cpp
        src/popups/BellRebootWindow.cpp
        src/widgets/ListItems.cpp
        src/widgets/BellStatusClock.cpp

        src/options/BellOptionWindow.cpp
        src/options/BellShortOptionWindow.cpp


@@ 44,6 45,7 @@ target_sources(application-bell-common
        include/common/popups/BellTurnOffOptionWindow.hpp
        include/common/popups/BellRebootWindow.hpp
        include/common/widgets/BellSideListItemWithCallbacks.hpp
        include/common/widgets/BellStatusClock.hpp
        include/common/widgets/ListItems.hpp
        include/common/options/BellOptionWindow.hpp
        include/common/options/BellShortOptionWindow.hpp

M products/BellHybrid/apps/common/include/common/data/StyleCommon.hpp => products/BellHybrid/apps/common/include/common/data/StyleCommon.hpp +4 -3
@@ 8,7 8,8 @@

namespace gui::bell_style
{
    inline constexpr auto font        = ::style::window::font::supersizemelight;
    inline constexpr auto font_center = ::style::window::font::largelight;
    inline constexpr auto font_top    = ::style::window::font::largelight;
    inline constexpr auto font            = ::style::window::font::supersizemelight;
    inline constexpr auto font_center     = ::style::window::font::largelight;
    inline constexpr auto font_top        = ::style::window::font::largelight;
    inline constexpr auto statusClockFont = style::window::font::verybiglight;
} // namespace gui::bell_style

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

#pragma once

#include <apps-common/widgets/TimeSetFmtSpinner.hpp>

namespace gui
{
    class BellStatusClock : public TimeSetFmtSpinner
    {
      public:
        explicit BellStatusClock(
            Item *parent                               = nullptr,
            uint32_t x                                 = 0U,
            uint32_t y                                 = 0U,
            uint32_t w                                 = 0U,
            uint32_t h                                 = 0U,
            utils::time::Locale::TimeFormat timeFormat = utils::time::Locale::TimeFormat::FormatTime12H);
    };

} // namespace gui

A products/BellHybrid/apps/common/src/widgets/BellStatusClock.cpp => products/BellHybrid/apps/common/src/widgets/BellStatusClock.cpp +21 -0
@@ 0,0 1,21 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include <common/widgets/BellStatusClock.hpp>

#include <common/data/StyleCommon.hpp>

namespace gui
{

    BellStatusClock::BellStatusClock(
        Item *parent, uint32_t x, uint32_t y, uint32_t w, uint32_t h, utils::time::Locale::TimeFormat timeFormat)
        : TimeSetFmtSpinner{parent, x, y, w, h, timeFormat}
    {
        setFont(bell_style::statusClockFont);
        setEditMode(EditMode::Browse);
        activeItem = false;
        setTimeFormatSpinnerVisibility(true);
    }

} // namespace gui