~aleteoryx/muditaos

ref: d528cac7df03906e67d64987e7c0b2ca5cfe6361 muditaos/module-apps/application-settings/presenter/network/SimPINSettingsPresenter.cpp -rw-r--r-- 2.2 KiB
d528cac7 — Maciej-Mudita [MOS-641] Fix SIM cards window 3 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
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimPINSettingsPresenter.hpp"

#include <application-settings/data/PINSettingsLockStateData.hpp>
#include <application-settings/data/PINSettingsSimData.hpp>
#include <EventStore.hpp>

SimPINSettingsPresenter::SimPINSettingsPresenter(app::ApplicationCommon *application) : application(application)
{}

void SimPINSettingsPresenter::setCurrentPinState(bool state) noexcept
{
    isPinOn = state;
}

void SimPINSettingsPresenter::togglePinState()
{
    isPinOn = !isPinOn;
    if (!isPinOn) {
        application->getSimLockSubject().disableSimPin();
    }
    else {
        application->getSimLockSubject().enableSimPin();
    }
}

bool SimPINSettingsPresenter::isPinEnabled() const noexcept
{
    return isPinOn;
}

void SimPINSettingsPresenter::requestLockState() const
{
    application->bus.sendUnicast<cellular::msg::request::sim::GetPinSettings>();
}

void SimPINSettingsPresenter::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)
{
    const auto view = getView();

    if (const auto pinSettingsSimData = dynamic_cast<gui::PINSettingsSimData *>(data); pinSettingsSimData != nullptr) {
        view->setTitle(utils::translate("app_settings_network_pin_settings") + " (" + pinSettingsSimData->getSim() +
                       ")");
    }

    if (const auto pinSettingsLockStateData = dynamic_cast<gui::PINSettingsLockStateData *>(data);
        pinSettingsLockStateData != nullptr) {
        view->setNavbarCenterActive(true);
        pinLockStateChanged = isPinEnabled() == pinSettingsLockStateData->getSimCardPinLockState() ? false : true;
        if (pinLockStateChanged) {
            const auto currentPinState = pinSettingsLockStateData->getSimCardPinLockState();
            setCurrentPinState(currentPinState);
        }
    }
    if (not Store::GSM::get()->simCardInserted()) {
        view->setNavbarCenterActive(false);
        return;
    }
    if (mode == gui::ShowMode::GUI_SHOW_RETURN) {
        requestLockState();
    }
    if (mode == gui::ShowMode::GUI_SHOW_INIT || pinLockStateChanged) {
        view->refreshOptionsList();
    }
}