diff --git a/src/components/ble/ImmediateAlertClient.cpp b/src/components/ble/ImmediateAlertClient.cpp index 3b266d54..9190f460 100644 --- a/src/components/ble/ImmediateAlertClient.cpp +++ b/src/components/ble/ImmediateAlertClient.cpp @@ -98,16 +98,16 @@ void ImmediateAlertClient::Discover(uint16_t connectionHandle, std::function(obj->user_data); screen->OnImmediateAlertEvent(obj, event); } + + void RestoreLabelTaskCallback(lv_task_t* task) { + auto* screen = static_cast(task->user_data); + screen->RestoreLabelText(); + screen->StopRestoreLabelTask(); + } } FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} { @@ -26,7 +37,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA label_title = lv_label_create(lv_scr_act(), nullptr); - lv_label_set_text_static(label_title, "Find my phone"); + lv_label_set_text_static(label_title, defaultLabelText); + lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); lv_obj_align(label_title, nullptr, LV_ALIGN_CENTER, 0, -40); bt_none = lv_btn_create(container, nullptr); @@ -55,8 +67,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA label_high = lv_label_create(bt_high, nullptr); lv_label_set_text_static(label_high, "High"); lv_obj_set_style_local_bg_color(bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); - - UpdateImmediateAlerts(); } FindMyPhone::~FindMyPhone() { @@ -88,7 +98,29 @@ void FindMyPhone::UpdateImmediateAlerts() { lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED); break; } - immediateAlertClient.sendImmediateAlert(last_level); - + if (immediateAlertClient.sendImmediateAlert(last_level)) { + lv_label_set_text_static(label_title, alertSentLabelText); + } else { + lv_label_set_text_static(label_title, noConnectionLabelText); + } + ScheduleRestoreLabelTask(); } +void FindMyPhone::ScheduleRestoreLabelTask() { + if (taskRestoreLabelText) { + return; + } + taskRestoreLabelText = lv_task_create(RestoreLabelTaskCallback, restoreLabelTimeoutTicks, LV_TASK_PRIO_MID, this); +} + +void FindMyPhone::StopRestoreLabelTask() { + if (taskRestoreLabelText) { + lv_task_del(taskRestoreLabelText); + taskRestoreLabelText = nullptr; + } +} + +void FindMyPhone::RestoreLabelText() { + lv_label_set_text_static(label_title, defaultLabelText); + lv_obj_set_style_local_text_color(label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray); +} diff --git a/src/displayapp/screens/FindMyPhone.h b/src/displayapp/screens/FindMyPhone.h index 82b2f3b5..a96bfc65 100644 --- a/src/displayapp/screens/FindMyPhone.h +++ b/src/displayapp/screens/FindMyPhone.h @@ -26,6 +26,10 @@ namespace Pinetime { void OnImmediateAlertEvent(lv_obj_t* obj, lv_event_t event); + void ScheduleRestoreLabelTask(); + void StopRestoreLabelTask(); + void RestoreLabelText(); + private: Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient; @@ -39,7 +43,7 @@ namespace Pinetime { lv_obj_t* label_none; lv_obj_t* label_high; lv_obj_t* label_mild; - + lv_task_t* taskRestoreLabelText = nullptr; Pinetime::Controllers::ImmediateAlertClient::Levels last_level; };