~aleteoryx/muditaos

74fc2bffc514d8cae18616b075f8d1919b55916f — Paweł Joński 4 years ago 490845c
[BH-593] Use correct time format in alarm setting

Use correct time format in alarm setting
Move TimeModel to common
M products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp => products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp +22 -5
@@ 6,16 6,31 @@
#include "windows/BellAlarmWindow.hpp"

#include <common/models/AlarmModel.hpp>
#include <common/models/TimeModel.hpp>

namespace app
{

    namespace internal
    {
        class BellAlarmPriv
        {
          public:
            std::shared_ptr<AlarmModel> alarmModel;
            std::shared_ptr<TimeModel> timeModel;
            std::shared_ptr<bell_alarm::BellAlarmWindowPresenter> alarmPresenter;
        };
    } // namespace internal

    ApplicationBellAlarm::ApplicationBellAlarm(std::string name,
                                               std::string parent,
                                               sys::phone_modes::PhoneMode mode,
                                               sys::bluetooth::BluetoothMode bluetoothMode,
                                               StartInBackground startInBackground)
        : Application(std::move(name), std::move(parent), mode, bluetoothMode, startInBackground)
        : Application(std::move(name), std::move(parent), mode, bluetoothMode, startInBackground),
          priv{std::make_unique<app::internal::BellAlarmPriv>()}
    {}
    ApplicationBellAlarm::~ApplicationBellAlarm() = default;

    sys::ReturnCodes ApplicationBellAlarm::InitHandler()
    {


@@ 31,10 46,12 @@ namespace app

    void ApplicationBellAlarm::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) {
            auto alarmModel = std::make_unique<app::AlarmModel>(app);
            auto presenter  = std::make_unique<bell_alarm::BellAlarmWindowPresenter>(std::move(alarmModel));
            return std::make_unique<gui::BellAlarmWindow>(app, std::move(presenter));
        windowsFactory.attach(gui::name::window::main_window, [&](ApplicationCommon *app, const std::string &name) {
            priv->alarmModel = std::make_shared<app::AlarmModel>(app);
            priv->timeModel  = std::make_shared<app::TimeModel>();
            priv->alarmPresenter =
                std::make_shared<bell_alarm::BellAlarmWindowPresenter>(priv->alarmModel, priv->timeModel);
            return std::make_unique<gui::BellAlarmWindow>(app, priv->alarmPresenter);
        });

        attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated});

M products/BellHybrid/apps/application-bell-alarm/include/application-bell-alarm/ApplicationBellAlarm.hpp => products/BellHybrid/apps/application-bell-alarm/include/application-bell-alarm/ApplicationBellAlarm.hpp +9 -0
@@ 12,10 12,18 @@ namespace gui::window::name

namespace app
{
    namespace internal
    {
        class BellAlarmPriv;
    } // namespace internal

    inline constexpr auto applicationBellAlarmName = "ApplicationBellAlarm";

    class ApplicationBellAlarm : public Application
    {
      private:
        std::unique_ptr<internal::BellAlarmPriv> priv;

      public:
        explicit ApplicationBellAlarm(
            std::string name                            = applicationBellAlarmName,


@@ 24,6 32,7 @@ namespace app
            sys::bluetooth::BluetoothMode bluetoothMode = sys::bluetooth::BluetoothMode::Disabled,
            StartInBackground startInBackground         = {false});

        ~ApplicationBellAlarm() override;
        sys::ReturnCodes InitHandler() override;

        void createUserInterface() override;

M products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp => products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp +19 -6
@@ 5,25 5,38 @@

namespace app::bell_alarm
{
    BellAlarmWindowPresenter::BellAlarmWindowPresenter(std::unique_ptr<AbstractAlarmModel> &&alarmModel)
        : alarmModel{std::move(alarmModel)}
    BellAlarmWindowPresenter::BellAlarmWindowPresenter(std::shared_ptr<AbstractAlarmModel> alarmModel,
                                                       std::shared_ptr<AbstractTimeModel> timeModel)
        : alarmModel{std::move(alarmModel)}, timeModel{std::move(timeModel)}
    {}

    auto BellAlarmWindowPresenter::onBeforeShow() -> void
    {
        getView()->setTimeFormat(timeModel->getTimeFormat());
    }

    auto BellAlarmWindowPresenter::saveData() -> void
    {
        auto view = getView();
        auto time = view->getAlarmTime();
        auto view       = getView();
        const auto time = view->getAlarmTime();
        alarmModel->setAlarmTime(time);
    }

    auto BellAlarmWindowPresenter::createData() -> void
    {
        auto updateAlarmTimeCallback = [&]() {
            auto time = alarmModel->getAlarmTime();
            auto view = getView();
            const auto time = alarmModel->getAlarmTime();
            auto view       = getView();
            view->setAlarmTime(time);
        };

        alarmModel->update(updateAlarmTimeCallback);
    }

    auto BellAlarmWindowPresenter::setTimeFormat(utils::time::Locale::TimeFormat fmt) -> void
    {
        auto view = getView();
        view->setTimeFormat(fmt);
    }

} // namespace app::bell_alarm

M products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp => products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp +13 -5
@@ 6,6 6,7 @@

#include <apps-common/BasePresenter.hpp>
#include <common/models/AbstractAlarmModel.hpp>
#include <common/models/TimeModel.hpp>
#include <time/dateCommon.hpp>

namespace app::bell_alarm


@@ 17,27 18,34 @@ namespace app::bell_alarm
        {
          public:
            virtual ~View() noexcept = default;
            virtual void setAlarmTime(time_t time) = 0;
            virtual time_t getAlarmTime()          = 0;
            virtual void setAlarmTime(time_t time)                          = 0;
            virtual time_t getAlarmTime() const                             = 0;
            virtual void setTimeFormat(utils::time::Locale::TimeFormat fmt) = 0;
        };

        class Presenter : public BasePresenter<BellAlarmWindowContract::View>
        {
          public:
            virtual ~Presenter() noexcept   = default;
            virtual auto createData() -> void = 0;
            virtual auto createData() -> void                                       = 0;
            virtual auto saveData() -> void = 0;
            virtual auto setTimeFormat(utils::time::Locale::TimeFormat fmt) -> void = 0;
            virtual auto onBeforeShow() -> void                                     = 0;
        };
    };

    class BellAlarmWindowPresenter : public BellAlarmWindowContract::Presenter
    {
      public:
        BellAlarmWindowPresenter(std::unique_ptr<AbstractAlarmModel> &&alarmModel);
        BellAlarmWindowPresenter(std::shared_ptr<AbstractAlarmModel> alarmModel,
                                 std::shared_ptr<AbstractTimeModel> timeModel);
        auto createData() -> void override;
        auto saveData() -> void override;
        auto setTimeFormat(utils::time::Locale::TimeFormat fmt) -> void override;
        auto onBeforeShow() -> void override;

      private:
        std::unique_ptr<AbstractAlarmModel> alarmModel;
        std::shared_ptr<AbstractAlarmModel> alarmModel;
        std::shared_ptr<AbstractTimeModel> timeModel;
    };
} // namespace app::bell_alarm

M products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.cpp => products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.cpp +13 -2
@@ 17,7 17,7 @@ namespace gui
{
    BellAlarmWindow::BellAlarmWindow(
        app::ApplicationCommon *app,
        std::unique_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> &&windowPresenter,
        std::shared_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> windowPresenter,
        std::string name)
        : AppWindow(app, std::move(name)), presenter{std::move(windowPresenter)}
    {


@@ 71,16 71,27 @@ namespace gui
        return AppWindow::onInput(inputEvent);
    }

    void BellAlarmWindow::onBeforeShow(ShowMode, SwitchData *data)
    {
        presenter->onBeforeShow();
    }

    void BellAlarmWindow::setAlarmTime(time_t time)
    {
        timeSetFmtSpinner->setTime(time);
    }

    time_t BellAlarmWindow::getAlarmTime()
    time_t BellAlarmWindow::getAlarmTime() const
    {
        return timeSetFmtSpinner->getTime();
    }

    void BellAlarmWindow::setTimeFormat(utils::time::Locale::TimeFormat fmt)
    {
        timeSetFmtSpinner->setTimeFormat(fmt);
        body->resizeItems();
    }

    void BellAlarmWindow::rebuild()
    {
        erase();

M products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.hpp => products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.hpp +5 -3
@@ 17,20 17,22 @@ namespace gui
    {
      public:
        explicit BellAlarmWindow(app::ApplicationCommon *app,
                                 std::unique_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> &&windowPresenter,
                                 std::shared_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> windowPresenter,
                                 std::string name = window::name::bellAlarm);

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

        void setAlarmTime(time_t time) override;
        time_t getAlarmTime() override;
        time_t getAlarmTime() const override;
        void setTimeFormat(utils::time::Locale::TimeFormat fmt);

      private:
        BellBaseLayout *body{nullptr};
        Label *topText{nullptr};
        TimeSetFmtSpinner *timeSetFmtSpinner{nullptr};
        std::unique_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> presenter;
        std::shared_ptr<app::bell_alarm::BellAlarmWindowContract::Presenter> presenter;
    };
} /* namespace gui */

M products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp => products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +2 -2
@@ 3,13 3,13 @@

#include "include/application-bell-main/ApplicationBellMain.hpp"
#include "models/TemperatureModel.hpp"
#include "models/TimeModel.hpp"
#include "presenters/HomeScreenPresenter.hpp"

#include "windows/BellHomeScreenWindow.hpp"
#include "windows/BellMainMenuWindow.hpp"

#include <common/models/AlarmModel.hpp>
#include <common/models/TimeModel.hpp>
#include <service-db/DBNotificationMessage.hpp>
#include <windows/Dialog.hpp>



@@ 44,7 44,7 @@ namespace app
    void ApplicationBellMain::createUserInterface()
    {
        windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) {
            auto timeModel        = std::make_unique<app::home_screen::TimeModel>();
            auto timeModel        = std::make_unique<app::TimeModel>();
            auto temperatureModel = std::make_unique<app::home_screen::TemperatureModel>(app);
            auto alarmModel       = std::make_unique<app::AlarmModel>(app);
            auto presenter        = std::make_unique<app::home_screen::HomeScreenPresenter>(

M products/BellHybrid/apps/application-bell-main/CMakeLists.txt => products/BellHybrid/apps/application-bell-main/CMakeLists.txt +0 -2
@@ 8,7 8,6 @@ target_sources(application-bell-main
        windows/BellMainMenuWindow.cpp

        models/TemperatureModel.cpp
        models/TimeModel.cpp

        presenters/HomeScreenPresenter.cpp
        presenters/StateController.cpp


@@ 17,7 16,6 @@ target_sources(application-bell-main
        windows/BellMainMenuWindow.hpp

        models/TemperatureModel.hpp
        models/TimeModel.hpp

        presenters/HomeScreenPresenter.hpp
        presenters/StateController.hpp

M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp +1 -1
@@ 4,9 4,9 @@
#include "HomeScreenPresenter.hpp"
#include "StateController.hpp"
#include "models/TemperatureModel.hpp"
#include "models/TimeModel.hpp"

#include <apps-common/ApplicationCommon.hpp>
#include <common/models/TimeModel.hpp>
#include <module-sys/Timers/SystemTimer.hpp>
#include <module-sys/Timers/TimerFactory.hpp>
#include <time/time_constants.hpp>

M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.hpp +1 -1
@@ 18,6 18,7 @@

namespace app
{
    class AbstractTimeModel;
    class ApplicationCommon;
}



@@ 33,7 34,6 @@ namespace db

namespace app::home_screen
{
    class AbstractTimeModel;
    class AbstractController;
    class AbstractTemperatureModel;


M products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.cpp +1 -1
@@ 3,9 3,9 @@

#include "StateController.hpp"
#include "HomeScreenPresenter.hpp"
#include "models/TimeModel.hpp"

#include <common/TimeUtils.hpp>
#include <common/models/TimeModel.hpp>

#include <keymap/KeyMap.hpp>


M products/BellHybrid/apps/application-bell-main/presenters/StateController.hpp => products/BellHybrid/apps/application-bell-main/presenters/StateController.hpp +5 -1
@@ 9,6 9,11 @@
#include <chrono>
#include <memory>

namespace app
{
    class AbstractTimeModel;
}

namespace app::home_screen
{



@@ 17,7 22,6 @@ namespace app::home_screen
    class AbstractView;
    class AbstractPresenter;
    class AbstractTemperatureModel;
    class AbstractTimeModel;
    class AbstractController
    {
      public:

M products/BellHybrid/apps/common/CMakeLists.txt => products/BellHybrid/apps/common/CMakeLists.txt +2 -0
@@ 11,6 11,7 @@ target_include_directories(application-bell-common
target_sources(application-bell-common
    PRIVATE
        src/AlarmModel.cpp
        src/TimeModel.cpp
        src/BellFinishedWindow.cpp
        src/BellSideListItemWithCallbacks.cpp
        src/SnoozeSettingsModel.cpp


@@ 23,6 24,7 @@ target_sources(application-bell-common
        include/common/models/AbstractAlarmModel.hpp
        include/common/models/AlarmModel.hpp
        include/common/models/SnoozeSettingsModel.hpp
        include/common/models/TimeModel.hpp
        include/common/popups/AlarmActivatedWindow.hpp
        include/common/popups/AlarmDeactivatedWindow.hpp
        include/common/widgets/BellSideListItemWithCallbacks.hpp

R products/BellHybrid/apps/application-bell-main/models/TimeModel.hpp => products/BellHybrid/apps/common/include/common/models/TimeModel.hpp +2 -2
@@ 5,7 5,7 @@

#include <service-time/api/TimeSettingsApi.hpp>

namespace app::home_screen
namespace app
{
    class AbstractTimeModel
    {


@@ 22,4 22,4 @@ namespace app::home_screen
        utils::time::Locale::TimeFormat getTimeFormat() const override;
        time_t getCurrentTime() const override;
    };
} // namespace app::home_screen
} // namespace app

R products/BellHybrid/apps/application-bell-main/models/TimeModel.cpp => products/BellHybrid/apps/common/src/TimeModel.cpp +3 -3
@@ 1,9 1,9 @@
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "TimeModel.hpp"
#include "models/TimeModel.hpp"

namespace app::home_screen
namespace app
{

    time_t TimeModel::getCurrentTime() const


@@ 14,4 14,4 @@ namespace app::home_screen
    {
        return stm::api::timeFormat();
    }
} // namespace app::home_screen
} // namespace app