From 12386846f573c57880caa544f8e597764351b0b1 Mon Sep 17 00:00:00 2001 From: Pawel Olejniczak Date: Tue, 12 Jan 2021 15:40:34 +0100 Subject: [PATCH] [EGD-2519] Fix keyboard mode in the search windows Keyboard mode was not displayed in the search windows. Now its fixed, both in Phonebook and Messages search. Additionaly code of the Phonebook Search window is cleaned up. --- changelog.md | 5 +- .../windows/SearchStart.cpp | 5 ++ .../windows/PhonebookSearch.cpp | 71 +++++++++---------- .../windows/PhonebookSearch.hpp | 20 ++---- 4 files changed, 48 insertions(+), 53 deletions(-) diff --git a/changelog.md b/changelog.md index 1602113782d7fa9e025d7bbe47118fa7abefd522..bd0abe256f17397816f3feb4e3139af116a4a141 100644 --- a/changelog.md +++ b/changelog.md @@ -7,14 +7,14 @@ * VoLTE ON/OFF switch in Settings Network window * Add PLL2 clock switching * Support for asynchronous callbacks on application side. -* APN settings window - empty +* APN settings window - empty. ### Changed * Input keyboard language files parser from KBD to JSON. * Input language files are now loaded based on files in "profiles" folder. * Minimum CPU frequency is now 132 MHz -* Icon widget now accepts rich text +* Icon widget now accepts rich text. ### Fixed @@ -22,6 +22,7 @@ * Fix newly added contact recognized as a duplicate of temporary contact. * Fix default borderCallback navigation in GridLayout. * Fix crash on enter Settings -> Information. +* Fix keyboard mode in the search windows. ## [0.52.1 2020-12-23] diff --git a/module-apps/application-messages/windows/SearchStart.cpp b/module-apps/application-messages/windows/SearchStart.cpp index ea9d0a5b4fc4616b3b2da7ace1fdb874c39e0e05..4b452098745e86af202bdd125c08fc73d1ab35ce 100644 --- a/module-apps/application-messages/windows/SearchStart.cpp +++ b/module-apps/application-messages/windows/SearchStart.cpp @@ -22,6 +22,11 @@ namespace gui body->setBoundingBox(bodySize()); addWidget(body); auto text = inputBox(this, utils::localize.get("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(application); diff --git a/module-apps/application-phonebook/windows/PhonebookSearch.cpp b/module-apps/application-phonebook/windows/PhonebookSearch.cpp index 91b875e00bb8b195894722893297b7cbf7cf4967..bcc296df48bc7397272fd6b61ff69a1f07c31679 100644 --- a/module-apps/application-phonebook/windows/PhonebookSearch.cpp +++ b/module-apps/application-phonebook/windows/PhonebookSearch.cpp @@ -3,10 +3,9 @@ #include "PhonebookSearch.hpp" #include "application-phonebook/ApplicationPhonebook.hpp" +#include "application-phonebook/data/PhonebookItemData.hpp" #include "widgets/InputBox.hpp" -#include - namespace gui { PhonebookSearch::PhonebookSearch(app::Application *app) : AppWindow(app, gui::window::name::search) @@ -22,6 +21,12 @@ namespace gui setTitle(utils::localize.get("app_phonebook_title_main")); inputField = inputBox(this, utils::localize.get("common_search_uc"), "search"); + inputField->setInputMode(new InputMode( + {InputMode::ABC, InputMode::abc, InputMode::digit}, + [=](const UTF8 &Text) { application->getCurrentWindow()->bottomBarTemporaryMode(Text); }, + [=]() { application->getCurrentWindow()->bottomBarRestoreFromTemporaryMode(); }, + [=]() { application->getCurrentWindow()->selectSpecialCharacter(); })); + bottomBar->setActive(BottomBar::Side::LEFT, false); bottomBar->setActive(BottomBar::Side::CENTER, true); bottomBar->setActive(BottomBar::Side::RIGHT, true); @@ -32,60 +37,50 @@ namespace gui setFocusItem(inputField); } - void PhonebookSearch::rebuild() - {} - - void PhonebookSearch::destroyInterface() - { - AppWindow::destroyInterface(); - } - - void PhonebookSearch::onBeforeShow(ShowMode mode, SwitchData *data) - { - inputField->setText(""); - setFocusItem(inputField); - } - - bool PhonebookSearch::handleSwitchData(SwitchData *data) + auto PhonebookSearch::handleSwitchData(SwitchData *data) -> bool { if (data == nullptr) { LOG_ERROR("Received null pointer"); return false; } - PhonebookSearchQuery *item = dynamic_cast(data); + auto item = dynamic_cast(data); + assert(item != nullptr); inputField->setText(item->getQuery()); return true; } - bool PhonebookSearch::onInput(const InputEvent &inputEvent) + void PhonebookSearch::onBeforeShow(ShowMode mode, SwitchData *data) + { + inputField->clear(); + setFocusItem(inputField); + } + + auto PhonebookSearch::onInput(const InputEvent &inputEvent) -> bool { - bool ret = AppWindow::onInput(inputEvent); - if (ret) { - return ret; + if (AppWindow::onInput(inputEvent)) { + return true; } - - if ((inputEvent.state != InputEvent::State::keyReleasedShort) && - ((inputEvent.state != InputEvent::State::keyReleasedLong))) { + if (!inputEvent.isShortPress()) { + return false; + } + if (!inputEvent.is(gui::KeyCode::KEY_ENTER)) { return false; } - if (inputEvent.keyCode == KeyCode::KEY_ENTER) { - std::string searchFilter = utils::trim(inputField->getText()); - - if (searchFilter.size() > 0) { - auto app = dynamic_cast(application); - if (app == nullptr) { - LOG_ERROR("Failed to get phonebook application."); - return false; - } + std::string searchFilter = utils::trim(inputField->getText()); + if (searchFilter.empty()) { + return false; + } - app->onSearchRequest(searchFilter); - return true; - } + auto app = dynamic_cast(application); + if (app == nullptr) { + LOG_ERROR("Failed to get phonebook application."); + return false; } - return ret; + app->onSearchRequest(searchFilter); + return true; } } // namespace gui diff --git a/module-apps/application-phonebook/windows/PhonebookSearch.hpp b/module-apps/application-phonebook/windows/PhonebookSearch.hpp index ba9e57a31bc2d9501d23f3c4dcbd4bacb3be9e27..19e84a2499474a6e6939b7f8ee19f1844b225fc6 100644 --- a/module-apps/application-phonebook/windows/PhonebookSearch.hpp +++ b/module-apps/application-phonebook/windows/PhonebookSearch.hpp @@ -3,11 +3,8 @@ #pragma once -#include "application-phonebook/data/PhonebookItemData.hpp" -#include "application-phonebook/models/PhonebookModel.hpp" -#include "application-phonebook/widgets/PhonebookListView.hpp" - #include +#include #include namespace gui @@ -15,19 +12,16 @@ namespace gui class PhonebookSearch : public AppWindow { public: - PhonebookSearch(app::Application *app); - ~PhonebookSearch() override = default; + explicit PhonebookSearch(app::Application *app); - bool onInput(const InputEvent &inputEvent) override; - void onBeforeShow(ShowMode mode, SwitchData *data) override; - bool handleSwitchData(SwitchData *data) override; - void rebuild() override; + private: void buildInterface() override; - void destroyInterface() override; + auto handleSwitchData(SwitchData *data) -> bool override; + void onBeforeShow(ShowMode mode, SwitchData *data) override; + auto onInput(const InputEvent &inputEvent) -> bool override; - private: - Text *inputField = nullptr; std::shared_ptr contact = nullptr; + Text *inputField = nullptr; }; } /* namespace gui */