-
-
Notifications
You must be signed in to change notification settings - Fork 960
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
settings: Add settings item for weather format
- Loading branch information
1 parent
9375e77
commit a793da8
Showing
8 changed files
with
112 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#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()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters