diff --git a/approot/artists.xml b/approot/artists.xml index b5ed55b3..83d44747 100644 --- a/approot/artists.xml +++ b/approot/artists.xml @@ -13,9 +13,7 @@ ${artists} -
- ${show-more class="btn-primary Lms-show-more"} -
+ ${loading-indicator class="Lms-horizontal-center Lms-loading-indicator"} diff --git a/approot/messages.xml b/approot/messages.xml index 45e0280f..ac96275f 100644 --- a/approot/messages.xml +++ b/approot/messages.xml @@ -9,6 +9,7 @@ Discard Cancel Create +Loading... Login Logout Not a directory @@ -117,7 +118,6 @@ Recently added Recently played Albums -Show more Tracks Type Value diff --git a/approot/messages_fr.xml b/approot/messages_fr.xml index e9dc699a..d28c0b35 100644 --- a/approot/messages_fr.xml +++ b/approot/messages_fr.xml @@ -9,6 +9,7 @@ Annuler Annuler Créer +Chargement... Login Quitter N'est pas un répertoire @@ -117,7 +118,6 @@ Ajoutés récemment Joués récemment Albums -Voir plus Pistes Type Valeur diff --git a/approot/playqueue.xml b/approot/playqueue.xml index e4e8ebcd..3fb28e46 100644 --- a/approot/playqueue.xml +++ b/approot/playqueue.xml @@ -16,9 +16,7 @@

${nb-tracks}

${entries} -
- ${show-more class="btn-primary Lms-show-more"} -
+ ${loading-indicator class="Lms-horizontal-center Lms-loading-indicator"}
diff --git a/approot/releases.xml b/approot/releases.xml index 3ccc42f5..288ac0a0 100644 --- a/approot/releases.xml +++ b/approot/releases.xml @@ -11,9 +11,7 @@
${releases}
-
- ${show-more class="btn-primary Lms-show-more"} -
+ ${loading-indicator class="Lms-horizontal-center Lms-loading-indicator"} diff --git a/approot/templates.xml b/approot/templates.xml index 78d826d1..2145b7f7 100644 --- a/approot/templates.xml +++ b/approot/templates.xml @@ -56,4 +56,9 @@ ${player class="Lms-player"} + + + ${tr:Lms.loading} + + diff --git a/approot/tracks.xml b/approot/tracks.xml index fe402479..ff664056 100644 --- a/approot/tracks.xml +++ b/approot/tracks.xml @@ -12,9 +12,7 @@ ${play-btn}${add-btn} ${tracks} -
- ${show-more class="btn-primary Lms-show-more"} -
+ ${loading-indicator class="Lms-horizontal-center Lms-loading-indicator"} diff --git a/docroot/css/lms.css b/docroot/css/lms.css index 3fecc982..b47302bb 100644 --- a/docroot/css/lms.css +++ b/docroot/css/lms.css @@ -259,6 +259,11 @@ a.Lms-artistname:hover, a.Lms-artistname:focus { justify-content: center; } +.Lms-loading-indicator { + margin-top: 8px; + margin-bottom: 8px; +} + .Lms-navbar-search { max-width: 175px; padding-top: 7.5px; @@ -478,9 +483,4 @@ a.Lms-releasename:hover, a.Lms-releasename:focus { padding-bottom: 100%; } -.Lms-show-more { - margin-top: 8px; - margin-bottom: 8px; -} - diff --git a/src/lms/CMakeLists.txt b/src/lms/CMakeLists.txt index 40fb59bf..beb8ac4a 100644 --- a/src/lms/CMakeLists.txt +++ b/src/lms/CMakeLists.txt @@ -15,6 +15,7 @@ add_executable(lms ui/admin/UserView.cpp ui/admin/UsersView.cpp ui/common/AuthModeModel.cpp + ui/common/LoadingIndicator.cpp ui/common/Validators.cpp ui/explore/ArtistListHelpers.cpp ui/explore/ArtistView.cpp diff --git a/src/lms/ui/LmsApplication.cpp b/src/lms/ui/LmsApplication.cpp index 86fc7a15..250ceaab 100644 --- a/src/lms/ui/LmsApplication.cpp +++ b/src/lms/ui/LmsApplication.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include diff --git a/src/lms/ui/PlayQueue.cpp b/src/lms/ui/PlayQueue.cpp index 04a895b7..f7c14424 100644 --- a/src/lms/ui/PlayQueue.cpp +++ b/src/lms/ui/PlayQueue.cpp @@ -32,6 +32,7 @@ #include "utils/Service.hpp" #include "utils/String.hpp" +#include "common/LoadingIndicator.hpp" #include "resource/ImageResource.hpp" #include "LmsApplication.hpp" #include "MediaPlayer.hpp" @@ -66,10 +67,12 @@ PlayQueue::PlayQueue() _entriesContainer = bindNew("entries"); - _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.show-more")); - _showMore->setHidden(true); - _showMore->clicked().connect([=] + _loadingIndicator = bindWidget("loading-indicator", createLoadingIndicator()); + _loadingIndicator->scrollVisibilityChanged().connect([this](bool visible) { + if (!visible) + return; + addSome(); updateCurrentTrack(true); }); @@ -202,7 +205,7 @@ PlayQueue::clearTracks() getTrackList().modify()->clear(); } - _showMore->setHidden(true); + _loadingIndicator->setHidden(true); _entriesContainer->clear(); updateInfo(); } @@ -447,7 +450,7 @@ PlayQueue::addSome() } - _showMore->setHidden(static_cast(_entriesContainer->count()) >= tracklist->getCount()); + _loadingIndicator->setHidden(static_cast(_entriesContainer->count()) >= tracklist->getCount()); } void diff --git a/src/lms/ui/PlayQueue.hpp b/src/lms/ui/PlayQueue.hpp index a2088ecd..ed417656 100644 --- a/src/lms/ui/PlayQueue.hpp +++ b/src/lms/ui/PlayQueue.hpp @@ -22,7 +22,6 @@ #include #include -#include #include #include @@ -84,7 +83,7 @@ class PlayQueue : public Wt::WTemplate bool _mediaPlayerSettingsLoaded {}; Database::IdType _tracklistId {}; Wt::WContainerWidget* _entriesContainer {}; - Wt::WPushButton* _showMore {}; + Wt::WTemplate* _loadingIndicator {}; Wt::WText* _nbTracks {}; Wt::WText* _repeatBtn {}; Wt::WText* _radioBtn {}; diff --git a/src/lms/ui/common/LoadingIndicator.cpp b/src/lms/ui/common/LoadingIndicator.cpp new file mode 100644 index 00000000..d3063f1a --- /dev/null +++ b/src/lms/ui/common/LoadingIndicator.cpp @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2020 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#include "LoadingIndicator.hpp" + +namespace UserInterface +{ + std::unique_ptr + createLoadingIndicator() + { + auto res {std::make_unique(Wt::WString::tr("Lms.LoadingIndicator.template"))}; + + res->addFunction("tr", &Wt::WTemplate::Functions::tr); + res->setScrollVisibilityMargin(200); + res->setScrollVisibilityEnabled(true); + + return res; + } +} + diff --git a/src/lms/ui/common/LoadingIndicator.hpp b/src/lms/ui/common/LoadingIndicator.hpp new file mode 100644 index 00000000..e118f567 --- /dev/null +++ b/src/lms/ui/common/LoadingIndicator.hpp @@ -0,0 +1,28 @@ +/* + * Copyright (C) 2020 Emeric Poupon + * + * This file is part of LMS. + * + * LMS is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * LMS is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with LMS. If not, see . + */ + +#pragma once + +#include + +namespace UserInterface +{ + std::unique_ptr createLoadingIndicator(); +} + diff --git a/src/lms/ui/explore/ArtistsView.cpp b/src/lms/ui/explore/ArtistsView.cpp index a2fae1f5..5214c142 100644 --- a/src/lms/ui/explore/ArtistsView.cpp +++ b/src/lms/ui/explore/ArtistsView.cpp @@ -29,6 +29,7 @@ #include "database/TrackList.hpp" #include "utils/Logger.hpp" +#include "common/LoadingIndicator.hpp" #include "ArtistListHelpers.hpp" #include "LmsApplication.hpp" #include "Filters.hpp" @@ -76,9 +77,12 @@ Artists::Artists(Filters* filters) _container = bindNew("artists"); - _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.show-more")); - _showMore->clicked().connect([=] + _loadingIndicator = bindWidget("loading-indicator", createLoadingIndicator()); + _loadingIndicator->scrollVisibilityChanged().connect([this](bool visible) { + if (!visible) + return; + addSome(); }); @@ -203,7 +207,7 @@ Artists::addSome() _container->addWidget(ArtistListHelpers::createEntry(artist)); } - _showMore->setHidden(!moreResults); + _loadingIndicator->setHidden(!moreResults); } } // namespace UserInterface diff --git a/src/lms/ui/explore/ArtistsView.hpp b/src/lms/ui/explore/ArtistsView.hpp index 546290eb..4169f74d 100644 --- a/src/lms/ui/explore/ArtistsView.hpp +++ b/src/lms/ui/explore/ArtistsView.hpp @@ -24,9 +24,7 @@ #include #include -#include #include -#include #include "database/Types.hpp" @@ -67,15 +65,15 @@ class Artists : public Wt::WTemplate { {Mode::Random, batchSize * 4}, {Mode::RecentlyPlayed, batchSize * 4}, - {Mode::RecentlyAdded, batchSize * 2}, - {Mode::MostPlayed, batchSize * 2}, + {Mode::RecentlyAdded, batchSize * 4}, + {Mode::MostPlayed, batchSize * 4}, {Mode::All, batchSize * 50}, }; Mode _mode {defaultMode}; std::vector _randomArtists; Filters* _filters {}; - Wt::WPushButton* _showMore {}; + Wt::WTemplate* _loadingIndicator {}; Wt::WContainerWidget* _container {}; Wt::WComboBox* _linkType {}; }; diff --git a/src/lms/ui/explore/ReleasesView.cpp b/src/lms/ui/explore/ReleasesView.cpp index a6a4e254..8489a1f8 100644 --- a/src/lms/ui/explore/ReleasesView.cpp +++ b/src/lms/ui/explore/ReleasesView.cpp @@ -32,6 +32,7 @@ #include "utils/Logger.hpp" #include "utils/String.hpp" +#include "common/LoadingIndicator.hpp" #include "resource/ImageResource.hpp" #include "ReleaseListHelpers.hpp" #include "Filters.hpp" @@ -79,9 +80,12 @@ _filters {filters} _container = bindNew("releases"); - _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.show-more")); - _showMore->clicked().connect([this] + _loadingIndicator = bindWidget("loading-indicator", createLoadingIndicator()); + _loadingIndicator->scrollVisibilityChanged().connect([this](bool visible) { + if (!visible) + return; + addSome(); }); @@ -118,7 +122,7 @@ Releases::addSome() _container->addWidget(ReleaseListHelpers::createEntry(release)); } - _showMore->setHidden(!moreResults); + _loadingIndicator->setHidden(!moreResults); } std::vector diff --git a/src/lms/ui/explore/ReleasesView.hpp b/src/lms/ui/explore/ReleasesView.hpp index e873d2f4..21f9a5dc 100644 --- a/src/lms/ui/explore/ReleasesView.hpp +++ b/src/lms/ui/explore/ReleasesView.hpp @@ -22,7 +22,6 @@ #include #include -#include #include #include "database/Types.hpp" @@ -57,19 +56,21 @@ class Releases : public Wt::WTemplate void refreshView(); void refreshView(Mode mode); + void addSome(); std::vector> getReleases(std::optional range, bool& moreResults); std::vector> getRandomReleases(std::optional range, bool& moreResults); std::vector getAllReleases(); static constexpr Mode defaultMode {Mode::Random}; - static constexpr std::size_t batchSize {18}; + static constexpr std::size_t maxItemsPerLine {6}; + static constexpr std::size_t batchSize {maxItemsPerLine * 3}; static inline std::unordered_map> maxItemsPerMode { - {Mode::Random, batchSize * 6}, - {Mode::RecentlyPlayed, batchSize * 3}, - {Mode::RecentlyAdded, batchSize * 2}, - {Mode::MostPlayed, batchSize * 2}, + {Mode::Random, batchSize * 10}, + {Mode::RecentlyPlayed, batchSize * 10}, + {Mode::RecentlyAdded, batchSize * 10}, + {Mode::MostPlayed, batchSize * 10}, {Mode::All, batchSize * 30}, }; @@ -77,7 +78,7 @@ class Releases : public Wt::WTemplate Filters* _filters {}; std::vector _randomReleases; Wt::WContainerWidget* _container {}; - Wt::WPushButton* _showMore {}; + Wt::WTemplate* _loadingIndicator {}; }; } // namespace UserInterface diff --git a/src/lms/ui/explore/TracksView.cpp b/src/lms/ui/explore/TracksView.cpp index db852f48..701c7ff0 100644 --- a/src/lms/ui/explore/TracksView.cpp +++ b/src/lms/ui/explore/TracksView.cpp @@ -34,6 +34,7 @@ #include "resource/ImageResource.hpp" +#include "common/LoadingIndicator.hpp" #include "Filters.hpp" #include "LmsApplication.hpp" #include "MediaPlayer.hpp" @@ -83,9 +84,12 @@ _filters {filters} _tracksContainer = bindNew("tracks"); - _showMore = bindNew("show-more", Wt::WString::tr("Lms.Explore.show-more")); - _showMore->clicked().connect([this] + _loadingIndicator = bindWidget("loading-indicator", createLoadingIndicator()); + _loadingIndicator->scrollVisibilityChanged().connect([this](bool visible) { + if (!visible) + return; + addSome(); }); @@ -206,7 +210,7 @@ Tracks::addSome() _tracksContainer->addWidget(TrackListHelpers::createEntry(track)); } - _showMore->setHidden(!moreResults); + _loadingIndicator->setHidden(!moreResults); } } // namespace UserInterface diff --git a/src/lms/ui/explore/TracksView.hpp b/src/lms/ui/explore/TracksView.hpp index 430f8a41..eba94b06 100644 --- a/src/lms/ui/explore/TracksView.hpp +++ b/src/lms/ui/explore/TracksView.hpp @@ -22,8 +22,6 @@ #include #include -#include -#include #include #include "database/Types.hpp" @@ -78,8 +76,7 @@ class Tracks : public Wt::WTemplate Filters* _filters {}; std::vector _randomTracks; Wt::WContainerWidget* _tracksContainer {}; - Wt::WPushButton* _showMore {}; - Wt::WLineEdit* _search {}; + Wt::WTemplate* _loadingIndicator {}; }; } // namespace UserInterface