~aleteoryx/muditaos

ref: 3d13f10839e218b65dc247f03a15fb5dfa87bc8b muditaos/module-apps/apps-common/notifications/NotificationData.cpp -rw-r--r-- 2.9 KiB
3d13f108 — Bartosz [MOS-668] Modify USB notifications logging 3 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "NotificationData.hpp"
#include <gsl/assert>
uint32_t notifications::Notification::priorityPool = 0;

using namespace notifications;

Notification::Notification(NotificationType type, NotificationPriority priorityType) : type{type}
{
    switch (priorityType) {
    case NotificationPriority::Next:
        if (priorityPool == highestPriority) {
            priorityPool = 0;
        }
        priority = ++priorityPool;
        break;
    case NotificationPriority::Highest:
        priority = highestPriority;
        break;
    case NotificationPriority::Lowest:
        priority = lowestPriority;
        break;
    }
}

auto Notification::getType() const noexcept -> NotificationType
{
    return type;
}

auto Notification::getPriority() const noexcept -> uint32_t
{
    return priority;
}

NotificationWithContact::NotificationWithContact(NotificationType type,
                                                 unsigned value,
                                                 std::optional<ContactRecord> record)
    : Notification(type), value{value}, record{std::move(record)}
{}

auto NotificationWithContact::hasRecord() const noexcept -> bool
{
    return record.has_value();
}

auto NotificationWithContact::getRecord() const noexcept -> const ContactRecord &
{
    Expects(hasRecord());
    return record.value();
}

auto NotificationWithContact::getValue() const noexcept -> unsigned
{
    return value;
}

NotificationWithCounter::NotificationWithCounter(NotificationType type, unsigned value)
    : Notification(type), value{value}
{}

auto NotificationWithCounter::getValue() const noexcept -> unsigned
{
    return value;
}

NotificationWithTime::NotificationWithTime(NotificationType type,
                                           NotificationPriority priorityType,
                                           std::string formattedTime)
    : Notification(type, priorityType), formattedTime(std::move(formattedTime))
{}

auto NotificationWithTime::getTime() const noexcept -> const std::string &
{
    return formattedTime;
}

NotSeenSMSNotification::NotSeenSMSNotification(unsigned value, std::optional<ContactRecord> record)
    : NotificationWithContact(NotificationType::NotSeenSms, value, std::move(record))
{}

NotSeenCallNotification::NotSeenCallNotification(unsigned value, std::optional<ContactRecord> record)
    : NotificationWithContact(NotificationType::NotSeenCall, value, std::move(record))
{}

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

AlarmSnoozeNotification::AlarmSnoozeNotification(unsigned value)
    : NotificationWithCounter(NotificationType::AlarmSnooze, value)
{}

PhoneLockNotification::PhoneLockNotification(std::string formattedTime)
    : NotificationWithTime(NotificationType::PhoneLock, NotificationPriority::Highest, std::move(formattedTime))
{}