From 4cefb5f114ea60de5e6ae30c404cef065f7d4b1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcin=20Zieli=C5=84ski?= Date: Mon, 12 Sep 2022 11:03:34 +0200 Subject: [PATCH] [MOS-640] Change windows flow in SIM settings Made SIM cards settings windows switching more robust --- .../ApplicationSettings.cpp | 35 +++++++++++++++++++ .../ApplicationSettings.hpp | 2 ++ module-apps/apps-common/ApplicationCommon.cpp | 12 ++++++- module-apps/apps-common/ApplicationCommon.hpp | 5 ++- .../popups/lock-popups/SimInfoWindow.cpp | 6 ++-- .../popups/lock-popups/SimInfoWindow.hpp | 9 +++++ .../popups/lock-popups/SimLockInputWindow.cpp | 10 +++++- pure_changelog.md | 1 + 8 files changed, 73 insertions(+), 7 deletions(-) diff --git a/module-apps/application-settings/ApplicationSettings.cpp b/module-apps/application-settings/ApplicationSettings.cpp index 79c42df1629765ed921b2ff9a0496be66a7983fa..ec0caa2486a7f70c3df9b5c9274211dfa22922f4 100644 --- a/module-apps/application-settings/ApplicationSettings.cpp +++ b/module-apps/application-settings/ApplicationSettings.cpp @@ -84,6 +84,7 @@ #include #include #include +#include #include #include @@ -570,6 +571,40 @@ namespace app return selectedSimNumber; } + void ApplicationSettings::returnToPreviousWindow() + { + using namespace gui::popup::window; + using namespace gui::window::name; + + auto previousWindowName = getPreviousWindow(); + if (!previousWindowName.has_value()) { + ApplicationCommon::returnToPreviousWindow(); + return; + } + + bool previousWindowBackingToSimCards = + (previousWindowName == sim_pin_settings || previousWindowName == import_contacts || + previousWindowName == sim_unlock_window); + auto currentWindowName = getCurrentWindow()->getName(); + + // despite "import_contacts" has auto-lock prevented, it's included here in previousWindowBackingToSimCards for + // simplicity + if (currentWindowName == phone_lock_window && previousWindowBackingToSimCards) { + switchWindow(sim_cards); + return; + } + + if (currentWindowName == sim_info_window) { + auto simInfoWindowAction = static_cast(getCurrentWindow())->getAction(); + if (simInfoWindowAction == locks::SimInputTypeAction::Error && previousWindowBackingToSimCards) { + switchWindow(sim_cards); + return; + } + } + + ApplicationCommon::returnToPreviousWindow(); + } + void ApplicationSettings::setSim(Store::GSM::SIM sim) { auto arg = (sim == Store::GSM::SIM::SIM2) ? cellular::api::SimSlot::SIM2 : cellular::api::SimSlot::SIM1; diff --git a/module-apps/application-settings/include/application-settings/ApplicationSettings.hpp b/module-apps/application-settings/include/application-settings/ApplicationSettings.hpp index b1079e3bd009700b115b680de961db91dab32c9d..633ff36a3a85bfa3e0531aa1e25f8e92c146a0cd 100644 --- a/module-apps/application-settings/include/application-settings/ApplicationSettings.hpp +++ b/module-apps/application-settings/include/application-settings/ApplicationSettings.hpp @@ -144,6 +144,8 @@ namespace app void createUserInterface() override; void destroyUserInterface() override; + void returnToPreviousWindow() override; + void setSim(Store::GSM::SIM sim) override; void updateSim() override; Store::GSM::SIM getSim() override; diff --git a/module-apps/apps-common/ApplicationCommon.cpp b/module-apps/apps-common/ApplicationCommon.cpp index c7ce02ab75b764ed81e75a6f17a74931db70f0fb..097894c52068362f7e2edb2886e5622bc8bd2174 100644 --- a/module-apps/apps-common/ApplicationCommon.cpp +++ b/module-apps/apps-common/ApplicationCommon.cpp @@ -921,7 +921,7 @@ namespace app return; } if (windowsStack().pop(newWindow)) { - LOG_INFO("Get back to window!"); + LOG_INFO("Requested window %s is previous one - get back to it", newWindow.c_str()); return; } LOG_INFO("Create window for stack: %s", newWindow.c_str()); @@ -956,6 +956,16 @@ namespace app return false; } + bool ApplicationCommon::isPreviousWindow(const std::string &windowName) const noexcept + { + if (const auto &previousWindowName = getPreviousWindow(); previousWindowName != std::nullopt) { + return previousWindowName == windowName; + } + + LOG_WARN("no previous window"); + return false; + } + gui::AppWindow *ApplicationCommon::getWindow(const std::string &name) { return windowsStack().get(name); diff --git a/module-apps/apps-common/ApplicationCommon.hpp b/module-apps/apps-common/ApplicationCommon.hpp index c9235b4c5819b7685d0df4344b579223e259f645..c88bc59dfc3d063ad3cc147c1458c8e528b64899 100644 --- a/module-apps/apps-common/ApplicationCommon.hpp +++ b/module-apps/apps-common/ApplicationCommon.hpp @@ -266,9 +266,7 @@ namespace app switchWindow(windowName, gui::ShowMode::GUI_SHOW_INIT, std::move(data)); }; - /// Method used to go back to desired window by using the index difference on stack value - /// @param ignoredWindowsNumber: defines how many windows will be skipped while going back on stack - [[deprecated]] void returnToPreviousWindow(); + [[deprecated]] virtual void returnToPreviousWindow(); /// Find and pop window from stack by window name void popWindow(const std::string &window); @@ -387,6 +385,7 @@ namespace app gui::AppWindow *getCurrentWindow(); /// @ingrup AppWindowStack bool isCurrentWindow(const std::string &windowName) const noexcept; + bool isPreviousWindow(const std::string &windowName) const noexcept; /// @ingrup AppWindowStack gui::AppWindow *getWindow(const std::string &name); diff --git a/module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp b/module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp index a227b2c1cd4dd9079c47895b3d570f8160a213ed..f0525bed9714d79a34a370f4780d6ebe0a57c7e0 100644 --- a/module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp +++ b/module-apps/apps-common/popups/lock-popups/SimInfoWindow.cpp @@ -6,6 +6,8 @@ #include #include +#include + using namespace gui; SimInfoWindow::SimInfoWindow(app::ApplicationCommon *app, const std::string &name) : WindowWithTimer(app, name) @@ -31,8 +33,8 @@ void SimInfoWindow::onBeforeShow(ShowMode mode, SwitchData *data) WindowWithTimer::onBeforeShow(mode, data); if (auto infoData = dynamic_cast(data)) { - - switch (infoData->getSimInputTypeAction()) { + action_ = infoData->getSimInputTypeAction(); + switch (action_.value()) { case locks::SimInputTypeAction::UnlockWithPuk: case locks::SimInputTypeAction::ChangePin: setTitle(utils::translate("sim_change_pin")); diff --git a/module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp b/module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp index ad7dc2737864049363a92350d45ec84ea6c563e9..6bd4a3458db2c0b6979cc82c07206c6354cbe230 100644 --- a/module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp +++ b/module-apps/apps-common/popups/lock-popups/SimInfoWindow.hpp @@ -6,6 +6,7 @@ #include #include #include +#include namespace gui { @@ -19,5 +20,13 @@ namespace gui void buildInterface() override; void onBeforeShow(ShowMode mode, SwitchData *data) override; status_bar::Configuration configureStatusBar(status_bar::Configuration appConfiguration) override; + + locks::SimInputTypeAction getAction() const + { + return action_.value(); + } + + private: + std::optional action_; }; } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp b/module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp index 070b00e46a1bd46991ea26330ec42ded83c68a83..3f7685145201f0f50457168d413c4d71740d58ad 100644 --- a/module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp +++ b/module-apps/apps-common/popups/lock-popups/SimLockInputWindow.cpp @@ -7,6 +7,8 @@ #include #include +#include + #include #include @@ -88,7 +90,13 @@ namespace gui lock->consumeState(); } application->getSimLockSubject().resetSimLockState(); - application->returnToPreviousWindow(); + if (auto *settingsApp = dynamic_cast(application); + settingsApp && settingsApp->isPreviousWindow(gui::window::name::sim_pin_settings)) { + settingsApp->switchWindow(gui::window::name::sim_cards); + } + else { + application->returnToPreviousWindow(); + } return true; } else if (inputEvent.is(KeyCode::KEY_PND)) { diff --git a/pure_changelog.md b/pure_changelog.md index e29eb9f75e684a44bcb67d7632b291a8ebe2586a..273562d173c098215f6620559a2525a07fb38c56 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -6,6 +6,7 @@ * Added Polish translation to a calendar title * Changed USB logging * Separated system volume from Bluetooth device volume for A2DP +* Made windows flow in SIM cards settings more robust ### Fixed * Fixed receiving an empty SMS message