From a187ba1e75456525d2cc9103dbf12a064b805162 Mon Sep 17 00:00:00 2001 From: eddyizm Date: Sat, 27 Sep 2025 22:37:30 -0700 Subject: [PATCH] fix: moved api call back to artist repository after losing the thread. --- .../tempo/repository/ArtistRepository.java | 42 ++++++++++++++----- 1 file changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/tempo/repository/ArtistRepository.java b/app/src/main/java/com/cappielloantonio/tempo/repository/ArtistRepository.java index 71b43fa9..4e06fad7 100644 --- a/app/src/main/java/com/cappielloantonio/tempo/repository/ArtistRepository.java +++ b/app/src/main/java/com/cappielloantonio/tempo/repository/ArtistRepository.java @@ -31,16 +31,38 @@ public class ArtistRepository { public void getArtistAllSongs(String artistId, ArtistSongsCallback callback) { Log.d("ArtistSync", "Getting albums for artist: " + artistId); - // Use AlbumRepository to get all albums by this artist - albumRepository.getArtistAlbums(artistId).observeForever(albums -> { - Log.d("ArtistSync", "Got albums: " + (albums != null ? albums.size() : 0)); - if (albums != null && !albums.isEmpty()) { - fetchAllAlbumSongsWithCallback(albums, callback); - } else { - Log.d("ArtistSync", "No albums found"); - callback.onSongsCollected(new ArrayList<>()); - } - }); + // Get the artist info first, which contains the albums + App.getSubsonicClientInstance(false) + .getBrowsingClient() + .getArtist(artistId) + .enqueue(new Callback() { + @Override + public void onResponse(@NonNull Call call, @NonNull Response response) { + if (response.isSuccessful() && response.body() != null && + response.body().getSubsonicResponse().getArtist() != null && + response.body().getSubsonicResponse().getArtist().getAlbums() != null) { + + List albums = response.body().getSubsonicResponse().getArtist().getAlbums(); + Log.d("ArtistSync", "Got albums directly: " + albums.size()); + + if (!albums.isEmpty()) { + fetchAllAlbumSongsWithCallback(albums, callback); + } else { + Log.d("ArtistSync", "No albums found in artist response"); + callback.onSongsCollected(new ArrayList<>()); + } + } else { + Log.d("ArtistSync", "Failed to get artist info"); + callback.onSongsCollected(new ArrayList<>()); + } + } + + @Override + public void onFailure(@NonNull Call call, @NonNull Throwable t) { + Log.d("ArtistSync", "Error getting artist info: " + t.getMessage()); + callback.onSongsCollected(new ArrayList<>()); + } + }); } private void fetchAllAlbumSongsWithCallback(List albums, ArtistSongsCallback callback) {