summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/Notifications.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/screens/Notifications.cpp')
-rw-r--r--src/displayapp/screens/Notifications.cpp166
1 files changed, 146 insertions, 20 deletions
diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp
index d88968f..4219bac 100644
--- a/src/displayapp/screens/Notifications.cpp
+++ b/src/displayapp/screens/Notifications.cpp
@@ -1,22 +1,42 @@
#include "Notifications.h"
#include <displayapp/DisplayApp.h>
+#include "components/ble/MusicService.h"
+#include "components/ble/AlertNotificationService.h"
+#include "Symbols.h"
using namespace Pinetime::Applications::Screens;
+extern lv_font_t jetbrains_mono_extrabold_compressed;
+extern lv_font_t jetbrains_mono_bold_20;
-Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager &notificationManager, Modes mode) :
- Screen(app), notificationManager{notificationManager}, mode{mode} {
+Notifications::Notifications(DisplayApp *app,
+ Pinetime::Controllers::NotificationManager &notificationManager,
+ Pinetime::Controllers::AlertNotificationService& alertNotificationService,
+ Modes mode) :
+ Screen(app), notificationManager{notificationManager}, alertNotificationService{alertNotificationService}, mode{mode} {
notificationManager.ClearNewNotificationFlag();
auto notification = notificationManager.GetLastNotification();
if(notification.valid) {
currentId = notification.id;
- currentItem.reset(new NotificationItem("\nNotification", notification.message.data(), notification.index, notificationManager.NbNotifications(), mode));
+ currentItem.reset(new NotificationItem("\nNotification",
+ notification.message.data(),
+ notification.index,
+ notification.category,
+ notificationManager.NbNotifications(),
+ mode,
+ alertNotificationService));
validDisplay = true;
} else {
- currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview));
+ currentItem.reset(new NotificationItem("\nNotification",
+ "No notification to display",
+ 0,
+ notification.category,
+ notificationManager.NbNotifications(),
+ Modes::Preview,
+ alertNotificationService));
}
if(mode == Modes::Preview) {
-
+
timeoutLine = lv_line_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_line_width(timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3);
@@ -67,7 +87,13 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
currentId = previousNotification.id;
currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Up);
- currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode));
+ currentItem.reset(new NotificationItem("\nNotification",
+ previousNotification.message.data(),
+ previousNotification.index,
+ previousNotification.category,
+ notificationManager.NbNotifications(),
+ mode,
+ alertNotificationService));
}
return true;
case Pinetime::Applications::TouchEvents::SwipeDown: {
@@ -83,9 +109,19 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
currentId = nextNotification.id;
currentItem.reset(nullptr);
app->SetFullRefresh(DisplayApp::FullRefreshDirections::Down);
- currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode));
+ currentItem.reset(new NotificationItem("\nNotification",
+ nextNotification.message.data(),
+ nextNotification.index,
+ nextNotification.category,
+ notificationManager.NbNotifications(),
+ mode,
+ alertNotificationService));
}
return true;
+ case Pinetime::Applications::TouchEvents::LongTap: {
+ notificationManager.ToggleVibrations();
+ return true;
+ }
default:
return false;
}
@@ -97,9 +133,31 @@ bool Notifications::OnButtonPushed() {
return true;
}
+namespace {
+ static void AcceptIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
+ auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
+ item->OnAcceptIncomingCall(event);
+ }
+
+ static void MuteIncomingCallEventHandler(lv_obj_t* obj, lv_event_t event) {
+ auto* item = static_cast<Notifications::NotificationItem*>(obj->user_data);
+ item->OnMuteIncomingCall(event);
+ }
+
+ 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, uint8_t notifNb, Modes mode)
- : notifNr{notifNr}, notifNb{notifNb}, mode{mode} {
+ 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} {
lv_obj_t* container1 = lv_cont_create(lv_scr_act(), NULL);
@@ -111,33 +169,101 @@ Notifications::NotificationItem::NotificationItem(const char *title, const char
lv_obj_set_pos(container1, 0, 50);
lv_obj_set_width(container1, 240);
lv_obj_set_height(container1, 190);
-
+
lv_cont_set_layout(container1, LV_LAYOUT_COLUMN_LEFT);
- lv_obj_t* alert_count = lv_label_create(lv_scr_act(), nullptr);
+ lv_obj_t* alert_count = lv_label_create(lv_scr_act(), 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_hex(0x888888));
+ lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x888888));
lv_label_set_text(alert_type, title);
- lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, -4);
+ lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, -4);
+
+ /////////
+ 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_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);
+ }
+ break;
+ case Controllers::NotificationManager::Categories::IncomingCall: {
+ 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);
+
+ lv_obj_t* callBtnContainer = lv_cont_create(container1, NULL);
+ lv_obj_set_width(callBtnContainer, 240);
+ lv_obj_set_height(callBtnContainer, 90);
+ lv_cont_set_layout(callBtnContainer, LV_LAYOUT_ROW_MID);
- 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);
- //lv_obj_align(alert_subject, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 50);
+ lv_obj_set_style_local_bg_color(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x222222));
+ lv_obj_set_style_local_pad_all(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
+ lv_obj_set_style_local_margin_top(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 40);
+ lv_obj_set_style_local_margin_left(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, -8);
+ lv_obj_set_style_local_pad_inner(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 5);
+ lv_obj_set_style_local_border_width(callBtnContainer, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, 0);
+
+ bt_accept = lv_btn_create(callBtnContainer, nullptr);
+ bt_accept->user_data = this;
+ lv_obj_set_event_cb(bt_accept, AcceptIncomingCallEventHandler);
+ lv_obj_set_size(bt_accept, (LV_HOR_RES / 3) - 5, 80);
+ label_accept = lv_label_create(bt_accept, nullptr);
+ lv_label_set_text(label_accept, Symbols::phone);
+
+ bt_reject = lv_btn_create(callBtnContainer, nullptr);
+ bt_reject->user_data = this;
+ lv_obj_set_event_cb(bt_reject, RejectIncomingCallEventHandler);
+ lv_obj_set_size(bt_reject, (LV_HOR_RES / 3) - 5, 80);
+ label_reject = lv_label_create(bt_reject, nullptr);
+ lv_label_set_text(label_reject, Symbols::phoneSlash);
+
+ bt_mute = lv_btn_create(callBtnContainer, nullptr);
+ bt_mute->user_data = this;
+ lv_obj_set_event_cb(bt_mute, MuteIncomingCallEventHandler);
+ lv_obj_set_size(bt_mute, (LV_HOR_RES / 3) - 5, 80);
+ label_mute = lv_label_create(bt_mute, nullptr);
+ lv_label_set_text(label_mute, Symbols::volumMute);
+ }
+ break;
+ }
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, "");
-
}
+void Notifications::NotificationItem::OnAcceptIncomingCall(lv_event_t event) {
+ if (event != LV_EVENT_CLICKED) return;
+
+ alertNotificationService.AcceptIncomingCall();
+}
+
+void Notifications::NotificationItem::OnMuteIncomingCall(lv_event_t event) {
+ if (event != LV_EVENT_CLICKED) return;
+
+ alertNotificationService.MuteIncomingCall();
+}
+
+void Notifications::NotificationItem::OnRejectIncomingCall(lv_event_t event) {
+ if (event != LV_EVENT_CLICKED) return;
+
+ alertNotificationService.RejectIncomingCall();
+}
Notifications::NotificationItem::~NotificationItem() {
lv_obj_clean(lv_scr_act());