From 37ee2ae4c967b07f56979ff6e9e7debab776b551 Mon Sep 17 00:00:00 2001 From: Przemyslaw Brudny Date: Wed, 29 Sep 2021 19:54:26 +0200 Subject: [PATCH] [BH-852] Bell settings language selector Bell settings language selector. --- image/assets/lang/English.json | 2 + .../apps-common/widgets/BellBaseLayout.cpp | 6 ++ .../apps-common/widgets/BellBaseLayout.hpp | 1 + .../ApplicationBellSettings.cpp | 22 ++++++ .../application-bell-settings/CMakeLists.txt | 4 ++ .../ApplicationBellSettings.hpp | 19 +++--- .../advanced/LanguageWindowPresenter.cpp | 26 +++++++ .../advanced/LanguageWindowPresenter.hpp | 46 +++++++++++++ .../advanced/BellSettingsAdvancedWindow.cpp | 2 + .../advanced/BellSettingsLanguageWindow.cpp | 67 +++++++++++++++++++ .../advanced/BellSettingsLanguageWindow.hpp | 32 +++++++++ 11 files changed, 218 insertions(+), 9 deletions(-) create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.cpp create mode 100644 products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 845d7c86da21dc0bb03dd53bf098292e175d0d0d..e15ec0512ec576acc20c334f7199c2168020acf4 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -581,6 +581,8 @@ "app_bell_settings_advanced": "Advanced", "app_bell_settings_advanced_time_units": "Time & units", "app_bell_settings_advanced_temp_scale": "Temperature scale", + "app_bell_settings_advanced_language": "Language", + "app_bell_settings_advanced_language_set": "Language is set", "app_bell_settings_advanced_about": "About", "app_bell_settings_advanced_about_product": "Mudita Harmony", "app_bell_settings_advanced_about_version": "OS version: $VERSION", diff --git a/module-apps/apps-common/widgets/BellBaseLayout.cpp b/module-apps/apps-common/widgets/BellBaseLayout.cpp index ef9a6db01f6e666222b4eb50c6adaae9f8cc44e2..01b6c22b73de73dc4470a5fa24d2ca5d5750bfdc 100644 --- a/module-apps/apps-common/widgets/BellBaseLayout.cpp +++ b/module-apps/apps-common/widgets/BellBaseLayout.cpp @@ -117,4 +117,10 @@ namespace gui item->setVisible(isVisible); } } + + void BellBaseLayout::setMinMaxArrowsVisibility(bool minCondition, bool maxCondition) + { + setArrowVisible(BellBaseLayout::Arrow::Left, !minCondition); + setArrowVisible(BellBaseLayout::Arrow::Right, !maxCondition); + } } // namespace gui diff --git a/module-apps/apps-common/widgets/BellBaseLayout.hpp b/module-apps/apps-common/widgets/BellBaseLayout.hpp index e61dfe50d9424b87ee191e155fd1d10598a88f72..543c191e7e4be977a96f13340e4f3fd6326b9330 100644 --- a/module-apps/apps-common/widgets/BellBaseLayout.hpp +++ b/module-apps/apps-common/widgets/BellBaseLayout.hpp @@ -48,6 +48,7 @@ namespace gui void resize(); void setArrowVisible(Arrow arrow, bool isVisible); + void setMinMaxArrowsVisibility(bool minCondition, bool maxCondition); private: HThreeBox *centerThreeBox{nullptr}; diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index 6359fefceaecc7e76eb80c3e0bd52a1d5b00aef4..c6b7a07b10ffa711b24cfa8111a717ac93f99114 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -18,6 +18,7 @@ #include "windows/advanced/AboutYourBellWindow.hpp" #include "windows/advanced/BellSettingsAdvancedWindow.hpp" #include "windows/advanced/BellSettingsTimeUnitsWindow.hpp" +#include "windows/advanced/BellSettingsLanguageWindow.hpp" #include "windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.hpp" #include "windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp" #include "windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp" @@ -33,6 +34,7 @@ #include #include #include +#include namespace app { @@ -51,6 +53,20 @@ namespace app } createUserInterface(); + connect(typeid(manager::GetCurrentDisplayLanguageResponse), [&](sys::Message *msg) { + if (gui::window::name::bellSettingsLanguage == getCurrentWindow()->getName()) { + + switchWindow(gui::BellFinishedWindow::defaultName, + gui::BellFinishedWindowData::Factory::create( + "big_check_W_G", + utils::translate("app_bell_settings_advanced_language_set"), + gui::window::name::bellSettingsAdvanced)); + + return sys::msgHandled(); + } + return sys::msgNotHandled(); + }); + return sys::ReturnCodes::Success; } @@ -75,6 +91,12 @@ namespace app return std::make_unique(app, std::move(presenter)); }); + windowsFactory.attach( + gui::window::name::bellSettingsLanguage, [&](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(this); + return std::make_unique(app, std::move(presenter), name); + }); + windowsFactory.attach( gui::window::name::bellSettingsFrontlight, [](ApplicationCommon *app, const std::string &name) { auto model = diff --git a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt index df79e51b6b0fec6d6a8bf1d961ae92b922186436..8b95796487b059e81c640811dc91ece7cf621aba 100644 --- a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt @@ -38,6 +38,7 @@ target_sources(application-bell-settings presenter/FrontlightPresenter.cpp presenter/TimeUnitsPresenter.cpp presenter/advanced/AboutYourBellWindowPresenter.cpp + presenter/advanced/LanguageWindowPresenter.cpp presenter/alarm_settings/AlarmSettingsPresenter.cpp presenter/alarm_settings/PrewakeUpPresenter.cpp presenter/alarm_settings/SnoozePresenter.cpp @@ -55,6 +56,7 @@ target_sources(application-bell-settings windows/BellSettingsWindow.cpp windows/advanced/AboutYourBellWindow.cpp windows/advanced/BellSettingsAdvancedWindow.cpp + windows/advanced/BellSettingsLanguageWindow.cpp windows/advanced/BellSettingsTimeUnitsWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.cpp @@ -76,6 +78,7 @@ target_sources(application-bell-settings presenter/FrontlightPresenter.hpp presenter/advanced/AboutYourBellWindowPresenter.hpp + presenter/advanced/LanguageWindowPresenter.hpp presenter/alarm_settings/AlarmSettingsPresenter.hpp presenter/alarm_settings/PrewakeUpPresenter.hpp presenter/alarm_settings/SnoozePresenter.hpp @@ -95,6 +98,7 @@ target_sources(application-bell-settings windows/BellSettingsTurnOffWindow.hpp windows/BellSettingsWindow.hpp windows/advanced/AboutYourBellWindow.hpp + windows/advanced/BellSettingsLanguageWindow.hpp windows/advanced/BellSettingsAdvancedWindow.hpp windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp windows/alarm_settings/BellSettingsAlarmSettingsMenuWindow.hpp 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 649d1c95c4a6e8cf5cc4fe644916afea0d39dde9..0beb12454781a25531c462336dba003f2cce68b3 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 @@ -8,15 +8,16 @@ namespace gui::window::name { - inline constexpr auto bellSettings = "BellSettings"; - inline constexpr auto bellSettingsAdvanced = "BellSettingsAdvanced"; - inline constexpr auto bellSettingsTimeUnits = "BellSettingsTimeUnits"; - inline constexpr auto bellSettingsDialog = "BellSettingsDialog"; - inline constexpr auto bellSettingsFinished = "BellSettingsFinished"; - inline constexpr auto bellSettingsFrontlight = "BellSettingsFrontlight"; - inline constexpr auto bellSettingsHomeView = "BellSettingsHomeView"; - inline constexpr auto bellSettingsBedtimeTone = "BellSettingsBedtimeTone"; - inline constexpr auto bellSettingsTurnOff = "BellSettingsTurnOff"; + inline constexpr auto bellSettings = "BellSettings"; + inline constexpr auto bellSettingsAdvanced = "BellSettingsAdvanced"; + inline constexpr auto bellSettingsTimeUnits = "BellSettingsTimeUnits"; + inline constexpr auto bellSettingsDialog = "BellSettingsDialog"; + inline constexpr auto bellSettingsFinished = "BellSettingsFinished"; + inline constexpr auto bellSettingsFrontlight = "BellSettingsFrontlight"; + inline constexpr auto bellSettingsHomeView = "BellSettingsHomeView"; + inline constexpr auto bellSettingsLanguage = "BellSettingsLanguage"; + inline constexpr auto bellSettingsBedtimeTone = "BellSettingsBedtimeTone"; + inline constexpr auto bellSettingsTurnOff = "BellSettingsTurnOff"; } // namespace gui::window::name namespace app diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a216f2a695d3c1bb56dcf7dcc44bea83ac97ffba --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "LanguageWindowPresenter.hpp" +#include + +namespace app::bell_settings +{ + LanguageWindowPresenter::LanguageWindowPresenter(app::ApplicationCommon *app) : app(app) + {} + + std::vector LanguageWindowPresenter::getLanguages() const + { + return loader.getAvailableDisplayLanguages(); + } + + std::string LanguageWindowPresenter::getSelectedLanguage() const + { + return utils::getDisplayLanguage(); + } + + void LanguageWindowPresenter::setLanguage(const std::string &selectedLanguage) + { + app::manager::Controller::changeDisplayLanguage(app, selectedLanguage); + } +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp new file mode 100644 index 0000000000000000000000000000000000000000..0507ea82a60960032484630559d2d37685f10061 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp @@ -0,0 +1,46 @@ +// Copyright (c) 2017-2021, 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 + +namespace app::bell_settings +{ + class LanguageWindowContract + { + public: + class View + { + public: + virtual ~View() = default; + }; + + class Presenter : public BasePresenter + { + public: + virtual std::vector getLanguages() const = 0; + virtual std::string getSelectedLanguage() const = 0; + virtual void setLanguage(const std::string &selectedLanguage) = 0; + }; + }; + + class LanguageWindowPresenter : public LanguageWindowContract::Presenter + { + private: + utils::LangLoader loader; + app::ApplicationCommon *app{}; + + public: + explicit LanguageWindowPresenter(app::ApplicationCommon *app); + + std::vector getLanguages() const override; + std::string getSelectedLanguage() const override; + void setLanguage(const std::string &selectedLanguage) override; + }; +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp index 5c31dd1a219d3de5695655819ad841677a81c50f..e23c24ff0514e8512b4f5951313adff2e1f7c1c5 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsAdvancedWindow.cpp @@ -45,6 +45,8 @@ namespace gui addWinSettings(utils::translate("app_bell_settings_advanced_time_units"), gui::window::name::bellSettingsTimeUnits); + addWinSettings(utils::translate("app_bell_settings_advanced_language"), + gui::window::name::bellSettingsLanguage); addWinSettings(utils::translate("app_bell_settings_advanced_frontlight"), gui::window::name::bellSettingsFrontlight); addWinSettings(utils::translate("app_bell_settings_advanced_about"), gui::AboutYourBellWindow::name); diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1e7225ea69fa5b7a40e593664150bc54bd19f428 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.cpp @@ -0,0 +1,67 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "BellSettingsLanguageWindow.hpp" +#include + +namespace gui +{ + BellSettingsLanguageWindow::BellSettingsLanguageWindow( + app::ApplicationCommon *app, + std::unique_ptr &&presenter, + const std::string &name) + : AppWindow(app, name), presenter{std::move(presenter)} + { + this->presenter->attach(this); + buildInterface(); + } + + void BellSettingsLanguageWindow::buildInterface() + { + AppWindow::buildInterface(); + + statusBar->setVisible(false); + header->setTitleVisibility(false); + bottomBar->setVisible(false); + + body = new BellBaseLayout(this, 0, 0, style::window_width, style::window_height, true); + + auto topMessage = new TextFixedSize(body->firstBox); + topMessage->setMaximumSize(style::bell_base_layout::w, style::bell_base_layout::outer_layouts_h); + topMessage->setFont(style::window::font::largelight); + topMessage->setEdges(gui::RectangleEdge::None); + topMessage->activeItem = false; + topMessage->setAlignment(Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Center)); + topMessage->setText(utils::translate("app_bell_settings_advanced_language")); + topMessage->drawUnderline(false); + + auto data = presenter->getLanguages(); + spinner = new UTF8Spinner({data.begin(), data.end()}, Boundaries::Fixed); + spinner->setMaximumSize(style::bell_base_layout::w, style::bell_base_layout::center_layout_h); + spinner->setFont(style::window::font::large); + spinner->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + spinner->setFocusEdges(RectangleEdge::None); + spinner->setCurrentValue(presenter->getSelectedLanguage()); + body->getCenterBox()->addWidget(spinner); + + setFocusItem(spinner); + body->resize(); + } + + bool BellSettingsLanguageWindow::onInput(const InputEvent &inputEvent) + { + if (spinner->onInput(inputEvent)) { + auto selectedLanguage = spinner->getCurrentValue(); + + body->setMinMaxArrowsVisibility(selectedLanguage == presenter->getLanguages().back(), + selectedLanguage == presenter->getLanguages().front()); + return true; + } + else if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) { + presenter->setLanguage(spinner->getCurrentValue()); + return true; + } + return AppWindow::onInput(inputEvent); + } + +} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..81c5416d14d1a21285f5e92a743333d3e51875e8 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/BellSettingsLanguageWindow.hpp @@ -0,0 +1,32 @@ +// Copyright (c) 2017-2021, 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 + +namespace gui +{ + class BellSettingsLanguageWindow : public AppWindow, public app::bell_settings::LanguageWindowContract::View + { + public: + BellSettingsLanguageWindow(app::ApplicationCommon *app, + std::unique_ptr &&presenter, + const std::string &name = gui::window::name::bellSettingsLanguage); + + void buildInterface() override; + bool onInput(const gui::InputEvent &inputEvent) override; + + private: + std::unique_ptr presenter; + + BellBaseLayout *body{}; + UTF8Spinner *spinner = nullptr; + }; +} // namespace gui