summaryrefslogtreecommitdiff
path: root/src/displayapp/screens/Timer.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/displayapp/screens/Timer.cpp')
-rw-r--r--src/displayapp/screens/Timer.cpp87
1 files changed, 11 insertions, 76 deletions
diff --git a/src/displayapp/screens/Timer.cpp b/src/displayapp/screens/Timer.cpp
index 998dfcb..2556bb8 100644
--- a/src/displayapp/screens/Timer.cpp
+++ b/src/displayapp/screens/Timer.cpp
@@ -5,7 +5,7 @@
using namespace Pinetime::Applications::Screens;
-static void btnEventHandler(lv_obj_t* obj, lv_event_t event) {
+void Timer::btnEventHandler(lv_obj_t* obj, lv_event_t event) {
auto* screen = static_cast<Timer*>(obj->user_data);
screen->OnButtonEvent(obj, event);
}
@@ -59,7 +59,6 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
time = lv_label_create(lv_scr_act(), nullptr);
lv_obj_set_style_local_text_font(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
- lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
uint32_t seconds = timerController.GetTimeRemaining() / 1000;
lv_label_set_text_fmt(time, "%02lu:%02lu", seconds / 60, seconds % 60);
@@ -72,13 +71,9 @@ Timer::Timer(DisplayApp* app, Controllers::TimerController& timerController)
lv_obj_align(btnPlayPause, lv_scr_act(), LV_ALIGN_IN_BOTTOM_MID, 0, -10);
lv_obj_set_height(btnPlayPause, 40);
txtPlayPause = lv_label_create(btnPlayPause, nullptr);
- if (timerController.IsRunning()) {
- lv_label_set_text_static(txtPlayPause, Symbols::pause);
- } else {
- lv_label_set_text_static(txtPlayPause, Symbols::play);
- CreateButtons();
- }
+ RefreshRunning();
+
taskRefresh = lv_task_create(RefreshTaskCallback, LV_DISP_DEF_REFR_PERIOD, LV_TASK_PRIO_MID, this);
}
@@ -94,73 +89,13 @@ void Timer::Refresh() {
}
}
-void Timer::OnButtonEvent(lv_obj_t* obj, lv_event_t event) {
- if (event == LV_EVENT_CLICKED) {
- if (obj == btnPlayPause) {
- if (timerController.IsRunning()) {
- lv_label_set_text_static(txtPlayPause, Symbols::play);
- uint32_t seconds = timerController.GetTimeRemaining() / 1000;
- minutesToSet = seconds / 60;
- secondsToSet = seconds % 60;
- timerController.StopTimer();
- CreateButtons();
-
- } else if (secondsToSet + minutesToSet > 0) {
- lv_label_set_text_static(txtPlayPause, Symbols::pause);
- timerController.StartTimer((secondsToSet + minutesToSet * 60) * 1000);
-
- lv_obj_del(btnSecondsDown);
- btnSecondsDown = nullptr;
- lv_obj_del(btnSecondsUp);
- btnSecondsUp = nullptr;
- lv_obj_del(btnMinutesDown);
- btnMinutesDown = nullptr;
- lv_obj_del(btnMinutesUp);
- btnMinutesUp = nullptr;
- }
- } else {
- if (!timerController.IsRunning()) {
- if (obj == btnMinutesUp) {
- if (minutesToSet >= 59) {
- minutesToSet = 0;
- } else {
- minutesToSet++;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnMinutesDown) {
- if (minutesToSet == 0) {
- minutesToSet = 59;
- } else {
- minutesToSet--;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnSecondsUp) {
- if (secondsToSet >= 59) {
- secondsToSet = 0;
- } else {
- secondsToSet++;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
-
- } else if (obj == btnSecondsDown) {
- if (secondsToSet == 0) {
- secondsToSet = 59;
- } else {
- secondsToSet--;
- }
- lv_label_set_text_fmt(time, "%02d:%02d", minutesToSet, secondsToSet);
- }
- }
- }
+void Timer::RefreshRunning() {
+ if (timerController.IsRunning()) {
+ lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_LIME);
+ lv_label_set_text_static(txtPlayPause, Symbols::pause);
+ } else {
+ lv_obj_set_style_local_text_color(time, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY);
+ lv_label_set_text_static(txtPlayPause, Symbols::play);
+ CreateButtons();
}
}
-
-void Timer::SetDone() {
- lv_label_set_text_static(time, "00:00");
- lv_label_set_text_static(txtPlayPause, Symbols::play);
- secondsToSet = 0;
- minutesToSet = 0;
- CreateButtons();
-}