~aleteoryx/muditaos

ref: 5fae63df3ef0389eb0ba1bfea1a85e94a211d909 muditaos/module-apps/application-desktop/models/ActiveNotificationsModel.cpp -rw-r--r-- 5.2 KiB
5fae63df — Radoslaw Wicik [EGD-6648] Fix Events Record tests 4 years 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// 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 <module-db/queries/notifications/QueryNotificationsClear.hpp>
#include <service-appmgr/Controller.hpp>
#include <application-messages/ApplicationMessages.hpp>
#include <application-call/data/CallSwitchData.hpp>
#include <SystemManager/messages/TetheringStateRequest.hpp>

using namespace gui;

void ActiveNotificationsModel::setParentBottomBar(const UTF8 &left, const UTF8 &center, const UTF8 &right)
{
    parent->setBottomBarText(left, BottomBar::Side::LEFT);
    parent->setBottomBarText(center, BottomBar::Side::CENTER);
    parent->setBottomBarText(right, BottomBar::Side::RIGHT);
}
auto ActiveNotificationsModel::create(const notifications::NotSeenSMSNotification *notification)
    -> NotificationListItem *
{
    auto item                  = NotificationsModel::create(notification);
    item->focusChangedCallback = [this](gui::Item &_item) {
        if (_item.focus) {
            setParentBottomBar({}, utils::translate("app_desktop_show"), utils::translate("app_desktop_clear"));
            return true;
        }
        return false;
    };
    item->activatedCallback = [this]([[maybe_unused]] gui::Item &_item) {
        return app::manager::Controller::sendAction(parent->getApplication(),
                                                    app::manager::actions::Launch,
                                                    std::make_unique<app::ApplicationLaunchData>(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<db::query::notifications::Clear>(NotificationsRecord::Key::Sms));
                return true;
            }
            return false;
        };
    item->setDismissible(true);
    return item;
}
auto ActiveNotificationsModel::create(const notifications::NotSeenCallNotification *notification)
    -> NotificationListItem *
{
    auto item               = NotificationsModel::create(notification);
    item->activatedCallback = [this]([[maybe_unused]] gui::Item &_item) {
        return app::manager::Controller::sendAction(parent->getApplication(), app::manager::actions::ShowCallLog);
    };

    std::function<void()> onRightFunctionalCallback = [this]() {
        DBServiceAPI::GetQuery(parent->getApplication(),
                               db::Interface::Name::Notifications,
                               std::make_unique<db::query::notifications::Clear>(NotificationsRecord::Key::Calls));
    };
    std::function<void()> onKeyLeftFunctionalCallback = nullptr;

    if (notification->hasRecord()) {
        if (const auto &record = notification->getRecord(); !record->numbers.empty()) {
            onKeyLeftFunctionalCallback = [this, number = record->numbers[0].number]() {
                app::manager::Controller::sendAction(parent->getApplication(),
                                                     app::manager::actions::Dial,
                                                     std::make_unique<app::ExecuteCallData>(number));
            };
        }
    }
    item->inputCallback = [keyRightFunctionalCb = std::move(onRightFunctionalCallback),
                           keyLeftFunctionalCb  = std::move(onKeyLeftFunctionalCallback)]([[maybe_unused]] Item &item,
                                                                                         const InputEvent &inputEvent) {
        if (inputEvent.isShortRelease()) {
            if (inputEvent.is(KeyCode::KEY_RF)) {
                keyRightFunctionalCb();
                return true;
            }
            else if (inputEvent.is(KeyCode::KEY_LF) && keyLeftFunctionalCb != nullptr) {
                keyLeftFunctionalCb();
                return true;
            }
        }
        return false;
    };

    item->focusChangedCallback = [this, canCall = notification->hasRecord()](gui::Item &_item) {
        if (_item.focus) {
            UTF8 bottomBarLeftText = canCall ? UTF8{utils::translate("common_call")} : UTF8{};
            setParentBottomBar(
                bottomBarLeftText, utils::translate("app_desktop_show"), utils::translate("app_desktop_clear"));
        }
        return true;
    };

    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;
}