// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "PhoneNameWindow.hpp" #include "application-settings-new/ApplicationSettings.hpp" #include "application-settings-new/data/PhoneNameData.hpp" #include "widgets/InputBox.hpp" #include namespace gui { PhoneNameWindow::PhoneNameWindow(app::Application *app) : AppWindow(app, gui::window::name::phone_name) { bluetoothSettingsModel = std::make_unique(application); bluetoothSettingsModel->requestDeviceName(); buildInterface(); } void PhoneNameWindow::buildInterface() { AppWindow::buildInterface(); setTitle(utils::localize.get("app_settings_bluetooth_phone_name")); inputField = inputBox(this, utils::localize.get("app_settings_bluetooth_phone_name")); bottomBar->setActive(BottomBar::Side::LEFT, false); bottomBar->setActive(BottomBar::Side::CENTER, true); bottomBar->setActive(BottomBar::Side::RIGHT, true); bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::save)); bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back)); setFocusItem(inputField); } void PhoneNameWindow::destroyInterface() { AppWindow::destroyInterface(); erase(inputField); inputField = nullptr; } void PhoneNameWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data) { inputField->clear(); if (const auto newData = dynamic_cast(data); data != nullptr) { inputField->setText(newData->getName()); } } auto PhoneNameWindow::onInput(const InputEvent &inputEvent) -> bool { if (AppWindow::onInput(inputEvent)) { return true; } if (!inputEvent.isShortPress()) { return false; } if (inputEvent.is(gui::KeyCode::KEY_ENTER) && !inputField->isEmpty()) { bluetoothSettingsModel->setDeviceName(inputField->getText()); return true; } return false; } } // namespace gui