~aleteoryx/muditaos

ref: cc0ec423bfc250c7828d2d8c180709a48eb3caa3 muditaos/module-apps/application-alarm-clock/models/CustomRepeatModel.cpp -rw-r--r-- 2.4 KiB
cc0ec423 — Lefucjusz [MOS-1035] Fixes in new alarm window UI flow 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CustomRepeatModel.hpp"

#include <application-alarm-clock/widgets/AlarmClockStyle.hpp>
#include <ListView.hpp>
#include <time/time_locale.hpp>
#include <AppWindow.hpp>

namespace app::alarmClock
{
    CustomRepeatModel::CustomRepeatModel(app::ApplicationCommon *app,
                                         std::shared_ptr<alarmClock::AlarmRRulePresenter> rRulePresenter)
        : application(app), rRulePresenter(std::move(rRulePresenter))
    {}

    unsigned int CustomRepeatModel::requestRecordsCount()
    {
        return internalData.size();
    }

    unsigned int CustomRepeatModel::getMinimalItemSpaceRequired() const
    {
        return style::window::label::big_h + style::margins::big;
    }

    void CustomRepeatModel::requestRecords(uint32_t offset, uint32_t limit)
    {
        setupModel(offset, limit);
        list->onProviderDataUpdate();
    }

    gui::ListItem *CustomRepeatModel::getItem(gui::Order order)
    {
        return getRecord(order);
    }

    void CustomRepeatModel::createData()
    {
        auto app = application;
        for (auto const &[day, selected] : rRulePresenter->getCustomDays()) {
            internalData.push_back(new gui::CustomCheckBoxWithLabel(
                utils::translate(day),
                selected,
                [app](const UTF8 &text) { app->getCurrentWindow()->navBarTemporaryMode(text, false); },
                [app]() { app->getCurrentWindow()->navBarRestoreFromTemporaryMode(); }));
        }

        for (auto &item : internalData) {
            item->deleteByList = false;
        }
    }

    void CustomRepeatModel::loadData()
    {
        list->reset();
        eraseInternalData();

        createData();

        list->rebuildList();
    }

    void CustomRepeatModel::saveCheckedData()
    {
        std::list<utl::Day> days = {};

        for (unsigned int i = 0; i < internalData.size(); i++) {
            if (internalData[i]->isChecked()) {
                days.emplace_back(magic_enum::enum_cast<utl::Day>(i).value());
            }
        }

        rRulePresenter->setOption(AlarmRRulePresenter::RRuleOptions::Custom, days);
    }

    void CustomRepeatModel::eraseData()
    {
        list->reset();
        eraseInternalData();
    }

} // namespace app::alarmClock