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.
2
2
// For licensing, see https://github.com/mudita/MuditaOS/blob/master/LICENSE.md
3
3
4
4
#include " RelaxationRunningLoopPresenter.hpp"
5
- #include " data/RelaxationCommon.hpp"
6
5
#include " widgets/RelaxationPlayer.hpp"
7
6
8
7
#include < common/models/TimeModel.hpp>
@@ -17,93 +16,55 @@ namespace app::relaxation
17
16
: settings{settings}, player{player}, batteryModel{battery}, timeModel{std::move (timeModel)}
18
17
{}
19
18
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
-
29
19
void RelaxationRunningLoopPresenter::activate (const db::multimedia_files::MultimediaFilesRecord &song)
30
20
{
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
-
52
21
auto onStartCallback = [this ](audio::RetCode retCode) {
53
- if (retCode == audio::RetCode::Success) {
54
- timer->start ();
55
- }
56
- else {
22
+ if (retCode != audio::RetCode::Success) {
57
23
getView ()->handleError ();
58
24
}
59
25
};
60
26
61
27
auto onFinishedCallback = [this ](AbstractAudioModel::PlaybackFinishStatus status) {
62
- if (status == AbstractAudioModel::PlaybackFinishStatus::Error) {
63
- timer->stop ();
28
+ if (status != AbstractAudioModel::PlaybackFinishStatus::Normal) {
64
29
getView ()->handleDeletedFile (); // Deleted file is currently the only error handled by player
65
30
}
66
31
};
67
32
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));
69
37
}
70
38
71
39
void RelaxationRunningLoopPresenter::stop ()
72
40
{
73
41
onFinished ();
74
- timer->stop ();
75
42
}
76
43
77
44
void RelaxationRunningLoopPresenter::onFinished ()
78
45
{
79
- auto onStopCallback = [this ](audio::RetCode retCode) {};
46
+ auto onStopCallback = [](audio::RetCode retCode) {};
80
47
player.stop (std::move (onStopCallback));
81
48
}
82
49
83
50
void RelaxationRunningLoopPresenter::pause ()
84
51
{
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));
94
58
}
95
59
96
60
void RelaxationRunningLoopPresenter::resume ()
97
61
{
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));
107
68
}
108
69
109
70
void RelaxationRunningLoopPresenter::handleUpdateTimeEvent ()
@@ -121,12 +82,7 @@ namespace app::relaxation
121
82
getView ()->setTimeFormat (timeModel->getTimeFormat ());
122
83
}
123
84
124
- bool RelaxationRunningLoopPresenter::isTimerStopped ()
125
- {
126
- return timer->isStopped ();
127
- }
128
-
129
- Store::Battery RelaxationRunningLoopPresenter::getBatteryState ()
85
+ Store::Battery RelaxationRunningLoopPresenter::getBatteryState () const
130
86
{
131
87
return batteryModel.getLevelState ();
132
88
}
0 commit comments