wip: refactor album repo to use the song repo instant mix

This commit is contained in:
eddyizm 2025-12-26 22:08:07 -08:00
parent 3c1975f6bf
commit 2624f396e5
No known key found for this signature in database
GPG key ID: CF5F671829E8158A

View file

@ -2,6 +2,7 @@ package com.cappielloantonio.tempo.repository;
import androidx.annotation.NonNull;
import androidx.lifecycle.MutableLiveData;
import android.util.Log;
import com.cappielloantonio.tempo.App;
@ -204,38 +205,15 @@ public class AlbumRepository {
return albumInfo;
}
public void getInstantMix(AlbumID3 album, int count, MediaCallback callback) {
Log.d("AlbumRepository", "Attempting getInstantMix for AlbumID: " + album.getId());
App.getSubsonicClientInstance(false)
.getBrowsingClient()
.getSimilarSongs2(album.getId(), count)
.enqueue(new Callback<ApiResponse>() {
@Override
public void onResponse(@NonNull Call<ApiResponse> call, @NonNull Response<ApiResponse> response) {
List<Child> songs = new ArrayList<>();
public void getInstantMix(AlbumID3 album, int count, final MediaCallback callback) {
Log.d("AlbumRepository", "Starting Instant Mix for album: " + album.getName());
if (response.isSuccessful()
&& response.body() != null
&& response.body().getSubsonicResponse().getSimilarSongs2() != null) {
List<Child> similarSongs = response.body().getSubsonicResponse().getSimilarSongs2().getSongs();
if (similarSongs == null) {
Log.w("AlbumRepository", "API successful but 'songs' list was NULL for AlbumID: " + album.getId());
} else {
songs.addAll(similarSongs);
}
}
new SongRepository().getInstantMix(album.getId(), count, songs -> {
callback.onLoadMedia(songs);
}
@Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
callback.onLoadMedia(new ArrayList<>());
}
});
if (songs != null && !songs.isEmpty()) {
callback.onLoadMedia(songs);
}
});
}
public MutableLiveData<List<Integer>> getDecades() {
@ -248,7 +226,7 @@ public class AlbumRepository {
@Override
public void onLoadYear(int last) {
if (first != -1 && last != -1) {
List<Integer> decadeList = new ArrayList();
List<Integer> decadeList = new ArrayList<>();
int startDecade = first - (first % 10);
int lastDecade = last - (last % 10);