From 25250fc9c8730d958eb4b7417bac2be0686a6eaf Mon Sep 17 00:00:00 2001 From: Tomasz Rybarski Date: Wed, 26 Jan 2022 14:09:24 +0100 Subject: [PATCH] [BH-1314] Home Screen Layouts Selectable Layouts can be changed in Settings-Clock Face --- image/assets/lang/English.json | 1 + image/user/db/settings_bell_002.sql | 3 +- module-apps/apps-common/CMakeLists.txt | 1 + .../widgets/spinners/ItemSpinner.hpp | 150 ++++++++++++++++++ .../widgets/spinners/SpinnerPolicies.hpp | 90 ++++++++++- .../apps-common/widgets/spinners/Spinners.hpp | 4 +- .../ApplicationBellMain.cpp | 16 +- .../presenters/HomeScreenPresenter.cpp | 2 +- .../ApplicationBellSettings.cpp | 16 +- .../application-bell-settings/CMakeLists.txt | 6 + .../ApplicationBellSettings.hpp | 3 +- .../models/LayoutModel.cpp | 26 +++ .../presenter/LayoutWindowPresenter.cpp | 119 ++++++++++++++ .../presenter/LayoutWindowPresenter.hpp | 54 +++++++ .../windows/BellSettingsLayoutWindow.cpp | 89 +++++++++++ .../windows/BellSettingsLayoutWindow.hpp | 32 ++++ .../windows/BellSettingsWindow.cpp | 4 +- .../BellHybrid/apps/common/CMakeLists.txt | 1 + .../include/common/models/LayoutModel.hpp | 36 +++++ .../common/src/layouts/HomeScreenLayouts.cpp | 2 + .../services/db/include/db/SystemSettings.hpp | 6 +- 21 files changed, 649 insertions(+), 12 deletions(-) create mode 100644 module-apps/apps-common/widgets/spinners/ItemSpinner.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/models/LayoutModel.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.hpp create mode 100644 products/BellHybrid/apps/common/include/common/models/LayoutModel.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 008345a20d556501cb16b587fd510dd508d5b8b2..16425ffd6fd63eb5299fd165ee7ab44407593345 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -612,6 +612,7 @@ "app_bell_settings_time_units": "Time", "app_bell_settings_temp_scale": "Temperature scale", "app_bell_settings_language": "Language", + "app_bell_settings_layout": "Clock face", "app_bell_settings_about": "About", "app_bell_settings_about_product": "Mudita Harmony", "app_bell_settings_about_version": "OS version: $VERSION", diff --git a/image/user/db/settings_bell_002.sql b/image/user/db/settings_bell_002.sql index 31a6f1d266772f66364d8ea596cc84d796fcef9c..17c825674d01a17b51eede44761234b4c6e5baad 100644 --- a/image/user/db/settings_bell_002.sql +++ b/image/user/db/settings_bell_002.sql @@ -1,4 +1,4 @@ --- Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +-- Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. -- For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md -- ----------- insert default values ---------------------- @@ -45,6 +45,7 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES ('bedtime_time','21:00'), ('bedtime_tone','Evening Horizon'), ('bedtime_duration','5'), + ('layout','ClassicWithTemp'), ('\ServiceEink\\display_inverted_mode', '0'); diff --git a/module-apps/apps-common/CMakeLists.txt b/module-apps/apps-common/CMakeLists.txt index 4228fcea0c6df77f7608e822c1f8e37f76303dad..90d449714ed226ad6c96019d066d33b5121f01ba 100644 --- a/module-apps/apps-common/CMakeLists.txt +++ b/module-apps/apps-common/CMakeLists.txt @@ -69,6 +69,7 @@ target_sources(apps-common models/SongsModelInterface.hpp widgets/spinners/GenericSpinner.hpp + widgets/spinners/ItemSpinner.hpp widgets/spinners/SpinnerPolicies.hpp widgets/spinners/Spinners.hpp ) diff --git a/module-apps/apps-common/widgets/spinners/ItemSpinner.hpp b/module-apps/apps-common/widgets/spinners/ItemSpinner.hpp new file mode 100644 index 0000000000000000000000000000000000000000..8a05721080513f5952e8aae69c766acf6cd4df77 --- /dev/null +++ b/module-apps/apps-common/widgets/spinners/ItemSpinner.hpp @@ -0,0 +1,150 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "SpinnerPolicies.hpp" +#include + +namespace gui +{ + template class ItemSpinner : public Item + { + public: + using Range = typename Policy::Range; + using Type = typename Policy::Type; + + using OnValueChanged = std::function; + + explicit ItemSpinner(Item *parent, + Range range, + Boundaries boundaries = Boundaries::Continuous, + Orientation orientation = Orientation::Vertical); + + [[nodiscard]] Type getCurrentValue() const noexcept; + void setCurrentValue(Type val); + void setRange(Range range); + + void setFocusEdges(RectangleEdge edges); + bool onInput(const InputEvent &inputEvent) override; + [[nodiscard]] bool isAtMin() const; + [[nodiscard]] bool isAtMax() const; + + OnValueChanged onValueChanged; + + private: + void stepNext(); + void stepPrevious(); + bool isPreviousEvent(const InputEvent &inputEvent); + bool isNextEvent(const InputEvent &inputEvent); + void update(); + void invoke(); + + Policy policy; + RectangleEdge focusEdges = RectangleEdge::Bottom; + Orientation orientation = Orientation::Vertical; + gui::Item *currentLayout = nullptr; + }; + + template + ItemSpinner::ItemSpinner(Item *parent, + ItemSpinner::Range range, + Boundaries boundaries, + Orientation orientation) + : Item(), policy{range, boundaries}, orientation(orientation) + { + this->parent = parent; + if (parent != nullptr) { + parent->addWidget(this); + } + } + + template void ItemSpinner::setFocusEdges(RectangleEdge edges) + { + focusEdges = edges; + } + + template void ItemSpinner::setRange(Range range) + { + policy.updateRange(range); + update(); + } + + template void ItemSpinner::setCurrentValue(const Type val) + { + policy.set(val); + update(); + } + + template typename ItemSpinner::Type ItemSpinner::getCurrentValue() const noexcept + { + return policy.get(); + } + + template bool ItemSpinner::isPreviousEvent(const InputEvent &inputEvent) + { + return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_DOWN)) || + (orientation == Orientation::Horizontal && inputEvent.is(KeyCode::KEY_LEFT)); + } + + template bool ItemSpinner::isNextEvent(const InputEvent &inputEvent) + { + return (orientation == Orientation::Vertical && inputEvent.is(KeyCode::KEY_UP)) || + (orientation == Orientation::Horizontal && inputEvent.is(KeyCode::KEY_RIGHT)); + } + + template bool ItemSpinner::onInput(const InputEvent &inputEvent) + { + if (inputEvent.isShortRelease()) { + if (isPreviousEvent(inputEvent)) { + stepPrevious(); + return true; + } + else if (isNextEvent(inputEvent)) { + stepNext(); + return true; + } + } + return false; + } + + template void ItemSpinner::stepNext() + { + if (policy.next()) { + update(); + invoke(); + } + } + + template void ItemSpinner::stepPrevious() + { + if (policy.previous()) { + update(); + invoke(); + } + } + + template void ItemSpinner::update() + { + if (currentLayout) { + this->removeWidget(currentLayout); + } + currentLayout = policy.get(); + this->addWidget(currentLayout); + informContentChanged(); + } + template void ItemSpinner::invoke() + { + if (onValueChanged) { + onValueChanged(getCurrentValue()); + } + } + template bool ItemSpinner::isAtMin() const + { + return policy.isAtMin(); + } + template bool ItemSpinner::isAtMax() const + { + return policy.isAtMax(); + } +} // namespace gui diff --git a/module-apps/apps-common/widgets/spinners/SpinnerPolicies.hpp b/module-apps/apps-common/widgets/spinners/SpinnerPolicies.hpp index e696c247aa9463b8c91d6038e3dd3e5f1d76e87b..96cb599ca6b159afc6b301134f3354e9aa20dd05 100644 --- a/module-apps/apps-common/widgets/spinners/SpinnerPolicies.hpp +++ b/module-apps/apps-common/widgets/spinners/SpinnerPolicies.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -105,6 +105,94 @@ namespace gui const Boundaries boundaries{}; }; + template class WidgetPolicy + { + public: + using Range = std::vector; + using Type = ValType; + + WidgetPolicy(Range range, Boundaries boundaries) : range{range}, boundaries{boundaries} + {} + + ValType get() const + { + return pos < range.size() ? range[pos] : ValType{}; + } + + void set(ValType val) + { + for (auto i = 0U; i < range.size(); i++) { + if (range[i] == val) { + pos = i; + break; + } + } + } + + bool next() + { + bool ret{true}; + if (pos >= upRange()) { + if (boundaries == Boundaries::Continuous) { + pos = 0; + } + else { + pos = upRange(); + ret = false; + } + } + else { + pos++; + } + return ret; + } + + bool previous() + { + bool ret{true}; + if (pos <= 0) { + if (boundaries == Boundaries::Continuous) { + pos = upRange(); + } + else { + pos = 0; + ret = false; + } + } + else { + pos--; + } + return ret; + } + + void updateRange(Range newRange) + { + if (range != newRange) { + range = newRange; + pos = 0; + } + } + + [[nodiscard]] bool isAtMin() const + { + return pos == 0; + } + [[nodiscard]] bool isAtMax() const + { + return pos == upRange(); + } + + private: + std::uint32_t upRange() const + { + return range.size() - 1; + } + + Range range; + std::uint32_t pos{}; + const Boundaries boundaries{}; + }; + template class DefaultNumericFormatter { public: diff --git a/module-apps/apps-common/widgets/spinners/Spinners.hpp b/module-apps/apps-common/widgets/spinners/Spinners.hpp index 29b187a5dc677cee51f00a7b5949b23477105ec2..383632a0e3366e858c25af1b62e62ec4a792969f 100644 --- a/module-apps/apps-common/widgets/spinners/Spinners.hpp +++ b/module-apps/apps-common/widgets/spinners/Spinners.hpp @@ -1,9 +1,10 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once #include "GenericSpinner.hpp" +#include "ItemSpinner.hpp" namespace gui { @@ -11,6 +12,7 @@ namespace gui using UIntegerSpinner = GenericSpinner>; using UIntegerSpinnerFixed = GenericSpinner>>; using IntegerSpinner = GenericSpinner>; + using WidgetSpinner = ItemSpinner>; template using ModelDelegateSpinner = GenericSpinner>; } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp index 45f9f0cdbc28ea10d14169cfb67cdce25315a06b..4de61d32258dd76051a232431ffb9ebbf14f0768 100644 --- a/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp +++ b/products/BellHybrid/apps/application-bell-main/ApplicationBellMain.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "include/application-bell-main/ApplicationBellMain.hpp" @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -91,9 +92,16 @@ namespace app void ApplicationBellMain::createUserInterface() { windowsFactory.attach(gui::name::window::main_window, [this](ApplicationCommon *app, const std::string &name) { - auto window = std::make_unique(app, homeScreenPresenter); - // TODO: To be replaced with settings db read - setHomeScreenLayout("ClassicWithTemp"); + auto timeModel = std::make_unique(); + auto batteryModel = std::make_unique(app); + auto temperatureModel = std::make_unique(app); + auto alarmModel = std::make_unique(app); + auto layoutModel = std::make_unique(app); + homeScreenPresenter = std::make_shared( + app, std::move(alarmModel), std::move(batteryModel), std::move(temperatureModel), std::move(timeModel)); + auto window = std::make_unique(app, homeScreenPresenter); + auto selectedLayout = layoutModel->getValue(); + setHomeScreenLayout(selectedLayout); return window; }); diff --git a/products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp b/products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp index b8efa55373901d2e94f51c1fe0be2fe4a002b75f..4c4444cefabba50b612f6a08e2add702fe3326c8 100644 --- a/products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-main/presenters/HomeScreenPresenter.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "application-bell-main/presenters/HomeScreenPresenter.hpp" diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index a4704fd01d62a318671dabdd3564c5b88be37937..5cf8371f750e8de399737469e2627ea71700e556 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -1,8 +1,9 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "ApplicationBellSettings.hpp" #include "presenter/TimeUnitsPresenter.hpp" +#include "presenter/LayoutWindowPresenter.hpp" #include "models/TemperatureUnitModel.hpp" #include "models/AboutYourBellModel.hpp" #include "models/alarm_settings/AlarmSettingsListItemProvider.hpp" @@ -17,6 +18,7 @@ #include "presenter/FrontlightPresenter.hpp" #include "windows/AboutYourBellWindow.hpp" #include "windows/BellSettingsLanguageWindow.hpp" +#include "windows/BellSettingsLayoutWindow.hpp" #include "windows/BellSettingsFrontlightWindow.hpp" #include "windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.hpp" #include "windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp" @@ -30,12 +32,15 @@ #include #include +#include #include #include +#include #include #include #include #include +#include #include #include #include @@ -88,6 +93,15 @@ namespace app return std::make_unique(app, std::move(presenter), name); }); + windowsFactory.attach( + gui::window::name::bellSettingsLayout, [this](ApplicationCommon *app, const std::string &name) { + auto layoutModel = std::make_unique(this); + auto timeModel = std::make_unique(); + auto presenter = std::make_unique( + this, std::move(layoutModel), std::move(timeModel)); + return std::make_unique(app, std::move(presenter), name); + }); + windowsFactory.attach( gui::BellSettingsFrontlightWindow::name, [](ApplicationCommon *app, const std::string &name) { auto model = std::make_unique(app); diff --git a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt index 80e3cf17f2e534951651df4a6bd9dd9d75dd66c9..cdf7b9d77ad0d39e6931e800e6114d297478ef5f 100644 --- a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt @@ -35,12 +35,14 @@ target_sources(application-bell-settings models/alarm_settings/SnoozeListItemProvider.cpp models/alarm_settings/SnoozeSettingsModel.cpp models/alarm_settings/SettingsListItemProvider.cpp + models/LayoutModel.cpp presenter/BedtimeSettingsPresenter.cpp presenter/TimeUnitsPresenter.cpp presenter/FrontlightPresenter.cpp presenter/AboutYourBellWindowPresenter.cpp presenter/LanguageWindowPresenter.cpp + presenter/LayoutWindowPresenter.cpp presenter/alarm_settings/AlarmSettingsPresenter.cpp presenter/alarm_settings/PrewakeUpPresenter.cpp presenter/alarm_settings/SnoozePresenter.cpp @@ -57,6 +59,7 @@ target_sources(application-bell-settings windows/BellSettingsWindow.cpp windows/AboutYourBellWindow.cpp windows/BellSettingsLanguageWindow.cpp + windows/BellSettingsLayoutWindow.cpp windows/BellSettingsFrontlightWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.cpp @@ -79,6 +82,7 @@ target_sources(application-bell-settings presenter/FrontlightPresenter.hpp presenter/AboutYourBellWindowPresenter.hpp presenter/LanguageWindowPresenter.hpp + presenter/LayoutWindowPresenter.hpp presenter/alarm_settings/AlarmSettingsPresenter.hpp presenter/alarm_settings/PrewakeUpPresenter.hpp presenter/alarm_settings/SnoozePresenter.hpp @@ -96,6 +100,7 @@ target_sources(application-bell-settings windows/BellSettingsWindow.hpp windows/AboutYourBellWindow.hpp windows/BellSettingsLanguageWindow.hpp + windows/BellSettingsLayoutWindow.hpp windows/BellSettingsFrontlightWindow.hpp windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.hpp @@ -119,6 +124,7 @@ target_link_libraries(application-bell-settings bell::db bell::alarms bell::app-main + bell::appmgr service-appmgr apps-common PUBLIC diff --git a/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp index 8ecfa6d721bbcfaa03a96f086da53b5c028fbe25..8bcdf8c2b5402b8e87bb91405f522ab1e4296ce5 100644 --- a/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp +++ b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/ApplicationBellSettings.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -17,6 +17,7 @@ namespace gui::window::name inline constexpr auto bellSettingsFrontlight = "BellSettingsFrontlight"; inline constexpr auto bellSettingsHomeView = "BellSettingsHomeView"; inline constexpr auto bellSettingsLanguage = "BellSettingsLanguage"; + inline constexpr auto bellSettingsLayout = "BellSettingsLayout"; inline constexpr auto bellSettingsBedtimeTone = "BellSettingsBedtimeTone"; inline constexpr auto bellSettingsFactoryReset = "BellSettingsFactoryReset"; } // namespace gui::window::name diff --git a/products/BellHybrid/apps/application-bell-settings/models/LayoutModel.cpp b/products/BellHybrid/apps/application-bell-settings/models/LayoutModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..361aa54bf796362d285a81c27f431d4c645b949a --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/models/LayoutModel.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include + +#include +#include + +namespace app::bell_settings +{ + + LayoutModel::LayoutModel(ApplicationCommon *app) + { + settings.init(service::ServiceProxy{app->weak_from_this()}); + } + + std::string LayoutModel::getValue() const + { + return settings.getValue(bell::settings::Layout::layout, settings::SettingsScope::Global); + } + + void LayoutModel::setValue(const std::string &value) const + { + settings.setValue(bell::settings::Layout::layout, value, settings::SettingsScope::Global); + } +} // namespace app::bell_settings \ No newline at end of file diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..fad1ff3ca6b3925143f624080432c704cca833fe --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.cpp @@ -0,0 +1,119 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "LayoutWindowPresenter.hpp" +#include +#include +#include +#include + +#include +#include +#include + +constexpr auto alarmTime = 1000 * 60 * 60 * 12; +constexpr auto clockTime = 1000 * 60 * 60 * 12; +constexpr Store::Battery batteryState = { + .levelState = Store::Battery::LevelState::Normal, + .state = Store::Battery::State::Discharging, + .level = 100, +}; +constexpr utils::temperature::Temperature temperature = { + .unit = utils::temperature::Temperature::Unit::Celsius, + .value = 21.0f, +}; + +namespace app::bell_settings +{ + LayoutWindowPresenter::LayoutWindowPresenter(app::ApplicationCommon *app, + std::unique_ptr &&layoutModel, + std::unique_ptr &&timeModel) + : app(app), layoutModel{std::move(layoutModel)}, timeModel{std::move(timeModel)} + { + initLayoutOptions(); + } + + std::vector LayoutWindowPresenter::getLayouts() const + { + std::vector layouts; + + for (auto const &option : layoutOptions) { + layouts.push_back(option.first); + } + + return layouts; + } + + gui::Item *LayoutWindowPresenter::getSelectedLayout() const + { + const auto layoutSelected = layoutModel->getValue(); + + for (auto const &option : layoutOptions) { + if (option.second == layoutSelected) { + return option.first; + } + } + + return layoutOptions.at(0).first; + } + + void LayoutWindowPresenter::setLayout(gui::Item *selectedLayout) + { + for (auto const &option : layoutOptions) { + if (option.first == selectedLayout) { + layoutModel->setValue(option.second); + auto layoutChangeRequest = std::make_shared(option.second); + app->bus.sendUnicast(layoutChangeRequest, service::name::appmgr); + break; + } + } + } + + void LayoutWindowPresenter::initLayoutOptions() + { + auto layoutsList = gui::homeScreenLayouts(); + + auto layoutClassicWithTemp = layoutsList.at("ClassicWithTemp")(); + layoutClassicWithTemp->setAlarmEdit(false); + layoutClassicWithTemp->setAlarmActive(true); + layoutClassicWithTemp->setTime(clockTime); + // layoutClassicWithTemp->setTimeFormat(timeModel->getTimeFormat()); + layoutClassicWithTemp->setAlarmTime(alarmTime); + layoutClassicWithTemp->setBatteryLevelState(batteryState); + layoutClassicWithTemp->setViewState(app::home_screen::ViewState::Activated); + layoutClassicWithTemp->setTemperature(temperature); + + auto layoutClassicWithBattery = layoutsList.at("ClassicWithBattery")(); + layoutClassicWithBattery->setAlarmEdit(false); + layoutClassicWithBattery->setAlarmActive(true); + layoutClassicWithBattery->setTime(clockTime); + // Commented out to remove "AM"/"PM" from time spinner + // layoutClassicWithBattery->setTimeFormat(timeModel->getTimeFormat()); + layoutClassicWithBattery->setAlarmTime(alarmTime); + layoutClassicWithBattery->setBatteryLevelState(batteryState); + layoutClassicWithBattery->setViewState(app::home_screen::ViewState::Activated); + + auto layoutClassicWithAmPm = layoutsList.at("ClassicWithAmPm")(); + layoutClassicWithAmPm->setAlarmEdit(false); + layoutClassicWithAmPm->setAlarmActive(true); + layoutClassicWithAmPm->setTime(clockTime); + // layoutClassicWithAmPm->setTimeFormat(timeModel->getTimeFormat()); + layoutClassicWithAmPm->setAlarmTime(alarmTime); + layoutClassicWithAmPm->setBatteryLevelState(batteryState); + layoutClassicWithAmPm->setViewState(app::home_screen::ViewState::Activated); + + auto layoutClassic = layoutsList.at("Classic")(); + layoutClassic->setAlarmEdit(false); + layoutClassic->setAlarmActive(true); + layoutClassic->setTime(clockTime); + // layoutClassic->setTimeFormat(timeModel->getTimeFormat()); + layoutClassic->setAlarmTime(alarmTime); + layoutClassic->setBatteryLevelState(batteryState); + layoutClassic->setViewState(app::home_screen::ViewState::Activated); + + layoutOptions.push_back({layoutClassicWithTemp->getLayout(), "ClassicWithTemp"}); + layoutOptions.push_back({layoutClassicWithBattery->getLayout(), "ClassicWithBattery"}); + layoutOptions.push_back({layoutClassicWithAmPm->getLayout(), "ClassicWithAmPm"}); + layoutOptions.push_back({layoutClassic->getLayout(), "Classic"}); + } +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5e64b23261be23b84a2bfe83e7f732913903dfae --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/LayoutWindowPresenter.hpp @@ -0,0 +1,54 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include + +namespace app::bell_settings +{ + class LayoutWindowContract + { + public: + class View + { + public: + virtual ~View() = default; + }; + + class Presenter : public BasePresenter + { + public: + virtual std::vector getLayouts() const = 0; + virtual gui::Item *getSelectedLayout() const = 0; + virtual void setLayout(gui::Item *selectedLayout) = 0; + }; + }; + + class LayoutWindowPresenter : public LayoutWindowContract::Presenter + { + private: + app::ApplicationCommon *app{}; + std::unique_ptr layoutModel; + std::unique_ptr timeModel; + std::vector> layoutOptions; + void initLayoutOptions(); + + public: + explicit LayoutWindowPresenter(app::ApplicationCommon *app, + std::unique_ptr &&layoutModel, + std::unique_ptr &&timeModel); + + std::vector getLayouts() const override; + gui::Item *getSelectedLayout() const override; + void setLayout(gui::Item *selectedLayout) override; + }; +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d8a1951107242471adab69928cb13b7112f3882f --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.cpp @@ -0,0 +1,89 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellSettingsLayoutWindow.hpp" +#include +#include +#include + +namespace gui +{ + BellSettingsLayoutWindow::BellSettingsLayoutWindow( + app::ApplicationCommon *app, + std::unique_ptr &&presenter, + const std::string &name) + : AppWindow(app, name), presenter{std::move(presenter)} + { + this->presenter->attach(this); + buildInterface(); + } + + void BellSettingsLayoutWindow::buildInterface() + { + AppWindow::buildInterface(); + + statusBar->setVisible(false); + header->setTitleVisibility(false); + navBar->setVisible(false); + + auto layouts = presenter->getLayouts(); + spinner = new WidgetSpinner(this, {layouts.begin(), layouts.end()}, Boundaries::Fixed); + spinner->setSize(style::window_width, style::window_height); + spinner->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + spinner->setFocusEdges(RectangleEdge::None); + auto selectedLayout = presenter->getSelectedLayout(); + spinner->setCurrentValue(selectedLayout); + + createArrowsOverlay(0, 0, style::window_width, style::window_height); + arrowLeft->setVisible(!spinner->isAtMin()); + arrowRight->setVisible(!spinner->isAtMax()); + + spinner->onValueChanged = [this](const auto &) { + arrowLeft->setVisible(!spinner->isAtMin()); + arrowRight->setVisible(!spinner->isAtMax()); + }; + setFocusItem(spinner); + } + + void BellSettingsLayoutWindow::createArrowsOverlay(unsigned int x, unsigned y, unsigned int w, unsigned int h) + { + auto arrowsOverlay = new HBox{this, x, y, w, h}; + arrowsOverlay->setEdges(gui::RectangleEdge::None); + arrowLeft = new Image("bell_arrow_left_W_M"); + arrowLeft->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center)); + arrowLeft->activeItem = false; + arrowLeft->setEdges(RectangleEdge::None); + arrowsOverlay->addWidget(arrowLeft); + + arrowRight = new Image("bell_arrow_right_W_M"); + arrowRight->setAlignment(Alignment(Alignment::Horizontal::Right, Alignment::Vertical::Center)); + arrowRight->activeItem = false; + arrowRight->setEdges(RectangleEdge::None); + + auto rectFiller = new gui::Rect(arrowsOverlay, + 0U, + 0U, + arrowsOverlay->getWidth() - arrowLeft->getWidth() - arrowRight->getWidth(), + arrowsOverlay->getHeight()); + + rectFiller->setMaximumSize(arrowsOverlay->getWidth(), arrowsOverlay->getHeight()); + rectFiller->setEdges(RectangleEdge::None); + + arrowsOverlay->addWidget(arrowRight); + } + bool BellSettingsLayoutWindow::onInput(const InputEvent &inputEvent) + { + if (spinner->onInput(inputEvent)) { + return true; + } + else if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) { + presenter->setLayout(spinner->getCurrentValue()); + application->switchWindow( + window::bell_finished::defaultName, + BellFinishedWindowData::Factory::create("circle_success_big", gui::name::window::main_window)); + return true; + } + return AppWindow::onInput(inputEvent); + } + +} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..04cd90f4833774c1d8c2520675ff9ffed4c552cc --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsLayoutWindow.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include + +#include + +namespace gui +{ + class BellSettingsLayoutWindow : public AppWindow, public app::bell_settings::LayoutWindowContract::View + { + public: + BellSettingsLayoutWindow(app::ApplicationCommon *app, + std::unique_ptr &&presenter, + const std::string &name = gui::window::name::bellSettingsLayout); + + void buildInterface() override; + bool onInput(const gui::InputEvent &inputEvent) override; + + private: + void createArrowsOverlay(unsigned int x, unsigned y, unsigned int w, unsigned int h); + + std::unique_ptr presenter; + Image *arrowLeft{}; + Image *arrowRight{}; + WidgetSpinner *spinner = nullptr; + }; +} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp index 9dff1abd5cfe96fe5ff19f9c0780f6d51b5d0fd8..f1031f89b006478770a04e4791357d5d7acbafab 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AboutYourBellWindow.hpp" @@ -75,6 +75,8 @@ namespace gui this)); }; + addWinSettings( + utils::translate("app_bell_settings_layout"), gui::window::name::bellSettingsLayout, defaultCallback); addWinSettings(utils::translate("app_bell_settings_alarm_settings"), BellSettingsAlarmSettingsMenuWindow::name, defaultCallback); diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index e2d2f627321439bdcbfbd617030fc9fbd5674511..09990efd952777db546172d6242729a022a3a3d1 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -76,6 +76,7 @@ target_sources(application-bell-common include/common/models/FrontlightModel.hpp include/common/models/AlarmSettingsModel.hpp include/common/models/AbstractAlarmSettingsModel.hpp + include/common/models/LayoutModel.hpp include/common/popups/presenter/AlarmActivatedPresenter.hpp include/common/popups/AlarmActivatedWindow.hpp include/common/popups/AlarmDeactivatedWindow.hpp diff --git a/products/BellHybrid/apps/common/include/common/models/LayoutModel.hpp b/products/BellHybrid/apps/common/include/common/models/LayoutModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..998ab76ff94a9e71d21e0ee622de5adc13be2cb6 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/models/LayoutModel.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include + +namespace app +{ + class ApplicationCommon; +} + +namespace app::bell_settings +{ + + class AbstractLayoutModel + { + public: + virtual ~AbstractLayoutModel() = default; + virtual std::string getValue() const = 0; + virtual void setValue(const std::string &value) const = 0; + }; + + class LayoutModel : public AbstractLayoutModel + { + public: + explicit LayoutModel(ApplicationCommon *app); + std::string getValue() const override; + void setValue(const std::string &value) const override; + + private: + mutable settings::Settings settings; + }; +} // namespace app::bell_settings \ No newline at end of file diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp index 61d8050614f6501b3ded99153be02ded103816bf..76ee7fd2c34d98fba8c9cf8869ad9bee68508bd9 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayouts.cpp @@ -3,6 +3,7 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include +#include #include #include #include @@ -12,6 +13,7 @@ namespace gui std::map homeScreenLayouts() { return {{"ClassicWithTemp", []() { return new HomeScreenLayoutClassicWithTemp("ClassicWithTemp"); }}, + {"Classic", []() { return new HomeScreenLayoutClassic("Classic"); }}, {"ClassicWithAmPm", []() { return new HomeScreenLayoutClassicWithAmPm("ClassicWithAmPm"); }}, {"ClassicWithBattery", []() { return new HomeScreenLayoutClassicWithBattery("ClassicWithBattery"); }}}; }; diff --git a/products/BellHybrid/services/db/include/db/SystemSettings.hpp b/products/BellHybrid/services/db/include/db/SystemSettings.hpp index e3cfb71e62691c3c4d0f8d6eca4c247ad475d2d6..276eb8e8a443167454905e8df232ab72795293af 100644 --- a/products/BellHybrid/services/db/include/db/SystemSettings.hpp +++ b/products/BellHybrid/services/db/include/db/SystemSettings.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -35,4 +35,8 @@ namespace bell::settings constexpr inline auto tone = "bedtime_tone"; constexpr inline auto duration = "bedtime_duration"; } // namespace Bedtime + namespace Layout + { + constexpr inline auto layout = "layout"; + } // namespace Layout }; // namespace bell::settings