@@ -11,13 +11,8 @@ extern lv_font_t jetbrains_mono_bold_20;
1111Notifications::Notifications (DisplayApp* app,
1212 Pinetime::Controllers::NotificationManager& notificationManager,
1313 Pinetime::Controllers::AlertNotificationService& alertNotificationService,
14- Controllers::MotorController& motorController,
1514 Modes mode)
16- : Screen(app),
17- notificationManager{notificationManager},
18- alertNotificationService{alertNotificationService},
19- motorController{motorController},
20- mode{mode} {
15+ : Screen(app), notificationManager {notificationManager}, alertNotificationService {alertNotificationService}, mode {mode} {
2116 notificationManager.ClearNewNotificationFlag ();
2217 auto notification = notificationManager.GetLastNotification ();
2318 if (notification.valid ) {
@@ -28,10 +23,7 @@ Notifications::Notifications(DisplayApp* app,
2823 notification.category ,
2924 notificationManager.NbNotifications (),
3025 mode,
31- alertNotificationService,
32- motorController,
33- &timeoutTickCountEnd,
34- &timeoutTickCountStart);
26+ alertNotificationService);
3527 validDisplay = true ;
3628 } else {
3729 currentItem = std::make_unique<NotificationItem>(" Notification" ,
@@ -40,14 +32,10 @@ Notifications::Notifications(DisplayApp* app,
4032 notification.category ,
4133 notificationManager.NbNotifications (),
4234 Modes::Preview,
43- alertNotificationService,
44- motorController,
45- &timeoutTickCountEnd,
46- &timeoutTickCountStart);
35+ alertNotificationService);
4736 }
4837
49- if (mode == Modes::Preview) {
50-
38+ if (mode == Modes::Preview && notification.category != Controllers::NotificationManager::Categories::IncomingCall) {
5139 timeoutLine = lv_line_create (lv_scr_act (), nullptr );
5240
5341 lv_obj_set_style_local_line_width (timeoutLine, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3 );
@@ -61,11 +49,13 @@ Notifications::Notifications(DisplayApp* app,
6149}
6250
6351Notifications::~Notifications () {
52+ // make sure we stop any vibrations before exiting
53+ Controllers::MotorController::StopRinging ();
6454 lv_obj_clean (lv_scr_act ());
6555}
6656
6757bool Notifications::Refresh () {
68- if (mode == Modes::Preview && !currentItem-> timeoutOnHold ) {
58+ if (mode == Modes::Preview && timeoutLine != nullptr ) {
6959 auto tick = xTaskGetTickCount ();
7060 int32_t pos = 240 - ((tick - timeoutTickCountStart) / ((timeoutTickCountEnd - timeoutTickCountStart) / 240 ));
7161 if (pos < 0 )
@@ -74,10 +64,7 @@ bool Notifications::Refresh() {
7464 timeoutLinePoints[1 ].x = pos;
7565 lv_line_set_points (timeoutLine, timeoutLinePoints, 2 );
7666 }
77- // make sure we stop any vibrations before exiting
78- if (!running)
79- motorController.stopRunning ();
80- return running;
67+ return running && currentItem->IsRunning ();
8168}
8269
8370bool Notifications::OnTouchEvent (Pinetime::Applications::TouchEvents event) {
@@ -105,10 +92,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
10592 previousNotification.category ,
10693 notificationManager.NbNotifications (),
10794 mode,
108- alertNotificationService,
109- motorController,
110- &timeoutTickCountEnd,
111- &timeoutTickCountStart);
95+ alertNotificationService);
11296 }
11397 return true ;
11498 case Pinetime::Applications::TouchEvents::SwipeUp: {
@@ -133,10 +117,7 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
133117 nextNotification.category ,
134118 notificationManager.NbNotifications (),
135119 mode,
136- alertNotificationService,
137- motorController,
138- &timeoutTickCountEnd,
139- &timeoutTickCountStart);
120+ alertNotificationService);
140121 }
141122 return true ;
142123 case Pinetime::Applications::TouchEvents::LongTap: {
@@ -149,19 +130,9 @@ bool Notifications::OnTouchEvent(Pinetime::Applications::TouchEvents event) {
149130}
150131
151132namespace {
152- static void AcceptIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
153- auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
154- item->OnAcceptIncomingCall (event);
155- }
156-
157- static void MuteIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
133+ void CallEventHandler (lv_obj_t * obj, lv_event_t event) {
158134 auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
159- item->OnMuteIncomingCall (event);
160- }
161-
162- static void RejectIncomingCallEventHandler (lv_obj_t * obj, lv_event_t event) {
163- auto * item = static_cast <Notifications::NotificationItem*>(obj->user_data );
164- item->OnRejectIncomingCall (event);
135+ item->OnCallButtonEvent (obj, event);
165136 }
166137}
167138
@@ -171,12 +142,8 @@ Notifications::NotificationItem::NotificationItem(const char* title,
171142 Controllers::NotificationManager::Categories category,
172143 uint8_t notifNb,
173144 Modes mode,
174- Pinetime::Controllers::AlertNotificationService& alertNotificationService,
175- Controllers::MotorController& motorController,
176- uint32_t * timeoutEnd,
177- uint32_t * timeoutStart)
178- : notifNr{notifNr}, notifNb{notifNb}, mode{mode}, alertNotificationService{alertNotificationService},
179- motorController{motorController}, timeoutEnd{timeoutEnd}, timeoutStart{timeoutStart} {
145+ Pinetime::Controllers::AlertNotificationService& alertNotificationService)
146+ : notifNr {notifNr}, notifNb {notifNb}, mode {mode}, alertNotificationService {alertNotificationService} {
180147 lv_obj_t * container1 = lv_cont_create (lv_scr_act (), NULL );
181148
182149 lv_obj_set_style_local_bg_color (container1, LV_CONT_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex (0x222222 ));
@@ -234,7 +201,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
234201
235202 bt_accept = lv_btn_create (lv_scr_act (), nullptr );
236203 bt_accept->user_data = this ;
237- lv_obj_set_event_cb (bt_accept, AcceptIncomingCallEventHandler );
204+ lv_obj_set_event_cb (bt_accept, CallEventHandler );
238205 lv_obj_set_size (bt_accept, 76 , 76 );
239206 lv_obj_align (bt_accept, NULL , LV_ALIGN_IN_BOTTOM_LEFT, 0 , 0 );
240207 label_accept = lv_label_create (bt_accept, nullptr );
@@ -243,7 +210,7 @@ Notifications::NotificationItem::NotificationItem(const char* title,
243210
244211 bt_reject = lv_btn_create (lv_scr_act (), nullptr );
245212 bt_reject->user_data = this ;
246- lv_obj_set_event_cb (bt_reject, RejectIncomingCallEventHandler );
213+ lv_obj_set_event_cb (bt_reject, CallEventHandler );
247214 lv_obj_set_size (bt_reject, 76 , 76 );
248215 lv_obj_align (bt_reject, NULL , LV_ALIGN_IN_BOTTOM_MID, 0 , 0 );
249216 label_reject = lv_label_create (bt_reject, nullptr );
@@ -252,13 +219,12 @@ Notifications::NotificationItem::NotificationItem(const char* title,
252219
253220 bt_mute = lv_btn_create (lv_scr_act (), nullptr );
254221 bt_mute->user_data = this ;
255- lv_obj_set_event_cb (bt_mute, MuteIncomingCallEventHandler );
222+ lv_obj_set_event_cb (bt_mute, CallEventHandler );
256223 lv_obj_set_size (bt_mute, 76 , 76 );
257224 lv_obj_align (bt_mute, NULL , LV_ALIGN_IN_BOTTOM_RIGHT, 0 , 0 );
258225 label_mute = lv_label_create (bt_mute, nullptr );
259226 lv_label_set_text (label_mute, Symbols::volumMute);
260227 lv_obj_set_style_local_bg_color (bt_mute, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
261- timeoutOnHold = true ;
262228 } break ;
263229 }
264230
@@ -269,35 +235,24 @@ Notifications::NotificationItem::NotificationItem(const char* title,
269235 lv_label_set_text (backgroundLabel, " " );
270236}
271237
272- void Notifications::NotificationItem::OnAcceptIncomingCall ( lv_event_t event) {
273- if (event != LV_EVENT_CLICKED)
238+ void Notifications::NotificationItem::OnCallButtonEvent ( lv_obj_t * obj, lv_event_t event) {
239+ if (event != LV_EVENT_CLICKED) {
274240 return ;
275- callPreviewInteraction ();
276- alertNotificationService.AcceptIncomingCall ();
277- }
241+ }
278242
279- void Notifications::NotificationItem::OnMuteIncomingCall (lv_event_t event) {
280- if (event != LV_EVENT_CLICKED)
281- return ;
282- callPreviewInteraction ();
283- alertNotificationService.MuteIncomingCall ();
284- }
243+ Controllers::MotorController::StopRinging ();
285244
286- void Notifications::NotificationItem::OnRejectIncomingCall (lv_event_t event) {
287- if (event != LV_EVENT_CLICKED)
288- return ;
289- callPreviewInteraction ();
290- alertNotificationService.RejectIncomingCall ();
291- }
245+ if (obj == bt_accept) {
246+ alertNotificationService.AcceptIncomingCall ();
247+ } else if (obj == bt_reject) {
248+ alertNotificationService.RejectIncomingCall ();
249+ } else if (obj == bt_mute) {
250+ alertNotificationService.MuteIncomingCall ();
251+ }
292252
293- inline void Notifications::NotificationItem::callPreviewInteraction () {
294- *timeoutStart = xTaskGetTickCount ();
295- *timeoutEnd = *timeoutStart + (5 * 1024 );
296- timeoutOnHold = false ;
297- motorController.stopRunning ();
253+ running = false ;
298254}
299255
300-
301256Notifications::NotificationItem::~NotificationItem () {
302257 lv_obj_clean (lv_scr_act ());
303258}
0 commit comments