From 2b592b4986b92c85150ecb9d08a521e6391cc160 Mon Sep 17 00:00:00 2001 From: manthole <67294267+manthole@users.noreply.github.com> Date: Sun, 27 Jun 2021 23:10:38 +0200 Subject: Add new feature - display playlist --- src/main/java/musichub/business/MusicHub.java | 28 +++++++++++++++++++++++++++ src/main/java/musichub/main/Main.java | 18 +++++++++++++++++ 2 files changed, 46 insertions(+) (limited to 'src/main') diff --git a/src/main/java/musichub/business/MusicHub.java b/src/main/java/musichub/business/MusicHub.java index 660f0f8..f6805b6 100644 --- a/src/main/java/musichub/business/MusicHub.java +++ b/src/main/java/musichub/business/MusicHub.java @@ -359,5 +359,33 @@ public class MusicHub { this.getAudioElement(searchResult, searchResult.get(0).getTitle()); } } + public String getPlayListsTitles() { + StringBuilder titleList = new StringBuilder(); + for (PlayList pl : playlists) + titleList.append(pl.getTitle()).append("\n"); + return titleList.toString(); + } + + public List getPlayListSongs(String playListTitle) throws NoPlayListFoundException { + PlayList thePlayList = null; + ArrayList songsInPlayList = new ArrayList<>(); + for (PlayList pl : playlists) { + if (pl.getTitle().equalsIgnoreCase(playListTitle)) { + thePlayList = pl; + break; + } + } + if (thePlayList == null) throw new NoPlayListFoundException("No playlist with this title in the MusicHub!"); + + List songIDs = thePlayList.getElements(); + for (UUID id : songIDs) + for (AudioElement el : elements) { + if (el instanceof Song) { + if (el.getUUID().equals(id)) songsInPlayList.add(el); + } + } + return songsInPlayList; + + } } \ No newline at end of file diff --git a/src/main/java/musichub/main/Main.java b/src/main/java/musichub/main/Main.java index bbcae79..2394ce6 100644 --- a/src/main/java/musichub/main/Main.java +++ b/src/main/java/musichub/main/Main.java @@ -264,6 +264,23 @@ public class Main { System.out.println("Type h for available commands"); choice = scan.nextLine(); break; + case 'm': + //songs of a playlist + System.out.println("Songs of a playlist will be displayed; enter the playlist name, available playlists are:"); + System.out.println(theHub.getPlayListsTitles()); + + playListTitle = scan.nextLine(); + try { + List songs = theHub.getPlayListSongs(playListTitle); + System.out.println(theHub.getPlayListSongs(playListTitle)); + String song = scan.nextLine(); + theHub.getAudioElement(songs, song); + } catch (NoPlayListFoundException ex) { + System.out.println("No playlist found with the requested title " + ex.getMessage()); + } + printAvailableCommands(); + choice = scan.nextLine(); + break; default: break; @@ -283,6 +300,7 @@ public class Main { System.out.println("+: add a song to an album"); System.out.println("l: add a new audiobook"); System.out.println("p: create a new playlist from existing songs and audio books"); + System.out.println("m: display songs of a playlist"); System.out.println("-: delete an existing playlist"); System.out.println("s: save elements, albums, playlists"); System.out.println("o: consult the app logs"); -- cgit v1.2.3 ing wrong input for songs' length at creation (command c)Clyhtsuriva2-7/+16 2021-06-28Changed the type of switch used in AudioElement.javaClyhtsuriva1-24/+14 2021-06-28Change out to err for the path verification error message.Clyhtsuriva1-1/+2 2021-06-28Added a break at the end of the r command.Clyhtsuriva1-0/+1 2021-06-27mvn packageClyhtsuriva11-6/+142 2021-06-27mvn packageClyhtsuriva26-301/+313 2021-06-27Fixing lower case issue following acceptance testClyhtsuriva1-9/+3 2021-06-27Fixing conflictsmanthole2-0/+139 2021-06-27Latest maven, jacoco and javadoc filesClyhtsuriva47-313/+822 2021-06-27Catch exception related to search functionalitysaid belhadj4-3/+11 2021-06-27Delete TEST-musichub.business.CategoryTest.xmlSaid Belhadj1-58/+0 2021-06-27Add unit test for Category and Languagesaid belhadj4-0/+164 2021-06-27Update search functionalitysaid belhadj2-0/+8 2021-06-27Added an extension check for songs and covered it with a test.Clyhtsuriva65-77/+92 2021-06-27Fix : Javadoc missingClyhtsuriva80-0/+8465 2021-06-27PlayList class covered at 84%.Clyhtsuriva14-78/+117 2021-06-27Song class fully covered.Clyhtsuriva13-49/+96 2021-06-27Starting Song testsClyhtsuriva17-59/+119 2021-06-27Changed the log type for the JUnit test of LogHandlerClyhtsuriva5-26/+4 2021-06-27XMLHandler tests covered at 91%Clyhtsuriva93-7962/+82