~aleteoryx/muditaos

bedb95eda24ce08fb008a7cd3310cd4386b3a79e — Michał Kamoń 4 years ago 4750fd2
[EGD-6337] Add desktop tethering notification

This PR adds home screen tethering notification. The notifications
allows user to disconnect tethering from desktop by focusing on
the notification and pressing `KEY_ENTER`

This PR adds also home screen notifications icons in `.png` format.
Icons shall be converted to `.vpi` and used in other tasks regarding
home screen notifications.
A art/phone/home_notifications/._Icon_ => art/phone/home_notifications/._Icon_ +0 -0
A art/phone/home_notifications/alarm_notification_icon.png => art/phone/home_notifications/alarm_notification_icon.png +0 -0
A art/phone/home_notifications/calendar_notification_icon.png => art/phone/home_notifications/calendar_notification_icon.png +0 -0
A art/phone/home_notifications/calls_notification_icon.png => art/phone/home_notifications/calls_notification_icon.png +0 -0
A art/phone/home_notifications/messages_notification_icon.png => art/phone/home_notifications/messages_notification_icon.png +0 -0
A art/phone/home_notifications/now_playing_notification_icon.png => art/phone/home_notifications/now_playing_notification_icon.png +0 -0
A art/phone/home_notifications/tethering_notification_icon.png => art/phone/home_notifications/tethering_notification_icon.png +0 -0
A image/assets/images/tethering_notification_icon.vpi => image/assets/images/tethering_notification_icon.vpi +0 -0
M module-apps/application-desktop/models/ActiveNotificationsModel.cpp => module-apps/application-desktop/models/ActiveNotificationsModel.cpp +20 -0
@@ 6,6 6,7 @@
#include <service-appmgr/Controller.hpp>
#include <application-messages/ApplicationMessages.hpp>
#include <application-call/data/CallSwitchData.hpp>
#include <SystemManager/messages/TetheringStateRequest.hpp>

using namespace gui;



@@ 98,3 99,22 @@ auto ActiveNotificationsModel::create(const notifications::NotSeenCallNotificati
    item->setDismissible(true);
    return item;
}

auto ActiveNotificationsModel::create(const notifications::TetheringNotification *notification)
    -> NotificationListItem *
{
    auto item               = NotificationsModel::create(notification);
    item->activatedCallback = [this]([[maybe_unused]] gui::Item &_item) {
        return parent->getApplication()->bus.sendUnicast(
            std::make_shared<sys::TetheringStateRequest>(sys::phone_modes::Tethering::Off),
            service::name::system_manager);
    };
    item->focusChangedCallback = [this](gui::Item &_item) {
        if (_item.focus) {
            setParentBottomBar({}, utils::translate("common_disconnect"), {});
            return true;
        }
        return false;
    };
    return item;
}

M module-apps/application-desktop/models/ActiveNotificationsModel.hpp => module-apps/application-desktop/models/ActiveNotificationsModel.hpp +1 -0
@@ 12,5 12,6 @@ namespace gui
        void setParentBottomBar(const UTF8 &left, const UTF8 &center, const UTF8 &right);
        auto create(const notifications::NotSeenSMSNotification *notification) -> NotificationListItem * override;
        auto create(const notifications::NotSeenCallNotification *notification) -> NotificationListItem * override;
        auto create(const notifications::TetheringNotification *notification) -> NotificationListItem * override;
    };
} // namespace gui

M module-apps/notifications/NotificationData.cpp => module-apps/notifications/NotificationData.cpp +3 -0
@@ 62,3 62,6 @@ auto NotSeenCallNotification::getValue() const noexcept -> unsigned
{
    return value;
}

TetheringNotification::TetheringNotification() : Notification(NotificationType::Tethering)
{}

M module-apps/notifications/NotificationData.hpp => module-apps/notifications/NotificationData.hpp +7 -0
@@ 15,6 15,7 @@ namespace notifications
        Unknown,
        NotSeenSms,
        NotSeenCall,
        Tethering
    };

    enum class NotificationPriority


@@ 65,4 66,10 @@ namespace notifications
        [[nodiscard]] auto getValue() const noexcept -> unsigned;
    };

    class TetheringNotification : public Notification
    {
      public:
        TetheringNotification();
    };

} // namespace notifications

M module-apps/notifications/NotificationListItem.cpp => module-apps/notifications/NotificationListItem.cpp +9 -1
@@ 86,7 86,7 @@ namespace
        {notifications::NotificationType::Unknown, "phone"},
        {notifications::NotificationType::NotSeenSms, "mail"},
        {notifications::NotificationType::NotSeenCall, "phone"},
    };
        {notifications::NotificationType::Tethering, "tethering_notification_icon"}};
} // namespace

NotificationListItem::NotificationListItem(NotificationType type) : type{type}


@@ 136,3 136,11 @@ NotificationWithEventCounter::NotificationWithEventCounter(notifications::Notifi
    box->addWidget(buildImageInactive("dot_12px_hard_alpha_W_G"));
    box->addWidget(buildNotificationCountText(indicator));
}

NotificationWithOnOffButton::NotificationWithOnOffButton(notifications::NotificationType type, gui::ButtonState state)
    : NotificationListItem(type)
{
    auto button = new ButtonOnOff(nullptr, state);
    button->setMargins(Margins(0, 0, 20, 0));
    box->addWidget(button);
}

M module-apps/notifications/NotificationListItem.hpp => module-apps/notifications/NotificationListItem.hpp +8 -0
@@ 7,6 7,7 @@
#include <BoxLayout.hpp>
#include <Text.hpp>
#include <RichTextParser.hpp>
#include <widgets/ButtonOnOff.hpp>

#include "NotificationData.hpp"



@@ 40,4 41,11 @@ namespace gui
        NotificationWithEventCounter(notifications::NotificationType type, const UTF8 &indicator);
    };

    class NotificationWithOnOffButton : public NotificationListItem
    {

      public:
        NotificationWithOnOffButton(notifications::NotificationType type, gui::ButtonState state);
    };

} // namespace gui

M module-apps/notifications/NotificationProvider.cpp => module-apps/notifications/NotificationProvider.cpp +19 -0
@@ 65,6 65,25 @@ void NotificationProvider::handle(db::NotificationMessage *msg)
    }
}

void NotificationProvider::handle(sys::phone_modes::Tethering tethering)
{
    using Tethering           = sys::phone_modes::Tethering;
    bool notificationsChanged = false;

    if (tethering == Tethering::On && notifications.count(NotificationType::Tethering) == 0) {
        notifications[NotificationType::Tethering] = std::make_shared<notifications::TetheringNotification>();
        notificationsChanged                       = true;
    }
    else if (tethering == Tethering::Off && notifications.count(NotificationType::Tethering) != 0) {
        notifications.erase(NotificationType::Tethering);
        notificationsChanged = true;
    }

    if (notificationsChanged) {
        send();
    }
}

void NotificationProvider::requestNotSeenNotifications()
{
    DBServiceAPI::GetQuery(

M module-apps/notifications/NotificationProvider.hpp => module-apps/notifications/NotificationProvider.hpp +2 -0
@@ 4,6 4,7 @@
#pragma once

#include "NotificationData.hpp"
#include <PhoneModes/Common.hpp>

namespace sys
{


@@ 31,6 32,7 @@ namespace notifications

        void handle(db::query::notifications::GetAllResult *msg);
        void handle(db::NotificationMessage *msg);
        void handle(sys::phone_modes::Tethering tethering);
        void requestNotSeenNotifications();
        void send();


M module-apps/notifications/NotificationsModel.cpp => module-apps/notifications/NotificationsModel.cpp +12 -1
@@ 74,6 74,14 @@ auto NotificationsModel::create(const notifications::NotSeenCallNotification *no
    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;
}

void NotificationsModel::updateData(app::manager::actions::NotificationsChangedParams *params)
{
    if (list == nullptr) {


@@ 86,7 94,6 @@ void NotificationsModel::updateData(app::manager::actions::NotificationsChangedP
            delete item;
        }
    };

    for (const auto &notification : params->getNotifications()) {
        if (typeid(*notification) == typeid(notifications::NotSeenSMSNotification)) {
            auto sms = static_cast<const notifications::NotSeenSMSNotification *>(notification.get());


@@ 96,6 103,10 @@ void NotificationsModel::updateData(app::manager::actions::NotificationsChangedP
            auto call = static_cast<const notifications::NotSeenCallNotification *>(notification.get());
            internalData.push_back(create(call));
        }
        else if (typeid(*notification) == typeid(notifications::TetheringNotification)) {
            auto tethering = static_cast<const notifications::TetheringNotification *>(notification.get());
            internalData.push_back(create(tethering));
        }
    }

    list->rebuildList(listview::RebuildType::InPlace);

M module-apps/notifications/NotificationsModel.hpp => module-apps/notifications/NotificationsModel.hpp +2 -0
@@ 27,6 27,8 @@ namespace gui
            -> NotificationListItem *;
        [[nodiscard]] virtual auto create(const notifications::NotSeenCallNotification *notification)
            -> NotificationListItem *;
        [[nodiscard]] virtual auto create(const notifications::TetheringNotification *notification)
            -> NotificationListItem *;

      public:
        [[nodiscard]] bool isEmpty() const noexcept;

M module-services/service-appmgr/model/ApplicationManager.cpp => module-services/service-appmgr/model/ApplicationManager.cpp +8 -0
@@ 279,6 279,9 @@ namespace app::manager
                ActionEntry{actions::ShowPopup, std::make_unique<gui::PhoneModePopupRequestParams>(phoneMode)});
        });

        phoneModeObserver->subscribe(
            [this](sys::phone_modes::Tethering tethering) { handleTetheringChanged(tethering); });

        connect(typeid(StartAllowedMessage), [this](sys::Message *request) {
            auto msg = static_cast<StartAllowedMessage *>(request);
            handleStart(msg);


@@ 583,6 586,11 @@ namespace app::manager
        actionsRegistry.enqueue(std::move(action));
    }

    void ApplicationManager::handleTetheringChanged(sys::phone_modes::Tethering tethering)
    {
        notificationProvider.handle(tethering);
    }

    ActionProcessStatus ApplicationManager::handleAction(ActionEntry &action)
    {
        switch (action.actionId) {

M module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp => module-services/service-appmgr/service-appmgr/model/ApplicationManager.hpp +1 -0
@@ 128,6 128,7 @@ namespace app::manager
        auto handleActionOnFocusedApp(ActionEntry &action) -> ActionProcessStatus;
        auto handlePhoneModeChangedAction(ActionEntry &action) -> ActionProcessStatus;
        void handlePhoneModeChanged(sys::phone_modes::PhoneMode phoneMode);
        void handleTetheringChanged(sys::phone_modes::Tethering tethering);
        void changePhoneMode(sys::phone_modes::PhoneMode phoneMode, const ApplicationHandle *app);
        auto handleCustomAction(ActionEntry &action) -> ActionProcessStatus;
        auto handleSwitchApplication(SwitchRequest *msg, bool closeCurrentlyFocusedApp = true) -> bool;