Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notification age (x minutes ago) on notifcation screen - second attempt. #2198

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/components/ble/NotificationManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ constexpr uint8_t NotificationManager::MessageSize;
void NotificationManager::Push(NotificationManager::Notification&& notif) {
notif.id = GetNextId();
notif.valid = true;
notif.timeArrived = std::chrono::system_clock::to_time_t(dateTimeController.CurrentDateTime());
newNotification = true;
if (beginIdx > 0) {
--beginIdx;
Expand Down
7 changes: 7 additions & 0 deletions src/components/ble/NotificationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#include <atomic>
#include <cstddef>
#include <cstdint>
#include <chrono>
#include "components/datetime/DateTimeController.h"

namespace Pinetime {
namespace Controllers {
Expand All @@ -28,6 +30,7 @@ namespace Pinetime {
using Id = uint8_t;
using Idx = uint8_t;

std::time_t timeArrived;
std::array<char, MessageSize + 1> message;
uint8_t size;
Categories category = Categories::Unknown;
Expand All @@ -38,6 +41,9 @@ namespace Pinetime {
const char* Title() const;
};

NotificationManager(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} {
}

void Push(Notification&& notif);
Notification GetLastNotification() const;
Notification Get(Notification::Id id) const;
Expand All @@ -61,6 +67,7 @@ namespace Pinetime {

private:
Notification::Id nextId {0};
Controllers::DateTime& dateTimeController;
Notification::Id GetNextId();
const Notification& At(Notification::Idx idx) const;
Notification& At(Notification::Idx idx);
Expand Down
2 changes: 2 additions & 0 deletions src/displayapp/DisplayApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
dateTimeController,
*systemTask,
Screens::Notifications::Modes::Normal);
break;
Expand All @@ -570,6 +571,7 @@ void DisplayApp::LoadScreen(Apps app, DisplayApp::FullRefreshDirections directio
notificationManager,
systemTask->nimble().alertService(),
motorController,
dateTimeController,
*systemTask,
Screens::Notifications::Modes::Preview);
break;
Expand Down
50 changes: 44 additions & 6 deletions src/displayapp/screens/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ Notifications::Notifications(DisplayApp* app,
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::DateTime& dateTimeController,
System::SystemTask& systemTask,
Modes mode)
: app {app},
notificationManager {notificationManager},
alertNotificationService {alertNotificationService},
motorController {motorController},
dateTimeController {dateTimeController},
wakeLock(systemTask),
mode {mode} {

Expand All @@ -31,6 +33,8 @@ Notifications::Notifications(DisplayApp* app,
notification.Message(),
1,
notification.category,
notification.timeArrived,
std::chrono::system_clock::to_time_t(this->dateTimeController.CurrentDateTime()),
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
Expand Down Expand Up @@ -107,6 +111,8 @@ void Notifications::Refresh() {
notification.Message(),
currentIdx + 1,
notification.category,
notification.timeArrived,
std::chrono::system_clock::to_time_t(this->dateTimeController.CurrentDateTime()),
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
Expand Down Expand Up @@ -200,6 +206,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
previousNotification.Message(),
currentIdx + 1,
previousNotification.category,
previousNotification.timeArrived,
std::chrono::system_clock::to_time_t(dateTimeController.CurrentDateTime()),
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
Expand Down Expand Up @@ -227,6 +235,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
nextNotification.Message(),
currentIdx + 1,
nextNotification.category,
nextNotification.timeArrived,
std::chrono::system_clock::to_time_t(dateTimeController.CurrentDateTime()),
notificationManager.NbNotifications(),
alertNotificationService,
motorController);
Expand All @@ -251,6 +261,8 @@ Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNo
0,
Controllers::NotificationManager::Categories::Unknown,
0,
0,
0,
alertNotificationService,
motorController) {
}
Expand All @@ -259,6 +271,8 @@ Notifications::NotificationItem::NotificationItem(const char* title,
const char* msg,
uint8_t notifNr,
Controllers::NotificationManager::Categories category,
std::time_t timeArrived,
std::time_t timeNow,
uint8_t notifNb,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController)
Expand Down Expand Up @@ -324,31 +338,55 @@ Notifications::NotificationItem::NotificationItem(const char* title,
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, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, 0);
lv_obj_set_size(bt_accept, 76, 38);
lv_obj_align(bt_accept, nullptr, LV_ALIGN_IN_BOTTOM_LEFT, 0, -34);
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, Colors::highlight);

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);
lv_obj_align(bt_reject, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
lv_obj_set_size(bt_reject, 76, 38);
lv_obj_align(bt_reject, nullptr, LV_ALIGN_IN_BOTTOM_MID, 0, -34);
label_reject = lv_label_create(bt_reject, nullptr);
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(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, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, 0);
lv_obj_set_size(bt_mute, 76, 38);
lv_obj_align(bt_mute, nullptr, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -34);
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, Colors::lightGray);
} break;
}
AddAlertAgeLabel(timeArrived, timeNow);
}

void Notifications::NotificationItem::AddAlertAgeLabel(std::time_t timeArrived, std::time_t timeNow) {
// almost impossible to receive a real notification at time 0, so skip because it is the "no notifications" notification
if (timeNow != 0) {
auto diff = std::chrono::system_clock::from_time_t(timeNow) - std::chrono::system_clock::from_time_t(timeArrived);
std::chrono::minutes age = std::chrono::duration_cast<std::chrono::minutes>(diff);
uint32_t ageInt = static_cast<uint32_t>(age.count());
char timeUnit;
if (ageInt / (60 * 24) >= 1) {
ageInt /= (60 * 24);
timeUnit = 'd';
} else if (ageInt >= 60) {
ageInt /= 60;
timeUnit = 'h';
} else {
timeUnit = 'm';
}
lv_obj_t* alertAge = lv_label_create(container, nullptr);
lv_label_set_text_fmt(alertAge, "%d%c ago", ageInt, timeUnit);
// same format as alert_count
lv_obj_align(alertAge, container, LV_ALIGN_IN_BOTTOM_RIGHT, -10, -10);
}
}

void Notifications::NotificationItem::OnCallButtonEvent(lv_obj_t* obj, lv_event_t event) {
Expand Down
8 changes: 8 additions & 0 deletions src/displayapp/screens/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

#include <lvgl/lvgl.h>
#include <FreeRTOS.h>
#include <chrono>
#include <cstdint>
#include <memory>
#include "displayapp/screens/Screen.h"
#include "components/ble/NotificationManager.h"
#include "components/datetime/DateTimeController.h"
#include "components/motor/MotorController.h"
#include "systemtask/SystemTask.h"
#include "systemtask/WakeLock.h"
Expand All @@ -25,6 +27,7 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController,
Pinetime::Controllers::DateTime& dateTimeController,
System::SystemTask& systemTask,
Modes mode);
~Notifications() override;
Expand All @@ -43,6 +46,8 @@ namespace Pinetime {
const char* msg,
uint8_t notifNr,
Controllers::NotificationManager::Categories,
std::time_t timeArrived,
std::time_t timeNow,
uint8_t notifNb,
Pinetime::Controllers::AlertNotificationService& alertNotificationService,
Pinetime::Controllers::MotorController& motorController);
Expand All @@ -55,6 +60,8 @@ namespace Pinetime {
void OnCallButtonEvent(lv_obj_t*, lv_event_t event);

private:
void AddAlertAgeLabel(std::time_t timeArrived, std::time_t timeNow);

lv_obj_t* container;
lv_obj_t* subject_container;
lv_obj_t* bt_accept;
Expand All @@ -74,6 +81,7 @@ namespace Pinetime {
Pinetime::Controllers::NotificationManager& notificationManager;
Pinetime::Controllers::AlertNotificationService& alertNotificationService;
Pinetime::Controllers::MotorController& motorController;
Pinetime::Controllers::DateTime& dateTimeController;
System::WakeLock wakeLock;
Modes mode = Modes::Normal;
std::unique_ptr<NotificationItem> currentItem;
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ Pinetime::Controllers::MotorController motorController {};

Pinetime::Controllers::DateTime dateTimeController {settingsController};
Pinetime::Drivers::Watchdog watchdog;
Pinetime::Controllers::NotificationManager notificationManager;
Pinetime::Controllers::NotificationManager notificationManager {dateTimeController};
Pinetime::Controllers::MotionController motionController;
Pinetime::Controllers::AlarmController alarmController {dateTimeController, fs};
Pinetime::Controllers::TouchHandler touchHandler;
Expand Down
Loading