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.annotation.NonNull;
import androidx.lifecycle.MutableLiveData; import androidx.lifecycle.MutableLiveData;
import android.util.Log; import android.util.Log;
import com.cappielloantonio.tempo.App; import com.cappielloantonio.tempo.App;
@ -204,37 +205,14 @@ public class AlbumRepository {
return albumInfo; return albumInfo;
} }
public void getInstantMix(AlbumID3 album, int count, MediaCallback callback) { public void getInstantMix(AlbumID3 album, int count, final MediaCallback callback) {
Log.d("AlbumRepository", "Attempting getInstantMix for AlbumID: " + album.getId()); Log.d("AlbumRepository", "Starting Instant Mix for album: " + album.getName());
App.getSubsonicClientInstance(false) new SongRepository().getInstantMix(album.getId(), count, songs -> {
.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<>();
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);
}
}
if (songs != null && !songs.isEmpty()) {
callback.onLoadMedia(songs); callback.onLoadMedia(songs);
} }
@Override
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
callback.onLoadMedia(new ArrayList<>());
}
}); });
} }
@ -248,7 +226,7 @@ public class AlbumRepository {
@Override @Override
public void onLoadYear(int last) { public void onLoadYear(int last) {
if (first != -1 && last != -1) { if (first != -1 && last != -1) {
List<Integer> decadeList = new ArrayList(); List<Integer> decadeList = new ArrayList<>();
int startDecade = first - (first % 10); int startDecade = first - (first % 10);
int lastDecade = last - (last % 10); int lastDecade = last - (last % 10);