-
-
Notifications
You must be signed in to change notification settings - Fork 953
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 #835
Changes from all commits
8466196
1de1d44
a7e8139
afe96d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -4,6 +4,8 @@ | |||||
#include <atomic> | ||||||
#include <cstddef> | ||||||
#include <cstdint> | ||||||
#include <chrono> | ||||||
#include "components/datetime/DateTimeController.h" | ||||||
|
||||||
namespace Pinetime { | ||||||
namespace Controllers { | ||||||
|
@@ -30,13 +32,16 @@ namespace Pinetime { | |||||
Id id = 0; | ||||||
bool valid = false; | ||||||
uint8_t size; | ||||||
std::time_t timeArrived; | ||||||
std::array<char, MessageSize + 1> message; | ||||||
Categories category = Categories::Unknown; | ||||||
|
||||||
const char* Message() const; | ||||||
const char* Title() const; | ||||||
}; | ||||||
|
||||||
NotificationManager(Controllers::DateTime& dateTimeController) : dateTimeController {dateTimeController} { | ||||||
} | ||||||
void Push(Notification&& notif); | ||||||
Notification GetLastNotification() const; | ||||||
Notification Get(Notification::Id id) const; | ||||||
|
@@ -57,6 +62,7 @@ namespace Pinetime { | |||||
size_t NbNotifications() const; | ||||||
|
||||||
private: | ||||||
Controllers::DateTime& dateTimeController; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we can even store a
Suggested change
|
||||||
Notification::Id nextId {0}; | ||||||
Notification::Id GetNextId(); | ||||||
const Notification& At(Notification::Idx idx) const; | ||||||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -13,12 +13,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) | ||||||||||||||||||
: Screen(app), | ||||||||||||||||||
notificationManager {notificationManager}, | ||||||||||||||||||
alertNotificationService {alertNotificationService}, | ||||||||||||||||||
motorController {motorController}, | ||||||||||||||||||
dateTimeController {dateTimeController}, | ||||||||||||||||||
systemTask {systemTask}, | ||||||||||||||||||
mode {mode} { | ||||||||||||||||||
|
||||||||||||||||||
|
@@ -30,6 +32,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); | ||||||||||||||||||
|
@@ -105,6 +109,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); | ||||||||||||||||||
|
@@ -186,6 +192,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); | ||||||||||||||||||
|
@@ -213,6 +221,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); | ||||||||||||||||||
|
@@ -237,6 +247,8 @@ Notifications::NotificationItem::NotificationItem(Pinetime::Controllers::AlertNo | |||||||||||||||||
0, | ||||||||||||||||||
Controllers::NotificationManager::Categories::Unknown, | ||||||||||||||||||
0, | ||||||||||||||||||
0, | ||||||||||||||||||
0, | ||||||||||||||||||
alertNotificationService, | ||||||||||||||||||
motorController) { | ||||||||||||||||||
} | ||||||||||||||||||
|
@@ -245,6 +257,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) | ||||||||||||||||||
|
@@ -270,6 +284,26 @@ Notifications::NotificationItem::NotificationItem(const char* title, | |||||||||||||||||
lv_obj_t* alert_count = lv_label_create(container, 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); | ||||||||||||||||||
// 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) >= 1) { | ||||||||||||||||||
Comment on lines
+293
to
+296
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These can be simplified.
Suggested change
|
||||||||||||||||||
ageInt /= 60; | ||||||||||||||||||
timeUnit = 'h'; | ||||||||||||||||||
} else { | ||||||||||||||||||
timeUnit = 'm'; | ||||||||||||||||||
} | ||||||||||||||||||
lv_obj_t* alert_age = lv_label_create(container, nullptr); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Variables names should be like this. Don't commit this suggestion.
Suggested change
|
||||||||||||||||||
lv_label_set_text_fmt(alert_age, "%d%c ago", ageInt, timeUnit); | ||||||||||||||||||
// same format as alert_count | ||||||||||||||||||
lv_obj_align(alert_age, container, LV_ALIGN_IN_BOTTOM_RIGHT, 0, -16); | ||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This will make the padding similar to the text.
Suggested change
|
||||||||||||||||||
} | ||||||||||||||||||
|
||||||||||||||||||
lv_obj_t* alert_type = lv_label_create(container, nullptr); | ||||||||||||||||||
lv_obj_set_style_local_text_color(alert_type, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_MAKE(0xb0, 0xb0, 0xb0)); | ||||||||||||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we can even store a
const
reference, to make it explicit, that a notification can't change the date-time, just get the current date and timeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At present it is not possible since DateTime controller updates it member variables during time retrieving.
InfiniTime/src/components/datetime/DateTimeController.cpp
Lines 72 to 102 in d69cfcf
It can be overcomed with
mutable
but I am not sure whether this is a good idea.