InfiniTime.git

ref: fc5424cb72e477c5f1bbfaeddb5c50b851a965ae

src/displayapp/screens/settings/SettingChimes.cpp


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include "displayapp/screens/settings/SettingChimes.h"
#include <lvgl/lvgl.h>
#include "displayapp/DisplayApp.h"
#include "displayapp/screens/Styles.h"
#include "displayapp/screens/Screen.h"
#include "displayapp/screens/Symbols.h"
#include <array>

using namespace Pinetime::Applications::Screens;

namespace {
  struct Option {
    Pinetime::Controllers::Settings::ChimesOption chimesOption;
    const char* name;
  };

  constexpr std::array<Option, 3> options = {{
    {Pinetime::Controllers::Settings::ChimesOption::None, "Off"},
    {Pinetime::Controllers::Settings::ChimesOption::Hours, "Every hour"},
    {Pinetime::Controllers::Settings::ChimesOption::HalfHours, "Every 30 mins"},
  }};

  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::ChimesOption currentOption) {
    for (size_t i = 0; i < options.size(); i++) {
      if (options[i].chimesOption == currentOption) {
        return i;
      }
    }
    return 0;
  }
}

SettingChimes::SettingChimes(Pinetime::Controllers::Settings& settingsController)
  : checkboxList(
      0,
      1,
      "Chimes",
      Symbols::clock,
      GetDefaultOption(settingsController.GetChimeOption()),
      [&settings = settingsController](uint32_t index) {
        settings.SetChimeOption(options[index].chimesOption);
        settings.SaveSettings();
      },
      CreateOptionArray()) {
}

SettingChimes::~SettingChimes() {
  lv_obj_clean(lv_scr_act());
}