From a9fba040be01d5845f8e20f4a4bc39ad64bd0b26 Mon Sep 17 00:00:00 2001 From: Bartosz Cichocki Date: Tue, 21 Dec 2021 15:46:49 +0100 Subject: [PATCH] [EGD-7773] Add popup drop possibility Added popup drop possibility with custom callback onPop to comply with Bell requirements --- module-apps/apps-common/ApplicationCommon.cpp | 19 ++++++++-- module-apps/apps-common/ApplicationCommon.hpp | 2 ++ module-apps/apps-common/WindowsStack.cpp | 23 ++++++++++++ module-apps/apps-common/WindowsStack.hpp | 6 +++- .../ApplicationBellMain.cpp | 35 ++++++++++--------- 5 files changed, 64 insertions(+), 21 deletions(-) diff --git a/module-apps/apps-common/ApplicationCommon.cpp b/module-apps/apps-common/ApplicationCommon.cpp index f9ddb8c0bd1b70af7b9f49795aa0a19bfd7b4ea8..ae206bfed45d474b23684ef310fe516ce87b9f92 100644 --- a/module-apps/apps-common/ApplicationCommon.cpp +++ b/module-apps/apps-common/ApplicationCommon.cpp @@ -836,6 +836,11 @@ namespace app LOG_ERROR("no blueprint to handle %s popup - fallback", std::string(magic_enum::enum_name(id)).c_str()); blueprint = popupBlueprintFallback(id); } + if (data->getDisposition().windowtype != gui::popup::Disposition::WindowType::Popup) { + LOG_ERROR("setting popup window type to popup - fallback"); + data->setDisposition(gui::popup::Disposition{ + gui::popup::Disposition::Priority::Normal, gui::popup::Disposition::WindowType::Popup, id}); + } auto request = gui::popup::Request(id, std::move(data), *blueprint); windowsPopupQueue->pushRequest(std::move(request)); tryShowPopup(); @@ -857,8 +862,8 @@ namespace app if (not retval) { LOG_ERROR("Popup %s handling failure, please check registered blueprint!", popup.c_str()); } - return retval; LOG_ERROR("no blueprint for popup: %s", popup.c_str()); + return retval; } return false; } @@ -867,8 +872,12 @@ namespace app { const auto popupName = gui::popup::resolveWindowName(id); LOG_INFO("abort popup: %s from window %s", popupName.c_str(), getCurrentWindow()->getName().c_str()); - windowsStack().pop(popupName); - returnToPreviousWindow(); + if (not windowsStack().pop(popupName)) { + return; + } + if (popupName == getCurrentWindow()->getName()) { + returnToPreviousWindow(); + } } bool ApplicationCommon::userInterfaceDBNotification([[maybe_unused]] sys::Message *msg, @@ -988,4 +997,8 @@ namespace app { return simLockSubject; } + void ApplicationCommon::registerOnPopCallback(std::function callback) + { + windowsStack().registerOnPopCallback(std::move(callback)); + } } /* namespace app */ diff --git a/module-apps/apps-common/ApplicationCommon.hpp b/module-apps/apps-common/ApplicationCommon.hpp index 144e9f712942bc6b973541b59f087e311b3a34d5..0df291527d89730bd3946bc79f551d2b575beed1 100644 --- a/module-apps/apps-common/ApplicationCommon.hpp +++ b/module-apps/apps-common/ApplicationCommon.hpp @@ -273,6 +273,8 @@ namespace app /// Find and pop window from stack by window name void popWindow(const std::string &window); + void registerOnPopCallback(std::function callback); + /// Pops the current window from the windows stack void popCurrentWindow(); diff --git a/module-apps/apps-common/WindowsStack.cpp b/module-apps/apps-common/WindowsStack.cpp index 4ffe5a61c37c56591b523c0fa5345a918b3b20cf..c6572d05e481774bc7ad5e87045bdc91c20acf6b 100644 --- a/module-apps/apps-common/WindowsStack.cpp +++ b/module-apps/apps-common/WindowsStack.cpp @@ -2,6 +2,8 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "WindowsStack.hpp" + +#include #include "WindowsFactory.hpp" #include "windows/AppWindow.hpp" @@ -67,6 +69,9 @@ namespace app auto ret = findInStack(window); if (ret != stack.end()) { stack.erase(std::next(ret), stack.end()); + if (onPopCallback) { + onPopCallback(*this); + } return true; } return false; @@ -112,5 +117,23 @@ namespace app { return std::find_if(stack.begin(), stack.end(), [&](auto &el) { return el.name == window; }); } + void WindowsStack::registerOnPopCallback(std::function callback) + { + onPopCallback = std::move(callback); + } + void WindowsStack::dropPendingPopups() + { + auto it = stack.rbegin(); + while (it != stack.rend()) { + LOG_DEBUG("Current window on stack: %s, type: %s", + it->name.c_str(), + magic_enum::enum_name(it->disposition.windowtype).data()); + if (it->disposition.windowtype == gui::popup::Disposition::WindowType::Popup) { + LOG_DEBUG("Erasing: %s", it->name.c_str()); + stack.erase(std::next(it).base()); + } + std::advance(it, 1); + } + } } // namespace app diff --git a/module-apps/apps-common/WindowsStack.hpp b/module-apps/apps-common/WindowsStack.hpp index 1563f0f639a3e14521d66d19e6029e1a7a2b3b38..054fb422ab787f0154e0a473dec7ea35018b1eca 100644 --- a/module-apps/apps-common/WindowsStack.hpp +++ b/module-apps/apps-common/WindowsStack.hpp @@ -40,8 +40,9 @@ namespace app class WindowsStack { - std::vector stack; + std::function onPopCallback = nullptr; std::map> windows{}; + std::vector stack; decltype(stack)::iterator findInStack(const std::string &); public: @@ -70,8 +71,11 @@ namespace app bool pop(const std::string &window); bool popLastWindow(); bool drop(const std::string &window); + void dropPendingPopups(); void clear(); bool rebuildWindows(app::WindowsFactory &windowsFactory, ApplicationCommon *app); + void registerOnPopCallback(std::function callback); }; + } // namespace app diff --git a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp index 4b5752e244a41749067c8776fe0c5dcf6bb0b081..e6f62e0298dcbcbd2ef283039870f108c291d28b 100644 --- a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +++ b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp @@ -24,6 +24,7 @@ #include #include #include +#include namespace app { @@ -34,23 +35,23 @@ namespace app std::uint32_t stackDepth) : Application(name, parent, statusIndicators, startInBackground, stackDepth) { - - getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams &popupParams) { - auto val = ((isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::Reboot))) || - (isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::PowerOff))) || - (isCurrentWindow(gui::BellTurnOffWindow::name))); - if (val) { - LOG_INFO("popup blocked"); - return !val; - } - if (not(((popupParams.getPopupId() == gui::popup::ID::AlarmActivated || - popupParams.getPopupId() == gui::popup::ID::AlarmDeactivated)) and - (not isHomeScreenFocused()))) { - LOG_INFO("popup blocked"); - return false; - } - return true; - }); + registerOnPopCallback([](WindowsStack &windowsStack) { windowsStack.dropPendingPopups(); }); + // getPopupFilter().addAppDependentFilter([&](const gui::PopupRequestParams &popupParams) { + // auto val = ((isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::Reboot))) || + // (isCurrentWindow(gui::popup::resolveWindowName(gui::popup::ID::PowerOff))) || + // (isCurrentWindow(gui::BellTurnOffWindow::name))); + // if (val) { + // LOG_INFO("popup blocked"); + // return !val; + // } + // if (not(((popupParams.getPopupId() == gui::popup::ID::AlarmActivated || + // popupParams.getPopupId() == gui::popup::ID::AlarmDeactivated)) and + // (not isHomeScreenFocused()))) { + // LOG_INFO("popup blocked"); + // return false; + // } + // return true; + // }); bus.channels.push_back(sys::BusChannel::ServiceDBNotifications); addActionReceiver(manager::actions::ShowAlarm, [this](auto &&data) {