~aleteoryx/muditaos

ref: 3cc3f50f7b9364ffac38349238cd6d9aa243dc23 muditaos/module-apps/apps-common/popups/AlarmPopup.cpp -rw-r--r-- 7.3 KiB
3cc3f50f — Maciej Gibowicz [BH-1809][BH-1835] Add date format setting 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
// 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 <popups/data/AlarmPopupRequestParams.hpp>
#include <InputEvent.hpp>
#include <i18n/i18n.hpp>

#include <ImageBox.hpp>

using namespace style::popup::alarm;

namespace gui
{
    AlarmPopup::AlarmPopup(app::ApplicationCommon *app,
                           const std::string &name,
                           std::shared_ptr<app::popup::AlarmPopupPresenter> presenter)
        : AppWindow(app, name), app::popup::AlarmPopupContract::View(std::move(presenter))
    {
        buildInterface();
        getPresenter()->setRefreshWindowCallback([this]() {
            updateItems();
            refillText();
        });
    }

    void AlarmPopup::buildInterface()
    {
        AppWindow::buildInterface();

        addArcOverlay();
        createMainLayout();
        createLabels();
        createSnoozeButton();
    }

    void AlarmPopup::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if ((data != nullptr) && mode == ShowMode::GUI_SHOW_INIT) {
            auto params = dynamic_cast<AlarmPopupRequestParams *>(data);
            assert(params);

            const auto popupType = params->getPopupType();
            getPresenter()->resetModel();
            if (popupType == AlarmPopupType::AlarmRing) {
                getPresenter()->setModel(params->popRecord());
                refillText();
            }
            else if (popupType == AlarmPopupType::SnoozeCheck) {
                getPresenter()->setSnoozedRecord(params->popSnoozed());
                getPresenter()->processIfSnoozed();
            }
            updateItems();
        }
    }

    status_bar::Configuration AlarmPopup::configureStatusBar(status_bar::Configuration appConfiguration)
    {
        appConfiguration.enable(status_bar::Indicator::Time);
        appConfiguration.enable(status_bar::Indicator::PhoneMode);
        appConfiguration.enable(status_bar::Indicator::Battery);
        appConfiguration.enable(status_bar::Indicator::Signal);
        appConfiguration.enable(status_bar::Indicator::SimCard);
        appConfiguration.enable(status_bar::Indicator::Bluetooth);

        return appConfiguration;
    }

    bool AlarmPopup::onInput(const InputEvent &inputEvent)
    {
        if (inputEvent.isShortRelease(KeyCode::KEY_RF) || inputEvent.isLongRelease(KeyCode::KEY_RF)) {
            getPresenter()->stopAlarm();
            return true;
        }
        else if (inputEvent.isShortRelease(KeyCode::KEY_LF) && getPresenter()->haveSnoozedSkip()) {
            getPresenter()->skipToNextSnooze();
            return true;
        }

        return AppWindow::onInput(inputEvent);
    }

    void AlarmPopup::addArcOverlay()
    {
        auto arcOverlay = new gui::ImageBox(this,
                                            style::window::default_left_margin,
                                            style::popup::alarm::window::y,
                                            style::window::default_body_width,
                                            style::window::default_body_width,
                                            new Image(ImageCircle::name, ImageTypeSpecifier::W_G));
        arcOverlay->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
        arcOverlay->setEdges(RectangleEdge::None);
    }

    void AlarmPopup::createMainLayout()
    {
        body = new VBox(this,
                        style::window::default_left_margin,
                        style::popup::alarm::window::y,
                        style::window::default_body_width,
                        style::window::default_body_width);

        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::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->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));

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

        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);

        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::createSnoozeButton()
    {
        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;
        };

        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) {
            alarmTimeLabel->setText(getPresenter()->startedAt());
        }
        if (snoozeLabel) {
            snoozeLabel->setText(utils::translate("app_popup_alarm_snoozed_till") + std::string{" "} +
                                 getPresenter()->snoozedTill());
        }
        body->resizeItems();
    }
} // namespace gui