|
| 1 | +#include "displayapp/screens/settings/SettingQuickAccess.h" |
| 2 | +#include <lvgl/lvgl.h> |
| 3 | +#include "displayapp/DisplayApp.h" |
| 4 | +#include "displayapp/screens/Styles.h" |
| 5 | +#include "displayapp/screens/Screen.h" |
| 6 | +#include "displayapp/screens/Symbols.h" |
| 7 | +#include <array> |
| 8 | + |
| 9 | +using namespace Pinetime::Applications::Screens; |
| 10 | + |
| 11 | +namespace { |
| 12 | + struct Option { |
| 13 | + Pinetime::Applications::Apps app; |
| 14 | + const char* name; |
| 15 | + }; |
| 16 | + |
| 17 | + constexpr std::array<Option, 3> options = {{ |
| 18 | + {Pinetime::Applications::Apps::Music, "Music"}, |
| 19 | + {Pinetime::Applications::Apps::HeartRate, "Heart Rate"}, |
| 20 | + {Pinetime::Applications::Apps::StopWatch, "Stopwatch"}, |
| 21 | + }}; |
| 22 | + |
| 23 | + std::array<CheckboxList::Item, CheckboxList::MaxItems> CreateOptionArray() { |
| 24 | + std::array<Pinetime::Applications::Screens::CheckboxList::Item, CheckboxList::MaxItems> optionArray; |
| 25 | + for (size_t i = 0; i < CheckboxList::MaxItems; i++) { |
| 26 | + if (i >= options.size()) { |
| 27 | + optionArray[i].name = ""; |
| 28 | + optionArray[i].enabled = false; |
| 29 | + } else { |
| 30 | + optionArray[i].name = options[i].name; |
| 31 | + optionArray[i].enabled = true; |
| 32 | + } |
| 33 | + } |
| 34 | + return optionArray; |
| 35 | + } |
| 36 | + |
| 37 | + uint32_t GetDefaultOption(Pinetime::Applications::Apps currentApp) { |
| 38 | + for (size_t i = 0; i < options.size(); i++) { |
| 39 | + if (options[i].app == currentApp) { |
| 40 | + return i; |
| 41 | + } |
| 42 | + } |
| 43 | + return 0; |
| 44 | + } |
| 45 | +} |
| 46 | + |
| 47 | +SettingQuickAccess::SettingQuickAccess(Pinetime::Controllers::Settings& settingsController) |
| 48 | + : checkboxList( |
| 49 | + 0, |
| 50 | + 1, |
| 51 | + "Quick Access", |
| 52 | + Symbols::list, |
| 53 | + GetDefaultOption(settingsController.GetQuickAccessApp()), |
| 54 | + [&settings = settingsController](uint32_t index) { |
| 55 | + settings.SetQuickAccessApp(options[index].app); |
| 56 | + settings.SaveSettings(); |
| 57 | + }, |
| 58 | + CreateOptionArray()) { |
| 59 | +} |
| 60 | + |
| 61 | +SettingQuickAccess::~SettingQuickAccess() { |
| 62 | + lv_obj_clean(lv_scr_act()); |
| 63 | +} |
0 commit comments