From fb48e3557b6aabb7bdd8bdb8473e2551d72041d7 Mon Sep 17 00:00:00 2001 From: Commenter Date: Fri, 25 Aug 2023 12:38:06 -0500 Subject: [PATCH] Music: Replace placeholder text Replaces the dev placeholder with waiting text, ensures it won't show 00:00/00:00 for consistency, and allows the waiting text to reappear when data becomes blank --- src/components/ble/MusicService.h | 4 ++-- src/displayapp/screens/Music.cpp | 33 +++++++++++++++++++++++-------- src/displayapp/screens/Music.h | 6 ++++++ 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/components/ble/MusicService.h b/src/components/ble/MusicService.h index f4b902fe..40b26877 100644 --- a/src/components/ble/MusicService.h +++ b/src/components/ble/MusicService.h @@ -70,9 +70,9 @@ namespace Pinetime { uint16_t eventHandle {}; - std::string artistName {"Waiting for"}; + std::string artistName {}; std::string albumName {}; - std::string trackName {"track information.."}; + std::string trackName {}; bool playing {false}; diff --git a/src/displayapp/screens/Music.cpp b/src/displayapp/screens/Music.cpp index 0763da0f..ad5d03ec 100644 --- a/src/displayapp/screens/Music.cpp +++ b/src/displayapp/screens/Music.cpp @@ -105,7 +105,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { txtTrackDuration = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(txtTrackDuration, LV_LABEL_LONG_SROLL); lv_obj_align(txtTrackDuration, nullptr, LV_ALIGN_IN_TOP_LEFT, 12, 20); - lv_label_set_text_static(txtTrackDuration, "--:--/--:--"); + lv_label_set_text_static(txtTrackDuration, lengthDefault); lv_label_set_align(txtTrackDuration, LV_ALIGN_IN_LEFT_MID); lv_obj_set_width(txtTrackDuration, LV_HOR_RES); @@ -117,7 +117,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { lv_obj_align(txtArtist, nullptr, LV_ALIGN_IN_LEFT_MID, 12, MIDDLE_OFFSET + 1 * FONT_HEIGHT); lv_label_set_align(txtArtist, LV_ALIGN_IN_LEFT_MID); lv_obj_set_width(txtArtist, LV_HOR_RES - 12); - lv_label_set_text_static(txtArtist, "Artist Name"); + lv_label_set_text_static(txtArtist, artistDefault); txtTrack = lv_label_create(lv_scr_act(), nullptr); lv_label_set_long_mode(txtTrack, LV_LABEL_LONG_SROLL_CIRC); @@ -125,7 +125,7 @@ Music::Music(Pinetime::Controllers::MusicService& music) : musicService(music) { lv_label_set_align(txtTrack, LV_ALIGN_IN_LEFT_MID); lv_obj_set_width(txtTrack, LV_HOR_RES - 12); - lv_label_set_text_static(txtTrack, "This is a very long getTrack name"); + lv_label_set_text_static(txtTrack, trackDefault); /** Init animation */ imgDisc = lv_img_create(lv_scr_act(), nullptr); @@ -150,14 +150,24 @@ Music::~Music() { } void Music::Refresh() { - if (artist != musicService.getArtist()) { + if (musicDidExist != musicExists || artist != musicService.getArtist()) { artist = musicService.getArtist(); - lv_label_set_text(txtArtist, artist.data()); + + if (musicExists) { + lv_label_set_text(txtArtist, artist.data()); + } else { + lv_label_set_text_static(txtArtist, artistDefault); + } } - if (track != musicService.getTrack()) { + if (musicDidExist != musicExists || track != musicService.getTrack()) { track = musicService.getTrack(); - lv_label_set_text(txtTrack, track.data()); + + if (musicExists) { + lv_label_set_text(txtTrack, track.data()); + } else { + lv_label_set_text_static(txtTrack, trackDefault); + } } if (album != musicService.getAlbum()) { @@ -173,8 +183,13 @@ void Music::Refresh() { UpdateLength(); } + if (musicDidExist != musicExists) { + musicDidExist = musicExists; + } + if (totalLength != musicService.getTrackLength()) { totalLength = musicService.getTrackLength(); + musicExists = totalLength > 0; UpdateLength(); } @@ -202,7 +217,9 @@ void Music::Refresh() { } void Music::UpdateLength() { - if (totalLength > (99 * 60 * 60)) { + if (!musicExists) { + lv_label_set_text_static(txtTrackDuration, lengthDefault); + } else if (totalLength > (99 * 60 * 60)) { lv_label_set_text_static(txtTrackDuration, "Inf/Inf"); } else if (totalLength > (99 * 60)) { lv_label_set_text_fmt(txtTrackDuration, diff --git a/src/displayapp/screens/Music.h b/src/displayapp/screens/Music.h index 847c6e74..b1b5ff15 100644 --- a/src/displayapp/screens/Music.h +++ b/src/displayapp/screens/Music.h @@ -68,6 +68,12 @@ namespace Pinetime { std::string album; std::string track; + bool musicExists = false; + bool musicDidExist = false; + static constexpr const char* artistDefault = "Waiting for"; + static constexpr const char* trackDefault = "track information.."; + static constexpr const char* lengthDefault = "--:--/--:--"; + /** Total length in seconds */ int totalLength = 0; /** Current position in seconds */