~aleteoryx/muditaos

d7115fe5d7ff6cb699faeeb6e14b607c0c18cad4 — Maciej-Mudita 3 years ago e07f2db
[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.
M module-apps/apps-common/popups/AlarmPopup.cpp => module-apps/apps-common/popups/AlarmPopup.cpp +41 -54
@@ 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 <data/AlarmPopupRequestParams.hpp>

#include <popups/data/AlarmPopupRequestParams.hpp>
#include <InputEvent.hpp>
#include <i18n/i18n.hpp>

#include <ImageBox.hpp>
#include <ImageBoxWithText.hpp>

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<AlarmPopupRequestParams *>(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) {

M module-apps/apps-common/popups/AlarmPopup.hpp => module-apps/apps-common/popups/AlarmPopup.hpp +8 -11
@@ 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 <AppWindow.hpp>
#include <TextFixedSize.hpp>
#include <ImageBoxWithText.hpp>

#include <string>



@@ 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();
    };


M module-apps/apps-common/popups/presenter/AlarmPresenter.hpp => module-apps/apps-common/popups/presenter/AlarmPresenter.hpp +1 -2
@@ 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) : presenter(std::move(presenter))
            {}
            virtual ~View() noexcept        = default;
            virtual void showSnoozeButton() = 0;
        };

        class Presenter : public BasePresenter<AlarmPopupContract::View>

M pure_changelog.md => pure_changelog.md +1 -0
@@ 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]