M products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp => products/BellHybrid/apps/application-bell-alarm/ApplicationBellAlarm.cpp +4 -1
@@ 5,6 5,8 @@
#include "presenter/BellAlarmWindowPresenter.hpp"
#include "windows/BellAlarmWindow.hpp"
+#include <common/models/AlarmModel.hpp>
+
namespace app
{
ApplicationBellAlarm::ApplicationBellAlarm(std::string name,
@@ 30,7 32,8 @@ namespace app
void ApplicationBellAlarm::createUserInterface()
{
windowsFactory.attach(gui::name::window::main_window, [](ApplicationCommon *app, const std::string &name) {
- auto presenter = std::make_unique<bell_alarm::BellAlarmWindowPresenter>();
+ 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));
});
M products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp => products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.cpp +18 -1
@@ 5,8 5,25 @@
namespace app::bell_alarm
{
+ BellAlarmWindowPresenter::BellAlarmWindowPresenter(std::unique_ptr<AbstractAlarmModel> &&alarmModel)
+ : alarmModel{std::move(alarmModel)}
+ {}
+
auto BellAlarmWindowPresenter::saveData() -> void
{
- // TODO
+ auto view = getView();
+ auto time = view->getAlarmTime();
+ alarmModel->setAlarmTime(time);
+ }
+
+ auto BellAlarmWindowPresenter::createData() -> void
+ {
+ auto updateAlarmTimeCallback = [&]() {
+ auto time = alarmModel->getAlarmTime();
+ auto view = getView();
+ view->setAlarmTime(time);
+ };
+
+ alarmModel->update(updateAlarmTimeCallback);
}
} // namespace app::bell_alarm
M products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp => products/BellHybrid/apps/application-bell-alarm/presenter/BellAlarmWindowPresenter.hpp +10 -0
@@ 5,6 5,8 @@
#pragma once
#include <apps-common/BasePresenter.hpp>
+#include <common/models/AbstractAlarmModel.hpp>
+#include <time/dateCommon.hpp>
namespace app::bell_alarm
{
@@ 15,12 17,15 @@ namespace app::bell_alarm
{
public:
virtual ~View() noexcept = default;
+ virtual void setAlarmTime(time_t time) = 0;
+ virtual time_t getAlarmTime() = 0;
};
class Presenter : public BasePresenter<BellAlarmWindowContract::View>
{
public:
virtual ~Presenter() noexcept = default;
+ virtual auto createData() -> void = 0;
virtual auto saveData() -> void = 0;
};
};
@@ 28,6 33,11 @@ namespace app::bell_alarm
class BellAlarmWindowPresenter : public BellAlarmWindowContract::Presenter
{
public:
+ BellAlarmWindowPresenter(std::unique_ptr<AbstractAlarmModel> &&alarmModel);
+ auto createData() -> void override;
auto saveData() -> void override;
+
+ private:
+ std::unique_ptr<AbstractAlarmModel> alarmModel;
};
} // namespace app::bell_alarm
M products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.cpp => products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.cpp +11 -0
@@ 23,6 23,7 @@ namespace gui
{
presenter->attach(this);
buildInterface();
+ presenter->createData();
}
void BellAlarmWindow::buildInterface()
@@ 70,6 71,16 @@ namespace gui
return AppWindow::onInput(inputEvent);
}
+ void BellAlarmWindow::setAlarmTime(time_t time)
+ {
+ timeSetFmtSpinner->setTime(time);
+ }
+
+ time_t BellAlarmWindow::getAlarmTime()
+ {
+ return timeSetFmtSpinner->getTime();
+ }
+
void BellAlarmWindow::rebuild()
{
erase();
M products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.hpp => products/BellHybrid/apps/application-bell-alarm/windows/BellAlarmWindow.hpp +3 -0
@@ 24,6 24,9 @@ namespace gui
bool onInput(const InputEvent &inputEvent) override;
void rebuild() override;
+ void setAlarmTime(time_t time) override;
+ time_t getAlarmTime() override;
+
private:
BellBaseLayout *body{nullptr};
Label *topText{nullptr};
M products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp => products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp +1 -0
@@ 63,6 63,7 @@ namespace app::home_screen
void HomeScreenPresenter::onBeforeShow()
{
+ alarmModel->update([&]() { handleAlarmModelReady(); });
getView()->setTimeFormat(timeModel->getTimeFormat());
getView()->setTime(timeModel->getCurrentTime());
getView()->setAlarmTimeFormat(timeModel->getTimeFormat());