2020-10-19 21:46:41 +02:00
|
|
|
#include "Notifications.h"
|
2020-11-15 16:49:36 +01:00
|
|
|
#include <displayapp/DisplayApp.h>
|
2021-01-24 17:22:39 +01:00
|
|
|
#include "components/ble/MusicService.h"
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2020-10-20 20:57:39 +02:00
|
|
|
using namespace Pinetime::Applications::Screens;
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
Notifications::Notifications(DisplayApp *app,
|
|
|
|
Pinetime::Controllers::NotificationManager ¬ificationManager,
|
|
|
|
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
|
|
|
|
Modes mode) :
|
|
|
|
Screen(app), notificationManager{notificationManager}, alertNotificationService{alertNotificationService}, mode{mode} {
|
2020-10-20 20:57:39 +02:00
|
|
|
notificationManager.ClearNewNotificationFlag();
|
|
|
|
auto notification = notificationManager.GetLastNotification();
|
|
|
|
if(notification.valid) {
|
|
|
|
currentId = notification.id;
|
2021-01-24 17:22:39 +01:00
|
|
|
currentItem.reset(new NotificationItem("\nNotification",
|
|
|
|
notification.message.data(),
|
|
|
|
notification.index,
|
|
|
|
notification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService));
|
2020-10-20 20:57:39 +02:00
|
|
|
validDisplay = true;
|
|
|
|
} else {
|
2021-01-24 17:22:39 +01:00
|
|
|
currentItem.reset(new NotificationItem("\nNotification",
|
|
|
|
"No notification to display",
|
|
|
|
0,
|
|
|
|
notification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
Modes::Preview,
|
|
|
|
alertNotificationService));
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if(mode == Modes::Preview) {
|
|
|
|
static lv_style_t style_line;
|
|
|
|
lv_style_copy(&style_line, &lv_style_plain);
|
|
|
|
style_line.line.color = LV_COLOR_WHITE;
|
|
|
|
style_line.line.width = 3;
|
|
|
|
style_line.line.rounded = 0;
|
|
|
|
|
|
|
|
|
|
|
|
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
|
|
|
|
lv_line_set_style(timeoutLine, LV_LINE_STYLE_MAIN, &style_line);
|
|
|
|
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
|
|
|
|
timeoutTickCountStart = xTaskGetTickCount();
|
|
|
|
timeoutTickCountEnd = timeoutTickCountStart + (5*1024);
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
Notifications::~Notifications() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
|
|
|
}
|
|
|
|
|
|
|
|
bool Notifications::Refresh() {
|
2020-10-20 20:57:39 +02:00
|
|
|
if (mode == Modes::Preview) {
|
|
|
|
auto tick = xTaskGetTickCount();
|
|
|
|
int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240));
|
|
|
|
if (pos < 0)
|
|
|
|
running = false;
|
|
|
|
|
|
|
|
timeoutLinePoints[1].x = pos;
|
|
|
|
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
|
|
|
|
|
|
|
|
if (!running) {
|
|
|
|
// Start clock app when exiting this one
|
|
|
|
app->StartApp(Apps::Clock);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-18 17:35:36 +02:00
|
|
|
return running;
|
|
|
|
}
|
|
|
|
|
2020-10-19 21:46:41 +02:00
|
|
|
bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
|
2020-10-20 20:57:39 +02:00
|
|
|
switch (event) {
|
|
|
|
case Pinetime::Applications::TouchEvents::SwipeUp: {
|
|
|
|
Controllers::NotificationManager::Notification previousNotification;
|
|
|
|
if(validDisplay)
|
|
|
|
previousNotification = notificationManager.GetPrevious(currentId);
|
|
|
|
else
|
|
|
|
previousNotification = notificationManager.GetLastNotification();
|
|
|
|
|
|
|
|
if (!previousNotification.valid) return true;
|
|
|
|
|
|
|
|
validDisplay = true;
|
|
|
|
currentId = previousNotification.id;
|
|
|
|
currentItem.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
|
2021-01-24 17:22:39 +01:00
|
|
|
currentItem.reset(new NotificationItem("\nNotification",
|
|
|
|
previousNotification.message.data(),
|
|
|
|
previousNotification.index,
|
|
|
|
previousNotification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService));
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
case Pinetime::Applications::TouchEvents::SwipeDown: {
|
|
|
|
Controllers::NotificationManager::Notification nextNotification;
|
|
|
|
if(validDisplay)
|
|
|
|
nextNotification = notificationManager.GetNext(currentId);
|
|
|
|
else
|
|
|
|
nextNotification = notificationManager.GetLastNotification();
|
|
|
|
|
|
|
|
if (!nextNotification.valid) return true;
|
|
|
|
|
|
|
|
validDisplay = true;
|
|
|
|
currentId = nextNotification.id;
|
|
|
|
currentItem.reset(nullptr);
|
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
2021-01-24 17:22:39 +01:00
|
|
|
currentItem.reset(new NotificationItem("\nNotification",
|
|
|
|
nextNotification.message.data(),
|
|
|
|
nextNotification.index,
|
|
|
|
nextNotification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService));
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool Notifications::OnButtonPushed() {
|
|
|
|
running = false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
namespace {
|
|
|
|
static void AcceptIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data);
|
|
|
|
item->OnAcceptIncomingCall(event);
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
static void RejectIncomingCallEventHandler(lv_obj_t *obj, lv_event_t event) {
|
|
|
|
auto* item = static_cast<Notifications::NotificationItem *>(obj->user_data);
|
|
|
|
item->OnRejectIncomingCall(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Notifications::NotificationItem::NotificationItem(const char *title,
|
|
|
|
const char *msg,
|
|
|
|
uint8_t notifNr,
|
|
|
|
Controllers::NotificationManager::Categories category,
|
|
|
|
uint8_t notifNb,
|
|
|
|
Modes mode,
|
|
|
|
Pinetime::Controllers::AlertNotificationService& alertNotificationService)
|
|
|
|
: notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService} {
|
2020-10-20 20:57:39 +02:00
|
|
|
container1 = lv_cont_create(lv_scr_act(), nullptr);
|
2020-10-18 17:35:36 +02:00
|
|
|
static lv_style_t contStyle;
|
|
|
|
lv_style_copy(&contStyle, lv_cont_get_style(container1, LV_CONT_STYLE_MAIN));
|
|
|
|
contStyle.body.padding.inner = 20;
|
|
|
|
lv_cont_set_style(container1, LV_CONT_STYLE_MAIN, &contStyle);
|
|
|
|
lv_obj_set_width(container1, LV_HOR_RES);
|
2020-10-19 21:46:41 +02:00
|
|
|
lv_obj_set_height(container1, LV_VER_RES);
|
2020-10-18 17:35:36 +02:00
|
|
|
lv_obj_set_pos(container1, 0, 0);
|
2020-10-19 21:46:41 +02:00
|
|
|
lv_cont_set_layout(container1, LV_LAYOUT_OFF);
|
|
|
|
lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD);
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2020-10-20 20:57:39 +02:00
|
|
|
t1 = lv_label_create(container1, nullptr);
|
2020-10-18 17:35:36 +02:00
|
|
|
static lv_style_t titleStyle;
|
|
|
|
static lv_style_t textStyle;
|
2020-10-19 21:46:41 +02:00
|
|
|
static lv_style_t bottomStyle;
|
2020-10-18 17:35:36 +02:00
|
|
|
lv_style_copy(&titleStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN));
|
|
|
|
lv_style_copy(&textStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN));
|
2020-10-19 21:46:41 +02:00
|
|
|
lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN));
|
2020-10-18 17:35:36 +02:00
|
|
|
titleStyle.body.padding.inner = 5;
|
2020-10-19 21:46:41 +02:00
|
|
|
titleStyle.body.grad_color = LV_COLOR_GRAY;
|
|
|
|
titleStyle.body.main_color = LV_COLOR_GRAY;
|
2020-10-20 20:57:39 +02:00
|
|
|
titleStyle.body.radius = 20;
|
2020-10-19 21:46:41 +02:00
|
|
|
textStyle.body.border.part = LV_BORDER_NONE;
|
2020-10-20 20:57:39 +02:00
|
|
|
textStyle.body.padding.inner = 5;
|
2020-10-19 21:46:41 +02:00
|
|
|
|
|
|
|
bottomStyle.body.main_color = LV_COLOR_GREEN;
|
|
|
|
bottomStyle.body.grad_color = LV_COLOR_GREEN;
|
|
|
|
bottomStyle.body.border.part = LV_BORDER_TOP;
|
|
|
|
bottomStyle.body.border.color = LV_COLOR_RED;
|
|
|
|
|
2020-10-18 17:35:36 +02:00
|
|
|
lv_label_set_style(t1, LV_LABEL_STYLE_MAIN, &titleStyle);
|
|
|
|
lv_label_set_long_mode(t1, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_body_draw(t1, true);
|
2020-10-20 20:57:39 +02:00
|
|
|
lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right));
|
2020-10-19 21:46:41 +02:00
|
|
|
lv_label_set_text(t1, title);
|
2020-10-22 15:39:20 +02:00
|
|
|
static constexpr int16_t offscreenOffset = -20 ;
|
|
|
|
lv_obj_set_pos(t1, titleStyle.body.padding.left, offscreenOffset);
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2020-10-19 21:46:41 +02:00
|
|
|
auto titleHeight = lv_obj_get_height(t1);
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
switch(category) {
|
|
|
|
default: {
|
|
|
|
l1 = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle);
|
|
|
|
lv_obj_set_pos(l1, textStyle.body.padding.left,
|
|
|
|
titleHeight + offscreenOffset + textStyle.body.padding.bottom +
|
|
|
|
textStyle.body.padding.top);
|
|
|
|
|
|
|
|
lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_body_draw(l1, true);
|
|
|
|
lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
|
|
|
|
lv_label_set_text(l1, msg);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Controllers::NotificationManager::Categories::IncomingCall: {
|
|
|
|
l1 = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_style(l1, LV_LABEL_STYLE_MAIN, &textStyle);
|
|
|
|
lv_obj_set_pos(l1, textStyle.body.padding.left,
|
|
|
|
titleHeight + offscreenOffset + textStyle.body.padding.bottom +
|
|
|
|
textStyle.body.padding.top);
|
|
|
|
|
|
|
|
lv_label_set_long_mode(l1, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_body_draw(l1, true);
|
|
|
|
lv_obj_set_width(l1, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
|
|
|
|
lv_label_set_text(l1, "Incoming call from ");
|
|
|
|
auto l1Height = lv_obj_get_height(l1);
|
|
|
|
|
|
|
|
l2 = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_style(l2, LV_LABEL_STYLE_MAIN, &textStyle);
|
|
|
|
lv_obj_set_pos(l2, textStyle.body.padding.left,
|
|
|
|
titleHeight + l1Height + offscreenOffset + (textStyle.body.padding.bottom*2) +
|
|
|
|
(textStyle.body.padding.top*2));
|
|
|
|
lv_label_set_long_mode(l2, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_body_draw(l2, true);
|
|
|
|
lv_obj_set_width(l2, LV_HOR_RES - (textStyle.body.padding.left + textStyle.body.padding.right));
|
|
|
|
lv_label_set_text(l2, msg);
|
|
|
|
|
|
|
|
bt_accept = lv_btn_create(container1, nullptr);
|
|
|
|
lv_obj_align(bt_accept, lv_scr_act(), LV_ALIGN_IN_BOTTOM_LEFT, 0, -20);
|
|
|
|
bt_accept->user_data = this;
|
|
|
|
lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
|
2020-10-19 21:46:41 +02:00
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
label_accept = lv_label_create(bt_accept, nullptr);
|
|
|
|
lv_label_set_text(label_accept, "Accept");
|
|
|
|
|
|
|
|
bt_reject = lv_btn_create(container1, nullptr);
|
|
|
|
lv_obj_align(bt_reject, lv_scr_act(), LV_ALIGN_IN_BOTTOM_RIGHT, 0, -20);
|
|
|
|
bt_reject->user_data = this;
|
|
|
|
lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
|
|
|
|
label_reject = lv_label_create(bt_reject, nullptr);
|
|
|
|
lv_label_set_text(label_reject, "Reject");
|
|
|
|
}
|
|
|
|
}
|
2020-10-19 21:46:41 +02:00
|
|
|
|
2020-10-20 20:57:39 +02:00
|
|
|
if(mode == Modes::Normal) {
|
2020-10-22 15:39:20 +02:00
|
|
|
if(notifNr < notifNb) {
|
|
|
|
bottomPlaceholder = lv_label_create(container1, nullptr);
|
|
|
|
lv_label_set_style(bottomPlaceholder, LV_LABEL_STYLE_MAIN, &titleStyle);
|
|
|
|
lv_label_set_long_mode(bottomPlaceholder, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_label_set_body_draw(bottomPlaceholder, true);
|
|
|
|
lv_obj_set_width(bottomPlaceholder, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right));
|
|
|
|
lv_label_set_text(bottomPlaceholder, " ");
|
|
|
|
lv_obj_set_pos(bottomPlaceholder, titleStyle.body.padding.left, LV_VER_RES - 5);
|
|
|
|
}
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
2020-10-19 21:46:41 +02:00
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_CLICKED) return;
|
|
|
|
|
|
|
|
alertNotificationService.AcceptIncomingCall();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
|
|
|
|
if (event != LV_EVENT_CLICKED) return;
|
|
|
|
|
|
|
|
alertNotificationService.RejectIncomingCall();
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2020-10-19 21:46:41 +02:00
|
|
|
Notifications::NotificationItem::~NotificationItem() {
|
|
|
|
lv_obj_clean(lv_scr_act());
|
2020-10-18 17:35:36 +02:00
|
|
|
}
|