From fd9d45423d6239294ff873045daaa856bf7cbe30 Mon Sep 17 00:00:00 2001 From: Maciej Gibowicz Date: Mon, 26 Feb 2024 15:17:18 +0100 Subject: [PATCH] [BH-1883] Add a low battery notification on home screen with quotes Below 20%, instead of quotes, the battery with percentage information about the charge level will appear on the main screen. --- harmony_changelog.md | 1 + .../HomeScreenLayoutClassicWithQuotes.hpp | 1 + .../src/layouts/HomeScreenLayoutClassic.cpp | 17 ++++++++--- .../HomeScreenLayoutClassicWithQuotes.cpp | 30 +++++++++++++------ 4 files changed, 36 insertions(+), 13 deletions(-) diff --git a/harmony_changelog.md b/harmony_changelog.md index c93b4be7cee9c23c96259cd7358643fc3e921e19..e52e4765276b5c6e4b447785a7fd0fb18c0a0ed7 100644 --- a/harmony_changelog.md +++ b/harmony_changelog.md @@ -10,6 +10,7 @@ * Added new clock face with quotes * Added a backend for quotes on home screen * Added progress bar to update process +* Added low battery notification on home screen with quotes ### Changed / Improved * Updated FSL drivers from NXP diff --git a/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassicWithQuotes.hpp b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassicWithQuotes.hpp index f78a1eb32bc1a07e692bb98b4523ae5def9f2d59..6ba12cc6c2a0559764032d14a25ba8bf0afd00a8 100644 --- a/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassicWithQuotes.hpp +++ b/products/BellHybrid/apps/common/include/common/layouts/HomeScreenLayoutClassicWithQuotes.hpp @@ -25,5 +25,6 @@ namespace gui private: void showQuotes(); void hideQuotes(); + void adjustWidgetBox(); }; }; // namespace gui diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp index 14dd5beea8a194c59707fa27e390d65dcf373cc0..57da9786edc71b9f3fecfdffe6cad938ec63fade 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassic.cpp @@ -304,9 +304,17 @@ namespace gui void HomeScreenLayoutClassic::setBatteryLevelState(const Store::Battery &batteryContext) { + const bool batteryVisibility = isBatteryVisibilityAllowed(batteryContext); battery->update(batteryContext.level, isBatteryCharging(batteryContext.state)); - battery->setVisible(isBatteryVisibilityAllowed(batteryContext)); + battery->setVisible(batteryVisibility); battery->informContentChanged(); + + if (batteryVisibility && (onShowMessage != nullptr)) { + onShowMessage(); + } + else if (!batteryVisibility && (onHideMessage != nullptr)) { + onHideMessage(); + } } void HomeScreenLayoutClassic::setTime(std::time_t newTime) @@ -358,15 +366,16 @@ namespace gui } auto HomeScreenLayoutClassic::updateUsbStatus(bool isConnected) -> void { + connectionStatus->show(isConnected); + connectionStatus->informContentChanged(); + adjustConnectionStatusPosition(); + if (isConnected && (onShowMessage != nullptr)) { onShowMessage(); } else if (!isConnected && (onHideMessage != nullptr)) { onHideMessage(); } - connectionStatus->show(isConnected); - connectionStatus->informContentChanged(); - adjustConnectionStatusPosition(); } auto HomeScreenLayoutClassic::adjustConnectionStatusPosition() -> void diff --git a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithQuotes.cpp b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithQuotes.cpp index 30b1b6ea2c60c1d078b7729594628557d93c1082..1c9a27d5d0365c33817b5be9f985ee2f3ed6695c 100644 --- a/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithQuotes.cpp +++ b/products/BellHybrid/apps/common/src/layouts/HomeScreenLayoutClassicWithQuotes.cpp @@ -7,11 +7,13 @@ #include #include #include +#include namespace { constexpr auto maxTimeBoxHeight{148U}; constexpr auto textBoxHeight{120U}; + constexpr auto infoBoxHeight{54U}; constexpr auto imgBoxHeight{52U}; constexpr auto imgTopMargin{10U}; @@ -30,9 +32,12 @@ namespace gui : HomeScreenLayoutClassic(std::move(name)) { buildInterface(); - onShowMessage = [this]() { hideQuotes(); }; + onShowMessage = [this]() { + hideQuotes(); + adjustWidgetBox(); + }; onHideMessage = [this]() { - if (!connectionStatus->isVisible()) { + if (!connectionStatus->isVisible() && !battery->visible) { showQuotes(); } }; @@ -61,14 +66,14 @@ namespace gui quoteImg->setMargins({0, imgTopMargin, 0, 0}); quoteImg->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); - /* We do not display information about the battery status at any time - * only about the status of the USB connection. */ - widgetBox->removeWidget(infoBox); widgetBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); - infoBox->setVisible(false); - /* Add item to body even if it won't fit to avoid manual memory - * management for item. */ - widgetBox->addWidget(infoBox); + + infoBox->setMinimumHeight(infoBoxHeight); + infoBox->setMaximumHeight(infoBoxHeight); + infoBox->setMargins(Margins(0, 0, 0, 0)); + + connectionBox->setMargins(Margins(0, 0, 0, 0)); + battery->setMargins(Margins(0, 0, 0, 0)); textBox = new VBox(nullptr); textBox->setMinimumSize(style::bell_base_layout::last_layout_w, textBoxHeight); @@ -137,4 +142,11 @@ namespace gui quotes->setText(quoteContent); } + void HomeScreenLayoutClassicWithQuotes::adjustWidgetBox() + { + infoBox->setVisible(battery->visible); + connectionBox->setVisible(connectionStatus->isVisible()); + widgetBox->informContentChanged(); + } + }; // namespace gui