From 04eca81a956ad84a5604096515da1ac148fe8921 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Sat, 29 Jan 2022 23:34:09 +0100 Subject: Notifications: use motorController object instead of class function We get the motoroController object, so store and use it. --- src/displayapp/screens/Notifications.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/displayapp/screens/Notifications.h') diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index 2f444c7c..f49d3b3a 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -39,7 +39,8 @@ namespace Pinetime { Controllers::NotificationManager::Categories, uint8_t notifNb, Modes mode, - Pinetime::Controllers::AlertNotificationService& alertNotificationService); + Pinetime::Controllers::AlertNotificationService& alertNotificationService, + Pinetime::Controllers::MotorController& motorController); ~NotificationItem(); bool IsRunning() const { return running; @@ -56,6 +57,7 @@ namespace Pinetime { lv_obj_t* label_reject; Modes mode; Pinetime::Controllers::AlertNotificationService& alertNotificationService; + Pinetime::Controllers::MotorController& motorController; bool running = true; }; @@ -66,6 +68,7 @@ namespace Pinetime { }; Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::AlertNotificationService& alertNotificationService; + Pinetime::Controllers::MotorController& motorController; System::SystemTask& systemTask; Modes mode = Modes::Normal; std::unique_ptr currentItem; -- cgit v1.2.3 From a29e30c1876891e504ad62fb35d3b1be76b175a4 Mon Sep 17 00:00:00 2001 From: Reinhold Gschweicher Date: Sat, 29 Jan 2022 23:30:03 +0100 Subject: Notifications: replace newlines in label-copy because of const char* title The variable `title` is defined as `const char*`, which means, that `strchr()` returns a `const char*` as well according to https://www.cplusplus.com/reference/cstring/strchr/ But in the same line the return value is assigned to a non-const `char*`, which shouldn't be allowed (error with `-pedantic`). Because the `lv_label` creates an internal copy of the title sting, just modify that one instead and replace newline in the copied string. --- src/displayapp/screens/Notifications.cpp | 19 +++++++++++-------- src/displayapp/screens/Notifications.h | 4 ---- 2 files changed, 11 insertions(+), 12 deletions(-) (limited to 'src/displayapp/screens/Notifications.h') diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp index 3a39dacf..f9afd8c7 100644 --- a/src/displayapp/screens/Notifications.cpp +++ b/src/displayapp/screens/Notifications.cpp @@ -198,15 +198,18 @@ Notifications::NotificationItem::NotificationItem(const char* title, 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)); - if (title == nullptr) - title = "Notification"; - char* pchar; - pchar = strchr(title, '\n'); - while (pchar != nullptr) { - *pchar = ' '; - pchar = strchr(pchar + 1, '\n'); + if(title == nullptr) { + lv_label_set_text_static(alert_type, "Notification"); + } else { + // copy title to label and replace newlines with spaces + lv_label_set_text(alert_type, title); + char *pchar = strchr(lv_label_get_text(alert_type), '\n'); + while (pchar != nullptr) { + *pchar = ' '; + pchar = strchr(pchar + 1, '\n'); + } + lv_label_refr_text(alert_type); } - lv_label_set_text(alert_type, title); lv_label_set_long_mode(alert_type, LV_LABEL_LONG_SROLL_CIRC); lv_obj_set_width(alert_type, 180); lv_obj_align(alert_type, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 16); diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h index f49d3b3a..74160356 100644 --- a/src/displayapp/screens/Notifications.h +++ b/src/displayapp/screens/Notifications.h @@ -62,10 +62,6 @@ namespace Pinetime { }; private: - struct NotificationData { - const char* title; - const char* text; - }; Pinetime::Controllers::NotificationManager& notificationManager; Pinetime::Controllers::AlertNotificationService& alertNotificationService; Pinetime::Controllers::MotorController& motorController; -- cgit v1.2.3