From 1abd6b18e2474d685cf105c037b2e36955bb5c5a Mon Sep 17 00:00:00 2001 From: Przemyslaw Brudny Date: Thu, 29 Apr 2021 11:26:57 +0200 Subject: [PATCH] [EGD-6641] Added Notifications to LockedPhone popup Added NotificationsModel to LockedPhone popup window. --- module-apps/Application.cpp | 18 +++++++------- module-apps/Application.hpp | 6 +---- module-apps/InternalModel.hpp | 2 -- .../ApplicationDesktop.cpp | 17 +++++++------ .../ApplicationDesktop.hpp | 4 +--- .../models/ActiveNotificationsModel.cpp | 23 +++++++++--------- .../models/ActiveNotificationsModel.hpp | 5 ++++ .../windows/DesktopMainWindow.cpp | 24 +++++++++---------- .../windows/DesktopMainWindow.hpp | 14 +++++------ .../widgets/MeditationModel.hpp | 3 ++- .../model/SearchResultsListModel.hpp | 13 ++++------ .../notifications/NotificationsModel.cpp | 5 ---- .../notifications/NotificationsModel.hpp | 2 -- .../popups/lock-popups/PhoneLockedWindow.cpp | 21 ++++++++++++---- .../popups/lock-popups/PhoneLockedWindow.hpp | 8 +++++-- 15 files changed, 86 insertions(+), 79 deletions(-) diff --git a/module-apps/Application.cpp b/module-apps/Application.cpp index c406f141897d2b1cf98d8d8fa24cb564e5970f24..c1bb10f425d9dff6e8eb57f356e920251dd26b71 100644 --- a/module-apps/Application.cpp +++ b/module-apps/Application.cpp @@ -2,10 +2,10 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Application.hpp" -#include "Common.hpp" // for RefreshModes -#include "GuiTimer.hpp" // for GuiTimer -#include "Item.hpp" // for Item -#include "MessageType.hpp" // for MessageType +#include "Common.hpp" // for RefreshModes +#include "GuiTimer.hpp" // for GuiTimer +#include "Item.hpp" // for Item +#include "MessageType.hpp" // for MessageType #include "module-sys/Timers/TimerFactory.hpp" // for Timer #include "TopBar.hpp" #include "TopBar/Time.hpp" @@ -146,8 +146,7 @@ namespace app return actionHandled(); }); addActionReceiver(app::manager::actions::NotificationsChanged, [this](auto &¶ms) { - auto notificationParams = static_cast(params.get()); - handle(notificationParams); + handleNotificationsChanged(std::move(params)); return actionHandled(); }); } @@ -903,9 +902,12 @@ namespace app receivers.insert_or_assign(actionId, std::move(callback)); } - void Application::handle(manager::actions::NotificationsChangedParams *params) + void Application::handleNotificationsChanged(std::unique_ptr notificationsParams) { - LOG_DEBUG("To be implemented by Pop-up based Locked-Screen [EGD-5884]"); + if (auto window = getCurrentWindow()->getName(); window == gui::popup::window::phone_lock_window) { + + updateWindow(window, std::move(notificationsParams)); + } } void Application::cancelCallbacks(AsyncCallbackReceiver::Ptr receiver) diff --git a/module-apps/Application.hpp b/module-apps/Application.hpp index 61e42f912cc7bab9e37817b793f3070d26a8543d..a5baa833c4ab0c96c171c3966d6cc1a3a7c4bfcf 100644 --- a/module-apps/Application.hpp +++ b/module-apps/Application.hpp @@ -37,10 +37,6 @@ namespace app { class WindowsStack; - namespace manager::actions - { - class NotificationsChangedParams; - } } // namespace app namespace gui { @@ -390,7 +386,7 @@ namespace app const gui::InputEvent &event); void addActionReceiver(manager::actions::ActionId actionId, OnActionReceived &&callback); - virtual void handle(manager::actions::NotificationsChangedParams *params); + virtual void handleNotificationsChanged(std::unique_ptr notificationsParams); std::unique_ptr topBarManager; diff --git a/module-apps/InternalModel.hpp b/module-apps/InternalModel.hpp index 0d42613784f0462644f824fed4f9296c9a9a4953..027c54557279470885989158049468a3c5d602f4 100644 --- a/module-apps/InternalModel.hpp +++ b/module-apps/InternalModel.hpp @@ -6,8 +6,6 @@ #include #include -#include "Application.hpp" - namespace app { diff --git a/module-apps/application-desktop/ApplicationDesktop.cpp b/module-apps/application-desktop/ApplicationDesktop.cpp index 0db790539f2c5d7586120e0cc79e705f1df994a8..d747ab76390704b1872b75d7c367085e1c186c7c 100644 --- a/module-apps/application-desktop/ApplicationDesktop.cpp +++ b/module-apps/application-desktop/ApplicationDesktop.cpp @@ -24,7 +24,6 @@ #include "AppWindow.hpp" #include "data/DesktopData.hpp" -#include "models/ActiveNotificationsModel.hpp" #include #include @@ -70,8 +69,7 @@ namespace app std::string parent, sys::phone_modes::PhoneMode mode, StartInBackground startInBackground) - : Application(std::move(name), std::move(parent), mode, startInBackground), - lockHandler(this), notificationsModel{std::make_shared()} + : Application(std::move(name), std::move(parent), mode, startInBackground), lockHandler(this) { using namespace gui::top_bar; topBarManager->enableIndicators({Indicator::Signal, @@ -253,11 +251,12 @@ namespace app return true; } - void ApplicationDesktop::handle(manager::actions::NotificationsChangedParams *params) + void ApplicationDesktop::handleNotificationsChanged(std::unique_ptr notificationsParams) { - if (getCurrentWindow()->getName() == app::window::name::desktop_main_window) { - notificationsModel->updateData(params); - refreshWindow(gui::RefreshModes::GUI_REFRESH_FAST); + if (auto window = getCurrentWindow()->getName(); + window == app::window::name::desktop_main_window || window == gui::popup::window::phone_lock_window) { + + updateWindow(window, std::move(notificationsParams)); } } @@ -458,8 +457,8 @@ namespace app void ApplicationDesktop::createUserInterface() { using namespace app::window::name; - windowsFactory.attach(desktop_main_window, [this](Application *app, const std::string &name) { - return std::make_unique(app, notificationsModel); + windowsFactory.attach(desktop_main_window, [](Application *app, const std::string &name) { + return std::make_unique(app); }); windowsFactory.attach(desktop_pin_lock, [&](Application *app, const std::string newname) { return std::make_unique(app, desktop_pin_lock); diff --git a/module-apps/application-desktop/ApplicationDesktop.hpp b/module-apps/application-desktop/ApplicationDesktop.hpp index 75110a14a5c4444aaad590061ee77815e752bd1c..ba6e14224aa915831d45bea8e36ad919bde1df95 100644 --- a/module-apps/application-desktop/ApplicationDesktop.hpp +++ b/module-apps/application-desktop/ApplicationDesktop.hpp @@ -14,7 +14,6 @@ #include #include #include -#include namespace cellular { @@ -82,7 +81,7 @@ namespace app auto handle(db::query::CalllogGetCountResult *msg) -> bool; auto handle(sdesktop::UpdateOsMessage *msg) -> bool; auto handle(sdesktop::developerMode::ScreenlockCheckEvent *event) -> bool; - void handle(manager::actions::NotificationsChangedParams *params) override; + void handleNotificationsChanged(std::unique_ptr notificationsParams) override; /** * This static method will be used to lock the phone */ @@ -113,7 +112,6 @@ namespace app void osCurrentVersionChanged(const std::string &value); std::string osUpdateVersion{updateos::initSysVer}; std::string osCurrentVersion{updateos::initSysVer}; - std::shared_ptr notificationsModel; }; template <> struct ManifestTraits diff --git a/module-apps/application-desktop/models/ActiveNotificationsModel.cpp b/module-apps/application-desktop/models/ActiveNotificationsModel.cpp index be8b345ac184678a3eb09b8b47cbd402ea0314e2..f2b613d423206552e6ecc8e17957bf5cd5ddcdb5 100644 --- a/module-apps/application-desktop/models/ActiveNotificationsModel.cpp +++ b/module-apps/application-desktop/models/ActiveNotificationsModel.cpp @@ -10,6 +10,9 @@ using namespace gui; +ActiveNotificationsModel::ActiveNotificationsModel(AppWindow *parent) : parent(parent) +{} + void ActiveNotificationsModel::setParentBottomBar(const UTF8 &left, const UTF8 ¢er, const UTF8 &right) { parent->setBottomBarText(left, BottomBar::Side::LEFT); @@ -32,17 +35,15 @@ auto ActiveNotificationsModel::create(const notifications::NotSeenSMSNotificatio app::manager::actions::Launch, std::make_unique(app::name_messages)); }; - item->inputCallback = - [this]([[maybe_unused]] Item &item, const InputEvent &inputEvent) { - if (inputEvent.isShortRelease(KeyCode::KEY_RF)) { - DBServiceAPI::GetQuery( - parent->getApplication(), - db::Interface::Name::Notifications, - std::make_unique(NotificationsRecord::Key::Sms)); - return true; - } - return false; - }; + item->inputCallback = [this]([[maybe_unused]] Item &item, const InputEvent &inputEvent) { + if (inputEvent.isShortRelease(KeyCode::KEY_RF)) { + DBServiceAPI::GetQuery(parent->getApplication(), + db::Interface::Name::Notifications, + std::make_unique(NotificationsRecord::Key::Sms)); + return true; + } + return false; + }; item->setDismissible(true); return item; } diff --git a/module-apps/application-desktop/models/ActiveNotificationsModel.hpp b/module-apps/application-desktop/models/ActiveNotificationsModel.hpp index 87141aee45568f078050ce9ed8aef13d8a4aae28..8dc67cc919e3bc4c0a5df36deac3c47d53263af1 100644 --- a/module-apps/application-desktop/models/ActiveNotificationsModel.hpp +++ b/module-apps/application-desktop/models/ActiveNotificationsModel.hpp @@ -9,6 +9,11 @@ namespace gui { class ActiveNotificationsModel : public gui::NotificationsModel { + private: + AppWindow *parent = nullptr; + + public: + explicit ActiveNotificationsModel(AppWindow *parent); void setParentBottomBar(const UTF8 &left, const UTF8 ¢er, const UTF8 &right); auto create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem * override; auto create(const notifications::NotSeenCallNotification *notification) -> NotificationListItem * override; diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.cpp b/module-apps/application-desktop/windows/DesktopMainWindow.cpp index 2938a330f6a6619e9c97885710fdc8d22d4cce55..10a6c59d24605bcc803c7060e922f4d8511f259f 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.cpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.cpp @@ -71,8 +71,8 @@ namespace gui void DesktopMainWindow::invalidate() noexcept { - time = nullptr; - dayText = nullptr; + time = nullptr; + dayText = nullptr; } top_bar::Configuration DesktopMainWindow::configureTopBar(top_bar::Configuration appConfiguration) @@ -82,10 +82,10 @@ namespace gui return appConfiguration; } - DesktopMainWindow::DesktopMainWindow(app::Application *app, std::shared_ptr model) - : AppWindow(app, app::window::name::desktop_main_window), notificationsModel(std::move(model)) + DesktopMainWindow::DesktopMainWindow(app::Application *app) + : AppWindow(app, app::window::name::desktop_main_window), + notificationsModel(std::make_shared(this)) { - notificationsModel->setParentWindow(this); osUpdateVer = getAppDesktop()->getOsUpdateVersion(); osCurrentVer = getAppDesktop()->getOsCurrentVersion(); @@ -94,12 +94,6 @@ namespace gui preBuildDrawListHook = [this](std::list &cmd) { updateTime(); }; } - DesktopMainWindow::~DesktopMainWindow() - { - notificationsModel->clearAll(); - notificationsModel->list = nullptr; - } - void DesktopMainWindow::setVisibleState() { auto app = getAppDesktop(); @@ -123,7 +117,13 @@ namespace gui void DesktopMainWindow::onBeforeShow(ShowMode mode, SwitchData *data) { - app::manager::Controller::requestNotifications(application); + if (auto notificationData = dynamic_cast(data)) { + notificationsModel->updateData(notificationData); + } + else { + app::manager::Controller::requestNotifications(application); + } + setVisibleState(); } diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.hpp b/module-apps/application-desktop/windows/DesktopMainWindow.hpp index a9baae7da762bdd809e77c3d74f39f20c164d144..618c20b20cc852c3f3a24312a85e328d2c923e32 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.hpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.hpp @@ -3,10 +3,11 @@ #pragma once +#include + #include #include #include -#include #include namespace app @@ -19,11 +20,11 @@ namespace gui class DesktopMainWindow : public AppWindow { protected: - gui::Label *time = nullptr; - gui::Label *dayText = nullptr; + gui::Label *time = nullptr; + gui::Label *dayText = nullptr; - gui::ListView *notificationsList = nullptr; - std::shared_ptr notificationsModel = nullptr; + gui::ListView *notificationsList = nullptr; + std::shared_ptr notificationsModel = nullptr; // method hides or show widgets and sets bars according to provided state void setVisibleState(); @@ -33,8 +34,7 @@ namespace gui app::ApplicationDesktop *getAppDesktop() const; public: - DesktopMainWindow(app::Application *app, std::shared_ptr model); - ~DesktopMainWindow(); + explicit DesktopMainWindow(app::Application *app); // virtual methods gui::Window bool onInput(const InputEvent &inputEvent) override; diff --git a/module-apps/application-meditation/widgets/MeditationModel.hpp b/module-apps/application-meditation/widgets/MeditationModel.hpp index 933660a57d100ef238522b7f70e28e8759d20d63..0f23d77af60897b89d1560f3ff30713b50ee2494 100644 --- a/module-apps/application-meditation/widgets/MeditationModel.hpp +++ b/module-apps/application-meditation/widgets/MeditationModel.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -6,6 +6,7 @@ #include "ListItemProvider.hpp" #include "InternalModel.hpp" #include "MeditationListItems.hpp" +#include "Application.hpp" namespace gui { diff --git a/module-apps/application-notes/model/SearchResultsListModel.hpp b/module-apps/application-notes/model/SearchResultsListModel.hpp index 57eb8166e6cbc8f13ce22594e3245377f995d370..4df21e9cddbe41453a8c98998cfe5eed7b0024f7 100644 --- a/module-apps/application-notes/model/SearchResultsListModel.hpp +++ b/module-apps/application-notes/model/SearchResultsListModel.hpp @@ -1,16 +1,13 @@ -// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// 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 #include - -#include -#include "module-apps/application-notes/widgets/NotesItem.hpp" -#include +#include +#include +#include namespace app::notes { diff --git a/module-apps/notifications/NotificationsModel.cpp b/module-apps/notifications/NotificationsModel.cpp index 274478623c4f8dc8b6b64082ff69e04ed39f6138..d43b17f820f22f3699b0317ad251a69f9673fdaf 100644 --- a/module-apps/notifications/NotificationsModel.cpp +++ b/module-apps/notifications/NotificationsModel.cpp @@ -118,8 +118,3 @@ void NotificationsModel::clearAll() list->reset(); eraseInternalData(); } - -void NotificationsModel::setParentWindow(AppWindow *parentWindow) noexcept -{ - parent = parentWindow; -} diff --git a/module-apps/notifications/NotificationsModel.hpp b/module-apps/notifications/NotificationsModel.hpp index c0768db2c8188f03a4a691c660faa3737017d55e..fbc4d1a827a55b8c62e67087fdeaf51c3324a647 100644 --- a/module-apps/notifications/NotificationsModel.hpp +++ b/module-apps/notifications/NotificationsModel.hpp @@ -22,7 +22,6 @@ namespace gui void requestRecords(uint32_t offset, uint32_t limit) final; protected: - AppWindow *parent = nullptr; [[nodiscard]] virtual auto create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem *; [[nodiscard]] virtual auto create(const notifications::NotSeenCallNotification *notification) @@ -37,7 +36,6 @@ namespace gui void updateData(app::manager::actions::NotificationsChangedParams *params); void dismissAll(const InputEvent &event); void clearAll(); - void setParentWindow(AppWindow *parentWindow) noexcept; }; } // namespace gui diff --git a/module-apps/popups/lock-popups/PhoneLockedWindow.cpp b/module-apps/popups/lock-popups/PhoneLockedWindow.cpp index 9d138ca714a1a2fa2d607333456aa94b63c0b2bf..a2c03d07f31a888e1727ee4493a8d60b3c65b1db 100644 --- a/module-apps/popups/lock-popups/PhoneLockedWindow.cpp +++ b/module-apps/popups/lock-popups/PhoneLockedWindow.cpp @@ -30,7 +30,8 @@ namespace gui return enterPressed; } - PhoneLockedWindow::PhoneLockedWindow(app::Application *app, const std::string &name) : AppWindow(app, name) + PhoneLockedWindow::PhoneLockedWindow(app::Application *app, const std::string &name) + : AppWindow(app, name), notificationsModel(std::make_shared()) { buildInterface(); @@ -54,6 +55,14 @@ namespace gui dayText->setBorderColor(gui::ColorNoColor); dayText->setFont(style::window::font::biglight); dayText->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); + + notificationsList = new ListView(this, + style::notifications::model::x, + style::notifications::model::y, + style::notifications::model::w, + style::notifications::model::h, + notificationsModel, + listview::ScrollBarType::None); } top_bar::Configuration PhoneLockedWindow::configureTopBar(top_bar::Configuration appConfiguration) @@ -70,14 +79,18 @@ namespace gui void PhoneLockedWindow::onBeforeShow(ShowMode mode, SwitchData *data) { + if (auto notificationData = dynamic_cast(data)) { + notificationsModel->updateData(notificationData); + } + else { + app::manager::Controller::requestNotifications(application); + } + bottomBar->setActive(BottomBar::Side::RIGHT, false); bottomBar->setText(BottomBar::Side::CENTER, utils::translate("app_desktop_unlock")); bottomBar->setActive(BottomBar::Side::LEFT, false); application->bus.sendUnicast(std::make_shared(), service::name::service_time); - - // To be added - // buildNotifications(app); } bool PhoneLockedWindow::processLongReleaseEvent(const InputEvent &inputEvent) diff --git a/module-apps/popups/lock-popups/PhoneLockedWindow.hpp b/module-apps/popups/lock-popups/PhoneLockedWindow.hpp index ba08b31c6caf24d86764c20b5acc35bb402a488c..624cbfd4336a478c22c5caa5dbe19f1f1d999fd9 100644 --- a/module-apps/popups/lock-popups/PhoneLockedWindow.hpp +++ b/module-apps/popups/lock-popups/PhoneLockedWindow.hpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include namespace app { @@ -17,8 +19,10 @@ namespace gui class PhoneLockedWindow : public AppWindow { protected: - gui::Label *time = nullptr; - gui::Label *dayText = nullptr; + gui::Label *time = nullptr; + gui::Label *dayText = nullptr; + gui::ListView *notificationsList = nullptr; + std::shared_ptr notificationsModel = nullptr; /// Locking timer on pressing enter class LockingTimer