~aleteoryx/muditaos

muditaos/module-apps/apps-common/notifications/NotificationTilesPresenter.cpp -rw-r--r-- 3.0 KiB
a405cad6Aleteoryx trim readme 6 days ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md

#include "NotificationTilesPresenter.hpp"
#include <Image.hpp>
#include <Style.hpp>

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";
    constexpr auto batteryIcon   = "battery_notification_icon_W_G";

    auto buildNotificationIcon(const UTF8 &imageName) -> gui::Image *
    {
        const 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 *newTilesBox)
{
    tilesBox = newTilesBox;
}

void NotificationTilesPresenter::updateData(app::manager::actions::NotificationsChangedParams *params,
                                            bool callAndSMSVisibility)
{
    if (tilesBox == nullptr) {
        LOG_ERROR("TilesBox not attached");
        return;
    }

    tilesBox->erase();

    for (const auto &notification : 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::BatteryTooHotNotification)) {
            tilesBox->addWidget(buildNotificationIcon(batteryIcon));
        }
        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;
}