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"
|
2021-02-23 21:18:59 +01:00
|
|
|
#include "components/ble/AlertNotificationService.h"
|
2021-01-27 13:45:06 +01:00
|
|
|
#include "Symbols.h"
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2020-10-20 20:57:39 +02:00
|
|
|
using namespace Pinetime::Applications::Screens;
|
2021-01-27 13:45:06 +01:00
|
|
|
extern lv_font_t jetbrains_mono_extrabold_compressed;
|
|
|
|
extern lv_font_t jetbrains_mono_bold_20;
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
Notifications::Notifications(DisplayApp* app,
|
|
|
|
Pinetime::Controllers::NotificationManager& notificationManager,
|
2021-01-24 17:22:39 +01:00
|
|
|
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
|
2021-04-18 19:28:14 +02:00
|
|
|
Modes mode)
|
|
|
|
: Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
|
2020-10-20 20:57:39 +02:00
|
|
|
notificationManager.ClearNewNotificationFlag();
|
|
|
|
auto notification = notificationManager.GetLastNotification();
|
2021-04-18 19:28:14 +02:00
|
|
|
if (notification.valid) {
|
2020-10-20 20:57:39 +02:00
|
|
|
currentId = notification.id;
|
2021-04-04 12:10:47 +02:00
|
|
|
currentItem = std::make_unique<NotificationItem>(notification.Title(),
|
2021-04-18 19:28:14 +02:00
|
|
|
notification.Message(),
|
|
|
|
notification.index,
|
|
|
|
notification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService);
|
2020-10-20 20:57:39 +02:00
|
|
|
validDisplay = true;
|
|
|
|
} else {
|
2021-04-09 20:50:09 +02:00
|
|
|
currentItem = std::make_unique<NotificationItem>("Notification",
|
2021-04-18 19:28:14 +02:00
|
|
|
"No notification to display",
|
|
|
|
0,
|
|
|
|
notification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
Modes::Preview,
|
|
|
|
alertNotificationService);
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (mode == Modes::Preview) {
|
2020-10-20 20:57:39 +02:00
|
|
|
|
|
|
|
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
|
|
|
|
|
2021-01-28 18:13:28 +01:00
|
|
|
lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
|
|
|
|
lv_obj_set_style_local_line_color(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_WHITE);
|
|
|
|
lv_obj_set_style_local_line_rounded(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, true);
|
2020-10-20 20:57:39 +02:00
|
|
|
|
|
|
|
lv_line_set_points(timeoutLine, timeoutLinePoints, 2);
|
|
|
|
timeoutTickCountStart = xTaskGetTickCount();
|
2021-04-18 19:28:14 +02:00
|
|
|
timeoutTickCountEnd = timeoutTickCountStart + (5 * 1024);
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
|
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) {
|
2021-04-18 19:28:14 +02:00
|
|
|
if (mode != Modes::Normal)
|
|
|
|
return true;
|
2021-04-04 13:42:22 +02:00
|
|
|
|
2020-10-20 20:57:39 +02:00
|
|
|
switch (event) {
|
2021-04-04 04:08:51 +02:00
|
|
|
case Pinetime::Applications::TouchEvents::SwipeDown: {
|
2020-10-20 20:57:39 +02:00
|
|
|
Controllers::NotificationManager::Notification previousNotification;
|
2021-04-18 19:28:14 +02:00
|
|
|
if (validDisplay)
|
2020-10-20 20:57:39 +02:00
|
|
|
previousNotification = notificationManager.GetPrevious(currentId);
|
|
|
|
else
|
|
|
|
previousNotification = notificationManager.GetLastNotification();
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
if (!previousNotification.valid)
|
|
|
|
return true;
|
2020-10-20 20:57:39 +02:00
|
|
|
|
|
|
|
validDisplay = true;
|
|
|
|
currentId = previousNotification.id;
|
|
|
|
currentItem.reset(nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
|
2021-04-04 12:10:47 +02:00
|
|
|
currentItem = std::make_unique<NotificationItem>(previousNotification.Title(),
|
2021-04-18 19:28:14 +02:00
|
|
|
previousNotification.Message(),
|
|
|
|
previousNotification.index,
|
|
|
|
previousNotification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService);
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
2021-04-04 04:08:51 +02:00
|
|
|
case Pinetime::Applications::TouchEvents::SwipeUp: {
|
2020-10-20 20:57:39 +02:00
|
|
|
Controllers::NotificationManager::Notification nextNotification;
|
2021-04-18 19:28:14 +02:00
|
|
|
if (validDisplay)
|
2020-10-20 20:57:39 +02:00
|
|
|
nextNotification = notificationManager.GetNext(currentId);
|
|
|
|
else
|
|
|
|
nextNotification = notificationManager.GetLastNotification();
|
|
|
|
|
2021-04-04 04:08:51 +02:00
|
|
|
if (!nextNotification.valid) {
|
|
|
|
running = false;
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-20 20:57:39 +02:00
|
|
|
|
|
|
|
validDisplay = true;
|
|
|
|
currentId = nextNotification.id;
|
|
|
|
currentItem.reset(nullptr);
|
2021-04-04 04:08:51 +02:00
|
|
|
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
|
2021-04-04 12:10:47 +02:00
|
|
|
currentItem = std::make_unique<NotificationItem>(nextNotification.Title(),
|
2021-04-18 19:28:14 +02:00
|
|
|
nextNotification.Message(),
|
|
|
|
nextNotification.index,
|
|
|
|
nextNotification.category,
|
|
|
|
notificationManager.NbNotifications(),
|
|
|
|
mode,
|
|
|
|
alertNotificationService);
|
2020-10-20 20:57:39 +02:00
|
|
|
}
|
|
|
|
return true;
|
2021-02-07 13:31:02 +01:00
|
|
|
case Pinetime::Applications::TouchEvents::LongTap: {
|
2021-04-18 19:28:14 +02:00
|
|
|
// notificationManager.ToggleVibrations();
|
2021-02-07 13:31:02 +01:00
|
|
|
return true;
|
|
|
|
}
|
2020-10-20 20:57:39 +02:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
}
|
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
namespace {
|
2021-02-23 21:18:59 +01:00
|
|
|
static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
|
2021-01-24 17:22:39 +01:00
|
|
|
item->OnAcceptIncomingCall(event);
|
|
|
|
}
|
2021-02-14 14:19:30 +01:00
|
|
|
|
2021-02-23 21:18:59 +01:00
|
|
|
static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
|
2021-01-27 13:45:06 +01:00
|
|
|
item->OnMuteIncomingCall(event);
|
|
|
|
}
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
static void RejectIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
|
|
|
|
auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
|
2021-01-24 17:22:39 +01:00
|
|
|
item->OnRejectIncomingCall(event);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-18 19:28:14 +02:00
|
|
|
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} {
|
2021-01-28 18:13:28 +01:00
|
|
|
|
|
|
|
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_hex(0x222222));
|
|
|
|
lv_obj_set_style_local_pad_all(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 10);
|
|
|
|
lv_obj_set_style_local_pad_inner(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
|
|
|
|
lv_obj_set_style_local_border_width(container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
|
|
|
|
|
|
|
|
lv_obj_set_pos(container1, 0, 50);
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_obj_set_size(container1, LV_HOR_RES, 190);
|
2020-10-18 17:35:36 +02:00
|
|
|
|
2021-01-28 18:13:28 +01:00
|
|
|
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_cont_set_fit(container1, LV_FIT_NONE);
|
2021-01-28 18:13:28 +01:00
|
|
|
|
2021-02-23 21:18:59 +01:00
|
|
|
lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr);
|
2021-01-28 18:13:28 +01:00
|
|
|
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_t* alert_type = lv_label_create(lv_scr_act(), nullptr);
|
2021-02-23 21:18:59 +01:00
|
|
|
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x888888));
|
2021-04-18 19:28:14 +02:00
|
|
|
if (title == nullptr)
|
|
|
|
title = "Notification";
|
2021-05-14 15:11:15 +02:00
|
|
|
char* pchar;
|
|
|
|
pchar = strchr(title, '\n');
|
|
|
|
while (pchar != nullptr) {
|
|
|
|
*pchar = ' ';
|
|
|
|
pchar = strchr(pchar + 1, '\n');
|
|
|
|
}
|
2021-01-28 18:13:28 +01:00
|
|
|
lv_label_set_text(alert_type, title);
|
2021-05-14 15:11:15 +02:00
|
|
|
lv_label_set_long_mode(alert_type, LV_LABEL_LONG_SROLL_CIRC);
|
|
|
|
lv_label_set_anim_speed(alert_type, 3);
|
|
|
|
lv_obj_set_width(alert_type, 180);
|
2021-04-04 12:10:47 +02:00
|
|
|
lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16);
|
2021-02-23 21:18:59 +01:00
|
|
|
|
|
|
|
/////////
|
2021-04-18 19:28:14 +02:00
|
|
|
switch (category) {
|
2021-01-24 17:22:39 +01:00
|
|
|
default: {
|
2021-02-23 21:18:59 +01:00
|
|
|
lv_obj_t* alert_subject = lv_label_create(container1, nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
|
|
|
lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_obj_set_width(alert_subject, LV_HOR_RES - 20);
|
|
|
|
lv_label_set_text(alert_subject, msg);
|
2021-04-18 19:28:14 +02:00
|
|
|
} break;
|
2021-01-24 17:22:39 +01:00
|
|
|
case Controllers::NotificationManager::Categories::IncomingCall: {
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_obj_set_height(container1, 108);
|
2021-02-23 21:18:59 +01:00
|
|
|
lv_obj_t* alert_subject = lv_label_create(container1, nullptr);
|
|
|
|
lv_obj_set_style_local_text_color(alert_subject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_ORANGE);
|
|
|
|
lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK);
|
|
|
|
lv_obj_set_width(alert_subject, LV_HOR_RES - 20);
|
|
|
|
lv_label_set_text(alert_subject, "Incoming call from");
|
|
|
|
|
|
|
|
lv_obj_t* alert_caller = lv_label_create(container1, nullptr);
|
|
|
|
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_obj_set_width(alert_caller, LV_HOR_RES - 20);
|
|
|
|
lv_label_set_text(alert_caller, msg);
|
|
|
|
|
2021-06-23 12:08:51 +02:00
|
|
|
bt_accept = lv_btn_create(lv_scr_act(), nullptr);
|
2021-01-24 17:22:39 +01:00
|
|
|
bt_accept->user_data = this;
|
|
|
|
lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_obj_set_size(bt_accept, 76, 76);
|
|
|
|
lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
|
2021-01-24 17:22:39 +01:00
|
|
|
label_accept = lv_label_create(bt_accept, nullptr);
|
2021-01-27 13:45:06 +01:00
|
|
|
lv_label_set_text(label_accept, Symbols::phone);
|
2021-04-04 14:51:22 +02:00
|
|
|
lv_obj_set_style_local_bg_color(bt_accept, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GREEN);
|
2021-01-24 17:22:39 +01:00
|
|
|
|
2021-06-23 12:08:51 +02:00
|
|
|
bt_reject = lv_btn_create(lv_scr_act(), nullptr);
|
2021-01-24 17:22:39 +01:00
|
|
|
bt_reject->user_data = this;
|
|
|
|
lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_obj_set_size(bt_reject, 76, 76);
|
|
|
|
lv_obj_align(bt_reject, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
2021-01-24 17:22:39 +01:00
|
|
|
label_reject = lv_label_create(bt_reject, nullptr);
|
2021-01-27 13:45:06 +01:00
|
|
|
lv_label_set_text(label_reject, Symbols::phoneSlash);
|
2021-04-04 14:51:22 +02:00
|
|
|
lv_obj_set_style_local_bg_color(bt_reject, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
|
2021-02-14 14:19:30 +01:00
|
|
|
|
2021-06-23 12:08:51 +02:00
|
|
|
bt_mute = lv_btn_create(lv_scr_act(), nullptr);
|
2021-01-27 13:45:06 +01:00
|
|
|
bt_mute->user_data = this;
|
|
|
|
lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
|
2021-06-23 12:08:51 +02:00
|
|
|
lv_obj_set_size(bt_mute, 76, 76);
|
|
|
|
lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
|
2021-01-27 13:45:06 +01:00
|
|
|
label_mute = lv_label_create(bt_mute, nullptr);
|
|
|
|
lv_label_set_text(label_mute, Symbols::volumMute);
|
2021-04-04 14:51:22 +02:00
|
|
|
lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
|
2021-04-18 19:28:14 +02:00
|
|
|
} break;
|
2021-01-24 17:22:39 +01:00
|
|
|
}
|
2020-10-19 21:46:41 +02:00
|
|
|
|
2021-01-28 18:13:28 +01:00
|
|
|
lv_obj_t* backgroundLabel = lv_label_create(lv_scr_act(), nullptr);
|
|
|
|
lv_label_set_long_mode(backgroundLabel, LV_LABEL_LONG_CROP);
|
|
|
|
lv_obj_set_size(backgroundLabel, 240, 240);
|
|
|
|
lv_obj_set_pos(backgroundLabel, 0, 0);
|
|
|
|
lv_label_set_text(backgroundLabel, "");
|
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) {
|
2021-04-18 19:28:14 +02:00
|
|
|
if (event != LV_EVENT_CLICKED)
|
|
|
|
return;
|
2021-01-24 17:22:39 +01:00
|
|
|
|
|
|
|
alertNotificationService.AcceptIncomingCall();
|
|
|
|
}
|
|
|
|
|
2021-01-27 13:45:06 +01:00
|
|
|
void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
|
2021-04-18 19:28:14 +02:00
|
|
|
if (event != LV_EVENT_CLICKED)
|
|
|
|
return;
|
2021-01-27 13:45:06 +01:00
|
|
|
|
|
|
|
alertNotificationService.MuteIncomingCall();
|
|
|
|
}
|
|
|
|
|
2021-01-24 17:22:39 +01:00
|
|
|
void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
|
2021-04-18 19:28:14 +02:00
|
|
|
if (event != LV_EVENT_CLICKED)
|
|
|
|
return;
|
2021-01-24 17:22:39 +01:00
|
|
|
|
|
|
|
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
|
|
|
}
|