mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Randomized and limited the elements shown in the home in the starred sections
This commit is contained in:
parent
d9ce19c265
commit
b92310f40f
5 changed files with 26 additions and 16 deletions
|
|
@ -15,6 +15,7 @@ import com.cappielloantonio.play.util.MappingUtil;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
|
|
@ -57,7 +58,7 @@ public class AlbumRepository {
|
|||
return listLiveAlbums;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Album>> getStarredAlbums() {
|
||||
public MutableLiveData<List<Album>> getStarredAlbums(boolean random, int size) {
|
||||
MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
|
|
@ -66,13 +67,16 @@ public class AlbumRepository {
|
|||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
List<Album> albums = new ArrayList<>();
|
||||
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getStarred2() != null) {
|
||||
albums.addAll(MappingUtil.mapAlbum(response.body().getStarred2().getAlbums()));
|
||||
}
|
||||
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getStarred2().getAlbums()));
|
||||
|
||||
starredAlbums.setValue(albums);
|
||||
if (!random) {
|
||||
starredAlbums.setValue(albums);
|
||||
} else {
|
||||
Collections.shuffle(albums);
|
||||
starredAlbums.setValue(albums.subList(0, Math.min(size, albums.size())));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ public class ArtistRepository {
|
|||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||
public MutableLiveData<List<Artist>> getStarredArtists(boolean random, int size) {
|
||||
MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
|
|
@ -41,7 +41,13 @@ public class ArtistRepository {
|
|||
public void onResponse(@NonNull Call<SubsonicResponse> call, @NonNull Response<SubsonicResponse> response) {
|
||||
if (response.isSuccessful() && response.body() != null && response.body().getStarred2() != null) {
|
||||
List<Artist> artists = new ArrayList<>(MappingUtil.mapArtist(response.body().getStarred2().getArtists()));
|
||||
getArtistInfo(artists, starredArtists);
|
||||
|
||||
if (!random) {
|
||||
getArtistInfo(artists, starredArtists);
|
||||
} else {
|
||||
Collections.shuffle(artists);
|
||||
getArtistInfo(artists.subList(0, Math.min(size, artists.size())), starredArtists);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue