From 8078dd240bb08f8d4c2d44bc944bf4e72d5e7e8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kamo=C5=84?= Date: Mon, 31 May 2021 13:27:26 +0200 Subject: [PATCH] [EGD-6855] Add no modem notification on tethering This commit provides the implementation of functionality that blocks sms/calls notifications on home screen when tethering is active. Previously, the notifications could be visible if the notifications were visible prior to tethering activation. By the design, the functionality should not clear the notifications, just temporary hide them. That is achieved by implementation ot the functionality in NotificationModel which is an UI presenter. --- .../notifications/NotificationsModel.cpp | 19 +++++++++++++++++-- .../notifications/NotificationsModel.hpp | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/module-apps/notifications/NotificationsModel.cpp b/module-apps/notifications/NotificationsModel.cpp index aaa5a1a5b..83a657627 100644 --- a/module-apps/notifications/NotificationsModel.cpp +++ b/module-apps/notifications/NotificationsModel.cpp @@ -20,6 +20,15 @@ namespace item->setName(utils::translate(text), true); } } + + bool hasTetheringNotification(app::manager::actions::NotificationsChangedParams *params) + { + const auto ¬ifications = params->getNotifications(); + const auto it = std::find_if(std::begin(notifications), std::end(notifications), [](const auto ¬ification) { + return notification->getType() == notifications::NotificationType::Tethering; + }); + return it != std::end(notifications); + } } // namespace unsigned int NotificationsModel::requestRecordsCount() @@ -104,12 +113,13 @@ void NotificationsModel::updateData(app::manager::actions::NotificationsChangedP delete item; } }; + tetheringOn = hasTetheringNotification(params); for (const auto ¬ification : params->getNotifications()) { - if (typeid(*notification) == typeid(notifications::NotSeenSMSNotification)) { + if (not tetheringOn && typeid(*notification) == typeid(notifications::NotSeenSMSNotification)) { auto sms = static_cast(notification.get()); internalData.push_back(create(sms)); } - else if (typeid(*notification) == typeid(notifications::NotSeenCallNotification)) { + else if (not tetheringOn && typeid(*notification) == typeid(notifications::NotSeenCallNotification)) { auto call = static_cast(notification.get()); internalData.push_back(create(call)); } @@ -128,3 +138,8 @@ void NotificationsModel::clearAll() list->reset(); eraseInternalData(); } + +bool NotificationsModel::isTetheringOn() const noexcept +{ + return tetheringOn; +} diff --git a/module-apps/notifications/NotificationsModel.hpp b/module-apps/notifications/NotificationsModel.hpp index fbc4d1a82..d01786637 100644 --- a/module-apps/notifications/NotificationsModel.hpp +++ b/module-apps/notifications/NotificationsModel.hpp @@ -22,6 +22,7 @@ namespace gui void requestRecords(uint32_t offset, uint32_t limit) final; protected: + bool tetheringOn = false; [[nodiscard]] virtual auto create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem *; [[nodiscard]] virtual auto create(const notifications::NotSeenCallNotification *notification) @@ -32,6 +33,7 @@ namespace gui public: [[nodiscard]] bool isEmpty() const noexcept; [[nodiscard]] bool hasDismissibleNotification() const noexcept; + [[nodiscard]] bool isTetheringOn() const noexcept; void updateData(app::manager::actions::NotificationsChangedParams *params); void dismissAll(const InputEvent &event);