From ca37adc33af7910ed671c1a585ea3574f75c23fa Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Mon, 2 Aug 2021 18:27:45 +0200 Subject: [PATCH] Preparation for requesting album information --- .../cappielloantonio/play/model/Album.java | 14 +++ .../play/repository/AlbumRepository.java | 23 ++++ .../play/subsonic/models/AlbumInfo.java | 115 ++++-------------- .../subsonic/models/SubsonicResponse.java | 1 + .../play/util/MappingUtil.java | 5 + 5 files changed, 69 insertions(+), 89 deletions(-) diff --git a/app/src/main/java/com/cappielloantonio/play/model/Album.java b/app/src/main/java/com/cappielloantonio/play/model/Album.java index 77a1735f..7b6323b5 100644 --- a/app/src/main/java/com/cappielloantonio/play/model/Album.java +++ b/app/src/main/java/com/cappielloantonio/play/model/Album.java @@ -6,6 +6,7 @@ import android.os.Parcelable; import androidx.annotation.NonNull; import com.cappielloantonio.play.subsonic.models.AlbumID3; +import com.cappielloantonio.play.subsonic.models.AlbumInfo; import com.cappielloantonio.play.subsonic.models.AlbumWithSongsID3; import com.cappielloantonio.play.util.MappingUtil; @@ -28,6 +29,7 @@ public class Album implements Parcelable { public String blurHash; public boolean favorite; public List songs; + public String notes; public Album(AlbumID3 albumID3) { this.id = albumID3.getId(); @@ -50,6 +52,10 @@ public class Album implements Parcelable { this.songs = MappingUtil.mapSong(albumWithSongsID3.getSongs()); } + public Album(AlbumInfo info) { + this.notes = info.getNotes(); + } + public String getId() { return id; } @@ -122,6 +128,14 @@ public class Album implements Parcelable { this.songs = songs; } + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java index c94a8a06..d36af812 100644 --- a/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java +++ b/app/src/main/java/com/cappielloantonio/play/repository/AlbumRepository.java @@ -223,6 +223,29 @@ public class AlbumRepository { return album; } + public MutableLiveData getAlbumInfo(String id) { + MutableLiveData album = new MutableLiveData<>(); + + App.getSubsonicClientInstance(application, false) + .getBrowsingClient() + .getAlbumInfo2(id) + .enqueue(new Callback() { + @Override + public void onResponse(Call call, Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + album.setValue(MappingUtil.mapAlbum(response.body().getAlbumInfo())); + } + } + + @Override + public void onFailure(Call call, Throwable t) { + + } + }); + + return album; + } + public void getInstantMix(Album album, int count, MediaCallback callback) { App.getSubsonicClientInstance(application, false) .getBrowsingClient() diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumInfo.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumInfo.java index 7dd9d2c2..21defd67 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumInfo.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumInfo.java @@ -1,131 +1,68 @@ package com.cappielloantonio.play.subsonic.models; -public class AlbumInfo { - protected String notes; - protected String musicBrainzId; - protected String lastFmUrl; - protected String smallImageUrl; - protected String mediumImageUrl; - protected String largeImageUrl; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Xml; - /** - * Gets the value of the notes property. - * - * @return possible object is - * {@link String } - */ +@Xml +public class AlbumInfo { + @Attribute + protected String notes; + @Attribute + protected String musicBrainzId; + @Attribute + protected String lastFmUrl; + @Attribute + protected String smallImageUrl; + @Attribute + protected String mediumImageUrl; + @Attribute + protected String largeImageUrl; + public String getNotes() { return notes; } - - /** - * Sets the value of the notes property. - * - * @param value allowed object is - * {@link String } - */ + public void setNotes(String value) { this.notes = value; } - - /** - * Gets the value of the musicBrainzId property. - * - * @return possible object is - * {@link String } - */ + public String getMusicBrainzId() { return musicBrainzId; } - /** - * Sets the value of the musicBrainzId property. - * - * @param value allowed object is - * {@link String } - */ public void setMusicBrainzId(String value) { this.musicBrainzId = value; } - - /** - * Gets the value of the lastFmUrl property. - * - * @return possible object is - * {@link String } - */ + public String getLastFmUrl() { return lastFmUrl; } - - /** - * Sets the value of the lastFmUrl property. - * - * @param value allowed object is - * {@link String } - */ + public void setLastFmUrl(String value) { this.lastFmUrl = value; } - /** - * Gets the value of the smallImageUrl property. - * - * @return possible object is - * {@link String } - */ public String getSmallImageUrl() { return smallImageUrl; } - - /** - * Sets the value of the smallImageUrl property. - * - * @param value allowed object is - * {@link String } - */ + public void setSmallImageUrl(String value) { this.smallImageUrl = value; } - - /** - * Gets the value of the mediumImageUrl property. - * - * @return possible object is - * {@link String } - */ + public String getMediumImageUrl() { return mediumImageUrl; } - - /** - * Sets the value of the mediumImageUrl property. - * - * @param value allowed object is - * {@link String } - */ + public void setMediumImageUrl(String value) { this.mediumImageUrl = value; } - - /** - * Gets the value of the largeImageUrl property. - * - * @return possible object is - * {@link String } - */ + public String getLargeImageUrl() { return largeImageUrl; } - - /** - * Sets the value of the largeImageUrl property. - * - * @param value allowed object is - * {@link String } - */ + public void setLargeImageUrl(String value) { this.largeImageUrl = value; } - } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/SubsonicResponse.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/SubsonicResponse.java index e5b46932..8f3a8a85 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/SubsonicResponse.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/SubsonicResponse.java @@ -18,6 +18,7 @@ public class SubsonicResponse { @Element(name = "artistInfo2") private ArtistInfo2 artistInfo2; private ArtistInfo artistInfo; + @Element(name = "albumInfo") private AlbumInfo albumInfo; @Element(name = "starred2") private Starred2 starred2; diff --git a/app/src/main/java/com/cappielloantonio/play/util/MappingUtil.java b/app/src/main/java/com/cappielloantonio/play/util/MappingUtil.java index 1ec4ad46..a22f594a 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/MappingUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/MappingUtil.java @@ -7,6 +7,7 @@ import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.model.Queue; import com.cappielloantonio.play.model.Song; import com.cappielloantonio.play.subsonic.models.AlbumID3; +import com.cappielloantonio.play.subsonic.models.AlbumInfo; import com.cappielloantonio.play.subsonic.models.AlbumWithSongsID3; import com.cappielloantonio.play.subsonic.models.ArtistID3; import com.cappielloantonio.play.subsonic.models.ArtistInfo2; @@ -43,6 +44,10 @@ public class MappingUtil { return new Album(albumWithSongsID3); } + public static Album mapAlbum(AlbumInfo albumInfo) { + return new Album(albumInfo); + } + public static ArrayList mapArtist(List artistID3List) { ArrayList artists = new ArrayList();