From d7115fe5d7ff6cb699faeeb6e14b607c0c18cad4 Mon Sep 17 00:00:00 2001 From: Maciej-Mudita Date: Fri, 27 Jan 2023 17:47:49 +0100 Subject: [PATCH] [MOS-52] Fix the data displayed on snoozed alarms screen When we were currently in the snoozed alarms screen and a new alarm rang, the data was displayed incorrectly. --- module-apps/apps-common/popups/AlarmPopup.cpp | 95 ++++++++----------- module-apps/apps-common/popups/AlarmPopup.hpp | 19 ++-- .../popups/presenter/AlarmPresenter.hpp | 3 +- pure_changelog.md | 1 + 4 files changed, 51 insertions(+), 67 deletions(-) diff --git a/module-apps/apps-common/popups/AlarmPopup.cpp b/module-apps/apps-common/popups/AlarmPopup.cpp index 777065c413c835ac70330bd81e939d5891319a5c..2e3bece5e6f004e1bb66334004bb1273178201a4 100644 --- a/module-apps/apps-common/popups/AlarmPopup.cpp +++ b/module-apps/apps-common/popups/AlarmPopup.cpp @@ -1,16 +1,15 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AlarmPopup.hpp" #include "log/log.hpp" #include "time/dateCommon.hpp" -#include +#include #include #include #include -#include using namespace style::popup::alarm; @@ -23,13 +22,8 @@ namespace gui { buildInterface(); getPresenter()->setRefreshWindowCallback([this]() { - if (this->snoozeShow == SnoozeShow::First) { - addWindowElements(); - this->snoozeShow = SnoozeShow::Next; - } - else if (this->snoozeShow == SnoozeShow::Next) { - refillText(); - } + updateItems(); + refillText(); }); } @@ -39,6 +33,8 @@ namespace gui addArcOverlay(); createMainLayout(); + createLabels(); + createSnoozeButton(); } void AlarmPopup::onBeforeShow(ShowMode mode, SwitchData *data) @@ -47,30 +43,20 @@ namespace gui auto params = dynamic_cast(data); assert(params); + const auto popupType = params->getPopupType(); getPresenter()->resetModel(); - if (params->getPopupType() == AlarmPopupType::AlarmRing) { + if (popupType == AlarmPopupType::AlarmRing) { getPresenter()->setModel(params->popRecord()); - addWindowElements(); + refillText(); } - else if (params->getPopupType() == AlarmPopupType::SnoozeCheck) { + else if (popupType == AlarmPopupType::SnoozeCheck) { getPresenter()->setSnoozedRecord(params->popSnoozed()); getPresenter()->processIfSnoozed(); } + updateItems(); } } - void AlarmPopup::addWindowElements() - { - navBar->setActive(nav_bar::Side::Right, true); - navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::stop)); - - addAlarmLabels(); - if (getPresenter()->isSnoozeAble()) { - showSnoozeButton(); - } - body->resizeItems(); - } - status_bar::Configuration AlarmPopup::configureStatusBar(status_bar::Configuration appConfiguration) { appConfiguration.enable(status_bar::Indicator::Time); @@ -119,62 +105,54 @@ namespace gui body->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); body->setEdges(RectangleEdge::None); + + navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::stop)); + navBar->setActive(nav_bar::Side::Right, true); + + navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select)); + navBar->setActive(nav_bar::Side::Center, false); + + navBar->setText(nav_bar::Side::Left, utils::translate(style::strings::common::skip)); + navBar->setActive(nav_bar::Side::Left, false); } - void AlarmPopup::addAlarmLabels() + void AlarmPopup::createLabels() { alarmTimeLabel = new gui::TextFixedSize(body); alarmTimeLabel->drawUnderline(false); alarmTimeLabel->setFont(style::window::font::largelight); alarmTimeLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); - alarmTimeLabel->setText(getPresenter()->startedAt()); alarmTimeLabel->setMaximumWidth(style::window::default_body_width); alarmTimeLabel->setMinimumHeightToFitText(); alarmTimeLabel->setMargins(Margins( 0, style::popup::alarm::AlarmTimeLabel::top_margin, 0, style::popup::alarm::AlarmTimeLabel::bottom_margin)); - auto alarmLabel = new gui::TextFixedSize(body); + alarmLabel = new gui::TextFixedSize(body); alarmLabel->drawUnderline(false); alarmLabel->setFont(style::window::font::mediumlight); alarmLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Top)); alarmLabel->setText(utils::translate("app_popup_alarm_text")); alarmLabel->setMinimumWidthToFitText(alarmLabel->getText()); alarmLabel->setMinimumHeightToFitText(); - } - void AlarmPopup::addSnoozeLabel() - { - auto snoozeLabelBox = new VBox(body); + snoozeLabelBox = new VBox(body); snoozeLabelBox->setMinimumSize(style::window::default_body_width, style::popup::alarm::SnoozeLabel::h); snoozeLabelBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); snoozeLabelBox->setMargins(Margins(0, style::popup::alarm::SnoozeLabel::top_margin, 0, 0)); snoozeLabelBox->setEdges(RectangleEdge::None); - if (getPresenter()->haveSnoozedSkip()) { - snoozeLabel = new gui::TextFixedSize(snoozeLabelBox); - snoozeLabel->drawUnderline(false); - snoozeLabel->setFont(style::window::font::mediumlight); - snoozeLabel->setAlignment( - gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom)); - snoozeLabel->setText(utils::translate("app_popup_alarm_snoozed_till") + std::string{" "} + - getPresenter()->snoozedTill()); - snoozeLabel->setMaximumWidth(style::window::default_body_width); - snoozeLabel->setMinimumHeightToFitText(); - - navBar->setActive(nav_bar::Side::Left, true); - navBar->setText(nav_bar::Side::Left, utils::translate(style::strings::common::skip)); - } + snoozeLabel = new gui::TextFixedSize(snoozeLabelBox); + snoozeLabel->drawUnderline(false); + snoozeLabel->setFont(style::window::font::mediumlight); + snoozeLabel->setAlignment(gui::Alignment(gui::Alignment::Horizontal::Center, gui::Alignment::Vertical::Bottom)); + snoozeLabel->setMaximumWidth(style::window::default_body_width); + snoozeLabel->setMinimumHeightToFitText(); } - - void AlarmPopup::showSnoozeButton() + void AlarmPopup::createSnoozeButton() { - navBar->setActive(nav_bar::Side::Center, true); - navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::select)); - - addSnoozeLabel(); - - auto snoozeIcon = new ImageBoxWithText( + snoozeIcon = new ImageBoxWithText( body, new Image("snooze_icon", ImageTypeSpecifier::W_G), utils::translate("app_popup_snooze_text")); + snoozeIcon->activatedCallback = [=](gui::Item & /*item*/) { getPresenter()->snoozeHit(); return true; @@ -183,6 +161,15 @@ namespace gui setFocusItem(snoozeIcon); } + void AlarmPopup::updateItems() + { + snoozeLabel->setVisible(getPresenter()->haveSnoozedSkip()); + snoozeIcon->setVisible(getPresenter()->isSnoozeAble()); + navBar->setActive(nav_bar::Side::Left, getPresenter()->haveSnoozedSkip()); + navBar->setActive(nav_bar::Side::Center, getPresenter()->isSnoozeAble()); + body->resizeItems(); + } + void AlarmPopup::refillText() { if (alarmTimeLabel) { diff --git a/module-apps/apps-common/popups/AlarmPopup.hpp b/module-apps/apps-common/popups/AlarmPopup.hpp index cb347a913268470efa65215db4deaf9c0e834bd3..5f2e716cfa40b44fda03bc368948d90da5510e4b 100644 --- a/module-apps/apps-common/popups/AlarmPopup.hpp +++ b/module-apps/apps-common/popups/AlarmPopup.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -7,6 +7,7 @@ #include #include +#include #include @@ -37,11 +38,6 @@ namespace style::popup::alarm namespace gui { - enum class SnoozeShow - { - First, - Next - }; class AlarmPopup : public AppWindow, app::popup::AlarmPopupContract::View { public: @@ -53,19 +49,20 @@ namespace gui bool onInput(const InputEvent &inputEvent) override; status_bar::Configuration configureStatusBar(status_bar::Configuration appConfiguration) override; - virtual void showSnoozeButton() override; private: VBox *body = nullptr; + VBox *snoozeLabelBox = nullptr; + gui::TextFixedSize *alarmLabel = nullptr; gui::TextFixedSize *alarmTimeLabel = nullptr; gui::TextFixedSize *snoozeLabel = nullptr; - SnoozeShow snoozeShow = SnoozeShow::First; + gui::ImageBoxWithText *snoozeIcon = nullptr; void addArcOverlay(); void createMainLayout(); - void addAlarmLabels(); - void addSnoozeLabel(); - void addWindowElements(); + void createLabels(); + void createSnoozeButton(); + void updateItems(); void refillText(); }; diff --git a/module-apps/apps-common/popups/presenter/AlarmPresenter.hpp b/module-apps/apps-common/popups/presenter/AlarmPresenter.hpp index 322e2f48e041a0c26df163b89d286a5103dcb21f..ad0c5d6baabbaaa0de99b47a4a966ca16b9c9f0e 100644 --- a/module-apps/apps-common/popups/presenter/AlarmPresenter.hpp +++ b/module-apps/apps-common/popups/presenter/AlarmPresenter.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -63,7 +63,6 @@ namespace app::popup explicit View(std::shared_ptr presenter) : presenter(std::move(presenter)) {} virtual ~View() noexcept = default; - virtual void showSnoozeButton() = 0; }; class Presenter : public BasePresenter diff --git a/pure_changelog.md b/pure_changelog.md index d59d1e4c5dfbfdda7acf11b75e81d269cc3b16e8..268bca965ed258a46f6752b6c73e8160ec1b36d1 100644 --- a/pure_changelog.md +++ b/pure_changelog.md @@ -52,6 +52,7 @@ * Fixed displaying wrong screen after contact removal * Fixed improper font weight used in navbar * Fix for country code in new contact based on deleted one +* Fixed the data displayed on snoozed alarms screen ## [1.5.0 2022-12-20]