Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 33 additions & 45 deletions src/main/java/org/example/MyPod.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import java.util.ArrayList;
import java.util.List;

/**
* Huvudklassen för applikationen "MyPod".
* Denna klass bygger upp GUI:t (simulerar en iPod) och hanterar navigering.
Expand Down Expand Up @@ -196,7 +197,6 @@ private StackPane createClickWheel() {
StackPane wheel = new StackPane();
wheel.setPrefSize(200, 200);


// Det stora yttre hjulet
Circle outerWheel = new Circle(100);
outerWheel.getStyleClass().add("outer-wheel");
Expand All @@ -217,8 +217,8 @@ private StackPane createClickWheel() {
Label rew = new Label("⏮");
rew.getStyleClass().add("wheel-text");
rew.setId("rew-button");
/// NY KOD ////////////////////////////////////////////
// --- NY PLAY/PAUSE-FUNKTION ---

// Play/pause-funktion
Label playPauseLabel = new Label("▶/⏸");
playPauseLabel.getStyleClass().add("wheel-text-play");

Expand All @@ -227,7 +227,7 @@ private StackPane createClickWheel() {
playPauseLabel.setOnMouseClicked(e ->
playPauseFunction());

playPauseLabel.setOnKeyPressed(e ->{
playPauseLabel.setOnKeyPressed(e -> {
if (e.getCode() == KeyCode.SPACE) {
playPauseFunction();
}
Expand All @@ -237,21 +237,18 @@ private StackPane createClickWheel() {
return wheel;
}

private void playPauseFunction(){
if(mediaPlayer != null) {
if(mediaPlayer.getStatus() == MediaPlayer.Status.PLAYING) {
private void playPauseFunction() {
if (mediaPlayer != null) {
if (mediaPlayer.getStatus() == MediaPlayer.Status.PLAYING) {
mediaPlayer.pause();

} else {
} else {
mediaPlayer.play();

}
}

}



/**
* Hanterar tangentbordsnavigering (Upp, Ner, Enter, Escape).
*/
Expand All @@ -274,10 +271,10 @@ private void setupNavigation(Scene scene) {

if ("NowPlaying".equals(currentScreenName)) {
showMainMenu();
} else if ("ArtistSongs".equals(currentScreenName)) {
} else if ("ArtistAlbums".equals(currentScreenName)) {
showScreen("Artists");
} else if ("AlbumSongs".equals(currentScreenName)) {
showScreen("Albums");
showScreen("Artists");
} else if ("PlaylistSongs".equals(currentScreenName)) {
showScreen("Playlists");
}
Comment on lines +274 to 280
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

Navigation bug: showScreen("ArtistAlbums") is not handled.

The showScreen method (lines 400-422) only handles "Songs", "Artists", "Albums", and "Playlists" in its switch statement. Calling showScreen("ArtistAlbums") will result in an empty screen with just the title label and no menu items.

Additionally, this logic doesn't account for users who navigate to AlbumSongs from the main Albums menu—they should return to "Albums", not "ArtistAlbums".

Consider tracking the previous screen or using a navigation stack to handle back navigation correctly.

🔧 Suggested fix (minimal)

If you want to simply fix the immediate crash by going back to Artists:

             } else if ("AlbumSongs".equals(currentScreenName)) {
-                showScreen("ArtistAlbums");
+                showScreen("Artists");

For a more robust solution, consider implementing a navigation history stack to properly track where the user came from.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
} else if ("ArtistAlbums".equals(currentScreenName)) {
showScreen("Artists");
} else if ("AlbumSongs".equals(currentScreenName)) {
showScreen("Albums");
showScreen("ArtistAlbums");
} else if ("PlaylistSongs".equals(currentScreenName)) {
showScreen("Playlists");
}
} else if ("ArtistAlbums".equals(currentScreenName)) {
showScreen("Artists");
} else if ("AlbumSongs".equals(currentScreenName)) {
showScreen("Artists");
} else if ("PlaylistSongs".equals(currentScreenName)) {
showScreen("Playlists");
}
🤖 Prompt for AI Agents
In `@src/main/java/org/example/MyPod.java` around lines 274 - 280, The
back-navigation branch uses showScreen("ArtistAlbums") even though showScreen
only handles "Songs","Artists","Albums","Playlists", causing an empty screen;
update the back-logic so AlbumSongs returns to the correct parent (Albums when
navigated from Albums, Artists when from an artist) and/or add support for
"ArtistAlbums" in showScreen. Modify the navigation code around
currentScreenName and the showScreen method (referenced symbols:
currentScreenName, showScreen, "AlbumSongs", "ArtistAlbums") to either (a)
push/pop a simple navigation stack or track a previousScreen variable and call
showScreen(previousScreen) on back, or (b) extend showScreen to handle
"ArtistAlbums" and render its menu items; implement the minimal fix by changing
the AlbumSongs back branch to call showScreen("Albums") when the user came from
Albums or fall back to showScreen("Artists") when appropriate.

Expand Down Expand Up @@ -350,7 +347,6 @@ private void showVolumeOverlay() {
fadeOut.play();
});
volumeHideTimer.play();

}

/**
Expand Down Expand Up @@ -484,7 +480,9 @@ private void handleSelection(ObjectLabel selection) {
System.out.println("User selected: " + selection.getText());

if ("Artists".equals(currentScreenName)) {
showArtistSongs(selection);
showArtistAlbums(selection);
} else if ("ArtistAlbums".equals(currentScreenName)) {
showAlbumSongs(selection);
} else if ("Albums".equals(currentScreenName)) {
showAlbumSongs(selection);
} else if ("Playlists".equals(currentScreenName)) {
Expand Down Expand Up @@ -580,41 +578,36 @@ private void openMusicPlayer() {
itunesPlayList.showLibrary();
}

private void showArtistSongs(ObjectLabel selection) {
private void showArtistAlbums(ObjectLabel selection) {
screenContent.getChildren().clear();
menuLabels.clear();
selectedIndex = 0;

currentScreenName = "ArtistSongs";
currentScreenName = "ArtistAlbums";

Label titleLabel = new Label(selection.getText());
titleLabel.getStyleClass().add("screen-title");
screenContent.getChildren().add(titleLabel);

if (selection.object() == null) {
addMenuItem("No songs found");
addMenuItem("No albums found");
updateMenu();
return;
}

if (songs != null && !songs.isEmpty()) {
List<Song> artistSongs = songs.stream()
.filter(s -> s.getAlbum() != null &&
s.getAlbum().getArtist() != null &&
s.getAlbum().getArtist().getId().equals(selection.object().getId()))
.toList();
Artist artist = (Artist) selection.object();
List<Album> artistAlbums = albumRepo.findByArtist(artist);

if (!artistSongs.isEmpty()) {
artistSongs.forEach(this::addMenuItem);
} else {
addMenuItem("No songs found");
}
if (!artistAlbums.isEmpty()) {
artistAlbums.forEach(this::addMenuItem);
} else {
addMenuItem("No songs found");
addMenuItem("No albums found");
}

updateMenu();
}


private void showAlbumSongs(ObjectLabel selection) {
screenContent.getChildren().clear();
menuLabels.clear();
Expand All @@ -632,24 +625,20 @@ private void showAlbumSongs(ObjectLabel selection) {
return;
}

if (songs != null && !songs.isEmpty()) {
List<Song> albumSongs = songs.stream()
.filter(al -> al.getAlbum() != null &&
al.getAlbum().getId().equals(selection.object().getId())).toList();
Album album = (Album) selection.object();
List<Song> albumSongs = songRepo.findByAlbum(album);

if (!albumSongs.isEmpty()) {
albumSongs.forEach(this::addMenuItem);
} else {
addMenuItem("No songs found");
}
if (!albumSongs.isEmpty()) {
albumSongs.forEach(this::addMenuItem);
} else {
addMenuItem("No songs found");
}

updateMenu();
}

private void showNowPlaying(ObjectLabel selection) {

private void showNowPlaying(ObjectLabel selection) {
screenContent.getChildren().clear();
menuLabels.clear();
selectedIndex = 0;
Expand Down Expand Up @@ -681,10 +670,10 @@ private void showNowPlaying(ObjectLabel selection) {
albumArtView.setPreserveRatio(true);
albumArtView.setSmooth(true);
albumArtView.setStyle("""
-fx-border-color: #ccc;
-fx-border-width: 1;
-fx-background-color: white;
""");
-fx-border-color: #ccc;
-fx-border-width: 1;
-fx-background-color: white;
""");

Label titleLabel = new Label(selection.getText());
titleLabel.getStyleClass().add("now-playing-title");
Expand Down Expand Up @@ -782,7 +771,6 @@ private void ensureVolumeBarExists() {
}
}


/**
* Initierar databasen och hämtar all data.
* OBS: Denna körs i en bakgrundstråd (via Task i start-metoden).
Expand Down