InfiniTime.git

commit d889f3e4446107ce5bdd45c6791281e37cadf5b0

Author: FintasticMan <finlay.neon.kid@gmail.com>

settings: Add settings item for weather format

 src/CMakeLists.txt | 1 
 src/components/settings/Settings.h | 15 ++
 src/displayapp/DisplayApp.cpp | 4 
 src/displayapp/apps/Apps.h.in | 1 
 src/displayapp/fonts/fonts.json | 2 
 src/displayapp/screens/settings/SettingWeatherFormat.cpp | 63 ++++++++++
 src/displayapp/screens/settings/SettingWeatherFormat.h | 26 ++++
 src/displayapp/screens/settings/Settings.h | 6 


diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index b9f333f6b7e5ebb2c39274cf97356a8130d49aa1..8b27c19de7602baeda255afd5edf2cb26e46b1bd 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -405,6 +405,7 @@         displayapp/screens/settings/QuickSettings.cpp
         displayapp/screens/settings/Settings.cpp
         displayapp/screens/settings/SettingWatchFace.cpp
         displayapp/screens/settings/SettingTimeFormat.cpp
+        displayapp/screens/settings/SettingWeatherFormat.cpp
         displayapp/screens/settings/SettingWakeUp.cpp
         displayapp/screens/settings/SettingDisplay.cpp
         displayapp/screens/settings/SettingSteps.cpp




diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h
index 89c2ba97a1cdc81000b7f0d66e7bce4f6c1df5ed..063120774a8548024da3935a03a5c84532f111a6 100644
--- a/src/components/settings/Settings.h
+++ b/src/components/settings/Settings.h
@@ -10,6 +10,7 @@   namespace Controllers {
     class Settings {
     public:
       enum class ClockType : uint8_t { H24, H12 };
+      enum class WeatherFormat : uint8_t { Metric, Imperial };
       enum class Notification : uint8_t { On, Off, Sleep };
       enum class ChimesOption : uint8_t { None, Hours, HalfHours };
       enum class WakeUpMode : uint8_t { SingleTap = 0, DoubleTap = 1, RaiseWrist = 2, Shake = 3, LowerWrist = 4 };
@@ -180,6 +181,17 @@       ClockType GetClockType() const {
         return settings.clockType;
       };
 
+      void SetWeatherFormat(WeatherFormat weatherFormat) {
+        if (weatherFormat != settings.weatherFormat) {
+          settingsChanged = true;
+        }
+        settings.weatherFormat = weatherFormat;
+      };
+
+      WeatherFormat GetWeatherFormat() const {
+        return settings.weatherFormat;
+      };
+
       void SetNotificationStatus(Notification status) {
         if (status != settings.notificationStatus) {
           settingsChanged = true;
@@ -274,7 +286,7 @@
     private:
       Pinetime::Controllers::FS& fs;
 
-      static constexpr uint32_t settingsVersion = 0x0006;
+      static constexpr uint32_t settingsVersion = 0x0007;
 
       struct SettingsData {
         uint32_t version = settingsVersion;
@@ -282,6 +294,7 @@         uint32_t stepsGoal = 10000;
         uint32_t screenTimeOut = 15000;
 
         ClockType clockType = ClockType::H24;
+        WeatherFormat weatherFormat = WeatherFormat::Metric;
         Notification notificationStatus = Notification::On;
 
         Pinetime::Applications::WatchFace watchFace = Pinetime::Applications::WatchFace::Digital;




diff --git a/src/displayapp/DisplayApp.cpp b/src/displayapp/DisplayApp.cpp
index 28ce0babd74d35c992402de40a7d12bd4a718be9..2792009f05cb59ed40b23efdc309f60012463c50 100644
--- a/src/displayapp/DisplayApp.cpp
+++ b/src/displayapp/DisplayApp.cpp
@@ -39,6 +39,7 @@ #include "displayapp/screens/settings/QuickSettings.h"
 #include "displayapp/screens/settings/Settings.h"
 #include "displayapp/screens/settings/SettingWatchFace.h"
 #include "displayapp/screens/settings/SettingTimeFormat.h"
+#include "displayapp/screens/settings/SettingWeatherFormat.h"
 #include "displayapp/screens/settings/SettingWakeUp.h"
 #include "displayapp/screens/settings/SettingDisplay.h"
 #include "displayapp/screens/settings/SettingSteps.h"
@@ -497,6 +498,9 @@       currentScreen = std::make_unique(this, std::move(items), settingsController, filesystem);
     } break;
     case Apps::SettingTimeFormat:
       currentScreen = std::make_unique<Screens::SettingTimeFormat>(settingsController);
+      break;
+    case Apps::SettingWeatherFormat:
+      currentScreen = std::make_unique<Screens::SettingWeatherFormat>(settingsController);
       break;
     case Apps::SettingWakeUp:
       currentScreen = std::make_unique<Screens::SettingWakeUp>(settingsController);




diff --git a/src/displayapp/apps/Apps.h.in b/src/displayapp/apps/Apps.h.in
index b4f117206d55f056b4f8ec0f1e22f13f1f369bd6..11fe17b57535aede586258d07489c33acef18fb7 100644
--- a/src/displayapp/apps/Apps.h.in
+++ b/src/displayapp/apps/Apps.h.in
@@ -32,6 +32,7 @@       QuickSettings,
       Settings,
       SettingWatchFace,
       SettingTimeFormat,
+      SettingWeatherFormat,
       SettingDisplay,
       SettingWakeUp,
       SettingSteps,




diff --git a/src/displayapp/fonts/fonts.json b/src/displayapp/fonts/fonts.json
index 48d382d006ec593b32ae11e04edafe79533e8507..ead5239eaeeb46bfebb79ed0f720cd52bf60882f 100644
--- a/src/displayapp/fonts/fonts.json
+++ b/src/displayapp/fonts/fonts.json
@@ -7,7 +7,7 @@             "range": "0x20-0x7e, 0x410-0x44f, 0xB0"
          },
          {
             "file": "FontAwesome5-Solid+Brands+Regular.woff",
-            "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c"
+            "range": "0xf294, 0xf242, 0xf54b, 0xf21e, 0xf1e6, 0xf017, 0xf129, 0xf03a, 0xf185, 0xf560, 0xf001, 0xf3fd, 0xf1fc, 0xf45d, 0xf59f, 0xf5a0, 0xf027, 0xf028, 0xf6a9, 0xf04b, 0xf04c, 0xf048, 0xf051, 0xf095, 0xf3dd, 0xf04d, 0xf2f2, 0xf024, 0xf252, 0xf569, 0xf06e, 0xf015, 0xf00c, 0xf743"
          }
       ],
       "bpp": 1,




diff --git a/src/displayapp/screens/settings/SettingWeatherFormat.cpp b/src/displayapp/screens/settings/SettingWeatherFormat.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..4f37ede62ba6933f061cbd40f614430eb18bfce8
--- /dev/null
+++ b/src/displayapp/screens/settings/SettingWeatherFormat.cpp
@@ -0,0 +1,63 @@
+#include "displayapp/screens/settings/SettingWeatherFormat.h"
+
+#include <lvgl/lvgl.h>
+
+#include "displayapp/DisplayApp.h"
+#include "displayapp/screens/Styles.h"
+#include "displayapp/screens/Screen.h"
+#include "displayapp/screens/Symbols.h"
+
+using namespace Pinetime::Applications::Screens;
+
+namespace {
+  struct Option {
+    Pinetime::Controllers::Settings::WeatherFormat weatherFormat;
+    const char* name;
+  };
+
+  constexpr std::array<Option, 2> options = {{
+    {Pinetime::Controllers::Settings::WeatherFormat::Metric, "Metric"},
+    {Pinetime::Controllers::Settings::WeatherFormat::Imperial, "Imperial"},
+  }};
+
+  std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() {
+    std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray;
+    for (size_t i = 0; i < CheckboxList::MaxItems; i++) {
+      if (i >= options.size()) {
+        optionArray[i].name = "";
+        optionArray[i].enabled = false;
+      } else {
+        optionArray[i].name = options[i].name;
+        optionArray[i].enabled = true;
+      }
+    }
+    return optionArray;
+  }
+
+  uint32_t GetDefaultOption(Pinetime::Controllers::Settings::WeatherFormat currentOption) {
+    for (size_t i = 0; i < options.size(); i++) {
+      if (options[i].weatherFormat == currentOption) {
+        return i;
+      }
+    }
+    return 0;
+  }
+}
+
+SettingWeatherFormat::SettingWeatherFormat(Pinetime::Controllers::Settings& settingsController)
+  : checkboxList(
+      0,
+      1,
+      "Weather format",
+      Symbols::clock,
+      GetDefaultOption(settingsController.GetWeatherFormat()),
+      [&settings = settingsController](uint32_t index) {
+        settings.SetWeatherFormat(options[index].weatherFormat);
+        settings.SaveSettings();
+      },
+      CreateOptionArray()) {
+}
+
+SettingWeatherFormat::~SettingWeatherFormat() {
+  lv_obj_clean(lv_scr_act());
+}




diff --git a/src/displayapp/screens/settings/SettingWeatherFormat.h b/src/displayapp/screens/settings/SettingWeatherFormat.h
new file mode 100644
index 0000000000000000000000000000000000000000..a3d2bf4b661699fc5c44f59ab2c2c01ec8a49c3c
--- /dev/null
+++ b/src/displayapp/screens/settings/SettingWeatherFormat.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <array>
+#include <cstdint>
+#include <lvgl/lvgl.h>
+
+#include "components/settings/Settings.h"
+#include "displayapp/screens/Screen.h"
+#include "displayapp/screens/CheckboxList.h"
+
+namespace Pinetime {
+
+  namespace Applications {
+    namespace Screens {
+
+      class SettingWeatherFormat : public Screen {
+      public:
+        explicit SettingWeatherFormat(Pinetime::Controllers::Settings& settingsController);
+        ~SettingWeatherFormat() override;
+
+      private:
+        CheckboxList checkboxList;
+      };
+    }
+  }
+}




diff --git a/src/displayapp/screens/settings/Settings.h b/src/displayapp/screens/settings/Settings.h
index 3f8097538e5d021993664488b87e33ae49aeb944..a21b4ccd858a66163a629a1ac95c27c3350a85a9 100644
--- a/src/displayapp/screens/settings/Settings.h
+++ b/src/displayapp/screens/settings/Settings.h
@@ -29,7 +29,7 @@
         static constexpr int entriesPerScreen = 4;
 
         // Increment this when more space is needed
-        static constexpr int nScreens = 3;
+        static constexpr int nScreens = 4;
 
         static constexpr std::array<List::Applications, entriesPerScreen * nScreens> entries {{
           {Symbols::sun, "Display", Apps::SettingDisplay},
@@ -39,12 +39,14 @@           {Symbols::home, "Watch face", Apps::SettingWatchFace},
 
           {Symbols::shoe, "Steps", Apps::SettingSteps},
           {Symbols::clock, "Date&Time", Apps::SettingSetDateTime},
+          {Symbols::cloudSunRain, "Weather", Apps::SettingWeatherFormat},
           {Symbols::batteryHalf, "Battery", Apps::BatteryInfo},
-          {Symbols::clock, "Chimes", Apps::SettingChimes},
 
+          {Symbols::clock, "Chimes", Apps::SettingChimes},
           {Symbols::tachometer, "Shake Calib.", Apps::SettingShakeThreshold},
           {Symbols::check, "Firmware", Apps::FirmwareValidation},
           {Symbols::bluetooth, "Bluetooth", Apps::SettingBluetooth},
+
           {Symbols::list, "About", Apps::SysInfo},
 
           // {Symbols::none, "None", Apps::None},