diff options
author | Jean-François Milants <jf@codingfield.com> | 2022-09-11 14:59:49 +0200 |
---|---|---|
committer | Jean-François Milants <jf@codingfield.com> | 2022-09-11 14:59:49 +0200 |
commit | ada2c09581d2d13acfa5ce9a97671c0ec17863f1 (patch) | |
tree | 2f776adc59d0c63e403d2043cb8460e65d6c46fe /src/displayapp/screens/Notifications.cpp | |
parent | 18cff286c75f432095db4b188e0f9a8a9e2bd8e8 (diff) | |
parent | c9a5c3fa5c930a5939d3114a6c6b48570d61ca24 (diff) |
Merge branch 'develop' into infineat-external-resources
# Conflicts:
# src/displayapp/screens/Symbols.h
# src/displayapp/screens/settings/SettingWatchFace.cpp
# src/displayapp/screens/settings/SettingWatchFace.h
Diffstat (limited to 'src/displayapp/screens/Notifications.cpp')
-rw-r--r-- | src/displayapp/screens/Notifications.cpp | 189 |
1 files changed, 130 insertions, 59 deletions
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index d7fe93a0..90a010f5 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -3,6 +3,8 @@ #include "components/ble/MusicService.h" #include "components/ble/AlertNotificationService.h" #include "displayapp/screens/Symbols.h" +#include <algorithm> +#include "displayapp/InfiniTimeTheme.h" using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; @@ -20,30 +22,23 @@ Notifications::Notifications(DisplayApp* app, motorController {motorController}, systemTask {systemTask}, mode {mode} { + notificationManager.ClearNewNotificationFlag(); auto notification = notificationManager.GetLastNotification(); if (notification.valid) { currentId = notification.id; currentItem = std::make_unique<NotificationItem>(notification.Title(), notification.Message(), - notification.index, + 1, notification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); validDisplay = true; } else { - currentItem = std::make_unique<NotificationItem>("Notification", - "No notification to display", - 0, - notification.category, - notificationManager.NbNotifications(), - Modes::Preview, - alertNotificationService, - motorController); + currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController); + validDisplay = false; } - if (mode == Modes::Preview) { systemTask.PushMessage(System::Messages::DisableSleeping); if (notification.category == Controllers::NotificationManager::Categories::IncomingCall) { @@ -77,7 +72,7 @@ Notifications::~Notifications() { void Notifications::Refresh() { if (mode == Modes::Preview && timeoutLine != nullptr) { 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) { running = false; } else { @@ -85,6 +80,40 @@ void Notifications::Refresh() { lv_line_set_points(timeoutLine, timeoutLinePoints, 2); } } + + if (dismissingNotification) { + dismissingNotification = false; + auto notification = notificationManager.Get(currentId); + if (!notification.valid) { + notification = notificationManager.GetLastNotification(); + } + currentId = notification.id; + + if (!notification.valid) { + validDisplay = false; + } + + currentItem.reset(nullptr); + if (afterDismissNextMessageFromAbove) { + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); + } else { + app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); + } + + if (validDisplay) { + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + currentItem = std::make_unique<NotificationItem>(notification.Title(), + notification.Message(), + currentIdx + 1, + notification.category, + notificationManager.NbNotifications(), + alertNotificationService, + motorController); + } else { + currentItem = std::make_unique<NotificationItem>(alertNotificationService, motorController); + } + } + running = currentItem->IsRunning() && running; } @@ -108,52 +137,84 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { } switch (event) { + case Pinetime::Applications::TouchEvents::SwipeRight: + if (validDisplay) { + Controllers::NotificationManager::Notification previousNotification; + auto previousMessage = notificationManager.GetPrevious(currentId); + auto nextMessage = notificationManager.GetNext(currentId); + if (!previousMessage.valid) { + // dismissed last message (like 5/5), need to go one message down (like 4/4) + afterDismissNextMessageFromAbove = false; // show next message coming from below + } else { + afterDismissNextMessageFromAbove = true; // show next message coming from above + } + notificationManager.Dismiss(currentId); + if (previousMessage.valid) { + currentId = previousMessage.id; + } else if (nextMessage.valid) { + currentId = nextMessage.id; + } else { + // don't update id, won't be found be refresh and try to load latest message or no message box + } + currentItem.reset(nullptr); + app->SetFullRefresh(DisplayApp::FullRefreshDirections::RightAnim); + // create black transition screen to let the notification dismiss to blackness + lv_obj_t* blackBox = lv_obj_create(lv_scr_act(), nullptr); + lv_obj_set_size(blackBox, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style_local_bg_color(blackBox, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + dismissingNotification = true; + return true; + } + return false; case Pinetime::Applications::TouchEvents::SwipeDown: { Controllers::NotificationManager::Notification previousNotification; - if (validDisplay) + if (validDisplay) { previousNotification = notificationManager.GetPrevious(currentId); - else + } else { previousNotification = notificationManager.GetLastNotification(); + } - if (!previousNotification.valid) + if (!previousNotification.valid) { return true; + } - validDisplay = true; currentId = previousNotification.id; + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + validDisplay = true; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down); currentItem = std::make_unique<NotificationItem>(previousNotification.Title(), previousNotification.Message(), - previousNotification.index, + currentIdx + 1, previousNotification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); } return true; case Pinetime::Applications::TouchEvents::SwipeUp: { Controllers::NotificationManager::Notification nextNotification; - if (validDisplay) + if (validDisplay) { nextNotification = notificationManager.GetNext(currentId); - else + } else { nextNotification = notificationManager.GetLastNotification(); + } if (!nextNotification.valid) { running = false; return false; } - validDisplay = true; currentId = nextNotification.id; + Controllers::NotificationManager::Notification::Idx currentIdx = notificationManager.IndexOf(currentId); + validDisplay = true; currentItem.reset(nullptr); app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up); currentItem = std::make_unique<NotificationItem>(nextNotification.Title(), nextNotification.Message(), - nextNotification.index, + currentIdx + 1, nextNotification.category, notificationManager.NbNotifications(), - mode, alertNotificationService, motorController); } @@ -170,34 +231,49 @@ namespace { } } +Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController) + : NotificationItem("Notification", + "No notification to display", + 0, + Controllers::NotificationManager::Categories::Unknown, + 0, + alertNotificationService, + motorController) { +} + 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, Pinetime::Controllers::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)); - 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); - lv_obj_set_size(container1, LV_HOR_RES, 190); - - lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT); - lv_cont_set_fit(container1, LV_FIT_NONE); - - lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr); + : alertNotificationService {alertNotificationService}, motorController {motorController} { + container = lv_cont_create(lv_scr_act(), nullptr); + lv_obj_set_size(container, LV_HOR_RES, LV_VER_RES); + lv_obj_set_style_local_bg_color(container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); + 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); + + subject_container = lv_cont_create(container, nullptr); + lv_obj_set_style_local_bg_color(subject_container, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, Colors::bgAlt); + 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_obj_set_pos(subject_container, 0, 50); + 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(container, nullptr); 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); - lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); + 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, Colors::orange); if (title == nullptr) { lv_label_set_text_static(alert_type, "Notification"); } else { @@ -214,39 +290,34 @@ Notifications::NotificationItem::NotificationItem(const char* title, lv_obj_set_width(alert_type, 180); lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16); - ///////// + lv_obj_t* alert_subject = lv_label_create(subject_container, nullptr); + lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); + lv_obj_set_width(alert_subject, LV_HOR_RES - 20); + switch (category) { - default: { - 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_MAKE(0xff, 0xb0, 0x0)); - lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); - lv_obj_set_width(alert_subject, LV_HOR_RES - 20); + default: lv_label_set_text(alert_subject, msg); - } break; + break; case Controllers::NotificationManager::Categories::IncomingCall: { - lv_obj_set_height(container1, 108); - 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_MAKE(0xff, 0xb0, 0x0)); - lv_label_set_long_mode(alert_subject, LV_LABEL_LONG_BREAK); - lv_obj_set_width(alert_subject, LV_HOR_RES - 20); + lv_obj_set_height(subject_container, 108); 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_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); - bt_accept = lv_btn_create(lv_scr_act(), nullptr); + bt_accept = lv_btn_create(container, nullptr); bt_accept->user_data = this; lv_obj_set_event_cb(bt_accept, CallEventHandler); lv_obj_set_size(bt_accept, 76, 76); lv_obj_align(bt_accept, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0); label_accept = lv_label_create(bt_accept, nullptr); 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, Colors::highlight); - bt_reject = lv_btn_create(lv_scr_act(), nullptr); + bt_reject = lv_btn_create(container, nullptr); bt_reject->user_data = this; lv_obj_set_event_cb(bt_reject, CallEventHandler); lv_obj_set_size(bt_reject, 76, 76); @@ -255,14 +326,14 @@ Notifications::NotificationItem::NotificationItem(const char* title, 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); - bt_mute = lv_btn_create(lv_scr_act(), nullptr); + bt_mute = lv_btn_create(container, nullptr); bt_mute->user_data = this; lv_obj_set_event_cb(bt_mute, CallEventHandler); lv_obj_set_size(bt_mute, 76, 76); lv_obj_align(bt_mute, NULL, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0); label_mute = lv_label_create(bt_mute, nullptr); lv_label_set_text_static(label_mute, Symbols::volumMute); - lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); + lv_obj_set_style_local_bg_color(bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); } break; } } |