From 097267d8602c5a8bd6cb2e763f8daf0d51cc327b Mon Sep 17 00:00:00 2001 From: Wojciech Rzepecki Date: Wed, 12 Jan 2022 10:00:32 +0100 Subject: [PATCH] [EGD-6824] Simplified notifications on quote wallpaper simplified home screen notifications as tiles on phone locked wallpaper --- .../application-desktop/CMakeLists.txt | 4 +- ...p => ActiveNotificationsListPresenter.cpp} | 55 +++--- ...p => ActiveNotificationsListPresenter.hpp} | 7 +- .../windows/DesktopMainWindow.cpp | 7 +- .../windows/DesktopMainWindow.hpp | 8 +- module-apps/apps-common/CMakeLists.txt | 3 + .../notifications/NotificationTilesBox.cpp | 22 +++ .../notifications/NotificationTilesBox.hpp | 22 +++ .../NotificationTilesPresenter.cpp | 79 +++++++++ .../NotificationTilesPresenter.hpp | 27 +++ .../NotificationsListPresenter.cpp | 163 ++++++++++++++++++ .../NotificationsListPresenter.hpp | 47 +++++ .../notifications/NotificationsModel.cpp | 151 +++------------- .../notifications/NotificationsModel.hpp | 32 +--- .../notifications/NotificationsPresenter.hpp | 22 +++ .../popups/lock-popups/PhoneLockedWindow.cpp | 20 ++- .../popups/lock-popups/PhoneLockedWindow.hpp | 15 +- .../phone-lock-wallpapers/WallpaperBase.hpp | 3 +- .../phone-lock-wallpapers/WallpaperClock.cpp | 14 +- .../phone-lock-wallpapers/WallpaperClock.hpp | 10 +- .../phone-lock-wallpapers/WallpaperLogo.cpp | 38 ++-- .../phone-lock-wallpapers/WallpaperLogo.hpp | 13 +- .../phone-lock-wallpapers/WallpaperQuote.cpp | 46 ++--- .../phone-lock-wallpapers/WallpaperQuote.hpp | 23 ++- .../popups/presenter/WallpaperPresenter.cpp | 99 +++++++---- .../popups/presenter/WallpaperPresenter.hpp | 28 ++- module-gui/gui/widgets/Style.hpp | 17 +- 27 files changed, 658 insertions(+), 317 deletions(-) rename module-apps/application-desktop/models/{ActiveNotificationsModel.cpp => ActiveNotificationsListPresenter.cpp} (83%) rename module-apps/application-desktop/models/{ActiveNotificationsModel.hpp => ActiveNotificationsListPresenter.hpp} (76%) create mode 100644 module-apps/apps-common/notifications/NotificationTilesBox.cpp create mode 100644 module-apps/apps-common/notifications/NotificationTilesBox.hpp create mode 100644 module-apps/apps-common/notifications/NotificationTilesPresenter.cpp create mode 100644 module-apps/apps-common/notifications/NotificationTilesPresenter.hpp create mode 100644 module-apps/apps-common/notifications/NotificationsListPresenter.cpp create mode 100644 module-apps/apps-common/notifications/NotificationsListPresenter.hpp create mode 100644 module-apps/apps-common/notifications/NotificationsPresenter.hpp diff --git a/module-apps/application-desktop/CMakeLists.txt b/module-apps/application-desktop/CMakeLists.txt index e63fc0c9b07bb1d794ad326a04e24e3668e3c427..822bb1843fdc6ab65f07f8c90e6bc37498963116 100644 --- a/module-apps/application-desktop/CMakeLists.txt +++ b/module-apps/application-desktop/CMakeLists.txt @@ -21,8 +21,8 @@ target_sources(application-desktop ApplicationDesktop.cpp data/DesktopData.hpp data/Mmi.hpp - models/ActiveNotificationsModel.cpp - models/ActiveNotificationsModel.hpp + models/ActiveNotificationsListPresenter.cpp + models/ActiveNotificationsListPresenter.hpp widgets/DBNotificationsHandler.cpp widgets/DesktopInputWidget.cpp widgets/DesktopInputWidget.hpp diff --git a/module-apps/application-desktop/models/ActiveNotificationsModel.cpp b/module-apps/application-desktop/models/ActiveNotificationsListPresenter.cpp similarity index 83% rename from module-apps/application-desktop/models/ActiveNotificationsModel.cpp rename to module-apps/application-desktop/models/ActiveNotificationsListPresenter.cpp index d78a1ba66a7107ac19e9c26689e878b8c38d8f7e..dbe1daf87d48a8c55b6eedd40714e02dd56f2b05 100644 --- a/module-apps/application-desktop/models/ActiveNotificationsModel.cpp +++ b/module-apps/application-desktop/models/ActiveNotificationsListPresenter.cpp @@ -1,7 +1,7 @@ // Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -#include "ActiveNotificationsModel.hpp" +#include "ActiveNotificationsListPresenter.hpp" #include "ApplicationDesktop.hpp" #include @@ -23,11 +23,12 @@ using namespace gui; namespace { using Notification = const notifications::NotificationWithContact *; - void setSMSFocusChangedCallback(NotificationListItem *item, ActiveNotificationsModel *model) + void setSMSFocusChangedCallback(NotificationListItem *item, ActiveNotificationsListPresenter *presenter) { - item->focusChangedCallback = [model](gui::Item &_item) { + item->focusChangedCallback = [presenter](gui::Item &_item) { if (_item.focus) { - model->setParentNavBar({}, utils::translate("app_desktop_show"), utils::translate("app_desktop_clear")); + presenter->setParentNavBar( + {}, utils::translate("app_desktop_show"), utils::translate("app_desktop_clear")); return true; } return false; @@ -96,12 +97,14 @@ namespace item->dismissCallback = [app]() { clearSMSNotifications(app); }; } - void setCallFocusChangedCallback(NotificationListItem *item, Notification provider, ActiveNotificationsModel *model) + void setCallFocusChangedCallback(NotificationListItem *item, + Notification provider, + ActiveNotificationsListPresenter *presenter) { - item->focusChangedCallback = [model, canCall = provider->hasRecord()](gui::Item &_item) { + item->focusChangedCallback = [presenter, canCall = provider->hasRecord()](gui::Item &_item) { if (_item.focus) { UTF8 navBarLeftText = canCall ? UTF8{utils::translate("common_call")} : UTF8{}; - model->setParentNavBar( + presenter->setParentNavBar( navBarLeftText, utils::translate("app_desktop_show"), utils::translate("app_desktop_clear")); } return true; @@ -172,32 +175,32 @@ namespace }; } - void setTetheringFocusChangedCallback(NotificationListItem *item, ActiveNotificationsModel *model) + void setTetheringFocusChangedCallback(NotificationListItem *item, ActiveNotificationsListPresenter *presenter) { - item->focusChangedCallback = [model](gui::Item &_item) { + item->focusChangedCallback = [presenter](gui::Item &_item) { if (_item.focus) { - model->setParentNavBar({}, utils::translate("common_disconnect"), {}); + presenter->setParentNavBar({}, utils::translate("common_disconnect"), {}); return true; } return false; }; } - void setSnoozeFocusChangedCallback(NotificationListItem *item, ActiveNotificationsModel *model) + void setSnoozeFocusChangedCallback(NotificationListItem *item, ActiveNotificationsListPresenter *presenter) { - item->focusChangedCallback = [model](gui::Item &_item) { + item->focusChangedCallback = [presenter](gui::Item &_item) { if (_item.focus) { - model->setParentNavBar({}, utils::translate("app_desktop_show"), utils::translate("common_stop")); + presenter->setParentNavBar({}, utils::translate("app_desktop_show"), utils::translate("common_stop")); } return true; }; } void setSnoozeActivatedCallback(NotificationListItem *item, - ActiveNotificationsModel *model, + ActiveNotificationsListPresenter *presenter, app::ApplicationCommon *app) { - item->activatedCallback = [model, app]([[maybe_unused]] gui::Item &_item) { + item->activatedCallback = [presenter, app]([[maybe_unused]] gui::Item &_item) { auto request = std::make_unique(); auto task = app::AsyncRequest::createFromMessage(std::move(request), service::name::service_time); auto cb = [&](auto response) { @@ -213,7 +216,7 @@ namespace std::move(result->snoozedAlarms))); return true; }; - task->execute(app, model, cb); + task->execute(app, presenter, cb); return true; }; } @@ -235,21 +238,21 @@ namespace } } // namespace -ActiveNotificationsModel::ActiveNotificationsModel(AppWindow *parent) +ActiveNotificationsListPresenter::ActiveNotificationsListPresenter(AppWindow *parent) : AsyncCallbackReceiver(parent->getApplication()), parent(parent) {} -void ActiveNotificationsModel::setParentNavBar(const UTF8 &left, const UTF8 ¢er, const UTF8 &right) +void ActiveNotificationsListPresenter::setParentNavBar(const UTF8 &left, const UTF8 ¢er, const UTF8 &right) { parent->setNavBarText(left, nav_bar::Side::Left); parent->setNavBarText(center, nav_bar::Side::Center); parent->setNavBarText(right, nav_bar::Side::Right); } -auto ActiveNotificationsModel::create(const notifications::NotSeenSMSNotification *notification) +auto ActiveNotificationsListPresenter::create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem * { - auto item = NotificationsModel::create(notification); + auto item = NotificationsListPresenter::create(notification); setSMSFocusChangedCallback(item, this); setSMSActivatedCallback(item, notification, parent->getApplication()); setSMSOnInputCallback(item, parent->getApplication()); @@ -257,10 +260,10 @@ auto ActiveNotificationsModel::create(const notifications::NotSeenSMSNotificatio item->setDismissible(true); return item; } -auto ActiveNotificationsModel::create(const notifications::NotSeenCallNotification *notification) +auto ActiveNotificationsListPresenter::create(const notifications::NotSeenCallNotification *notification) -> NotificationListItem * { - auto item = NotificationsModel::create(notification); + auto item = NotificationsListPresenter::create(notification); setCallFocusChangedCallback(item, notification, this); setCallActivatedCallback(item, parent->getApplication()); setCallOnInputCallback(item, notification, parent->getApplication()); @@ -269,19 +272,19 @@ auto ActiveNotificationsModel::create(const notifications::NotSeenCallNotificati return item; } -auto ActiveNotificationsModel::create(const notifications::TetheringNotification *notification) +auto ActiveNotificationsListPresenter::create(const notifications::TetheringNotification *notification) -> NotificationListItem * { - auto item = NotificationsModel::create(notification); + auto item = NotificationsListPresenter::create(notification); setTetheringActivatedCallback(item, parent->getApplication()); setTetheringFocusChangedCallback(item, this); return item; } -auto ActiveNotificationsModel::create(const notifications::AlarmSnoozeNotification *notification) +auto ActiveNotificationsListPresenter::create(const notifications::AlarmSnoozeNotification *notification) -> NotificationListItem * { - auto item = NotificationsModel::create(notification); + auto item = NotificationsListPresenter::create(notification); setSnoozeFocusChangedCallback(item, this); setSnoozeActivatedCallback(item, this, parent->getApplication()); setSnoozeOnInputCallback(item, parent->getApplication()); diff --git a/module-apps/application-desktop/models/ActiveNotificationsModel.hpp b/module-apps/application-desktop/models/ActiveNotificationsListPresenter.hpp similarity index 76% rename from module-apps/application-desktop/models/ActiveNotificationsModel.hpp rename to module-apps/application-desktop/models/ActiveNotificationsListPresenter.hpp index 93291d474629cf46208d07b6aeb54b087bbd7567..3503eb668f2ec3023fbda434c928f6926f76b433 100644 --- a/module-apps/application-desktop/models/ActiveNotificationsModel.hpp +++ b/module-apps/application-desktop/models/ActiveNotificationsListPresenter.hpp @@ -3,16 +3,17 @@ #pragma once -#include +#include namespace gui { - class ActiveNotificationsModel : public gui::NotificationsModel, public app::AsyncCallbackReceiver + class ActiveNotificationsListPresenter : public gui::NotificationsListPresenter, public app::AsyncCallbackReceiver { private: AppWindow *parent = nullptr; + public: - explicit ActiveNotificationsModel(AppWindow *parent); + explicit ActiveNotificationsListPresenter(AppWindow *parent); void setParentNavBar(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 df07849e814bd1990ec4155a52a2769493fa5a2d..0632ef4ec229a8c5ff41afb70a759512d93aeb0c 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.cpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationDesktop.hpp" @@ -49,7 +49,7 @@ namespace gui style::notifications::model::y, style::notifications::model::w, style::notifications::model::h, - notificationsModel, + notificationsListPresenter, listview::ScrollBarType::Fixed); notificationsList->emptyListCallback = [this]() { setFocusItem(nullptr); @@ -79,7 +79,8 @@ namespace gui DesktopMainWindow::DesktopMainWindow(app::ApplicationCommon *app) : AppWindow(app, app::window::name::desktop_main_window), - notificationsModel(std::make_shared(this)) + notificationsListPresenter(std::make_shared(this)), + notificationsModel(std::make_shared(notificationsListPresenter)) { buildInterface(); diff --git a/module-apps/application-desktop/windows/DesktopMainWindow.hpp b/module-apps/application-desktop/windows/DesktopMainWindow.hpp index ffed64ef0e71d21a06d82a95dff20ac8aeb8cf19..e76f16a1f516913d9b1ac5a5d55c1bcebeca420b 100644 --- a/module-apps/application-desktop/windows/DesktopMainWindow.hpp +++ b/module-apps/application-desktop/windows/DesktopMainWindow.hpp @@ -1,9 +1,10 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, 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 @@ -23,7 +24,8 @@ namespace gui protected: gui::ClockDateWidget *clockDate = nullptr; gui::ListView *notificationsList = nullptr; - std::shared_ptr notificationsModel = nullptr; + std::shared_ptr notificationsListPresenter; + std::shared_ptr notificationsModel; // method hides or show widgets and sets bars according to provided state void setVisibleState(); diff --git a/module-apps/apps-common/CMakeLists.txt b/module-apps/apps-common/CMakeLists.txt index 46e9f8c384f388072babde3bf6e1e9fd26dcfabf..1b073bef95a8bec436f8dbfab86b7479fe30e129 100644 --- a/module-apps/apps-common/CMakeLists.txt +++ b/module-apps/apps-common/CMakeLists.txt @@ -24,8 +24,11 @@ target_sources(apps-common notifications/NotificationListItem.cpp notifications/NotificationProvider.cpp notifications/NotificationsModel.cpp + notifications/NotificationsListPresenter.cpp + notifications/NotificationTilesPresenter.cpp notifications/NotificationsHandler.cpp notifications/NotificationsConfiguration.cpp + notifications/NotificationTilesBox.cpp notifications/policies/CallNotificationPolicy.cpp notifications/policies/SMSNotificationPolicy.cpp notifications/policies/NotificationsListPolicy.cpp diff --git a/module-apps/apps-common/notifications/NotificationTilesBox.cpp b/module-apps/apps-common/notifications/NotificationTilesBox.cpp new file mode 100644 index 0000000000000000000000000000000000000000..681d523b2f4dfca35fa9b3390a62893c2e8226bf --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationTilesBox.cpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "NotificationTilesBox.hpp" + +#include +#include +#include + +namespace gui +{ + NotificationTilesBox::NotificationTilesBox(Item *parent, + std::shared_ptr notificationsPresenter) + : HBox( + parent, 0, 0, ::style::window::default_body_width, ::style::wallpaper::notificationTiles::tileIconHeight), + notificationsPresenter(notificationsPresenter) + { + setEdges(RectangleEdge::None); + setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + notificationsPresenter->attach(this); + } +} // namespace gui diff --git a/module-apps/apps-common/notifications/NotificationTilesBox.hpp b/module-apps/apps-common/notifications/NotificationTilesBox.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a3fec538d95e9b31ad11667cd8dd38220a6df1ae --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationTilesBox.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +#include "NotificationData.hpp" +#include + +namespace gui +{ + class NotificationTilesBox : public HBox + { + public: + explicit NotificationTilesBox(Item *parent, std::shared_ptr notificationsPresenter); + + private: + std::shared_ptr notificationsPresenter; + }; + +} // namespace gui diff --git a/module-apps/apps-common/notifications/NotificationTilesPresenter.cpp b/module-apps/apps-common/notifications/NotificationTilesPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92fb49c43c49ae270f460113c92a3ea21c584d44 --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationTilesPresenter.cpp @@ -0,0 +1,79 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "NotificationTilesPresenter.hpp" +#include +#include + +using namespace gui; + +namespace +{ + constexpr auto messagesIcon = "messages_notification_icon_W_G"; + constexpr auto callsIcon = "calls_notification_icon_W_G"; + constexpr auto tetheringIcon = "tethering_notification_icon_W_G"; + constexpr auto alarmIcon = "alarm_notification_icon_W_G"; + constexpr auto lockIcon = "lock_notification_icon_W_G"; + + auto buildNotificationIcon(const UTF8 &imageName) -> gui::Image * + { + auto icon = new gui::Image(imageName); + icon->setMinimumWidth(::style::wallpaper::notificationTiles::tileIconHeight); + icon->setMargins(gui::Margins(::style::wallpaper::notificationTiles::tileIconMarigin, + 0, + ::style::wallpaper::notificationTiles::tileIconMarigin, + 0)); + return icon; + } +} // namespace + +NotificationTilesPresenter::NotificationTilesPresenter() +{} + +void NotificationTilesPresenter::attach(HBox *tilesBox) +{ + this->tilesBox = tilesBox; +} + +void NotificationTilesPresenter::updateData(app::manager::actions::NotificationsChangedParams *params, + bool callAndSMSVisibility) +{ + if (tilesBox == nullptr) { + LOG_ERROR("TilesBox not attached"); + return; + } + + tilesBox->erase(); + + for (const auto ¬ification : params->getNotifications()) { + if (typeid(*notification) == typeid(notifications::NotSeenSMSNotification) && callAndSMSVisibility) { + tilesBox->addWidget(buildNotificationIcon(messagesIcon)); + } + else if (typeid(*notification) == typeid(notifications::NotSeenCallNotification) && callAndSMSVisibility) { + tilesBox->addWidget(buildNotificationIcon(callsIcon)); + } + else if (typeid(*notification) == typeid(notifications::TetheringNotification)) { + tilesBox->addWidget(buildNotificationIcon(tetheringIcon)); + } + else if (typeid(*notification) == typeid(notifications::PhoneLockNotification)) { + tilesBox->addWidget(buildNotificationIcon(lockIcon)); + } + else if (typeid(*notification) == typeid(notifications::AlarmSnoozeNotification)) { + tilesBox->addWidget(buildNotificationIcon(alarmIcon)); + } + } + tilesBox->resizeItems(); +} + +bool NotificationTilesPresenter::hasDismissibleNotification() const noexcept +{ + return false; +} + +void NotificationTilesPresenter::dismissAll() +{} + +bool NotificationTilesPresenter::isEmpty() const noexcept +{ + return false; +} diff --git a/module-apps/apps-common/notifications/NotificationTilesPresenter.hpp b/module-apps/apps-common/notifications/NotificationTilesPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..51272e0c84a8405f71ca08f1d5744223fd1593b3 --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationTilesPresenter.hpp @@ -0,0 +1,27 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "NotificationsPresenter.hpp" + +#include + +namespace gui +{ + class NotificationTilesPresenter : public NotificationsPresenter + { + public: + NotificationTilesPresenter(); + void attach(HBox *tilesBox); + [[nodiscard]] bool isEmpty() const noexcept final; + [[nodiscard]] bool hasDismissibleNotification() const noexcept final; + + void updateData(app::manager::actions::NotificationsChangedParams *params, bool callAndSMSVisibility) final; + void dismissAll() final; + + private: + HBox *tilesBox = nullptr; + }; + +} // namespace gui diff --git a/module-apps/apps-common/notifications/NotificationsListPresenter.cpp b/module-apps/apps-common/notifications/NotificationsListPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d555090fb543f5b72b5756a16c9bc4fb741c3fe2 --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationsListPresenter.cpp @@ -0,0 +1,163 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "NotificationsListPresenter.hpp" +#include + +using namespace gui; + +namespace +{ + void setNotificationText(NotificationListItem *item, + const notifications::NotificationWithContact *notification, + const std::string &text) + { + if (notification->hasRecord()) { + const auto &record = notification->getRecord(); + item->setName(record.getFormattedName()); + } + else { + item->setName(utils::translate(text), true); + } + } +} // namespace + +NotificationsListPresenter::NotificationsListPresenter() + : app::InternalModel{}, gui::ListItemProvider{} +{} + +unsigned int NotificationsListPresenter::requestRecordsCount() +{ + return internalData.size(); +} + +gui::ListItem *NotificationsListPresenter::getItem(gui::Order order) +{ + return getRecord(order); +} + +void NotificationsListPresenter::requestRecords(uint32_t offset, uint32_t limit) +{ + setupModel(offset, limit); + list->onProviderDataUpdate(); +} + +unsigned int NotificationsListPresenter::getMinimalItemSpaceRequired() const +{ + return style::notifications::itemHeight; +} + +bool NotificationsListPresenter::hasDismissibleNotification() const noexcept +{ + for (const auto notification : internalData) { + if (notification->isDismissible()) { + return true; + } + } + return false; +} + +void NotificationsListPresenter::dismissAll() +{ + for (auto it = std::begin(internalData); it != std::end(internalData); it++) { + if (auto item = *it; item->isDismissible()) { + if (item->dismissCallback) { + item->dismissCallback(); + } + } + } +} + +bool NotificationsListPresenter::isEmpty() const noexcept +{ + return internalData.empty(); +} + +auto NotificationsListPresenter::create(const notifications::NotSeenSMSNotification *notification) + -> NotificationListItem * +{ + auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenSms, + utils::to_string(notification->getValue())); + setNotificationText(item, notification, "app_desktop_unread_messages"); + item->deleteByList = false; + return item; +} +auto NotificationsListPresenter::create(const notifications::NotSeenCallNotification *notification) + -> NotificationListItem * +{ + auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenCall, + utils::to_string(notification->getValue())); + setNotificationText(item, notification, "app_desktop_missed_calls"); + item->deleteByList = false; + return item; +} + +auto NotificationsListPresenter::create(const notifications::TetheringNotification *notification) + -> NotificationListItem * +{ + auto item = new NotificationWithOnOffButton(notifications::NotificationType::Tethering, gui::ButtonState::On); + item->setName(utils::translate("Tethering"), false); + item->deleteByList = false; + return item; +} + +auto NotificationsListPresenter::create(const notifications::AlarmSnoozeNotification *notification) + -> NotificationListItem * +{ + auto item = new NotificationWithEventCounter(notifications::NotificationType::AlarmSnooze, + utils::to_string(notification->getValue())); + item->setName(utils::translate("app_desktop_alarm_snooze"), true); + item->deleteByList = false; + return item; +} + +auto NotificationsListPresenter::create(const notifications::PhoneLockNotification *notification) + -> NotificationListItem * +{ + auto item = new NotificationListItem(notifications::NotificationType::PhoneLock); + + item->setName(utils::translate("phone_lock_notification"), true, {{"$TIME", notification->getTime()}}); + item->deleteByList = false; + return item; +} + +void NotificationsListPresenter::updateData(app::manager::actions::NotificationsChangedParams *params, + bool callAndSMSVisibility) +{ + if (list == nullptr) { + LOG_ERROR("ListView object not provided"); + } + + list->prepareRebuildCallback = [this, toRemove = std::move(internalData)] { + list->clear(); + for (auto item : toRemove) { + delete item; + } + }; + + for (const auto ¬ification : params->getNotifications()) { + if (typeid(*notification) == typeid(notifications::NotSeenSMSNotification) && callAndSMSVisibility) { + auto sms = static_cast(notification.get()); + internalData.push_back(create(sms)); + } + else if (typeid(*notification) == typeid(notifications::NotSeenCallNotification) && callAndSMSVisibility) { + auto call = static_cast(notification.get()); + internalData.push_back(create(call)); + } + else if (typeid(*notification) == typeid(notifications::TetheringNotification)) { + auto tethering = static_cast(notification.get()); + internalData.push_back(create(tethering)); + } + else if (typeid(*notification) == typeid(notifications::PhoneLockNotification)) { + auto phoneLock = static_cast(notification.get()); + internalData.push_back(create(phoneLock)); + } + else if (typeid(*notification) == typeid(notifications::AlarmSnoozeNotification)) { + auto snooze = static_cast(notification.get()); + internalData.push_back(create(snooze)); + } + } + + list->rebuildList(listview::RebuildType::InPlace); + list->prepareRebuildCallback = nullptr; +} diff --git a/module-apps/apps-common/notifications/NotificationsListPresenter.hpp b/module-apps/apps-common/notifications/NotificationsListPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..541790add73a09254959e611f3576dc103901fee --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationsListPresenter.hpp @@ -0,0 +1,47 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "NotificationsPresenter.hpp" +#include "NotificationListItem.hpp" +#include "NotificationData.hpp" +#include "ListItemProvider.hpp" + +#include +#include "InternalModel.hpp" +#include + +namespace gui +{ + class NotificationsListPresenter : public NotificationsPresenter, + public app::InternalModel, + public gui::ListItemProvider + { + [[nodiscard]] unsigned int requestRecordsCount() final; + [[nodiscard]] unsigned int getMinimalItemSpaceRequired() const final; + ListItem *getItem(Order order) final; + void requestRecords(uint32_t offset, uint32_t limit) final; + + protected: + [[nodiscard]] virtual auto create(const notifications::NotSeenSMSNotification *notification) + -> NotificationListItem *; + [[nodiscard]] virtual auto create(const notifications::NotSeenCallNotification *notification) + -> NotificationListItem *; + [[nodiscard]] virtual auto create(const notifications::TetheringNotification *notification) + -> NotificationListItem *; + [[nodiscard]] virtual auto create(const notifications::AlarmSnoozeNotification *notification) + -> NotificationListItem *; + [[nodiscard]] virtual auto create(const notifications::PhoneLockNotification *notification) + -> NotificationListItem *; + + public: + NotificationsListPresenter(); + [[nodiscard]] bool isEmpty() const noexcept final; + [[nodiscard]] bool hasDismissibleNotification() const noexcept final; + + void updateData(app::manager::actions::NotificationsChangedParams *params, bool callAndSMSVisibility) final; + void dismissAll() final; + }; + +} // namespace gui diff --git a/module-apps/apps-common/notifications/NotificationsModel.cpp b/module-apps/apps-common/notifications/NotificationsModel.cpp index 319cc603b31ed1076cd458e5dee22e29999d322c..826efefae701a01e9382dc75952ef8ebe79b2a07 100644 --- a/module-apps/apps-common/notifications/NotificationsModel.cpp +++ b/module-apps/apps-common/notifications/NotificationsModel.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "NotificationsModel.hpp" @@ -8,18 +8,6 @@ using namespace gui; namespace { - void setNotificationText(NotificationListItem *item, - const notifications::NotificationWithContact *notification, - const std::string &text) - { - if (notification->hasRecord()) { - const auto &record = notification->getRecord(); - item->setName(record.getFormattedName()); - } - else { - item->setName(utils::translate(text), true); - } - } bool hasTetheringNotification(app::manager::actions::NotificationsChangedParams *params) { @@ -40,113 +28,53 @@ namespace } } // namespace -NotificationsModel::NotificationsModel(NotificationsListPlacement listPlacement) - : app::InternalModel{}, gui::ListItemProvider{}, listPlacement{listPlacement} +NotificationsModel::NotificationsModel(std::shared_ptr notificationsPresenter, + NotificationsListPlacement listPlacement) + : notificationsPresenter{std::move(notificationsPresenter)}, listPlacement{listPlacement} {} -unsigned int NotificationsModel::requestRecordsCount() -{ - return internalData.size(); -} - -gui::ListItem *NotificationsModel::getItem(gui::Order order) -{ - return getRecord(order); -} - -void NotificationsModel::requestRecords(uint32_t offset, uint32_t limit) -{ - setupModel(offset, limit); - list->onProviderDataUpdate(); -} +NotificationsModel::NotificationsModel(NotificationsListPlacement listPlacement) : listPlacement{listPlacement} +{} -unsigned int NotificationsModel::getMinimalItemSpaceRequired() const +void NotificationsModel::attachPresenter(std::shared_ptr notificationsPresenter) { - return style::notifications::itemHeight; + this->notificationsPresenter = notificationsPresenter; } bool NotificationsModel::hasDismissibleNotification() const noexcept { - for (const auto notification : internalData) { - if (notification->isDismissible()) { - return true; - } + if (notificationsPresenter == nullptr) { + LOG_ERROR("Presenter not attached!"); + return false; } - return false; + return notificationsPresenter->hasDismissibleNotification(); } void NotificationsModel::dismissAll() { - for (auto it = std::begin(internalData); it != std::end(internalData); it++) { - if (auto item = *it; item->isDismissible()) { - if (item->dismissCallback) { - item->dismissCallback(); - } - } + if (notificationsPresenter == nullptr) { + LOG_ERROR("Presenter not attached!"); + return; } + notificationsPresenter->dismissAll(); } bool NotificationsModel::isEmpty() const noexcept { - return internalData.empty(); -} - -auto NotificationsModel::create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem * -{ - auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenSms, - utils::to_string(notification->getValue())); - setNotificationText(item, notification, "app_desktop_unread_messages"); - item->deleteByList = false; - return item; -} -auto NotificationsModel::create(const notifications::NotSeenCallNotification *notification) -> NotificationListItem * -{ - auto item = new NotificationWithEventCounter(notifications::NotificationType::NotSeenCall, - utils::to_string(notification->getValue())); - setNotificationText(item, notification, "app_desktop_missed_calls"); - item->deleteByList = false; - return item; -} - -auto NotificationsModel::create(const notifications::TetheringNotification *notification) -> NotificationListItem * -{ - auto item = new NotificationWithOnOffButton(notifications::NotificationType::Tethering, gui::ButtonState::On); - item->setName(utils::translate("Tethering"), false); - item->deleteByList = false; - return item; -} - -auto NotificationsModel::create(const notifications::AlarmSnoozeNotification *notification) -> NotificationListItem * -{ - auto item = new NotificationWithEventCounter(notifications::NotificationType::AlarmSnooze, - utils::to_string(notification->getValue())); - item->setName(utils::translate("app_desktop_alarm_snooze"), true); - item->deleteByList = false; - return item; -} - -auto NotificationsModel::create(const notifications::PhoneLockNotification *notification) -> NotificationListItem * -{ - auto item = new NotificationListItem(notifications::NotificationType::PhoneLock); - - item->setName(utils::translate("phone_lock_notification"), true, {{"$TIME", notification->getTime()}}); - item->deleteByList = false; - return item; + if (notificationsPresenter == nullptr) { + LOG_ERROR("Presenter not attached!"); + return false; + } + return notificationsPresenter->isEmpty(); } void NotificationsModel::updateData(app::manager::actions::NotificationsChangedParams *params) { - if (list == nullptr) { - LOG_ERROR("ListView object not provided"); + if (notificationsPresenter == nullptr) { + LOG_ERROR("Presenter not attached!"); + return; } - list->prepareRebuildCallback = [this, toRemove = std::move(internalData)] { - list->clear(); - for (auto item : toRemove) { - delete item; - } - }; - const auto showOnLocked = (listPlacement == NotificationsListPlacement::LockedScreen) && params->showNotificationsWhenLocked(); phoneTimeLock = hasPhoneLockTime(params); @@ -154,38 +82,9 @@ void NotificationsModel::updateData(app::manager::actions::NotificationsChangedP const auto callAndSMSVisibility = ((listPlacement == NotificationsListPlacement::Desktop) || showOnLocked) && not tetheringOn; - for (const auto ¬ification : params->getNotifications()) { - if (typeid(*notification) == typeid(notifications::NotSeenSMSNotification) && callAndSMSVisibility) { - auto sms = static_cast(notification.get()); - internalData.push_back(create(sms)); - } - else if (typeid(*notification) == typeid(notifications::NotSeenCallNotification) && callAndSMSVisibility) { - auto call = static_cast(notification.get()); - internalData.push_back(create(call)); - } - else if (typeid(*notification) == typeid(notifications::TetheringNotification)) { - auto tethering = static_cast(notification.get()); - internalData.push_back(create(tethering)); - } - else if (typeid(*notification) == typeid(notifications::PhoneLockNotification)) { - auto phoneLock = static_cast(notification.get()); - internalData.push_back(create(phoneLock)); - } - else if (typeid(*notification) == typeid(notifications::AlarmSnoozeNotification)) { - auto snooze = static_cast(notification.get()); - internalData.push_back(create(snooze)); - } - } - - list->rebuildList(listview::RebuildType::InPlace); - list->prepareRebuildCallback = nullptr; + notificationsPresenter->updateData(params, callAndSMSVisibility); } -void NotificationsModel::clearAll() -{ - list->reset(); - eraseInternalData(); -} bool NotificationsModel::isTetheringOn() const noexcept { diff --git a/module-apps/apps-common/notifications/NotificationsModel.hpp b/module-apps/apps-common/notifications/NotificationsModel.hpp index 195602afc9b2982a7edd43ac36fdf8ec1c8398da..e706ba50947e14d285a189887cd81e6db9042455 100644 --- a/module-apps/apps-common/notifications/NotificationsModel.hpp +++ b/module-apps/apps-common/notifications/NotificationsModel.hpp @@ -1,14 +1,10 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once -#include "NotificationListItem.hpp" -#include "NotificationData.hpp" -#include "ListItemProvider.hpp" - +#include "NotificationsPresenter.hpp" #include -#include "InternalModel.hpp" #include namespace gui @@ -18,30 +14,19 @@ namespace gui Desktop, LockedScreen }; - class NotificationsModel : public app::InternalModel, public gui::ListItemProvider + class NotificationsModel { - [[nodiscard]] unsigned int requestRecordsCount() final; - [[nodiscard]] unsigned int getMinimalItemSpaceRequired() const final; - ListItem *getItem(Order order) final; - void requestRecords(uint32_t offset, uint32_t limit) final; - - protected: + private: + std::shared_ptr notificationsPresenter; bool tetheringOn = false; bool phoneTimeLock = false; const NotificationsListPlacement listPlacement; - [[nodiscard]] virtual auto create(const notifications::NotSeenSMSNotification *notification) - -> NotificationListItem *; - [[nodiscard]] virtual auto create(const notifications::NotSeenCallNotification *notification) - -> NotificationListItem *; - [[nodiscard]] virtual auto create(const notifications::TetheringNotification *notification) - -> NotificationListItem *; - [[nodiscard]] virtual auto create(const notifications::AlarmSnoozeNotification *notification) - -> NotificationListItem *; - [[nodiscard]] virtual auto create(const notifications::PhoneLockNotification *notification) - -> NotificationListItem *; public: + explicit NotificationsModel(std::shared_ptr notificationsPresenter, + NotificationsListPlacement listPlacement = NotificationsListPlacement::Desktop); explicit NotificationsModel(NotificationsListPlacement listPlacement = NotificationsListPlacement::Desktop); + void attachPresenter(std::shared_ptr notificationsPresenter); [[nodiscard]] bool isEmpty() const noexcept; [[nodiscard]] bool hasDismissibleNotification() const noexcept; [[nodiscard]] bool isTetheringOn() const noexcept; @@ -49,7 +34,6 @@ namespace gui void updateData(app::manager::actions::NotificationsChangedParams *params); void dismissAll(); - void clearAll(); }; } // namespace gui diff --git a/module-apps/apps-common/notifications/NotificationsPresenter.hpp b/module-apps/apps-common/notifications/NotificationsPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..6726b3928ca6096876bc1e19318d5dc77313077a --- /dev/null +++ b/module-apps/apps-common/notifications/NotificationsPresenter.hpp @@ -0,0 +1,22 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "NotificationData.hpp" +#include + +namespace gui +{ + class NotificationsPresenter + { + public: + NotificationsPresenter() = default; + [[nodiscard]] virtual auto isEmpty() const noexcept -> bool = 0; + [[nodiscard]] virtual auto hasDismissibleNotification() const noexcept -> bool = 0; + virtual void updateData(app::manager::actions::NotificationsChangedParams *params, + bool callAndSMSVisibility) = 0; + virtual void dismissAll() = 0; + }; + +} // namespace gui diff --git a/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp b/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp index 5a25ba0ada9f8dc8947146b82a7c96355a95ffa2..527c47235184164e4cf25b5c27debcf82bf5dfe3 100644 --- a/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp +++ b/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.cpp @@ -8,20 +8,15 @@ #include #include #include +#include namespace gui { PhoneLockedWindow::PhoneLockedWindow(app::ApplicationCommon *app, const std::string &name, std::unique_ptr &&presenter) - : AppWindow(app, name), - notificationsModel(std::make_shared(NotificationsListPlacement::LockedScreen)), - clockWallpaper(std::make_shared(this, notificationsModel)), - wallpaperPresenter(std::move(presenter)) + : AppWindow(app, name), wallpaperPresenter(std::move(presenter)) { - wallpaperPresenter->attachWallpapers( - clockWallpaper, std::make_shared(app, this), std::make_shared(this)); - buildInterface(); preBuildDrawListHook = [this](std::list &cmd) { updateTime(); }; @@ -36,11 +31,12 @@ namespace gui void PhoneLockedWindow::buildInterface() { AppWindow::buildInterface(); - wallpaperPresenter->setupWallpaper(); + wallpaperPresenter->setupWallpaper(this); } void PhoneLockedWindow::onBeforeShow(ShowMode mode, SwitchData *data) { + auto notificationsModel = wallpaperPresenter->getNotificationsModel(); auto notificationData = dynamic_cast(data); if (notificationData) { notificationsModel->updateData(notificationData); @@ -54,6 +50,9 @@ namespace gui } if (notificationsModel->isPhoneTimeLock()) { + wallpaperPresenter->forceClockWallpaper(); + notificationsModel->updateData(notificationData); + if (!refreshedOnPhoneLockTimeLock) { application->refreshWindow(RefreshModes::GUI_REFRESH_DEEP); refreshedOnPhoneLockTimeLock = true; @@ -64,6 +63,9 @@ namespace gui navBar->setActive(nav_bar::Side::Right, false); } else { + if (wallpaperPresenter->switchBackWallpaper()) { + notificationsModel->updateData(notificationData); + } navBar->setActive(nav_bar::Side::Left, false); navBar->setText(nav_bar::Side::Center, utils::translate("app_desktop_unlock")); navBar->setActive(nav_bar::Side::Right, false); @@ -74,7 +76,7 @@ namespace gui bool PhoneLockedWindow::updateTime() { auto ret = AppWindow::updateTime(); - clockWallpaper->updateTime(); + wallpaperPresenter->updateTime(); return ret; } diff --git a/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.hpp b/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.hpp index c5aa95735f5ed479c310b5fa48d6782796fce43c..84b4d46025efaedf7f630f82f76e18bc1f65f5a8 100644 --- a/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.hpp +++ b/module-apps/apps-common/popups/lock-popups/PhoneLockedWindow.hpp @@ -3,10 +3,6 @@ #pragma once -#include "phone-lock-wallpapers/WallpaperClock.hpp" -#include "phone-lock-wallpapers/WallpaperQuote.hpp" -#include "phone-lock-wallpapers/WallpaperLogo.hpp" - #include #include @@ -32,21 +28,14 @@ namespace gui bool updateTime() override; - protected: - gui::ClockDateWidget *clockDate = nullptr; - gui::ListView *notificationsList = nullptr; - std::shared_ptr notificationsModel = nullptr; - bool refreshedOnPhoneLockTimeLock = false; - - bool processLongReleaseEvent(const InputEvent &inputEvent); - private: + bool processLongReleaseEvent(const InputEvent &inputEvent); static constexpr auto refreshTimerName = "PhoneLockRefreshTimer"; static constexpr auto refreshTimeout = std::chrono::hours(4); sys::TimerHandle screenRefreshTimer; - std::shared_ptr clockWallpaper; std::unique_ptr wallpaperPresenter; + bool refreshedOnPhoneLockTimeLock = false; }; } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperBase.hpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperBase.hpp index 180bfa4bc0ac887dcc2b489d103d79413ffdb1bc..71320907f8e50dad50b597600ae572d0beac28a2 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperBase.hpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperBase.hpp @@ -4,6 +4,7 @@ #pragma once #include +#include namespace gui { @@ -14,9 +15,9 @@ namespace gui public: explicit WallpaperBase(Item *parent); - virtual void build() = 0; virtual void show() = 0; virtual void hide() = 0; + virtual std::shared_ptr getNotificationsPresenter() = 0; }; } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.cpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.cpp index 1df23c46b33ce4e999caf789459e4b6d51700387..c5cb18f15d4632481cab813db87b751851bb19a9 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.cpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.cpp @@ -6,11 +6,8 @@ namespace gui { - WallpaperClock::WallpaperClock(Item *parent, std::shared_ptr notificationsModel) - : WallpaperBase(parent), notificationsModel(notificationsModel) - {} - - void WallpaperClock::build() + WallpaperClock::WallpaperClock(Item *parent) + : WallpaperBase(parent), notificationsListPresenter(std::make_shared()) { clockDate = new ClockDateWidget( parent, 0, style::window::default_vertical_pos, style::window_width, clock_date_widget::h); @@ -20,7 +17,7 @@ namespace gui style::notifications::model::y, style::notifications::model::w, style::notifications::model::h, - notificationsModel, + notificationsListPresenter, listview::ScrollBarType::None); hide(); } @@ -37,6 +34,11 @@ namespace gui notificationsList->setVisible(false); } + std::shared_ptr WallpaperClock::getNotificationsPresenter() + { + return notificationsListPresenter; + } + void WallpaperClock::updateTime() { clockDate->setTime(std::time(nullptr)); diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.hpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.hpp index e0ad7d183d9c514afd48bafb0a23b51576523873..8cf0de10a7059b46e01cb136e9d3c6a95880aa36 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.hpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperClock.hpp @@ -1,11 +1,11 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "WallpaperBase.hpp" #include -#include +#include #include namespace gui @@ -15,13 +15,13 @@ namespace gui private: gui::ClockDateWidget *clockDate = nullptr; gui::ListView *notificationsList = nullptr; - std::shared_ptr notificationsModel = nullptr; + std::shared_ptr notificationsListPresenter; public: - WallpaperClock(gui::Item *parent, std::shared_ptr notificationsModel); - void build() override; + WallpaperClock(gui::Item *parent); void show() override; void hide() override; + std::shared_ptr getNotificationsPresenter() override; void updateTime(); }; diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.cpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.cpp index 40f066d36ca267359c7d025d3baed9288939b144..4967997ed247862e00d8d28b1115a9864c4459e3 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.cpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.cpp @@ -4,36 +4,46 @@ #include "WallpaperLogo.hpp" #include #include +#include #include namespace gui { - WallpaperLogo::WallpaperLogo(Item *parent) : WallpaperBase(parent) - {} - - void WallpaperLogo::build() + WallpaperLogo::WallpaperLogo(Item *parent) + : WallpaperBase(parent), notificationsPresenter(std::make_shared()) { - logoImage = new ImageBox(parent, - 0, - style::logo::y, - ::style::window_width, - ::style::window::default_body_height - style::logo::y, - new Image("logo", ImageTypeSpecifier::W_G)); + wallpaperBox = new VBox(parent, + ::style::window::default_left_margin, + ::style::wallpaper::wallpaperBox::y, + ::style::window::default_body_width, + ::style::wallpaper::wallpaperBox::h); + wallpaperBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + wallpaperBox->setEdges(RectangleEdge::None); + + auto logoImage = new ImageBox(wallpaperBox, new Image("logo", ImageTypeSpecifier::W_G)); logoImage->setMinimumSizeToFitImage(); logoImage->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + logoImage->setMargins(Margins(0, style::logo::logoTopMarigin, 0, style::logo::logoBottomMarigin)); + + new NotificationTilesBox(wallpaperBox, notificationsPresenter); hide(); } void WallpaperLogo::show() { - logoImage->setVisible(true); - logoImage->resizeItems(); + wallpaperBox->setVisible(true); + wallpaperBox->resizeItems(); } void WallpaperLogo::hide() { - logoImage->setVisible(false); - logoImage->resizeItems(); + wallpaperBox->setVisible(false); + wallpaperBox->resizeItems(); + } + + std::shared_ptr WallpaperLogo::getNotificationsPresenter() + { + return notificationsPresenter; } } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.hpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.hpp index 03eeb79577d6b8fcd145713973e6f6d1c1a0ff8f..f2fb737366d5a9d8649aff34c47a55071f32d1b7 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.hpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperLogo.hpp @@ -1,11 +1,12 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "WallpaperBase.hpp" -#include +#include +#include namespace gui { @@ -13,20 +14,22 @@ namespace gui { namespace logo { - constexpr auto y = 163; + constexpr inline auto logoTopMarigin = 53; + constexpr inline auto logoBottomMarigin = 70; } // namespace logo } // namespace style class WallpaperLogo : public WallpaperBase { private: - ImageBox *logoImage = nullptr; + std::shared_ptr notificationsPresenter; + VBox *wallpaperBox = nullptr; public: WallpaperLogo(gui::Item *parent); - void build() override; void show() override; void hide() override; + std::shared_ptr getNotificationsPresenter() override; }; } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.cpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.cpp index 6e3018813330618de95bc43b6bb6594b2d40167e..38035198703f708706572484938e3f7bac9bcb56 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.cpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.cpp @@ -6,11 +6,12 @@ #include #include #include - +#include namespace gui { WallpaperQuote::WallpaperQuote(app::ApplicationCommon *app, Item *parent) - : WallpaperBase(parent), quotesPresenter{std::make_unique(app)} + : WallpaperBase(parent), quotesPresenter{std::make_unique(app)}, + notificationsPresenter(std::make_shared()) { quotesPresenter->setQuoteDisplayCallback([&](std::string quote, std::string author) { quoteText->setText(quote); @@ -19,26 +20,23 @@ namespace gui authorText->setText(std::string("- ") + author); authorText->setMinimumWidthToFitText(); authorText->setMinimumHeightToFitText(); - textBox->resizeItems(); + wallpaperBox->resizeItems(); }); - } - void WallpaperQuote::build() - { - textBox = new VBox(parent, - ::style::window::default_left_margin, - style::textBox::y, - ::style::window::default_body_width, - style::textBox::h); - textBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); - textBox->setEdges(RectangleEdge::None); + wallpaperBox = new VBox(parent, + ::style::window::default_left_margin, + ::style::wallpaper::wallpaperBox::y, + ::style::window::default_body_width, + ::style::wallpaper::wallpaperBox::h); + wallpaperBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + wallpaperBox->setEdges(RectangleEdge::None); - auto quoteImage = new ImageBox(textBox, new Image("quote", ImageTypeSpecifier::W_G)); + auto quoteImage = new ImageBox(wallpaperBox, new Image("quote", ImageTypeSpecifier::W_G)); quoteImage->setMinimumSizeToFitImage(); quoteImage->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); quoteImage->setMargins(Margins(0, 0, 0, 0)); - quoteText = new TextFixedSize(textBox, 0, 0, 0, 0); + quoteText = new TextFixedSize(wallpaperBox, 0, 0, 0, 0); quoteText->setMaximumSize(::style::window::default_body_width, style::text::h); quoteText->setMargins(Margins(0, style::text::topMarigin, 0, style::text::bottomMarigin)); quoteText->setFont(::style::window::font::biglight); @@ -47,25 +45,31 @@ namespace gui quoteText->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); quoteText->drawUnderline(false); - authorText = new Text(textBox, 0, 0, 0, 0); - authorText->setMargins(Margins(0, 0, 0, 0)); + authorText = new Text(wallpaperBox, 0, 0, 0, 0); + authorText->setMargins(Margins(0, 0, 0, style::text::authorBottomMarigin)); authorText->setFont(::style::window::font::small); authorText->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + new NotificationTilesBox(wallpaperBox, notificationsPresenter); + hide(); } void WallpaperQuote::show() { quotesPresenter->requestQuote(); - textBox->setVisible(true); - textBox->resizeItems(); + wallpaperBox->setVisible(true); + wallpaperBox->resizeItems(); } void WallpaperQuote::hide() { - textBox->setVisible(false); - textBox->resizeItems(); + wallpaperBox->setVisible(false); + wallpaperBox->resizeItems(); } + std::shared_ptr WallpaperQuote::getNotificationsPresenter() + { + return notificationsPresenter; + } } /* namespace gui */ diff --git a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.hpp b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.hpp index 743bd477f209a12606d36210fa85e376b6ed9408..7e101ff0e014eb4fc3aa457c6d1b366673a8826b 100644 --- a/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.hpp +++ b/module-apps/apps-common/popups/lock-popups/phone-lock-wallpapers/WallpaperQuote.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -6,23 +6,19 @@ #include "WallpaperBase.hpp" #include #include +#include namespace gui { namespace style { - namespace textBox - { - constexpr auto y = 110; - constexpr auto h = 340; - } // namespace textBox - namespace text { - constexpr auto h = 225; - constexpr auto topMarigin = 20; - constexpr auto bottomMarigin = 30; - constexpr auto interline = 12; + constexpr inline auto h = 225; + constexpr inline auto topMarigin = 20; + constexpr inline auto bottomMarigin = 30; + constexpr inline auto interline = 12; + constexpr inline auto authorBottomMarigin = 42; } // namespace text @@ -32,15 +28,16 @@ namespace gui { private: std::unique_ptr quotesPresenter; - VBox *textBox = nullptr; + std::shared_ptr notificationsPresenter; + VBox *wallpaperBox = nullptr; TextFixedSize *quoteText = nullptr; Text *authorText = nullptr; public: WallpaperQuote(app::ApplicationCommon *app, Item *parent); - void build() override; void show() override; void hide() override; + std::shared_ptr getNotificationsPresenter() override; }; } /* namespace gui */ diff --git a/module-apps/apps-common/popups/presenter/WallpaperPresenter.cpp b/module-apps/apps-common/popups/presenter/WallpaperPresenter.cpp index 16147b0167cce827d777fc33e43b1bfdf5099e50..d163123dd0082ec392f324fe36ab0f27738b0f7f 100644 --- a/module-apps/apps-common/popups/presenter/WallpaperPresenter.cpp +++ b/module-apps/apps-common/popups/presenter/WallpaperPresenter.cpp @@ -2,58 +2,91 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "WallpaperPresenter.hpp" -#include #include namespace gui { - WallpaperPresenter::WallpaperPresenter(app::ApplicationCommon *app) : AsyncCallbackReceiver(app), application(app) + WallpaperPresenter::WallpaperPresenter(app::ApplicationCommon *app) + : AsyncCallbackReceiver(app), application(app), + notificationsModel(std::make_shared(NotificationsListPlacement::LockedScreen)) {} - void WallpaperPresenter::attachWallpapers(std::shared_ptr clockWallpaper, - std::shared_ptr quoteWallpaper, - std::shared_ptr logoWallpaper) + void WallpaperPresenter::setupWallpaper(Item *parent) { - this->clockWallpaper = clockWallpaper; - this->quoteWallpaper = quoteWallpaper; - this->logoWallpaper = logoWallpaper; - } - - void WallpaperPresenter::setupWallpaper() - { - buildWallpapers(); + buildWallpapers(parent); auto request = std::make_unique(); auto task = app::AsyncRequest::createFromMessage(std::move(request), service::name::appmgr); auto cb = [&](auto response) { auto result = dynamic_cast(response); - switch (result->getWallpaperOption()) { - case WallpaperOption::Clock: - clockWallpaper->show(); - quoteWallpaper->hide(); - logoWallpaper->hide(); - break; - case WallpaperOption::Quote: - clockWallpaper->hide(); - quoteWallpaper->show(); - logoWallpaper->hide(); - break; - case WallpaperOption::Logo: - clockWallpaper->hide(); - quoteWallpaper->hide(); - logoWallpaper->show(); - break; + if (!clockWallpaperForced) { + switchWallpaper(result->getWallpaperOption()); } + selectedOption = result->getWallpaperOption(); return true; }; task->execute(application, this, cb); } - void WallpaperPresenter::buildWallpapers() + void WallpaperPresenter::switchWallpaper(WallpaperOption option) + { + switch (option) { + case WallpaperOption::Clock: + notificationsModel->attachPresenter(clockWallpaper->getNotificationsPresenter()); + clockWallpaper->show(); + quoteWallpaper->hide(); + logoWallpaper->hide(); + break; + case WallpaperOption::Quote: + notificationsModel->attachPresenter(quoteWallpaper->getNotificationsPresenter()); + clockWallpaper->hide(); + quoteWallpaper->show(); + logoWallpaper->hide(); + break; + case WallpaperOption::Logo: + notificationsModel->attachPresenter(logoWallpaper->getNotificationsPresenter()); + clockWallpaper->hide(); + quoteWallpaper->hide(); + logoWallpaper->show(); + break; + } + } + + void WallpaperPresenter::buildWallpapers(Item *parent) { - clockWallpaper->build(); - quoteWallpaper->build(); - logoWallpaper->build(); + clockWallpaper = std::make_shared(parent); + quoteWallpaper = std::make_shared(application, parent); + logoWallpaper = std::make_shared(parent); + } + + std::shared_ptr WallpaperPresenter::getNotificationsModel() + { + return notificationsModel; + } + + void WallpaperPresenter::updateTime() + { + if (clockWallpaper) { + clockWallpaper->updateTime(); + } + } + + void WallpaperPresenter::forceClockWallpaper() + { + switchWallpaper(WallpaperOption::Clock); + clockWallpaperForced = true; + } + + bool WallpaperPresenter::switchBackWallpaper() + { + if (clockWallpaperForced) { + clockWallpaperForced = false; + switchWallpaper(selectedOption); + return true; + } + else { + return false; + } } } // namespace gui diff --git a/module-apps/apps-common/popups/presenter/WallpaperPresenter.hpp b/module-apps/apps-common/popups/presenter/WallpaperPresenter.hpp index ac5d16f1f58090812345d20530dd8359b5c3808c..8f246e18b1e483f140c64f8cf144b3a0f9c61ad3 100644 --- a/module-apps/apps-common/popups/presenter/WallpaperPresenter.hpp +++ b/module-apps/apps-common/popups/presenter/WallpaperPresenter.hpp @@ -4,7 +4,11 @@ #pragma once #include -#include +#include +#include +#include +#include +#include namespace gui { @@ -12,17 +16,23 @@ namespace gui { public: WallpaperPresenter(app::ApplicationCommon *app); - void attachWallpapers(std::shared_ptr clockWallpaper, - std::shared_ptr quoteWallpaper, - std::shared_ptr logoWallpaper); - void setupWallpaper(); + void setupWallpaper(Item *parent); + std::shared_ptr getNotificationsModel(); + void updateTime(); + void forceClockWallpaper(); + /// returns true if actual switch back occured + bool switchBackWallpaper(); private: - void buildWallpapers(); + void buildWallpapers(Item *parent); + void switchWallpaper(WallpaperOption option); app::ApplicationCommon *application; - std::shared_ptr clockWallpaper = nullptr; - std::shared_ptr quoteWallpaper = nullptr; - std::shared_ptr logoWallpaper = nullptr; + std::shared_ptr notificationsModel; + std::shared_ptr clockWallpaper = nullptr; + std::shared_ptr quoteWallpaper = nullptr; + std::shared_ptr logoWallpaper = nullptr; + bool clockWallpaperForced = false; + WallpaperOption selectedOption = WallpaperOption::Clock; }; } // namespace gui diff --git a/module-gui/gui/widgets/Style.hpp b/module-gui/gui/widgets/Style.hpp index 1f5b2c05a8db37d20e184f1ad93d62ca4271c8ea..5bcad973b47063ed0f39620e693ef928028102d6 100644 --- a/module-gui/gui/widgets/Style.hpp +++ b/module-gui/gui/widgets/Style.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -311,4 +311,19 @@ namespace style } // namespace model } // namespace notifications + namespace wallpaper + { + namespace wallpaperBox + { + constexpr auto y = 110; + constexpr auto h = 534; + } // namespace wallpaperBox + + namespace notificationTiles + { + constexpr inline auto tileIconHeight = 45; + constexpr inline auto tileIconMarigin = 15; + } // namespace notificationTiles + } // namespace wallpaper + }; // namespace style