~aleteoryx/muditaos

ref: 18bb7e8c24abf1a54bdb5b06818906ad4cd175b0 muditaos/module-apps/application-onboarding/windows/ConfigurePasscodeWindow.cpp -rw-r--r-- 4.4 KiB
18bb7e8c — Mateusz Grzegorzek [EGD-6315] Fix issues during saving new APN 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "ConfigurePasscodeWindow.hpp"

#include <application-onboarding/ApplicationOnBoarding.hpp>
#include <application-onboarding/data/OnBoardingSwitchData.hpp>
#include <application-desktop/data/AppDesktopStyle.hpp>
#include <application-settings-new/ApplicationSettings.hpp>
#include <application-settings-new/windows/ChangePasscodeWindow.hpp>

#include <DialogMetadata.hpp>
#include <DialogMetadataMessage.hpp>
#include <windows/Dialog.hpp>

namespace lock_style        = style::window::pin_lock;
namespace screen_lock_style = style::window::screen_pin_lock;

namespace gui
{
    ConfigurePasscodeWindow::ConfigurePasscodeWindow(app::Application *app) : ChangePasscodeWindow(app)
    {
        lockState = PinLock::LockState::NewPasscodeRequired;

        textForEnterNewPassword = "app_onboarding_set_password";
        testForConfirmPassword  = "app_onboarding_confirm_password";
        textForWrongPassword    = "app_onboarding_worng_password";
    }

    auto ConfigurePasscodeWindow::onInput(const InputEvent &inputEvent) -> bool
    {
        if (inputEvent.isShortPress() && inputEvent.is(KeyCode::KEY_LF)) {
            application->setLockScreenPasscodeOn(false);
            application->switchWindow(gui::window::name::onBoarding_date_and_time,
                                      gui::ShowMode::GUI_SHOW_INIT,
                                      std::make_unique<app::onBoarding::OnBoardingSwitchData>());
        }

        return ChangePasscodeWindow::onInput(inputEvent);
    }

    void ConfigurePasscodeWindow::buildBottomBar()
    {
        bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::confirm));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back));
        bottomBar->setText(BottomBar::Side::LEFT, utils::translate(style::strings::common::skip));
    }

    void ConfigurePasscodeWindow::buildTitleBar()
    {
        setTitle(utils::translate("app_onboarding_passcode_configuration"));
    }

    void ConfigurePasscodeWindow::processPasscode()
    {
        switch (lockState) {
        case PinLock::LockState::NewPasscodeConfirmRequired:
        case PinLock::LockState::NewPasscodeInvalid: {
            lockState = lockHandler.newPasscodeConfirmed();
            if (lockState == PinLock::LockState::Unlocked) {
                auto app = static_cast<app::ApplicationOnBoarding *>(application);
                app->setLockPassHash(lockHandler.getNewPasscodeHash());
            }
            break;
        }
        default:
            return ChangePasscodeWindow::processPasscode();
        }
    }

    void ConfigurePasscodeWindow::setVisibleState()
    {
        switch (lockState) {
        case PinLock::LockState::NewPasscodeInvalid: {

            auto metaData = std::make_unique<gui::DialogMetadataMessage>(
                gui::DialogMetadata{utils::translate("app_onboarding_passcode_configuration"),
                                    "info_big_circle_W_G",
                                    utils::translate("app_onboarding_wrong_password"),
                                    "",
                                    [this]() {
                                        application->switchWindow(gui::window::name::onBoarding_configure_passcode,
                                                                  gui::ShowMode::GUI_SHOW_INIT,
                                                                  std::make_unique<ChangePasscodeData>(
                                                                      ChangePasscodeAction::OnlyProvideNewPasscode));
                                        return true;
                                    }});

            application->switchWindow(
                gui::window::name::dialog_confirm, gui::ShowMode::GUI_SHOW_INIT, std::move(metaData));

            break;
        }
        case PinLock::LockState::Unlocked: {
            application->setLockScreenPasscodeOn(true);
            application->switchWindow(gui::window::name::onBoarding_date_and_time,
                                      gui::ShowMode::GUI_SHOW_INIT,
                                      std::make_unique<app::onBoarding::OnBoardingSwitchData>());
            break;
        }
        default:
            ChangePasscodeWindow::setVisibleState();
            break;
        }
    }
} // namespace gui