77using namespace Pinetime ::Applications::Screens;
88
99namespace {
10+ static constexpr char defaultLabelText[] = " Find my phone" ;
11+ static constexpr char alertSentLabelText[] = " Alert sent" ;
12+ static constexpr char noConnectionLabelText[] = " No connection" ;
13+ static constexpr auto restoreLabelTimeoutTicks = pdMS_TO_TICKS(2 * 1000 );
14+
1015 void btnImmediateAlertEventHandler (lv_obj_t * obj, lv_event_t event) {
1116 auto * screen = static_cast <FindMyPhone*>(obj->user_data );
1217 screen->OnImmediateAlertEvent (obj, event);
1318 }
19+
20+ void RestoreLabelTaskCallback (lv_task_t * task) {
21+ auto * screen = static_cast <FindMyPhone*>(task->user_data );
22+ screen->RestoreLabelText ();
23+ screen->StopRestoreLabelTask ();
24+ }
1425}
1526
1627FindMyPhone::FindMyPhone (Pinetime::Controllers::ImmediateAlertClient& immediateAlertClient) : immediateAlertClient {immediateAlertClient} {
@@ -26,7 +37,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
2637
2738 label_title = lv_label_create (lv_scr_act (), nullptr );
2839
29- lv_label_set_text_static (label_title, " Find my phone" );
40+ lv_label_set_text_static (label_title, defaultLabelText);
41+ lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
3042 lv_obj_align (label_title, nullptr , LV_ALIGN_CENTER, 0 , -40 );
3143
3244 bt_none = lv_btn_create (container, nullptr );
@@ -55,8 +67,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
5567 label_high = lv_label_create (bt_high, nullptr );
5668 lv_label_set_text_static (label_high, " High" );
5769 lv_obj_set_style_local_bg_color (bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
58-
59- UpdateImmediateAlerts ();
6070}
6171
6272FindMyPhone::~FindMyPhone () {
@@ -88,7 +98,29 @@ void FindMyPhone::UpdateImmediateAlerts() {
8898 lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
8999 break ;
90100 }
91- immediateAlertClient.sendImmediateAlert (last_level);
101+ if (immediateAlertClient.sendImmediateAlert (last_level)) {
102+ lv_label_set_text_static (label_title, alertSentLabelText);
103+ } else {
104+ lv_label_set_text_static (label_title, noConnectionLabelText);
105+ }
106+ ScheduleRestoreLabelTask ();
107+ }
92108
109+ void FindMyPhone::ScheduleRestoreLabelTask () {
110+ if (taskRestoreLabelText) {
111+ return ;
112+ }
113+ taskRestoreLabelText = lv_task_create (RestoreLabelTaskCallback, restoreLabelTimeoutTicks, LV_TASK_PRIO_MID, this );
93114}
94115
116+ void FindMyPhone::StopRestoreLabelTask () {
117+ if (taskRestoreLabelText) {
118+ lv_task_del (taskRestoreLabelText);
119+ taskRestoreLabelText = nullptr ;
120+ }
121+ }
122+
123+ void FindMyPhone::RestoreLabelText () {
124+ lv_label_set_text_static (label_title, defaultLabelText);
125+ lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
126+ }
0 commit comments