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 +++++++++++++++ target/classes/musichub/business/MusicHub.class | Bin 12507 -> 13297 bytes target/classes/musichub/main/Main.class | Bin 10828 -> 11373 bytes target/classes/musichub/util/Policy.class | Bin 10981 -> 10860 bytes 5 files changed, 46 insertions(+) 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"); diff --git a/target/classes/musichub/business/MusicHub.class b/target/classes/musichub/business/MusicHub.class index 8614d25..42d7480 100644 Binary files a/target/classes/musichub/business/MusicHub.class and b/target/classes/musichub/business/MusicHub.class differ diff --git a/target/classes/musichub/main/Main.class b/target/classes/musichub/main/Main.class index 6a37d2d..d1f8ea2 100644 Binary files a/target/classes/musichub/main/Main.class and b/target/classes/musichub/main/Main.class differ diff --git a/target/classes/musichub/util/Policy.class b/target/classes/musichub/util/Policy.class index bec4189..4bf6b23 100644 Binary files a/target/classes/musichub/util/Policy.class and b/target/classes/musichub/util/Policy.class differ -- cgit v1.2.3