mirror of
https://github.com/antebudimir/tempus.git
synced 2026-01-01 18:03:33 +00:00
Implementation of album and artist catalog recovery
This commit is contained in:
parent
64cd8ed0ac
commit
98ffec9b72
15 changed files with 330 additions and 160 deletions
|
|
@ -11,6 +11,7 @@ import androidx.room.Ignore;
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ArtistInfo2;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||||
import com.cappielloantonio.play.util.MappingUtil;
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
||||||
|
|
@ -23,6 +24,7 @@ public class Artist implements Parcelable {
|
||||||
public List<Genre> genres;
|
public List<Genre> genres;
|
||||||
public List<Album> albums;
|
public List<Album> albums;
|
||||||
public List<Song> songs;
|
public List<Song> songs;
|
||||||
|
public List<Artist> similarArtists;
|
||||||
|
|
||||||
public String id;
|
public String id;
|
||||||
public String name;
|
public String name;
|
||||||
|
|
@ -32,6 +34,7 @@ public class Artist implements Parcelable {
|
||||||
public String backdropBlurHash;
|
public String backdropBlurHash;
|
||||||
public int albumCount;
|
public int albumCount;
|
||||||
public boolean favorite;
|
public boolean favorite;
|
||||||
|
public String bio;
|
||||||
|
|
||||||
public Artist(ArtistID3 artistID3) {
|
public Artist(ArtistID3 artistID3) {
|
||||||
this.id = artistID3.getId();
|
this.id = artistID3.getId();
|
||||||
|
|
@ -52,6 +55,11 @@ public class Artist implements Parcelable {
|
||||||
this.favorite = artistWithAlbumsID3.getStarred() != null;
|
this.favorite = artistWithAlbumsID3.getStarred() != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Artist(ArtistInfo2 artistInfo2) {
|
||||||
|
this.similarArtists = MappingUtil.mapArtist(artistInfo2.getSimilarArtists());
|
||||||
|
this.bio = artistInfo2.getBiography();
|
||||||
|
}
|
||||||
|
|
||||||
public Artist(String id, String name) {
|
public Artist(String id, String name) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
@ -129,6 +137,23 @@ public class Artist implements Parcelable {
|
||||||
this.favorite = favorite;
|
this.favorite = favorite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<Artist> getSimilarArtists() {
|
||||||
|
return similarArtists;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSimilarArtists(List<Artist> similarArtists) {
|
||||||
|
this.similarArtists = similarArtists;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getBio() {
|
||||||
|
return bio;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBio(String bio) {
|
||||||
|
this.bio = bio;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public boolean equals(Object o) {
|
||||||
if (this == o) return true;
|
if (this == o) return true;
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
import com.cappielloantonio.play.subsonic.models.ResponseStatus;
|
||||||
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
import com.cappielloantonio.play.subsonic.models.SubsonicResponse;
|
||||||
import com.cappielloantonio.play.util.MappingUtil;
|
import com.cappielloantonio.play.util.MappingUtil;
|
||||||
|
|
@ -94,6 +95,7 @@ public class AlbumRepository {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -150,4 +152,50 @@ public class AlbumRepository {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Song>> getAlbumTracks(String id) {
|
||||||
|
MutableLiveData<List<Song>> albumTracks = new MutableLiveData<>();
|
||||||
|
|
||||||
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
.getBrowsingClient()
|
||||||
|
.getAlbum(id)
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
|
List<Song> tracks = new ArrayList<>(MappingUtil.mapSong(response.body().getAlbum().getSongs()));
|
||||||
|
albumTracks.setValue(tracks);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return albumTracks;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<List<Album>> getArtistAlbums(String id) {
|
||||||
|
MutableLiveData<List<Album>> artistsAlbum = new MutableLiveData<>();
|
||||||
|
|
||||||
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
.getBrowsingClient()
|
||||||
|
.getArtist(id)
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
|
List<Album> albums = new ArrayList<>(MappingUtil.mapAlbum(response.body().getArtist().getAlbums()));
|
||||||
|
artistsAlbum.setValue(albums);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return artistsAlbum;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import android.app.Application;
|
||||||
import androidx.lifecycle.MutableLiveData;
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
import com.cappielloantonio.play.subsonic.models.IndexID3;
|
||||||
|
|
@ -84,6 +85,9 @@ public class ArtistRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metodo che mi restituisce le informazioni essenzionali dell'artista (cover, numero di album...)
|
||||||
|
*/
|
||||||
public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) {
|
public void getArtistInfo(List<Artist> artists, MutableLiveData<List<Artist>> list) {
|
||||||
for (Artist artist : artists) {
|
for (Artist artist : artists) {
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
|
@ -103,6 +107,51 @@ public class ArtistRepository {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public MutableLiveData<Artist> getArtistInfo(String id) {
|
||||||
|
MutableLiveData<Artist> artist = new MutableLiveData<>();
|
||||||
|
|
||||||
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
.getBrowsingClient()
|
||||||
|
.getArtist(id)
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
|
artist.setValue(MappingUtil.mapArtistWithAlbum(response.body().getArtist()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return artist;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Metodo che mi restituisce le informazioni complete dell'artista (bio, immagini prese da last.fm, artisti simili...)
|
||||||
|
*/
|
||||||
|
public MutableLiveData<Artist> getArtistFullInfo(String id) {
|
||||||
|
MutableLiveData<Artist> artistFullInfo = new MutableLiveData<>();
|
||||||
|
|
||||||
|
App.getSubsonicClientInstance(application, false)
|
||||||
|
.getBrowsingClient()
|
||||||
|
.getArtistInfo2(id)
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, Response<SubsonicResponse> response) {
|
||||||
|
artistFullInfo.setValue(MappingUtil.mapArtist(response.body().getArtistInfo2()));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return artistFullInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public void star(String id) {
|
public void star(String id) {
|
||||||
App.getSubsonicClientInstance(application, false)
|
App.getSubsonicClientInstance(application, false)
|
||||||
.getMediaAnnotationClient()
|
.getMediaAnnotationClient()
|
||||||
|
|
|
||||||
|
|
@ -1,36 +1,25 @@
|
||||||
package com.cappielloantonio.play.subsonic.models;
|
package com.cappielloantonio.play.subsonic.models;
|
||||||
|
|
||||||
|
import com.tickaroo.tikxml.annotation.Element;
|
||||||
|
import com.tickaroo.tikxml.annotation.ElementNameMatcher;
|
||||||
|
import com.tickaroo.tikxml.annotation.Xml;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Xml
|
||||||
public class ArtistInfo2 extends ArtistInfoBase {
|
public class ArtistInfo2 extends ArtistInfoBase {
|
||||||
|
@Element(name = "similarArtist", typesByElement = @ElementNameMatcher(type = ArtistID3.class))
|
||||||
protected List<ArtistID3> similarArtists;
|
protected List<ArtistID3> similarArtists;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the similarArtists property.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* This accessor method returns a reference to the live list,
|
|
||||||
* not a snapshot. Therefore any modification you make to the
|
|
||||||
* returned list will be present inside the JAXB object.
|
|
||||||
* This is why there is not a <CODE>set</CODE> method for the similarArtists property.
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* For example, to add a new item, do as follows:
|
|
||||||
* <pre>
|
|
||||||
* getSimilarArtists().add(newItem);
|
|
||||||
* </pre>
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* <p>
|
|
||||||
* Objects of the following type(s) are allowed in the list
|
|
||||||
* {@link ArtistID3 }
|
|
||||||
*/
|
|
||||||
public List<ArtistID3> getSimilarArtists() {
|
public List<ArtistID3> getSimilarArtists() {
|
||||||
if (similarArtists == null) {
|
if (similarArtists == null) {
|
||||||
similarArtists = new ArrayList<ArtistID3>();
|
similarArtists = new ArrayList<>();
|
||||||
}
|
}
|
||||||
return this.similarArtists;
|
return this.similarArtists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setSimilarArtists(List<ArtistID3> similarArtists) {
|
||||||
|
this.similarArtists = similarArtists;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,129 +1,67 @@
|
||||||
package com.cappielloantonio.play.subsonic.models;
|
package com.cappielloantonio.play.subsonic.models;
|
||||||
|
|
||||||
|
import com.tickaroo.tikxml.annotation.PropertyElement;
|
||||||
|
import com.tickaroo.tikxml.annotation.Xml;
|
||||||
|
|
||||||
|
@Xml
|
||||||
public class ArtistInfoBase {
|
public class ArtistInfoBase {
|
||||||
|
@PropertyElement
|
||||||
protected String biography;
|
protected String biography;
|
||||||
|
@PropertyElement
|
||||||
protected String musicBrainzId;
|
protected String musicBrainzId;
|
||||||
|
@PropertyElement
|
||||||
protected String lastFmUrl;
|
protected String lastFmUrl;
|
||||||
|
@PropertyElement
|
||||||
protected String smallImageUrl;
|
protected String smallImageUrl;
|
||||||
|
@PropertyElement
|
||||||
protected String mediumImageUrl;
|
protected String mediumImageUrl;
|
||||||
|
@PropertyElement
|
||||||
protected String largeImageUrl;
|
protected String largeImageUrl;
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the biography property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getBiography() {
|
public String getBiography() {
|
||||||
return biography;
|
return biography;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the biography property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setBiography(String value) {
|
public void setBiography(String value) {
|
||||||
this.biography = value;
|
this.biography = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the musicBrainzId property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getMusicBrainzId() {
|
public String getMusicBrainzId() {
|
||||||
return musicBrainzId;
|
return musicBrainzId;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the musicBrainzId property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setMusicBrainzId(String value) {
|
public void setMusicBrainzId(String value) {
|
||||||
this.musicBrainzId = value;
|
this.musicBrainzId = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the lastFmUrl property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getLastFmUrl() {
|
public String getLastFmUrl() {
|
||||||
return lastFmUrl;
|
return lastFmUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the lastFmUrl property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setLastFmUrl(String value) {
|
public void setLastFmUrl(String value) {
|
||||||
this.lastFmUrl = value;
|
this.lastFmUrl = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the smallImageUrl property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getSmallImageUrl() {
|
public String getSmallImageUrl() {
|
||||||
return smallImageUrl;
|
return smallImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the smallImageUrl property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setSmallImageUrl(String value) {
|
public void setSmallImageUrl(String value) {
|
||||||
this.smallImageUrl = value;
|
this.smallImageUrl = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the mediumImageUrl property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getMediumImageUrl() {
|
public String getMediumImageUrl() {
|
||||||
return mediumImageUrl;
|
return mediumImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the mediumImageUrl property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setMediumImageUrl(String value) {
|
public void setMediumImageUrl(String value) {
|
||||||
this.mediumImageUrl = value;
|
this.mediumImageUrl = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Gets the value of the largeImageUrl property.
|
|
||||||
*
|
|
||||||
* @return possible object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public String getLargeImageUrl() {
|
public String getLargeImageUrl() {
|
||||||
return largeImageUrl;
|
return largeImageUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Sets the value of the largeImageUrl property.
|
|
||||||
*
|
|
||||||
* @param value allowed object is
|
|
||||||
* {@link String }
|
|
||||||
*/
|
|
||||||
public void setLargeImageUrl(String value) {
|
public void setLargeImageUrl(String value) {
|
||||||
this.largeImageUrl = value;
|
this.largeImageUrl = value;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ public class SubsonicResponse {
|
||||||
@Element(name = "similarSongs2")
|
@Element(name = "similarSongs2")
|
||||||
private SimilarSongs2 similarSongs2;
|
private SimilarSongs2 similarSongs2;
|
||||||
private SimilarSongs similarSongs;
|
private SimilarSongs similarSongs;
|
||||||
|
@Element(name = "artistInfo2")
|
||||||
private ArtistInfo2 artistInfo2;
|
private ArtistInfo2 artistInfo2;
|
||||||
private ArtistInfo artistInfo;
|
private ArtistInfo artistInfo;
|
||||||
private AlbumInfo albumInfo;
|
private AlbumInfo albumInfo;
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package com.cappielloantonio.play.ui.fragment;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
|
|
@ -36,11 +37,14 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
private AlbumCatalogueViewModel albumCatalogueViewModel;
|
private AlbumCatalogueViewModel albumCatalogueViewModel;
|
||||||
|
|
||||||
private AlbumCatalogueAdapter albumAdapter;
|
private AlbumCatalogueAdapter albumAdapter;
|
||||||
|
private GridLayoutManager gridLayoutManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -49,7 +53,6 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
|
|
||||||
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
|
bind = FragmentAlbumCatalogueBinding.inflate(inflater, container, false);
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
|
||||||
|
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initAlbumCatalogueView();
|
initAlbumCatalogueView();
|
||||||
|
|
@ -69,6 +72,11 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
bind = null;
|
bind = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
albumCatalogueViewModel = new ViewModelProvider(requireActivity()).get(AlbumCatalogueViewModel.class);
|
||||||
|
albumCatalogueViewModel.loadAlbums(requireContext(), 500);
|
||||||
|
}
|
||||||
|
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
activity.setSupportActionBar(bind.toolbar);
|
activity.setSupportActionBar(bind.toolbar);
|
||||||
|
|
||||||
|
|
@ -94,13 +102,16 @@ public class AlbumCatalogueFragment extends Fragment {
|
||||||
|
|
||||||
@SuppressLint("ClickableViewAccessibility")
|
@SuppressLint("ClickableViewAccessibility")
|
||||||
private void initAlbumCatalogueView() {
|
private void initAlbumCatalogueView() {
|
||||||
bind.albumCatalogueRecyclerView.setLayoutManager(new GridLayoutManager(requireContext(), 2));
|
gridLayoutManager = new GridLayoutManager(requireContext(), 2);
|
||||||
|
|
||||||
|
bind.albumCatalogueRecyclerView.setLayoutManager(gridLayoutManager);
|
||||||
bind.albumCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
bind.albumCatalogueRecyclerView.addItemDecoration(new GridItemDecoration(2, 20, false));
|
||||||
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
bind.albumCatalogueRecyclerView.setHasFixedSize(true);
|
||||||
|
|
||||||
albumAdapter = new AlbumCatalogueAdapter(activity, requireContext());
|
albumAdapter = new AlbumCatalogueAdapter(activity, requireContext());
|
||||||
albumAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
|
albumAdapter.setStateRestorationPolicy(RecyclerView.Adapter.StateRestorationPolicy.PREVENT_WHEN_EMPTY);
|
||||||
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
|
bind.albumCatalogueRecyclerView.setAdapter(albumAdapter);
|
||||||
|
|
||||||
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
albumCatalogueViewModel.getAlbumList().observe(requireActivity(), albums -> {
|
||||||
albumAdapter.setItems(albums);
|
albumAdapter.setItems(albums);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -100,7 +100,7 @@ public class AlbumPageFragment extends Fragment {
|
||||||
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
|
||||||
switch (item.getItemId()) {
|
switch (item.getItemId()) {
|
||||||
case R.id.action_download_album:
|
case R.id.action_download_album:
|
||||||
DownloadUtil.getDownloadTracker(requireContext()).toggleDownload(albumPageViewModel.getAlbumSongList());
|
DownloadUtil.getDownloadTracker(requireContext()).toggleDownload(albumPageViewModel.getAlbumSongLiveList().getValue());
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
|
@ -132,20 +132,21 @@ public class AlbumPageFragment extends Fragment {
|
||||||
|
|
||||||
private void initAlbumInfoTextButton() {
|
private void initAlbumInfoTextButton() {
|
||||||
bind.albumArtistLabel.setOnClickListener(v -> {
|
bind.albumArtistLabel.setOnClickListener(v -> {
|
||||||
Artist artist = albumPageViewModel.getArtist();
|
albumPageViewModel.getArtist().observe(requireActivity(), artist -> {
|
||||||
if(artist != null) {
|
if(artist != null) {
|
||||||
Bundle bundle = new Bundle();
|
Bundle bundle = new Bundle();
|
||||||
bundle.putParcelable("artist_object", artist);
|
bundle.putParcelable("artist_object", artist);
|
||||||
activity.navController.navigate(R.id.action_albumPageFragment_to_artistPageFragment, bundle);
|
activity.navController.navigate(R.id.action_albumPageFragment_to_artistPageFragment, bundle);
|
||||||
}
|
}
|
||||||
else Toast.makeText(requireContext(), "Error retrieving artist", Toast.LENGTH_SHORT).show();
|
else Toast.makeText(requireContext(), "Error retrieving artist", Toast.LENGTH_SHORT).show();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
bind.albumReleaseYearLabel.setOnClickListener(v -> {
|
bind.albumReleaseYearLabel.setOnClickListener(v -> {
|
||||||
Bundle bundle = new Bundle();
|
/*Bundle bundle = new Bundle();
|
||||||
bundle.putString(Song.BY_YEAR, Song.BY_YEAR);
|
bundle.putString(Song.BY_YEAR, Song.BY_YEAR);
|
||||||
bundle.putInt("year_object", albumPageViewModel.getAlbum().getYear());
|
bundle.putInt("year_object", albumPageViewModel.getAlbum().getYear());
|
||||||
activity.navController.navigate(R.id.action_albumPageFragment_to_songListPageFragment, bundle);
|
activity.navController.navigate(R.id.action_albumPageFragment_to_songListPageFragment, bundle);*/
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -197,22 +198,6 @@ public class AlbumPageFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSimilarAlbumsView() {
|
private void initSimilarAlbumsView() {
|
||||||
SyncUtil.getSimilarItems(requireContext(), new MediaCallback() {
|
|
||||||
@Override
|
|
||||||
public void onError(Exception exception) {
|
|
||||||
// Toast.makeText(requireContext(), "Error retrieving similar items", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoadMedia(List<?> media) {
|
|
||||||
bind.similarAlbumSector.setVisibility(View.VISIBLE);
|
|
||||||
|
|
||||||
bind.similarAlbumsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
|
||||||
|
|
||||||
albumArtistPageOrSimilarAdapter = new AlbumArtistPageOrSimilarAdapter(requireContext());
|
|
||||||
bind.similarAlbumsRecyclerView.setAdapter(albumArtistPageOrSimilarAdapter);
|
|
||||||
albumArtistPageOrSimilarAdapter.setItems((ArrayList<Album>) media);
|
|
||||||
}
|
|
||||||
}, SyncUtil.ALBUM, albumPageViewModel.getAlbum().getId(), PreferenceUtil.getInstance(requireContext()).getSimilarItemsNumber());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -26,6 +26,7 @@ import com.cappielloantonio.play.adapter.ArtistCatalogueAdapter;
|
||||||
import com.cappielloantonio.play.databinding.FragmentArtistCatalogueBinding;
|
import com.cappielloantonio.play.databinding.FragmentArtistCatalogueBinding;
|
||||||
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
import com.cappielloantonio.play.helper.recyclerview.GridItemDecoration;
|
||||||
import com.cappielloantonio.play.ui.activity.MainActivity;
|
import com.cappielloantonio.play.ui.activity.MainActivity;
|
||||||
|
import com.cappielloantonio.play.viewmodel.AlbumCatalogueViewModel;
|
||||||
import com.cappielloantonio.play.viewmodel.ArtistCatalogueViewModel;
|
import com.cappielloantonio.play.viewmodel.ArtistCatalogueViewModel;
|
||||||
|
|
||||||
public class ArtistCatalogueFragment extends Fragment {
|
public class ArtistCatalogueFragment extends Fragment {
|
||||||
|
|
@ -41,6 +42,8 @@ public class ArtistCatalogueFragment extends Fragment {
|
||||||
public void onCreate(@Nullable Bundle savedInstanceState) {
|
public void onCreate(@Nullable Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
setHasOptionsMenu(true);
|
setHasOptionsMenu(true);
|
||||||
|
|
||||||
|
initData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -49,7 +52,6 @@ public class ArtistCatalogueFragment extends Fragment {
|
||||||
|
|
||||||
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
|
bind = FragmentArtistCatalogueBinding.inflate(inflater, container, false);
|
||||||
View view = bind.getRoot();
|
View view = bind.getRoot();
|
||||||
artistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(ArtistCatalogueViewModel.class);
|
|
||||||
|
|
||||||
initAppBar();
|
initAppBar();
|
||||||
initArtistCatalogueView();
|
initArtistCatalogueView();
|
||||||
|
|
@ -69,6 +71,11 @@ public class ArtistCatalogueFragment extends Fragment {
|
||||||
bind = null;
|
bind = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void initData() {
|
||||||
|
artistCatalogueViewModel = new ViewModelProvider(requireActivity()).get(ArtistCatalogueViewModel.class);
|
||||||
|
artistCatalogueViewModel.loadArtists(requireContext());
|
||||||
|
}
|
||||||
|
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
activity.setSupportActionBar(bind.toolbar);
|
activity.setSupportActionBar(bind.toolbar);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,9 @@
|
||||||
package com.cappielloantonio.play.ui.fragment;
|
package com.cappielloantonio.play.ui.fragment;
|
||||||
|
|
||||||
|
import android.annotation.SuppressLint;
|
||||||
import android.graphics.BlendMode;
|
import android.graphics.BlendMode;
|
||||||
import android.graphics.BlendModeColorFilter;
|
import android.graphics.BlendModeColorFilter;
|
||||||
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
|
|
@ -9,6 +11,7 @@ import android.view.ViewGroup;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import androidx.annotation.RequiresApi;
|
||||||
import androidx.core.view.ViewCompat;
|
import androidx.core.view.ViewCompat;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.lifecycle.ViewModelProvider;
|
import androidx.lifecycle.ViewModelProvider;
|
||||||
|
|
@ -16,6 +19,7 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
|
|
||||||
import com.cappielloantonio.play.App;
|
import com.cappielloantonio.play.App;
|
||||||
import com.cappielloantonio.play.R;
|
import com.cappielloantonio.play.R;
|
||||||
|
import com.cappielloantonio.play.adapter.AlbumAdapter;
|
||||||
import com.cappielloantonio.play.adapter.AlbumArtistPageOrSimilarAdapter;
|
import com.cappielloantonio.play.adapter.AlbumArtistPageOrSimilarAdapter;
|
||||||
import com.cappielloantonio.play.adapter.ArtistSimilarAdapter;
|
import com.cappielloantonio.play.adapter.ArtistSimilarAdapter;
|
||||||
import com.cappielloantonio.play.adapter.SongHorizontalAdapter;
|
import com.cappielloantonio.play.adapter.SongHorizontalAdapter;
|
||||||
|
|
@ -93,6 +97,7 @@ public class ArtistPageFragment extends Fragment {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SuppressLint("NewApi")
|
||||||
private void initAppBar() {
|
private void initAppBar() {
|
||||||
activity.setSupportActionBar(bind.animToolbar);
|
activity.setSupportActionBar(bind.animToolbar);
|
||||||
if (activity.getSupportActionBar() != null)
|
if (activity.getSupportActionBar() != null)
|
||||||
|
|
@ -168,22 +173,14 @@ public class ArtistPageFragment extends Fragment {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initSimilarArtistsView() {
|
private void initSimilarArtistsView() {
|
||||||
SyncUtil.getSimilarItems(requireContext(), new MediaCallback() {
|
bind.similarArtistsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
||||||
@Override
|
bind.similarArtistsRecyclerView.setHasFixedSize(true);
|
||||||
public void onError(Exception exception) {
|
|
||||||
// Toast.makeText(requireContext(), "Error retrieving similar items", Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
artistSimilarAdapter = new ArtistSimilarAdapter(requireContext());
|
||||||
public void onLoadMedia(List<?> media) {
|
bind.similarArtistsRecyclerView.setAdapter(artistSimilarAdapter);
|
||||||
bind.similarArtistSector.setVisibility(View.VISIBLE);
|
artistPageViewModel.getArtistInfo(artistPageViewModel.getArtist().getId()).observe(requireActivity(), artist -> {
|
||||||
|
if(bind != null) bind.similarArtistSector.setVisibility(!artist.getSimilarArtists().isEmpty() ? View.VISIBLE : View.GONE);
|
||||||
bind.similarArtistsRecyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.HORIZONTAL, false));
|
artistSimilarAdapter.setItems(artist.getSimilarArtists());
|
||||||
|
});
|
||||||
artistSimilarAdapter = new ArtistSimilarAdapter(requireContext());
|
|
||||||
bind.similarArtistsRecyclerView.setAdapter(artistSimilarAdapter);
|
|
||||||
artistSimilarAdapter.setItems((ArrayList<Artist>) media);
|
|
||||||
}
|
|
||||||
}, SyncUtil.ARTIST, artistPageViewModel.getArtist().getId(), PreferenceUtil.getInstance(requireContext()).getSimilarItemsNumber());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,6 +8,7 @@ import com.cappielloantonio.play.model.Queue;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ArtistInfo2;
|
||||||
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
import com.cappielloantonio.play.subsonic.models.ArtistWithAlbumsID3;
|
||||||
import com.cappielloantonio.play.subsonic.models.Child;
|
import com.cappielloantonio.play.subsonic.models.Child;
|
||||||
import com.cappielloantonio.play.subsonic.models.Playlists;
|
import com.cappielloantonio.play.subsonic.models.Playlists;
|
||||||
|
|
@ -46,6 +47,10 @@ public class MappingUtil {
|
||||||
return artists;
|
return artists;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Artist mapArtist(ArtistInfo2 artistInfo2) {
|
||||||
|
return new Artist(artistInfo2);
|
||||||
|
}
|
||||||
|
|
||||||
public static Artist mapArtistWithAlbum(ArtistWithAlbumsID3 artistWithAlbumsID3) {
|
public static Artist mapArtistWithAlbum(ArtistWithAlbumsID3 artistWithAlbumsID3) {
|
||||||
return new Artist(artistWithAlbumsID3);
|
return new Artist(artistWithAlbumsID3);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,35 @@
|
||||||
package com.cappielloantonio.play.viewmodel;
|
package com.cappielloantonio.play.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||||
|
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.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import retrofit2.Call;
|
||||||
|
import retrofit2.Callback;
|
||||||
|
|
||||||
public class AlbumCatalogueViewModel extends AndroidViewModel {
|
public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
public LiveData<List<Album>> albumList;
|
private MutableLiveData<List<Album>> albumList = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
private AlbumRepository albumRepository;
|
private AlbumRepository albumRepository;
|
||||||
private String query = "";
|
private String query = "";
|
||||||
|
private int page = 0;
|
||||||
|
|
||||||
public AlbumCatalogueViewModel(@NonNull Application application) {
|
public AlbumCatalogueViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -23,10 +38,51 @@ public class AlbumCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Album>> getAlbumList() {
|
public LiveData<List<Album>> getAlbumList() {
|
||||||
// albumList = albumRepository.getListLiveAlbums();
|
|
||||||
return albumList;
|
return albumList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadAlbums(Context context, int size) {
|
||||||
|
retrieveAlbums(context, new MediaCallback() {
|
||||||
|
@Override
|
||||||
|
public void onError(Exception exception) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadMedia(List<?> media) {
|
||||||
|
List<Album> liveAlbum = albumList.getValue();
|
||||||
|
liveAlbum.addAll(MappingUtil.mapAlbum((List<AlbumID3>) media));
|
||||||
|
albumList.setValue(liveAlbum);
|
||||||
|
|
||||||
|
if (media.size() == size) {
|
||||||
|
loadAlbums(context, size);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, size, size * page++);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void retrieveAlbums(Context context, MediaCallback callback, int size, int offset) {
|
||||||
|
App.getSubsonicClientInstance(context, false)
|
||||||
|
.getAlbumSongListClient()
|
||||||
|
.getAlbumList2("alphabeticalByName", size, offset)
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||||
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
|
List<AlbumID3> albumList = new ArrayList<>();
|
||||||
|
albumList.addAll(response.body().getAlbumList2().getAlbums());
|
||||||
|
callback.onLoadMedia(albumList);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
callback.onError(new Exception(t.getMessage()));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getQuery() {
|
public String getQuery() {
|
||||||
return query;
|
return query;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,10 +5,12 @@ import android.app.Application;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
||||||
|
|
@ -16,9 +18,10 @@ import java.util.List;
|
||||||
|
|
||||||
public class AlbumPageViewModel extends AndroidViewModel {
|
public class AlbumPageViewModel extends AndroidViewModel {
|
||||||
private SongRepository songRepository;
|
private SongRepository songRepository;
|
||||||
|
private AlbumRepository albumRepository;
|
||||||
private ArtistRepository artistRepository;
|
private ArtistRepository artistRepository;
|
||||||
|
|
||||||
private LiveData<List<Song>> songLiveList;
|
private LiveData<List<Song>> songLiveList = new MutableLiveData<>();
|
||||||
|
|
||||||
private Album album;
|
private Album album;
|
||||||
|
|
||||||
|
|
@ -26,19 +29,15 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
||||||
songRepository = new SongRepository(application);
|
songRepository = new SongRepository(application);
|
||||||
|
albumRepository = new AlbumRepository(application);
|
||||||
artistRepository = new ArtistRepository(application);
|
artistRepository = new ArtistRepository(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Song>> getAlbumSongLiveList() {
|
public LiveData<List<Song>> getAlbumSongLiveList() {
|
||||||
// songLiveList = songRepository.getAlbumListLiveSong(album.getId());
|
songLiveList = albumRepository.getAlbumTracks(album.getId());
|
||||||
return songLiveList;
|
return songLiveList;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Song> getAlbumSongList() {
|
|
||||||
// return songRepository.getAlbumListSong(album.getId(), false);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Album getAlbum() {
|
public Album getAlbum() {
|
||||||
return album;
|
return album;
|
||||||
}
|
}
|
||||||
|
|
@ -47,8 +46,7 @@ public class AlbumPageViewModel extends AndroidViewModel {
|
||||||
this.album = album;
|
this.album = album;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Artist getArtist() {
|
public LiveData<Artist> getArtist() {
|
||||||
// return artistRepository.getArtistByID(album.getArtistId());
|
return artistRepository.getArtistInfo(album.getArtistId());
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,37 @@
|
||||||
package com.cappielloantonio.play.viewmodel;
|
package com.cappielloantonio.play.viewmodel;
|
||||||
|
|
||||||
import android.app.Application;
|
import android.app.Application;
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
|
import com.cappielloantonio.play.App;
|
||||||
|
import com.cappielloantonio.play.interfaces.MediaCallback;
|
||||||
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.repository.ArtistRepository;
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.AlbumID3;
|
||||||
|
import com.cappielloantonio.play.subsonic.models.ArtistID3;
|
||||||
|
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.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ArtistCatalogueViewModel extends AndroidViewModel {
|
import retrofit2.Call;
|
||||||
private ArtistRepository artistRepository;
|
import retrofit2.Callback;
|
||||||
|
|
||||||
private LiveData<List<Artist>> artistList;
|
public class ArtistCatalogueViewModel extends AndroidViewModel {
|
||||||
|
private MutableLiveData<List<Artist>> artistList = new MutableLiveData<>(new ArrayList<>());
|
||||||
|
|
||||||
|
private ArtistRepository artistRepository;
|
||||||
|
private String query = "";
|
||||||
|
private int page = 0;
|
||||||
|
|
||||||
public ArtistCatalogueViewModel(@NonNull Application application) {
|
public ArtistCatalogueViewModel(@NonNull Application application) {
|
||||||
super(application);
|
super(application);
|
||||||
|
|
@ -23,7 +40,39 @@ public class ArtistCatalogueViewModel extends AndroidViewModel {
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Artist>> getArtistList() {
|
public LiveData<List<Artist>> getArtistList() {
|
||||||
// artistList = artistRepository.getListLiveArtists();
|
|
||||||
return artistList;
|
return artistList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void loadArtists(Context context) {
|
||||||
|
App.getSubsonicClientInstance(context, false)
|
||||||
|
.getBrowsingClient()
|
||||||
|
.getArtists()
|
||||||
|
.enqueue(new Callback<SubsonicResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Call<SubsonicResponse> call, retrofit2.Response<SubsonicResponse> response) {
|
||||||
|
if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) {
|
||||||
|
List<ArtistID3> artists = new ArrayList<>();
|
||||||
|
|
||||||
|
for (IndexID3 index : response.body().getArtists().getIndices()) {
|
||||||
|
artists.addAll(index.getArtists());
|
||||||
|
}
|
||||||
|
|
||||||
|
artistList.setValue(MappingUtil.mapArtist(artists));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onFailure(Call<SubsonicResponse> call, Throwable t) {
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getQuery() {
|
||||||
|
return query;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setQuery(String query) {
|
||||||
|
this.query = query;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,28 @@ import android.app.Application;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.lifecycle.AndroidViewModel;
|
import androidx.lifecycle.AndroidViewModel;
|
||||||
import androidx.lifecycle.LiveData;
|
import androidx.lifecycle.LiveData;
|
||||||
|
import androidx.lifecycle.MutableLiveData;
|
||||||
|
|
||||||
import com.cappielloantonio.play.model.Album;
|
import com.cappielloantonio.play.model.Album;
|
||||||
import com.cappielloantonio.play.model.Artist;
|
import com.cappielloantonio.play.model.Artist;
|
||||||
import com.cappielloantonio.play.model.Song;
|
import com.cappielloantonio.play.model.Song;
|
||||||
import com.cappielloantonio.play.repository.AlbumRepository;
|
import com.cappielloantonio.play.repository.AlbumRepository;
|
||||||
|
import com.cappielloantonio.play.repository.ArtistRepository;
|
||||||
import com.cappielloantonio.play.repository.SongRepository;
|
import com.cappielloantonio.play.repository.SongRepository;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class ArtistPageViewModel extends AndroidViewModel {
|
public class ArtistPageViewModel extends AndroidViewModel {
|
||||||
private SongRepository songRepository;
|
private SongRepository songRepository;
|
||||||
private AlbumRepository albumRepository;
|
private AlbumRepository albumRepository;
|
||||||
|
private ArtistRepository artistRepository;
|
||||||
|
|
||||||
private List<Song> randomList;
|
private List<Song> randomList = new ArrayList<>();
|
||||||
private LiveData<List<Song>> songList;
|
private LiveData<List<Song>> songList = new MutableLiveData<>();
|
||||||
private LiveData<List<Album>> albumList;
|
private LiveData<List<Album>> albumList = new MutableLiveData<>();
|
||||||
|
private LiveData<List<Artist>> artistList = new MutableLiveData<>();
|
||||||
|
private LiveData<Artist> artistInfo = new MutableLiveData<>();
|
||||||
|
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
|
|
||||||
|
|
@ -29,13 +35,19 @@ public class ArtistPageViewModel extends AndroidViewModel {
|
||||||
|
|
||||||
songRepository = new SongRepository(application);
|
songRepository = new SongRepository(application);
|
||||||
albumRepository = new AlbumRepository(application);
|
albumRepository = new AlbumRepository(application);
|
||||||
|
artistRepository = new ArtistRepository(application);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LiveData<List<Album>> getAlbumList() {
|
public LiveData<List<Album>> getAlbumList() {
|
||||||
// albumList = albumRepository.getArtistListLiveAlbums(artist.id);
|
albumList = albumRepository.getArtistAlbums(artist.id);
|
||||||
return albumList;
|
return albumList;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LiveData<Artist> getArtistInfo(String id) {
|
||||||
|
artistInfo = artistRepository.getArtistFullInfo(id);
|
||||||
|
return artistInfo;
|
||||||
|
}
|
||||||
|
|
||||||
public List<Song> getArtistRandomSongList() {
|
public List<Song> getArtistRandomSongList() {
|
||||||
// randomList = songRepository.getArtistListLiveRandomSong(artist.id);
|
// randomList = songRepository.getArtistListLiveRandomSong(artist.id);
|
||||||
return randomList;
|
return randomList;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue