InfiniTime.git

commit 7a6ede112e2a777321db16f367a6e4429604e5d9

Author: Riku Isokoski <riksu9000@gmail.com>

Remove clockType variable by checking for nullptr instead.

Saves a few bytes

 src/displayapp/screens/Alarm.cpp | 16 ++++++++--------
 src/displayapp/screens/Alarm.h | 4 ++--


diff --git a/src/displayapp/screens/Alarm.cpp b/src/displayapp/screens/Alarm.cpp
index d508dd397542fa2a45a4e883123ec81e44cb65c7..bcb6eff8efe1b3f07288f2643b70616b7fa64bec 100644
--- a/src/displayapp/screens/Alarm.cpp
+++ b/src/displayapp/screens/Alarm.cpp
@@ -43,12 +43,18 @@ Alarm::Alarm(DisplayApp* app,
              Controllers::AlarmController& alarmController,
              Controllers::Settings::ClockType clockType,
              System::SystemTask& systemTask)
-  : Screen(app), alarmController {alarmController}, clockType {clockType}, systemTask {systemTask} {
+  : Screen(app), alarmController {alarmController}, systemTask {systemTask} {
 
   hourCounter.Create();
   lv_obj_align(hourCounter.GetObject(), nullptr, LV_ALIGN_IN_TOP_LEFT, 0, 0);
   if (clockType == Controllers::Settings::ClockType::H12) {
     hourCounter.EnableTwelveHourMode();
+
+    lblampm = lv_label_create(lv_scr_act(), nullptr);
+    lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
+    lv_label_set_text_static(lblampm, "AM");
+    lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
+    lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);
   }
   hourCounter.SetValue(alarmController.Hours());
   hourCounter.SetValueChangedEventCallback(this, ValueChangedHandler);
@@ -62,12 +68,6 @@   lv_obj_t* colonLabel = lv_label_create(lv_scr_act(), nullptr);
   lv_obj_set_style_local_text_font(colonLabel, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_76);
   lv_label_set_text_static(colonLabel, ":");
   lv_obj_align(colonLabel, lv_scr_act(), LV_ALIGN_CENTER, 0, -29);
-
-  lblampm = lv_label_create(lv_scr_act(), nullptr);
-  lv_obj_set_style_local_text_font(lblampm, LV_LABEL_PART_MAIN, LV_STATE_DEFAULT, &jetbrains_mono_bold_20);
-  lv_label_set_text_static(lblampm, "  ");
-  lv_label_set_align(lblampm, LV_LABEL_ALIGN_CENTER);
-  lv_obj_align(lblampm, lv_scr_act(), LV_ALIGN_CENTER, 0, 30);
 
   btnStop = lv_btn_create(lv_scr_act(), nullptr);
   btnStop->user_data = this;
@@ -179,7 +179,7 @@   UpdateAlarmTime();
 }
 
 void Alarm::UpdateAlarmTime() {
-  if (clockType == Controllers::Settings::ClockType::H12) {
+  if (lblampm != nullptr) {
     if (hourCounter.GetValue() >= 12) {
       lv_label_set_text_static(lblampm, "PM");
     } else {




diff --git a/src/displayapp/screens/Alarm.h b/src/displayapp/screens/Alarm.h
index a64bbe81d93eee01bac17ecdecc68e8fbdfc21dc..fba9d5d9fb23c7f8a080efb5b0e3d5e4e1ba3005 100644
--- a/src/displayapp/screens/Alarm.h
+++ b/src/displayapp/screens/Alarm.h
@@ -42,10 +42,10 @@         void StopAlerting();
 
       private:
         Controllers::AlarmController& alarmController;
-        const Controllers::Settings::ClockType clockType;
         System::SystemTask& systemTask;
 
-        lv_obj_t *lblampm, *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch;
+        lv_obj_t *btnStop, *txtStop, *btnRecur, *txtRecur, *btnInfo, *enableSwitch;
+        lv_obj_t* lblampm = nullptr;
         lv_obj_t* txtMessage = nullptr;
         lv_obj_t* btnMessage = nullptr;
         lv_task_t* taskStopAlarm = nullptr;