From e415112fb009e02e6233447192c2414eddcce12e Mon Sep 17 00:00:00 2001 From: Mateusz Piesta Date: Wed, 24 Nov 2021 08:31:19 +0100 Subject: [PATCH] [BH-1220] Various critical bug fixes BH-1220 - Hide memory info from About screen BH-1224 - Removed Svenska language BH-1226 - Onboarding trigger set to light click BH-1243 - Implemented proper snooze settings flow --- products/BellHybrid/CMakeLists.txt | 1 + .../OnBoardingLanguageWindowPresenter.cpp | 4 +- .../OnBoardingLanguageWindowPresenter.hpp | 4 +- .../models/advanced/AboutYourBellModel.cpp | 3 + .../alarm_settings/SnoozeListItemProvider.cpp | 79 +++++++++++++------ .../advanced/LanguageWindowPresenter.cpp | 4 +- .../advanced/LanguageWindowPresenter.hpp | 4 +- .../advanced/AboutYourBellListItem.cpp | 2 +- .../windows/advanced/AboutYourBellWindow.cpp | 7 +- .../windows/advanced/AboutYourBellWindow.hpp | 4 + .../BellHybrid/apps/common/CMakeLists.txt | 1 + .../apps/common/include/common/Languages.hpp | 39 +++++++++ .../include/common/widgets/ListItems.hpp | 3 +- .../apps/common/src/widgets/ListItems.cpp | 15 ++-- .../common/src/windows/BellWelcomeWindow.cpp | 2 +- .../BellHybrid/config/ProductConfig.in.hpp | 1 + 16 files changed, 126 insertions(+), 47 deletions(-) create mode 100644 products/BellHybrid/apps/common/include/common/Languages.hpp diff --git a/products/BellHybrid/CMakeLists.txt b/products/BellHybrid/CMakeLists.txt index 37b52c6e2f452751c4cd16a45e95625b41844a8a..619315d737a9072fd390061011abd3081414774c 100644 --- a/products/BellHybrid/CMakeLists.txt +++ b/products/BellHybrid/CMakeLists.txt @@ -104,4 +104,5 @@ add_subdirectory(services) add_subdirectory(sys) option(CONFIG_ENABLE_TEMP "Enable displaying temperature" OFF) +option(CONFIG_SHOW_MEMORY_INFO "Enable displaying memory info" OFF) configure_file(config/ProductConfig.in.hpp ${CMAKE_BINARY_DIR}/ProductConfig.hpp @ONLY) diff --git a/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.cpp index 595473a47969c34ea8bab9c20dabf70bee93de8c..39d18d10a5eda2200af41ccd2730c5232e1789e7 100644 --- a/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.cpp @@ -11,9 +11,7 @@ namespace app::OnBoarding std::vector OnBoardingLanguageWindowPresenter::getLanguages() { - auto languages = loader.getAvailableDisplayLanguages(); - std::sort(languages.begin(), languages.end()); - return languages; + return languages.getSupportedLanguages(); } unsigned OnBoardingLanguageWindowPresenter::getSelectedLanguageIndex() diff --git a/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.hpp index 1f8d35b693efc1990c199719515aa86b8db0d90d..7d332a876766c5f50e921d73aba816994434b16c 100644 --- a/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.hpp +++ b/products/BellHybrid/apps/application-bell-onboarding/presenter/OnBoardingLanguageWindowPresenter.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ namespace app::OnBoarding class OnBoardingLanguageWindowPresenter : public OnBoardingLanguageWindowContract::Presenter { private: - utils::LangLoader loader; + common::Languages languages; app::ApplicationCommon *app; public: diff --git a/products/BellHybrid/apps/application-bell-settings/models/advanced/AboutYourBellModel.cpp b/products/BellHybrid/apps/application-bell-settings/models/advanced/AboutYourBellModel.cpp index 7e30c863670cc2e61c8dfffad9b7bc1515b0f3c0..741334178c0d057c3f7f8af030c71a9f2f30de2c 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/advanced/AboutYourBellModel.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/advanced/AboutYourBellModel.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include @@ -46,6 +47,7 @@ namespace app::bell_settings utils::translate("app_bell_settings_advanced_about_version"), gui::AboutYourBellListItem::TokenMap({{"$VERSION", std::string(VERSION)}}))); +#if CONFIG_SHOW_MEMORY_INFO == 1 struct statvfs stat; const auto result = statvfs(purefs::dir::getRootDiskPath().c_str(), &stat); if (result < 0) { @@ -60,6 +62,7 @@ namespace app::bell_settings utils::translate("app_bell_settings_advanced_about_storage_text"), gui::AboutYourBellListItem::TokenMap( {{"$USED_MEMORY", std::to_string(usedMB)}, {"$TOTAL_MEMORY", std::to_string(totalMB)}}))); +#endif internalData.push_back( new gui::AboutYourBellListItem(utils::translate("app_bell_settings_advanced_about_info_title"), diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp index 86492e760ec0a59f844fefc117ad09a70c7a3481..12f7525f6149bbcc0eadd8125c5ab604bd17bc5b 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp @@ -11,15 +11,46 @@ namespace app::bell_settings { using namespace gui; - enum Intervals + NumWithStringListItem::NumWithStringSpinner::Range getDefaultChimeIntervalRange() { - Interval_1 = 1, - Interval_2 = 2, - Interval_5 = 5, - Interval_10 = 10, - Interval_15 = 15, - Interval_30 = 30 - }; + const UTF8 minStr = utils::translate("common_minute_short"); + return { + NumWithStringListItem::Value{utils::translate("app_settings_toggle_off")}, + NumWithStringListItem::Value{1, minStr}, + NumWithStringListItem::Value{2, minStr}, + NumWithStringListItem::Value{3, minStr}, + NumWithStringListItem::Value{5, minStr}, + }; + } + + NumWithStringListItem::NumWithStringSpinner::Range transformChimeIntervalsRange(const std::uint32_t chimeLength) + { + auto chimeIntervals = getDefaultChimeIntervalRange(); + + chimeIntervals.erase( + std::remove_if(chimeIntervals.begin() + 1, + chimeIntervals.end(), + [chimeLength](const auto &e) { return e.getValue().value() >= chimeLength; }), + chimeIntervals.end()); + + return chimeIntervals; + } + + std::optional calculateCurrentChimeIntervalValue( + const NumWithStringListItem::NumWithStringSpinner::Range &range, + const NumWithStringListItem::Value &chimeInterval) + { + if (range.size() == 1) { + return {}; + } + + if (chimeInterval.getValue() && (chimeInterval.getValue().value() >= range.back().getValue().value())) { + return range.back(); + } + else { + return chimeInterval; + } + } SnoozeListItemProvider::SnoozeListItemProvider(AbstractSnoozeSettingsModel &model, std::vector chimeTonesRange) @@ -66,33 +97,31 @@ namespace app::bell_settings internalData.emplace_back(chimeLength); - const UTF8 minStr = utils::translate("common_minute_short"); - const auto range = NumWithStringListItem::NumWithStringSpinner::Range{NumWithStringListItem::Value{0, minStr}}; - auto chimeInterval = new NumWithStringListItem( model.getSnoozeChimeInterval(), - range, + getDefaultChimeIntervalRange(), utils::translate("app_bell_settings_alarm_settings_snooze_chime_interval"), utils::translate("app_bell_settings_alarm_settings_snooze_chime_interval_bot_desc")); + chimeLength->setValue(); internalData.emplace_back(chimeInterval); chimeLength->onProceed = [chimeInterval, chimeLength, this]() { if (chimeInterval != nullptr) { - auto val = chimeLength->getCurrentValue(); - NumWithStringListItem::NumWithStringSpinner::Range chimeRange; - const UTF8 minStr = utils::translate("common_minute_short"); - chimeRange.push_back(NumWithStringListItem::Value{utils::translate("app_alarm_clock_no_snooze")}); - for (unsigned int i = 1; i <= val; i++) { - if ((i != Intervals::Interval_1) && (i != Intervals::Interval_2) && (i != Intervals::Interval_5) && - (i != Intervals::Interval_10) && (i != Intervals::Interval_15) && - (i != Intervals::Interval_30)) { - continue; - } - chimeRange.push_back(NumWithStringListItem::Value{i, minStr}); + const auto currentChimeLength = chimeLength->getCurrentValue(); + const auto currentChimeInterval = chimeInterval->getCurrentValue(); + const auto calculatedRange = transformChimeIntervalsRange(currentChimeLength); + const auto calculatedChimeInterval = + calculateCurrentChimeIntervalValue(calculatedRange, currentChimeInterval); + + if (calculatedChimeInterval) { + chimeInterval->getSpinner()->setRange(calculatedRange); + chimeInterval->getSpinner()->setCurrentValue(calculatedChimeInterval.value()); + chimeInterval->setArrowsVisibility(); + } + else { + this->onExit(); } - chimeInterval->getSpinner()->setRange(chimeRange); - chimeInterval->setArrowsVisibility(chimeRange); } return false; }; diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp index 6aa5525282478f680f24784264a339ce25695993..483979096fee0e087369ab00a711c3eb2fc90419 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.cpp @@ -11,9 +11,7 @@ namespace app::bell_settings std::vector LanguageWindowPresenter::getLanguages() const { - auto languages = loader.getAvailableDisplayLanguages(); - std::sort(languages.begin(), languages.end()); - return languages; + return languages.getSupportedLanguages(); } std::string LanguageWindowPresenter::getSelectedLanguage() const diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp index 0507ea82a60960032484630559d2d37685f10061..45ff5bdee1bb46027e33c3cb2357b54de2e97a72 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/advanced/LanguageWindowPresenter.hpp @@ -5,7 +5,7 @@ #include #include -#include +#include #include #include @@ -33,7 +33,7 @@ namespace app::bell_settings class LanguageWindowPresenter : public LanguageWindowContract::Presenter { private: - utils::LangLoader loader; + common::Languages languages; app::ApplicationCommon *app{}; public: diff --git a/products/BellHybrid/apps/application-bell-settings/widgets/advanced/AboutYourBellListItem.cpp b/products/BellHybrid/apps/application-bell-settings/widgets/advanced/AboutYourBellListItem.cpp index 785e9a81ea4f17846c1033c10577dc248d8f6412..699882bc72bcefb9fae0fb6a4e77c438f7a61d73 100644 --- a/products/BellHybrid/apps/application-bell-settings/widgets/advanced/AboutYourBellListItem.cpp +++ b/products/BellHybrid/apps/application-bell-settings/widgets/advanced/AboutYourBellListItem.cpp @@ -14,7 +14,7 @@ namespace gui { setMinimumSize(bell_settings_style::about_your_bell_window::list_item::width, bell_settings_style::about_your_bell_window::list_item::height); - setMargins(Margins(0, style::margins::big, 0, style::margins::big)); + setMargins(Margins(0, style::margins::big, 0, style::margins::huge)); activeItem = false; body = new VBox(this, 0, 0, 0, 0); diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.cpp index ae70f7689e05267b0d7184316039c3c9fe78c3d1..aebe6aa2a6811025189436154495db4fba9ea0f4 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.cpp @@ -28,11 +28,12 @@ namespace gui list = new ListView(this, style::window::default_left_margin, - style::window::default_vertical_pos, - style::listview::body_width_with_scroll, - style::window::default_body_height, + top_margin, + width, + height, presenter->getPagesProvider(), listview::ScrollBarType::Fixed); + list->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); setFocusItem(list); list->rebuildList(); diff --git a/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.hpp index 98fc0c2390e79417cc6cdd9a057b044684934a17..ae5c6235cd21131d683c52d1f9e419b899b38b0e 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/advanced/AboutYourBellWindow.hpp @@ -18,6 +18,10 @@ namespace gui std::shared_ptr presenter); private: + static constexpr auto height = 400; + static constexpr auto width = 380; + static constexpr auto top_margin = 41; + void buildInterface() override; ListView *list{}; diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index f3327e2d5b0d89ed51a0a887c840ac656c2ce633..30e903e2a859a00d029b2eb29dd5afb8fdb010f2 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -40,6 +40,7 @@ target_sources(application-bell-common src/options/OptionBellMenu.cpp src/options/BellOptionsNavigation.cpp PUBLIC + include/common/Languages.hpp include/common/BellListItemProvider.hpp include/common/SoundsRepository.hpp include/common/BellPowerOffPresenter.hpp diff --git a/products/BellHybrid/apps/common/include/common/Languages.hpp b/products/BellHybrid/apps/common/include/common/Languages.hpp new file mode 100644 index 0000000000000000000000000000000000000000..5d6d901565543a8adaa83ee3cb0180ac48235759 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/Languages.hpp @@ -0,0 +1,39 @@ +// 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 common +{ + class Languages + { + public: + std::vector getSupportedLanguages() const + { + auto languages = loader.getAvailableDisplayLanguages(); + languages.erase( + std::remove_if(languages.begin(), languages.end(), [this](const auto &lang) { return matcher(lang); }), + languages.end()); + std::sort(languages.begin(), languages.end()); + return languages; + } + + private: + bool matcher(const std::string_view language) const + { + const auto result = std::find(excludedLanguages.begin(), excludedLanguages.end(), language); + return result != excludedLanguages.end(); + } + + static constexpr std::array excludedLanguages = {{"Svenska"}}; + utils::LangLoader loader; + }; + +} // namespace common diff --git a/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp b/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp index d63cd5fec1b19f9a92d751664396a8b9f4297e59..161a277d54fc9496d0695841a010025329156dc2 100644 --- a/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp +++ b/products/BellHybrid/apps/common/include/common/widgets/ListItems.hpp @@ -63,7 +63,8 @@ namespace gui { return spinner; } - void setArrowsVisibility(const NumWithStringSpinner::Range &range); + NumWithStringSpinner::Type getCurrentValue(); + void setArrowsVisibility(); private: NumWithStringSpinner *spinner{}; diff --git a/products/BellHybrid/apps/common/src/widgets/ListItems.cpp b/products/BellHybrid/apps/common/src/widgets/ListItems.cpp index ef634f7128da004163e5bc2cb1fdff13ecb67ce2..41f38384f11feb77f169ee5bad4b75b13f4029b8 100644 --- a/products/BellHybrid/apps/common/src/widgets/ListItems.cpp +++ b/products/BellHybrid/apps/common/src/widgets/ListItems.cpp @@ -103,7 +103,7 @@ namespace gui inputCallback = [&, range](Item &item, const InputEvent &event) { const auto result = OnInputCallback(event); bottomText->setVisible(spinner->getCurrentValue().getValue().has_value()); - setArrowsVisibility(range); + setArrowsVisibility(); return result; }; @@ -117,7 +117,7 @@ namespace gui const auto val = spinner->getCurrentValue().getValue(); model.setValue(not val ? 0 : *val); }; - setValue = [&model, this, range]() { + setValue = [&model, this]() { const auto modelValue = model.getValue(); if (modelValue > 0) { spinner->setCurrentValue(Value{modelValue, minStr}); @@ -125,7 +125,7 @@ namespace gui else { spinner->setCurrentValue(Value{minStr}); } - setArrowsVisibility(range); + setArrowsVisibility(); }; } @@ -134,10 +134,13 @@ namespace gui return not spinner->getCurrentValue().getValue().has_value(); } - void NumWithStringListItem::setArrowsVisibility(const NumWithStringSpinner::Range &range) + void NumWithStringListItem::setArrowsVisibility() { - const auto selectedVal = spinner->getCurrentValue(); - body->setMinMaxArrowsVisibility(selectedVal == range.front(), selectedVal == range.back()); + body->setMinMaxArrowsVisibility(spinner->isAtMin(), spinner->isAtMax()); + } + NumWithString NumWithStringListItem::getCurrentValue() + { + return spinner->getCurrentValue(); } UTF8ListItem::UTF8ListItem(AbstractSettingsModel &model, diff --git a/products/BellHybrid/apps/common/src/windows/BellWelcomeWindow.cpp b/products/BellHybrid/apps/common/src/windows/BellWelcomeWindow.cpp index b6bbfc11aaacf1de8753a790d905cb6e77f591a7..ae125c3abd8acd887edc041f7e05fb7e9b46e671 100644 --- a/products/BellHybrid/apps/common/src/windows/BellWelcomeWindow.cpp +++ b/products/BellHybrid/apps/common/src/windows/BellWelcomeWindow.cpp @@ -57,7 +57,7 @@ namespace gui bool BellWelcomeWindow::onInput(const InputEvent &inputEvent) { - if (inputEvent.isKeyRelease(KeyCode::KEY_LF)) { + if (inputEvent.isKeyRelease(KeyCode::KEY_ENTER)) { if (onAction) { onAction(); } diff --git a/products/BellHybrid/config/ProductConfig.in.hpp b/products/BellHybrid/config/ProductConfig.in.hpp index b807e6d665373cd24fbdaa93c0bf7a0414754083..d235488ea2429f675e48eee4034a92d471c85d6b 100644 --- a/products/BellHybrid/config/ProductConfig.in.hpp +++ b/products/BellHybrid/config/ProductConfig.in.hpp @@ -4,3 +4,4 @@ #pragma once #cmakedefine01 CONFIG_ENABLE_TEMP +#cmakedefine01 CONFIG_SHOW_MEMORY_INFO