2020-03-28 14:05:28 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <array>
|
2020-10-20 14:57:39 -04:00
|
|
|
#include <atomic>
|
2020-11-15 09:05:51 -05:00
|
|
|
#include <cstddef>
|
|
|
|
#include <cstdint>
|
2020-03-28 14:05:28 -04:00
|
|
|
|
|
|
|
namespace Pinetime {
|
|
|
|
namespace Controllers {
|
|
|
|
class NotificationManager {
|
2021-04-24 05:00:45 -04:00
|
|
|
public:
|
2021-04-18 13:28:14 -04:00
|
|
|
enum class Categories {
|
|
|
|
Unknown,
|
|
|
|
SimpleAlert,
|
|
|
|
Email,
|
|
|
|
News,
|
|
|
|
IncomingCall,
|
|
|
|
MissedCall,
|
|
|
|
Sms,
|
|
|
|
VoiceMail,
|
|
|
|
Schedule,
|
|
|
|
HighProriotyAlert,
|
|
|
|
InstantMessage
|
|
|
|
};
|
|
|
|
static constexpr uint8_t MessageSize {100};
|
2020-03-28 14:05:28 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
struct Notification {
|
|
|
|
using Id = uint8_t;
|
2022-05-19 13:59:09 -04:00
|
|
|
using Idx = uint8_t;
|
|
|
|
Id id = 0;
|
2021-04-18 13:28:14 -04:00
|
|
|
bool valid = false;
|
|
|
|
uint8_t size;
|
|
|
|
std::array<char, MessageSize + 1> message;
|
|
|
|
Categories category = Categories::Unknown;
|
2021-04-04 06:10:47 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
const char* Message() const;
|
|
|
|
const char* Title() const;
|
|
|
|
};
|
2020-03-28 14:05:28 -04:00
|
|
|
|
2020-10-22 04:43:42 -04:00
|
|
|
void Push(Notification&& notif);
|
2022-05-19 13:59:09 -04:00
|
|
|
Notification GetLastNotification() const;
|
|
|
|
Notification Get(Notification::Id id) const;
|
|
|
|
Notification GetNext(Notification::Id id) const;
|
|
|
|
Notification GetPrevious(Notification::Id id) const;
|
|
|
|
// Return the index of the notification with the specified id, if not found return NbNotifications()
|
|
|
|
Notification::Idx IndexOf(Notification::Id id) const;
|
2020-10-20 14:57:39 -04:00
|
|
|
bool ClearNewNotificationFlag();
|
2022-05-19 13:59:09 -04:00
|
|
|
bool AreNewNotificationsAvailable() const;
|
|
|
|
void Dismiss(Notification::Id id);
|
2020-03-28 14:05:28 -04:00
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr size_t MaximumMessageSize() {
|
|
|
|
return MessageSize;
|
|
|
|
};
|
2022-05-19 13:59:09 -04:00
|
|
|
bool IsEmpty() const {
|
|
|
|
return size == 0;
|
|
|
|
}
|
2020-10-21 16:15:02 -04:00
|
|
|
size_t NbNotifications() const;
|
2020-03-28 14:05:28 -04:00
|
|
|
|
2021-04-24 05:00:45 -04:00
|
|
|
private:
|
2022-05-19 13:59:09 -04:00
|
|
|
Notification::Id nextId {0};
|
2021-04-18 13:28:14 -04:00
|
|
|
Notification::Id GetNextId();
|
2022-05-19 13:59:09 -04:00
|
|
|
const Notification& At(Notification::Idx idx) const;
|
|
|
|
Notification& At(Notification::Idx idx);
|
|
|
|
void DismissIdx(Notification::Idx idx);
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
static constexpr uint8_t TotalNbNotifications = 5;
|
|
|
|
std::array<Notification, TotalNbNotifications> notifications;
|
2022-05-19 13:59:09 -04:00
|
|
|
size_t beginIdx = TotalNbNotifications - 1; // index of the newest notification
|
|
|
|
size_t size = 0; // number of valid notifications in buffer
|
|
|
|
|
2021-04-18 13:28:14 -04:00
|
|
|
std::atomic<bool> newNotification {false};
|
2020-03-28 14:05:28 -04:00
|
|
|
};
|
|
|
|
}
|
2021-09-12 04:08:25 -04:00
|
|
|
}
|