diff --git a/src/components/settings/Settings.h b/src/components/settings/Settings.h index 9661a199..93f861f3 100644 --- a/src/components/settings/Settings.h +++ b/src/components/settings/Settings.h @@ -52,6 +52,11 @@ namespace Pinetime { Settings(Pinetime::Controllers::FS& fs); + Settings(const Settings&) = delete; + Settings& operator=(const Settings&) = delete; + Settings(Settings&&) = delete; + Settings& operator=(Settings&&) = delete; + void Init(); void SaveSettings(); @@ -135,14 +140,6 @@ namespace Pinetime { appMenu = menu; }; - void SetWatchfacesMenu(uint8_t menu) { - watchFacesMenu = menu; - }; - - uint8_t GetWatchfacesMenu() const { - return watchFacesMenu; - }; - uint8_t GetAppMenu() const { return appMenu; }; diff --git a/src/displayapp/screens/CheckboxList.cpp b/src/displayapp/screens/CheckboxList.cpp index 952d86da..42f9f57d 100644 --- a/src/displayapp/screens/CheckboxList.cpp +++ b/src/displayapp/screens/CheckboxList.cpp @@ -1,5 +1,5 @@ -#include "displayapp/screens/CheckboxList.h" #include "displayapp/DisplayApp.h" +#include "displayapp/screens/CheckboxList.h" #include "displayapp/screens/Styles.h" using namespace Pinetime::Applications::Screens; @@ -9,27 +9,21 @@ namespace { CheckboxList* screen = static_cast(obj->user_data); screen->UpdateSelected(obj, event); } - } CheckboxList::CheckboxList(const uint8_t screenID, const uint8_t numScreens, DisplayApp* app, - Controllers::Settings& settingsController, const char* optionsTitle, const char* optionsSymbol, - void (Controllers::Settings::*SetOptionIndex)(uint8_t), - uint8_t (Controllers::Settings::*GetOptionIndex)() const, + uint32_t originalValue, + std::functionOnValueChanged, std::array options) : Screen(app), screenID {screenID}, - settingsController {settingsController}, - SetOptionIndex {SetOptionIndex}, - GetOptionIndex {GetOptionIndex}, - options {options} { - - settingsController.SetWatchfacesMenu(screenID); - + OnValueChanged{std::move(OnValueChanged)}, + options {options}, + newValue{originalValue} { // Set the background to Black lv_obj_set_style_local_bg_color(lv_scr_act(), LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_BLACK); @@ -39,7 +33,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, pageIndicatorBasePoints[1].x = LV_HOR_RES - 1; pageIndicatorBasePoints[1].y = LV_VER_RES; - pageIndicatorBase = lv_line_create(lv_scr_act(), NULL); + pageIndicatorBase = lv_line_create(lv_scr_act(), nullptr); lv_obj_set_style_local_line_width(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicatorBase, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, lv_color_hex(0x111111)); lv_line_set_points(pageIndicatorBase, pageIndicatorBasePoints.data(), 2); @@ -52,7 +46,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, pageIndicatorPoints[1].x = LV_HOR_RES - 1; pageIndicatorPoints[1].y = indicatorPos + indicatorSize; - pageIndicator = lv_line_create(lv_scr_act(), NULL); + pageIndicator = lv_line_create(lv_scr_act(), nullptr); lv_obj_set_style_local_line_width(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, 3); lv_obj_set_style_local_line_color(pageIndicator, LV_LINE_PART_MAIN, LV_STATE_DEFAULT, LV_COLOR_GRAY); lv_line_set_points(pageIndicator, pageIndicatorPoints.data(), 2); @@ -89,7 +83,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, lv_obj_set_event_cb(cbOption[i], event_handler); SetRadioButtonStyle(cbOption[i]); - if (static_cast((settingsController.*GetOptionIndex)() - MaxItems * screenID) == i) { + if (static_cast(originalValue - MaxItems * screenID) == i) { lv_checkbox_set_checked(cbOption[i], true); } } @@ -98,6 +92,7 @@ CheckboxList::CheckboxList(const uint8_t screenID, CheckboxList::~CheckboxList() { lv_obj_clean(lv_scr_act()); + OnValueChanged(newValue); } void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { @@ -106,7 +101,7 @@ void CheckboxList::UpdateSelected(lv_obj_t* object, lv_event_t event) { if (strcmp(options[i], "")) { if (object == cbOption[i]) { lv_checkbox_set_checked(cbOption[i], true); - (settingsController.*SetOptionIndex)(MaxItems * screenID + i); + newValue = MaxItems * screenID + i; } else { lv_checkbox_set_checked(cbOption[i], false); } diff --git a/src/displayapp/screens/CheckboxList.h b/src/displayapp/screens/CheckboxList.h index 5bdd143e..4d27a62b 100644 --- a/src/displayapp/screens/CheckboxList.h +++ b/src/displayapp/screens/CheckboxList.h @@ -1,12 +1,12 @@ #pragma once -#include -#include -#include -#include -#include "displayapp/screens/Screen.h" #include "displayapp/Apps.h" -#include "components/settings/Settings.h" +#include "displayapp/screens/Screen.h" +#include +#include +#include +#include +#include namespace Pinetime { namespace Applications { @@ -14,34 +14,27 @@ namespace Pinetime { class CheckboxList : public Screen { public: static constexpr size_t MaxItems = 4; - CheckboxList(const uint8_t screenID, const uint8_t numScreens, DisplayApp* app, - Controllers::Settings& settingsController, const char* optionsTitle, const char* optionsSymbol, - void (Controllers::Settings::*SetOptionIndex)(uint8_t), - uint8_t (Controllers::Settings::*GetOptionIndex)() const, + uint32_t originalValue, + std::functionOnValueChanged, std::array options); - ~CheckboxList() override; - void UpdateSelected(lv_obj_t* object, lv_event_t event); private: const uint8_t screenID; - Controllers::Settings& settingsController; - const char* optionsTitle; - const char* optionsSymbol; - void (Controllers::Settings::*SetOptionIndex)(uint8_t); - uint8_t (Controllers::Settings::*GetOptionIndex)() const; + std::functionOnValueChanged; std::array options; std::array cbOption; std::array pageIndicatorBasePoints; std::array pageIndicatorPoints; lv_obj_t* pageIndicatorBase; lv_obj_t* pageIndicator; + uint32_t newValue; }; } } diff --git a/src/displayapp/screens/settings/SettingWatchFace.cpp b/src/displayapp/screens/settings/SettingWatchFace.cpp index 411cc898..ce1efaa2 100644 --- a/src/displayapp/screens/settings/SettingWatchFace.cpp +++ b/src/displayapp/screens/settings/SettingWatchFace.cpp @@ -3,8 +3,6 @@ #include "displayapp/DisplayApp.h" #include "displayapp/screens/CheckboxList.h" #include "displayapp/screens/Screen.h" -#include "displayapp/screens/Styles.h" -#include "displayapp/screens/Symbols.h" #include "components/settings/Settings.h" using namespace Pinetime::Applications::Screens; @@ -16,7 +14,7 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine : Screen(app), settingsController {settingsController}, screens {app, - settingsController.GetWatchfacesMenu(), + 0, {[this]() -> std::unique_ptr { return CreateScreen1(); }, @@ -28,7 +26,6 @@ SettingWatchFace::SettingWatchFace(Pinetime::Applications::DisplayApp* app, Pine SettingWatchFace::~SettingWatchFace() { lv_obj_clean(lv_scr_act()); - settingsController.SaveSettings(); } bool SettingWatchFace::OnTouchEvent(Pinetime::Applications::TouchEvents event) { @@ -40,11 +37,13 @@ std::unique_ptr SettingWatchFace::CreateScreen1() { return std::make_unique(0, 2, app, - settingsController, title, symbol, - &Controllers::Settings::SetClockFace, - &Controllers::Settings::GetClockFace, + settingsController.GetClockFace(), + [&settings = settingsController](uint32_t clockFace) { + settings.SetClockFace(clockFace); + settings.SaveSettings(); + }, watchfaces); } @@ -53,10 +52,12 @@ std::unique_ptr SettingWatchFace::CreateScreen2() { return std::make_unique(1, 2, app, - settingsController, title, symbol, - &Controllers::Settings::SetClockFace, - &Controllers::Settings::GetClockFace, + settingsController.GetClockFace(), + [&settings = settingsController](uint32_t clockFace) { + settings.SetClockFace(clockFace); + settings.SaveSettings(); + }, watchfaces); }