~aleteoryx/muditaos

ref: 1d2f5cf7a49cf1fb9463d289daa1492a2bec2d1d muditaos/module-apps/application-phonebook/windows/PhonebookIceContacts.cpp -rw-r--r-- 2.9 KiB
1d2f5cf7 — Piotr Tański [EGD-7754] Dates bumped in disclaimers 4 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "PhonebookIceContacts.hpp"
#include "application-phonebook/ApplicationPhonebook.hpp"
#include "application-phonebook/data/PhonebookStyle.hpp"

#include <service-db/DBNotificationMessage.hpp>

namespace gui
{
    PhonebookIceContacts::PhonebookIceContacts(app::ApplicationCommon *app)
        : AppWindow(app, gui::window::name::ice_contacts), phonebookModel{std::make_shared<PhonebookModel>(
                                                               this->application, "", ContactsDB::iceGroupId())}
    {
        buildInterface();
    }

    void PhonebookIceContacts::rebuild()
    {
        contactsListIce->rebuildList();
    }

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

        setTitle(utils::translate("app_phonebook_ice_contacts_title"));

        contactsListIce = new gui::ListView(this,
                                            phonebookStyle::iceContactsWindow::contactsListIce::x,
                                            phonebookStyle::iceContactsWindow::contactsListIce::y,
                                            phonebookStyle::iceContactsWindow::contactsListIce::w,
                                            phonebookStyle::iceContactsWindow::contactsListIce::h,
                                            phonebookModel,
                                            gui::listview::ScrollBarType::Fixed);

        setFocusItem(contactsListIce);

        bottomBar->setActive(BottomBar::Side::LEFT, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::LEFT, utils::translate(style::strings::common::call));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back));
    }

    void PhonebookIceContacts::destroyInterface()
    {
        erase();
    }

    PhonebookIceContacts::~PhonebookIceContacts()
    {
        destroyInterface();
    }

    bool PhonebookIceContacts::onInput(const InputEvent &inputEvent)
    {
        if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) {
            return true;
        }
        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
    }

    bool PhonebookIceContacts::onDatabaseMessage(sys::Message *msgl)
    {
        auto *msgNotification = dynamic_cast<db::NotificationMessage *>(msgl);
        if (msgNotification != nullptr) {
            if (msgNotification->interface == db::Interface::Name::Contact) {

                if (msgNotification->dataModified()) {

                    rebuild();

                    return true;
                }
            }
        }

        return false;
    }

    void PhonebookIceContacts::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        rebuild();
    }
} /* namespace gui */