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)
@@ -27,7 +38,8 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
2738
2839 label_title = lv_label_create (lv_scr_act (), nullptr );
2940
30- lv_label_set_text_static (label_title, " Find my phone" );
41+ lv_label_set_text_static (label_title, defaultLabelText);
42+ lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
3143 lv_obj_align (label_title, nullptr , LV_ALIGN_CENTER, 0 , -40 );
3244
3345 bt_none = lv_btn_create (container, nullptr );
@@ -56,8 +68,6 @@ FindMyPhone::FindMyPhone(Pinetime::Controllers::ImmediateAlertClient& immediateA
5668 label_high = lv_label_create (bt_high, nullptr );
5769 lv_label_set_text_static (label_high, " High" );
5870 lv_obj_set_style_local_bg_color (bt_high, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED );
59-
60- UpdateImmediateAlerts ();
6171}
6272
6373FindMyPhone::~FindMyPhone () {
@@ -89,7 +99,29 @@ void FindMyPhone::UpdateImmediateAlerts() {
8999 lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_RED);
90100 break ;
91101 }
92- immediateAlertClient.sendImmediateAlert (last_level);
102+ if (immediateAlertClient.sendImmediateAlert (last_level)) {
103+ lv_label_set_text_static (label_title, alertSentLabelText);
104+ } else {
105+ lv_label_set_text_static (label_title, noConnectionLabelText);
106+ }
107+ ScheduleRestoreLabelTask ();
108+ }
93109
110+ void FindMyPhone::ScheduleRestoreLabelTask () {
111+ if (taskRestoreLabelText) {
112+ return ;
113+ }
114+ taskRestoreLabelText = lv_task_create (RestoreLabelTaskCallback, restoreLabelTimeoutTicks, LV_TASK_PRIO_MID, this );
94115}
95116
117+ void FindMyPhone::StopRestoreLabelTask () {
118+ if (taskRestoreLabelText) {
119+ lv_task_del (taskRestoreLabelText);
120+ taskRestoreLabelText = nullptr ;
121+ }
122+ }
123+
124+ void FindMyPhone::RestoreLabelText () {
125+ lv_label_set_text_static (label_title, defaultLabelText);
126+ lv_obj_set_style_local_text_color (label_title, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, Colors::lightGray);
127+ }
0 commit comments