~aleteoryx/muditaos

ref: sign_test muditaos/module-apps/application-phonebook/models/ContactDetailsModel.cpp -rw-r--r-- 2.4 KiB
a217eeb3 — Dawid Wojtas [BH-2024] Fix lack of alarm directory after updating software 1 year, 5 months 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
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ContactDetailsModel.hpp"

#include "application-phonebook/widgets/ContactListItem.hpp"
#include "application-phonebook/widgets/InformationWidget.hpp"
#include "application-phonebook/widgets/OutputLinesTextWithLabelWidget.hpp"

#include <ListView.hpp>
#include <time/ScopedTime.hpp>
#include <module-apps/application-phonebook/data/PhonebookInternals.hpp>

ContactDetailsModel::ContactDetailsModel(app::ApplicationCommon *app) : application(app)
{}

void ContactDetailsModel::clearData()
{
    list->reset();
    eraseInternalData();
}

auto ContactDetailsModel::requestRecordsCount() -> unsigned int
{
    return internalData.size();
}

auto ContactDetailsModel::getMinimalItemSpaceRequired() const -> unsigned int
{
    return phonebookStyle::outputLinesTextWithLabelWidget::h;
}

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

auto ContactDetailsModel::getItem(gui::Order order) -> gui::ListItem *
{
    return getRecord(order);
}

void ContactDetailsModel::createData(bool showInformationWidget, bool showAddressWidget, bool showNoteWidget)
{
    if (showInformationWidget) {
        internalData.push_back(new gui::InformationWidget(application));
    }

    if (showAddressWidget) {
        internalData.push_back(new gui::OutputLinesTextWithLabelWidget(phonebookInternals::ListItemName::Address));
    }

    if (showNoteWidget) {
        internalData.push_back(new gui::OutputLinesTextWithLabelWidget(phonebookInternals::ListItemName::Note));
    }

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

void ContactDetailsModel::loadData(std::shared_ptr<ContactRecord> contactRecord)
{
    clearData();

    auto isInformationDataExist = [&]() -> bool {
        return contactRecord->numbers.size() > 0 || contactRecord->mail.length() > 0;
    };
    auto isAddressDataExist = [&]() -> bool { return contactRecord->address.length() > 0; };
    auto isNoteDataExist    = [&]() -> bool { return contactRecord->note.length() > 0; };

    createData(isInformationDataExist(), isAddressDataExist(), isNoteDataExist());

    for (auto item : internalData) {
        if (item->onLoadCallback) {
            item->onLoadCallback(contactRecord);
        }
    }

    list->rebuildList();
}