~aleteoryx/muditaos

ref: 1fff0a5115f78af1d5bccad88e366dd1d9663e36 muditaos/module-apps/application-alarm-clock/windows/CustomRepeatWindow.cpp -rw-r--r-- 2.4 KiB
1fff0a51 — Lukasz Mastalerz [BH-1768] Snooze mode with deep pressed knob 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CustomRepeatWindow.hpp"

#include <application-alarm-clock/data/AlarmsData.hpp>
#include <application-alarm-clock/widgets/AlarmClockStyle.hpp>

#include <InputEvent.hpp>

namespace app::alarmClock
{

    CustomRepeatWindow::CustomRepeatWindow(app::ApplicationCommon *app,
                                           std::unique_ptr<CustomRepeatWindowContract::Presenter> &&windowPresenter)
        : AppWindow(app, style::alarmClock::window::name::customRepeat), presenter{std::move(windowPresenter)}
    {
        presenter->attach(this);
        buildInterface();
    }

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

        navBar->setActive(gui::nav_bar::Side::Right, true);
        navBar->setActive(gui::nav_bar::Side::Center, true);
        navBar->setText(gui::nav_bar::Side::Right, utils::translate(style::strings::common::back));
        navBar->setText(gui::nav_bar::Side::Center, utils::translate(style::strings::common::save));

        setTitle(utils::translate("app_alarm_clock_custom_repeat_title"));
        list = new gui::ListView(this,
                                 style::alarmClock::window::listView_x,
                                 style::alarmClock::window::listView_y,
                                 style::alarmClock::window::listView_w,
                                 style::alarmClock::window::listView_h,
                                 presenter->getItemProvider(),
                                 gui::listview::ScrollBarType::None);
        setFocusItem(list);
    }

    void CustomRepeatWindow::onClose(gui::Window::CloseReason reason)
    {
        if (reason != CloseReason::PhoneLock) {
            presenter->eraseProviderData();
        }
    }

    void CustomRepeatWindow::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)
    {
        presenter->loadData();
    }

    bool CustomRepeatWindow::onInput(const gui::InputEvent &inputEvent)
    {
        if (AppWindow::onInput(inputEvent)) {
            return true;
        }

        if (inputEvent.isShortRelease(gui::KeyCode::KEY_ENTER)) {
            presenter->saveData();
            application->switchWindow(style::alarmClock::window::name::newEditAlarm, gui::ShowMode::GUI_SHOW_RETURN);
            return true;
        }
        return false;
    }
} // namespace app::alarmClock