mirror of
https://github.com/mudita/MuditaOS.git
synced 2026-01-01 18:39:03 -05:00
Added timeout for displaying selected input mode - now it automatically disappears after 3 seconds since last change was made.
76 lines
2.7 KiB
C++
76 lines
2.7 KiB
C++
// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved.
|
|
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
|
|
|
|
#include "PhoneNameWindow.hpp"
|
|
|
|
#include <application-settings/data/PhoneNameData.hpp>
|
|
#include <application-settings/windows/WindowNames.hpp>
|
|
|
|
#include <widgets/InputBox.hpp>
|
|
|
|
namespace gui
|
|
{
|
|
PhoneNameWindow::PhoneNameWindow(app::ApplicationCommon *app,
|
|
std::shared_ptr<BluetoothSettingsModel> bluetoothSettingsModel)
|
|
: AppWindow(app, gui::window::name::phone_name), bluetoothSettingsModel(bluetoothSettingsModel)
|
|
{
|
|
bluetoothSettingsModel->requestDeviceName();
|
|
buildInterface();
|
|
}
|
|
|
|
void PhoneNameWindow::buildInterface()
|
|
{
|
|
AppWindow::buildInterface();
|
|
|
|
setTitle(utils::translate("app_settings_bluetooth_phone_name"));
|
|
|
|
inputField = inputBox(this, utils::translate("app_settings_bluetooth_phone_name"));
|
|
inputField->setInputMode(new InputMode(
|
|
{InputMode::Abc, InputMode::ABC, InputMode::abc, InputMode::digit},
|
|
[=](const UTF8 &text) { application->getCurrentWindow()->navBarTemporaryMode(text); },
|
|
[=]() { application->getCurrentWindow()->navBarRestoreFromTemporaryMode(); },
|
|
nullptr,
|
|
[=](std::function<void()> restoreFunction) {
|
|
application->getCurrentWindow()->startInputModeRestoreTimer(std::move(restoreFunction));
|
|
}));
|
|
navBar->setActive(nav_bar::Side::Left, false);
|
|
navBar->setActive(nav_bar::Side::Center, true);
|
|
navBar->setActive(nav_bar::Side::Right, true);
|
|
|
|
navBar->setText(nav_bar::Side::Center, utils::translate(style::strings::common::save));
|
|
navBar->setText(nav_bar::Side::Right, utils::translate(style::strings::common::back));
|
|
|
|
setFocusItem(inputField);
|
|
}
|
|
|
|
void PhoneNameWindow::destroyInterface()
|
|
{
|
|
AppWindow::destroyInterface();
|
|
erase(inputField);
|
|
inputField = nullptr;
|
|
}
|
|
|
|
void PhoneNameWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
|
|
{
|
|
if (const auto newData = dynamic_cast<PhoneNameData *>(data); newData != nullptr) {
|
|
inputField->setText(newData->getName());
|
|
inputField->setTextLimitType(gui::TextLimitType::MaxSignsCount, maxNameLength);
|
|
}
|
|
}
|
|
|
|
auto PhoneNameWindow::onInput(const InputEvent &inputEvent) -> bool
|
|
{
|
|
if (AppWindow::onInput(inputEvent)) {
|
|
return true;
|
|
}
|
|
|
|
if (inputEvent.isShortRelease(gui::KeyCode::KEY_ENTER) && !inputField->isEmpty()) {
|
|
bluetoothSettingsModel->setDeviceName(inputField->getText());
|
|
application->returnToPreviousWindow();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
} // namespace gui
|