Skip to content

Commit

Permalink
Fix label on last call screen.
Browse files Browse the repository at this point in the history
  • Loading branch information
vchigrin committed Dec 11, 2024
1 parent 2224fcd commit 27f248f
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 27 deletions.
57 changes: 30 additions & 27 deletions src/displayapp/screens/Notifications.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,27 +304,6 @@ Notifications::NotificationItem::NotificationItem(const char* title,
if (title == nullptr) {
lv_label_set_text_static(alert_type, "Notification");
} else {
// 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);
}

// 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');
Expand Down Expand Up @@ -359,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
2 changes: 2 additions & 0 deletions src/displayapp/screens/Notifications.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,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 Down

0 comments on commit 27f248f

Please sign in to comment.