@@ -14,12 +14,14 @@ Notifications::Notifications(DisplayApp* app,
1414 Pinetime::Controllers::NotificationManager& notificationManager,
1515 Pinetime::Controllers::AlertNotificationService& alertNotificationService,
1616 Pinetime::Controllers::MotorController& motorController,
17+ Pinetime::Controllers::DateTime& dateTimeController,
1718 System::SystemTask& systemTask,
1819 Modes mode)
1920 : app {app},
2021 notificationManager {notificationManager},
2122 alertNotificationService {alertNotificationService},
2223 motorController {motorController},
24+ dateTimeController {dateTimeController},
2325 wakeLock (systemTask),
2426 mode {mode} {
2527
@@ -31,6 +33,8 @@ Notifications::Notifications(DisplayApp* app,
3133 notification.Message (),
3234 1 ,
3335 notification.category ,
36+ notification.timeArrived ,
37+ std::chrono::system_clock::to_time_t (this ->dateTimeController .CurrentDateTime ()),
3438 notificationManager.NbNotifications (),
3539 alertNotificationService,
3640 motorController);
@@ -200,6 +204,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
200204 previousNotification.Message (),
201205 currentIdx + 1 ,
202206 previousNotification.category ,
207+ previousNotification.timeArrived ,
208+ std::chrono::system_clock::to_time_t (dateTimeController.CurrentDateTime ()),
203209 notificationManager.NbNotifications (),
204210 alertNotificationService,
205211 motorController);
@@ -227,6 +233,8 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
227233 nextNotification.Message (),
228234 currentIdx + 1 ,
229235 nextNotification.category ,
236+ nextNotification.timeArrived ,
237+ std::chrono::system_clock::to_time_t (dateTimeController.CurrentDateTime ()),
230238 notificationManager.NbNotifications (),
231239 alertNotificationService,
232240 motorController);
@@ -251,6 +259,8 @@ Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNo
251259 0 ,
252260 Controllers::NotificationManager::Categories::Unknown,
253261 0 ,
262+ 0 ,
263+ 0 ,
254264 alertNotificationService,
255265 motorController) {
256266}
@@ -259,6 +269,8 @@ Notifications::NotificationItem::NotificationItem(const char* title,
259269 const char * msg,
260270 uint8_t notifNr,
261271 Controllers::NotificationManager::Categories category,
272+ std::time_t timeArrived,
273+ std::time_t timeNow,
262274 uint8_t notifNb,
263275 Pinetime::Controllers::AlertNotificationService& alertNotificationService,
264276 Pinetime::Controllers::MotorController& motorController)
@@ -290,6 +302,21 @@ Notifications::NotificationItem::NotificationItem(const char* title,
290302 if (title == nullptr ) {
291303 lv_label_set_text_static (alert_type, " Notification" );
292304 } else {
305+ auto diff = std::chrono::system_clock::from_time_t (timeNow) - std::chrono::system_clock::from_time_t (timeArrived);
306+ std::chrono::minutes age = std::chrono::duration_cast<std::chrono::minutes>(diff);
307+ std::string ageString;
308+ ageString.reserve (10 );
309+ if ((age.count () / (60 * 24 )) >= 1 ) {
310+ ageString = std::to_string (static_cast <uint16_t >(age.count () / (60 * 24 ))) + " d ago" ;
311+ } else if ((age.count () / 60 ) >= 1 ) {
312+ ageString = std::to_string (static_cast <uint8_t >(age.count () / 60 )) + " h ago" ;
313+ } else {
314+ ageString = std::to_string (static_cast <uint8_t >(age.count ())) + " m ago" ;
315+ }
316+ lv_obj_t * alert_age = lv_label_create (lv_scr_act (), nullptr );
317+ lv_label_set_text (alert_age, ageString.c_str ());
318+ lv_obj_align (alert_age, container1, LV_ALIGN_IN_BOTTOM_RIGHT, 0 , 0 );
319+
293320 // copy title to label and replace newlines with spaces
294321 lv_label_set_text (alert_type, title);
295322 char * pchar = strchr (lv_label_get_text (alert_type), ' \n ' );
0 commit comments