~aleteoryx/muditaos

ref: bcdaf15ed1560876b4a784f758ead67a7e240968 muditaos/module-apps/locks/widgets/SimLockBox.cpp -rw-r--r-- 3.9 KiB
bcdaf15e — Przemyslaw Brudny [EGD-6740] Availability and Change handled by PhoneLockHandler 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimLockBox.hpp"

#include "locks/data/LockStyle.hpp"
#include "locks/windows/PinLockBaseWindow.hpp"
#include "Lock.hpp"
#include <Style.hpp>
#include <Image.hpp>

namespace label_style = style::window::pin_lock::pin_label;

namespace gui
{

    void SimLockBox::popChar(unsigned int charNum)
    {
        rebuildInputLabels(charNum);
    }
    void SimLockBox::putChar(unsigned int charNum)
    {
        rebuildInputLabels(++charNum);
    }

    void SimLockBox::buildLockBox(unsigned int inputSize)
    {
        LockWindow->buildImages("pin_lock", "pin_lock_info");
        buildInputLabels(0);
    }
    void SimLockBox::buildInputLabels(unsigned int inputSize)
    {
        auto itemBuilder = []() {
            auto label = new gui::Image("dot_12px_hard_alpha_W_G");
            return label;
        };

        LockWindow->buildPinLabels(itemBuilder, inputSize, label_style::x, label_style::y, label_style::w);
        LockWindow->pinLabelsBox->setEdges(RectangleEdge::Bottom);
    }

    void SimLockBox::rebuildInputLabels(unsigned int inputSize)
    {
        LockWindow->pinLabelsBox->erase();
        buildInputLabels(inputSize);
    }

    void SimLockBox::setVisibleStateInputRequired(InputActionType type)
    {
        LockWindow->pinLabelsBox->setVisible(true);
        switch (type) {
        case LockBox::InputActionType::ProvideInput: {
            LockWindow->setText(
                "app_desktop_sim_enter_pin_unlock",
                PinLockBaseWindow::TextType::Primary,
                {{LockWindow->getToken(PinLockBaseWindow::Token::PinType), LockWindow->lock->getLockName()}});
            break;
        }
        case LockBox::InputActionType::ProvideNewInput:
            LockWindow->setText("app_desktop_sim_enter_new_pin", PinLockBaseWindow::TextType::Primary);
            break;
        case LockBox::InputActionType::ConfirmNewInput:
            LockWindow->setText("app_desktop_sim_confirm_new_pin", PinLockBaseWindow::TextType::Primary);
            break;
        }

        LockWindow->setImagesVisible(true, false);
        LockWindow->setBottomBarWidgetsActive(false, false, true);
    }
    void SimLockBox::setVisibleStateInputInvalid(InputErrorType type, unsigned int value)
    {
        switch (type) {
        case LockBox::InputErrorType::InvalidInput:
            if (value == 1) {
                LockWindow->setText("app_desktop_sim_setup_wrong_pin_last_attempt",
                                    PinLockBaseWindow::TextType::Primary);
            }
            else {
                LockWindow->setText(
                    "app_desktop_sim_setup_wrong_pin",
                    PinLockBaseWindow::TextType::Primary,
                    {{LockWindow->getToken(PinLockBaseWindow::Token::Attempts), static_cast<int>(value)}});
            }
            break;
        case LockBox::InputErrorType::NewInputConfirmFailed:
            LockWindow->setText("app_desktop_sim_wrong_pin_confirmation", PinLockBaseWindow::TextType::Primary);
            break;
        case LockBox::InputErrorType::UnhandledError: {
            LockWindow->setText("app_desktop_sim_cme_error",
                                PinLockBaseWindow::TextType::Primary,
                                {{LockWindow->getToken(PinLockBaseWindow::Token::CmeCode), static_cast<int>(value)}});
            break;
        }
        }
        LockWindow->setImagesVisible(false, true);
        LockWindow->setBottomBarWidgetsActive(false, true, true);
    }
    void SimLockBox::setVisibleStateBlocked()
    {
        LockWindow->setText("app_desktop_sim_puk_blocked", PinLockBaseWindow::TextType::Primary);
        LockWindow->setImagesVisible(false, true);
        LockWindow->setBottomBarWidgetsActive(false, true, true);
    }

    void SimLockBox::clear()
    {
        rebuildInputLabels(0);
    }
} // namespace gui