~aleteoryx/muditaos

ref: 0ef0d615f34e275f088890a1244dd480dd467920 muditaos/module-apps/application-settings-new/windows/MessagesWindow.cpp -rw-r--r-- 3.2 KiB
0ef0d615 — Krzysztof Mozdzynski [EGD-4150] Change filename i18 to i18n (#1108) 5 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
// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "MessagesWindow.hpp"

#include <application-settings-new/ApplicationSettings.hpp>
#include <module-utils/i18n/i18n.hpp>
#include <OptionWindow.hpp>
#include <OptionSetting.hpp>

namespace gui
{
    MessagesWindow::MessagesWindow(app::Application *app) : OptionWindow(app, gui::window::name::messages)
    {
        addOptions(messagesOptList());
        setTitle(utils::localize.get("app_settings_apps_messages"));
    }

    std::list<Option> MessagesWindow::messagesOptList()
    {
        std::list<gui::Option> optionList;

        auto addMenuSwitch = [&](UTF8 name, std::string window) {
            optionList.emplace_back(std::make_unique<gui::OptionSettings>(
                name,
                [=](gui::Item &item) {
                    showUnreadMessagesFirst = !showUnreadMessagesFirst;
                    if (showUnreadMessagesFirst)
                        LOG_INFO("showUnreadMessagesFirst =true ");
                    else
                        LOG_INFO("showUnreadMessagesFirst =false ");
                    rebuildOptList();
                    return true;
                },
                [&](gui::Item &item) {
                    if (item.focus) {
                        this->setBottomBarText(utils::localize.get(style::strings::common::Switch),
                                               BottomBar::Side::CENTER);
                    }
                    else {
                        this->setBottomBarText(utils::localize.get(style::strings::common::select),
                                               BottomBar::Side::CENTER);
                    }
                    return true;
                },
                nullptr,
                showUnreadMessagesFirst ? RightItem::On : RightItem::Off));
        };

        auto addMenu = [&](UTF8 name, std::string window) {
            optionList.emplace_back(std::make_unique<gui::OptionSettings>(
                name,
                [=](gui::Item &item) {
                    if (window.empty()) {
                        return false;
                    }
                    LOG_INFO("switching to %s page", window.c_str());
                    application->switchWindow(window, nullptr);
                    return true;
                },
                nullptr,
                nullptr,
                RightItem::ArrowWhite));
        };

        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select));
        topBar->setActive(TopBar::Elements::SIGNAL, false);
        topBar->setActive(TopBar::Elements::BATTERY, false);
        topBar->setActive(TopBar::Elements::SIM, false);

        addMenuSwitch(utils::translateI18("app_settings_show_unread_first"), "");
        addMenu(utils::translateI18("app_settings_Templates"), gui::window::name::templates);

        return optionList;
    }

    void MessagesWindow::rebuildOptList()
    {
        clearOptions();
        addOptions(messagesOptList());
    }

    void MessagesWindow::onBeforeShow(ShowMode m, SwitchData *d)
    {
        rebuildOptList();
    }

} // namespace gui