~aleteoryx/muditaos

ref: 95d96b82b63c85af4f655d10e52c5612121c23f6 muditaos/module-apps/application-messages/windows/SearchStart.cpp -rw-r--r-- 2.1 KiB
95d96b82 — Pawel.Paprocki [BH-370] Convert utils common_data into a libs 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
// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md

#include "SearchStart.hpp"
#include "../ApplicationMessages.hpp"
#include <i18n/i18n.hpp>
#include <widgets/InputBox.hpp>
#include <cassert>

namespace gui
{

    SMSSearch::SMSSearch(app::Application *app) : AppWindow(app, name::window::thread_sms_search)
    {
        buildInterface();
        setTitle(utils::translate("app_messages_title_main"));
        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::search));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back));
        body = new gui::Item();
        body->setBoundingBox(bodySize());
        addWidget(body);
        auto text = inputBox(this, utils::translate("common_search_uc"), "search");
        text->setInputMode(new InputMode(
            {InputMode::ABC, InputMode::abc, InputMode::digit},
            [=](const UTF8 &Text) { application->getCurrentWindow()->bottomBarTemporaryMode(Text); },
            [=]() { application->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); },
            [=]() { application->getCurrentWindow()->selectSpecialCharacter(); }));

        inputCallback = [=](Item &, const InputEvent &inputEvent) -> bool {
            auto app = dynamic_cast<app::ApplicationMessages *>(application);
            assert(app);
            if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) {
                auto search_text = text->getText();
                app->showSearchResults(utils::translate("common_search_results") + ": " + std::string(search_text),
                                       search_text);
                return true;
            }
            return false;
        };

        setFocusItem(text);
    }

    bool SMSSearch::onInput(const InputEvent &inputEvent)
    {
        return AppWindow::onInput(inputEvent) || (inputCallback && inputCallback(*this, inputEvent));
    }

} // namespace gui