From c0e13a83973fcb27e9fe99cd8044921a067fd89c Mon Sep 17 00:00:00 2001 From: Maciej Gibowicz Date: Mon, 25 Mar 2024 14:01:34 +0100 Subject: [PATCH] [BH-1916] Add Error handling to the vertical list Added error handling in case the file selected in the vertical list is either corrupted or deleted. --- image/system_a/data/lang/Deutsch.json | 6 +- image/system_a/data/lang/English.json | 6 +- image/system_a/data/lang/Espanol.json | 6 +- image/system_a/data/lang/Francais.json | 6 +- image/system_a/data/lang/Polski.json | 6 +- .../ApplicationCommonPopupBlueprints.cpp | 16 ++- module-apps/apps-common/popups/Popups.cpp | 4 +- module-apps/apps-common/popups/Popups.hpp | 4 +- .../popups/data/AudioErrorParams.hpp | 36 +++++++ products/BellHybrid/apps/Application.cpp | 9 ++ .../ApplicationBellRelaxation.cpp | 16 +-- .../CMakeLists.txt | 5 - .../data/RelaxationErrorData.hpp | 31 ------ .../data/RelaxationStyle.hpp | 8 +- .../ApplicationBellRelaxation.hpp | 1 - .../presenter/RelaxationErrorPresenter.cpp | 23 ---- .../windows/RelaxationErrorWindow.cpp | 93 ---------------- .../windows/RelaxationErrorWindow.hpp | 34 ------ .../windows/RelaxationMainWindow.cpp | 7 +- .../windows/RelaxationRunningLoopWindow.cpp | 11 +- .../RelaxationRunningProgressWindow.cpp | 12 +-- .../ApplicationBellSettings.cpp | 31 ++++-- .../application-bell-settings/CMakeLists.txt | 2 + .../models/AudioErrorModel.hpp | 28 +++++ .../models/AudioErrorModel.cpp | 29 +++++ .../AlarmSettingsListItemProvider.cpp | 6 ++ .../BedtimeSettingsListItemProvider.cpp | 6 ++ .../PrewakeUpListItemProvider.cpp | 6 ++ .../SettingsListItemProvider.hpp | 2 + .../alarm_settings/SnoozeListItemProvider.cpp | 6 ++ .../presenter/BedtimeSettingsPresenter.cpp | 61 +++++++++-- .../presenter/BedtimeSettingsPresenter.hpp | 22 ++-- .../alarm_settings/AlarmSettingsPresenter.cpp | 53 +++++++++- .../alarm_settings/AlarmSettingsPresenter.hpp | 10 +- .../alarm_settings/PrewakeUpPresenter.cpp | 59 +++++++++-- .../alarm_settings/PrewakeUpPresenter.hpp | 20 ++-- .../alarm_settings/SnoozePresenter.cpp | 64 +++++++++-- .../alarm_settings/SnoozePresenter.hpp | 32 +++--- .../windows/BellSettingsBedtimeToneWindow.cpp | 17 ++- .../windows/BellSettingsBedtimeToneWindow.hpp | 4 +- .../BellSettingsAlarmSettingsSnoozeWindow.cpp | 17 ++- .../BellSettingsAlarmSettingsSnoozeWindow.hpp | 4 +- .../BellSettingsAlarmSettingsWindow.cpp | 16 ++- .../BellSettingsAlarmSettingsWindow.hpp | 4 +- .../BellSettingsPrewakeUpWindow.cpp | 18 +++- .../BellSettingsPrewakeUpWindow.hpp | 4 +- .../BellHybrid/apps/common/CMakeLists.txt | 4 + .../include/common/AudioErrorPresenter.hpp} | 12 +-- .../common/include/common/BellCommonNames.hpp | 4 +- .../common/windows/AudioErrorWindow.hpp | 37 +++++++ .../apps/common/src/AudioErrorPresenter.cpp | 19 ++++ .../common/src/windows/AudioErrorWindow.cpp | 100 ++++++++++++++++++ 52 files changed, 730 insertions(+), 307 deletions(-) create mode 100644 module-apps/apps-common/popups/data/AudioErrorParams.hpp delete mode 100644 products/BellHybrid/apps/application-bell-relaxation/data/RelaxationErrorData.hpp delete mode 100644 products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.cpp delete mode 100644 products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.cpp delete mode 100644 products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/models/AudioErrorModel.hpp create mode 100644 products/BellHybrid/apps/application-bell-settings/models/AudioErrorModel.cpp rename products/BellHybrid/apps/{application-bell-relaxation/presenter/RelaxationErrorPresenter.hpp => common/include/common/AudioErrorPresenter.hpp} (64%) create mode 100644 products/BellHybrid/apps/common/include/common/windows/AudioErrorWindow.hpp create mode 100644 products/BellHybrid/apps/common/src/AudioErrorPresenter.cpp create mode 100644 products/BellHybrid/apps/common/src/windows/AudioErrorWindow.cpp diff --git a/image/system_a/data/lang/Deutsch.json b/image/system_a/data/lang/Deutsch.json index cec2c01593e4c07edb99680f055742993c4fcac1..8d2fc9afc9e7e572f9139c463d1f672d0c78194b 100644 --- a/image/system_a/data/lang/Deutsch.json +++ b/image/system_a/data/lang/Deutsch.json @@ -52,9 +52,9 @@ "app_bell_onboarding_shortcuts_step_restart": "F\u00fcr Ger\u00e4teneustart beide Seitenkn\u00f6pfe 10 Sek. dr\u00fccken", "app_bell_onboarding_shortcuts_step_rotate": "Zum Ausw\u00e4hlen drehen", "app_bell_onboarding_shortcuts_step_turn_off": "Zum Ausstellen des Ger\u00e4ts R\u00fcckseite 10 Sek. dr\u00fccken", - "app_bell_relaxation_error_message": "Nicht unterst\u00fctztes Dateiformat", - "app_bell_relaxation_file_deleted_message": "Die Datei wurde gel\u00f6scht.", - "app_bell_relaxation_limit_error_message": "Datenlimit \u00fcberschritten.
Es k\u00f6nnte zu Fehlern kommen.
", + "app_bell_audio_error_message": "Nicht unterst\u00fctztes Dateiformat", + "app_bell_audio_file_deleted_message": "Die Datei wurde gel\u00f6scht.", + "app_bell_audio_limit_error_message": "Datenlimit \u00fcberschritten.
Es k\u00f6nnte zu Fehlern kommen.
", "app_bell_relaxation_loop": "endlos", "app_bell_relaxation_loop_description": "der Titel wird abgespielt, bis Sie ihn ausschalten", "app_bell_relaxation_looped": "geschlungen", diff --git a/image/system_a/data/lang/English.json b/image/system_a/data/lang/English.json index 4d5de8d431f62b65bf6a145e6a7377a74e6bfa80..db01aea117170e9fd2066d591a2eeb7c68c89619 100644 --- a/image/system_a/data/lang/English.json +++ b/image/system_a/data/lang/English.json @@ -85,9 +85,9 @@ "app_bell_onboarding_shortcuts_step_restart": "Press both side buttons for 10s to restart the device", "app_bell_onboarding_shortcuts_step_rotate": "Rotate to select", "app_bell_onboarding_shortcuts_step_turn_off": "Press back for 10s to turn off the device", - "app_bell_relaxation_error_message": "Unsupported media type", - "app_bell_relaxation_file_deleted_message": "The file has been deleted.", - "app_bell_relaxation_limit_error_message": "File limit exceeded.
Not all files may be displayed
correctly
", + "app_bell_audio_error_message": "Unsupported media type", + "app_bell_audio_file_deleted_message": "The file has been deleted.", + "app_bell_audio_limit_error_message": "File limit exceeded.
Not all files may be displayed
correctly
", "app_bell_relaxation_loop": "loop", "app_bell_relaxation_loop_description": "the song will play until you turn it off", "app_bell_relaxation_looped": "looped", diff --git a/image/system_a/data/lang/Espanol.json b/image/system_a/data/lang/Espanol.json index 19c345c757da13805ff062d4d22922ecd2d6f79b..4ae73d19d6f81c9cb42aa8b2e1faeba46ecccc7c 100644 --- a/image/system_a/data/lang/Espanol.json +++ b/image/system_a/data/lang/Espanol.json @@ -51,9 +51,9 @@ "app_bell_onboarding_shortcuts_step_restart": "Pulsa ambos botones laterales 10 s para reiniciar", "app_bell_onboarding_shortcuts_step_rotate": "Girar para seleccionar", "app_bell_onboarding_shortcuts_step_turn_off": "Pulsa Volver atr\u00e1s 10 s para apagar el dispositivo", - "app_bell_relaxation_error_message": "Formato de archivo no admitido", - "app_bell_relaxation_file_deleted_message": "Se ha eliminado el archivo.", - "app_bell_relaxation_limit_error_message": "L\u00edmite de archivos alcanzado,
pueden producirse errores.
", + "app_bell_audio_error_message": "Formato de archivo no admitido", + "app_bell_audio_file_deleted_message": "Se ha eliminado el archivo.", + "app_bell_audio_limit_error_message": "L\u00edmite de archivos alcanzado,
pueden producirse errores.
", "app_bell_relaxation_loop": "bucle", "app_bell_relaxation_loop_description": "la canci\u00f3n se reproducir\u00e1 hasta que la apagues", "app_bell_relaxation_looped": "en bucle", diff --git a/image/system_a/data/lang/Francais.json b/image/system_a/data/lang/Francais.json index b566c2a02d39338fc317642cc64feedee9667581..70c4ed675fce2c106498398234d20e3ffc19ce55 100644 --- a/image/system_a/data/lang/Francais.json +++ b/image/system_a/data/lang/Francais.json @@ -53,9 +53,9 @@ "app_bell_onboarding_shortcuts_step_restart": "Pressez les boutons lat\u00e9raux pendant 10 sec pour red\u00e9marrer", "app_bell_onboarding_shortcuts_step_rotate": "Faites tourner pour s\u00e9lectionner", "app_bell_onboarding_shortcuts_step_turn_off": "Appuyez sur Retour pendant 10 sec pour \u00e9teindre l'appareil", - "app_bell_relaxation_error_message": "Format de fichier non pris en

charge
", - "app_bell_relaxation_file_deleted_message": "Le fichier a \u00e9t\u00e9 supprim\u00e9.", - "app_bell_relaxation_limit_error_message": "Limite de fichiers exc\u00e9d\u00e9e.
Risque de probl\u00e8mes
d'affichage
", + "app_bell_audio_error_message": "Format de fichier non pris en

charge
", + "app_bell_audio_file_deleted_message": "Le fichier a \u00e9t\u00e9 supprim\u00e9.", + "app_bell_audio_limit_error_message": "Limite de fichiers exc\u00e9d\u00e9e.
Risque de probl\u00e8mes
d'affichage
", "app_bell_relaxation_loop": "en boucle", "app_bell_relaxation_loop_description": "le morceau sera lu jusqu'\u00e0 ce que vous l'\u00e9teigniez", "app_bell_relaxation_looped": "en boucle", diff --git a/image/system_a/data/lang/Polski.json b/image/system_a/data/lang/Polski.json index de9171642eb3a7761a8c7ead44b64efb7d6a1e06..ee9df5015de92a3ef67c7ea917ef0401deca42b2 100644 --- a/image/system_a/data/lang/Polski.json +++ b/image/system_a/data/lang/Polski.json @@ -52,9 +52,9 @@ "app_bell_onboarding_shortcuts_step_restart": "Przytrzymaj oba boczne przyciski przez 10s, aby zrestartowa\u0107 urz\u0105dzenie", "app_bell_onboarding_shortcuts_step_rotate": "Obr\u00f3\u0107, aby wybra\u0107", "app_bell_onboarding_shortcuts_step_turn_off": "Przytrzymaj przycisk wstecz przez 10s aby wy\u0142\u0105czy\u0107 urz\u0105dzenie", - "app_bell_relaxation_error_message": "Nieobs\u0142ugiwany format pliku", - "app_bell_relaxation_file_deleted_message": "Plik zosta\u0142 usuni\u0119ty.", - "app_bell_relaxation_limit_error_message": "Przekroczono limit plik\u00f3w.
Nie wszystkie pliki mog\u0105 by\u0107
wy\u015bwietlone poprawnie
", + "app_bell_audio_error_message": "Nieobs\u0142ugiwany format pliku", + "app_bell_audio_file_deleted_message": "Plik zosta\u0142 usuni\u0119ty.", + "app_bell_audio_limit_error_message": "Przekroczono limit plik\u00f3w.
Nie wszystkie pliki mog\u0105 by\u0107
wy\u015bwietlone poprawnie
", "app_bell_relaxation_loop": "w p\u0119tli", "app_bell_relaxation_loop_description": "utw\u00f3r b\u0119dzie odtwarzany do momentu wy\u0142\u0105czenia go", "app_bell_relaxation_looped": "zap\u0119tlony", diff --git a/module-apps/apps-common/ApplicationCommonPopupBlueprints.cpp b/module-apps/apps-common/ApplicationCommonPopupBlueprints.cpp index 69b4fbe9e0fbfb7e9a3f053d0ae242cd27110fdd..ecfe4d0c28e2ef06010df08dade36730924dc429 100644 --- a/module-apps/apps-common/ApplicationCommonPopupBlueprints.cpp +++ b/module-apps/apps-common/ApplicationCommonPopupBlueprints.cpp @@ -1,9 +1,10 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "AppWindow.hpp" #include "ApplicationCommon.hpp" #include "data/AlarmPopupRequestParams.hpp" +#include "data/AudioErrorParams.hpp" #include "service-db/Settings.hpp" #include "service-db/agents/settings/SystemSettings.hpp" #include "popups/data/PopupData.hpp" @@ -133,6 +134,19 @@ namespace app std::make_unique(popupParams)); return true; }); + + auto audioErrorBlueprint = [&](gui::popup::ID id, std::unique_ptr ¶ms) { + auto popupParams = dynamic_cast(params.get()); + if (popupParams == nullptr) { + return false; + } + switchWindowPopup(gui::popup::resolveWindowName(id), + popupParams->getDisposition(), + std::make_unique(popupParams), + SwitchReason::Popup); + return true; + }; + popupBlueprint.registerBlueprint(ID::AudioError, audioErrorBlueprint); } std::optional ApplicationCommon::popupBlueprintFallback(gui::popup::ID id) diff --git a/module-apps/apps-common/popups/Popups.cpp b/module-apps/apps-common/popups/Popups.cpp index 0de4fb2b5b1f7b1efed1671dbda465ee007fcd77..57650eef86ec78c1447a02e825e7c3facab40189 100644 --- a/module-apps/apps-common/popups/Popups.cpp +++ b/module-apps/apps-common/popups/Popups.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "Popups.hpp" @@ -56,6 +56,8 @@ namespace gui::popup return gui::popup::window::charging_notification_window; case ID::ChargingDoneNotification: return gui::popup::window::charging_done_notification_window; + case ID::AudioError: + return gui::popup::window::audio_error_window; case ID::AppTestPopup: return gui::popup::window::test_popup; case ID::Invalid: diff --git a/module-apps/apps-common/popups/Popups.hpp b/module-apps/apps-common/popups/Popups.hpp index 9451841fee89c3b05c1a96940f2c5d103f8eecae..f6bc83877481fd2dd7d5d9280e9ef1fd1e7fa56d 100644 --- a/module-apps/apps-common/popups/Popups.hpp +++ b/module-apps/apps-common/popups/Popups.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -34,6 +34,7 @@ namespace gui BedtimeNotification, ChargingNotification, ChargingDoneNotification, + AudioError, AppTestPopup, Invalid, }; @@ -65,6 +66,7 @@ namespace gui inline constexpr auto bedtime_notification_window = "BedtimeNotificationPopup"; inline constexpr auto charging_notification_window = "ChargingNotificationPopup"; inline constexpr auto charging_done_notification_window = "ChargingDoneNotificationPopup"; + inline constexpr auto audio_error_window = "AudioErrorPopup"; inline constexpr auto test_popup = "test_popup"; } // namespace window diff --git a/module-apps/apps-common/popups/data/AudioErrorParams.hpp b/module-apps/apps-common/popups/data/AudioErrorParams.hpp new file mode 100644 index 0000000000000000000000000000000000000000..adca33dd2aabd66b8683efe31ea254f2e2965582 --- /dev/null +++ b/module-apps/apps-common/popups/data/AudioErrorParams.hpp @@ -0,0 +1,36 @@ +// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "PopupRequestParams.hpp" + +namespace gui +{ + enum class AudioErrorType + { + UnsupportedMediaType, + FilesLimitExceeded, + FileDeleted, + Unknown + }; + + class AudioErrorParams : public PopupRequestParams + { + public: + explicit AudioErrorParams(AudioErrorType errorType) + : PopupRequestParams{popup::ID::AudioError}, errorType{errorType} + {} + + explicit AudioErrorParams(AudioErrorParams *p) : PopupRequestParams{p->getPopupId()}, errorType(p->errorType) + {} + + [[nodiscard]] AudioErrorType getErrorType() + { + return errorType; + } + + private: + AudioErrorType errorType; + }; +} // namespace gui diff --git a/products/BellHybrid/apps/Application.cpp b/products/BellHybrid/apps/Application.cpp index f6199685e2946e0fc4f4c189dcf4854e61561edc..ed34f2002f325e20cf4256fd8477f5c168d1bc65 100644 --- a/products/BellHybrid/apps/Application.cpp +++ b/products/BellHybrid/apps/Application.cpp @@ -13,6 +13,8 @@ #include #include #include +#include +#include #include #include #include @@ -79,6 +81,13 @@ namespace app return std::make_unique(app, std::move(presenter)); }); break; + case ID::AudioError: + windowsFactory.attach( + window::audio_error_window, [this](app::ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app); + return std::make_unique(app, name, std::move(presenter)); + }); + break; case ID::PowerOff: windowsFactory.attach(window::power_off_window, [](ApplicationCommon *app, const std::string &name) { return std::make_unique( diff --git a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp index 6b0309ed2c21cc5532caa97fd7c5d6414c4d6945..cc159d1be45081dc9a5b64560e5321663a833e40 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/ApplicationBellRelaxation.cpp @@ -9,7 +9,6 @@ #include "presenter/RelaxationVolumePresenter.hpp" #include "presenter/RelaxationPausedPresenter.hpp" #include "presenter/RelaxationEndedPresenter.hpp" -#include "presenter/RelaxationErrorPresenter.hpp" #include "windows/RelaxationMainWindow.hpp" #include "windows/RelaxationPausedWindow.hpp" #include "windows/RelaxationRunningProgressWindow.hpp" @@ -17,7 +16,6 @@ #include "windows/RelaxationTimerSelectWindow.hpp" #include "windows/RelaxationVolumeWindow.hpp" #include "windows/RelaxationEndedWindow.hpp" -#include "windows/RelaxationErrorWindow.hpp" #include "widgets/RelaxationPlayer.hpp" #include #include @@ -28,6 +26,9 @@ #include #include #include +#include +#include +#include #include #include @@ -147,10 +148,13 @@ namespace app return std::make_unique(app, name); }); - windowsFactory.attach(gui::window::name::relaxationError, [](ApplicationCommon *app, const std::string &name) { - auto presenter = std::make_unique(app); - return std::make_unique(app, std::move(presenter)); - }); + windowsFactory.attach(gui::window::name::audioErrorWindow, + [this](ApplicationCommon *app, const std::string &name) { + auto presenter = std::make_unique(app); + auto onExitCallback = [this]() { switchWindow(gui::name::window::main_window); }; + return std::make_unique( + app, name, std::move(presenter), std::move(onExitCallback)); + }); attachPopups({gui::popup::ID::AlarmActivated, gui::popup::ID::AlarmDeactivated, diff --git a/products/BellHybrid/apps/application-bell-relaxation/CMakeLists.txt b/products/BellHybrid/apps/application-bell-relaxation/CMakeLists.txt index 2d3ddfc1685775665918280dc37fde39b360439d..426bb832218ab7a046c79c2a63c5d6fdb2de2351 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-relaxation/CMakeLists.txt @@ -20,7 +20,6 @@ target_sources(application-bell-relaxation presenter/RelaxationVolumePresenter.cpp presenter/RelaxationPausedPresenter.cpp presenter/RelaxationEndedPresenter.cpp - presenter/RelaxationErrorPresenter.cpp widgets/RelaxationPlayer.cpp windows/RelaxationMainWindow.cpp windows/RelaxationPausedWindow.cpp @@ -29,13 +28,11 @@ target_sources(application-bell-relaxation windows/RelaxationTimerSelectWindow.cpp windows/RelaxationVolumeWindow.cpp windows/RelaxationEndedWindow.cpp - windows/RelaxationErrorWindow.cpp data/RelaxationCommon.hpp data/RelaxationStyle.hpp data/RelaxationAudioData.hpp data/RelaxationSwitchData.hpp - data/RelaxationErrorData.hpp widgets/RelaxationPlayer.hpp windows/RelaxationMainWindow.hpp presenter/RelaxationMainWindowPresenter.hpp @@ -45,7 +42,6 @@ target_sources(application-bell-relaxation presenter/RelaxationVolumePresenter.hpp presenter/RelaxationPausedPresenter.hpp presenter/RelaxationEndedPresenter.hpp - presenter/RelaxationErrorPresenter.cpp windows/RelaxationMainWindow.hpp windows/RelaxationPausedWindow.hpp windows/RelaxationRunningProgressWindow.hpp @@ -53,7 +49,6 @@ target_sources(application-bell-relaxation windows/RelaxationTimerSelectWindow.hpp windows/RelaxationVolumeWindow.hpp windows/RelaxationEndedWindow.hpp - windows/RelaxationErrorWindow.hpp PUBLIC include/application-bell-relaxation/ApplicationBellRelaxation.hpp diff --git a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationErrorData.hpp b/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationErrorData.hpp deleted file mode 100644 index ea08171f2beb4fabaa85526921103b7a1fdeed4d..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationErrorData.hpp +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once -#include - -namespace gui -{ - - enum class RelaxationErrorType - { - UnsupportedMediaType, - FilesLimitExceeded, - FileDeleted, - Unknown - }; - - class RelaxationErrorData : public SwitchData - { - RelaxationErrorType errorType; - - public: - explicit RelaxationErrorData(const RelaxationErrorType &relaxationErrorType) : errorType{relaxationErrorType} - {} - - [[nodiscard]] RelaxationErrorType getErrorType() - { - return errorType; - } - }; -} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp b/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp index 396e6b524ec70c3451889765e83915c678520727..f85f014df0f40cee34c090c4c3ff67902ca432a9 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/data/RelaxationStyle.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -70,10 +70,4 @@ namespace gui::relaxationStyle inline constexpr auto maxSizeY = 84U; } // namespace clock } // namespace relStyle - - namespace error - { - inline constexpr auto imageMarginTop = 122U; - inline constexpr auto textPaddingTop = 30U; - } // namespace error } // namespace gui::relaxationStyle diff --git a/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp b/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp index a4ab2a61642ab40b23a8fb84fd420c60fe922d1f..3d1cd9b3f8e9f3d72b9719e14c93188840fcf7ef 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp +++ b/products/BellHybrid/apps/application-bell-relaxation/include/application-bell-relaxation/ApplicationBellRelaxation.hpp @@ -17,7 +17,6 @@ namespace gui::window::name inline constexpr auto relaxationTimerSelect = "RelaxationTimerSelectWindow"; inline constexpr auto relaxationEnded = "RelaxationEndedWindow"; inline constexpr auto relaxationLowBattery = "RelaxationLowBatteryWindow"; - inline constexpr auto relaxationError = "RelaxationError"; } // namespace gui::window::name namespace app { diff --git a/products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.cpp b/products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.cpp deleted file mode 100644 index c2126ee6a4aae7cb870f643e58382966ffa1ead9..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.cpp +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "presenter/RelaxationErrorPresenter.hpp" -#include "ApplicationBellRelaxation.hpp" - -#include -#include -#include - -namespace app::relaxation -{ - RelaxationErrorPresenter::RelaxationErrorPresenter(app::ApplicationCommon *app) : app{app} - {} - - void RelaxationErrorPresenter::activate() - { - app::manager::Controller::sendAction( - app, - app::manager::actions::Launch, - std::make_unique(app::applicationBellRelaxationName)); - } -} // namespace app::relaxation diff --git a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.cpp b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.cpp deleted file mode 100644 index 6b4c53af700dfce78f550dc6b9a08a364f85520a..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.cpp +++ /dev/null @@ -1,93 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#include "RelaxationErrorWindow.hpp" -#include -#include - -#include - -namespace -{ - constexpr auto unsupportedMediaMessage = "app_bell_relaxation_error_message"; - constexpr auto exceededFilesLimitMessage = "app_bell_relaxation_limit_error_message"; - constexpr auto fileDeletedMessage = "app_bell_relaxation_file_deleted_message"; - constexpr auto emptyErrorMessage = ""; - -} // namespace - -namespace gui -{ - RelaxationErrorWindow::RelaxationErrorWindow( - app::ApplicationCommon *app, std::unique_ptr &&presenter) - : WindowWithTimer(app, gui::window::name::relaxationError, std::chrono::seconds{6}), presenter{ - std::move(presenter)} - { - buildInterface(); - } - - void RelaxationErrorWindow::buildInterface() - { - AppWindow::buildInterface(); - buildLayout(); - registerCallbacks(); - } - - void RelaxationErrorWindow::buildLayout() - { - statusBar->setVisible(false); - - icon = new Icon( - this, 0, 0, style::window_width, style::window_height, "big_information", "", ImageTypeSpecifier::W_G); - icon->image->setMargins({0, gui::relaxationStyle::error::imageMarginTop, 0, 0}); - icon->text->setFont(style::window::font::verybiglight); - const auto textPadding = icon->text->getPadding(); - icon->text->setPadding( - {textPadding.left, gui::relaxationStyle::error::textPaddingTop, textPadding.right, textPadding.bottom}); - icon->text->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); - icon->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); - icon->resizeItems(); - } - - void RelaxationErrorWindow::registerCallbacks() - { - timerCallback = [this](Item &, sys::Timer &timer) { - application->switchWindow(gui::name::window::main_window); - return true; - }; - } - - void RelaxationErrorWindow::onBeforeShow(ShowMode mode, SwitchData *data) - { - if (data && typeid(*data) == typeid(RelaxationErrorData)) { - auto *errorData = static_cast(data); - errorType = errorData->getErrorType(); - switch (errorType) { - case RelaxationErrorType::UnsupportedMediaType: { - icon->text->setRichText(utils::translate(unsupportedMediaMessage)); - break; - } - case RelaxationErrorType::FilesLimitExceeded: { - icon->text->setRichText(utils::translate(exceededFilesLimitMessage)); - break; - } - case RelaxationErrorType::FileDeleted: { - icon->text->setRichText(utils::translate(fileDeletedMessage)); - break; - } - default: - icon->text->setRichText(utils::translate(emptyErrorMessage)); - } - } - WindowWithTimer::onBeforeShow(mode, data); - } - - bool RelaxationErrorWindow::onInput(const InputEvent &inputEvent) - { - if (inputEvent.isShortRelease(KeyCode::KEY_ENTER) || inputEvent.isShortRelease(KeyCode::KEY_RF)) { - application->switchWindow(gui::name::window::main_window); - return true; - } - return true; - } -} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.hpp b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.hpp deleted file mode 100644 index 401e60d76529bdc123a9dac452234910adebd3a2..0000000000000000000000000000000000000000 --- a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationErrorWindow.hpp +++ /dev/null @@ -1,34 +0,0 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. -// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md - -#pragma once - -#include "presenter/RelaxationErrorPresenter.hpp" -#include -#include -#include -#include - -namespace gui -{ - class BellBaseLayout; - class RelaxationErrorWindow : public WindowWithTimer - { - public: - explicit RelaxationErrorWindow( - app::ApplicationCommon *app, - std::unique_ptr &&presenter); - - private: - std::unique_ptr presenter; - std::string errorText; - gui::Icon *icon = nullptr; - RelaxationErrorType errorType = RelaxationErrorType::Unknown; - - void buildInterface() override; - bool onInput(const gui::InputEvent &inputEvent) override; - void registerCallbacks(); - void buildLayout(); - void onBeforeShow(ShowMode mode, SwitchData *data) override; - }; -} // namespace gui diff --git a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp index 79e67c0db958a77f7a770dc59edaaaa683cc04d8..53aedee13aa17df97ab028479412c5b982f74039 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationMainWindow.cpp @@ -4,11 +4,12 @@ #include "RelaxationMainWindow.hpp" #include "data/RelaxationAudioData.hpp" -#include "data/RelaxationErrorData.hpp" #include #include #include +#include +#include #include namespace gui @@ -60,8 +61,8 @@ namespace gui void RelaxationMainWindow::handleError() { - auto switchData = std::make_unique(RelaxationErrorType::FilesLimitExceeded); - application->switchWindow(gui::window::name::relaxationError, std::move(switchData)); + auto switchData = std::make_unique(AudioErrorType::FilesLimitExceeded); + application->switchWindow(gui::window::name::audioErrorWindow, std::move(switchData)); } void RelaxationMainWindow::updateViewState() diff --git a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningLoopWindow.cpp b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningLoopWindow.cpp index 6c813845545e1b470bd1906a799d6d9c59c55168..b45f361db5e839f647a5a9b0d66e0b1597945732 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningLoopWindow.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningLoopWindow.cpp @@ -4,7 +4,8 @@ #include "RelaxationRunningLoopWindow.hpp" #include #include -#include +#include +#include #include #include @@ -232,13 +233,13 @@ namespace gui void RelaxationRunningLoopWindow::handleError() { - auto switchData = std::make_unique(RelaxationErrorType::UnsupportedMediaType); - application->switchWindow(gui::window::name::relaxationError, std::move(switchData)); + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + application->switchWindow(gui::window::name::audioErrorWindow, std::move(switchData)); } void RelaxationRunningLoopWindow::handleDeletedFile() { - auto switchData = std::make_unique(RelaxationErrorType::FileDeleted); - application->switchWindow(gui::window::name::relaxationError, std::move(switchData)); + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + application->switchWindow(gui::window::name::audioErrorWindow, std::move(switchData)); } } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp index ae750cdc8ba65862fe80d8e87ec1b0b1efa45ea9..b688b0aacaded3a7c62b65f930ed37814473ba30 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp +++ b/products/BellHybrid/apps/application-bell-relaxation/windows/RelaxationRunningProgressWindow.cpp @@ -4,8 +4,8 @@ #include "RelaxationRunningProgressWindow.hpp" #include #include -#include - +#include +#include #include #include #include @@ -177,13 +177,13 @@ namespace gui void RelaxationRunningProgressWindow::handleError() { - auto switchData = std::make_unique(RelaxationErrorType::UnsupportedMediaType); - application->switchWindow(gui::window::name::relaxationError, std::move(switchData)); + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + application->switchWindow(gui::window::name::audioErrorWindow, std::move(switchData)); } void RelaxationRunningProgressWindow::handleDeletedFile() { - auto switchData = std::make_unique(RelaxationErrorType::FileDeleted); - application->switchWindow(gui::window::name::relaxationError, std::move(switchData)); + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + application->switchWindow(gui::window::name::audioErrorWindow, std::move(switchData)); } } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp index 9f89dd5c7f919f46fd9e321f4d8b49ec40203f55..da65ea109f2c7ef6bf45ec7ed9681e7c6b540897 100644 --- a/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp +++ b/products/BellHybrid/apps/application-bell-settings/ApplicationBellSettings.cpp @@ -6,6 +6,7 @@ #include "presenter/LayoutWindowPresenter.hpp" #include "models/TemperatureUnitModel.hpp" #include "models/AboutYourBellModel.hpp" +#include "models/AudioErrorModel.hpp" #include "models/alarm_settings/AlarmSettingsListItemProvider.hpp" #include "models/alarm_settings/PrewakeUpListItemProvider.hpp" #include "models/alarm_settings/BedtimeSettingsListItemProvider.hpp" @@ -132,10 +133,11 @@ namespace app auto soundsRepository = std::make_unique(this, pathSorting); auto songsModel = std::make_unique(this, std::move(soundsRepository)); - auto provider = std::make_shared(bedtimeModel, + auto provider = std::make_unique(bedtimeModel, std::move(songsModel)); - auto presenter = - std::make_unique(provider, bedtimeModel, *audioModel); + auto audioErrorModel = std::make_unique(); + auto presenter = std::make_unique( + std::move(provider), bedtimeModel, *audioModel, std::move(audioErrorModel)); return std::make_unique(app, std::move(presenter)); }); @@ -188,8 +190,13 @@ namespace app std::move(songsModel)); auto frontlightModel = std::make_unique(app); - auto presenter = std::make_unique( - std::move(provider), std::move(prewakeUpSettingsModel), *audioModel, std::move(frontlightModel)); + auto audioErrorModel = std::make_unique(); + auto presenter = + std::make_unique(std::move(provider), + std::move(prewakeUpSettingsModel), + *audioModel, + std::move(frontlightModel), + std::move(audioErrorModel)); return std::make_unique(app, std::move(presenter)); }); @@ -220,9 +227,10 @@ namespace app auto songsModel = std::make_unique(this, std::move(soundsRepository)); auto provider = std::make_unique(*snoozeSettingsModel, std::move(songsModel)); + auto audioErrorModel = std::make_unique(); auto presenter = std::make_unique( - std::move(provider), std::move(snoozeSettingsModel), *audioModel); + std::move(provider), std::move(snoozeSettingsModel), *audioModel, std::move(audioErrorModel)); return std::make_unique(app, std::move(presenter)); }); windowsFactory.attach( @@ -254,8 +262,12 @@ namespace app auto frontlightModel = std::make_unique(app); auto provider = std::make_unique(*alarmSettingsModel, std::move(songsModel)); - auto presenter = std::make_unique( - std::move(provider), std::move(alarmSettingsModel), *audioModel, std::move(frontlightModel)); + auto audioErrorModel = std::make_unique(); + auto presenter = std::make_unique(std::move(provider), + std::move(alarmSettingsModel), + *audioModel, + std::move(frontlightModel), + std::move(audioErrorModel)); return std::make_unique(app, std::move(presenter)); }); @@ -279,7 +291,8 @@ namespace app gui::popup::ID::Reboot, gui::popup::ID::BedtimeNotification, gui::popup::ID::ChargingNotification, - gui::popup::ID::ChargingDoneNotification}); + gui::popup::ID::ChargingDoneNotification, + gui::popup::ID::AudioError}); } sys::MessagePointer ApplicationBellSettings::DataReceivedHandler(sys::DataMessage *msgl, sys::ResponseMessage *resp) diff --git a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt index 4e75b8d95c08d0e747d7b386e8c836db23764c01..ffb5f1f9d02aac8793ca16c23b74e53da6c8e339 100644 --- a/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt +++ b/products/BellHybrid/apps/application-bell-settings/CMakeLists.txt @@ -27,6 +27,7 @@ target_sources(application-bell-settings models/AboutYourBellModel.cpp models/FrontlightListItemProvider.cpp models/FrontlightModel.cpp + models/AudioErrorModel.cpp models/alarm_settings/AlarmSettingsListItemProvider.cpp models/alarm_settings/AlarmSettingsModel.cpp models/alarm_settings/BedtimeSettingsListItemProvider.cpp @@ -119,6 +120,7 @@ target_sources(application-bell-settings PUBLIC include/application-bell-settings/models/DateTimeUnitsModel.hpp + include/application-bell-settings/models/AudioErrorModel.hpp include/application-bell-settings/presenter/TimeUnitsPresenter.hpp include/application-bell-settings/windows/BellSettingsTimeUnitsWindow.hpp include/application-bell-settings/ApplicationBellSettings.hpp diff --git a/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/models/AudioErrorModel.hpp b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/models/AudioErrorModel.hpp new file mode 100644 index 0000000000000000000000000000000000000000..a783b37ea998bd1248a881f039a456fe3338ef0c --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/include/application-bell-settings/models/AudioErrorModel.hpp @@ -0,0 +1,28 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include +#include +#include + +namespace app::bell_settings +{ + class AudioErrorModel + { + public: + struct ErrorPaths + { + UTF8 path; + gui::AudioErrorType type; + }; + + bool isPathOnErrorList(const UTF8 &path) const; + void addPathToErrorList(const UTF8 &path, gui::AudioErrorType errorType); + std::optional getErrorType(const UTF8 &path) const; + + private: + std::vector errorPaths; + }; +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/models/AudioErrorModel.cpp b/products/BellHybrid/apps/application-bell-settings/models/AudioErrorModel.cpp new file mode 100644 index 0000000000000000000000000000000000000000..014b6462eb477fdd5d578d25f679f63361024180 --- /dev/null +++ b/products/BellHybrid/apps/application-bell-settings/models/AudioErrorModel.cpp @@ -0,0 +1,29 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "models/AudioErrorModel.hpp" + +namespace app::bell_settings +{ + bool AudioErrorModel::isPathOnErrorList(const UTF8 &path) const + { + const auto res = + std::find_if(errorPaths.begin(), errorPaths.end(), [&path](auto err) { return err.path == path; }); + return res != errorPaths.end(); + } + + void AudioErrorModel::addPathToErrorList(const UTF8 &path, gui::AudioErrorType errorType) + { + errorPaths.emplace_back(ErrorPaths{path, errorType}); + } + + std::optional AudioErrorModel::getErrorType(const UTF8 &path) const + { + const auto res = + std::find_if(errorPaths.begin(), errorPaths.end(), [&path](auto err) { return err.path == path; }); + if (res != errorPaths.end()) { + return (*res).type; + } + return std::nullopt; + } +} // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp index a22a6e98b49d8468f0b079a729682dda95d8e33e..7bdf9affe15923dc1daf75f8f45043e5a70c99b2 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/AlarmSettingsListItemProvider.cpp @@ -51,6 +51,12 @@ namespace app::bell_settings onToneExit(currentSoundPath); } }; + alarmTone->onProceed = [this]() { + if (onToneProceed) { + return onToneProceed(currentSoundPath); + } + return false; + }; internalData.emplace_back(alarmTone); constexpr auto volumeStep = 1U; diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp index 10fc598a000012d66c8a8818cb4a6ac002bc48b2..4d0fe9f50ce7b0fc3bd14ae86ad130cf3a5a4c1d 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/BedtimeSettingsListItemProvider.cpp @@ -42,6 +42,12 @@ namespace app::bell_settings onToneExit(currentSoundPath); } }; + chimeTone->onProceed = [this]() { + if (onToneProceed) { + return onToneProceed(currentSoundPath); + } + return false; + }; internalData.emplace_back(chimeTone); constexpr auto volumeStep = 1U; diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp index e3342b243e9d2c1f8c508d8f1b53ba3c76996cc8..2b407eed67c6a334a163899df69b909f06e30e45 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/PrewakeUpListItemProvider.cpp @@ -70,6 +70,12 @@ namespace app::bell_settings onToneExit(currentSoundPath); } }; + chimeTone->onProceed = [this]() { + if (onToneProceed) { + return onToneProceed(currentSoundPath); + } + return false; + }; internalData.emplace_back(chimeTone); constexpr auto volumeStep = 1U; diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SettingsListItemProvider.hpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SettingsListItemProvider.hpp index dd4daf98ba45ea8f2a515352bd2c9799395c5cab..a5530c5c3fb37a453232ccc7d2b6541723dd4b1c 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SettingsListItemProvider.hpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SettingsListItemProvider.hpp @@ -15,6 +15,7 @@ namespace app::bell_settings public: /// Val contains currently chosen tone using ToneCallback = std::function; + using ToneProceedCallback = std::function; /// Val contains currently chosen volume (1-10 range) using VolumeCallback = std::function; using VolumeEnterCallback = ToneCallback; @@ -39,6 +40,7 @@ namespace app::bell_settings ToneCallback onToneEnter; ToneCallback onToneExit; ToneCallback onToneChange; + ToneProceedCallback onToneProceed; VolumeEnterCallback onVolumeEnter; VolumeCallback onVolumeExit; diff --git a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp index db06625b42a95b1b84930564d780d1ed92cf7782..6e981b36670759c6002baf16fb1485d01e02ec52 100644 --- a/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp +++ b/products/BellHybrid/apps/application-bell-settings/models/alarm_settings/SnoozeListItemProvider.cpp @@ -149,6 +149,12 @@ namespace app::bell_settings onToneExit(currentSoundPath); } }; + snoozeChimeTone->onProceed = [this]() { + if (onToneProceed) { + return onToneProceed(currentSoundPath); + } + return false; + }; internalData.emplace_back(snoozeChimeTone); constexpr auto volumeStep = 1U; diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.cpp index 398514b47fee12d0af369e5b8543068183426138..73296ba3791087b3c5750cb80f2551013144a34f 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.cpp @@ -5,21 +5,38 @@ namespace app::bell_settings { - SettingsPresenter::SettingsPresenter(std::shared_ptr provider, + SettingsPresenter::SettingsPresenter(std::unique_ptr &&provider, std::shared_ptr model, - AbstractAudioModel &audioModel) - : provider(std::move(provider)), model(std::move(model)), audioModel{audioModel} + AbstractAudioModel &audioModel, + std::unique_ptr &&audioErrorModel) + : provider{std::move(provider)}, model{std::move(model)}, audioModel{audioModel}, audioErrorModel{std::move( + audioErrorModel)} { auto playSound = [this](const UTF8 &val) { + auto onStartCallback = [this, val](audio::RetCode retCode) { + if (retCode != audio::RetCode::Success) { + handleAudioError(val, gui::AudioErrorType::UnsupportedMediaType); + } + }; + + auto onFinishedCallback = [this, val](AbstractAudioModel::PlaybackFinishStatus status) { + if (status == AbstractAudioModel::PlaybackFinishStatus::Error) { + handleAudioError(val, gui::AudioErrorType::FileDeleted); + } + }; + currentSoundPath = val; this->audioModel.setVolume(this->provider->getCurrentVolume(), AbstractAudioModel::PlaybackType::Bedtime); - this->audioModel.play(currentSoundPath, AbstractAudioModel::PlaybackType::Bedtime, {}); + this->audioModel.setPlaybackFinishedCb(std::move(onFinishedCallback)); + this->audioModel.play( + currentSoundPath, AbstractAudioModel::PlaybackType::Bedtime, std::move(onStartCallback)); }; this->provider->onExit = [this]() { getView()->exit(); }; this->provider->onToneEnter = playSound; this->provider->onToneChange = playSound; + this->provider->onToneProceed = [this](const auto &path) { return validatePath(path); }; this->provider->onVolumeEnter = playSound; this->provider->onVolumeExit = [this](const auto &) { this->stopSound(); }; @@ -56,13 +73,45 @@ namespace app::bell_settings provider->clearData(); } - void SettingsPresenter::stopSound() + auto SettingsPresenter::stopSound() -> void { this->audioModel.stopPlayedByThis({}); } - void SettingsPresenter::exitWithoutSave() + + auto SettingsPresenter::exitWithoutSave() -> void { this->stopSound(); model->getBedtimeVolume().restoreDefault(); } + + auto SettingsPresenter::handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void + { + const bool validPath = !audioErrorModel->isPathOnErrorList(path); + if (validPath) { + audioErrorModel->addPathToErrorList(path, errorType); + showAudioError(errorType); + } + } + + auto SettingsPresenter::validatePath(const UTF8 &path) const -> bool + { + const auto errorType = audioErrorModel->getErrorType(path); + if (errorType.has_value()) { + showAudioError(errorType.value()); + return true; + } + return false; + } + + auto SettingsPresenter::showAudioError(gui::AudioErrorType errorType) const -> void + { + switch (errorType) { + case gui::AudioErrorType::FileDeleted: + getView()->handleDeletedFile(); + break; + default: + getView()->handleError(); + break; + } + } } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.hpp index d0441532b36f5606e498fe2b7589197c37d9eb16..8aafa510efec672cc64e2c71f34aa08e1a49afa9 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/BedtimeSettingsPresenter.hpp @@ -3,6 +3,7 @@ #pragma once +#include "models/AudioErrorModel.hpp" #include "models/alarm_settings/BedtimeSettingsListItemProvider.hpp" #include #include @@ -23,8 +24,10 @@ namespace app::bell_settings class View { public: - virtual ~View() noexcept = default; - virtual void exit() = 0; + virtual ~View() noexcept = default; + virtual auto exit() -> void = 0; + virtual auto handleError() -> void = 0; + virtual auto handleDeletedFile() -> void = 0; }; class Presenter : public BasePresenter @@ -35,29 +38,34 @@ namespace app::bell_settings virtual auto saveData() -> void = 0; virtual auto loadData() -> void = 0; virtual auto eraseProviderData() -> void = 0; - virtual void exitWithoutSave() = 0; + virtual auto exitWithoutSave() -> void = 0; }; }; class SettingsPresenter : public BedtimeSettingsWindowContract::Presenter { public: - SettingsPresenter(std::shared_ptr provider, + SettingsPresenter(std::unique_ptr &&provider, std::shared_ptr model, - AbstractAudioModel &audioModel); + AbstractAudioModel &audioModel, + std::unique_ptr &&audioErrorModel); auto getPagesProvider() const -> std::shared_ptr override; auto saveData() -> void override; auto loadData() -> void override; auto eraseProviderData() -> void override; - void exitWithoutSave() override; + auto exitWithoutSave() -> void override; private: - void stopSound(); + auto stopSound() -> void; + auto handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void; + auto showAudioError(gui::AudioErrorType errorType) const -> void; + auto validatePath(const UTF8 &path) const -> bool; std::shared_ptr provider; std::shared_ptr model; AbstractAudioModel &audioModel; + std::unique_ptr audioErrorModel; UTF8 currentSoundPath; }; } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.cpp index 6ecc4c949446da7b1165ea4aa05e626c9efa8626..45eafe4f4935b2d7c2ffe70cbbb3c3a9b5b28567 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.cpp @@ -9,15 +9,30 @@ namespace app::bell_settings AlarmSettingsPresenter::AlarmSettingsPresenter(std::unique_ptr &&provider, std::unique_ptr &&settingsModel, AbstractAudioModel &audioModel, - std::unique_ptr &&frontlight) + std::unique_ptr &&frontlight, + std::unique_ptr &&audioErrorModel) : provider{std::move(provider)}, settingsModel{std::move(settingsModel)}, audioModel{audioModel}, - frontlight{std::move(frontlight)} + frontlight{std::move(frontlight)}, audioErrorModel{std::move(audioErrorModel)} { auto playSound = [this](const UTF8 &val) { + auto onStartCallback = [this, val](audio::RetCode retCode) { + if (retCode != audio::RetCode::Success) { + handleAudioError(val, gui::AudioErrorType::UnsupportedMediaType); + } + }; + + auto onFinishedCallback = [this, val](AbstractAudioModel::PlaybackFinishStatus status) { + if (status == AbstractAudioModel::PlaybackFinishStatus::Error) { + handleAudioError(val, gui::AudioErrorType::FileDeleted); + } + }; + currentSoundPath = val; this->audioModel.setVolume(this->provider->getCurrentVolume(), AbstractAudioModel::PlaybackType::Alarm); - this->audioModel.play(currentSoundPath, AbstractAudioModel::PlaybackType::Alarm, {}); + this->audioModel.setPlaybackFinishedCb(std::move(onFinishedCallback)); + this->audioModel.play( + currentSoundPath, AbstractAudioModel::PlaybackType::Alarm, std::move(onStartCallback)); }; this->provider->onExit = [this]() { getView()->exit(); }; @@ -25,6 +40,7 @@ namespace app::bell_settings this->provider->onToneEnter = playSound; this->provider->onToneExit = [this](const auto &) { stopSound(); }; this->provider->onToneChange = playSound; + this->provider->onToneProceed = [this](const auto &path) { return validatePath(path); }; this->provider->onVolumeEnter = playSound; this->provider->onVolumeExit = [this](const auto &) { stopSound(); }; @@ -90,4 +106,35 @@ namespace app::bell_settings settingsModel->getAlarmVolume().restoreDefault(); eraseProviderData(); } + + auto AlarmSettingsPresenter::handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void + { + const bool validPath = !audioErrorModel->isPathOnErrorList(path); + if (validPath) { + audioErrorModel->addPathToErrorList(path, errorType); + showAudioError(errorType); + } + } + + auto AlarmSettingsPresenter::validatePath(const UTF8 &path) const -> bool + { + const auto errorType = audioErrorModel->getErrorType(path); + if (errorType.has_value()) { + showAudioError(errorType.value()); + return true; + } + return false; + } + + auto AlarmSettingsPresenter::showAudioError(gui::AudioErrorType errorType) const -> void + { + switch (errorType) { + case gui::AudioErrorType::FileDeleted: + getView()->handleDeletedFile(); + break; + default: + getView()->handleError(); + break; + } + } } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.hpp index 4f07cb00e4681ebedcdfc76a1d027d475dac257a..8a9d0a2f416fc07bfa999a8119e331506fc46436 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/AlarmSettingsPresenter.hpp @@ -3,6 +3,7 @@ #pragma once +#include "models/AudioErrorModel.hpp" #include #include #include @@ -28,6 +29,8 @@ namespace app::bell_settings public: virtual ~View() noexcept = default; virtual void exit() = 0; + virtual void handleError() = 0; + virtual void handleDeletedFile() = 0; }; class Presenter : public BasePresenter @@ -49,7 +52,8 @@ namespace app::bell_settings AlarmSettingsPresenter(std::unique_ptr &&provider, std::unique_ptr &&settingsModel, AbstractAudioModel &audioModel, - std::unique_ptr &&frontlight); + std::unique_ptr &&frontlight, + std::unique_ptr &&audioErrorModel); auto getPagesProvider() const -> std::shared_ptr override; auto loadData() -> void override; @@ -60,11 +64,15 @@ namespace app::bell_settings private: auto stopSound() -> void; + auto handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void; + auto showAudioError(gui::AudioErrorType errorType) const -> void; + auto validatePath(const UTF8 &path) const -> bool; std::shared_ptr provider; std::unique_ptr settingsModel; AbstractAudioModel &audioModel; std::unique_ptr frontlight; + std::unique_ptr audioErrorModel; UTF8 currentSoundPath; }; } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp index ed655f03d62acaf286916e2217442661164c36d6..66610928cb00d24249d39f1384e883c501c96fb1 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.cpp @@ -9,14 +9,29 @@ namespace app::bell_settings PrewakeUpWindowPresenter::PrewakeUpWindowPresenter(std::unique_ptr &&provider, std::unique_ptr &&model, AbstractAudioModel &audioModel, - std::unique_ptr &&frontlight) - : provider{std::move(provider)}, model{std::move(model)}, audioModel{audioModel}, frontlight{ - std::move(frontlight)} + std::unique_ptr &&frontlight, + std::unique_ptr &&audioErrorModel) + : provider{std::move(provider)}, model{std::move(model)}, audioModel{audioModel}, + frontlight{std::move(frontlight)}, audioErrorModel{std::move(audioErrorModel)} { auto playSound = [this](const UTF8 &val) { + auto onStartCallback = [this, val](audio::RetCode retCode) { + if (retCode != audio::RetCode::Success) { + handleAudioError(val, gui::AudioErrorType::UnsupportedMediaType); + } + }; + + auto onFinishedCallback = [this, val](AbstractAudioModel::PlaybackFinishStatus status) { + if (status == AbstractAudioModel::PlaybackFinishStatus::Error) { + handleAudioError(val, gui::AudioErrorType::FileDeleted); + } + }; + currentSoundPath = val; this->audioModel.setVolume(this->provider->getCurrentVolume(), AbstractAudioModel::PlaybackType::PreWakeup); - this->audioModel.play(currentSoundPath, AbstractAudioModel::PlaybackType::PreWakeup, {}); + this->audioModel.setPlaybackFinishedCb(std::move(onFinishedCallback)); + this->audioModel.play( + currentSoundPath, AbstractAudioModel::PlaybackType::PreWakeup, std::move(onStartCallback)); }; this->provider->onExit = [this]() { getView()->exit(); }; @@ -24,6 +39,7 @@ namespace app::bell_settings this->provider->onToneEnter = playSound; this->provider->onToneExit = [this](const auto &) { stopSound(); }; this->provider->onToneChange = playSound; + this->provider->onToneProceed = [this](const auto &path) { return validatePath(path); }; this->provider->onVolumeEnter = playSound; this->provider->onVolumeExit = [this](const auto &) { stopSound(); }; @@ -72,13 +88,44 @@ namespace app::bell_settings provider->clearData(); } - void PrewakeUpWindowPresenter::stopSound() + auto PrewakeUpWindowPresenter::stopSound() -> void { this->audioModel.stopPlayedByThis({}); } - void PrewakeUpWindowPresenter::exitWithoutSave() + auto PrewakeUpWindowPresenter::exitWithoutSave() -> void { model->getChimeVolume().restoreDefault(); } + + auto PrewakeUpWindowPresenter::handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void + { + const bool validPath = !audioErrorModel->isPathOnErrorList(path); + if (validPath) { + audioErrorModel->addPathToErrorList(path, errorType); + showAudioError(errorType); + } + } + + auto PrewakeUpWindowPresenter::validatePath(const UTF8 &path) const -> bool + { + const auto errorType = audioErrorModel->getErrorType(path); + if (errorType.has_value()) { + showAudioError(errorType.value()); + return true; + } + return false; + } + + auto PrewakeUpWindowPresenter::showAudioError(gui::AudioErrorType errorType) const -> void + { + switch (errorType) { + case gui::AudioErrorType::FileDeleted: + getView()->handleDeletedFile(); + break; + default: + getView()->handleError(); + break; + } + } } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.hpp index cad39b755c4851ddb54b007e91a8f7a5dcde91d2..a056cb42b1aa43dd89ae19ca6e476f0e566d6cae 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/PrewakeUpPresenter.hpp @@ -3,6 +3,7 @@ #pragma once +#include "models/AudioErrorModel.hpp" #include #include #include @@ -25,8 +26,10 @@ namespace app::bell_settings class View { public: - virtual ~View() noexcept = default; - virtual void exit() = 0; + virtual ~View() noexcept = default; + virtual auto exit() -> void = 0; + virtual auto handleError() -> void = 0; + virtual auto handleDeletedFile() -> void = 0; }; class Presenter : public BasePresenter @@ -37,7 +40,7 @@ namespace app::bell_settings virtual auto saveData() -> void = 0; virtual auto loadData() -> void = 0; virtual auto eraseProviderData() -> void = 0; - virtual void exitWithoutSave() = 0; + virtual auto exitWithoutSave() -> void = 0; }; }; @@ -47,21 +50,26 @@ namespace app::bell_settings PrewakeUpWindowPresenter(std::unique_ptr &&provider, std::unique_ptr &&model, AbstractAudioModel &audioModel, - std::unique_ptr &&frontlight); + std::unique_ptr &&frontlight, + std::unique_ptr &&audioErrorModel); auto getPagesProvider() const -> std::shared_ptr override; auto saveData() -> void override; auto loadData() -> void override; auto eraseProviderData() -> void override; - void exitWithoutSave() override; + auto exitWithoutSave() -> void override; private: - void stopSound(); + auto stopSound() -> void; + auto handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void; + auto showAudioError(gui::AudioErrorType errorType) const -> void; + auto validatePath(const UTF8 &path) const -> bool; std::shared_ptr provider; std::unique_ptr model; AbstractAudioModel &audioModel; std::unique_ptr frontlight; + std::unique_ptr audioErrorModel; UTF8 currentSoundPath; }; } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.cpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.cpp index e6378b327fc536cc84b66be1bbe407853776cf32..0327052fe8300eca795641cc997ada6c83fab804 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.cpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.cpp @@ -8,13 +8,29 @@ namespace app::bell_settings { SnoozePresenter::SnoozePresenter(std::unique_ptr &&provider, std::unique_ptr &&snoozeSettingsModel, - AbstractAudioModel &audioModel) - : provider{std::move(provider)}, snoozeSettingsModel{std::move(snoozeSettingsModel)}, audioModel{audioModel} + AbstractAudioModel &audioModel, + std::unique_ptr &&audioErrorModel) + : provider{std::move(provider)}, snoozeSettingsModel{std::move(snoozeSettingsModel)}, audioModel{audioModel}, + audioErrorModel{std::move(audioErrorModel)} { auto playSound = [this](const UTF8 &val) { + auto onStartCallback = [this, val](audio::RetCode retCode) { + if (retCode != audio::RetCode::Success) { + handleAudioError(val, gui::AudioErrorType::UnsupportedMediaType); + } + }; + + auto onFinishedCallback = [this, val](AbstractAudioModel::PlaybackFinishStatus status) { + if (status == AbstractAudioModel::PlaybackFinishStatus::Error) { + handleAudioError(val, gui::AudioErrorType::FileDeleted); + } + }; + currentSoundPath = val; this->audioModel.setVolume(this->provider->getCurrentVolume(), AbstractAudioModel::PlaybackType::Snooze); - this->audioModel.play(currentSoundPath, AbstractAudioModel::PlaybackType::Snooze, {}); + this->audioModel.setPlaybackFinishedCb(std::move(onFinishedCallback)); + this->audioModel.play( + currentSoundPath, AbstractAudioModel::PlaybackType::Snooze, std::move(onStartCallback)); }; this->provider->onExit = [this]() { getView()->exit(); }; @@ -22,6 +38,7 @@ namespace app::bell_settings this->provider->onToneEnter = playSound; this->provider->onToneExit = [this](const auto &) { stopSound(); }; this->provider->onToneChange = playSound; + this->provider->onToneProceed = [this](const auto &path) { return validatePath(path); }; this->provider->onVolumeEnter = playSound; this->provider->onVolumeExit = [this](const auto &) { stopSound(); }; @@ -34,7 +51,7 @@ namespace app::bell_settings }; } - void SnoozePresenter::saveData() + auto SnoozePresenter::saveData() -> void { stopSound(); for (const auto &item : provider->getListItems()) { @@ -42,7 +59,7 @@ namespace app::bell_settings } } - void SnoozePresenter::loadData() + auto SnoozePresenter::loadData() -> void { for (const auto &item : provider->getListItems()) { item->setValue(); @@ -54,18 +71,49 @@ namespace app::bell_settings return provider; } - void SnoozePresenter::stopSound() + auto SnoozePresenter::stopSound() -> void { audioModel.stopPlayedByThis({}); } - void SnoozePresenter::eraseProviderData() + auto SnoozePresenter::eraseProviderData() -> void { provider->clearData(); } - void SnoozePresenter::exitWithoutSave() + auto SnoozePresenter::exitWithoutSave() -> void { snoozeSettingsModel->getSnoozeChimeVolume().restoreDefault(); } + + auto SnoozePresenter::handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void + { + const bool validPath = !audioErrorModel->isPathOnErrorList(path); + if (validPath) { + audioErrorModel->addPathToErrorList(path, errorType); + showAudioError(errorType); + } + } + + auto SnoozePresenter::validatePath(const UTF8 &path) const -> bool + { + const auto errorType = audioErrorModel->getErrorType(path); + if (errorType.has_value()) { + showAudioError(errorType.value()); + return true; + } + return false; + } + + auto SnoozePresenter::showAudioError(gui::AudioErrorType errorType) const -> void + { + switch (errorType) { + case gui::AudioErrorType::FileDeleted: + getView()->handleDeletedFile(); + break; + default: + getView()->handleError(); + break; + } + } } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp index aac4142f56d22654649af524304e38e684c43463..dd5c4441e889040c4c0cf884cdc91f5d8cc1f295 100644 --- a/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp +++ b/products/BellHybrid/apps/application-bell-settings/presenter/alarm_settings/SnoozePresenter.hpp @@ -3,6 +3,7 @@ #pragma once +#include "models/AudioErrorModel.hpp" #include #include #include @@ -21,8 +22,10 @@ namespace app::bell_settings class View { public: - virtual ~View() noexcept = default; - virtual void exit() = 0; + virtual ~View() noexcept = default; + virtual auto exit() -> void = 0; + virtual auto handleError() -> void = 0; + virtual auto handleDeletedFile() -> void = 0; }; class AbstractSnoozePresenter : public BasePresenter @@ -30,10 +33,10 @@ namespace app::bell_settings public: virtual ~AbstractSnoozePresenter() = default; virtual auto getPagesProvider() const -> std::shared_ptr = 0; - virtual void saveData() = 0; - virtual void loadData() = 0; - virtual void eraseProviderData() = 0; - virtual void exitWithoutSave() = 0; + virtual auto saveData() -> void = 0; + virtual auto loadData() -> void = 0; + virtual auto eraseProviderData() -> void = 0; + virtual auto exitWithoutSave() -> void = 0; }; class SnoozePresenter : public AbstractSnoozePresenter @@ -41,19 +44,24 @@ namespace app::bell_settings public: SnoozePresenter(std::unique_ptr &&provider, std::unique_ptr &&snoozeSettingsModel, - AbstractAudioModel &audioModel); + AbstractAudioModel &audioModel, + std::unique_ptr &&audioErrorModel); auto getPagesProvider() const -> std::shared_ptr override; - void saveData() override; - void loadData() override; - void eraseProviderData() override; - void exitWithoutSave() override; + auto saveData() -> void override; + auto loadData() -> void override; + auto eraseProviderData() -> void override; + auto exitWithoutSave() -> void override; private: - void stopSound(); + auto stopSound() -> void; + auto handleAudioError(const UTF8 &path, gui::AudioErrorType errorType) -> void; + auto showAudioError(gui::AudioErrorType errorType) const -> void; + auto validatePath(const UTF8 &path) const -> bool; std::shared_ptr provider; std::unique_ptr snoozeSettingsModel; AbstractAudioModel &audioModel; + std::unique_ptr audioErrorModel; UTF8 currentSoundPath; }; } // namespace app::bell_settings diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.cpp index 02f29419ae87f5a9a59291158d5d702d397654ca..95585ecdbcc5a8b4a67602e37f3ccdb326c7e5e4 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.cpp @@ -1,12 +1,15 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "BellSettingsBedtimeToneWindow.hpp" #include "application-bell-settings/ApplicationBellSettings.hpp" #include "BellSettingsStyle.hpp" + #include #include #include +#include +#include namespace gui { @@ -75,4 +78,16 @@ namespace gui presenter->eraseProviderData(); } } + + void BellSettingsBedtimeToneWindow::handleError() + { + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } + + void BellSettingsBedtimeToneWindow::handleDeletedFile() + { + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } } /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.hpp index 35212d8c35be06de99ad594d2dbf094c350da131..323a096c387a723a6e622285de0de53395416489 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/BellSettingsBedtimeToneWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -25,6 +25,8 @@ namespace gui bool onInput(const InputEvent &inputEvent) override; void rebuild() override; void exit() override; + void handleError() override; + void handleDeletedFile() override; private: SideListView *sidelistview{}; diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp index caeff6f9be28b765470407ef10cb1cd01fbef8b7..a2dcf893ec3748d8841972b0cf57b5553d2d4217 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.cpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "BellSettingsAlarmSettingsSnoozeWindow.hpp" @@ -9,6 +9,8 @@ #include #include +#include +#include #include #include @@ -74,10 +76,23 @@ namespace gui window::bell_finished::defaultName, BellFinishedWindowData::Factory::create("circle_success_big", BellSettingsAlarmSettingsMenuWindow::name)); } + void BellSettingsAlarmSettingsSnoozeWindow::onClose(Window::CloseReason reason) { if (reason != CloseReason::Popup) { presenter->eraseProviderData(); } } + + void BellSettingsAlarmSettingsSnoozeWindow::handleError() + { + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } + + void BellSettingsAlarmSettingsSnoozeWindow::handleDeletedFile() + { + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } } // namespace gui diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp index e1f517ce34cd8e240020f1b46376b0a8dd7ad75e..3b92a0399bec03cd01800a3bc53506e0d4ef08d2 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsSnoozeWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -25,6 +25,8 @@ namespace gui void onClose(CloseReason reason) override; void rebuild() override; void exit() override; + void handleError() override; + void handleDeletedFile() override; private: SideListView *listView{}; diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp index df08bcfb46ca51666a7f15653d5c8064c13873ad..bb126fd1eb05a8543c09ac9aa5180973064affcf 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.cpp @@ -5,8 +5,10 @@ #include "BellSettingsAlarmSettingsMenuWindow.hpp" #include "BellSettingsAlarmSettingsWindow.hpp" #include "BellSettingsStyle.hpp" -#include +#include +#include +#include #include #include #include @@ -79,4 +81,16 @@ namespace gui { setFocusItem(sidelistview); } + + void BellSettingsAlarmSettingsWindow::handleError() + { + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } + + void BellSettingsAlarmSettingsWindow::handleDeletedFile() + { + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } } /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp index 12a846efe26e24c4f6591518b4251f556e9248b2..661c86e9b0b352e74c79a4ae1fee00335ce17d56 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsAlarmSettingsWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -27,6 +27,8 @@ namespace gui bool onInput(const InputEvent &inputEvent) override; void rebuild() override; void exit() override; + void handleError() override; + void handleDeletedFile() override; private: SideListView *sidelistview{}; diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.cpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.cpp index bdcf4fb0ef921cf4de74bb589ab301eecba73ebe..04c618fb0090f15d2369cfcc6c5604e28f7b4ad8 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.cpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.cpp @@ -1,12 +1,14 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include "application-bell-settings/ApplicationBellSettings.hpp" #include "BellSettingsAlarmSettingsMenuWindow.hpp" #include "BellSettingsPrewakeUpWindow.hpp" #include "BellSettingsStyle.hpp" -#include +#include +#include +#include #include #include #include @@ -78,4 +80,16 @@ namespace gui presenter->eraseProviderData(); } } + + void BellSettingsPrewakeUpWindow::handleError() + { + auto switchData = std::make_unique(AudioErrorType::UnsupportedMediaType); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } + + void BellSettingsPrewakeUpWindow::handleDeletedFile() + { + auto switchData = std::make_unique(AudioErrorType::FileDeleted); + app::manager::Controller::sendAction(application, app::manager::actions::ShowPopup, std::move(switchData)); + } } /* namespace gui */ diff --git a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.hpp b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.hpp index a1e7193ffce4e4748cbb49d0fc7626e4571cdda6..9ec7b39c03a22321463e555b482d51969b150c9f 100644 --- a/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.hpp +++ b/products/BellHybrid/apps/application-bell-settings/windows/alarm_settings/BellSettingsPrewakeUpWindow.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -26,6 +26,8 @@ namespace gui bool onInput(const InputEvent &inputEvent) override; void rebuild() override; void exit() override; + void handleError() override; + void handleDeletedFile() override; private: SideListView *sidelistview{}; diff --git a/products/BellHybrid/apps/common/CMakeLists.txt b/products/BellHybrid/apps/common/CMakeLists.txt index 58c30fdcb8e4e942198b162e78aef074e40fd44d..c783f76f5112bf9c4337ae70f8a76103e3ea6dcd 100644 --- a/products/BellHybrid/apps/common/CMakeLists.txt +++ b/products/BellHybrid/apps/common/CMakeLists.txt @@ -27,6 +27,7 @@ target_sources(application-bell-common src/SoundsProvider.cpp src/BellSideListItemWithCallbacks.cpp src/TimeUtils.cpp + src/AudioErrorPresenter.cpp src/windows/BellFactoryReset.cpp src/windows/BellFinishedWindow.cpp @@ -36,6 +37,7 @@ target_sources(application-bell-common src/windows/ShortcutsWindow.cpp src/windows/BellBatteryStatusWindow.cpp src/windows/AppsBatteryStatusWindow.cpp + src/windows/AudioErrorWindow.cpp src/models/SettingsModel.cpp src/models/BedtimeModel.cpp @@ -93,6 +95,7 @@ target_sources(application-bell-common include/common/SoundsRepository.hpp include/common/BellPowerOffPresenter.hpp include/common/BellFactoryResetPresenter.hpp + include/common/AudioErrorPresenter.hpp include/common/windows/BellFactoryReset.hpp include/common/windows/BellFinishedWindow.hpp include/common/windows/BellTurnOffWindow.hpp @@ -102,6 +105,7 @@ target_sources(application-bell-common include/common/windows/ShortcutsWindow.hpp include/common/windows/BellBatteryStatusWindow.hpp include/common/windows/AppsBatteryStatusWindow.hpp + include/common/windows/AudioErrorWindow.hpp include/common/TimeUtils.hpp include/common/data/BatteryUtils.hpp diff --git a/products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.hpp b/products/BellHybrid/apps/common/include/common/AudioErrorPresenter.hpp similarity index 64% rename from products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.hpp rename to products/BellHybrid/apps/common/include/common/AudioErrorPresenter.hpp index 3e7a6d6a6ed87841fe7f18a17e5a40cd9179f2dd..b5848731cefa213d4f34c3b5fa8dbfb49fc2e2ea 100644 --- a/products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationErrorPresenter.hpp +++ b/products/BellHybrid/apps/common/include/common/AudioErrorPresenter.hpp @@ -10,9 +10,9 @@ namespace app class ApplicationCommon; } -namespace app::relaxation +namespace gui { - class RelaxationErrorContract + class AudioErrorContract { public: class View @@ -20,19 +20,19 @@ namespace app::relaxation public: virtual ~View() = default; }; - class Presenter : public BasePresenter + class Presenter : public app::BasePresenter { public: virtual void activate() = 0; }; }; - class RelaxationErrorPresenter : public RelaxationErrorContract::Presenter + class AudioErrorPresenter : public AudioErrorContract::Presenter { app::ApplicationCommon *app{}; void activate() override; public: - explicit RelaxationErrorPresenter(app::ApplicationCommon *app); + explicit AudioErrorPresenter(app::ApplicationCommon *app); }; -} // namespace app::relaxation +} // namespace gui diff --git a/products/BellHybrid/apps/common/include/common/BellCommonNames.hpp b/products/BellHybrid/apps/common/include/common/BellCommonNames.hpp index 51893ccf5e9786bdf0fe272af25a6b4524e80514..84c25a06a1f1a4fb3d0f76ad9105490044d0511b 100644 --- a/products/BellHybrid/apps/common/include/common/BellCommonNames.hpp +++ b/products/BellHybrid/apps/common/include/common/BellCommonNames.hpp @@ -1,4 +1,4 @@ -// Copyright (c) 2017-2023, Mudita Sp. z.o.o. All rights reserved. +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #pragma once @@ -6,5 +6,5 @@ namespace gui::window::name { inline constexpr auto shortcutsWindow = "BellShortcuts"; - + inline constexpr auto audioErrorWindow = "AudioError"; } // namespace gui::window::name diff --git a/products/BellHybrid/apps/common/include/common/windows/AudioErrorWindow.hpp b/products/BellHybrid/apps/common/include/common/windows/AudioErrorWindow.hpp new file mode 100644 index 0000000000000000000000000000000000000000..24d675ebf3b701c12e1b3798bf35413de544be25 --- /dev/null +++ b/products/BellHybrid/apps/common/include/common/windows/AudioErrorWindow.hpp @@ -0,0 +1,37 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include "common/AudioErrorPresenter.hpp" +#include +#include +#include + +namespace gui +{ + class BellBaseLayout; + class AudioErrorWindow : public WindowWithTimer + { + public: + using OnExitCallback = std::function; + + AudioErrorWindow(app::ApplicationCommon *app, + const std::string &name, + std::unique_ptr &&presenter, + OnExitCallback callback = nullptr); + + private: + std::unique_ptr presenter; + std::string errorText; + Icon *icon{nullptr}; + AudioErrorType errorType{AudioErrorType::Unknown}; + OnExitCallback onExitCallback; + + void buildInterface() override; + bool onInput(const InputEvent &inputEvent) override; + void registerCallbacks(); + void buildLayout(); + void onBeforeShow(ShowMode mode, SwitchData *data) override; + }; +} // namespace gui diff --git a/products/BellHybrid/apps/common/src/AudioErrorPresenter.cpp b/products/BellHybrid/apps/common/src/AudioErrorPresenter.cpp new file mode 100644 index 0000000000000000000000000000000000000000..26d592dbecc88cd91eae4f8065e71172e2eaea17 --- /dev/null +++ b/products/BellHybrid/apps/common/src/AudioErrorPresenter.cpp @@ -0,0 +1,19 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "AudioErrorPresenter.hpp" + +#include +#include + +namespace gui +{ + AudioErrorPresenter::AudioErrorPresenter(app::ApplicationCommon *app) : app{app} + {} + + void AudioErrorPresenter::activate() + { + app::manager::Controller::sendAction( + app, app::manager::actions::Launch, std::make_unique(app->GetName())); + } +} // namespace gui diff --git a/products/BellHybrid/apps/common/src/windows/AudioErrorWindow.cpp b/products/BellHybrid/apps/common/src/windows/AudioErrorWindow.cpp new file mode 100644 index 0000000000000000000000000000000000000000..bbf59288cd86ae05c5134aad067c5d77c65a7d8d --- /dev/null +++ b/products/BellHybrid/apps/common/src/windows/AudioErrorWindow.cpp @@ -0,0 +1,100 @@ +// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "windows/AudioErrorWindow.hpp" + +#include +#include + +namespace +{ + constexpr auto windowTimeout = std::chrono::seconds{6}; + constexpr auto unsupportedMediaMessage = "app_bell_audio_error_message"; + constexpr auto exceededFilesLimitMessage = "app_bell_audio_limit_error_message"; + constexpr auto fileDeletedMessage = "app_bell_audio_file_deleted_message"; + constexpr auto emptyErrorMessage = ""; + + constexpr auto imageMarginTop = 122U; + constexpr auto textPaddingTop = 30U; +} // namespace + +namespace gui +{ + AudioErrorWindow::AudioErrorWindow(app::ApplicationCommon *app, + const std::string &name, + std::unique_ptr &&presenter, + OnExitCallback callback) + : WindowWithTimer(app, name, windowTimeout), presenter{std::move(presenter)}, onExitCallback{ + std::move(callback)} + { + if (onExitCallback == nullptr) { + onExitCallback = [this]() { application->returnToPreviousWindow(); }; + } + buildInterface(); + } + + void AudioErrorWindow::buildInterface() + { + AppWindow::buildInterface(); + buildLayout(); + registerCallbacks(); + } + + void AudioErrorWindow::buildLayout() + { + statusBar->setVisible(false); + + icon = new Icon( + this, 0, 0, style::window_width, style::window_height, "big_information", "", ImageTypeSpecifier::W_G); + icon->image->setMargins({0, imageMarginTop, 0, 0}); + icon->text->setFont(style::window::font::verybiglight); + const auto textPadding = icon->text->getPadding(); + icon->text->setPadding({textPadding.left, textPaddingTop, textPadding.right, textPadding.bottom}); + icon->text->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Center)); + icon->setAlignment(Alignment(Alignment::Horizontal::Center, Alignment::Vertical::Top)); + icon->resizeItems(); + } + + void AudioErrorWindow::registerCallbacks() + { + timerCallback = [this](Item &, sys::Timer &timer) { + onExitCallback(); + return true; + }; + } + + void AudioErrorWindow::onBeforeShow(ShowMode mode, SwitchData *data) + { + if (data && typeid(*data) == typeid(AudioErrorParams)) { + auto *errorData = static_cast(data); + errorType = errorData->getErrorType(); + switch (errorType) { + case AudioErrorType::UnsupportedMediaType: { + icon->text->setRichText(utils::translate(unsupportedMediaMessage)); + break; + } + case AudioErrorType::FilesLimitExceeded: { + icon->text->setRichText(utils::translate(exceededFilesLimitMessage)); + break; + } + case AudioErrorType::FileDeleted: { + icon->text->setRichText(utils::translate(fileDeletedMessage)); + break; + } + default: + icon->text->setRichText(utils::translate(emptyErrorMessage)); + } + } + WindowWithTimer::onBeforeShow(mode, data); + } + + bool AudioErrorWindow::onInput(const InputEvent &inputEvent) + { + if (inputEvent.isShortRelease(KeyCode::KEY_ENTER) || inputEvent.isShortRelease(KeyCode::KEY_RF)) { + detachTimerIfExists(); + onExitCallback(); + return true; + } + return true; + } +} // namespace gui