~aleteoryx/muditaos

29827a91f34b0063ca878b9d0bfc68d11c66e133 — mkamonMdt 4 years ago b1f6d67
[BH-850] PowerNap: SessionEnd implementation

The implementation of the SessionEnd covers:
* SessionEnd window
* SessionEnd Presenter

Additionaly in order to match application's flow requirement
the PowerNapProgress was equipped with:
* OnInput behaviour that allows to transition to the
SessionEnd window
* AlarmTimer timer that automatically transitions to
the SessionEnd window
M image/assets/lang/English.json => image/assets/lang/English.json +2 -1
@@ 583,5 583,6 @@
  "app_bell_alarm_ringing_deactivated": "Good morning!\nRise and shine",
  "app_bell_settings_advanced_frontlight": "Frontlight",
  "app_bell_settings_frontlight_top_message": "Frontlight intensity",
  "app_bell_settings_frontlight_finished_message": "Frontlight is set"
  "app_bell_settings_frontlight_finished_message": "Frontlight is set",
  "app_bell_powernap_session_ended_message": "<text>Hello!<br />Rise & shine</text>"
}

M module-gui/gui/widgets/ProgressBar.cpp => module-gui/gui/widgets/ProgressBar.cpp +1 -1
@@ 139,7 139,7 @@ namespace gui
    {
        using namespace trigonometry;

        progressArc->setSweepAngle(getPercentageValue() * FullAngle);
        progressArc->setSweepAngle(std::ceil(getPercentageValue() * FullAngle));
        progressIndicator->setCenter(calculateProgressIndicatorCenter());

        Circle::buildDrawListImplementation(commands);

M products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp => products/BellHybrid/apps/application-bell-powernap/ApplicationBellPowerNap.cpp +6 -0
@@ 4,8 4,10 @@
#include "ApplicationBellPowerNap.hpp"
#include "presenter/PowerNapMainWindowPresenter.hpp"
#include "presenter/PowerNapProgressPresenter.hpp"
#include "presenter/PowerNapSessionEndedPresenter.hpp"
#include "windows/PowerNapMainWindow.hpp"
#include "windows/PowerNapProgressWindow.hpp"
#include "windows/PowerNapSessionEndedWindow.hpp"

namespace app
{


@@ 38,6 40,10 @@ namespace app
            auto presenter = std::make_unique<powernap::PowerNapProgressPresenter>(app, settings.get());
            return std::make_unique<gui::PowerNapProgressWindow>(app, std::move(presenter));
        });
        windowsFactory.attach(gui::window::name::powernapSessionEnded, [](Application *app, const std::string &name) {
            auto presenter = std::make_unique<powernap::PowerNapSessionEndPresenter>(app);
            return std::make_unique<gui::PowerNapSessionEndedWindow>(app, std::move(presenter));
        });
    }

    sys::MessagePointer ApplicationBellPowerNap::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp)

M products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt => products/BellHybrid/apps/application-bell-powernap/CMakeLists.txt +5 -0
@@ 18,15 18,19 @@ target_sources(application-bell-powernap
        ApplicationBellPowerNap.cpp
        presenter/PowerNapMainWindowPresenter.cpp
        presenter/PowerNapProgressPresenter.cpp
        presenter/PowerNapSessionEndedPresenter.cpp
        windows/PowerNapMainWindow.cpp
        windows/PowerNapProgressWindow.cpp
        windows/PowerNapSessionEndedWindow.cpp
        data/PowerNapListItem.cpp
        models/PowerNapModel.cpp

        presenter/PowerNapMainWindowPresenter.hpp
        presenter/PowerNapProgressPresenter.hpp
        presenter/PowerNapSessionEndedPresenter.hpp
        windows/PowerNapMainWindow.hpp
        windows/PowerNapProgressWindow.hpp
        windows/PowerNapSessionEndedWindow.hpp
        data/PowerNapListItem.hpp
        data/PowerNapStyle.hpp
        data/PowerNapCommon.hpp


@@ 38,6 42,7 @@ target_sources(application-bell-powernap

target_link_libraries(application-bell-powernap
    PRIVATE
        bell::app-main

    PUBLIC
        apps-common

M products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp => products/BellHybrid/apps/application-bell-powernap/data/PowerNapStyle.hpp +5 -0
@@ 20,4 20,9 @@ namespace gui::powerNapStyle
        inline constexpr auto bottomDescTopMargin = 20U;
        inline constexpr auto boxesCount          = 16;
    } // namespace progress

    namespace sessionEnd
    {
        inline constexpr auto textH = 200U;
    }
} // namespace gui::powerNapStyle

A products/BellHybrid/apps/application-bell-powernap/data/PowerNapSwitchData.hpp => products/BellHybrid/apps/application-bell-powernap/data/PowerNapSwitchData.hpp +17 -0
@@ 0,0 1,17 @@
// 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 <SwitchData.hpp>
namespace gui
{
    class PowerNapSwitchData : public SwitchData
    {
      public:
        PowerNapSwitchData()
        {
            ignoreCurrentWindowOnStack = true;
        }
    };

} // namespace gui

M products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp => products/BellHybrid/apps/application-bell-powernap/include/application-bell-powernap/ApplicationBellPowerNap.hpp +1 -0
@@ 8,6 8,7 @@
namespace gui::window::name
{
    inline constexpr auto powernapProgress = "PowerNapProgressWindow";
    inline constexpr auto powernapSessionEnded = "PowerNapSessionEndedWindow";
}
namespace app
{

M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.cpp +18 -2
@@ 2,11 2,12 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PowerNapProgressPresenter.hpp"
#include "application-bell-powernap/ApplicationBellPowerNap.hpp"
#include "data/PowerNapCommon.hpp"

#include <apps-common/widgets/ProgressTimerImpl.hpp>
#include <apps-common/Application.hpp>
#include <service-db/Settings.hpp>
#include <Timers/TimerFactory.hpp>
#include <Utils.hpp>

#include <gsl/assert>


@@ 14,16 15,22 @@
namespace
{
    inline constexpr auto powernapTimerName = "PowerNapTimer";
    inline constexpr auto powernapAlarmTimerName = "PowerNapAlarmTimer";
    inline constexpr std::chrono::seconds timerTick{1};
    inline constexpr std::chrono::minutes powernapAlarmTimeout{3};
} // namespace
namespace app::powernap
{
    PowerNapProgressPresenter::PowerNapProgressPresenter(app::Application *app, settings::Settings *settings)
        : app{app}, settings{settings}
        : app{app}, settings{settings}, napAlarmTimer{sys::TimerFactory::createSingleShotTimer(
                                            app, powernapAlarmTimerName, powernapAlarmTimeout, [this](sys::Timer &) {
                                                onNapAlarmFinished();
                                            })}
    {}
    void PowerNapProgressPresenter::initTimer(gui::Item *parent)
    {
        timer = std::make_unique<app::ProgressTimerImpl>(app, parent, powernapTimerName, timerTick);
        timer->registerOnFinishedCallback([this]() { onNapFinished(); });
    }
    void PowerNapProgressPresenter::activate()
    {


@@ 37,4 44,13 @@ namespace app::powernap
        Expects(timer != nullptr);
        return *timer;
    }
    void PowerNapProgressPresenter::onNapFinished()
    {
        napAlarmTimer.start();
    }

    void PowerNapProgressPresenter::onNapAlarmFinished()
    {
        getView()->switchWindow();
    }
} // namespace app::powernap

M products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapProgressPresenter.hpp +7 -1
@@ 5,6 5,7 @@

#include <apps-common/BasePresenter.hpp>
#include <apps-common/widgets/ProgressTimer.hpp>
#include <Timers/TimerHandle.hpp>
#include <memory>
namespace app
{


@@ 28,6 29,7 @@ namespace app::powernap
        {
          public:
            ~View() = default;
            virtual void switchWindow() = 0;
        };

        class Presenter : public BasePresenter<PowerNapProgressContract::View>


@@ 44,10 46,14 @@ namespace app::powernap
        app::Application *app        = nullptr;
        settings::Settings *settings = nullptr;
        std::unique_ptr<app::ProgressTimer> timer;
        sys::TimerHandle napAlarmTimer;

        void initTimer(gui::Item *parent) override;
        void activate() override;
        app::ProgressTimerUIConfigurator &getUIConfigurator() noexcept override;
        void activate() override;

        void onNapFinished();
        void onNapAlarmFinished();

      public:
        PowerNapProgressPresenter(app::Application *app, settings::Settings *settings);

A products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapSessionEndedPresenter.cpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapSessionEndedPresenter.cpp +20 -0
@@ 0,0 1,20 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PowerNapSessionEndedPresenter.hpp"
#include <Timers/TimerFactory.hpp>
#include <Application.hpp>
#include <service-appmgr/Controller.hpp>
#include "application-bell-main/ApplicationBellMain.hpp"

namespace app::powernap
{
    PowerNapSessionEndPresenter ::PowerNapSessionEndPresenter(app::Application *app) : app{app}
    {}

    void PowerNapSessionEndPresenter::activate()
    {
        app::manager::Controller::sendAction(
            app, app::manager::actions::Launch, std::make_unique<app::ApplicationLaunchData>(app::applicationBellName));
    }
} // namespace app::powernap

A products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapSessionEndedPresenter.hpp => products/BellHybrid/apps/application-bell-powernap/presenter/PowerNapSessionEndedPresenter.hpp +38 -0
@@ 0,0 1,38 @@
// 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/BasePresenter.hpp>

namespace app
{
    class Application;
}

namespace app::powernap
{
    class PowerNapSessionEndedContract
    {
      public:
        class View
        {
          public:
            virtual ~View() = default;
        };
        class Presenter : public BasePresenter<PowerNapSessionEndedContract::View>
        {
          public:
            virtual void activate() = 0;
        };
    };

    class PowerNapSessionEndPresenter : public PowerNapSessionEndedContract::Presenter
    {
        app::Application *app{};
        void activate() override;

      public:
        explicit PowerNapSessionEndPresenter(app::Application *app);
    };
} // namespace app::powernap

M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.cpp +16 -0
@@ 4,6 4,7 @@
#include "PowerNapProgressWindow.hpp"
#include "application-bell-powernap/ApplicationBellPowerNap.hpp"
#include "data/PowerNapStyle.hpp"
#include "data/PowerNapSwitchData.hpp"
#include <apps-common/widgets/BellBaseLayout.hpp>
#include <apps-common/widgets/BarGraph.hpp>
#include <apps-common/GuiTimer.hpp>


@@ 87,4 88,19 @@ namespace gui
        presenter->getUIConfigurator().attach(progressBar);
        presenter->getUIConfigurator().attach(timerText);
    }

    auto PowerNapProgressWindow::onInput(const InputEvent &inputEvent) -> bool
    {
        if (inputEvent.isShortRelease()) {
            if (inputEvent.is(KeyCode::KEY_RF) || inputEvent.is(KeyCode::KEY_ENTER)) {
                switchWindow();
                return true;
            }
        }
        return AppWindow::onInput(inputEvent);
    }
    void PowerNapProgressWindow::switchWindow()
    {
        application->switchWindow(gui::window::name::powernapSessionEnded, std::make_unique<gui::PowerNapSwitchData>());
    }
} // namespace gui

M products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.hpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapProgressWindow.hpp +3 -0
@@ 18,10 18,13 @@ namespace gui

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

        void buildLayout();
        void configureTimer();

        void switchWindow() override;

      public:
        PowerNapProgressWindow(app::Application *app,
                               std::shared_ptr<app::powernap::PowerNapProgressContract::Presenter> presenter);

A products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.cpp +52 -0
@@ 0,0 1,52 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PowerNapSessionEndedWindow.hpp"
#include "data/PowerNapStyle.hpp"
#include <application-bell-powernap/ApplicationBellPowerNap.hpp>
#include <RichTextParser.hpp>
#include <BoxLayout.hpp>
#include <Image.hpp>
#include <Text.hpp>
#include <gui/core/FontManager.hpp>

namespace gui
{
    PowerNapSessionEndedWindow::PowerNapSessionEndedWindow(
        app::Application *app, std::shared_ptr<app::powernap::PowerNapSessionEndedContract::Presenter> presenter)
        : WindowWithTimer(app, gui::window::name::powernapSessionEnded), presenter{std::move(presenter)}
    {
        buildInterface();
    }

    void PowerNapSessionEndedWindow::buildInterface()
    {
        AppWindow::buildInterface();
        buildLayout();
        registerCallbacks();
    }

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

        new gui::Image(body, "tethering_notification_icon"); // TODO: ICON!!!!

        auto text = new gui::Text(body, 0, 0, body->getWidth(), powerNapStyle::sessionEnd::textH);
        TextFormat format(FontManager::getInstance().getFont(powerNapStyle::descriptionFont));
        gui::text::RichTextParser parser;
        auto textParsed = parser.parse(utils::translate("app_bell_powernap_session_ended_message"), &format);
        text->setText(std::move(textParsed));
        text->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center));
        text->setVisible(true);
    }

    void PowerNapSessionEndedWindow::registerCallbacks()
    {
        timerCallback = [this](Item &, sys::Timer &timer) {
            presenter->activate();
            return true;
        };
    }
} // namespace gui

A products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.hpp => products/BellHybrid/apps/application-bell-powernap/windows/PowerNapSessionEndedWindow.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 "presenter/PowerNapSessionEndedPresenter.hpp"
#include <apps-common/popups/WindowWithTimer.hpp>

namespace gui
{
    class PowerNapSessionEndedWindow : public WindowWithTimer, public app::powernap::PowerNapSessionEndedContract::View
    {
        std::shared_ptr<app::powernap::PowerNapSessionEndedContract::Presenter> presenter;
        void buildInterface() override;
        void buildLayout();
        void registerCallbacks();

      public:
        explicit PowerNapSessionEndedWindow(
            app::Application *app, std::shared_ptr<app::powernap::PowerNapSessionEndedContract::Presenter> presenter);
    };
} // namespace gui