Files
MuditaOS/module-apps/application-settings/windows/network/NewApnWindow.cpp
Mateusz Grzegorzek 58dd02cff1 [BH-861] Cleanup Application split - part I
1. Prepare Pure and Bell specific `Application`
   classes and add them to `app` target:

- `products/BellHybrid/apps/Application.cpp`
- `products/PurePhone/apps/Application.cpp`

2. Update `CMakeLists.txt` files.
3. Move `ApplicationBell` implementation to Bell-specific
   `Application` class and remove `ApplicationBell` files.
4. Change Bell apps parent classes from `ApplicationBell`
  to Bell-specific `Application` class.
5. Rename `Application` to `ApplicationCommon` in the rest of the files.
2021-09-13 11:58:10 +02:00

116 lines
3.2 KiB
C++

// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "NewApnWindow.hpp"
#include <application-settings/widgets/SettingsStyle.hpp>
#include <application-settings/windows/WindowNames.hpp>
namespace gui
{
NewApnWindow::NewApnWindow(app::ApplicationCommon *app)
: AppWindow(app, gui::window::name::new_apn),
apn(std::make_shared<packet_data::APN::Config>()), newApnModel{std::make_shared<NewApnModel>(app)}
{
buildInterface();
}
void NewApnWindow::rebuild()
{
destroyInterface();
buildInterface();
}
void NewApnWindow::buildInterface()
{
AppWindow::buildInterface();
bottomBar->setText(BottomBar::Side::CENTER, utils::translate(style::strings::common::save));
bottomBar->setText(BottomBar::Side::RIGHT, utils::translate(style::strings::common::back));
setTitle(utils::translate("app_settings_new_edit_apn"));
list = new gui::ListView(this,
style::settings::window::newApn::x,
style::settings::window::newApn::y,
style::settings::window::newApn::w,
style::settings::window::newApn::h,
newApnModel);
setFocusItem(list);
apnSettingsModel = new ApnSettingsModel(application);
}
void NewApnWindow::destroyInterface()
{
erase();
}
void NewApnWindow::onBeforeShow(ShowMode mode, SwitchData *data)
{
if (mode != ShowMode::GUI_SHOW_RETURN) {
newApnModel->clearData();
}
if (mode == ShowMode::GUI_SHOW_INIT) {
list->rebuildList();
}
if (apn != nullptr) {
newApnModel->loadData(apn);
}
}
auto NewApnWindow::handleSwitchData(SwitchData *data) -> bool
{
setSaveButtonVisible(false);
if (data == nullptr) {
return false;
}
auto *item = dynamic_cast<ApnItemData *>(data);
if (item == nullptr) {
return false;
}
auto apnItem = item->getApn();
if (apnItem != nullptr) {
apn = apnItem;
}
if (!apn->apn.empty()) {
setSaveButtonVisible(true);
}
return true;
}
void NewApnWindow::setSaveButtonVisible(bool visible)
{
bottomBar->setActive(BottomBar::Side::CENTER, visible);
}
auto NewApnWindow::onInput(const InputEvent &inputEvent) -> bool
{
if (!inputEvent.isShortRelease()) {
return false;
}
if (inputEvent.is(gui::KeyCode::KEY_ENTER)) {
newApnModel->saveData(apn);
LOG_DEBUG("APN: \"%s\" ", apn->apn.c_str());
if (apn != nullptr && !apn->apn.empty()) {
apnSettingsModel->saveAPN(apn);
LOG_INFO("APN record saved: \"%s\" ", apn->apn.c_str());
application->returnToPreviousWindow();
}
else {
LOG_WARN("APN not saved, name is empty!");
}
return true;
}
return AppWindow::onInput(inputEvent);
}
} // namespace gui