~aleteoryx/muditaos

ref: fe8671698432b6877da6b8e911b8df77fc439922 muditaos/module-apps/application-messages/windows/SearchStart.cpp -rw-r--r-- 1.9 KiB
fe867169 — Piotr Tanski [EGD-4153] Use actions instead explicit applications switch. (#1032) 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
// Copyright (c) 2017-2020, 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 <i18/i18.hpp>
#include <widgets/InputBox.hpp>
#include <cassert>

namespace gui
{

    SMSSearch::SMSSearch(app::Application *app) : AppWindow(app, name::window::thread_sms_search)
    {
        buildInterface();
        setTitle(utils::localize.get("app_messages_title_main"));
        bottomBar->setActive(BottomBar::Side::CENTER, true);
        bottomBar->setActive(BottomBar::Side::RIGHT, true);
        bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::search));
        bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back));
        body = new gui::Item();
        body->setBoundingBox(bodySize());
        addWidget(body);
        auto text = inputBox(this, utils::localize.get("common_search_uc"), "search");

        inputCallback = [=](Item &, const InputEvent &inputEvent) -> bool {
            auto app = dynamic_cast<app::ApplicationMessages *>(application);
            assert(app);
            if (inputEvent.state != InputEvent::State::keyReleasedShort) {
                return false;
            }
            if (inputEvent.keyCode == KeyCode::KEY_ENTER) {
                auto search_text = text->getText();
                app->showSearchResults(utils::localize.get("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