From 39e6f1b18a93471342a4f8cce3810dee0e7948be Mon Sep 17 00:00:00 2001 From: RobertPiet Date: Fri, 26 Feb 2021 17:52:45 +0100 Subject: [PATCH] [EGD-5902] Phone Modes Windows Windows for phone modes created. Offline:FightMode/messages only ServiceCellularApi created. ConnectionFrequency and DND options settings throught AppSettings. --- image/assets/lang/English.json | 15 +++- image/user/db/settings_v2_002.sql | 7 +- .../ApplicationSettings.cpp | 79 +++++++++++++++++ .../ApplicationSettings.hpp | 50 ++++++++++- .../application-settings-new/CMakeLists.txt | 4 + .../widgets/SettingsStyle.hpp | 12 +++ .../windows/ConnectionFrequencyWindow.cpp | 63 ++++++++++++++ .../windows/ConnectionFrequencyWindow.hpp | 34 ++++++++ .../windows/DoNotDisturbWindow.cpp | 72 +++++++++++++++ .../windows/DoNotDisturbWindow.hpp | 35 ++++++++ .../windows/OfflineWindow.cpp | 87 +++++++++++++++++++ .../windows/OfflineWindow.hpp | 31 +++++++ .../windows/PhoneModesWindow.cpp | 79 +++++++++++++++++ .../windows/PhoneModesWindow.hpp | 37 ++++++++ module-apps/options/OptionStyle.hpp | 1 + module-apps/options/type/OptionSetting.cpp | 7 +- module-apps/options/type/OptionSetting.hpp | 6 +- module-gui/gui/widgets/Style.hpp | 1 + .../service-cellular/CellularServiceAPI.cpp | 6 ++ .../service-cellular/ServiceCellular.cpp | 13 +++ .../service-cellular/CellularMessage.hpp | 9 ++ .../service-cellular/CellularServiceAPI.hpp | 2 + .../service-cellular/ServiceCellular.hpp | 2 + .../agents/settings/SystemSettings.hpp | 8 ++ source/MessageType.hpp | 1 + 25 files changed, 654 insertions(+), 7 deletions(-) create mode 100644 module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp create mode 100644 module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp create mode 100644 module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp create mode 100644 module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp create mode 100644 module-apps/application-settings-new/windows/OfflineWindow.cpp create mode 100644 module-apps/application-settings-new/windows/OfflineWindow.hpp create mode 100644 module-apps/application-settings-new/windows/PhoneModesWindow.cpp create mode 100644 module-apps/application-settings-new/windows/PhoneModesWindow.hpp diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index 97eba447541f88f951dcce0627970d2ce2810a19..0c92700f3c554c370f6d618994fbc32c5226b7db 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -28,6 +28,7 @@ "common_connect": "CONNECT", "common_disconnect": "DISCONNECT", "common_forget": "FORGET", + "common_adjust": "ADJUST", "common_mo": "MO", "common_tu": "TU", "common_we": "WE", @@ -434,6 +435,19 @@ "app_settings_title_color_test": "Display available colors", "app_settings_toolbar_reset": "RESET", "app_settings_option_connected": "CONNECTED", + "app_settings_title_phone_modes": "Phone modes", + "app_settings_title_do_not_disturb": "Do not disturb", + "app_settings_title_offline": "Offline", + "app_settings_title_connection_frequency": "Connection frequency", + "app_settings_connected": "Connected", + "app_settings_notifications_when_locked": "Notifications when locked", + "app_settings_calls_from_favorites": "Calls from favorites", + "app_settings_allow": "Allow", + "app_settings_no_network_connection_flight_mode": "No network connection (flight mode)", + "app_settings_messages_only": "Messages only", + "app_settings_info_dnd": "This mode enables Pure to silently receive all notifications. You can allow notifications when favorite contacts call you.", + "app_settings_info_offline_flight_mode": "This mode causes your Pure to be fully disconnected. You can safely use it as flight mode. Calls, messages and tethering are unavailable.", + "app_settings_info_offline_messages_only": "Pure will log into the network to send and download messages based on connection frequency. Calls and tethering are unavailable.", "app_phonebook_title_main": "Contacts", "app_phonebook_search_win_contacts": "Contacts", "common_search_uc": "Search", @@ -520,7 +534,6 @@ "app_desktop_update_to": "Update to", "app_desktop_update_apply": "Do you want to apply this update?", "app_desktop_update_current": "Current", - "app_desktop_update_apply": "Apply update?", "app_desktop_update_start": "Update start", "app_desktop_update_size": "size", "app_desktop_update_bytes": "bytes", diff --git a/image/user/db/settings_v2_002.sql b/image/user/db/settings_v2_002.sql index cc79d27855f6a0e84e10cb396f72e7e1f0286eef..c95886fad393640677716aa1e1a8cf72b7663a06 100644 --- a/image/user/db/settings_v2_002.sql +++ b/image/user/db/settings_v2_002.sql @@ -28,5 +28,10 @@ INSERT OR IGNORE INTO settings_tab (path, value) VALUES ('bt_device_visibility', '0'), ('bt_device_name', 'PurePhone'), ('bt_bonded_devices', ''), - ('battery_critical_level', '0'); + ('battery_critical_level', '0'), + ('cl_offline_mode', '0'), + ('off_connection_frequency', '0'), + ('off_notifications_when_locked', '0'), + ('off_calls_from_favorites', '0'); + diff --git a/module-apps/application-settings-new/ApplicationSettings.cpp b/module-apps/application-settings-new/ApplicationSettings.cpp index e0fe29c43a7df30fd6bc6d110fa7ed1626491f56..d7b72205e72cc1cab859d37158806fd5ce7d8c38 100644 --- a/module-apps/application-settings-new/ApplicationSettings.cpp +++ b/module-apps/application-settings-new/ApplicationSettings.cpp @@ -37,6 +37,10 @@ #include "windows/ChangeTimeZone.hpp" #include "windows/ChangeDateAndTimeWindow.hpp" #include +#include "windows/PhoneModesWindow.hpp" +#include "windows/DoNotDisturbWindow.hpp" +#include "windows/OfflineWindow.hpp" +#include "windows/ConnectionFrequencyWindow.hpp" #include "Dialog.hpp" #include "DialogMetadataMessage.hpp" @@ -349,6 +353,23 @@ namespace app [this](std::string value) { usbSecured = utils::getNumericValue(value); }, ::settings::SettingsScope::Global); */ + settings->registerValueChange( + ::settings::Cellular::offlineMode, + [this](const std::string &value) { flightModeOn = utils::getNumericValue(value); }, + ::settings::SettingsScope::Global); + + settings->registerValueChange( + ::settings::Offline::callsFromFavorites, + [this](const std::string &value) { callsFromFavorites = utils::getNumericValue(value); }, + ::settings::SettingsScope::Global); + settings->registerValueChange( + ::settings::Offline::connectionFrequency, + [this](const std::string &value) { utils::toNumeric(value, connectionFrequency); }, + ::settings::SettingsScope::Global); + settings->registerValueChange( + ::settings::Offline::notificationsWhenLocked, + [this](const std::string &value) { notificationsWhenLocked = utils::getNumericValue(value); }, + ::settings::SettingsScope::Global); return ret; } @@ -473,6 +494,19 @@ namespace app }); attachPopups({gui::popup::ID::Volume}); + windowsFactory.attach(gui::window::name::phone_modes, [](Application *app, const std::string &name) { + return std::make_unique( + app, static_cast(app), static_cast(app)); + }); + windowsFactory.attach(gui::window::name::do_not_disturb, [](Application *app, const std::string &name) { + return std::make_unique(app, static_cast(app)); + }); + windowsFactory.attach(gui::window::name::offline, [](Application *app, const std::string &name) { + return std::make_unique(app, static_cast(app)); + }); + windowsFactory.attach(gui::window::name::connection_frequency, [](Application *app, const std::string &name) { + return std::make_unique(app, static_cast(app)); + }); } void ApplicationSettingsNew::destroyUserInterface() @@ -624,4 +658,49 @@ namespace app settings->setValue( ::settings::SystemProperties::usbSecurity, std::to_string(security), ::settings::SettingsScope::Global); } + + auto ApplicationSettingsNew::getNotificationsWhenLocked() const noexcept -> bool + { + return notificationsWhenLocked; + } + void ApplicationSettingsNew::setNotificationsWhenLocked(bool on) noexcept + { + notificationsWhenLocked = on; + settings->setValue( + ::settings::Offline::notificationsWhenLocked, std::to_string(on), ::settings::SettingsScope::Global); + } + auto ApplicationSettingsNew::getCallsFromFavourite() const noexcept -> bool + { + return callsFromFavorites; + } + void ApplicationSettingsNew::setCallsFromFavourite(bool on) noexcept + { + callsFromFavorites = on; + settings->setValue( + ::settings::Offline::callsFromFavorites, std::to_string(on), ::settings::SettingsScope::Global); + } + + auto ApplicationSettingsNew::isFlightMode() const noexcept -> bool + { + return flightModeOn; + } + + void ApplicationSettingsNew::setFlightMode(bool flightModeOn) noexcept + { + this->flightModeOn = flightModeOn; + CellularServiceAPI::SetFlightMode(this, flightModeOn); + } + + auto ApplicationSettingsNew::getConnectionFrequency() const noexcept -> uint8_t + { + return connectionFrequency; + } + + void ApplicationSettingsNew::setConnectionFrequency(uint8_t val) noexcept + { + connectionFrequency = val; + settings->setValue( + ::settings::Offline::connectionFrequency, std::to_string(val), ::settings::SettingsScope::Global); + } + } /* namespace app */ diff --git a/module-apps/application-settings-new/ApplicationSettings.hpp b/module-apps/application-settings-new/ApplicationSettings.hpp index f83214219a53f0a5158bd87f99566f8b4e8d6856..67bbff629d4e72a4f55642689343ac427178d66a 100644 --- a/module-apps/application-settings-new/ApplicationSettings.hpp +++ b/module-apps/application-settings-new/ApplicationSettings.hpp @@ -65,6 +65,10 @@ namespace gui::window::name inline constexpr auto new_apn = "NewApn"; inline constexpr auto bluetooth_check_passkey = "BluetoothCheckPasskey"; + inline constexpr auto do_not_disturb = "DoNotDisturb"; + inline constexpr auto offline = "Offline"; + inline constexpr auto connection_frequency = "ConnectionFrequency"; + } // namespace gui::window::name namespace app @@ -124,6 +128,32 @@ namespace app virtual void setUSBSecurity(bool security) = 0; }; + class DndSettings + { + public: + virtual ~DndSettings() = default; + + virtual auto getNotificationsWhenLocked() const noexcept -> bool = 0; + virtual void setNotificationsWhenLocked(bool on) noexcept = 0; + virtual auto getCallsFromFavourite() const noexcept -> bool = 0; + virtual void setCallsFromFavourite(bool on) noexcept = 0; + }; + + class ConnectionSettings + { + public: + virtual ~ConnectionSettings() = default; + + virtual auto getConnectionFrequency() const noexcept -> uint8_t = 0; + virtual void setConnectionFrequency(uint8_t val) noexcept = 0; + }; + + class OfflineSettings + { + public: + virtual auto isFlightMode() const noexcept -> bool = 0; + virtual void setFlightMode(bool flightModeOn) noexcept = 0; + }; }; // namespace settingsInterface class ApplicationSettingsNew : public app::Application, @@ -131,7 +161,10 @@ namespace app public settingsInterface::OperatorsSettings, public settingsInterface::ScreenLightSettings, public settingsInterface::KeypdBacklightSettings, - public settingsInterface::SecuritySettings + public settingsInterface::SecuritySettings, + public settingsInterface::DndSettings, + public settingsInterface::OfflineSettings, + public settingsInterface::ConnectionSettings { public: ApplicationSettingsNew(std::string name = name_settings_new, @@ -179,6 +212,17 @@ namespace app void setLockScreenPasscodeOn(bool passcodeOn); auto isLockScreenPasscodeOn() const -> bool; + auto getNotificationsWhenLocked() const noexcept -> bool override; + void setNotificationsWhenLocked(bool on) noexcept override; + auto getCallsFromFavourite() const noexcept -> bool override; + void setCallsFromFavourite(bool on) noexcept override; + + auto isFlightMode() const noexcept -> bool override; + void setFlightMode(bool flightModeOn) noexcept override; + + auto getConnectionFrequency() const noexcept -> uint8_t override; + void setConnectionFrequency(uint8_t val) noexcept override; + private: void attachQuotesWindows(); @@ -190,6 +234,10 @@ namespace app bool usbSecured = true; bool lockScreenPasscodeOn = true; unsigned int lockPassHash = 0; + bool notificationsWhenLocked = true; + bool callsFromFavorites = false; + int connectionFrequency = 0; + bool flightModeOn = true; }; template <> struct ManifestTraits diff --git a/module-apps/application-settings-new/CMakeLists.txt b/module-apps/application-settings-new/CMakeLists.txt index 66e5d53ec30ffecfebdf63804b7348bbc0874516..a349bed9b0d3db5ff564c17efd3c65516b3036fb 100644 --- a/module-apps/application-settings-new/CMakeLists.txt +++ b/module-apps/application-settings-new/CMakeLists.txt @@ -66,6 +66,10 @@ target_sources( ${PROJECT_NAME} windows/BluetoothCheckPasskeyWindow.cpp windows/EditQuotesWindow.cpp windows/QuoteCategoriesWindow.cpp + windows/ConnectionFrequencyWindow.cpp + windows/DoNotDisturbWindow.cpp + windows/OfflineWindow.cpp + windows/PhoneModesWindow.cpp PUBLIC ApplicationSettings.hpp diff --git a/module-apps/application-settings-new/widgets/SettingsStyle.hpp b/module-apps/application-settings-new/widgets/SettingsStyle.hpp index bf916e683225d0cd34d8ecbcee76a1c6a33b3850..6e0ae913c5303bcc0fae60509518ee25dd164cbc 100644 --- a/module-apps/application-settings-new/widgets/SettingsStyle.hpp +++ b/module-apps/application-settings-new/widgets/SettingsStyle.hpp @@ -116,6 +116,18 @@ namespace style } // namespace text } // namespace passkey } // namespace bluetooth + + namespace offline + { + inline constexpr auto body_offset = 155; + + inline constexpr auto bar_y = 396; + inline constexpr auto bar_h = 1; + + inline constexpr auto description_y = 375; + inline constexpr auto description_h = 150; + } // namespace offline + } // namespace window }; // namespace settings namespace quotes::categories diff --git a/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp b/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..db6c9b81672abc537b417bb2e8014b7e457f37cb --- /dev/null +++ b/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.cpp @@ -0,0 +1,63 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "ConnectionFrequencyWindow.hpp" +#include "application-settings-new/ApplicationSettings.hpp" +#include "OptionSetting.hpp" +#include + +namespace gui +{ + ConnectionFrequencyWindow::ConnectionFrequencyWindow(app::Application *app, + app::settingsInterface::ConnectionSettings *connectionSettings) + : BaseSettingsWindow(app, gui::window::name::connection_frequency), connectionSettings(connectionSettings) + {} + void ConnectionFrequencyWindow::onBeforeShow(ShowMode m, SwitchData *d) + { + rebuild(); + } + auto ConnectionFrequencyWindow::buildOptionsList() -> std::list + { + std::list optList; + std::vector frequency{0, 15, 30, 45, 60}; + + auto intervalText = [](uint8_t value) { + if (value == 0) { + return utils::localize.get("app_alarm_clock_repeat_never"); + } + const std::string toReplace = "%0"; + std::string temp = utils::translateI18("app_meditation_interval_every_x_minutes"); + temp.replace(temp.find(toReplace), toReplace.size(), std::to_string(value)); + return temp; + }; + + for (auto freq : frequency) { + optList.emplace_back(std::make_unique( + intervalText(freq), + [=](gui::Item &item) { + updateInterval(freq); + return true; + }, + nullptr, + nullptr, + (freq == connectionSettings->getConnectionFrequency()) ? option::SettingRightItem::Checked + : option::SettingRightItem::Disabled)); + } + + bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::select)); + bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back)); + + return optList; + } + void ConnectionFrequencyWindow::rebuild() + { + clearOptions(); + addOptions(buildOptionsList()); + } + void ConnectionFrequencyWindow::updateInterval(uint8_t value) + { + connectionSettings->setConnectionFrequency(value); + refreshOptionsList(); + } + +} // namespace gui diff --git a/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp b/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f5bda8fb5c9be6c3a4c928c1e1242cb2fce2845e --- /dev/null +++ b/module-apps/application-settings-new/windows/ConnectionFrequencyWindow.hpp @@ -0,0 +1,34 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "BaseSettingsWindow.hpp" + +namespace app::settingsInterface +{ + class ConnectionSettings; +}; // namespace app::settingsInterface + +namespace gui +{ + + namespace window + { + inline constexpr auto connection_frequency_window = "ConnectionFrequency"; + }; + + class ConnectionFrequencyWindow : public BaseSettingsWindow + { + private: + auto buildOptionsList() -> std::list override; + void rebuild() override; + app::settingsInterface::ConnectionSettings *connectionSettings; + void updateInterval(uint8_t value); + + public: + ConnectionFrequencyWindow(app::Application *app, + app::settingsInterface::ConnectionSettings *connectionSettings); + void onBeforeShow(ShowMode m, SwitchData *d) override; + }; +} // namespace gui diff --git a/module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp b/module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd4397eeabcb5f8fe9350ef8878f78b088fde6c5 --- /dev/null +++ b/module-apps/application-settings-new/windows/DoNotDisturbWindow.cpp @@ -0,0 +1,72 @@ +// Copyright (c) 2017-2020, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "DoNotDisturbWindow.hpp" +#include "application-settings-new/ApplicationSettings.hpp" +#include "application-settings-new/widgets/SettingsStyle.hpp" + +#include "OptionSetting.hpp" + +#include + +namespace gui +{ + DoNotDisturbWindow::DoNotDisturbWindow(app::Application *app, app::settingsInterface::DndSettings *dndSettings) + : BaseSettingsWindow(app, gui::window::name::do_not_disturb), dndSettings(dndSettings) + { + buildInterface(); + } + + void DoNotDisturbWindow::buildInterface() + { + setTitle(utils::translateI18("app_settings_title_do_not_disturb")); + optionsList->setSize(optionsList->getWidth(), + optionsList->getHeight() - style::settings::window::offline::body_offset); + bar = new Rect(this, + style::window::default_left_margin, + style::settings::window::offline::bar_y, + style::window::default_body_width, + style::settings::window::offline::bar_h); + bar->setVisible(true); + descriptionText = new Text(this, + style::window::default_left_margin, + style::settings::window::offline::description_y, + style::window::default_body_width, + style::settings::window::offline::description_h); + descriptionText->setFont(style::window::font::medium); + descriptionText->setText(utils::translateI18("app_settings_info_dnd")); + descriptionText->setVisible(true); + } + + auto DoNotDisturbWindow::buildOptionsList() -> std::list + { + std::list optList; + optList.emplace_back(std::make_unique( + utils::translateI18("app_settings_notifications_when_locked"), + [=](gui::Item &item) { + dndSettings->setNotificationsWhenLocked(!dndSettings->getNotificationsWhenLocked()); + refreshOptionsList(); + return true; + }, + nullptr, + this, + (dndSettings->getNotificationsWhenLocked()) ? gui::option::SettingRightItem::On + : gui::option::SettingRightItem::Off)); + + optList.emplace_back(std::make_unique( + utils::translateI18("app_settings_calls_from_favorites"), + [=](gui::Item &item) { + dndSettings->setCallsFromFavourite(!dndSettings->getCallsFromFavourite()); + refreshOptionsList(); + return true; + }, + nullptr, + this, + (dndSettings->getCallsFromFavourite()) ? gui::option::SettingRightItem::On + : gui::option::SettingRightItem::Off)); + + bottomBar->setText(BottomBar::Side::RIGHT, utils::localize.get(style::strings::common::back)); + bottomBar->setText(BottomBar::Side::CENTER, utils::localize.get(style::strings::common::Switch)); + return optList; + } +} // namespace gui diff --git a/module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp b/module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a5df4e79edf28f56f843d6b1c71276469311c127 --- /dev/null +++ b/module-apps/application-settings-new/windows/DoNotDisturbWindow.hpp @@ -0,0 +1,35 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "BaseSettingsWindow.hpp" + +#include + +namespace app::settingsInterface +{ + class DndSettings; +} // namespace app::settingsInterface + +namespace gui +{ + + namespace window + { + inline constexpr auto do_not_disturb_window = "DoNotDisturb"; + }; + + class DoNotDisturbWindow : public BaseSettingsWindow + { + public: + DoNotDisturbWindow(app::Application *app, app::settingsInterface::DndSettings *dndSettings); + void buildInterface() override; + + private: + app::settingsInterface::DndSettings *dndSettings = nullptr; + Rect *bar = nullptr; + Text *descriptionText = nullptr; + auto buildOptionsList() -> std::list