diff options
author | JF002 <JF002@users.noreply.github.com> | 2020-10-27 21:57:48 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-27 21:57:48 +0100 |
commit | cb9e8815d8bc6ce71fd8e97f3e3dae402658ce1f (patch) | |
tree | 1750edfed02f547102e468eca485caab3b08e98d /src/displayapp/screens | |
parent | c5bf09d21b2ed8e2435ec625e351594f58713924 (diff) | |
parent | 7de43a16608e599369867cb3cfa7d5776a5b6380 (diff) |
Merge pull request #108 from JF002/notification-ui
Improved notification UI
Diffstat (limited to 'src/displayapp/screens')
-rw-r--r-- | src/displayapp/screens/ApplicationList.cpp | 6 | ||||
-rw-r--r-- | src/displayapp/screens/Clock.cpp | 20 | ||||
-rw-r--r-- | src/displayapp/screens/Clock.h | 12 | ||||
-rw-r--r-- | src/displayapp/screens/NotificationIcon.cpp | 8 | ||||
-rw-r--r-- | src/displayapp/screens/NotificationIcon.h | 12 | ||||
-rw-r--r-- | src/displayapp/screens/Notifications.cpp | 174 | ||||
-rw-r--r-- | src/displayapp/screens/Notifications.h | 61 |
7 files changed, 284 insertions, 9 deletions
diff --git a/src/displayapp/screens/ApplicationList.cpp b/src/displayapp/screens/ApplicationList.cpp index 71ba91c4..7eb97188 100644 --- a/src/displayapp/screens/ApplicationList.cpp +++ b/src/displayapp/screens/ApplicationList.cpp @@ -58,9 +58,9 @@ std::unique_ptr<Screen> ApplicationList::CreateScreen2() { {{Symbols::tachometer, Apps::Gauge}, {Symbols::asterisk, Apps::Meter}, {Symbols::paintbrush, Apps::Paint}, - {Symbols::none, Apps::None}, - {Symbols::none, Apps::None}, - {Symbols::none, Apps::None} + {Symbols::info, Apps::Notifications}, + {Symbols::none, Apps::None}, + {Symbols::none, Apps::None} } }; diff --git a/src/displayapp/screens/Clock.cpp b/src/displayapp/screens/Clock.cpp index bb14d520..977321c1 100644 --- a/src/displayapp/screens/Clock.cpp +++ b/src/displayapp/screens/Clock.cpp @@ -8,6 +8,9 @@ #include "BatteryIcon.h" #include "BleIcon.h" #include "Symbols.h" +#include "components/ble/NotificationManager.h" +#include "NotificationIcon.h" + using namespace Pinetime::Applications::Screens; extern lv_font_t jetbrains_mono_extrabold_compressed; extern lv_font_t jetbrains_mono_bold_20; @@ -21,8 +24,10 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) { Clock::Clock(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, - Controllers::Ble& bleController) : Screen(app), currentDateTime{{}}, - dateTimeController{dateTimeController}, batteryController{batteryController}, bleController{bleController} { + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager) : Screen(app), currentDateTime{{}}, + dateTimeController{dateTimeController}, batteryController{batteryController}, + bleController{bleController}, notificatioManager{notificatioManager} { displayedChar[0] = 0; displayedChar[1] = 0; displayedChar[2] = 0; @@ -41,6 +46,9 @@ Clock::Clock(DisplayApp* app, lv_label_set_text(bleIcon, Symbols::bluetooth); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); + notificationIcon = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + lv_obj_align(notificationIcon, nullptr, LV_ALIGN_IN_TOP_LEFT, 10, 0); label_date = lv_label_create(lv_scr_act(), nullptr); @@ -106,6 +114,14 @@ bool Clock::Refresh() { lv_obj_align(batteryPlug, batteryIcon, LV_ALIGN_OUT_LEFT_MID, -5, 0); lv_obj_align(bleIcon, batteryPlug, LV_ALIGN_OUT_LEFT_MID, -5, 0); + notificationState = notificatioManager.AreNewNotificationsAvailable(); + if(notificationState.IsUpdated()) { + if(notificationState.Get() == true) + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(true)); + else + lv_label_set_text(notificationIcon, NotificationIcon::GetIcon(false)); + } + currentDateTime = dateTimeController.CurrentDateTime(); if(currentDateTime.IsUpdated()) { diff --git a/src/displayapp/screens/Clock.h b/src/displayapp/screens/Clock.h index 5753f6a3..58149a79 100644 --- a/src/displayapp/screens/Clock.h +++ b/src/displayapp/screens/Clock.h @@ -7,6 +7,7 @@ #include <bits/unique_ptr.h> #include <libs/lvgl/src/lv_core/lv_style.h> #include <libs/lvgl/src/lv_core/lv_obj.h> +#include "components/ble/NotificationManager.h" #include "components/battery/BatteryController.h" #include "components/ble/BleController.h" @@ -38,7 +39,8 @@ namespace Pinetime { Clock(DisplayApp* app, Controllers::DateTime& dateTimeController, Controllers::Battery& batteryController, - Controllers::Ble& bleController); + Controllers::Ble& bleController, + Controllers::NotificationManager& notificatioManager); ~Clock() override; bool Refresh() override; @@ -63,23 +65,25 @@ namespace Pinetime { DirtyValue<std::chrono::time_point<std::chrono::system_clock, std::chrono::nanoseconds>> currentDateTime; DirtyValue<uint32_t> stepCount {0}; DirtyValue<uint8_t> heartbeat {0}; - + DirtyValue<bool> notificationState {false}; lv_obj_t* label_time; lv_obj_t* label_date; lv_obj_t* backgroundLabel; - lv_obj_t * batteryIcon; - lv_obj_t * bleIcon; + lv_obj_t* batteryIcon; + lv_obj_t* bleIcon; lv_obj_t* batteryPlug; lv_obj_t* heartbeatIcon; lv_obj_t* heartbeatValue; lv_obj_t* heartbeatBpm; lv_obj_t* stepIcon; lv_obj_t* stepValue; + lv_obj_t* notificationIcon; Controllers::DateTime& dateTimeController; Controllers::Battery& batteryController; Controllers::Ble& bleController; + Controllers::NotificationManager& notificatioManager; bool running = true; diff --git a/src/displayapp/screens/NotificationIcon.cpp b/src/displayapp/screens/NotificationIcon.cpp new file mode 100644 index 00000000..64898c2c --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.cpp @@ -0,0 +1,8 @@ +#include "NotificationIcon.h" +#include "Symbols.h" +using namespace Pinetime::Applications::Screens; + +const char* NotificationIcon::GetIcon(bool newNotificationAvailable) { + if(newNotificationAvailable) return Symbols::info; + else return ""; +}
\ No newline at end of file diff --git a/src/displayapp/screens/NotificationIcon.h b/src/displayapp/screens/NotificationIcon.h new file mode 100644 index 00000000..dc34c3f0 --- /dev/null +++ b/src/displayapp/screens/NotificationIcon.h @@ -0,0 +1,12 @@ +#pragma once + +namespace Pinetime { + namespace Applications { + namespace Screens { + class NotificationIcon { + public: + static const char* GetIcon(bool newNotificationAvailable); + }; + } + } +}
\ No newline at end of file diff --git a/src/displayapp/screens/Notifications.cpp b/src/displayapp/screens/Notifications.cpp new file mode 100644 index 00000000..85848b2f --- /dev/null +++ b/src/displayapp/screens/Notifications.cpp @@ -0,0 +1,174 @@ +#include <libs/lvgl/lvgl.h> +#include <displayapp/DisplayApp.h> +#include <functional> +#include "Notifications.h" + +using namespace Pinetime::Applications::Screens; + +Notifications::Notifications(DisplayApp *app, Pinetime::Controllers::NotificationManager ¬ificationManager, Modes mode) : + Screen(app), notificationManager{notificationManager}, 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)); + validDisplay = true; + } else { + currentItem.reset(new NotificationItem("\nNotification", "No notification to display", 0, notificationManager.NbNotifications(), Modes::Preview)); + } + + 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); + } +} + +Notifications::~Notifications() { + lv_obj_clean(lv_scr_act()); +} + +bool Notifications::Refresh() { + 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); + } + } + + return running; +} + +bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) { + 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); + currentItem.reset(new NotificationItem("\nNotification", previousNotification.message.data(), previousNotification.index, notificationManager.NbNotifications(), mode)); + } + 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); + currentItem.reset(new NotificationItem("\nNotification", nextNotification.message.data(), nextNotification.index, notificationManager.NbNotifications(), mode)); + } + return true; + default: + return false; + } +} + + +bool Notifications::OnButtonPushed() { + running = false; + return true; +} + + +Notifications::NotificationItem::NotificationItem(const char *title, const char *msg, uint8_t notifNr, uint8_t notifNb, Modes mode) + : notifNr{notifNr}, notifNb{notifNb}, mode{mode} { + container1 = lv_cont_create(lv_scr_act(), nullptr); + 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); + lv_obj_set_height(container1, LV_VER_RES); + lv_obj_set_pos(container1, 0, 0); + lv_cont_set_layout(container1, LV_LAYOUT_OFF); + lv_cont_set_fit2(container1, LV_FIT_FLOOD, LV_FIT_FLOOD); + + t1 = lv_label_create(container1, nullptr); + static lv_style_t titleStyle; + static lv_style_t textStyle; + static lv_style_t bottomStyle; + 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)); + lv_style_copy(&bottomStyle, lv_label_get_style(t1, LV_LABEL_STYLE_MAIN)); + titleStyle.body.padding.inner = 5; + titleStyle.body.grad_color = LV_COLOR_GRAY; + titleStyle.body.main_color = LV_COLOR_GRAY; + titleStyle.body.radius = 20; + textStyle.body.border.part = LV_BORDER_NONE; + textStyle.body.padding.inner = 5; + + 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; + + 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); + lv_obj_set_width(t1, LV_HOR_RES - (titleStyle.body.padding.left + titleStyle.body.padding.right)); + lv_label_set_text(t1, title); + static constexpr int16_t offscreenOffset = -20 ; + lv_obj_set_pos(t1, titleStyle.body.padding.left, offscreenOffset); + + auto titleHeight = lv_obj_get_height(t1); + + 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); + + if(mode == Modes::Normal) { + 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); + } + } +} + + +Notifications::NotificationItem::~NotificationItem() { + lv_obj_clean(lv_scr_act()); +} diff --git a/src/displayapp/screens/Notifications.h b/src/displayapp/screens/Notifications.h new file mode 100644 index 00000000..fb4e1ef2 --- /dev/null +++ b/src/displayapp/screens/Notifications.h @@ -0,0 +1,61 @@ +#pragma once + +#include <functional> +#include <vector> + +#include "Screen.h" +#include "ScreenList.h" + + +namespace Pinetime { + namespace Applications { + namespace Screens { + class Notifications : public Screen { + public: + enum class Modes {Normal, Preview}; + explicit Notifications(DisplayApp* app, Pinetime::Controllers::NotificationManager& notificationManager, Modes mode); + ~Notifications() override; + + bool Refresh() override; + bool OnButtonPushed() override; + bool OnTouchEvent(Pinetime::Applications::TouchEvents event) override; + + private: + bool running = true; + + class NotificationItem { + public: + NotificationItem(const char* title, const char* msg, uint8_t notifNr, uint8_t notifNb, Modes mode); + ~NotificationItem(); + bool Refresh() {return false;} + + private: + uint8_t notifNr = 0; + uint8_t notifNb = 0; + char pageText[4]; + + lv_obj_t* container1; + lv_obj_t* t1; + lv_obj_t* l1; + lv_obj_t* bottomPlaceholder; + Modes mode; + }; + + struct NotificationData { + const char* title; + const char* text; + }; + Pinetime::Controllers::NotificationManager& notificationManager; + Modes mode = Modes::Normal; + std::unique_ptr<NotificationItem> currentItem; + Controllers::NotificationManager::Notification::Id currentId; + bool validDisplay = false; + + lv_point_t timeoutLinePoints[2] { {0, 237}, {239, 237} }; + lv_obj_t* timeoutLine; + uint32_t timeoutTickCountStart; + uint32_t timeoutTickCountEnd; + }; + } + } +} |