Dismiss notifications by swiping right

Rework notification ring buffer to have a begin-idx and a size_
internally. And add  a new interface to access the notifications by
index. The `0` index is always the latest notification.

The second new function is a `Dismiss` function to remove the
notification with a specified idx from the buffer.

Fixes: https://github.com/InfiniTimeOrg/InfiniTime/issues/176

Co-authored-by: Simon Willshire <me@simonwillshire.com>
Co-authored-by: NeroBurner <pyro4hell@gmail.com>
This commit is contained in:
Simon Willshire 2022-05-19 13:59:09 -04:00 committed by Reinhold Gschweicher
parent 955dda60c5
commit b93438302e
4 changed files with 204 additions and 106 deletions

View File

@ -1,81 +1,86 @@
#include "components/ble/NotificationManager.h" #include "components/ble/NotificationManager.h"
#include <cstring> #include <cstring>
#include <algorithm> #include <algorithm>
#include <cassert>
using namespace Pinetime::Controllers; using namespace Pinetime::Controllers;
constexpr uint8_t NotificationManager::MessageSize; constexpr uint8_t NotificationManager::MessageSize;
void NotificationManager::Push(NotificationManager::Notification&& notif) { void NotificationManager::Push(NotificationManager::Notification&& notif) {
notif.id = GetNextId();
notif.valid = true; notif.valid = true;
notifications[writeIndex] = std::move(notif);
writeIndex = (writeIndex + 1 < TotalNbNotifications) ? writeIndex + 1 : 0;
if (!empty)
readIndex = (readIndex + 1 < TotalNbNotifications) ? readIndex + 1 : 0;
else
empty = false;
newNotification = true; newNotification = true;
if (begin_idx > 0) {
--begin_idx;
} else {
begin_idx = notifications.size() - 1;
}
notifications[begin_idx] = std::move(notif);
if (size_ < notifications.size()) {
size_++;
}
} }
NotificationManager::Notification NotificationManager::GetLastNotification() { NotificationManager::Notification NotificationManager::GetLastNotification() {
NotificationManager::Notification notification = notifications[readIndex]; if (this->IsEmpty()) {
notification.index = 1;
return notification;
}
NotificationManager::Notification::Id NotificationManager::GetNextId() {
return nextId++;
}
NotificationManager::Notification NotificationManager::GetNext(NotificationManager::Notification::Id id) {
auto currentIterator = std::find_if(notifications.begin(), notifications.end(), [id](const Notification& n) {
return n.valid && n.id == id;
});
if (currentIterator == notifications.end() || currentIterator->id != id)
return Notification {};
auto& lastNotification = notifications[readIndex];
NotificationManager::Notification result;
if (currentIterator == (notifications.end() - 1))
result = *(notifications.begin());
else
result = *(currentIterator + 1);
if (result.id <= id)
return {}; return {};
}
result.index = (lastNotification.id - result.id) + 1; return this->At(0);
return result;
} }
NotificationManager::Notification NotificationManager::GetPrevious(NotificationManager::Notification::Id id) { const NotificationManager::Notification& NotificationManager::At(NotificationManager::Notification::Id idx) const {
auto currentIterator = std::find_if(notifications.begin(), notifications.end(), [id](const Notification& n) { if (idx >= notifications.size()) {
return n.valid && n.id == id; assert(false);
}); return notifications.at(begin_idx); // this should not happen
if (currentIterator == notifications.end() || currentIterator->id != id) }
return Notification {}; size_t read_idx = (begin_idx + idx) % notifications.size();
return notifications.at(read_idx);
}
auto& lastNotification = notifications[readIndex]; NotificationManager::Notification& NotificationManager::At(NotificationManager::Notification::Id idx) {
if (idx >= notifications.size()) {
assert(false);
return notifications.at(begin_idx); // this should not happen
}
size_t read_idx = (begin_idx + idx) % notifications.size();
return notifications.at(read_idx);
}
NotificationManager::Notification result; NotificationManager::Notification NotificationManager::GetNext(NotificationManager::Notification::Id idx) const {
if (idx == 0 || idx > notifications.size()) {
if (currentIterator == notifications.begin())
result = *(notifications.end() - 1);
else
result = *(currentIterator - 1);
if (result.id >= id)
return {}; return {};
}
result.index = (lastNotification.id - result.id) + 1; return this->At(idx - 1);
return result;
} }
bool NotificationManager::AreNewNotificationsAvailable() { NotificationManager::Notification NotificationManager::GetPrevious(NotificationManager::Notification::Id idx) const {
if (static_cast<size_t>(idx + 1) >= notifications.size()) {
return {};
}
return this->At(idx + 1);
}
void NotificationManager::Dismiss(NotificationManager::Notification::Id idx) {
if (this->IsEmpty())
return;
if (idx >= size_) {
assert(false);
return; // this should not happen
}
if (idx == 0) { // just remove the first element, don't need to change the other elements
notifications.at(begin_idx).valid = false;
begin_idx = (begin_idx + 1) % notifications.size();
} else {
// overwrite the specified entry by moving all later messages one index to the front
for (size_t i = idx; i < size_ - 1; ++i) {
this->At(i) = this->At(i + 1);
}
this->At(size_ - 1).valid = false;
}
--size_;
}
bool NotificationManager::AreNewNotificationsAvailable() const {
return newNotification; return newNotification;
} }
@ -84,9 +89,7 @@ bool NotificationManager::ClearNewNotificationFlag() {
} }
size_t NotificationManager::NbNotifications() const { size_t NotificationManager::NbNotifications() const {
return std::count_if(notifications.begin(), notifications.end(), [](const Notification& n) { return size_;
return n.valid;
});
} }
const char* NotificationManager::Notification::Message() const { const char* NotificationManager::Notification::Message() const {

View File

@ -26,9 +26,7 @@ namespace Pinetime {
struct Notification { struct Notification {
using Id = uint8_t; using Id = uint8_t;
Id id;
bool valid = false; bool valid = false;
uint8_t index;
uint8_t size; uint8_t size;
std::array<char, MessageSize + 1> message; std::array<char, MessageSize + 1> message;
Categories category = Categories::Unknown; Categories category = Categories::Unknown;
@ -36,27 +34,31 @@ namespace Pinetime {
const char* Message() const; const char* Message() const;
const char* Title() const; const char* Title() const;
}; };
Notification::Id nextId {0};
void Push(Notification&& notif); void Push(Notification&& notif);
Notification GetLastNotification(); Notification GetLastNotification();
Notification GetNext(Notification::Id id); const Notification& At(Notification::Id id) const;
Notification GetPrevious(Notification::Id id); Notification& At(Notification::Id id);
Notification GetNext(Notification::Id id) const;
Notification GetPrevious(Notification::Id id) const;
bool ClearNewNotificationFlag(); bool ClearNewNotificationFlag();
bool AreNewNotificationsAvailable(); bool AreNewNotificationsAvailable() const;
void Dismiss(Notification::Id id);
static constexpr size_t MaximumMessageSize() { static constexpr size_t MaximumMessageSize() {
return MessageSize; return MessageSize;
}; };
bool IsEmpty() const {
return size_ == 0;
}
size_t NbNotifications() const; size_t NbNotifications() const;
private: private:
Notification::Id GetNextId();
static constexpr uint8_t TotalNbNotifications = 5; static constexpr uint8_t TotalNbNotifications = 5;
std::array<Notification, TotalNbNotifications> notifications; std::array<Notification, TotalNbNotifications> notifications;
uint8_t readIndex = 0; size_t begin_idx = TotalNbNotifications - 1; // index of the newest notification
uint8_t writeIndex = 0; size_t size_ = 0; // number of valid notifications in buffer
bool empty = true;
std::atomic<bool> newNotification {false}; std::atomic<bool> newNotification {false};
}; };
} }

View File

@ -3,6 +3,7 @@
#include "components/ble/MusicService.h" #include "components/ble/MusicService.h"
#include "components/ble/AlertNotificationService.h" #include "components/ble/AlertNotificationService.h"
#include "displayapp/screens/Symbols.h" #include "displayapp/screens/Symbols.h"
#include <algorithm>
using namespace Pinetime::Applications::Screens; using namespace Pinetime::Applications::Screens;
extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_extrabold_compressed;
@ -20,13 +21,14 @@ Notifications::Notifications(DisplayApp* app,
motorController {motorController}, motorController {motorController},
systemTask {systemTask}, systemTask {systemTask},
mode {mode} { mode {mode} {
notificationManager.ClearNewNotificationFlag(); notificationManager.ClearNewNotificationFlag();
auto notification = notificationManager.GetLastNotification(); auto notification = notificationManager.GetLastNotification();
currentId = 0;
if (notification.valid) { if (notification.valid) {
currentId = notification.id;
currentItem = std::make_unique<NotificationItem>(notification.Title(), currentItem = std::make_unique<NotificationItem>(notification.Title(),
notification.Message(), notification.Message(),
notification.index, 1,
notification.category, notification.category,
notificationManager.NbNotifications(), notificationManager.NbNotifications(),
mode, mode,
@ -34,14 +36,7 @@ Notifications::Notifications(DisplayApp* app,
motorController); motorController);
validDisplay = true; validDisplay = true;
} else { } else {
currentItem = std::make_unique<NotificationItem>("Notification", currentItem = std::make_unique<NotificationItem>(notification.category, alertNotificationService, motorController);
"No notification to display",
0,
notification.category,
notificationManager.NbNotifications(),
Modes::Preview,
alertNotificationService,
motorController);
} }
if (mode == Modes::Preview) { if (mode == Modes::Preview) {
@ -77,7 +72,7 @@ Notifications::~Notifications() {
void Notifications::Refresh() { void Notifications::Refresh() {
if (mode == Modes::Preview && timeoutLine != nullptr) { if (mode == Modes::Preview && timeoutLine != nullptr) {
TickType_t tick = xTaskGetTickCount(); TickType_t tick = xTaskGetTickCount();
int32_t pos = 240 - ((tick - timeoutTickCountStart) / (timeoutLength / 240)); int32_t pos = LV_HOR_RES - ((tick - timeoutTickCountStart) / (timeoutLength / LV_HOR_RES));
if (pos <= 0) { if (pos <= 0) {
running = false; running = false;
} else { } else {
@ -85,6 +80,36 @@ void Notifications::Refresh() {
lv_line_set_points(timeoutLine, timeoutLinePoints, 2); lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
} }
} }
if (currentItem != nullptr && currentItem->AnimationElapsed()) {
auto notification = notificationManager.At(currentId);
if (!notification.valid) {
notification = notificationManager.GetLastNotification();
currentId = 0;
}
if (!notification.valid) {
validDisplay = false;
}
currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
if (validDisplay) {
currentItem = std::make_unique<NotificationItem>(notification.Title(),
notification.Message(),
currentId + 1,
notification.category,
notificationManager.NbNotifications(),
mode,
alertNotificationService,
motorController);
} else {
currentItem = std::make_unique<NotificationItem>(notification.category, alertNotificationService, motorController);
currentId = 0;
}
}
running = currentItem->IsRunning() && running; running = currentItem->IsRunning() && running;
} }
@ -108,23 +133,39 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
} }
switch (event) { switch (event) {
case Pinetime::Applications::TouchEvents::SwipeRight:
if (validDisplay) {
notificationManager.Dismiss(currentId);
if (currentId > 0 && currentId == notificationManager.NbNotifications()) {
// dismissed last message (like 5/5), need to go one message down (like 4/4)
--currentId;
}
currentItem->AnimateDismiss();
return true;
}
return false;
case Pinetime::Applications::TouchEvents::SwipeDown: { case Pinetime::Applications::TouchEvents::SwipeDown: {
Controllers::NotificationManager::Notification previousNotification; Controllers::NotificationManager::Notification previousNotification;
if (validDisplay) if (validDisplay) {
previousNotification = notificationManager.GetPrevious(currentId); previousNotification = notificationManager.GetPrevious(currentId);
else if (previousNotification.valid) {
currentId = std::min(static_cast<uint8_t>(currentId + 1), static_cast<uint8_t>(notificationManager.NbNotifications() - 1));
}
} else {
previousNotification = notificationManager.GetLastNotification(); previousNotification = notificationManager.GetLastNotification();
currentId = 0;
}
if (!previousNotification.valid) if (!previousNotification.valid) {
return true; return true;
}
validDisplay = true; validDisplay = true;
currentId = previousNotification.id;
currentItem.reset(nullptr); currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
currentItem = std::make_unique<NotificationItem>(previousNotification.Title(), currentItem = std::make_unique<NotificationItem>(previousNotification.Title(),
previousNotification.Message(), previousNotification.Message(),
previousNotification.index, currentId + 1,
previousNotification.category, previousNotification.category,
notificationManager.NbNotifications(), notificationManager.NbNotifications(),
mode, mode,
@ -145,12 +186,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
} }
validDisplay = true; validDisplay = true;
currentId = nextNotification.id; if (currentId > 0)
--currentId;
currentItem.reset(nullptr); currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
currentItem = std::make_unique<NotificationItem>(nextNotification.Title(), currentItem = std::make_unique<NotificationItem>(nextNotification.Title(),
nextNotification.Message(), nextNotification.Message(),
nextNotification.index, currentId + 1,
nextNotification.category, nextNotification.category,
notificationManager.NbNotifications(), notificationManager.NbNotifications(),
mode, mode,
@ -170,6 +212,19 @@ namespace {
} }
} }
Notifications::NotificationItem::NotificationItem(Controllers::NotificationManager::Categories category,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController)
: NotificationItem("Notification",
"No notification to display",
0,
category,
0,
Modes::Preview,
alertNotificationService,
motorController) {
}
Notifications::NotificationItem::NotificationItem(const char* title, Notifications::NotificationItem::NotificationItem(const char* title,
const char* msg, const char* msg,
uint8_t notifNr, uint8_t notifNr,
@ -179,24 +234,36 @@ Notifications::NotificationItem::NotificationItem(const char* title,
Pinetime::Controllers::AlertNotificationService& alertNotificationService, Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController) Pinetime::Controllers::MotorController& motorController)
: mode {mode}, alertNotificationService {alertNotificationService}, motorController {motorController} { : mode {mode}, alertNotificationService {alertNotificationService}, motorController {motorController} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
lv_obj_set_style_local_bg_color(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38)); container = lv_cont_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10); lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES);
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5); lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK);
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0); lv_obj_set_style_local_pad_all(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_set_style_local_pad_inner(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_set_style_local_border_width(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_obj_set_pos(container1, 0, 50); subject_container = lv_cont_create(container, nullptr);
lv_obj_set_size(container1, LV_HOR_RES, 190); lv_obj_set_style_local_bg_color(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x38, 0x38, 0x38));
lv_obj_set_style_local_pad_all(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
lv_obj_set_style_local_pad_inner(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
lv_obj_set_style_local_border_width(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); lv_obj_set_pos(subject_container, 0, 50);
lv_cont_set_fit(container1, LV_FIT_NONE); lv_obj_set_size(subject_container, LV_HOR_RES, LV_VER_RES - 50);
lv_cont_set_layout(subject_container, LV_LAYOUT_COLUMN_LEFT);
lv_cont_set_fit(subject_container, LV_FIT_NONE);
lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr); lv_anim_init(&dismissAnim);
lv_anim_set_exec_cb(&dismissAnim, (lv_anim_exec_xcb_t) lv_obj_set_x);
lv_anim_set_var(&dismissAnim, container);
lv_anim_set_time(&dismissAnim, dismissAnimLength);
lv_anim_set_values(&dismissAnim, 0, LV_HOR_RES);
lv_obj_t* alert_count = lv_label_create(container, nullptr);
lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb); lv_label_set_text_fmt(alert_count, "%i/%i", notifNr, notifNb);
lv_obj_align(alert_count, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 16); lv_obj_align(alert_count, NULL, LV_ALIGN_IN_TOP_RIGHT, 0, 16);
lv_obj_t* alert_type = lv_label_create(lv_scr_act(), nullptr); lv_obj_t* alert_type = lv_label_create(container, nullptr);
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0));
if (title == nullptr) { if (title == nullptr) {
lv_label_set_text_static(alert_type, "Notification"); lv_label_set_text_static(alert_type, "Notification");
@ -217,27 +284,27 @@ Notifications::NotificationItem::NotificationItem(const char* title,
///////// /////////
switch (category) { switch (category) {
default: { default: {
lv_obj_t* alert_subject = lv_label_create(container1, nullptr); lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr);
lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0)); lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0));
lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK);
lv_obj_set_width(alert_subject, LV_HOR_RES - 20); lv_obj_set_width(alert_subject, LV_HOR_RES - 20);
lv_label_set_text(alert_subject, msg); lv_label_set_text(alert_subject, msg);
} break; } break;
case Controllers::NotificationManager::Categories::IncomingCall: { case Controllers::NotificationManager::Categories::IncomingCall: {
lv_obj_set_height(container1, 108); lv_obj_set_height(subject_container, 108);
lv_obj_t* alert_subject = lv_label_create(container1, nullptr); lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr);
lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0)); lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xff, 0xb0, 0x0));
lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK);
lv_obj_set_width(alert_subject, LV_HOR_RES - 20); lv_obj_set_width(alert_subject, LV_HOR_RES - 20);
lv_label_set_text_static(alert_subject, "Incoming call from"); lv_label_set_text_static(alert_subject, "Incoming call from");
lv_obj_t* alert_caller = lv_label_create(container1, nullptr); lv_obj_t* alert_caller = lv_label_create(subject_container, nullptr);
lv_obj_align(alert_caller, alert_subject, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0); lv_obj_align(alert_caller, alert_subject, LV_ALIGN_OUT_BOTTOM_LEFT, 0, 0);
lv_label_set_long_mode(alert_caller, LV_LABEL_LONG_BREAK); lv_label_set_long_mode(alert_caller, LV_LABEL_LONG_BREAK);
lv_obj_set_width(alert_caller, LV_HOR_RES - 20); lv_obj_set_width(alert_caller, LV_HOR_RES - 20);
lv_label_set_text(alert_caller, msg); lv_label_set_text(alert_caller, msg);
bt_accept = lv_btn_create(lv_scr_act(), nullptr); bt_accept = lv_btn_create(container, nullptr);
bt_accept->user_data = this; bt_accept->user_data = this;
lv_obj_set_event_cb(bt_accept, CallEventHandler); lv_obj_set_event_cb(bt_accept, CallEventHandler);
lv_obj_set_size(bt_accept, 76, 76); lv_obj_set_size(bt_accept, 76, 76);
@ -246,7 +313,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_label_set_text_static(label_accept, Symbols::phone); lv_label_set_text_static(label_accept, Symbols::phone);
lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0)); lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0x0, 0xb0, 0x0));
bt_reject = lv_btn_create(lv_scr_act(), nullptr); bt_reject = lv_btn_create(container, nullptr);
bt_reject->user_data = this; bt_reject->user_data = this;
lv_obj_set_event_cb(bt_reject, CallEventHandler); lv_obj_set_event_cb(bt_reject, CallEventHandler);
lv_obj_set_size(bt_reject, 76, 76); lv_obj_set_size(bt_reject, 76, 76);
@ -255,7 +322,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
lv_label_set_text_static(label_reject, Symbols::phoneSlash); lv_label_set_text_static(label_reject, Symbols::phoneSlash);
lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
bt_mute = lv_btn_create(lv_scr_act(), nullptr); bt_mute = lv_btn_create(container, nullptr);
bt_mute->user_data = this; bt_mute->user_data = this;
lv_obj_set_event_cb(bt_mute, CallEventHandler); lv_obj_set_event_cb(bt_mute, CallEventHandler);
lv_obj_set_size(bt_mute, 76, 76); lv_obj_set_size(bt_mute, 76, 76);
@ -285,6 +352,20 @@ void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_
running = false; running = false;
} }
void Notifications::NotificationItem::AnimateDismiss() {
dismissAnimTickCount = xTaskGetTickCount();
lv_anim_start(&dismissAnim);
}
bool Notifications::NotificationItem::AnimationElapsed() {
bool elapsed = dismissAnimTickCount != 0 && xTaskGetTickCount() > dismissAnimTickCount + dismissAnimLength;
if (elapsed)
dismissAnimTickCount = 0;
return elapsed;
}
Notifications::NotificationItem::~NotificationItem() { Notifications::NotificationItem::~NotificationItem() {
lv_obj_clean(lv_scr_act()); lv_obj_clean(lv_scr_act());
} }

View File

@ -33,6 +33,9 @@ namespace Pinetime {
class NotificationItem { class NotificationItem {
public: public:
NotificationItem(Controllers::NotificationManager::Categories,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController);
NotificationItem(const char* title, NotificationItem(const char* title,
const char* msg, const char* msg,
uint8_t notifNr, uint8_t notifNr,
@ -46,9 +49,12 @@ namespace Pinetime {
return running; return running;
} }
void OnCallButtonEvent(lv_obj_t*, lv_event_t event); void OnCallButtonEvent(lv_obj_t*, lv_event_t event);
void AnimateDismiss();
bool AnimationElapsed();
private: private:
lv_obj_t* container1; lv_obj_t* container;
lv_obj_t* subject_container;
lv_obj_t* bt_accept; lv_obj_t* bt_accept;
lv_obj_t* bt_mute; lv_obj_t* bt_mute;
lv_obj_t* bt_reject; lv_obj_t* bt_reject;
@ -58,6 +64,11 @@ namespace Pinetime {
Modes mode; Modes mode;
Pinetime::Controllers::AlertNotificationService& alertNotificationService; Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController; Pinetime::Controllers::MotorController& motorController;
lv_anim_t dismissAnim;
TickType_t dismissAnimTickCount;
static const TickType_t dismissAnimLength = pdMS_TO_TICKS(300);
bool running = true; bool running = true;
}; };
@ -74,6 +85,7 @@ namespace Pinetime {
lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}}; lv_point_t timeoutLinePoints[2] {{0, 1}, {239, 1}};
lv_obj_t* timeoutLine = nullptr; lv_obj_t* timeoutLine = nullptr;
TickType_t timeoutTickCountStart; TickType_t timeoutTickCountStart;
static const TickType_t timeoutLength = pdMS_TO_TICKS(7000); static const TickType_t timeoutLength = pdMS_TO_TICKS(7000);
bool interacted = true; bool interacted = true;