mirror of
https://github.com/antebudimir/tempus.git
synced 2026-04-15 16:27:26 +00:00
wip: refactor album repo to use the song repo instant mix
This commit is contained in:
parent
3c1975f6bf
commit
2624f396e5
1 changed files with 9 additions and 31 deletions
|
|
@ -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,38 +205,15 @@ 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)
|
|
||||||
.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()
|
new SongRepository().getInstantMix(album.getId(), count, songs -> {
|
||||||
&& 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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.onLoadMedia(songs);
|
if (songs != null && !songs.isEmpty()) {
|
||||||
}
|
callback.onLoadMedia(songs);
|
||||||
|
}
|
||||||
@Override
|
});
|
||||||
public void onFailure(@NonNull Call<ApiResponse> call, @NonNull Throwable t) {
|
|
||||||
callback.onLoadMedia(new ArrayList<>());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MutableLiveData<List<Integer>> getDecades() {
|
public MutableLiveData<List<Integer>> getDecades() {
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue