~aleteoryx/muditaos

ref: af960b6fac2fdd9e42072c4632ca769fce76f95f muditaos/module-apps/application-calendar/windows/CustomRepeatWindow.cpp -rw-r--r-- 3.2 KiB
af960b6f — Lucjan Bryndza [EGD-5146] Add read LFS block size from part 5 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CustomRepeatWindow.hpp"
#include "InputEvent.hpp"
#include "application-calendar/widgets/CheckBoxWithLabelItem.hpp"
#include "module-apps/application-calendar/data/CalendarData.hpp"
#include <Utils.hpp>
#include <gui/widgets/Window.hpp>

namespace gui
{

    CustomRepeatWindow::CustomRepeatWindow(app::Application *app, std::string name)
        : AppWindow(app, style::window::calendar::name::custom_repeat_window),
          customRepeatModel{std::make_shared<CustomRepeatModel>(this->application)}
    {
        buildInterface();
    }

    void CustomRepeatWindow::rebuild()
    {
        erase();
        buildInterface();
    }

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

        topBar->setActive(gui::TopBar::Elements::TIME, true);
        bottomBar->setActive(gui::BottomBar::Side::RIGHT, true);
        bottomBar->setText(gui::BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));

        setTitle(utils::localize.get("app_calendar_custom_repeat_title"));
        list = new gui::ListView(this,
                                 style::window::calendar::listView_x,
                                 style::window::calendar::listView_y,
                                 style::window::calendar::listView_w,
                                 style::window::calendar::listView_h,
                                 customRepeatModel);
        setFocusItem(list);
    }

    void CustomRepeatWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (mode == ShowMode::GUI_SHOW_INIT) {
            list->rebuildList();
        }

        auto recievedData = dynamic_cast<WeekDaysRepeatData *>(data);
        if (recievedData != nullptr) {
            weekDaysOptData = std::make_shared<WeekDaysRepeatData>(*recievedData);
        }
        else {
            weekDaysOptData = std::make_shared<WeekDaysRepeatData>();
        }
        customRepeatModel->loadData(weekDaysOptData);
    }

    bool CustomRepeatWindow::onInput(const InputEvent &inputEvent)
    {
        // check if any of the lower inheritance onInput methods catch the event
        if (Window::onInput(inputEvent)) {
            return true;
        }
        // process only if key is released
        if (!inputEvent.isShortPress())
            return false;

        switch (inputEvent.keyCode) {
        case KeyCode::KEY_RF: {
            if (weekDaysOptData != nullptr) {
                auto isCheckedData = customRepeatModel->getIsCheckedData();
                uint32_t i         = 0;
                for (auto checked : isCheckedData) {
                    weekDaysOptData->setData(i, checked);
                    ++i;
                }
                auto data = weekDaysOptData.get();
                application->switchWindow(style::window::calendar::name::new_edit_event,
                                          gui::ShowMode::GUI_SHOW_RETURN,
                                          std::make_unique<WeekDaysRepeatData>(*data));
                return true;
            }
        }
        default:
            break;
        }

        return false;
    }

} /* namespace gui */