~aleteoryx/muditaos

ref: de5b923e81ed56bc845b75b2833cb040fafc3409 muditaos/module-apps/popups/lock-popups/SimLockInputWindow.cpp -rw-r--r-- 4.5 KiB
de5b923e — DariuszSabala [BH-369] Turned UTF8 into separate library 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockInputWindow.hpp"

#include <locks/data/LockData.hpp>
#include <locks/widgets/SimLockBox.hpp>
#include <locks/widgets/LockHash.hpp>

#include <service-appmgr/Controller.hpp>
#include <popups/data/PopupRequestParams.hpp>

namespace gui
{
    SimLockInputWindow::SimLockInputWindow(app::Application *app, const std::string &window_name)
        : LockInputWindow(app, window_name)
    {
        buildInterface();
    }

    void SimLockInputWindow::rebuild()
    {
        destroyInterface();
        buildInterface();
    }
    void SimLockInputWindow::buildInterface()
    {
        AppWindow::buildInterface();
        LockInputWindow::build();
    }

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

    void SimLockInputWindow::setVisibleState()
    {
        LockInputWindow::setVisibleState();

        if (lock->isState(locks::Lock::LockState::ErrorOccurred)) {
            lockBox->setVisibleStateError(errorCode);
        }
    }

    status_bar::Configuration SimLockInputWindow::configureStatusBar(status_bar::Configuration appConfiguration)
    {
        appConfiguration.disable(status_bar::Indicator::NetworkAccessTechnology);
        appConfiguration.enable(status_bar::Indicator::Time);
        appConfiguration.enable(status_bar::Indicator::PhoneMode);
        appConfiguration.enable(status_bar::Indicator::Battery);
        appConfiguration.enable(status_bar::Indicator::Signal);
        appConfiguration.enable(status_bar::Indicator::SimCard);
        return appConfiguration;
    }

    void SimLockInputWindow::onBeforeShow(ShowMode mode, SwitchData *data)
    {
        if (auto SimLockData = dynamic_cast<locks::SimLockData *>(data)) {
            lock                   = std::make_unique<locks::Lock>(SimLockData->getLock());
            simLockInputTypeAction = SimLockData->getSimInputTypeAction();
            errorCode              = SimLockData->getErrorCode();
        }

        // Lock need to exist in that window flow
        assert(lock);

        rebuild();
        lockBox = std::make_unique<SimLockBox>(this, simLockInputTypeAction);
        lockBox->buildLockBox(lock->getMaxInputSize());

        setVisibleState();
    }

    bool SimLockInputWindow::onInput(const InputEvent &inputEvent)
    {
        if (!inputEvent.isShortRelease()) {
            return AppWindow::onInput(inputEvent);
        }
        else if (inputEvent.is(KeyCode::KEY_RF) && bottomBar->isActive(BottomBar::Side::RIGHT)) {
            if (isInInputState()) {
                lock->clearAttempt();
            }
            else if (lock->isState(locks::Lock::LockState::InputInvalid)) {
                lock->consumeState();
            }
            application->returnToPreviousWindow();
            return true;
        }
        else if (inputEvent.is(KeyCode::KEY_PND)) {
            if (isInInputState()) {
                lock->popChar();
                lockBox->popChar(lock->getCharCount());
                bottomBar->setActive(BottomBar::Side::CENTER, lock->canVerify());
                return true;
            }
        }
        else if (inputEvent.isDigit()) {
            if (isInInputState() && lock->canPut()) {
                lockBox->putChar(lock->getCharCount());
                lock->putNextChar(inputEvent.numericValue());

                bottomBar->setActive(BottomBar::Side::CENTER, lock->canVerify());
                return true;
            }
        }
        else if (inputEvent.is(KeyCode::KEY_ENTER) && bottomBar->isActive(BottomBar::Side::CENTER)) {
            if (isInInputState()) {
                application->getSimLockSubject().verifyInput(lock->getInput());
            }
            else if (isInInvalidInputState()) {
                lock->consumeState();
                lock->clearAttempt();
                setVisibleState();
            }
            return true;
        }
        else if (inputEvent.is(KeyCode::KEY_LEFT) && isIceVisible()) {
            app::manager::Controller::sendAction(application,
                                                 app::manager::actions::EmergencyDial,
                                                 std::make_unique<gui::SwitchData>(),
                                                 app::manager::OnSwitchBehaviour::RunInBackground);
            return true;
        }

        // check if any of the lower inheritance onInput methods catch the event
        return AppWindow::onInput(inputEvent);
    }

} /* namespace gui */