~aleteoryx/muditaos

ref: cc151403c58f91d6ee33115422091e176a04db76 muditaos/module-apps/application-call/windows/EnterNumberWindow.cpp -rw-r--r-- 3.4 KiB
cc151403 — patrycja-paczkowska [MOS-188] Fix notes window title 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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "CallAppStyle.hpp"
#include "CallSwitchData.hpp"
#include "EnterNumberWindow.hpp"

#include <ContactRecord.hpp>
#include <country.hpp>
#include <i18n/i18n.hpp>
#include <text/modes/InputMode.hpp>
#include <phonenumbers/asyoutypeformatter.h>
#include <phonenumbers/phonenumberutil.h>
#include <service-appmgr/Controller.hpp>
#include <service-cellular/CellularServiceAPI.hpp>

#include <cassert>

namespace gui
{
    EnterNumberWindow::EnterNumberWindow(app::ApplicationCommon *app,
                                         app::EnterNumberWindowInterface *interface,
                                         std::string windowName)
        : NumberWindow(app, interface, std::move(windowName))
    {
        buildInterface();
    }

    void EnterNumberWindow::buildInterface()
    {
        using namespace callAppStyle;
        using namespace callAppStyle::enterNumberWindow;
        NumberWindow::buildInterface();

        navBar->setText(nav_bar::Side::Center, utils::translate("common_add"));
        navBar->setText(nav_bar::Side::Right, utils::translate("app_call_clear"));

        auto iconsBox = new HBox(
            this, style::window::default_left_margin, iconsBox::y, style::window::default_body_width, iconsBox::h);
        iconsBox->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top));
        iconsBox->setEdges(RectangleEdge::None);

        newContactIcon                    = new gui::AddContactIcon(iconsBox);
        newContactIcon->activatedCallback = [=](gui::Item &item) { return addNewContact(); };
        setFocusItem(newContactIcon);

        iconsBox->resizeItems();
    }

    status_bar::Configuration EnterNumberWindow::configureStatusBar(status_bar::Configuration appConfiguration)
    {
        appConfiguration.enable(status_bar::Indicator::PhoneMode);
        return appConfiguration;
    }

    bool EnterNumberWindow::addNewContact()
    {
        interface->handleAddContactEvent(enteredNumber);
        return true;
    }

    bool EnterNumberWindow::handleSwitchData(SwitchData *data)
    {
        if (data == nullptr) {
            LOG_ERROR("Received null pointer");
            return false;
        }

        if (data->getDescription() == app::EnterNumberData::descriptionStr) {
            auto *callData = dynamic_cast<app::EnterNumberData *>(data);
            assert(callData != nullptr);

            initFormatterInput(callData->getPhoneNumber());
            setNumberLabel(formattedNumber);
            application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
        }
        else if (data->getDescription() == app::CallSwitchData::descriptionStr) {
            auto *callData = dynamic_cast<app::CallSwitchData *>(data);
            assert(callData != nullptr);

            auto &phoneNumber = callData->getPhoneNumber();

            initFormatterInput(phoneNumber.getEntered());
            setNumberLabel(phoneNumber.getFormatted());
            application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);

            if (callData->getType() == app::CallSwitchData::Type::EXECUTE_CALL) {
                interface->handleCallEvent(phoneNumber.getEntered());
            }
        }
        else {
            LOG_ERROR("Unhandled switch data");
            abort();
        }

        return true;
    }
} /* namespace gui */