~aleteoryx/muditaos

ref: e296013b51c6fcdfbb18adcdaf4783a6ff6f5378 muditaos/module-apps/apps-common/popups/lock-popups/SimSwitchingWindow.cpp -rw-r--r-- 3.7 KiB
e296013b — Adam Wulkiewicz [BH-1622][BH-1623] Add/fix translations in relaxation 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SimSwitchingWindow.hpp"

#include <Application.hpp>
#include <EventStore.hpp>

namespace constants
{
    constexpr auto timerName = "SimSwitchingTimer";
    inline constexpr std::chrono::seconds timerStartInterval{3};
    inline constexpr std::chrono::seconds timerRepeatInterval{1};
    inline constexpr std::chrono::seconds maxDurationTime{10};
} // namespace constants

namespace gui
{
    SimSwitchingWindow::SimSwitchingWindow(app::ApplicationCommon *app, const std::string &name)
        : WindowWithTimer(app, name)
    {
        buildInterface();
        auto startTime = std::chrono::steady_clock::now();
        timerCallback  = [this, name, startTime](Item &, sys::Timer &timer) {
            if (application->getCurrentWindow()->getName() == name) {
                auto simState = Store::GSM::get()->sim;

                if (switchedSuccessful) {
                    application->getSimLockSubject().simSwitched();
                    application->returnToPreviousWindow();
                }
                else {
                    switch (simState) {
                    case Store::GSM::SIM::SIM1:
                    case Store::GSM::SIM::SIM2:
                    case Store::GSM::SIM::SIM_NEED_PIN:
                    case Store::GSM::SIM::SIM_NEED_PUK:
                    case Store::GSM::SIM::SIM_LOCKED:
                        switchedSuccessful = true;
                        resetTimer(constants::timerStartInterval);
                        updateInterface();
                        application->refreshWindow(RefreshModes::GUI_REFRESH_FAST);
                        break;
                    case Store::GSM::SIM::NONE:
                    case Store::GSM::SIM::SIM_FAIL:
                    case Store::GSM::SIM::SIM_UNKNOWN:
                        if (std::chrono::steady_clock::now() - startTime >= constants::maxDurationTime) {
                            LOG_INFO("The SIM switch operation failed. We return to the previous window.");
                            application->getSimLockSubject().simSwitched();
                            application->returnToPreviousWindow();
                        }
                        else {
                            resetTimer(constants::timerRepeatInterval);
                        }
                        break;
                    }
                }
                return true;
            }
            else {
                return false;
            }
        };
        resetTimer(constants::timerStartInterval);
    }

    void SimSwitchingWindow::buildInterface()
    {
        AppWindow::buildInterface();
        setTitle(utils::translate("app_settings_network_sim_cards"));
        infoIcon = new gui::Icon(this,
                                 style::window::default_left_margin,
                                 style::window::default_vertical_pos,
                                 style::window::default_body_width,
                                 style::window::default_body_height,
                                 "progress_128px_W_G",
                                 utils::translate("sim_card_change_in_progress"));
        infoIcon->setAlignment(Alignment::Horizontal::Center);
    }

    void SimSwitchingWindow::updateInterface()
    {
        setTitle(utils::translate(switchedSuccessful ? "app_settings_net" : "app_settings_network_sim_cards"));
        infoIcon->text->setRichText(
            utils::translate(switchedSuccessful ? "sim_card_changed_successfully" : "sim_card_change_in_progress"));
        infoIcon->image->set(switchedSuccessful ? "success_128px_W_G" : "progress_128px_W_G");
    }

} // namespace gui