Skip to content

Commit e84aa4a

Browse files
committed
[BH-2091] Remove timer from loop mode in Relaxation
* Removed timer logic that would refresh the entire loop mode screen in Relaxation. The contents of the screen doesn't change unless there's a user activity or time update, so the timer is not needed. This should improve battery life in Relaxation loop mode. * Minor cleanups.
1 parent ca171b7 commit e84aa4a

16 files changed

+86
-153
lines changed

harmony_changelog.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
### Added
88

99
### Changed / Improved
10+
* Optimized power consumption in Relaxation loop mode
1011

1112
## [2.9.1 2024-12-16]
1213

Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#pragma once
55

66
namespace app::relaxation
77
{
8-
constexpr auto timerValueDBRecordName = "RelaxationTimerValue";
8+
inline constexpr auto timerValueDBRecordName = "RelaxationTimerValue";
99
} // namespace app::relaxation

products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationRunningLoopPresenter.cpp

+21-65
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#include "RelaxationRunningLoopPresenter.hpp"
5-
#include "data/RelaxationCommon.hpp"
65
#include "widgets/RelaxationPlayer.hpp"
76

87
#include <common/models/TimeModel.hpp>
@@ -17,93 +16,55 @@ namespace app::relaxation
1716
: settings{settings}, player{player}, batteryModel{battery}, timeModel{std::move(timeModel)}
1817
{}
1918

20-
void RelaxationRunningLoopPresenter::setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer)
21-
{
22-
timer = std::move(_timer);
23-
timer->registerOnFinishedCallback([this]() {
24-
onFinished();
25-
getView()->onFinished();
26-
});
27-
}
28-
2919
void RelaxationRunningLoopPresenter::activate(const db::multimedia_files::MultimediaFilesRecord &song)
3020
{
31-
Expects(timer != nullptr);
32-
33-
AbstractAudioModel::PlaybackMode mode;
34-
const auto value = settings->getValue(timerValueDBRecordName, settings::SettingsScope::AppLocal);
35-
if (utils::is_number(value) && utils::getNumericValue<int>(value) != 0) {
36-
timer->reset(std::chrono::minutes{utils::getNumericValue<int>(value)});
37-
mode = AbstractAudioModel::PlaybackMode::Loop;
38-
}
39-
else {
40-
const auto songLength = std::chrono::seconds{song.audioProperties.songLength};
41-
mode = AbstractAudioModel::PlaybackMode::Single;
42-
43-
if (songLength > std::chrono::seconds::zero()) {
44-
timer->reset(songLength);
45-
}
46-
else {
47-
getView()->handleError();
48-
return;
49-
}
50-
}
51-
5221
auto onStartCallback = [this](audio::RetCode retCode) {
53-
if (retCode == audio::RetCode::Success) {
54-
timer->start();
55-
}
56-
else {
22+
if (retCode != audio::RetCode::Success) {
5723
getView()->handleError();
5824
}
5925
};
6026

6127
auto onFinishedCallback = [this](AbstractAudioModel::PlaybackFinishStatus status) {
62-
if (status == AbstractAudioModel::PlaybackFinishStatus::Error) {
63-
timer->stop();
28+
if (status != AbstractAudioModel::PlaybackFinishStatus::Normal) {
6429
getView()->handleDeletedFile(); // Deleted file is currently the only error handled by player
6530
}
6631
};
6732

68-
player.start(song.fileInfo.path, mode, std::move(onStartCallback), std::move(onFinishedCallback));
33+
player.start(song.fileInfo.path,
34+
AbstractAudioModel::PlaybackMode::Loop,
35+
std::move(onStartCallback),
36+
std::move(onFinishedCallback));
6937
}
7038

7139
void RelaxationRunningLoopPresenter::stop()
7240
{
7341
onFinished();
74-
timer->stop();
7542
}
7643

7744
void RelaxationRunningLoopPresenter::onFinished()
7845
{
79-
auto onStopCallback = [this](audio::RetCode retCode) {};
46+
auto onStopCallback = [](audio::RetCode retCode) {};
8047
player.stop(std::move(onStopCallback));
8148
}
8249

8350
void RelaxationRunningLoopPresenter::pause()
8451
{
85-
if (not timer->isStopped()) {
86-
auto onPauseCallback = [this](audio::RetCode retCode) {
87-
if (retCode == audio::RetCode::Success) {
88-
timer->stop();
89-
getView()->onPaused();
90-
}
91-
};
92-
player.pause(std::move(onPauseCallback));
93-
}
52+
auto onPauseCallback = [this](audio::RetCode retCode) {
53+
if (retCode == audio::RetCode::Success) {
54+
getView()->onPaused();
55+
}
56+
};
57+
player.pause(std::move(onPauseCallback));
9458
}
9559

9660
void RelaxationRunningLoopPresenter::resume()
9761
{
98-
if (timer->isStopped()) {
99-
auto onResumeCallback = [this](audio::RetCode retCode) {
100-
if (retCode == audio::RetCode::Success) {
101-
timer->start();
102-
getView()->resume();
103-
}
104-
};
105-
player.resume(std::move(onResumeCallback));
106-
}
62+
auto onResumeCallback = [this](audio::RetCode retCode) {
63+
if (retCode == audio::RetCode::Success) {
64+
getView()->resume();
65+
}
66+
};
67+
player.resume(std::move(onResumeCallback));
10768
}
10869

10970
void RelaxationRunningLoopPresenter::handleUpdateTimeEvent()
@@ -121,12 +82,7 @@ namespace app::relaxation
12182
getView()->setTimeFormat(timeModel->getTimeFormat());
12283
}
12384

124-
bool RelaxationRunningLoopPresenter::isTimerStopped()
125-
{
126-
return timer->isStopped();
127-
}
128-
129-
Store::Battery RelaxationRunningLoopPresenter::getBatteryState()
85+
Store::Battery RelaxationRunningLoopPresenter::getBatteryState() const
13086
{
13187
return batteryModel.getLevelState();
13288
}

products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationRunningLoopPresenter.hpp

+15-19
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#pragma once
55

66
#include <apps-common/BasePresenter.hpp>
7-
#include <apps-common/widgets/TimerWithCallbacks.hpp>
87
#include <common/models/BatteryModel.hpp>
98
#include <module-utils/EventStore/EventStore.hpp>
109
#include <module-db/Interface/MultimediaFilesRecord.hpp>
@@ -17,10 +16,12 @@ namespace app
1716
class AbstractBatteryModel;
1817
class ApplicationCommon;
1918
} // namespace app
19+
2020
namespace gui
2121
{
2222
class Item;
2323
} // namespace gui
24+
2425
namespace settings
2526
{
2627
class Settings;
@@ -35,7 +36,6 @@ namespace app::relaxation
3536
{
3637
public:
3738
virtual ~View() = default;
38-
virtual void onFinished() = 0;
3939
virtual void onPaused() = 0;
4040
virtual void resume() = 0;
4141
virtual void setTime(std::time_t newTime) = 0;
@@ -51,44 +51,40 @@ namespace app::relaxation
5151
virtual void stop() = 0;
5252
virtual void pause() = 0;
5353
virtual void resume() = 0;
54-
virtual bool isTimerStopped() = 0;
55-
virtual void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&timer) = 0;
5654
virtual void handleUpdateTimeEvent() = 0;
5755
virtual bool isPaused() = 0;
5856
virtual void onBeforeShow() = 0;
59-
virtual Store::Battery getBatteryState() = 0;
60-
virtual bool isBatteryCharging(Store::Battery::State state) const = 0;
57+
[[nodiscard]] virtual Store::Battery getBatteryState() const = 0;
58+
[[nodiscard]] virtual bool isBatteryCharging(Store::Battery::State state) const = 0;
6159
};
6260
};
6361

6462
class AbstractRelaxationPlayer;
6563

6664
class RelaxationRunningLoopPresenter : public RelaxationRunningLoopContract::Presenter
6765
{
68-
settings::Settings *settings = nullptr;
66+
public:
67+
RelaxationRunningLoopPresenter(settings::Settings *settings,
68+
AbstractRelaxationPlayer &player,
69+
AbstractBatteryModel &batteryModel,
70+
std::unique_ptr<AbstractTimeModel> timeModel);
71+
72+
private:
73+
settings::Settings *settings{nullptr};
6974
AbstractRelaxationPlayer &player;
7075
AbstractBatteryModel &batteryModel;
71-
std::unique_ptr<app::TimerWithCallbacks> timer;
7276
std::unique_ptr<AbstractTimeModel> timeModel;
7377

7478
void activate(const db::multimedia_files::MultimediaFilesRecord &tags) override;
7579
void stop() override;
7680
void pause() override;
7781
void resume() override;
78-
bool isTimerStopped() override;
79-
void setTimer(std::unique_ptr<app::TimerWithCallbacks> &&_timer) override;
8082
void handleUpdateTimeEvent() override;
8183
bool isPaused() override;
8284
void onBeforeShow() override;
83-
Store::Battery getBatteryState() override;
84-
bool isBatteryCharging(Store::Battery::State state) const override;
85+
[[nodiscard]] Store::Battery getBatteryState() const override;
86+
[[nodiscard]] bool isBatteryCharging(Store::Battery::State state) const override;
8587

8688
void onFinished();
87-
88-
public:
89-
RelaxationRunningLoopPresenter(settings::Settings *settings,
90-
AbstractRelaxationPlayer &player,
91-
AbstractBatteryModel &batteryModel,
92-
std::unique_ptr<AbstractTimeModel> timeModel);
9389
};
9490
} // namespace app::relaxation

products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationRunningProgressPresenter.hpp

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#pragma once
@@ -65,7 +65,13 @@ namespace app::relaxation
6565

6666
class RelaxationRunningProgressPresenter : public RelaxationRunningProgressContract::Presenter
6767
{
68-
settings::Settings *settings = nullptr;
68+
public:
69+
RelaxationRunningProgressPresenter(settings::Settings *settings,
70+
AbstractRelaxationPlayer &player,
71+
std::unique_ptr<AbstractTimeModel> timeModel);
72+
73+
private:
74+
settings::Settings *settings{nullptr};
6975
AbstractRelaxationPlayer &player;
7076
std::unique_ptr<app::TimerWithCallbacks> timer;
7177
std::unique_ptr<AbstractTimeModel> timeModel;
@@ -83,10 +89,5 @@ namespace app::relaxation
8389
void onBeforeShow() override;
8490

8591
void onFinished();
86-
87-
public:
88-
RelaxationRunningProgressPresenter(settings::Settings *settings,
89-
AbstractRelaxationPlayer &player,
90-
std::unique_ptr<AbstractTimeModel> timeModel);
9192
};
9293
} // namespace app::relaxation

products/BellHybrid/apps/application-bell-relaxation/presenter/RelaxationTimerSelectPresenter.cpp

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#include "RelaxationTimerSelectPresenter.hpp"
@@ -66,5 +66,4 @@ namespace app::relaxation
6666
{
6767
lowBatteryInfoModel.handleInfo();
6868
}
69-
7069
} // namespace app::relaxation

products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.cpp

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#include "RelaxationPlayer.hpp"
@@ -27,7 +27,7 @@ namespace app::relaxation
2727
recentFilePath = filePath;
2828
playbackMode = mode;
2929

30-
auto onPlayerFinished = [callback = finishedCallback, this](Status status) {
30+
auto onPlayerFinished = [callback = finishedCallback](Status status) {
3131
if (status == Status::Error) {
3232
callback(status); // Playback finished with error
3333
}
@@ -38,8 +38,7 @@ namespace app::relaxation
3838

3939
auto fadeParams = audio::FadeParams{.mode = getFadeMode(), .playbackDuration = playbackDuration};
4040
audioModel.setPlaybackFinishedCb(std::move(onPlayerFinished));
41-
audioModel.play(
42-
filePath, Type::Multimedia, playbackMode, std::move(stateChangeCallback), std::move(fadeParams));
41+
audioModel.play(filePath, Type::Multimedia, playbackMode, std::move(stateChangeCallback), fadeParams);
4342
}
4443

4544
audio::Fade RelaxationPlayer::getFadeMode() const
@@ -65,7 +64,7 @@ namespace app::relaxation
6564
audioModel.resume(std::move(callback));
6665
}
6766

68-
bool RelaxationPlayer::isPaused()
67+
bool RelaxationPlayer::isPaused() const noexcept
6968
{
7069
return paused;
7170
}

products/BellHybrid/apps/application-bell-relaxation/widgets/RelaxationPlayer.hpp

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) 2017-2024, Mudita Sp. z.o.o. All rights reserved.
1+
// Copyright (c) 2017-2025, Mudita Sp. z.o.o. All rights reserved.
22
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
33

44
#pragma once
@@ -30,9 +30,9 @@ namespace app::relaxation
3030
virtual void stop(AbstractAudioModel::OnStateChangeCallback &&callback) = 0;
3131
virtual void pause(AbstractAudioModel::OnStateChangeCallback &&callback) = 0;
3232
virtual void resume(AbstractAudioModel::OnStateChangeCallback &&callback) = 0;
33-
virtual AbstractAudioModel::PlaybackMode getCurrentMode() const noexcept = 0;
34-
virtual audio::Fade getFadeMode() const = 0;
35-
virtual bool isPaused() = 0;
33+
[[nodiscard]] virtual AbstractAudioModel::PlaybackMode getCurrentMode() const noexcept = 0;
34+
[[nodiscard]] virtual audio::Fade getFadeMode() const = 0;
35+
[[nodiscard]] virtual bool isPaused() const noexcept = 0;
3636
};
3737

3838
class RelaxationPlayer : public AbstractRelaxationPlayer
@@ -49,9 +49,9 @@ namespace app::relaxation
4949
void stop(AbstractAudioModel::OnStateChangeCallback &&callback) override;
5050
void pause(AbstractAudioModel::OnStateChangeCallback &&callback) override;
5151
void resume(AbstractAudioModel::OnStateChangeCallback &&callback) override;
52-
AbstractAudioModel::PlaybackMode getCurrentMode() const noexcept override;
53-
audio::Fade getFadeMode() const override;
54-
bool isPaused() override;
52+
[[nodiscard]] AbstractAudioModel::PlaybackMode getCurrentMode() const noexcept override;
53+
[[nodiscard]] audio::Fade getFadeMode() const override;
54+
[[nodiscard]] bool isPaused() const noexcept override;
5555

5656
AbstractRelaxationFadeModel &fadeModel;
5757
AbstractAudioModel &audioModel;

0 commit comments

Comments
 (0)