mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-02 10:23:33 +00:00
Fix artist cover visualization
This commit is contained in:
parent
80f30aa41a
commit
c55f639368
21 changed files with 157 additions and 334 deletions
|
|
@ -26,13 +26,15 @@ public class AlbumRepository {
|
|||
private MutableLiveData<List<Album>> listLiveRecentlyAddedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveMostPlayedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveRecentlyPlayedAlbums = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Album>> listLiveRandomAlbums = new MutableLiveData<>();
|
||||
|
||||
public AlbumRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public LiveData<List<Album>> getListLiveAlbums(String type, int size) {
|
||||
App.getSubsonicClientInstance(application, false).getAlbumSongListClient()
|
||||
public LiveData<List<Album>> getAlbums(String type, int size) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getAlbumList2(type, size, 0)
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
|
|
@ -49,6 +51,9 @@ public class AlbumRepository {
|
|||
case "recent":
|
||||
listLiveRecentlyPlayedAlbums.setValue(albums);
|
||||
break;
|
||||
case "random":
|
||||
listLiveRandomAlbums.setValue(albums);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +70,8 @@ public class AlbumRepository {
|
|||
return listLiveMostPlayedAlbums;
|
||||
case "recent":
|
||||
return listLiveRecentlyPlayedAlbums;
|
||||
case "random":
|
||||
return listLiveRandomAlbums;
|
||||
default:
|
||||
return new MutableLiveData<>();
|
||||
}
|
||||
|
|
@ -73,7 +80,8 @@ public class AlbumRepository {
|
|||
public MutableLiveData<List<Album>> getStarredAlbums() {
|
||||
MutableLiveData<List<Album>> starredAlbums = new MutableLiveData<>();
|
||||
|
||||
App.getSubsonicClientInstance(application, false).getAlbumSongListClient()
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getStarred2()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -6,11 +6,14 @@ import androidx.lifecycle.MutableLiveData;
|
|||
|
||||
import com.cappielloantonio.play.App;
|
||||
import com.cappielloantonio.play.model.Artist;
|
||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||
import com.cappielloantonio.play.util.MappingUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import retrofit2.Call;
|
||||
|
|
@ -20,21 +23,24 @@ import retrofit2.Response;
|
|||
public class ArtistRepository {
|
||||
private Application application;
|
||||
|
||||
private MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>();
|
||||
private MutableLiveData<List<Artist>> starredArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Artist>> listLiveRandomArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
private MutableLiveData<List<Artist>> listLiveArtists = new MutableLiveData<>(new ArrayList<>());
|
||||
|
||||
public ArtistRepository(Application application) {
|
||||
this.application = application;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getStarredArtists() {
|
||||
App.getSubsonicClientInstance(application, false).getAlbumSongListClient()
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getAlbumSongListClient()
|
||||
.getStarred2()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
List<Artist> artists = new ArrayList<>(MappingUtil.mapArtist(response.body().getStarred2().getArtists()));
|
||||
starredArtists.setValue(artists);
|
||||
getArtistInfo(artists, starredArtists);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -45,4 +51,61 @@ public class ArtistRepository {
|
|||
|
||||
return starredArtists;
|
||||
}
|
||||
|
||||
public MutableLiveData<List<Artist>> getArtists(boolean random, int size) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getArtists()
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||
List<Artist> artists = new ArrayList<>();
|
||||
|
||||
for (IndexID3 index : response.body().getArtists().getIndices()) {
|
||||
artists.addAll(MappingUtil.mapArtist(index.getArtists()));
|
||||
}
|
||||
|
||||
listLiveArtists.setValue(artists);
|
||||
Collections.shuffle(artists);
|
||||
getArtistInfo(artists.subList(0, artists.size() / size > 0 ? size : artists.size()), listLiveRandomArtists);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
}
|
||||
});
|
||||
|
||||
if (random) {
|
||||
return listLiveRandomArtists;
|
||||
} else {
|
||||
return listLiveArtists;
|
||||
}
|
||||
}
|
||||
|
||||
public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) {
|
||||
for (Artist artist : artists) {
|
||||
App.getSubsonicClientInstance(application, false)
|
||||
.getBrowsingClient()
|
||||
.getArtist(artist.getId())
|
||||
.enqueue(new Callback<SubsonicResponse>() {
|
||||
@Override
|
||||
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||
addToMutableLiveData(list, MappingUtil.mapArtistWithAlbum(response.body().getArtist()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void addToMutableLiveData(MutableLiveData<List<Artist>> liveData, Artist artist) {
|
||||
List<Artist> liveArtists = liveData.getValue();
|
||||
liveArtists.add(artist);
|
||||
liveData.setValue(liveArtists);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ import com.cappielloantonio.play.model.RecentSearch;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class RecentSearchRepository {
|
||||
public class SearchingRepository {
|
||||
private RecentSearchDao recentSearchDao;
|
||||
|
||||
public RecentSearchRepository(Application application) {
|
||||
public SearchingRepository(Application application) {
|
||||
AppDatabase database = AppDatabase.getInstance(application);
|
||||
recentSearchDao = database.recentSearchDao();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue