M products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp => products/BellHybrid/apps/application-bell-meditation-timer/MeditationTimer.cpp +1 -1
@@ 64,7 64,7 @@ namespace app
windowsFactory.attach(meditation::SettingsWindow::name,
[this](ApplicationCommon *app, const std::string &name) {
auto presenter = std::make_unique<app::meditation::SettingsPresenter>(
- app, *chimeIntervalModel, *chimeVolumeModel, *startDelayModel, *audioModel);
+ *chimeIntervalModel, *chimeVolumeModel, *startDelayModel, *audioModel);
return std::make_unique<meditation::SettingsWindow>(app, std::move(presenter));
});
M products/BellHybrid/apps/application-bell-meditation-timer/data/Contract.hpp => products/BellHybrid/apps/application-bell-meditation-timer/data/Contract.hpp +2 -2
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 22,7 22,7 @@ namespace app::meditation::contract
virtual void loadData() = 0;
virtual void saveData() = 0;
virtual void eraseProviderData() = 0;
- virtual void handleEnter() = 0;
+ virtual void exitWithSave() = 0;
virtual void exitWithoutSave() = 0;
};
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.cpp +12 -18
@@ 2,7 2,6 @@
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#include "SettingsPresenter.hpp"
-#include "MeditationMainWindow.hpp"
#include "MeditationCommon.hpp"
#include "models/ChimeInterval.hpp"
@@ 12,7 11,6 @@
#include <ApplicationCommon.hpp>
#include <common/widgets/list_items/Fraction.hpp>
#include <common/widgets/list_items/Numeric.hpp>
-#include <common/windows/BellFinishedWindow.hpp>
#include <common/LanguageUtils.hpp>
#include <apps-common/InternalModel.hpp>
#include <apps-common/widgets/spinners/Spinners.hpp>
@@ 58,13 56,12 @@ namespace app::list_items
namespace app::meditation
{
using namespace gui;
- SettingsPresenter::SettingsPresenter(app::ApplicationCommon *app,
- models::ChimeInterval &chimeIntervalModel,
+ SettingsPresenter::SettingsPresenter(models::ChimeInterval &chimeIntervalModel,
models::ChimeVolume &chimeVolumeModel,
models::StartDelay &startDelayModel,
AbstractAudioModel &audioModel)
- : application{app}, chimeIntervalModel{chimeIntervalModel}, chimeVolumeModel{chimeVolumeModel},
- startDelayModel{startDelayModel}, audioModel{audioModel}
+ : chimeIntervalModel{chimeIntervalModel}, chimeVolumeModel{chimeVolumeModel}, startDelayModel{startDelayModel},
+ audioModel{audioModel}
{
auto chimeInterval =
@@ 73,15 70,11 @@ namespace app::meditation
utils::translate("app_bell_meditation_chime_interval"),
utils::translate("app_bell_meditation_chime_interval_bottom")};
- chimeInterval->set_on_value_change_cb([this](const auto &val) { this->chimeIntervalModel.setValue(val); });
-
auto startDelay = new list_items::StartDelay{list_items::StartDelay::spinner_type::range{0, 90, 10},
startDelayModel,
utils::translate("app_bell_meditation_start_delay"),
utils::translate("common_second_lower")};
- startDelay->set_on_value_change_cb([this](const auto &val) { this->startDelayModel.setValue(val); });
-
auto chimeVolume = new list_items::Numeric{list_items::Numeric::spinner_type::range{1, 10, 1},
chimeVolumeModel,
utils::translate("app_bell_meditation_chime_volume")};
@@ 89,16 82,18 @@ namespace app::meditation
listItemsProvider =
std::make_shared<BellListItemProvider>(BellListItemProvider::Items{startDelay, chimeInterval, chimeVolume});
- chimeVolume->onEnter = [this]() {
+ auto playSound = [this]() {
this->audioModel.play(getMeditationAudioPath(), AbstractAudioModel::PlaybackType::Meditation, {});
};
+ chimeVolume->onEnter = playSound;
+
chimeVolume->onExit = [this]() { stopSound(); };
- chimeVolume->set_on_value_change_cb([this](const auto &val) {
+ chimeVolume->set_on_value_change_cb([this, playSound](const auto &val) {
this->audioModel.setVolume(val, AbstractAudioModel::PlaybackType::Meditation, {});
if (this->audioModel.hasPlaybackFinished()) {
- this->audioModel.play(getMeditationAudioPath(), AbstractAudioModel::PlaybackType::Meditation, {});
+ playSound();
}
});
@@ 114,7 109,6 @@ namespace app::meditation
}
void SettingsPresenter::saveData()
{
- stopSound();
for (auto &item : listItemsProvider->getListItems()) {
item->getValue();
}
@@ 127,12 121,10 @@ namespace app::meditation
{
listItemsProvider->clearData();
}
- void SettingsPresenter::handleEnter()
+ void SettingsPresenter::exitWithSave()
{
saveData();
- application->switchWindow(
- window::bell_finished::defaultName,
- BellFinishedWindowData::Factory::create("circle_success_big", MeditationMainWindow::defaultName));
+ eraseProviderData();
}
void SettingsPresenter::stopSound()
@@ 142,7 134,9 @@ namespace app::meditation
void SettingsPresenter::exitWithoutSave()
{
+ this->stopSound();
chimeVolumeModel.restoreDefault();
+ eraseProviderData();
}
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.hpp => products/BellHybrid/apps/application-bell-meditation-timer/presenter/SettingsPresenter.hpp +3 -5
@@ 1,4 1,4 @@
-// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved.
+// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
#pragma once
@@ 26,8 26,7 @@ namespace app::meditation
class SettingsPresenter : public contract::Presenter
{
public:
- SettingsPresenter(app::ApplicationCommon *app,
- models::ChimeInterval &chimeIntervalModel,
+ SettingsPresenter(models::ChimeInterval &chimeIntervalModel,
models::ChimeVolume &chimeVolumeModel,
models::StartDelay &startDelayModel,
AbstractAudioModel &audioModel);
@@ 35,12 34,11 @@ namespace app::meditation
void saveData() override;
auto getPagesProvider() const -> std::shared_ptr<gui::ListItemProvider> override;
void eraseProviderData() override;
- void handleEnter() override;
+ void exitWithSave() override;
void exitWithoutSave() override;
private:
void stopSound();
- ApplicationCommon *application{};
models::ChimeInterval &chimeIntervalModel;
models::ChimeVolume &chimeVolumeModel;
models::StartDelay &startDelayModel;
M products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.cpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.cpp +19 -4
@@ 1,9 1,11 @@
// Copyright (c) 2017-2022, Mudita Sp. z.o.o. All rights reserved.
// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md
+#include "MeditationMainWindow.hpp"
#include "SettingsWindow.hpp"
#include <common/data/StyleCommon.hpp>
+#include <common/windows/BellFinishedWindow.hpp>
#include <apps-common/ApplicationCommon.hpp>
#include <module-gui/gui/input/InputEvent.hpp>
#include <module-gui/gui/widgets/SideListView.hpp>
@@ 23,6 25,7 @@ namespace app::meditation
{
erase();
buildInterface();
+ isSaveNeeded = false;
}
void SettingsWindow::buildInterface()
@@ 38,13 41,12 @@ namespace app::meditation
sideListView->rebuildList(listview::RebuildType::Full);
- setFocusItem(sideListView);
+ presenter->loadData();
}
void SettingsWindow::onBeforeShow(gui::ShowMode mode, gui::SwitchData *data)
{
AppWindow::onBeforeShow(mode, data);
- presenter->loadData();
setFocusItem(sideListView);
}
@@ 54,7 56,8 @@ namespace app::meditation
return true;
}
if (inputEvent.isShortRelease(KeyCode::KEY_ENTER)) {
- presenter->handleEnter();
+ isSaveNeeded = true;
+ switchToExitWindow();
return true;
}
if (inputEvent.isShortRelease(KeyCode::KEY_RF)) {
@@ 64,10 67,22 @@ namespace app::meditation
return AppWindow::onInput(inputEvent);
}
+ void SettingsWindow::switchToExitWindow()
+ {
+ application->switchWindow(
+ window::bell_finished::defaultName,
+ BellFinishedWindowData::Factory::create("circle_success_big", MeditationMainWindow::defaultName));
+ }
+
void SettingsWindow::onClose(const CloseReason reason)
{
if (reason != CloseReason::Popup) {
- presenter->eraseProviderData();
+ if (isSaveNeeded) {
+ presenter->exitWithSave();
+ }
+ else {
+ presenter->exitWithoutSave();
+ }
}
}
} // namespace app::meditation
M products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.hpp => products/BellHybrid/apps/application-bell-meditation-timer/windows/SettingsWindow.hpp +3 -0
@@ 27,7 27,10 @@ namespace app::meditation
void rebuild() override;
private:
+ void switchToExitWindow();
+
gui::SideListView *sideListView{};
std::unique_ptr<app::meditation::contract::Presenter> presenter;
+ bool isSaveNeeded{false};
};
} // namespace app::meditation