M module-apps/application-settings/ApplicationSettings.cpp => module-apps/application-settings/ApplicationSettings.cpp +6 -7
@@ 160,11 160,9 @@ namespace app
connect(typeid(::message::bluetooth::ResponseStatus), [&](sys::Message *msg) {
auto responseStatusMsg = static_cast<::message::bluetooth::ResponseStatus *>(msg);
- if (gui::window::name::bluetooth == getCurrentWindow()->getName()) {
- const auto status = responseStatusMsg->getStatus();
- auto btStatusData = std::make_unique<gui::BluetoothStatusData>(status.state, status.visibility);
- switchWindow(gui::window::name::bluetooth, std::move(btStatusData));
- }
+ const auto status = responseStatusMsg->getStatus();
+ const auto bluetoothState = status.state == BluetoothStatus::State::On;
+ bluetoothSettingsModel->setStatus(bluetoothState, status.visibility);
return sys::MessageNone{};
});
@@ 327,6 325,7 @@ namespace app
::settings::SettingsScope::Global);
bluetoothSettingsModel->requestBondedDevices();
+ bluetoothSettingsModel->requestStatus();
return ret;
}
@@ 363,8 362,8 @@ namespace app
return std::make_unique<gui::TextImageColorWindow>(app);
});
// Bluetooth
- windowsFactory.attach(gui::window::name::bluetooth, [](ApplicationCommon *app, const std::string &name) {
- return std::make_unique<gui::BluetoothWindow>(app);
+ windowsFactory.attach(gui::window::name::bluetooth, [this](ApplicationCommon *app, const std::string &name) {
+ return std::make_unique<gui::BluetoothWindow>(app, bluetoothSettingsModel);
});
windowsFactory.attach(gui::window::name::add_device, [this](ApplicationCommon *app, const std::string &name) {
return std::make_unique<gui::AddDeviceWindow>(app, bluetoothSettingsModel);
M module-apps/application-settings/windows/bluetooth/BluetoothWindow.cpp => module-apps/application-settings/windows/bluetooth/BluetoothWindow.cpp +10 -15
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "BluetoothWindow.hpp"
@@ 11,25 11,20 @@
namespace gui
{
- BluetoothWindow::BluetoothWindow(app::ApplicationCommon *app) : BaseSettingsWindow(app, window::name::bluetooth)
+ BluetoothWindow::BluetoothWindow(app::ApplicationCommon *app,
+ std::shared_ptr<BluetoothSettingsModel> bluetoothSettingsModel)
+ : BaseSettingsWindow(app, window::name::bluetooth), bluetoothSettingsModel(bluetoothSettingsModel)
{
setTitle(utils::translate("app_settings_bluetooth_main"));
-
- bluetoothSettingsModel = std::make_unique<BluetoothSettingsModel>(application);
- bluetoothSettingsModel->requestStatus();
}
- void BluetoothWindow::onBeforeShow(ShowMode /*mode*/, SwitchData *data)
+ void BluetoothWindow::onBeforeShow([[maybe_unused]] ShowMode mode, [[maybe_unused]] SwitchData *data)
{
- const auto newData = dynamic_cast<BluetoothStatusData *>(data);
- if (newData != nullptr) {
- if (const auto btState = newData->getState(); btState.has_value()) {
- isBluetoothSwitchOn = btState.value();
- }
- if (const auto visibility = newData->getVisibility(); visibility.has_value()) {
- isPhoneVisibilitySwitchOn = visibility.value();
- }
- }
+ const auto bluetoothStatus = bluetoothSettingsModel->getStatus();
+
+ isBluetoothSwitchOn = bluetoothStatus.state == BluetoothStatus::State::On;
+ isPhoneVisibilitySwitchOn = bluetoothStatus.visibility;
+
refreshOptionsList();
}
M module-apps/application-settings/windows/bluetooth/BluetoothWindow.hpp => module-apps/application-settings/windows/bluetooth/BluetoothWindow.hpp +2 -2
@@ 11,7 11,7 @@ namespace gui
class BluetoothWindow : public BaseSettingsWindow
{
public:
- explicit BluetoothWindow(app::ApplicationCommon *app);
+ BluetoothWindow(app::ApplicationCommon *app, std::shared_ptr<BluetoothSettingsModel> bluetoothSettingsModel);
private:
void onBeforeShow(ShowMode mode, SwitchData *data) override;
@@ 19,7 19,7 @@ namespace gui
void changeBluetoothState(bool ¤tState);
void changeVisibility(bool ¤tVisibility);
- std::unique_ptr<BluetoothSettingsModel> bluetoothSettingsModel;
+ std::shared_ptr<BluetoothSettingsModel> bluetoothSettingsModel;
bool isBluetoothSwitchOn = false;
bool isPhoneVisibilitySwitchOn = false;
OptionWindowDestroyer rai_destroyer = OptionWindowDestroyer(*this);