~aleteoryx/muditaos

ref: 0823d82e5141f44812c54debf07245d0ca746124 muditaos/module-apps/application-calendar/models/DayEventsInternalModel.cpp -rw-r--r-- 2.0 KiB
0823d82e — Radoslaw Wicik [EGD-3743] Update copyrights in fies - add empty line after license 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
#include "DayEventsInternalModel.hpp"
#include "application-calendar/widgets/DayEventsItem.hpp"
#include "application-calendar/data/CalendarData.hpp"
#include "module-apps/application-calendar/ApplicationCalendar.hpp"
#include <ListView.hpp>
#include <algorithm>

DayEventsInternalModel::DayEventsInternalModel(app::Application *app) : application(app)
{}

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

unsigned int DayEventsInternalModel::getMinimalItemHeight() const
{
    return style::window::calendar::item::dayEvents::height;
}

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

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

void DayEventsInternalModel::loadData(std::unique_ptr<std::vector<EventsRecord>> records)
{
    auto app = dynamic_cast<app::ApplicationCalendar *>(application);
    assert(app != nullptr);

    list->clear();
    eraseInternalData();

    std::sort(records->begin(), records->end(), [](const EventsRecord &first, const EventsRecord &second) {
        return first.date_from < second.date_from;
    });

    auto eventShift = app->getEventShift();
    if (eventShift) {
        for (auto &record : *records) {
            record.date_from += hours(eventShift);
            record.date_till += hours(eventShift);
        }
    }

    for (auto &record : *records) {
        auto item = new gui::DayEventsItem();
        item->setEvent(std::make_shared<EventsRecord>(record));
        item->activatedCallback = [=](gui::Item &item) {
            auto rec  = std::make_unique<EventsRecord>(record);
            auto data = std::make_unique<EventRecordData>(std::move(rec));
            app->switchWindow(style::window::calendar::name::details_window, std::move(data));
            return true;
        };
        internalData.push_back(item);
    }

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

    list->rebuildList();
}