~aleteoryx/muditaos

ref: 0eb1fd03e56cedef8df68eb04043db1dd6e327b3 muditaos/module-apps/application-calllog/CalllogModel.cpp -rw-r--r-- 2.3 KiB
0eb1fd03 — Przemyslaw Brudny [EGD-3985] Removed unique_ptr to vector for DatabaseModel updateRecords Method. 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
#include "CalllogModel.hpp"
#include "InputEvent.hpp"
#include "ListView.hpp"
#include "UiCommonActions.hpp"
#include "data/CallLogInternals.hpp"
#include "data/CallLogSwitchData.hpp"
#include "service-db/api/DBServiceAPI.hpp"
#include "widgets/CalllogItem.hpp"

using namespace calllog;

CalllogModel::CalllogModel(app::Application *app) : DatabaseModel(app)
{}

unsigned int CalllogModel::requestRecordsCount()
{
    recordsCount = DBServiceAPI::CalllogGetCount(application);
    return recordsCount;
}

void CalllogModel::requestRecords(const uint32_t offset, const uint32_t limit)
{
    DBServiceAPI::CalllogGetLimitOffset(application, offset, limit);
}

bool CalllogModel::updateRecords(std::vector<CalllogRecord> records)
{
#if DEBUG_DB_MODEL_DATA == 1
    LOG_DEBUG("Offset: %" PRIu32 ", Limit: %" PRIu32 " Count: %" PRIu32 "", offset, limit, count);
    for (uint32_t i = 0; i < records.get()->size(); ++i) {
        LOG_DEBUG(
            "id: %" PRIu32 ", name: %s", records.get()->operator[](i).ID, records.get()->operator[](i).name.c_str());
    }
#endif

    DatabaseModel::updateRecords(std::move(records));
    list->onProviderDataUpdate();

    return true;
}

unsigned int CalllogModel::getMinimalItemHeight() const
{

    return gui::clItemStyle::h;
}

gui::ListItem *CalllogModel::getItem(gui::Order order)
{

    std::shared_ptr<CalllogRecord> call = getRecord(order);

    SettingsRecord &settings = application->getSettings();
    if (call.get() == nullptr) {
        return nullptr;
    }

    auto item = new gui::CalllogItem(this, !settings.timeFormat12);

    item->setCall(call);
    item->activatedCallback = [=](gui::Item &item) {
        LOG_INFO("activatedCallback");
        std::unique_ptr<gui::SwitchData> data = std::make_unique<calllog::CallLogSwitchData>(*call);
        application->switchWindow(calllog::settings::DetailsWindowStr, std::move(data));
        return true;
    };

    item->inputCallback = [this, item](gui::Item &, const gui::InputEvent &event) {
        if (event.state != gui::InputEvent::State::keyReleasedShort) {
            return false;
        }
        if (event.keyCode == gui::KeyCode::KEY_LF) {
            LOG_DEBUG("calling");
            return app::call(application, item->getCall().phoneNumber);
        }
        return false;
    };
    return item;
}