From c7d9b6e2e9649bc45b682d1b279a0df10f10691a Mon Sep 17 00:00:00 2001 From: RobertPiet Date: Thu, 10 Dec 2020 18:36:35 +0100 Subject: [PATCH] [EGD-4732] "All Operators" menu option is shown when "Operator auto-select" is off; the state is kept in db [EGD-4732] Network menu items visibility / indentation --- changelog.md | 4 +++ .../ApplicationSettings.cpp | 30 ++++++++++++++++++- .../ApplicationSettings.hpp | 21 +++++++++++-- .../windows/NetworkWindow.cpp | 25 ++++++++++------ .../windows/NetworkWindow.hpp | 13 ++++---- module-apps/windows/OptionSetting.cpp | 6 +++- module-apps/windows/OptionSetting.hpp | 7 +++-- 7 files changed, 85 insertions(+), 21 deletions(-) diff --git a/changelog.md b/changelog.md index 009e305cb1c6515c455075ca08253758f03eafa6..91668a7f016e150422d3a28f087ce37bde9dc6ea 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,10 @@ # MuditaOS changelog ## Current release +### Fixed +* `[settings]` Fix lack of sim at startup +* `[settings]` Fix Network All Operators display condition +* `[settings]` Fix Network window items indentation ### Added diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index fc1903826c6a4dc8d1d2085ea297d7d53a818cc8..4b2d8fc39e0fa9bbeb268907e4f163eb8120e901 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -35,6 +35,11 @@ namespace app { + namespace settings + { + constexpr inline auto operators_on = "operators_on"; + } + ApplicationSettingsNew::ApplicationSettingsNew(std::string name, std::string parent, StartInBackground startInBackground) @@ -44,6 +49,13 @@ namespace app Store::GSM::get()->sim == selectedSim) { selectedSimNumber = CellularServiceAPI::GetOwnNumber(this); } + settings->registerValueChange(settings::operators_on, + [this](const std::string &value) { operatorOnChanged(value); }); + } + + ApplicationSettingsNew::~ApplicationSettingsNew() + { + settings->unregisterValueChange(settings::operators_on); } // Invoked upon receiving data message @@ -143,7 +155,8 @@ namespace app return std::make_unique(app); }); windowsFactory.attach(gui::window::name::network, [](Application *app, const std::string &name) { - return std::make_unique(app, dynamic_cast(app)); + return std::make_unique( + app, static_cast(app), static_cast(app)); }); windowsFactory.attach(gui::window::name::messages, [](Application *app, const std::string &name) { return std::make_unique(app); @@ -186,4 +199,19 @@ namespace app return selectedSim; } + void ApplicationSettingsNew::operatorOnChanged(const std::string &value) + { + if (!value.empty()) { + operatorsOn = utils::getNumericValue(value); + } + } + bool ApplicationSettingsNew::getOperatorsOn() const noexcept + { + return operatorsOn; + } + void ApplicationSettingsNew::setOperatorsOn(bool value) + { + operatorsOn = value; + settings->setValue(settings::operators_on, std::to_string(value)); + } } /* namespace app */ diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index 141de14a125af9be1acdcb048a8ea18446ab3425..896f2fca17ceda169cdc86086595ea9d884515a1 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -58,14 +58,24 @@ namespace app virtual Store::GSM::SIM getSim() = 0; virtual std::string getNumber() = 0; }; - } // namespace settingsInterface + class OperatorsSettings + { + public: + virtual ~OperatorsSettings() = default; + virtual void setOperatorsOn(bool value) = 0; + [[nodiscard]] virtual bool getOperatorsOn() const noexcept = 0; + }; + }; // namespace settingsInterface - class ApplicationSettingsNew : public app::Application, public settingsInterface::SimParams + class ApplicationSettingsNew : public app::Application, + public settingsInterface::SimParams, + public settingsInterface::OperatorsSettings { public: ApplicationSettingsNew(std::string name = name_settings_new, std::string parent = {}, StartInBackground startInBackground = {false}); + ~ApplicationSettingsNew() override; auto DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) -> sys::MessagePointer override; auto InitHandler() -> sys::ReturnCodes override; @@ -79,11 +89,16 @@ namespace app void setSim(Store::GSM::SIM sim) override; Store::GSM::SIM getSim() override; std::string getNumber() override; - bsp::Board board = bsp::Board::none; + + void operatorOnChanged(const std::string &value); + void setOperatorsOn(bool value) override; + bool getOperatorsOn() const noexcept override; private: Store::GSM::SIM selectedSim = Store::GSM::get()->selected; std::string selectedSimNumber = {}; + bsp::Board board = bsp::Board::none; + bool operatorsOn = false; }; template <> struct ManifestTraits diff --git a/module-apps/application-settings-new/windows/NetworkWindow.cpp b/module-apps/application-settings-new/windows/NetworkWindow.cpp index 7f0d28f64e3128d074cb077b119bd65cac6abfe2..4ea613d25e4f15a6a3cf606516ae9fabdd9232b3 100644 --- a/module-apps/application-settings-new/windows/NetworkWindow.cpp +++ b/module-apps/application-settings-new/windows/NetworkWindow.cpp @@ -10,10 +10,11 @@ namespace gui { - NetworkWindow::NetworkWindow(app::Application *app, app::settingsInterface::SimParams *simParams) - : OptionWindow(app, gui::window::name::network), simParams(simParams) + NetworkWindow::NetworkWindow(app::Application *app, + app::settingsInterface::SimParams *simParams, + app::settingsInterface::OperatorsSettings *operatorsSettings) + : OptionWindow(app, gui::window::name::network), simParams(simParams), operatorsSettings(operatorsSettings) { - operatorsOn = false; } void NetworkWindow::onBeforeShow(ShowMode m, SwitchData *d) { @@ -39,6 +40,7 @@ namespace gui phoneNumber = {}; break; } + auto operatorsOn = operatorsSettings->getOperatorsOn(); optList.emplace_back(std::make_unique( utils::translateI18("app_settings_network_active_card") + ":" + simStr + " / " + phoneNumber, [=](gui::Item &item) { @@ -63,17 +65,18 @@ namespace gui return true; }, this)); + optList.emplace_back(std::make_unique( utils::translateI18("app_settings_network_operator_auto_select"), [=](gui::Item &item) { - operatorsOn = !operatorsOn; + operatorsSettings->setOperatorsOn(!operatorsOn); rebuild(); return true; }, nullptr, nullptr, operatorsOn ? RightItem::On : RightItem::Off)); - if (operatorsOn) { + if (!operatorsOn) { optList.emplace_back(std::make_unique( utils::translateI18("app_settings_network_all_operators"), [=](gui::Item &item) { @@ -82,13 +85,17 @@ namespace gui }, nullptr, nullptr, - RightItem::ArrowWhite)); + RightItem::ArrowWhite, + true)); } - optList.emplace_back(gui::Option{ - utils::translateI18("app_settings_network_import_contacts_from_sim_card"), [=](gui::Item &item) { + optList.emplace_back(std::make_unique( + utils::translateI18("app_settings_network_import_contacts_from_sim_card"), + [=](gui::Item &item) { this->application->switchWindow(gui::window::name::import_contacts, nullptr); return true; - }}); + }, + nullptr, + nullptr)); bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select)); diff --git a/module-apps/application-settings-new/windows/NetworkWindow.hpp b/module-apps/application-settings-new/windows/NetworkWindow.hpp index 710fcd3b2229899d60833219b812d71fa748ce6e..41b8b994b072eb61681210cae77df2c27eedab00 100644 --- a/module-apps/application-settings-new/windows/NetworkWindow.hpp +++ b/module-apps/application-settings-new/windows/NetworkWindow.hpp @@ -9,7 +9,8 @@ namespace app::settingsInterface { class SimParams; -} + class OperatorsSettings; +}; // namespace app::settingsInterface namespace gui { @@ -22,13 +23,15 @@ namespace gui class NetworkWindow : public OptionWindow { private: - bool operatorsOn; - app::settingsInterface::SimParams *simParams; auto netOptList() -> std::list; - void rebuild() override; + app::settingsInterface::SimParams *simParams; + void rebuild(); + app::settingsInterface::OperatorsSettings *operatorsSettings; public: - NetworkWindow(app::Application *app, app::settingsInterface::SimParams *simParams); + NetworkWindow(app::Application *app, + app::settingsInterface::SimParams *simParams, + app::settingsInterface::OperatorsSettings *operatorsSettings); void onBeforeShow(ShowMode m, SwitchData *d) override; }; } // namespace gui diff --git a/module-apps/windows/OptionSetting.cpp b/module-apps/windows/OptionSetting.cpp index 6a788837a34d086c7540bc6f460e3b528d2088f8..d85d67285acf0b4b256e7acf512354a8c1afe234 100644 --- a/module-apps/windows/OptionSetting.cpp +++ b/module-apps/windows/OptionSetting.cpp @@ -14,7 +14,8 @@ namespace gui optionBodyHBox->focusChangedCallback = focusCb; style::window::decorate(optionBodyHBox); - auto optionNameLabel = new Label(optionBodyHBox, 0, 0, 0, 0, text); + auto optionNameLabel = + new Label(optionBodyHBox, indent ? style::window::default_left_margin : 0, 0, 0, 0, text); optionNameLabel->setEdges(RectangleEdge::None); optionNameLabel->setAlignment(Alignment(gui::Alignment::Horizontal::Left, gui::Alignment::Vertical::Center)); optionNameLabel->setFont(style::window::font::big); @@ -51,6 +52,9 @@ namespace gui auto image = new gui::Image(optionBodyHBox, 0, 0, 0, 0, imageName); optionRightItemWidth = image->getWidth(); } + if (indent) { + optionRightItemWidth += style::window::default_left_margin; + } optionNameLabel->setMinimumSize(style::window::default_body_width - optionRightItemWidth, style::window::label::big_h); diff --git a/module-apps/windows/OptionSetting.hpp b/module-apps/windows/OptionSetting.hpp index bf6f503539787a6a3b686b11ee344d09becd142a..6abe5d67c6dc9b3459d454bed16bdce13f4d35e4 100644 --- a/module-apps/windows/OptionSetting.hpp +++ b/module-apps/windows/OptionSetting.hpp @@ -27,14 +27,17 @@ namespace gui std::function focusCb = nullptr; AppWindow *app = nullptr; RightItem rightItem = RightItem::Disabled; + bool indent = false; public: OptionSettings(const UTF8 text, std::function cb, std::function cbFocus, AppWindow *app, - RightItem rightItem = RightItem::Disabled) - : text(text), activatedCallback(std::move(cb)), focusCb(std::move(cbFocus)), app(app), rightItem(rightItem) + RightItem rightItem = RightItem::Disabled, + bool indent = false) + : text(text), activatedCallback(std::move(cb)), focusCb(std::move(cbFocus)), app(app), rightItem(rightItem), + indent(indent) {} [[nodiscard]] auto build() const -> Item * override; };