aboutsummaryrefslogtreecommitdiffstats
path: root/src/displayapp/screens/settings
diff options
context:
space:
mode:
authorFintasticMan <finlay.neon.kid@gmail.com>2023-07-15 02:23:10 +0200
committerJF <JF002@users.noreply.github.com>2023-12-23 21:42:16 +0100
commitd889f3e4446107ce5bdd45c6791281e37cadf5b0 (patch)
treea0b7d59842dd0a1a97b524bc093bfe69948bd521 /src/displayapp/screens/settings
parentc04813b6d303f4b341e5c7df885809913e83060a (diff)
settings: Add settings item for weather format
Diffstat (limited to 'src/displayapp/screens/settings')
-rw-r--r--src/displayapp/screens/settings/SettingWeatherFormat.cpp63
-rw-r--r--src/displayapp/screens/settings/SettingWeatherFormat.h26
-rw-r--r--src/displayapp/screens/settings/Settings.h6
3 files changed, 93 insertions, 2 deletions
diff --git a/src/displayapp/screens/settings/SettingWeatherFormat.cpp b/src/displayapp/screens/settings/SettingWeatherFormat.cpp
new file mode 100644
index 00000000..4f37ede6
--- /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 00000000..a3d2bf4b
--- /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 3f809753..a21b4ccd 100644
--- a/src/displayapp/screens/settings/Settings.h
+++ b/src/displayapp/screens/settings/Settings.h
@@ -29,7 +29,7 @@ namespace Pinetime {
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 @@ namespace Pinetime {
{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},