From cf019e3d9604bb7599f3bfb49d4cda47aff9815d Mon Sep 17 00:00:00 2001 From: Alek Rudnik Date: Tue, 27 Jul 2021 11:56:14 +0200 Subject: [PATCH] [EGD-6776] Music Player All Songs Window Full MVP design. Removed redundant Empty Window. Added play/pause/resume/stop control. --- .../now_playing_icon_list.png | Bin 0 -> 635 bytes .../now_playing_icon_pause_list.png | Bin 0 -> 541 bytes image/assets/images/now_playing_icon_list.vpi | Bin 0 -> 813 bytes .../images/now_playing_icon_pause_list.vpi | Bin 0 -> 1021 bytes image/assets/lang/English.json | 1 + .../ApplicationMusicPlayer.cpp | 24 ++- .../AudioNotificationsHandler.cpp | 26 +++ .../AudioNotificationsHandler.hpp | 21 +++ .../application-music-player/CMakeLists.txt | 10 +- .../data/MusicPlayerStyle.hpp | 8 +- .../models/SongContext.cpp | 30 ++++ .../models/SongContext.hpp | 30 ++++ .../models/SongsModel.cpp | 97 +++++++++-- .../models/SongsModel.hpp | 25 ++- .../models/SongsModelInterface.hpp | 26 +-- .../models/SongsRepository.cpp | 44 +++-- .../models/SongsRepository.hpp | 46 +++++- .../presenters/AudioOperations.cpp | 43 +++-- .../presenters/AudioOperations.hpp | 18 ++- .../presenters/SongsPresenter.cpp | 141 +++++++++++----- .../presenters/SongsPresenter.hpp | 30 +++- .../tests/CMakeLists.txt | 12 ++ .../tests/MockSongsRepository.hpp | 24 +++ .../tests/MockTagsFetcher.hpp | 20 +++ .../tests/unittest.cpp | 10 ++ .../tests/unittest_songrepository.cpp | 153 ++++++++++++++++++ .../tests/unittest_songsmodel.cpp | 46 ++++++ .../widgets/SongItem.cpp | 65 +++++++- .../widgets/SongItem.hpp | 35 ++-- .../windows/MusicPlayerAllSongsWindow.cpp | 59 ++++++- .../windows/MusicPlayerAllSongsWindow.hpp | 9 +- .../windows/MusicPlayerEmptyWindow.cpp | 80 --------- .../windows/MusicPlayerEmptyWindow.hpp | 35 ---- .../service-audio/ServiceAudio.cpp | 2 - .../include/service-audio/AudioMessage.hpp | 7 - 35 files changed, 905 insertions(+), 272 deletions(-) create mode 100644 art/phone/application_musicplayer/now_playing_icon_list.png create mode 100644 art/phone/application_musicplayer/now_playing_icon_pause_list.png create mode 100644 image/assets/images/now_playing_icon_list.vpi create mode 100644 image/assets/images/now_playing_icon_pause_list.vpi create mode 100644 module-apps/application-music-player/AudioNotificationsHandler.cpp create mode 100644 module-apps/application-music-player/AudioNotificationsHandler.hpp create mode 100644 module-apps/application-music-player/models/SongContext.cpp create mode 100644 module-apps/application-music-player/models/SongContext.hpp create mode 100644 module-apps/application-music-player/tests/CMakeLists.txt create mode 100644 module-apps/application-music-player/tests/MockSongsRepository.hpp create mode 100644 module-apps/application-music-player/tests/MockTagsFetcher.hpp create mode 100644 module-apps/application-music-player/tests/unittest.cpp create mode 100644 module-apps/application-music-player/tests/unittest_songrepository.cpp create mode 100644 module-apps/application-music-player/tests/unittest_songsmodel.cpp delete mode 100644 module-apps/application-music-player/windows/MusicPlayerEmptyWindow.cpp delete mode 100644 module-apps/application-music-player/windows/MusicPlayerEmptyWindow.hpp diff --git a/art/phone/application_musicplayer/now_playing_icon_list.png b/art/phone/application_musicplayer/now_playing_icon_list.png new file mode 100644 index 0000000000000000000000000000000000000000..25d33b37d55fdd7621f4623cf9a1d267cc2d5dd0 GIT binary patch literal 635 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzmUKs7M+SzC{oH>NS%G|u)CkWs zUtb0-Ae)1Mu|1Q41;}CqVksbIU|?Fn1Q$_Qz>HvnB>VjwP68Fb^K@|xiQs%2W_#+8 zgTUM){w&$jYjeH`%sZ?X7M1x_RObx~w|4(S#hg7&PFn&Tt2Y+y+jHR1uH7f!v8nd* ztE3r!ex_<|FI~W-C79T`@$vkS| zYt99V6fO-qxkYf>C($`-608g6q@@4+pSRt+^4o7){&weeVXJ3u+azz{dx7Ono_X?I zZX-p939|j}a{b3+R$nb@UEtpk-Kv(b`|dNLl}s!Tf7U#ES#s)YmF;EuJ6c;3OZLW1 zp8l2n*2kiqODy_U-hVI6>2qfm!{X(~lY+|RuDRSY$TFK9$8t!bIdfygg{r;Fjz3nM zc7NRuFR3fGAAJv9etBf_$s?MalQmbhCF^n~K8$KxeDTHSR1U^%ZYB~u`)+r5Wl>rNsFuk7R|Sr z!lrP2*W^^jgVS2r#nV!Z literal 0 HcmV?d00001 diff --git a/art/phone/application_musicplayer/now_playing_icon_pause_list.png b/art/phone/application_musicplayer/now_playing_icon_pause_list.png new file mode 100644 index 0000000000000000000000000000000000000000..23194909a4f7825d9418e39b1681b046d9936b17 GIT binary patch literal 541 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdz#^NA%Cx&(BWL^R}E~ycoX}-P; zT0k}j17mw80}DtA5K93u0|WB{Mh0de%?J`(zyz07Sip>6gA}f5OZp5{*6!)z7!twx zHq5cl)j>da^2QCnJ6l_WEf~}%6bOeW=eBb1XpuD+u${L=-L3q!oblXyf2MmZUL9vU zW!0w}d_^7n?Hl_q zB_T!5(u~{FR6UzguF7p_-m96%y5{w%RjV$sP33Hs|5F;k)lfX|d4E%}{=0bCWo zp4eE#A1r2H$x!3$R}j~%kWjs8qefTVo5xb$H`Z@^{=D2$k>kcT-jZ`Yyo>x1Xvavy4lbbF3|8Pi&-nqks)h0?}`dm#ta>^1&>5o7OaLyPRnBU zx|dy85XY%_B2)iC{*g@c7LMni8N@$+@jc*g-lNcVfw%B8*OQjDGcPzBOuo;TmJ#w| zTEzNb!(|UQ>D1ebN^=_s{ygHQ;o|S{@6l(m2Y+~L7*ozBa%w$XvJVtBp00i_>zopr E0BgL=YybcN literal 0 HcmV?d00001 diff --git a/image/assets/images/now_playing_icon_list.vpi b/image/assets/images/now_playing_icon_list.vpi new file mode 100644 index 0000000000000000000000000000000000000000..fb956b98bb5edbafaf041ce9b07ee04fa5148673 GIT binary patch literal 813 zcmbVL?Gl1849oZ!AmTWmfcJk&ld!2AqMScUuSwQ+U0JYT4gi+4|8~Tu1cV#y3RIWX zE1r_rQS3mgfyh{1@o07sJJKqEN9`34sb$oQ?ExmU?~QgDoio}QjXBd@C^N(t%G^fj zV`4hA(y|BlLm;pin>W@b^*{9|b$o-`}U;WgL&Q0m}#C0dX-{z&BC|`5?s-HJtzb%^I@rH^0 NzMaRLz5f$dLq0=-{&VSwGRjmK)3#77XdPoTN2atB5-m$<}BMT1H4%Hb$$7`vberu0N3Rl875Oe*b3tEJZC$wS;w8tjms+sPOT2{_ zk;(91EGqfLQbxPH#7piS8S+NI;$S};gO0lk=ju7vyTk8vd?t>~9kaBaUC`}0U+)BO R@O_WSX8%sIsau;p;%{pQ44MD{ literal 0 HcmV?d00001 diff --git a/image/assets/lang/English.json b/image/assets/lang/English.json index f782d9c6914df1bb223e3ff7a23498ddd7b71081..14bfac10e8190b307b8edeac4de48bf965c517ae 100644 --- a/image/assets/lang/English.json +++ b/image/assets/lang/English.json @@ -513,6 +513,7 @@ "app_meditation_minutes": "MINUTES", "app_music_player_all_songs": "All songs", "app_music_player_play": "PLAY", + "app_music_player_music_library_window_name": "Music Library", "app_music_player_music_library": "MUSIC LIBRARY", "app_music_player_quit": "QUIT", "app_music_player_music_empty_window_notification": "Press Music Library to choose\n a song from the library", diff --git a/module-apps/application-music-player/ApplicationMusicPlayer.cpp b/module-apps/application-music-player/ApplicationMusicPlayer.cpp index d2c1bb9955cfedbf20375f1b3fdb1a6394aec331..27763a1dc286285e7eaaebed62a09ea539db69e6 100644 --- a/module-apps/application-music-player/ApplicationMusicPlayer.cpp +++ b/module-apps/application-music-player/ApplicationMusicPlayer.cpp @@ -2,8 +2,10 @@ // For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md #include + +#include "AudioNotificationsHandler.hpp" + #include -#include #include #include #include @@ -40,14 +42,17 @@ namespace app { LOG_INFO("ApplicationMusicPlayer::create"); - auto songsRepository = std::make_unique(this); + bus.channels.push_back(sys::BusChannel::ServiceAudioNotifications); + + auto tagsFetcher = std::make_unique(this); + auto songsRepository = std::make_unique(std::move(tagsFetcher)); priv->songsModel = std::make_unique(std::move(songsRepository)); auto audioOperations = std::make_unique(this); priv->songsPresenter = std::make_unique(priv->songsModel, std::move(audioOperations)); // callback used when playing state is changed - using SongState = music_player::SongsModelInterface::SongState; + using SongState = app::music_player::SongState; std::function autolockCallback = [this](SongState isPlaying) { if (isPlaying == SongState::Playing) { LOG_DEBUG("Preventing autolock while playing track."); @@ -64,6 +69,12 @@ namespace app // callback used when track is not played and we are in DetermineByAppState std::function stateLockCallback = []() -> bool { return true; }; lockPolicyHandler.setPreventsAutoLockByStateCallback(std::move(stateLockCallback)); + + connect(typeid(AudioStopNotification), [&](sys::Message *msg) -> sys::MessagePointer { + auto notification = static_cast(msg); + music_player::AudioNotificationsHandler audioNotificationHandler{priv->songsPresenter}; + return audioNotificationHandler.handleAudioStopNotification(notification); + }); } ApplicationMusicPlayer::~ApplicationMusicPlayer() = default; @@ -96,24 +107,21 @@ namespace app } createUserInterface(); - return ret; } sys::ReturnCodes ApplicationMusicPlayer::DeinitHandler() { + priv->songsPresenter->getMusicPlayerItemProvider()->clearData(); priv->songsPresenter->stop(); return Application::DeinitHandler(); } void ApplicationMusicPlayer::createUserInterface() { - windowsFactory.attach(gui::name::window::all_songs_window, [&](Application *app, const std::string &name) { + windowsFactory.attach(gui::name::window::main_window, [&](Application *app, const std::string &name) { return std::make_unique(app, priv->songsPresenter); }); - windowsFactory.attach(gui::name::window::main_window, [](Application *app, const std::string &name) { - return std::make_unique(app); - }); attachPopups( {gui::popup::ID::Volume, gui::popup::ID::Tethering, gui::popup::ID::PhoneModes, gui::popup::ID::PhoneLock}); diff --git a/module-apps/application-music-player/AudioNotificationsHandler.cpp b/module-apps/application-music-player/AudioNotificationsHandler.cpp new file mode 100644 index 0000000000000000000000000000000000000000..56a7ddf8bd4c2be58cb4d41172c9aeb14028cc79 --- /dev/null +++ b/module-apps/application-music-player/AudioNotificationsHandler.cpp @@ -0,0 +1,26 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "AudioNotificationsHandler.hpp" + +#include + +namespace app::music_player +{ + + AudioNotificationsHandler::AudioNotificationsHandler( + std::shared_ptr presenter) + : presenter(presenter) + {} + + sys::MessagePointer AudioNotificationsHandler::handleAudioStopNotification( + const AudioStopNotification *notification) + { + if (notification == nullptr) { + return sys::msgNotHandled(); + } + + return presenter->handleAudioStopNotifiaction(notification->token) ? sys::msgNotHandled() : sys::msgHandled(); + } + +} // namespace app::music_player diff --git a/module-apps/application-music-player/AudioNotificationsHandler.hpp b/module-apps/application-music-player/AudioNotificationsHandler.hpp new file mode 100644 index 0000000000000000000000000000000000000000..517c7d6f3ed4f1fbdbb7bf4518c3afc09b900ccb --- /dev/null +++ b/module-apps/application-music-player/AudioNotificationsHandler.hpp @@ -0,0 +1,21 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#pragma once + +#include + +class AudioStopNotification; +namespace app::music_player +{ + class AudioNotificationsHandler + { + public: + explicit AudioNotificationsHandler(std::shared_ptr presenter); + + sys::MessagePointer handleAudioStopNotification(const AudioStopNotification *notification); + + private: + std::shared_ptr presenter; + }; +} // namespace app::music_player diff --git a/module-apps/application-music-player/CMakeLists.txt b/module-apps/application-music-player/CMakeLists.txt index 12978a398a8c0d1664c17fef6a17db0ac7828165..94caca52fedfa62435d1fdddf17593b4d4dffa1c 100644 --- a/module-apps/application-music-player/CMakeLists.txt +++ b/module-apps/application-music-player/CMakeLists.txt @@ -13,6 +13,8 @@ target_include_directories(application-music-player target_sources(application-music-player PRIVATE ApplicationMusicPlayer.cpp + AudioNotificationsHandler.cpp + models/SongContext.cpp models/SongsModel.cpp models/SongsRepository.cpp presenters/AudioOperations.cpp @@ -20,9 +22,10 @@ target_sources(application-music-player widgets/Action.cpp widgets/SongItem.cpp windows/MusicPlayerAllSongsWindow.cpp - windows/MusicPlayerEmptyWindow.cpp PRIVATE + AudioNotificationsHandler.hpp data/MusicPlayerStyle.hpp + models/SongContext.hpp models/SongsModel.hpp models/SongsRepository.hpp models/SongsModelInterface.hpp @@ -31,7 +34,6 @@ target_sources(application-music-player widgets/Action.hpp widgets/SongItem.hpp windows/MusicPlayerAllSongsWindow.hpp - windows/MusicPlayerEmptyWindow.hpp PUBLIC include/application-music-player/ApplicationMusicPlayer.hpp ) @@ -54,3 +56,7 @@ target_link_libraries(application-music-player apps-common module-audio ) + +if (${ENABLE_TESTS}) + add_subdirectory(tests) +endif() diff --git a/module-apps/application-music-player/data/MusicPlayerStyle.hpp b/module-apps/application-music-player/data/MusicPlayerStyle.hpp index d7369f6d5f8d7f8ffa4bde33fdec9a180a6ad71e..394cd41540568a21ce760b374d1750d252a804a6 100644 --- a/module-apps/application-music-player/data/MusicPlayerStyle.hpp +++ b/module-apps/application-music-player/data/MusicPlayerStyle.hpp @@ -101,13 +101,13 @@ namespace musicPlayerStyle constexpr uint32_t w = style::window::default_body_width; constexpr uint32_t h = 100; - constexpr uint32_t bold_text_h = 24; - constexpr uint32_t text_h = 22; + constexpr uint32_t bold_text_h = 33; + constexpr uint32_t text_h = 33; constexpr uint32_t duration_w = 50; - constexpr int32_t topMargin = 18; + constexpr int32_t topMargin = 16; constexpr int32_t leftMargin = 10; - constexpr int32_t rightMargin = 10; + constexpr int32_t rightMargin = 4; } // namespace songItem diff --git a/module-apps/application-music-player/models/SongContext.cpp b/module-apps/application-music-player/models/SongContext.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0e4f26f6570a2baa0a8ee9f5b3d2dffd2da6b8fc --- /dev/null +++ b/module-apps/application-music-player/models/SongContext.cpp @@ -0,0 +1,30 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md + +#include "SongContext.hpp" +#include + +namespace app::music_player +{ + void SongContext::clear() + { + currentSongState = SongState::NotPlaying; + currentFileToken = std::nullopt; + filePath = ""; + } + + bool SongContext::isValid() const + { + return (currentFileToken && currentFileToken->IsValid() && !filePath.empty()); + } + + bool SongContext::isPlaying() const + { + return isValid() && currentSongState == SongState::Playing; + } + + bool SongContext::isPaused() const + { + return isValid() && currentSongState == SongState::NotPlaying; + } +} // namespace app::music_player diff --git a/module-apps/application-music-player/models/SongContext.hpp b/module-apps/application-music-player/models/SongContext.hpp new file mode 100644 index 0000000000000000000000000000000000000000..f6e8d6fefdbf404a046df74ab3f631f2d5cfcb9d --- /dev/null +++ b/module-apps/application-music-player/models/SongContext.hpp @@ -0,0 +1,30 @@ +// Copyright (c) 2017-2021, Mudita Sp. z.o.o. All rights reserved. +// For licensing, see https://github.com/mudita/MuditaOS/LICENSE.md +#pragma once + +#include