From 4e9dbda5c88133a87e6199c305489ef2ca7ac42e Mon Sep 17 00:00:00 2001 From: Tigran Soghbatyan Date: Mon, 25 Oct 2021 15:35:42 +0200 Subject: [PATCH] [BH-1094] Fix bedtime confirmation window Remove BellFinishedCallbackWindow class Add ability to return to the previous app in BellFinishedWindow --- .../ApplicationBellBedtime.cpp | 6 +- .../windows/BellBedtimeWindow.cpp | 9 +-- .../ApplicationBellSettings.cpp | 6 -- .../advanced/BellSettingsAdvancedWindow.cpp | 1 - .../BellHybrid/apps/common/CMakeLists.txt | 3 - .../BellFinishedCallbackWindowSwitchData.hpp | 37 ------------ .../data/BellFinishedWindowSwitchData.hpp | 14 +++-- .../windows/BellFinishedCallbackWindow.hpp | 30 ---------- .../common/windows/BellFinishedWindow.hpp | 4 +- .../windows/BellFinishedCallbackWindow.cpp | 59 ------------------- .../common/src/windows/BellFinishedWindow.cpp | 19 ++++-- 11 files changed, 34 insertions(+), 154 deletions(-) delete mode 100644 products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp delete mode 100644 products/BellHybrid/apps/common/include/common/windows/BellFinishedCallbackWindow.hpp delete mode 100644 products/BellHybrid/apps/common/src/windows/BellFinishedCallbackWindow.cpp diff --git a/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp b/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp index 138cd5597db95fb792d22df49fad29b041676190..aeaf23258901afea697ad102c40c23128f7d4244 100644 --- a/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp +++ b/products/BellHybrid/apps/application-bell-bedtime/ApplicationBellBedtime.cpp @@ -5,9 +5,9 @@ #include "presenter/BellBedtimeWindowPresenter.hpp" #include "windows/BellBedtimeWindow.hpp" #include "common/models/BedtimeModel.hpp" +#include #include "models/BedtimeListItemProvider.hpp" -#include namespace app { ApplicationBellBedtime::ApplicationBellBedtime(std::string name, @@ -38,9 +38,9 @@ namespace app return std::make_unique(app, std::move(presenter)); }); - windowsFactory.attach(gui::BellFinishedCallbackWindow::defaultName, + windowsFactory.attach(gui::window::bell_finished::defaultName, [](ApplicationCommon *app, const std::string &name) { - return std::make_unique(app); + return std::make_unique(app); }); attachPopups({gui::popup::ID::AlarmActivated, diff --git a/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp index 0e48cf8ad5c17ab3f3dfbccf099e570900e2e909..f3e2bfda149a7ba048e671e3773b6d2ed80f7ba5 100644 --- a/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp +++ b/products/BellHybrid/apps/application-bell-bedtime/windows/BellBedtimeWindow.cpp @@ -14,7 +14,7 @@ #include #include -#include +#include #include "service-appmgr/Controller.hpp" // for Controller namespace gui @@ -70,11 +70,8 @@ namespace gui { presenter->saveData(); if (showSuccessWindow) { - application->switchWindow(BellFinishedCallbackWindow::defaultName, - BellFinishedCallbackWindowSwitchData::Factory::create( - "circle_success", - utils::translate("app_bell_bedtime_set_finished"), - [this]() { app::manager::Controller::switchBack(application); })); + application->switchWindow(gui::window::bell_finished::defaultName, + BellFinishedWindowData::Factory::create("circle_success_big", "", "", true)); } else { application->returnToPreviousWindow(); diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index a6bfd3b00fb55ae92c85556f6335d13d4c00f979..82fed2dcb67425131f0584772d43c3f12c0e7817 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -35,7 +35,6 @@ #include #include #include -#include #include #include #include @@ -115,11 +114,6 @@ namespace app return std::make_unique(app); }); - windowsFactory.attach(gui::BellFinishedCallbackWindow::defaultName, - [](ApplicationCommon *app, const std::string &name) { - return std::make_unique(app); - }); - windowsFactory.attach(gui::window::name::bellSettingsHomeView, [](ApplicationCommon *app, const std::string &name) { return std::make_unique(app); diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp index 490e495f6baa9a3f66a67f1bb2e724cc4b3f561f..7bbd51cf5f76e6a9e0850247d5dbbdaa4b70fcbd 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp @@ -15,7 +15,6 @@ #include #include #include -#include #include namespace gui diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index 56af8ff9636abfbcb489e833be05211e0b6c5214..9073e9d80c0662b4e58e88512212f97e62dd011e 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -18,7 +18,6 @@ target_sources(application-bell-common src/BellListItemProvider.cpp src/windows/BellFactoryReset.cpp src/windows/BellFinishedWindow.cpp - src/windows/BellFinishedCallbackWindow.cpp src/windows/BellTurnOffWindow.cpp src/windows/BellWelcomeWindow.cpp src/BellSideListItemWithCallbacks.cpp @@ -45,11 +44,9 @@ target_sources(application-bell-common include/common/BellPowerOffPresenter.hpp include/common/windows/BellFactoryReset.hpp include/common/windows/BellFinishedWindow.hpp - include/common/windows/BellFinishedCallbackWindow.hpp include/common/windows/BellTurnOffWindow.hpp include/common/windows/BellWelcomeWindow.hpp include/common/TimeUtils.hpp - include/common/data/BellFinishedCallbackWindowSwitchData.hpp include/common/models/AbstractAlarmModel.hpp include/common/models/AbstractBedtimeModel.hpp include/common/models/AbstractSettingsModel.hpp diff --git a/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp b/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp deleted file mode 100644 index 73595d642f4b5f00f4485fd2837280f43e26da42..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/common/include/common/data/BellFinishedCallbackWindowSwitchData.hpp +++ /dev/null @@ -1,37 +0,0 @@ -// 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 // for function -#include -#include - -namespace gui -{ - struct BellFinishedCallbackWindowSwitchData : public gui::SwitchData - { - public: - struct Factory - { - static std::unique_ptr create(const UTF8 &icon, - const UTF8 &text, - std::function finishCallback) - { - return std::unique_ptr( - new BellFinishedCallbackWindowSwitchData(icon, text, finishCallback)); - } - }; - - UTF8 icon{}; - UTF8 text{}; - std::function finishCallback; - - private: - BellFinishedCallbackWindowSwitchData() = default; - - BellFinishedCallbackWindowSwitchData(const UTF8 &icon, const UTF8 &text, std::function finishCallback) - : icon{icon}, text{text}, finishCallback{finishCallback} - {} - }; -} // namespace gui diff --git a/products/BellHybrid/apps/common/include/common/data/BellFinishedWindowSwitchData.hpp b/products/BellHybrid/apps/common/include/common/data/BellFinishedWindowSwitchData.hpp index 33cbf665ef562f3123606e5215efa00b4e6a63ae..fd7cd94f40d8f81ebd1fae3908f5f2511ac41a93 100644 --- a/products/BellHybrid/apps/common/include/common/data/BellFinishedWindowSwitchData.hpp +++ b/products/BellHybrid/apps/common/include/common/data/BellFinishedWindowSwitchData.hpp @@ -15,21 +15,27 @@ namespace gui { static std::unique_ptr create(const UTF8 &icon, const std::string &windowToReturn, - const UTF8 &text = "") + const UTF8 &text = "", + bool closeApplication = false) { - return std::unique_ptr(new BellFinishedWindowData(icon, windowToReturn, text)); + return std::unique_ptr( + new BellFinishedWindowData(icon, windowToReturn, text, closeApplication)); } }; UTF8 icon{}; std::string windowToReturn; UTF8 text{}; + bool closeApplication; private: BellFinishedWindowData() = default; - BellFinishedWindowData(const UTF8 &icon, const std::string &windowToReturn, const UTF8 &text = "") - : icon{icon}, windowToReturn{windowToReturn}, text{text} + BellFinishedWindowData(const UTF8 &icon, + const std::string &windowToReturn, + const UTF8 &text = "", + bool closeApplication = false) + : icon{icon}, windowToReturn{windowToReturn}, text{text}, closeApplication{closeApplication} {} }; } // namespace gui diff --git a/products/BellHybrid/apps/common/include/common/windows/BellFinishedCallbackWindow.hpp b/products/BellHybrid/apps/common/include/common/windows/BellFinishedCallbackWindow.hpp deleted file mode 100644 index 8ffd2527a6076c7d5e6c46110dab82e5b2ac2a0b..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/common/include/common/windows/BellFinishedCallbackWindow.hpp +++ /dev/null @@ -1,30 +0,0 @@ -// 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 -#include -#include - -namespace gui -{ - class Icon; - - class BellFinishedCallbackWindow : public WindowWithTimer - { - public: - static constexpr auto defaultName = "BellFinishedCallbackWindow"; - - explicit BellFinishedCallbackWindow(app::ApplicationCommon *app, const std::string &name = defaultName); - - protected: - void buildInterface() override; - bool onInput(const InputEvent &inputEvent) override; - void onBeforeShow(ShowMode mode, SwitchData *data) override; - - Icon *icon{}; - std::function finishCallback = nullptr; - }; - -} // namespace gui diff --git a/products/BellHybrid/apps/common/include/common/windows/BellFinishedWindow.hpp b/products/BellHybrid/apps/common/include/common/windows/BellFinishedWindow.hpp index c81b379ac1f0ec5c3959d877e6f9a752f6799c03..7038d2db1ad5d012bbaac1ef0c14e0e5bfaf13bb 100644 --- a/products/BellHybrid/apps/common/include/common/windows/BellFinishedWindow.hpp +++ b/products/BellHybrid/apps/common/include/common/windows/BellFinishedWindow.hpp @@ -11,7 +11,7 @@ namespace gui { namespace window::bell_finished { - constexpr inline auto defaultName = "BellFinishedWindow"; + constexpr inline auto defaultName = "BellFinishedWindow"; } // namespace window::bell_finished class Icon; @@ -24,11 +24,13 @@ namespace gui protected: void buildInterface() override; + void exit(); bool onInput(const InputEvent &inputEvent) override; void onBeforeShow(ShowMode mode, SwitchData *data) override; Icon *icon{}; std::string windowToReturn; + bool closeApplication; // is close application is true windowToReturn variable is ignored }; } // namespace gui diff --git a/products/BellHybrid/apps/common/src/windows/BellFinishedCallbackWindow.cpp b/products/BellHybrid/apps/common/src/windows/BellFinishedCallbackWindow.cpp deleted file mode 100644 index 230df919ac9d4a5473e9c7a4fb18509a675ba28c..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/common/src/windows/BellFinishedCallbackWindow.cpp +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "common/windows/BellFinishedCallbackWindow.hpp" -#include "common/data/BellFinishedCallbackWindowSwitchData.hpp" -#include -#include -#include - -namespace gui -{ - - BellFinishedCallbackWindow::BellFinishedCallbackWindow(app::ApplicationCommon *app, const std::string &name) - : WindowWithTimer(app, name) - { - buildInterface(); - - timerCallback = [this](Item &, sys::Timer &) { - if (this->finishCallback) { - this->finishCallback(); - } - return true; - }; - } - - void BellFinishedCallbackWindow::buildInterface() - { - WindowWithTimer::buildInterface(); - - statusBar->setVisible(false); - header->setTitleVisibility(false); - navBar->setVisible(false); - - icon = new Icon(this, 0, 0, style::window_width, style::window_height, {}, {}); - icon->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); - } - - bool BellFinishedCallbackWindow::onInput(const InputEvent &inputEvent) - { - if (inputEvent.isShortRelease(KeyCode::KEY_ENTER) || inputEvent.isShortRelease(KeyCode::KEY_RF)) { - if (this->finishCallback) { - this->finishCallback(); - } - return true; - } - return false; - } - - void BellFinishedCallbackWindow::onBeforeShow(ShowMode mode, SwitchData *data) - { - WindowWithTimer::onBeforeShow(mode, data); - - if (auto metadata = dynamic_cast(data)) { - icon->image->set(metadata->icon); - finishCallback = metadata->finishCallback; - } - } - -} // namespace gui diff --git a/products/BellHybrid/apps/common/src/windows/BellFinishedWindow.cpp b/products/BellHybrid/apps/common/src/windows/BellFinishedWindow.cpp index fbd37e4da7f4ba07707d5c960ecfc9cca3dd9eb9..d3aa6b838f402e723c4add16c66767aa6ba3989d 100644 --- a/products/BellHybrid/apps/common/src/windows/BellFinishedWindow.cpp +++ b/products/BellHybrid/apps/common/src/windows/BellFinishedWindow.cpp @@ -5,6 +5,7 @@ #include #include #include +#include "service-appmgr/Controller.hpp" namespace gui { @@ -13,13 +14,22 @@ namespace gui : WindowWithTimer(app, name) { buildInterface(); - timerCallback = [this](Item &, sys::Timer &) { - application->switchWindow(windowToReturn); + exit(); return true; }; } + void BellFinishedWindow::exit() + { + if (closeApplication) { + app::manager::Controller::switchBack(application); + } + else { + application->switchWindow(windowToReturn); + } + } + void BellFinishedWindow::buildInterface() { WindowWithTimer::buildInterface(); @@ -37,7 +47,7 @@ namespace gui bool BellFinishedWindow::onInput(const InputEvent &inputEvent) { if (inputEvent.isShortRelease(KeyCode::KEY_ENTER) || inputEvent.isShortRelease(KeyCode::KEY_RF)) { - application->switchWindow(windowToReturn); + exit(); return true; } return false; @@ -51,7 +61,8 @@ namespace gui icon->image->set(metadata->icon); icon->text->setRichText(metadata->text); icon->resizeItems(); - windowToReturn = metadata->windowToReturn; + windowToReturn = metadata->windowToReturn; + closeApplication = metadata->closeApplication; } }