diff --git a/app/build.gradle b/app/build.gradle index f7c6f233..a50798fb 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -86,6 +86,7 @@ dependencies { implementation 'com.tickaroo.tikxml:annotation:0.9.0_11-SNAPSHOT' implementation 'com.tickaroo.tikxml:core:0.9.0_11-SNAPSHOT' annotationProcessor 'com.tickaroo.tikxml:processor:0.9.0_11-SNAPSHOT' + implementation 'com.tickaroo.tikxml:converter-date-rfc3339:0.9.0_11-SNAPSHOT' // implementation 'net.beardbot:subsonic-client:0.2.0' diff --git a/app/src/main/java/com/cappielloantonio/play/helper/ErrorHelper.java b/app/src/main/java/com/cappielloantonio/play/helper/ErrorHelper.java new file mode 100644 index 00000000..80befef4 --- /dev/null +++ b/app/src/main/java/com/cappielloantonio/play/helper/ErrorHelper.java @@ -0,0 +1,10 @@ +package com.cappielloantonio.play.helper; + +import android.content.Context; +import android.widget.Toast; + +public class ErrorHelper { + public static void handle(Context context, int code, String message) { + Toast.makeText(context, code + " - " + message, Toast.LENGTH_LONG).show(); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/cappielloantonio/play/model/Song.java b/app/src/main/java/com/cappielloantonio/play/model/Song.java index 5f99ee87..e69f9553 100644 --- a/app/src/main/java/com/cappielloantonio/play/model/Song.java +++ b/app/src/main/java/com/cappielloantonio/play/model/Song.java @@ -1,5 +1,6 @@ package com.cappielloantonio.play.model; +import android.annotation.SuppressLint; import android.os.Parcel; import android.os.Parcelable; import android.util.Log; @@ -10,6 +11,8 @@ import androidx.room.Entity; import androidx.room.Ignore; import androidx.room.PrimaryKey; +import com.cappielloantonio.play.subsonic.models.Child; + import org.jellyfin.apiclient.model.dto.BaseItemDto; import org.jellyfin.apiclient.model.dto.MediaSourceInfo; import org.jellyfin.apiclient.model.entities.ImageType; @@ -17,6 +20,7 @@ import org.jellyfin.apiclient.model.entities.MediaStream; import java.time.Instant; import java.util.ArrayList; +import java.util.Date; import java.util.List; import java.util.UUID; @@ -54,16 +58,6 @@ public class Song implements Parcelable { @Ignore public static final String RADIO = "RADIO"; - /* - * TODO: Da capire chi tra albumArtist e artistItems sono i compositori e suonatori dell'album, oppure le comparse - * In teoria AlbumArtist sono i creatori, mentre ArtistItems le comparse - */ - @Ignore - public List albumArtists; - - @Ignore - public List artistItems; - @NonNull @PrimaryKey @ColumnInfo(name = "id") @@ -99,9 +93,6 @@ public class Song implements Parcelable { @ColumnInfo(name = "primary") private String primary; - @ColumnInfo(name = "blurHash") - private String blurHash; - @ColumnInfo(name = "favorite") private boolean favorite; @@ -114,21 +105,9 @@ public class Song implements Parcelable { @ColumnInfo(name = "container") private String container; - @ColumnInfo(name = "codec") - private String codec; - - @ColumnInfo(name = "sampleRate") - private int sampleRate; - @ColumnInfo(name = "bitRate") private int bitRate; - @ColumnInfo(name = "bitDepth") - private int bitDepth; - - @ColumnInfo(name = "channels") - private int channels; - @ColumnInfo(name = "added") private long added; @@ -141,7 +120,7 @@ public class Song implements Parcelable { @ColumnInfo(name = "offline") private boolean offline; - public Song(@NonNull String id, String title, int trackNumber, int discNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName, String primary, String blurHash, boolean favorite, String path, long size, String container, String codec, int sampleRate, int bitRate, int bitDepth, int channels, long added, int playCount, long lastPlay, boolean offline) { + public Song(@NonNull String id, String title, int trackNumber, int discNumber, int year, long duration, String albumId, String albumName, String artistId, String artistName, String primary, boolean favorite, String path, long size, String container, int bitRate, long added, int playCount, long lastPlay, boolean offline) { this.id = id; this.title = title; this.trackNumber = trackNumber; @@ -153,16 +132,11 @@ public class Song implements Parcelable { this.artistId = artistId; this.artistName = artistName; this.primary = primary; - this.blurHash = blurHash; this.favorite = favorite; this.path = path; this.size = size; this.container = container; - this.codec = codec; - this.sampleRate = sampleRate; this.bitRate = bitRate; - this.bitDepth = bitDepth; - this.channels = channels; this.added = added; this.playCount = playCount; this.lastPlay = lastPlay; @@ -175,64 +149,24 @@ public class Song implements Parcelable { } @Ignore - public Song(BaseItemDto itemDto) { - this.id = itemDto.getId(); - this.title = itemDto.getName(); - this.trackNumber = itemDto.getIndexNumber() != null ? itemDto.getIndexNumber() : 0; - this.discNumber = itemDto.getParentIndexNumber() != null ? itemDto.getParentIndexNumber() : 0; - this.year = itemDto.getProductionYear() != null ? itemDto.getProductionYear() : 0; - this.duration = itemDto.getRunTimeTicks() != null ? itemDto.getRunTimeTicks() / 10000 : 0; - - this.albumId = itemDto.getAlbumId(); - this.albumName = itemDto.getAlbum(); - - albumArtists = new ArrayList<>(); - artistItems = new ArrayList<>(); - - if (itemDto.getAlbumArtists().size() != 0) { - this.artistId = itemDto.getAlbumArtists().get(0).getId(); - this.artistName = itemDto.getAlbumArtists().get(0).getName(); - - itemDto.getAlbumArtists().forEach(artist -> { - albumArtists.add(new Artist(artist.getId(), artist.getName())); - }); - } - else if (itemDto.getArtistItems().size() != 0) { - this.artistId = itemDto.getArtistItems().get(0).getId(); - this.artistName = itemDto.getArtistItems().get(0).getName(); - - itemDto.getArtistItems().forEach(artist -> { - artistItems.add(new Artist(artist.getId(), artist.getName())); - }); - } - - this.primary = itemDto.getAlbumPrimaryImageTag() != null ? albumId : null; - if (itemDto.getImageBlurHashes() != null && itemDto.getImageBlurHashes().get(ImageType.Primary) != null) { - this.blurHash = (String) itemDto.getImageBlurHashes().get(ImageType.Primary).values().toArray()[0]; - } - - this.favorite = itemDto.getUserData() != null && itemDto.getUserData().getIsFavorite(); - - if (itemDto.getMediaSources() != null && itemDto.getMediaSources().get(0) != null) { - MediaSourceInfo source = itemDto.getMediaSources().get(0); - - this.path = source.getPath(); - this.size = source.getSize() != null ? source.getSize() : 0; - - this.container = source.getContainer(); - this.bitRate = source.getBitrate() != null ? source.getBitrate() : 0; - - if (source.getMediaStreams() != null && source.getMediaStreams().size() != 0) { - MediaStream stream = source.getMediaStreams().get(0); - - this.codec = stream.getCodec(); - this.sampleRate = stream.getSampleRate() != null ? stream.getSampleRate() : 0; - this.bitDepth = stream.getBitDepth() != null ? stream.getBitDepth() : 0; - this.channels = stream.getChannels() != null ? stream.getChannels() : 0; - } - } - - this.added = Instant.now().toEpochMilli(); + public Song(Child child) { + this.id = child.getId(); + this.title = child.getTitle(); + this.trackNumber = child.getTrack(); + this.discNumber = child.getDiscNumber(); + this.year = child.getYear(); + this.duration = child.getDuration(); + this.albumId = child.getAlbumId(); + this.albumName = child.getAlbum(); + this.artistId = child.getArtistId(); + this.artistName = child.getArtist(); + this.primary = child.getCoverArtId(); + this.favorite = child.getStarred() != null; + this.path = child.getPath(); + this.size = child.getSize(); + this.container = child.getContentType(); + this.bitRate = child.getBitRate(); + this.added = child.getCreated().getTime(); this.playCount = 0; this.lastPlay = 0; this.offline = false; @@ -283,10 +217,6 @@ public class Song implements Parcelable { return primary; } - public String getBlurHash() { - return blurHash; - } - public boolean isFavorite() { return favorite; } @@ -303,26 +233,10 @@ public class Song implements Parcelable { return container; } - public String getCodec() { - return codec; - } - - public int getSampleRate() { - return sampleRate; - } - public int getBitRate() { return bitRate; } - public int getBitDepth() { - return bitDepth; - } - - public int getChannels() { - return channels; - } - public long getAdded() { return added; } @@ -383,10 +297,6 @@ public class Song implements Parcelable { this.primary = primary; } - public void setBlurHash(String blurHash) { - this.blurHash = blurHash; - } - public void setFavorite(boolean favorite) { this.favorite = favorite; } @@ -403,26 +313,10 @@ public class Song implements Parcelable { this.container = container; } - public void setCodec(String codec) { - this.codec = codec; - } - - public void setSampleRate(int sampleRate) { - this.sampleRate = sampleRate; - } - public void setBitRate(int bitRate) { this.bitRate = bitRate; } - public void setBitDepth(int bitDepth) { - this.bitDepth = bitDepth; - } - - public void setChannels(int channels) { - this.channels = channels; - } - public void setAdded(long added) { this.added = added; } @@ -481,6 +375,7 @@ public class Song implements Parcelable { return 0; } + @SuppressLint("NewApi") @Override public void writeToParcel(Parcel dest, int flags) { dest.writeString(this.id); @@ -495,21 +390,17 @@ public class Song implements Parcelable { dest.writeString(this.artistName); dest.writeString(this.primary); dest.writeString(Boolean.toString(favorite)); - dest.writeString(this.blurHash); dest.writeString(this.path); dest.writeLong(this.size); dest.writeString(this.container); - dest.writeString(this.codec); - dest.writeInt(this.sampleRate); dest.writeInt(this.bitRate); - dest.writeInt(this.bitDepth); - dest.writeInt(this.channels); dest.writeLong(this.added); dest.writeInt(this.playCount); dest.writeLong(this.lastPlay); dest.writeBoolean(this.offline); } + @SuppressLint("NewApi") protected Song(Parcel in) { this.id = in.readString(); this.title = in.readString(); @@ -523,15 +414,10 @@ public class Song implements Parcelable { this.artistName = in.readString(); this.primary = in.readString(); this.favorite = Boolean.parseBoolean(in.readString()); - this.blurHash = in.readString(); this.path = in.readString(); this.size = in.readLong(); this.container = in.readString(); - this.codec = in.readString(); - this.sampleRate = in.readInt(); this.bitRate = in.readInt(); - this.bitDepth = in.readInt(); - this.channels = in.readInt(); this.added = in.readLong(); this.playCount = in.readInt(); this.lastPlay = in.readLong(); diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java index 1234a4d0..133a49e7 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/Subsonic.java @@ -1,7 +1,13 @@ package com.cappielloantonio.play.subsonic; +import com.cappielloantonio.play.subsonic.api.albumsonglist.AlbumSongListClient; +import com.cappielloantonio.play.subsonic.api.browsing.BrowsingClient; +import com.cappielloantonio.play.subsonic.api.mediaretrieval.MediaRetrievalClient; +import com.cappielloantonio.play.subsonic.api.playlist.PlaylistClient; +import com.cappielloantonio.play.subsonic.api.searching.SearchingClient; import com.cappielloantonio.play.subsonic.api.system.SystemClient; import com.cappielloantonio.play.subsonic.base.Version; +import com.cappielloantonio.play.subsonic.models.Playlist; import java.util.HashMap; import java.util.Map; @@ -14,6 +20,11 @@ public class Subsonic { private Version apiVersion = API_MAX_VERSION; private SystemClient systemClient; + private BrowsingClient browsingClient; + private MediaRetrievalClient mediaRetrievalClient; + private PlaylistClient playlistClient; + private SearchingClient searchingClient; + private AlbumSongListClient albumSongListClient; public Subsonic(SubsonicPreferences preferences) { this.preferences = preferences; @@ -34,6 +45,41 @@ public class Subsonic { return systemClient; } + public BrowsingClient getBrowsingClient() { + if (browsingClient == null) { + browsingClient = new BrowsingClient(this); + } + return browsingClient; + } + + public MediaRetrievalClient getMediaRetrievalClient() { + if (mediaRetrievalClient == null) { + mediaRetrievalClient = new MediaRetrievalClient(this); + } + return mediaRetrievalClient; + } + + public PlaylistClient getPlaylistClient() { + if (playlistClient == null) { + playlistClient = new PlaylistClient(this); + } + return playlistClient; + } + + public SearchingClient getSearchingClient() { + if (searchingClient == null) { + searchingClient = new SearchingClient(this); + } + return searchingClient; + } + + public AlbumSongListClient getAlbumSongListClient() { + if (albumSongListClient == null) { + albumSongListClient = new AlbumSongListClient(this); + } + return albumSongListClient; + } + public String getUrl() { return preferences.getServerUrl() + "/rest/"; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListClient.java b/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListClient.java index 2b1d4160..61db7b05 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListClient.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListClient.java @@ -30,14 +30,14 @@ public class AlbumSongListClient { this.albumSongListService = retrofit.create(AlbumSongListService.class); } - public Call getAlbumList() { + public Call getAlbumList(String type, int size, int offset) { Log.d(TAG, "getAlbumList()"); - return albumSongListService.getAlbumList(subsonic.getParams()); + return albumSongListService.getAlbumList(subsonic.getParams(), type, size, offset); } - public Call getAlbumList2() { + public Call getAlbumList2(String type, int size, int offset) { Log.d(TAG, "getAlbumList2()"); - return albumSongListService.getAlbumList2(subsonic.getParams()); + return albumSongListService.getAlbumList2(subsonic.getParams(), type, size, offset); } public Call getRandomSongs(int size) { @@ -45,9 +45,9 @@ public class AlbumSongListClient { return albumSongListService.getRandomSongs(subsonic.getParams(), size); } - public Call getSongsByGenre(String genre, int count) { + public Call getSongsByGenre(String genre, int count, int offset) { Log.d(TAG, "getSongsByGenre()"); - return albumSongListService.getSongsByGenre(subsonic.getParams(), genre, count); + return albumSongListService.getSongsByGenre(subsonic.getParams(), genre, count, offset); } public Call getNowPlaying() { diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListService.java b/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListService.java index 3916f4b9..74550987 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListService.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/api/albumsonglist/AlbumSongListService.java @@ -6,20 +6,21 @@ import java.util.Map; import retrofit2.Call; import retrofit2.http.GET; +import retrofit2.http.Query; import retrofit2.http.QueryMap; public interface AlbumSongListService { - @GET("getAlbumList?type=random") - Call getAlbumList(@QueryMap Map params); + @GET("getAlbumList") + Call getAlbumList(@QueryMap Map params, @Query("type") String type, @Query("size") int size, @Query("offset") int offset); - @GET("getAlbumList2?type=random") - Call getAlbumList2(@QueryMap Map params); + @GET("getAlbumList2") + Call getAlbumList2(@QueryMap Map params, @Query("type") String type, @Query("size") int size, @Query("offset") int offset); - @GET("getRandomSongs?size={size}") - Call getRandomSongs(@QueryMap Map params, int size); + @GET("getRandomSongs") + Call getRandomSongs(@QueryMap Map params, @Query("size") int size); - @GET("getSongsByGenre?genre={genre}?count={count}") - Call getSongsByGenre(@QueryMap Map params, String genre, int count); + @GET("getSongsByGenre") + Call getSongsByGenre(@QueryMap Map params, @Query("genre") String genre, @Query("count") int count, @Query("offset") int offset); @GET("getNowPlaying") Call getNowPlaying(@QueryMap Map params); diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/api/browsing/BrowsingService.java b/app/src/main/java/com/cappielloantonio/play/subsonic/api/browsing/BrowsingService.java index 9dc3d399..ed06d5be 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/api/browsing/BrowsingService.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/api/browsing/BrowsingService.java @@ -6,6 +6,7 @@ import java.util.Map; import retrofit2.Call; import retrofit2.http.GET; +import retrofit2.http.Query; import retrofit2.http.QueryMap; public interface BrowsingService { @@ -15,8 +16,8 @@ public interface BrowsingService { @GET("getIndexes") Call getIndexes(@QueryMap Map params); - @GET("getMusicDirectory?id={id}") - Call getMusicDirectory(@QueryMap Map params, String id); + @GET("getMusicDirectory") + Call getMusicDirectory(@QueryMap Map params, @Query("id") String id); @GET("getGenres") Call getGenres(@QueryMap Map params); @@ -24,39 +25,39 @@ public interface BrowsingService { @GET("getArtists") Call getArtists(@QueryMap Map params); - @GET("getArtist?id={id}") - Call getArtist(@QueryMap Map params, String id); + @GET("getArtist") + Call getArtist(@QueryMap Map params, @Query("id") String id); - @GET("getAlbum?id={id}") - Call getAlbum(@QueryMap Map params, String id); + @GET("getAlbum") + Call getAlbum(@QueryMap Map params, @Query("id") String id); - @GET("getSong?id={id}") - Call getSong(@QueryMap Map params, String id); + @GET("getSong") + Call getSong(@QueryMap Map params, @Query("id") String id); @GET("getVideos") Call getVideos(@QueryMap Map params); - @GET("getVideoInfo?id={id}") - Call getVideoInfo(@QueryMap Map params, String id); + @GET("getVideoInfo") + Call getVideoInfo(@QueryMap Map params, @Query("id") String id); - @GET("getArtistInfo?id={id}") - Call getArtistInfo(@QueryMap Map params, String id); + @GET("getArtistInfo") + Call getArtistInfo(@QueryMap Map params, @Query("id") String id); - @GET("getArtistInfo2?id={id}") - Call getArtistInfo2(@QueryMap Map params, String id); + @GET("getArtistInfo2") + Call getArtistInfo2(@QueryMap Map params, @Query("id") String id); - @GET("getAlbumInfo?id={id}") - Call getAlbumInfo(@QueryMap Map params, String id); + @GET("getAlbumInfo") + Call getAlbumInfo(@QueryMap Map params, @Query("id") String id); - @GET("getAlbumInfo2?id={id}") - Call getAlbumInfo2(@QueryMap Map params, String id); + @GET("getAlbumInfo2") + Call getAlbumInfo2(@QueryMap Map params, @Query("id") String id); - @GET("getSimilarSongs?id={id}?count={count}") - Call getSimilarSongs(@QueryMap Map params, String id, int count); + @GET("getSimilarSongs") + Call getSimilarSongs(@QueryMap Map params, @Query("id") String id, @Query("count") int count); - @GET("getSimilarSongs2?id={id}?count={count}") - Call getSimilarSongs2(@QueryMap Map params, String id, int count); + @GET("getSimilarSongs2") + Call getSimilarSongs2(@QueryMap Map params, @Query("id") String id, @Query("count") int count); - @GET("getTopSongs?id={id}?count={count}") - Call getTopSongs(@QueryMap Map params, String id, int count); + @GET("getTopSongs") + Call getTopSongs(@QueryMap Map params, @Query("id") String id, @Query("count") int count); } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumID3.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumID3.java index 0f6e7452..6a9b3c47 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumID3.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumID3.java @@ -1,247 +1,132 @@ package com.cappielloantonio.play.subsonic.models; -import java.time.LocalDateTime; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Xml; +import com.tickaroo.tikxml.converters.date.rfc3339.DateRfc3339TypeConverter; +import java.time.LocalDateTime; +import java.util.Date; + +@Xml(name = "album") public class AlbumID3 { + @Attribute protected String id; + @Attribute protected String name; + @Attribute protected String artist; + @Attribute protected String artistId; + @Attribute protected String coverArtId; + @Attribute protected int songCount; + @Attribute protected int duration; + @Attribute protected Long playCount; - protected LocalDateTime created; - protected LocalDateTime starred; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date created; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date starred; + @Attribute protected Integer year; + @Attribute protected String genre; - /** - * Gets the value of the id property. - * - * @return possible object is - * {@link String } - */ public String getId() { return id; } - /** - * Sets the value of the id property. - * - * @param value allowed object is - * {@link String } - */ public void setId(String value) { this.id = value; } - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ public String getName() { return name; } - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ public void setName(String value) { this.name = value; } - /** - * Gets the value of the artist property. - * - * @return possible object is - * {@link String } - */ public String getArtist() { return artist; } - /** - * Sets the value of the artist property. - * - * @param value allowed object is - * {@link String } - */ public void setArtist(String value) { this.artist = value; } - /** - * Gets the value of the artistId property. - * - * @return possible object is - * {@link String } - */ public String getArtistId() { return artistId; } - /** - * Sets the value of the artistId property. - * - * @param value allowed object is - * {@link String } - */ public void setArtistId(String value) { this.artistId = value; } - /** - * Gets the value of the coverArtId property. - * - * @return possible object is - * {@link String } - */ public String getCoverArtId() { return coverArtId; } - /** - * Sets the value of the coverArtId property. - * - * @param value allowed object is - * {@link String } - */ public void setCoverArtId(String value) { this.coverArtId = value; } - /** - * Gets the value of the songCount property. - */ public int getSongCount() { return songCount; } - /** - * Sets the value of the songCount property. - */ public void setSongCount(int value) { this.songCount = value; } - /** - * Gets the value of the duration property. - */ public int getDuration() { return duration; } - /** - * Sets the value of the duration property. - */ public void setDuration(int value) { this.duration = value; } - /** - * Gets the value of the playCount property. - * - * @return possible object is - * {@link Long } - */ public Long getPlayCount() { return playCount; } - /** - * Sets the value of the playCount property. - * - * @param value allowed object is - * {@link Long } - */ public void setPlayCount(Long value) { this.playCount = value; } - /** - * Gets the value of the created property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getCreated() { + public Date getCreated() { return created; } - /** - * Sets the value of the created property. - * - * @param value allowed object is - * {@link String } - */ - public void setCreated(LocalDateTime value) { + public void setCreated(Date value) { this.created = value; } - /** - * Gets the value of the starred property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getStarred() { + public Date getStarred() { return starred; } - /** - * Sets the value of the starred property. - * - * @param value allowed object is - * {@link String } - */ - public void setStarred(LocalDateTime value) { + public void setStarred(Date value) { this.starred = value; } - /** - * Gets the value of the year property. - * - * @return possible object is - * {@link Integer } - */ public Integer getYear() { return year; } - /** - * Sets the value of the year property. - * - * @param value allowed object is - * {@link Integer } - */ public void setYear(Integer value) { this.year = value; } - /** - * Gets the value of the genre property. - * - * @return possible object is - * {@link String } - */ public String getGenre() { return genre; } - /** - * Sets the value of the genre property. - * - * @param value allowed object is - * {@link String } - */ public void setGenre(String value) { this.genre = value; } - } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumList2.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumList2.java index 97999c19..12797881 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumList2.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumList2.java @@ -1,36 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class AlbumList2 { + @Element protected List albums; - /** - * Gets the value of the albums property. - * - *

- * 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 set method for the albums property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getAlbums().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link AlbumID3 } - */ public List getAlbums() { if (albums == null) { - albums = new ArrayList(); + albums = new ArrayList<>(); } return this.albums; } + public void setAlbums(List albums) { + this.albums = albums; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumWithSongsID3.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumWithSongsID3.java index a959c7bb..dc8158d2 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumWithSongsID3.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/AlbumWithSongsID3.java @@ -1,36 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class AlbumWithSongsID3 extends AlbumID3 { + @Element(name = "song") protected List songs; - - /** - * Gets the value of the songs property. - * - *

- * 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 set method for the songs property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getSongs().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link Child } - */ + public List getSongs() { if (songs == null) { - songs = new ArrayList(); + songs = new ArrayList<>(); } return this.songs; } + public void setSongs(List songs) { + this.songs = songs; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistID3.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistID3.java index 36198387..11115ed4 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistID3.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistID3.java @@ -1,105 +1,65 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Xml; +import com.tickaroo.tikxml.converters.date.rfc3339.DateRfc3339TypeConverter; + import java.time.LocalDateTime; +import java.util.Date; +@Xml public class ArtistID3 { + @Attribute protected String id; + @Attribute protected String name; + @Attribute(name = "coverArt") protected String coverArtId; + @Attribute protected int albumCount; - protected LocalDateTime starred; - - /** - * Gets the value of the id property. - * - * @return possible object is - * {@link String } - */ + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date starred; + public String getId() { return id; } - - /** - * Sets the value of the id property. - * - * @param value allowed object is - * {@link String } - */ + public void setId(String value) { this.id = value; } - - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ + public String getName() { return name; } - - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ + public void setName(String value) { this.name = value; } - /** - * Gets the value of the coverArtId property. - * - * @return possible object is - * {@link String } - */ public String getCoverArtId() { return coverArtId; } - /** - * Sets the value of the coverArtId property. - * - * @param value allowed object is - * {@link String } - */ + public void setCoverArtId(String value) { this.coverArtId = value; } - /** - * Gets the value of the albumCount property. - */ + public int getAlbumCount() { return albumCount; } - /** - * Sets the value of the albumCount property. - */ + public void setAlbumCount(int value) { this.albumCount = value; } - /** - * Gets the value of the starred property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getStarred() { + public Date getStarred() { return starred; } - /** - * Sets the value of the starred property. - * - * @param value allowed object is - * {@link String } - */ - public void setStarred(LocalDateTime value) { + public void setStarred(Date value) { this.starred = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistsID3.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistsID3.java index 9984f548..7a1530b0 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistsID3.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/ArtistsID3.java @@ -1,55 +1,32 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class ArtistsID3 { + @Element(name = "index") protected List indices; protected String ignoredArticles; - /** - * Gets the value of the indices property. - * - *

- * 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 set method for the indices property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getIndices().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link IndexID3 } - */ public List getIndices() { if (indices == null) { - indices = new ArrayList(); + indices = new ArrayList<>(); } return this.indices; } - /** - * Gets the value of the ignoredArticles property. - * - * @return possible object is - * {@link String } - */ + public void setIndices(List indices) { + this.indices = indices; + } + public String getIgnoredArticles() { return ignoredArticles; } - /** - * Sets the value of the ignoredArticles property. - * - * @param value allowed object is - * {@link String } - */ public void setIgnoredArticles(String value) { this.ignoredArticles = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Child.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Child.java index 61bd8f6f..92df49b1 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Child.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Child.java @@ -1,650 +1,322 @@ package com.cappielloantonio.play.subsonic.models; -import java.time.LocalDateTime; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; +import com.tickaroo.tikxml.converters.date.rfc3339.DateRfc3339TypeConverter; +import java.util.Date; + +@Xml public class Child { + @Attribute protected String id; + @Attribute(name = "parent") protected String parentId; + @Attribute(name = "isDir") protected boolean dir; + @Attribute protected String title; + @Attribute protected String album; + @Attribute protected String artist; + @Attribute protected Integer track; + @Attribute protected Integer year; + @Attribute(name = "genre") protected String genre; + @Attribute(name = "coverArt") protected String coverArtId; + @Attribute protected Long size; + @Attribute protected String contentType; + @Attribute protected String suffix; + @Attribute protected String transcodedContentType; + @Attribute protected String transcodedSuffix; + @Attribute protected Integer duration; + @Attribute protected Integer bitRate; + @Attribute protected String path; + @Attribute(name = "isVideo") protected Boolean video; + @Attribute protected Integer userRating; + @Attribute protected Double averageRating; + @Attribute protected Long playCount; + @Attribute protected Integer discNumber; - protected LocalDateTime created; - protected LocalDateTime starred; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date created; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date starred; + @Attribute protected String albumId; + @Attribute protected String artistId; + @Element protected MediaType type; + @Attribute protected Long bookmarkPosition; + @Attribute protected Integer originalWidth; + @Attribute protected Integer originalHeight; - /** - * Gets the value of the id property. - * - * @return possible object is - * {@link String } - */ + @Attribute public String getId() { return id; } - /** - * Sets the value of the id property. - * - * @param value allowed object is - * {@link String } - */ public void setId(String value) { this.id = value; } - /** - * Gets the value of the parentId property. - * - * @return possible object is - * {@link String } - */ public String getParentId() { return parentId; } - /** - * Sets the value of the parentId property. - * - * @param value allowed object is - * {@link String } - */ public void setParentId(String value) { this.parentId = value; } - /** - * Gets the value of the dir property. - */ public boolean isDir() { return dir; } - /** - * Sets the value of the dir property. - */ public void setDir(boolean value) { this.dir = value; } - /** - * Gets the value of the title property. - * - * @return possible object is - * {@link String } - */ public String getTitle() { return title; } - /** - * Sets the value of the title property. - * - * @param value allowed object is - * {@link String } - */ public void setTitle(String value) { this.title = value; } - /** - * Gets the value of the album property. - * - * @return possible object is - * {@link String } - */ public String getAlbum() { return album; } - /** - * Sets the value of the album property. - * - * @param value allowed object is - * {@link String } - */ public void setAlbum(String value) { this.album = value; } - /** - * Gets the value of the artist property. - * - * @return possible object is - * {@link String } - */ public String getArtist() { return artist; } - /** - * Sets the value of the artist property. - * - * @param value allowed object is - * {@link String } - */ public void setArtist(String value) { this.artist = value; } - /** - * Gets the value of the track property. - * - * @return possible object is - * {@link Integer } - */ public Integer getTrack() { return track; } - /** - * Sets the value of the track property. - * - * @param value allowed object is - * {@link Integer } - */ public void setTrack(Integer value) { this.track = value; } - /** - * Gets the value of the year property. - * - * @return possible object is - * {@link Integer } - */ public Integer getYear() { return year; } - /** - * Sets the value of the year property. - * - * @param value allowed object is - * {@link Integer } - */ public void setYear(Integer value) { this.year = value; } - /** - * Gets the value of the genre property. - * - * @return possible object is - * {@link String } - */ public String getGenre() { return genre; } - /** - * Sets the value of the genre property. - * - * @param value allowed object is - * {@link String } - */ public void setGenre(String value) { this.genre = value; } - /** - * Gets the value of the coverArtId property. - * - * @return possible object is - * {@link String } - */ public String getCoverArtId() { return coverArtId; } - /** - * Sets the value of the coverArtId property. - * - * @param value allowed object is - * {@link String } - */ public void setCoverArtId(String value) { this.coverArtId = value; } - /** - * Gets the value of the size property. - * - * @return possible object is - * {@link Long } - */ public Long getSize() { return size; } - /** - * Sets the value of the size property. - * - * @param value allowed object is - * {@link Long } - */ public void setSize(Long value) { this.size = value; } - /** - * Gets the value of the contentType property. - * - * @return possible object is - * {@link String } - */ public String getContentType() { return contentType; } - /** - * Sets the value of the contentType property. - * - * @param value allowed object is - * {@link String } - */ public void setContentType(String value) { this.contentType = value; } - /** - * Gets the value of the suffix property. - * - * @return possible object is - * {@link String } - */ public String getSuffix() { return suffix; } - /** - * Sets the value of the suffix property. - * - * @param value allowed object is - * {@link String } - */ public void setSuffix(String value) { this.suffix = value; } - /** - * Gets the value of the transcodedContentType property. - * - * @return possible object is - * {@link String } - */ public String getTranscodedContentType() { return transcodedContentType; } - /** - * Sets the value of the transcodedContentType property. - * - * @param value allowed object is - * {@link String } - */ public void setTranscodedContentType(String value) { this.transcodedContentType = value; } - /** - * Gets the value of the transcodedSuffix property. - * - * @return possible object is - * {@link String } - */ public String getTranscodedSuffix() { return transcodedSuffix; } - /** - * Sets the value of the transcodedSuffix property. - * - * @param value allowed object is - * {@link String } - */ public void setTranscodedSuffix(String value) { this.transcodedSuffix = value; } - /** - * Gets the value of the duration property. - * - * @return possible object is - * {@link Integer } - */ public Integer getDuration() { return duration; } - /** - * Sets the value of the duration property. - * - * @param value allowed object is - * {@link Integer } - */ public void setDuration(Integer value) { this.duration = value; } - /** - * Gets the value of the bitRate property. - * - * @return possible object is - * {@link Integer } - */ public Integer getBitRate() { return bitRate; } - /** - * Sets the value of the bitRate property. - * - * @param value allowed object is - * {@link Integer } - */ public void setBitRate(Integer value) { this.bitRate = value; } - /** - * Gets the value of the path property. - * - * @return possible object is - * {@link String } - */ public String getPath() { return path; } - /** - * Sets the value of the path property. - * - * @param value allowed object is - * {@link String } - */ public void setPath(String value) { this.path = value; } - /** - * Gets the value of the video property. - * - * @return possible object is - * {@link Boolean } - */ public Boolean isVideo() { return video; } - /** - * Sets the value of the video property. - * - * @param value allowed object is - * {@link Boolean } - */ public void setVideo(Boolean value) { this.video = value; } - /** - * Gets the value of the userRating property. - * - * @return possible object is - * {@link Integer } - */ public Integer getUserRating() { return userRating; } - /** - * Sets the value of the userRating property. - * - * @param value allowed object is - * {@link Integer } - */ public void setUserRating(Integer value) { this.userRating = value; } - /** - * Gets the value of the averageRating property. - * - * @return possible object is - * {@link Double } - */ public Double getAverageRating() { return averageRating; } - /** - * Sets the value of the averageRating property. - * - * @param value allowed object is - * {@link Double } - */ public void setAverageRating(Double value) { this.averageRating = value; } - /** - * Gets the value of the playCount property. - * - * @return possible object is - * {@link Long } - */ public Long getPlayCount() { return playCount; } - /** - * Sets the value of the playCount property. - * - * @param value allowed object is - * {@link Long } - */ public void setPlayCount(Long value) { this.playCount = value; } - /** - * Gets the value of the discNumber property. - * - * @return possible object is - * {@link Integer } - */ public Integer getDiscNumber() { return discNumber; } - /** - * Sets the value of the discNumber property. - * - * @param value allowed object is - * {@link Integer } - */ public void setDiscNumber(Integer value) { this.discNumber = value; } - /** - * Gets the value of the created property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getCreated() { + public Date getCreated() { return created; } - /** - * Sets the value of the created property. - * - * @param value allowed object is - * {@link String } - */ - public void setCreated(LocalDateTime value) { + public void setCreated(Date value) { this.created = value; } - /** - * Gets the value of the starred property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getStarred() { + public Date getStarred() { return starred; } - /** - * Sets the value of the starred property. - * - * @param value allowed object is - * {@link String } - */ - public void setStarred(LocalDateTime value) { + public void setStarred(Date value) { this.starred = value; } - /** - * Gets the value of the albumId property. - * - * @return possible object is - * {@link String } - */ public String getAlbumId() { return albumId; } - /** - * Sets the value of the albumId property. - * - * @param value allowed object is - * {@link String } - */ public void setAlbumId(String value) { this.albumId = value; } - /** - * Gets the value of the artistId property. - * - * @return possible object is - * {@link String } - */ public String getArtistId() { return artistId; } - /** - * Sets the value of the artistId property. - * - * @param value allowed object is - * {@link String } - */ public void setArtistId(String value) { this.artistId = value; } - /** - * Gets the value of the type property. - * - * @return possible object is - * {@link MediaType } - */ public MediaType getType() { return type; } - /** - * Sets the value of the type property. - * - * @param value allowed object is - * {@link MediaType } - */ public void setType(MediaType value) { this.type = value; } - /** - * Gets the value of the bookmarkPosition property. - * - * @return possible object is - * {@link Long } - */ public Long getBookmarkPosition() { return bookmarkPosition; } - /** - * Sets the value of the bookmarkPosition property. - * - * @param value allowed object is - * {@link Long } - */ public void setBookmarkPosition(Long value) { this.bookmarkPosition = value; } - /** - * Gets the value of the originalWidth property. - * - * @return possible object is - * {@link Integer } - */ public Integer getOriginalWidth() { return originalWidth; } - /** - * Sets the value of the originalWidth property. - * - * @param value allowed object is - * {@link Integer } - */ public void setOriginalWidth(Integer value) { this.originalWidth = value; } - /** - * Gets the value of the originalHeight property. - * - * @return possible object is - * {@link Integer } - */ public Integer getOriginalHeight() { return originalHeight; } - /** - * Sets the value of the originalHeight property. - * - * @param value allowed object is - * {@link Integer } - */ public void setOriginalHeight(Integer value) { this.originalHeight = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genre.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genre.java index 22173424..117431f6 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genre.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genre.java @@ -1,54 +1,38 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.TextContent; +import com.tickaroo.tikxml.annotation.Xml; + +@Xml public class Genre { - protected String name; + @TextContent + protected String genre; + @Attribute protected int songCount; + @Attribute protected int albumCount; - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ - public String getName() { - return name; + public String getGenre() { + return genre; } - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ - public void setName(String value) { - this.name = value; + public void setGenre(String value) { + this.genre = value; } - /** - * Gets the value of the songCount property. - */ public int getSongCount() { return songCount; } - /** - * Sets the value of the songCount property. - */ public void setSongCount(int value) { this.songCount = value; } - /** - * Gets the value of the albumCount property. - */ public int getAlbumCount() { return albumCount; } - /** - * Sets the value of the albumCount property. - */ public void setAlbumCount(int value) { this.albumCount = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genres.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genres.java index 2c7a22d7..6458719a 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genres.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Genres.java @@ -1,35 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class Genres { + @Element protected List genres; - /** - * Gets the value of the genres property. - * - *

- * 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 set method for the genres property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getGenres().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link Genre } - */ public List getGenres() { if (genres == null) { - genres = new ArrayList(); + genres = new ArrayList<>(); } return this.genres; } + + public void setGenres(List genres) { + this.genres = genres; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/IndexID3.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/IndexID3.java index 5b47b670..cb31eeae 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/IndexID3.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/IndexID3.java @@ -1,55 +1,32 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class IndexID3 { + @Element(name = "artist") protected List artists; protected String name; - /** - * Gets the value of the artists property. - * - *

- * 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 set method for the artists property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getArtists().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link ArtistID3 } - */ public List getArtists() { if (artists == null) { - artists = new ArrayList(); + artists = new ArrayList<>(); } return this.artists; } - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ + public void setArtists(List artists) { + this.artists = artists; + } + public String getName() { return name; } - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ public void setName(String value) { this.name = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MediaType.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MediaType.java index 5c2498f7..3cd6a2e1 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MediaType.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MediaType.java @@ -1,27 +1,23 @@ package com.cappielloantonio.play.subsonic.models; -public enum MediaType { - MUSIC("music"), - PODCAST("podcast"), - AUDIOBOOK("audiobook"), - VIDEO("video"); +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Xml; - private final String value; +@Xml +public class MediaType { + public static String MUSIC = "music"; + public static String PODCAST = "podcast"; + public static String AUDIOBOOK = "audiobook"; + public static String VIDEO = "video"; - MediaType(String v) { - value = v; - } + @Attribute + private String value; - public String value() { + public String getValue() { return value; } - public static MediaType fromValue(String v) { - for (MediaType c : MediaType.values()) { - if (c.value.equals(v)) { - return c; - } - } - throw new IllegalArgumentException(v); + public void setValue(String value) { + this.value = value; } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolder.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolder.java index 159a20ae..fdaed933 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolder.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolder.java @@ -1,39 +1,27 @@ package com.cappielloantonio.play.subsonic.models; -public class MusicFolder { - protected int id; - protected String name; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Xml; - /** - * Gets the value of the id property. - */ +@Xml +public class MusicFolder { + @Attribute + protected int id; + @Attribute + protected String name; + public int getId() { return id; } - /** - * Sets the value of the id property. - */ public void setId(int value) { this.id = value; } - - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ + public String getName() { return name; } - - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ + public void setName(String value) { this.name = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolders.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolders.java index 393c1a42..016bdb42 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolders.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/MusicFolders.java @@ -1,36 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class MusicFolders { + @Element protected List musicFolders; - /** - * Gets the value of the musicFolders property. - * - *

- * 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 set method for the musicFolders property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getMusicFolders().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link MusicFolder } - */ public List getMusicFolders() { if (musicFolders == null) { - musicFolders = new ArrayList(); + musicFolders = new ArrayList<>(); } return this.musicFolders; } + public void setMusicFolders(List musicFolders) { + this.musicFolders = musicFolders; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlist.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlist.java index b0cc26f5..643e2d69 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlist.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlist.java @@ -1,233 +1,126 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Attribute; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; +import com.tickaroo.tikxml.converters.date.rfc3339.DateRfc3339TypeConverter; + import java.time.LocalDateTime; import java.util.ArrayList; +import java.util.Date; import java.util.List; +@Xml public class Playlist { protected List allowedUsers; + @Attribute protected String id; + @Attribute protected String name; + @Attribute protected String comment; + @Attribute protected String owner; - protected Boolean _public; + @Attribute(name = "public") + protected Boolean universal; + @Attribute protected int songCount; + @Attribute protected int duration; - protected LocalDateTime created; - protected LocalDateTime changed; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date created; + @Attribute(converter = DateRfc3339TypeConverter.class) + protected Date changed; + @Attribute protected String coverArtId; - - /** - * Gets the value of the allowedUsers property. - * - *

- * 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 set method for the allowedUsers property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getAllowedUsers().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link String } - */ + public List getAllowedUsers() { if (allowedUsers == null) { - allowedUsers = new ArrayList(); + allowedUsers = new ArrayList<>(); } return this.allowedUsers; } - /** - * Gets the value of the id property. - * - * @return possible object is - * {@link String } - */ + public void setAllowedUsers(List allowedUsers) { + this.allowedUsers = allowedUsers; + } + public String getId() { return id; } - - /** - * Sets the value of the id property. - * - * @param value allowed object is - * {@link String } - */ + public void setId(String value) { this.id = value; } - /** - * Gets the value of the name property. - * - * @return possible object is - * {@link String } - */ public String getName() { return name; } - - /** - * Sets the value of the name property. - * - * @param value allowed object is - * {@link String } - */ + public void setName(String value) { this.name = value; } - /** - * Gets the value of the comment property. - * - * @return possible object is - * {@link String } - */ public String getComment() { return comment; } - /** - * Sets the value of the comment property. - * - * @param value allowed object is - * {@link String } - */ public void setComment(String value) { this.comment = value; } - /** - * Gets the value of the owner property. - * - * @return possible object is - * {@link String } - */ public String getOwner() { return owner; } - - /** - * Sets the value of the owner property. - * - * @param value allowed object is - * {@link String } - */ + public void setOwner(String value) { this.owner = value; } - /** - * Gets the value of the public property. - * - * @return possible object is - * {@link Boolean } - */ - public Boolean isPublic() { - return _public; + public Boolean isUniversal() { + return universal; } - /** - * Sets the value of the public property. - * - * @param value allowed object is - * {@link Boolean } - */ - public void setPublic(Boolean value) { - this._public = value; + public void setUniversal(Boolean value) { + this.universal = value; } - /** - * Gets the value of the songCount property. - */ public int getSongCount() { return songCount; } - - /** - * Sets the value of the songCount property. - */ + public void setSongCount(int value) { this.songCount = value; } - - /** - * Gets the value of the duration property. - */ + public int getDuration() { return duration; } - - /** - * Sets the value of the duration property. - */ + public void setDuration(int value) { this.duration = value; } - - /** - * Gets the value of the created property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getCreated() { + + public Date getCreated() { return created; } - /** - * Sets the value of the created property. - * - * @param value allowed object is - * {@link String } - */ - public void setCreated(LocalDateTime value) { + public void setCreated(Date value) { this.created = value; } - - /** - * Gets the value of the changed property. - * - * @return possible object is - * {@link String } - */ - public LocalDateTime getChanged() { + + public Date getChanged() { return changed; } - /** - * Sets the value of the changed property. - * - * @param value allowed object is - * {@link String } - */ - public void setChanged(LocalDateTime value) { + public void setChanged(Date value) { this.changed = value; } - /** - * Gets the value of the coverArtId property. - * - * @return possible object is - * {@link String } - */ public String getCoverArtId() { return coverArtId; } - /** - * Sets the value of the coverArtId property. - * - * @param value allowed object is - * {@link String } - */ public void setCoverArtId(String value) { this.coverArtId = value; } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/PlaylistWithSongs.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/PlaylistWithSongs.java index 2d2f63b6..d03a8c3c 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/PlaylistWithSongs.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/PlaylistWithSongs.java @@ -1,35 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class PlaylistWithSongs extends Playlist { + @Element(name = "entry") protected List entries; - /** - * Gets the value of the entries property. - * - *

- * 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 set method for the entries property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getEntries().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link Child } - */ public List getEntries() { if (entries == null) { - entries = new ArrayList(); + entries = new ArrayList<>(); } return this.entries; } + + public void setEntries(List entries) { + this.entries = entries; + } } diff --git a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlists.java b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlists.java index 66ec8629..bb90eb8d 100644 --- a/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlists.java +++ b/app/src/main/java/com/cappielloantonio/play/subsonic/models/Playlists.java @@ -1,35 +1,24 @@ package com.cappielloantonio.play.subsonic.models; +import com.tickaroo.tikxml.annotation.Element; +import com.tickaroo.tikxml.annotation.Xml; + import java.util.ArrayList; import java.util.List; +@Xml public class Playlists { + @Element protected List playlists; - /** - * Gets the value of the playlists property. - * - *

- * 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 set method for the playlists property. - * - *

- * For example, to add a new item, do as follows: - *

-     *    getPlaylists().add(newItem);
-     * 
- * - * - *

- * Objects of the following type(s) are allowed in the list - * {@link Playlist } - */ public List getPlaylists() { if (playlists == null) { - playlists = new ArrayList(); + playlists = new ArrayList<>(); } return this.playlists; } + + public void setPlaylists(List playlists) { + this.playlists = playlists; + } } 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 ef388a3c..dfd137ab 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 @@ -27,6 +27,7 @@ public class SubsonicResponse { private Lyrics lyrics; private Songs songsByGenre; private Songs randomSongs; + @Element private AlbumList2 albumList2; private AlbumList albumList; private ChatMessages chatMessages; @@ -35,7 +36,9 @@ public class SubsonicResponse { private License license; private JukeboxPlaylist jukeboxPlaylist; private JukeboxStatus jukeboxStatus; + @Element private PlaylistWithSongs playlist; + @Element private Playlists playlists; private SearchResult3 searchResult3; private SearchResult2 searchResult2; @@ -44,12 +47,16 @@ public class SubsonicResponse { private VideoInfo videoInfo; private Videos videos; private Child song; + @Element(name = "album") private AlbumWithSongsID3 album; private ArtistWithAlbumsID3 artist; + @Element(name = "artists") private ArtistsID3 artists; + @Element private Genres genres; private Directory directory; private Indexes indexes; + @Element private MusicFolders musicFolders; @Attribute(converter = ResponseStatusConverter.class) private ResponseStatus status; diff --git a/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java b/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java index 0038d720..f5cdc68d 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/activity/MainActivity.java @@ -217,11 +217,11 @@ public class MainActivity extends BaseActivity { setBottomSheetVisibility(false); if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.loginFragment) { - Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true, true); + Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true); navController.navigate(R.id.action_loginFragment_to_syncFragment, bundle); } else if (Objects.requireNonNull(navController.getCurrentDestination()).getId() == R.id.landingFragment) { - Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true, true); + Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true); navController.navigate(R.id.action_landingFragment_to_syncFragment, bundle); } } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/LoginFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/LoginFragment.java index 8072c992..19031a18 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/LoginFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/LoginFragment.java @@ -14,11 +14,16 @@ import androidx.fragment.app.Fragment; import com.cappielloantonio.play.App; import com.cappielloantonio.play.databinding.FragmentLoginBinding; +import com.cappielloantonio.play.helper.ErrorHelper; +import com.cappielloantonio.play.subsonic.models.Genre; import com.cappielloantonio.play.subsonic.models.ResponseStatus; import com.cappielloantonio.play.subsonic.models.SubsonicResponse; import com.cappielloantonio.play.ui.activity.MainActivity; import com.cappielloantonio.play.util.PreferenceUtil; +import java.util.ArrayList; +import java.util.List; + import retrofit2.Call; import retrofit2.Callback; @@ -91,21 +96,22 @@ public class LoginFragment extends Fragment { @Override public void onResponse(Call call, retrofit2.Response response) { if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { - int code = response.body().getError().getCode().getValue(); - String message = response.body().getError().getMessage(); - Toast.makeText(requireContext(), code + " - " + message, Toast.LENGTH_LONG).show(); + ErrorHelper.handle(requireContext(), response.body().getError().getCode().getValue(), response.body().getError().getMessage()); } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { - Toast.makeText(requireContext(), response.body().getStatus().getValue(), Toast.LENGTH_LONG).show(); + enter(); } else { Toast.makeText(requireContext(), "Empty response", Toast.LENGTH_LONG).show(); } } - @Override public void onFailure(Call call, Throwable t) { - Log.d(TAG, "+++ " + t.getMessage()); + Log.e(TAG, t.getMessage()); Toast.makeText(requireContext(), t.getMessage(), Toast.LENGTH_LONG).show(); } }); } + + private void enter() { + activity.goFromLogin(); + } } diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SettingsFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SettingsFragment.java index 63a1cfb3..312554a1 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SettingsFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SettingsFragment.java @@ -64,7 +64,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { PreferenceUtil.getInstance(requireContext()).setSync(false); PreferenceUtil.getInstance(requireContext()).setSongGenreSync(false); - Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true, true); + Bundle bundle = SyncUtil.getSyncBundle(true, true, true, true, true); activity.goFromSettingsToSync(bundle); }) .show(); @@ -78,7 +78,7 @@ public class SettingsFragment extends PreferenceFragmentCompat { .setTitle("Force sync playlist") .setNegativeButton(R.string.ignore, null) .setPositiveButton("Sync", (dialog, id) -> { - Bundle bundle = SyncUtil.getSyncBundle(false, false, false, true, false, false); + Bundle bundle = SyncUtil.getSyncBundle(false, false, false, true, false); activity.goFromSettingsToSync(bundle); }) .show(); diff --git a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SyncFragment.java b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SyncFragment.java index d058dfee..b0a27b09 100644 --- a/app/src/main/java/com/cappielloantonio/play/ui/fragment/SyncFragment.java +++ b/app/src/main/java/com/cappielloantonio/play/ui/fragment/SyncFragment.java @@ -17,12 +17,10 @@ import com.cappielloantonio.play.interfaces.MediaCallback; import com.cappielloantonio.play.model.Album; import com.cappielloantonio.play.model.AlbumArtistCross; import com.cappielloantonio.play.model.Artist; -import com.cappielloantonio.play.model.Genre; import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.model.PlaylistSongCross; import com.cappielloantonio.play.model.Song; import com.cappielloantonio.play.model.SongArtistCross; -import com.cappielloantonio.play.model.SongGenreCross; import com.cappielloantonio.play.repository.AlbumArtistRepository; import com.cappielloantonio.play.repository.AlbumRepository; import com.cappielloantonio.play.repository.ArtistRepository; @@ -32,6 +30,10 @@ import com.cappielloantonio.play.repository.PlaylistSongRepository; import com.cappielloantonio.play.repository.SongArtistRepository; import com.cappielloantonio.play.repository.SongGenreRepository; import com.cappielloantonio.play.repository.SongRepository; +import com.cappielloantonio.play.subsonic.models.AlbumID3; +import com.cappielloantonio.play.subsonic.models.ArtistID3; +import com.cappielloantonio.play.subsonic.models.Child; +import com.cappielloantonio.play.subsonic.models.Genre; import com.cappielloantonio.play.ui.activity.MainActivity; import com.cappielloantonio.play.util.DownloadUtil; import com.cappielloantonio.play.util.PreferenceUtil; @@ -39,8 +41,6 @@ import com.cappielloantonio.play.util.SyncUtil; import com.cappielloantonio.play.util.Util; import com.cappielloantonio.play.viewmodel.SyncViewModel; -import org.jellyfin.apiclient.model.dto.BaseItemDto; - import java.util.ArrayList; import java.util.List; @@ -56,9 +56,6 @@ public class SyncFragment extends Fragment { private ArtistRepository artistRepository; private PlaylistRepository playlistRepository; private GenreRepository genreRepository; - private SongGenreRepository songGenreRepository; - private SongArtistRepository songArtistRepository; - private AlbumArtistRepository albumArtistRepository; private PlaylistSongRepository playlistSongRepository; private final int LIBRARIES = 0; @@ -67,8 +64,7 @@ public class SyncFragment extends Fragment { private final int GENRES = 3; private final int PLAYLISTS = 4; private final int SONGS = 5; - private final int SONG_X_GENRE = 6; - private final int SONG_X_PLAYLIST = 7; + private final int SONG_X_PLAYLIST = 6; @Nullable @Override @@ -84,9 +80,6 @@ public class SyncFragment extends Fragment { artistRepository = new ArtistRepository(activity.getApplication()); playlistRepository = new PlaylistRepository(activity.getApplication()); genreRepository = new GenreRepository(activity.getApplication()); - songGenreRepository = new SongGenreRepository(activity.getApplication()); - songArtistRepository = new SongArtistRepository(activity.getApplication()); - albumArtistRepository = new AlbumArtistRepository(activity.getApplication()); playlistSongRepository = new PlaylistSongRepository(activity.getApplication()); init(); @@ -105,7 +98,6 @@ public class SyncFragment extends Fragment { private void init() { syncViewModel.setArguemnts(getArguments()); - bind.syncingDateLabel.setText(Util.getDate()); } @@ -116,8 +108,6 @@ public class SyncFragment extends Fragment { if (!syncViewModel.isSyncPlaylist()) bind.syncPlaylistsSector.setVisibility(View.GONE); if (!syncViewModel.isSyncPlaylist()) bind.syncSongXPlaylistSector.setVisibility(View.GONE); if (!syncViewModel.isSyncSong()) bind.syncSongsSector.setVisibility(View.GONE); - if (!syncViewModel.isCrossSyncSongGenre()) - bind.syncSongXGenreSector.setVisibility(View.GONE); } private void initButtonListeners() { @@ -127,7 +117,7 @@ public class SyncFragment extends Fragment { }); bind.syncAlbumsRetryImageView.setOnClickListener(v -> { resetSectorInfo(ALBUMS); - syncAlbums(); + syncAlbums(500, 0, 0); }); bind.syncArtistsRetryImageView.setOnClickListener(v -> { resetSectorInfo(ARTISTS); @@ -141,18 +131,14 @@ public class SyncFragment extends Fragment { resetSectorInfo(PLAYLISTS); syncPlaylist(); }); - bind.syncSongsRetryImageView.setOnClickListener(v -> { - resetSectorInfo(SONGS); - syncSongs(); - }); - bind.syncSongXGenreRetryImageView.setOnClickListener(v -> { - resetSectorInfo(SONG_X_GENRE); - syncSongsPerGenre(syncViewModel.getGenreList()); - }); bind.syncSongXPlaylistRetryImageView.setOnClickListener(v -> { resetSectorInfo(SONG_X_PLAYLIST); syncSongsPerPlaylist(syncViewModel.getPlaylistList()); }); + bind.syncSongsRetryImageView.setOnClickListener(v -> { + resetSectorInfo(SONGS); + syncSongs(); + }); bind.syncingGoHomeImageView.setOnClickListener(v -> { AlertDialog.Builder builder = new AlertDialog.Builder(requireContext()); builder.setMessage("Make sure each category has been properly synchronized") @@ -175,20 +161,12 @@ public class SyncFragment extends Fragment { @Override public void onLoadMedia(List media) { - List libraries = (List) media; - - for (BaseItemDto itemDto : libraries) { - if (itemDto.getCollectionType().equals("music")) { - PreferenceUtil.getInstance(requireContext()).setMusicLibraryID(itemDto.getId()); - } - } - loadSectorInfo(LIBRARIES, "", true); } }); } - private void syncAlbums() { + private void syncAlbums(int size, int offset, int page) { SyncUtil.getAlbums(requireContext(), new MediaCallback() { @Override public void onError(Exception exception) { @@ -197,12 +175,15 @@ public class SyncFragment extends Fragment { @Override public void onLoadMedia(List media) { - syncViewModel.setAlbumList((ArrayList) media); - albumRepository.insertAll(syncViewModel.getAlbumList()); - syncAlbumArtistCross(syncViewModel.getAlbumList()); - loadSectorInfo(ALBUMS, "Found " + syncViewModel.getAlbumList().size() + " elements", true); + syncViewModel.addToAlbumList((List) media); + + if (media.size() == size) { + syncAlbums(size, size * (page + 1), page + 1); + } else { + loadSectorInfo(ALBUMS, "Found " + syncViewModel.getAlbumList().size() + " elements", true); + } } - }); + }, size, offset); } private void syncArtists() { @@ -214,8 +195,7 @@ public class SyncFragment extends Fragment { @Override public void onLoadMedia(List media) { - syncViewModel.setArtistList((ArrayList) media); - artistRepository.insertAll(syncViewModel.getArtistList()); + syncViewModel.setArtistList((ArrayList) media); loadSectorInfo(ARTISTS, "Found " + syncViewModel.getArtistList().size() + " elements", true); } }); @@ -231,8 +211,6 @@ public class SyncFragment extends Fragment { @Override public void onLoadMedia(List media) { syncViewModel.setGenreList((ArrayList) media); - songGenreRepository.deleteAll(); - genreRepository.insertAll(syncViewModel.getGenreList()); loadSectorInfo(GENRES, "Found " + syncViewModel.getGenreList().size() + " elements", true); } }); @@ -248,53 +226,13 @@ public class SyncFragment extends Fragment { @Override public void onLoadMedia(List media) { syncViewModel.setPlaylistList((ArrayList) media); - playlistSongRepository.deleteAll(); - playlistRepository.insertAll(syncViewModel.getPlaylistList()); loadSectorInfo(PLAYLISTS, "Found " + syncViewModel.getPlaylistList().size() + " elements", true); } }); } - private void syncSongs() { - SyncUtil.getSongs(requireContext(), syncViewModel.getCatalogue(), new MediaCallback() { - @Override - public void onError(Exception exception) { - loadSectorInfo(SONGS, exception.getMessage(), false); - } - - @Override - public void onLoadMedia(List media) { - syncViewModel.setSongList((ArrayList) media); - songRepository.insertAll(syncViewModel.getSongList()); - syncSongArtistCross(syncViewModel.getSongList()); - syncDownloadedSong(); - loadSectorInfo(SONGS, "Found " + syncViewModel.getSongList().size() + " elements", true); - PreferenceUtil.getInstance(requireContext()).setSongNumber(syncViewModel.getSongList().size()); - } - }); - } - - private void syncSongsPerGenre(List genres) { - for (Genre genre : genres) { - SyncUtil.getSongsPerGenre(requireContext(), new MediaCallback() { - @Override - public void onError(Exception exception) { - loadSectorInfo(SONG_X_GENRE, exception.getMessage(), false); - } - - @Override - public void onLoadMedia(List media) { - songGenreRepository.insertAll((ArrayList) media); - loadSectorInfo(SONG_X_GENRE, "Genre processed: " + genre.getName(), true); - } - }, genre.id); - } - - PreferenceUtil.getInstance(requireContext()).setSongGenreSync(true); - } - private void syncSongsPerPlaylist(List playlists) { - for (Playlist playlist : playlists) { + /* for (Playlist playlist : playlists) { SyncUtil.getSongsPerPlaylist(requireContext(), new MediaCallback() { @Override public void onError(Exception exception) { @@ -307,62 +245,30 @@ public class SyncFragment extends Fragment { loadSectorInfo(SONG_X_PLAYLIST, "Playlist processed: " + playlist.getName(), true); } }, playlist.getId()); - } + } */ + + loadSectorInfo(SONG_X_PLAYLIST, "Playlist processed: SEI BRAVO", true); + enableHomeButton(SONG_X_PLAYLIST); } - // --------------------------------------------------------------------------------------------- - /* - * Sincronizzazzione dell'album con gli artisti che lo hanno prodotto | isProduced = true - * Sincronizzazzione dell'album con gli artisti che hanno collaborato per la sua produzione | isProduced = false - */ - private void syncAlbumArtistCross(ArrayList albums) { - List crosses = new ArrayList<>(); + private void syncSongs() { + enableHomeButton(SONGS); - for (Album album : albums) { - List artists = new ArrayList<>(); - - if (album.albumArtists.size() > 0) { - for (Artist artist : album.albumArtists) { - artists.add(artist); - crosses.add(new AlbumArtistCross(album.getId(), artist.getId(), true)); + for (AlbumID3 album : syncViewModel.getAlbumList()) { + SyncUtil.getSongs(requireContext(), new MediaCallback() { + @Override + public void onError(Exception exception) { + loadSectorInfo(SONGS, exception.getMessage(), false); } - } - if (album.artistItems.size() > 0) { - for (Artist artist : album.artistItems) { - if (!artists.contains(artist)) { - crosses.add(new AlbumArtistCross(album.getId(), artist.getId(), false)); - } + @Override + public void onLoadMedia(List media) { + syncViewModel.addToChildList((ArrayList) media); + + loadSectorInfo(SONGS, "Found " + syncViewModel.getChildList().size() + " elements", true); } - } + }, album); } - - albumArtistRepository.insertAll(crosses); - } - - private void syncSongArtistCross(ArrayList songs) { - List crosses = new ArrayList<>(); - - for (Song song : songs) { - List artists = new ArrayList<>(); - - if (song.albumArtists.size() > 0) { - for (Artist artist : song.albumArtists) { - artists.add(artist); - crosses.add(new SongArtistCross(song.getId(), artist.getId())); - } - } - - if (song.artistItems.size() > 0) { - for (Artist artist : song.artistItems) { - if (!artists.contains(artist)) { - crosses.add(new SongArtistCross(song.getId(), artist.getId())); - } - } - } - } - - songArtistRepository.insertAll(crosses); } private void syncDownloadedSong() { @@ -402,8 +308,6 @@ public class SyncFragment extends Fragment { bind.syncAlbumsDetailLabel.setText(message); bind.syncAlbumsRetryImageView.setVisibility(View.GONE); } - syncViewModel.increaseProggress(); - checkStep(); syncNextSector(ALBUMS); } else { if (bind != null) { @@ -420,8 +324,6 @@ public class SyncFragment extends Fragment { bind.syncArtistsDetailLabel.setText(message); bind.syncArtistsRetryImageView.setVisibility(View.GONE); } - syncViewModel.increaseProggress(); - checkStep(); syncNextSector(ARTISTS); } else { if (bind != null) { @@ -438,8 +340,6 @@ public class SyncFragment extends Fragment { bind.syncGenresDetailLabel.setText(message); bind.syncGenresRetryImageView.setVisibility(View.GONE); } - syncViewModel.increaseProggress(); - checkStep(); syncNextSector(GENRES); } else { if (bind != null) { @@ -456,8 +356,6 @@ public class SyncFragment extends Fragment { bind.syncPlaylistsDetailLabel.setText(message); bind.syncPlaylistsRetryImageView.setVisibility(View.GONE); } - syncViewModel.increaseProggress(); - checkStep(); syncNextSector(PLAYLISTS); } else { if (bind != null) { @@ -467,40 +365,6 @@ public class SyncFragment extends Fragment { } } break; - case SONGS: - if (isSuccess) { - if (bind != null) { - bind.syncSongsStatusLabel.setText("Status: SUCCESS"); - bind.syncSongsDetailLabel.setText(message); - bind.syncSongsRetryImageView.setVisibility(View.GONE); - } - syncViewModel.increaseProggress(); - checkStep(); - syncNextSector(SONGS); - } else { - if (bind != null) { - bind.syncSongsStatusLabel.setText("Status: ERROR"); - bind.syncSongsDetailLabel.setText(message); - bind.syncSongsRetryImageView.setVisibility(View.VISIBLE); - } - } - break; - case SONG_X_GENRE: - if (isSuccess) { - if (bind != null) { - bind.syncSongXGenreStatusLabel.setText("Status: SUCCESS"); - bind.syncSongXGenreDetailLabel.setText(message); - bind.syncSongXGenreRetryImageView.setVisibility(View.GONE); - } - checkStep(); - } else { - if (bind != null) { - bind.syncSongXGenreStatusLabel.setText("Status: ERROR"); - bind.syncSongXGenreDetailLabel.setText(message); - bind.syncSongXGenreRetryImageView.setVisibility(View.VISIBLE); - } - } - break; case SONG_X_PLAYLIST: if (isSuccess) { if (bind != null) { @@ -508,7 +372,7 @@ public class SyncFragment extends Fragment { bind.syncSongXPlaylistDetailLabel.setText(message); bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE); } - checkStep(); + syncNextSector(SONG_X_PLAYLIST); } else { if (bind != null) { bind.syncSongXPlaylistStatusLabel.setText("Status: ERROR"); @@ -517,6 +381,21 @@ public class SyncFragment extends Fragment { } } break; + case SONGS: + if (isSuccess) { + if (bind != null) { + bind.syncSongsStatusLabel.setText("Status: SUCCESS"); + bind.syncSongsDetailLabel.setText(message); + bind.syncSongsRetryImageView.setVisibility(View.GONE); + } + } else { + if (bind != null) { + bind.syncSongsStatusLabel.setText("Status: ERROR"); + bind.syncSongsDetailLabel.setText(message); + bind.syncSongsRetryImageView.setVisibility(View.VISIBLE); + } + } + break; } } @@ -549,21 +428,16 @@ public class SyncFragment extends Fragment { bind.syncPlaylistsDetailLabel.setText(R.string.label_placeholder); bind.syncPlaylistsRetryImageView.setVisibility(View.GONE); break; - case SONGS: - bind.syncSongsStatusLabel.setText("Loading..."); - bind.syncSongsDetailLabel.setText(R.string.label_placeholder); - bind.syncSongsRetryImageView.setVisibility(View.GONE); - break; - case SONG_X_GENRE: - bind.syncSongXGenreStatusLabel.setText("Loading..."); - bind.syncSongXGenreDetailLabel.setText(R.string.label_placeholder); - bind.syncSongXGenreRetryImageView.setVisibility(View.GONE); - break; case SONG_X_PLAYLIST: bind.syncSongXPlaylistStatusLabel.setText("Loading..."); bind.syncSongXPlaylistDetailLabel.setText(R.string.label_placeholder); bind.syncSongXPlaylistRetryImageView.setVisibility(View.GONE); break; + case SONGS: + bind.syncSongsStatusLabel.setText("Loading..."); + bind.syncSongsDetailLabel.setText(R.string.label_placeholder); + bind.syncSongsRetryImageView.setVisibility(View.GONE); + break; } } } @@ -571,7 +445,7 @@ public class SyncFragment extends Fragment { private void syncNextSector(int sector) { switch (sector) { case LIBRARIES: - if (syncViewModel.isSyncAlbum()) syncAlbums(); + if (syncViewModel.isSyncAlbum()) syncAlbums(500, 0, 0); else syncPlaylist(); break; case ALBUMS: @@ -584,21 +458,24 @@ public class SyncFragment extends Fragment { syncPlaylist(); break; case PLAYLISTS: - if (syncViewModel.isSyncSong()) syncSongs(); - else syncSongsPerPlaylist(syncViewModel.getPlaylistList()); - break; - case SONGS: - syncSongsPerGenre(syncViewModel.getGenreList()); syncSongsPerPlaylist(syncViewModel.getPlaylistList()); break; - case SONG_X_GENRE | SONG_X_PLAYLIST: + case SONG_X_PLAYLIST: + if (syncViewModel.isSyncSong()) syncSongs(); + break; + case SONGS: break; } } - private void checkStep() { - if (syncViewModel.getStep() == syncViewModel.getProgress()) { - bind.syncingGoHomeImageView.setVisibility(View.VISIBLE); + private void enableHomeButton(int sector) { + switch (sector) { + case SONG_X_PLAYLIST: + if (!syncViewModel.isSyncSong()) bind.syncingGoHomeImageView.setVisibility(View.VISIBLE); + break; + case SONGS: + bind.syncingGoHomeImageView.setVisibility(View.VISIBLE); + break; } } } diff --git a/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java b/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java index 888e69bc..1b81aa9d 100644 --- a/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java +++ b/app/src/main/java/com/cappielloantonio/play/util/SyncUtil.java @@ -2,34 +2,32 @@ package com.cappielloantonio.play.util; import android.content.Context; import android.os.Bundle; -import android.util.Log; 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.Genre; -import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.model.PlaylistSongCross; import com.cappielloantonio.play.model.Song; -import com.cappielloantonio.play.model.SongGenreCross; +import com.cappielloantonio.play.subsonic.models.AlbumID3; +import com.cappielloantonio.play.subsonic.models.ArtistID3; +import com.cappielloantonio.play.subsonic.models.Child; +import com.cappielloantonio.play.subsonic.models.IndexID3; +import com.cappielloantonio.play.subsonic.models.MusicFolder; +import com.cappielloantonio.play.subsonic.models.ResponseStatus; +import com.cappielloantonio.play.subsonic.models.SubsonicResponse; import org.jellyfin.apiclient.interaction.Response; import org.jellyfin.apiclient.model.dto.BaseItemDto; -import org.jellyfin.apiclient.model.dto.BaseItemType; import org.jellyfin.apiclient.model.playlists.PlaylistItemQuery; -import org.jellyfin.apiclient.model.querying.ArtistsQuery; import org.jellyfin.apiclient.model.querying.ItemFields; -import org.jellyfin.apiclient.model.querying.ItemQuery; -import org.jellyfin.apiclient.model.querying.ItemsByNameQuery; import org.jellyfin.apiclient.model.querying.ItemsResult; -import org.jellyfin.apiclient.model.querying.SimilarItemsQuery; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import java.util.Map; +import retrofit2.Call; +import retrofit2.Callback; + public class SyncUtil { private static final String TAG = "SyncUtil"; @@ -38,182 +36,170 @@ public class SyncUtil { public static final String ARTIST = "artist"; public static void getLibraries(Context context, MediaCallback callback) { - String id = App.getApiClientInstance(context).getCurrentUserId(); + App.getSubsonicClientInstance(context, false) + .getBrowsingClient() + .getMusicFolders() + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + boolean musicFolderFound = false; - App.getApiClientInstance(context).GetUserViews(id, new Response() { - @Override - public void onResponse(ItemsResult result) { - List libraries = new ArrayList<>(); - libraries.addAll(Arrays.asList(result.getItems())); + for (MusicFolder folder : response.body().getMusicFolders().getMusicFolders()) { + if (folder.getName().equals("music")) { + PreferenceUtil.getInstance(context).setMusicLibraryID(String.valueOf(folder.getId())); + musicFolderFound = true; + } + } - callback.onLoadMedia(libraries); - } + if (musicFolderFound) callback.onLoadMedia(null); + } else { + callback.onError(new Exception("Empty response")); + } + } - @Override - public void onError(Exception exception) { - exception.printStackTrace(); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } - public static void getSongs(Context context, Map currentCatalogue, MediaCallback callback) { - ItemQuery query = new ItemQuery(); + public static void getSongs(Context context, MediaCallback callback, AlbumID3 album) { + App.getSubsonicClientInstance(context, false) + .getBrowsingClient() + .getAlbum(album.getId()) + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + List childList = new ArrayList<>(); + childList.addAll(response.body().getAlbum().getSongs()); + callback.onLoadMedia(childList); + } else { + callback.onError(new Exception("Empty response")); + } + } - query.setIncludeItemTypes(new String[]{"Audio"}); - query.setFields(new ItemFields[]{ItemFields.MediaSources}); - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); - - App.getApiClientInstance(context).GetItemsAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - ArrayList songs = new ArrayList<>(); - - for (BaseItemDto itemDto : result.getItems()) { - songs.add(updateSongData(currentCatalogue, new Song(itemDto))); - } - - callback.onLoadMedia(songs); - } - - @Override - public void onError(Exception exception) { - callback.onError(exception); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } - public static void getAlbums(Context context, MediaCallback callback) { - ItemQuery query = new ItemQuery(); + public static void getAlbums(Context context, MediaCallback callback, int size, int offset) { + App.getSubsonicClientInstance(context, false) + .getAlbumSongListClient() + .getAlbumList2("alphabeticalByName", size, offset) + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + List albumList = new ArrayList<>(); + albumList.addAll(response.body().getAlbumList2().getAlbums()); + callback.onLoadMedia(albumList); + } else { + callback.onError(new Exception("Empty response")); + } + } - query.setIncludeItemTypes(new String[]{"MusicAlbum"}); - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); - - App.getApiClientInstance(context).GetItemsAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - List albums = new ArrayList<>(); - for (BaseItemDto itemDto : result.getItems()) { - albums.add(new Album(itemDto)); - } - - callback.onLoadMedia(albums); - } - - @Override - public void onError(Exception exception) { - exception.printStackTrace(); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } public static void getArtists(Context context, MediaCallback callback) { - ArtistsQuery query = new ArtistsQuery(); + App.getSubsonicClientInstance(context, false) + .getBrowsingClient() + .getArtists() + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + List artistList = new ArrayList<>(); - query.setFields(new ItemFields[]{ItemFields.Genres}); - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); + for (IndexID3 index : response.body().getArtists().getIndices()) { + artistList.addAll(index.getArtists()); + } - App.getApiClientInstance(context).GetAlbumArtistsAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - List artists = new ArrayList<>(); - for (BaseItemDto itemDto : result.getItems()) { - artists.add(new Artist(itemDto)); - } + callback.onLoadMedia(artistList); + } else { + callback.onError(new Exception("Empty response")); + } + } - callback.onLoadMedia(artists); - } - - @Override - public void onError(Exception exception) { - exception.printStackTrace(); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } public static void getPlaylists(Context context, MediaCallback callback) { - ItemQuery query = new ItemQuery(); + App.getSubsonicClientInstance(context, false) + .getPlaylistClient() + .getPlaylists() + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + List playlistList = new ArrayList<>(); + playlistList.addAll(response.body().getPlaylists().getPlaylists()); + callback.onLoadMedia(playlistList); + } else { + callback.onError(new Exception("Empty response")); + } + } - query.setIncludeItemTypes(new String[]{"Playlist"}); - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); - - App.getApiClientInstance(context).GetItemsAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - List playlists = new ArrayList<>(); - for (BaseItemDto itemDto : result.getItems()) { - playlists.add(new Playlist(itemDto)); - } - - callback.onLoadMedia(playlists); - } - - @Override - public void onError(Exception exception) { - exception.printStackTrace(); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } public static void getGenres(Context context, MediaCallback callback) { - ItemsByNameQuery query = new ItemsByNameQuery(); + App.getSubsonicClientInstance(context, false) + .getBrowsingClient() + .getGenres() + .enqueue(new Callback() { + @Override + public void onResponse(Call call, retrofit2.Response response) { + if (response.body().getStatus().getValue().equals(ResponseStatus.FAILED)) { + String errorMessage = response.body().getError().getCode().getValue() + " - " + response.body().getError().getMessage(); + callback.onError(new Exception(errorMessage)); + } else if (response.body().getStatus().getValue().equals(ResponseStatus.OK)) { + List genreList = new ArrayList<>(); + genreList.addAll(response.body().getGenres().getGenres()); + callback.onLoadMedia(genreList); + } else { + callback.onError(new Exception("Empty response")); + } + } - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); - - App.getApiClientInstance(context).GetGenresAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - List genres = new ArrayList<>(); - for (BaseItemDto itemDto : result.getItems()) { - genres.add(new Genre(itemDto)); - } - - callback.onLoadMedia(genres); - } - - @Override - public void onError(Exception exception) { - exception.printStackTrace(); - } - }); - } - - public static void getSongsPerGenre(Context context, MediaCallback callback, String genreId) { - ItemQuery query = new ItemQuery(); - - query.setIncludeItemTypes(new String[]{"Audio"}); - query.setFields(new ItemFields[]{ItemFields.MediaSources}); - query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); - query.setRecursive(true); - query.setParentId(PreferenceUtil.getInstance(context).getMusicLibraryID()); - query.setGenreIds(new String[]{genreId}); - - App.getApiClientInstance(context).GetItemsAsync(query, new Response() { - @Override - public void onResponse(ItemsResult result) { - ArrayList crosses = new ArrayList<>(); - - for (BaseItemDto itemDto : result.getItems()) { - crosses.add(new SongGenreCross(itemDto.getId(), genreId)); - } - - callback.onLoadMedia(crosses); - } - - @Override - public void onError(Exception exception) { - callback.onError(exception); - } - }); + @Override + public void onFailure(Call call, Throwable t) { + callback.onError(new Exception(t.getMessage())); + } + }); } public static void getSongsPerPlaylist(Context context, MediaCallback callback, String playlistId) { @@ -245,7 +231,7 @@ public class SyncUtil { } public static void getInstantMix(Context context, MediaCallback callback, String resultType, String itemID, int limit) { - SimilarItemsQuery query = new SimilarItemsQuery(); + /*SimilarItemsQuery query = new SimilarItemsQuery(); query.setId(itemID); query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); @@ -274,11 +260,11 @@ public class SyncUtil { public void onError(Exception exception) { callback.onError(exception); } - }); + });*/ } public static void getSimilarItems(Context context, MediaCallback callback, String resultType, String itemID, int limit) { - SimilarItemsQuery query = new SimilarItemsQuery(); + /*SimilarItemsQuery query = new SimilarItemsQuery(); query.setId(itemID); query.setUserId(App.getApiClientInstance(context).getCurrentUserId()); @@ -307,17 +293,16 @@ public class SyncUtil { public void onError(Exception exception) { callback.onError(exception); } - }); + });*/ } - public static Bundle getSyncBundle(Boolean syncAlbum, Boolean syncArtist, Boolean syncGenres, Boolean syncPlaylist, Boolean syncSong, Boolean crossSyncSongGenre) { + public static Bundle getSyncBundle(Boolean syncAlbum, Boolean syncArtist, Boolean syncGenres, Boolean syncPlaylist, Boolean syncSong) { Bundle bundle = new Bundle(); bundle.putBoolean("sync_album", syncAlbum); bundle.putBoolean("sync_artist", syncArtist); bundle.putBoolean("sync_genres", syncGenres); bundle.putBoolean("sync_playlist", syncPlaylist); bundle.putBoolean("sync_song", syncSong); - bundle.putBoolean("cross_sync_song_genre", crossSyncSongGenre); return bundle; } diff --git a/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java b/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java index adeae45a..a75194e3 100644 --- a/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java +++ b/app/src/main/java/com/cappielloantonio/play/viewmodel/SyncViewModel.java @@ -6,64 +6,66 @@ import android.os.Bundle; import androidx.annotation.NonNull; import androidx.lifecycle.AndroidViewModel; -import com.cappielloantonio.play.model.Album; -import com.cappielloantonio.play.model.Artist; -import com.cappielloantonio.play.model.Genre; import com.cappielloantonio.play.model.Playlist; import com.cappielloantonio.play.model.Song; +import com.cappielloantonio.play.repository.AlbumRepository; +import com.cappielloantonio.play.repository.ArtistRepository; +import com.cappielloantonio.play.repository.GenreRepository; +import com.cappielloantonio.play.repository.PlaylistRepository; +import com.cappielloantonio.play.repository.PlaylistSongRepository; import com.cappielloantonio.play.repository.SongRepository; +import com.cappielloantonio.play.subsonic.models.AlbumID3; +import com.cappielloantonio.play.subsonic.models.ArtistID3; +import com.cappielloantonio.play.subsonic.models.Child; +import com.cappielloantonio.play.subsonic.models.Genre; import java.util.ArrayList; import java.util.HashMap; +import java.util.HashSet; +import java.util.List; import java.util.Map; +import java.util.Set; public class SyncViewModel extends AndroidViewModel { private static final String TAG = "SyncViewModel"; - - private SongRepository songRepository; - + private boolean syncAlbum = false; private boolean syncArtist = false; private boolean syncGenres = false; private boolean syncPlaylist = false; private boolean syncSong = false; - private boolean crossSyncSongGenre = false; - private ArrayList albumList = new ArrayList<>(); - private ArrayList artistList = new ArrayList<>(); + private ArrayList albumList = new ArrayList<>(); + private ArrayList artistList = new ArrayList<>(); private ArrayList genreList = new ArrayList<>(); private ArrayList playlistList = new ArrayList<>(); private ArrayList songList = new ArrayList<>(); + private ArrayList childList = new ArrayList<>(); - private int step = 0; - private int progress = 0; + private SongRepository songRepository; + private AlbumRepository albumRepository; + private ArtistRepository artistRepository; + private PlaylistRepository playlistRepository; + private GenreRepository genreRepository; + private PlaylistSongRepository playlistSongRepository; public SyncViewModel(@NonNull Application application) { super(application); songRepository = new SongRepository(application); + albumRepository = new AlbumRepository(application); + artistRepository = new ArtistRepository(application); + playlistRepository = new PlaylistRepository(application); + genreRepository = new GenreRepository(application); + playlistSongRepository = new PlaylistSongRepository(application); } public void setArguemnts(Bundle bundle) { - step = 0; - progress = 0; - syncAlbum = bundle.getBoolean("sync_album", false); syncArtist = bundle.getBoolean("sync_artist", false); syncGenres = bundle.getBoolean("sync_genres", false); syncPlaylist = bundle.getBoolean("sync_playlist", false); syncSong = bundle.getBoolean("sync_song", false); - crossSyncSongGenre = bundle.getBoolean("cross_sync_song_genre", false); - - countStep(); - } - - private void countStep() { - if (syncAlbum) step++; - if (syncArtist) step++; - if (syncGenres) step++; - if (syncPlaylist) step++; - if (syncSong) step++; } public boolean isSyncAlbum() { @@ -86,23 +88,19 @@ public class SyncViewModel extends AndroidViewModel { return syncSong; } - public boolean isCrossSyncSongGenre() { - return crossSyncSongGenre; - } - - public ArrayList getAlbumList() { + public ArrayList getAlbumList() { return albumList; } - public void setAlbumList(ArrayList albumList) { - this.albumList = albumList; + public void addToAlbumList(List albumList) { + this.albumList.addAll(albumList); } - public ArrayList getArtistList() { + public ArrayList getArtistList() { return artistList; } - public void setArtistList(ArrayList artistList) { + public void setArtistList(ArrayList artistList) { this.artistList = artistList; } @@ -130,19 +128,14 @@ public class SyncViewModel extends AndroidViewModel { this.songList = songList; } - public void increaseProggress() { - progress++; + public ArrayList getChildList() { + return childList; } - public int getStep() { - return step; + public void addToChildList(ArrayList childList) { + this.childList.addAll(childList); } - public int getProgress() { - return progress; - } - - public Map getCatalogue() { Map map = new HashMap<>(); diff --git a/app/src/main/res/layout/fragment_sync.xml b/app/src/main/res/layout/fragment_sync.xml index d04c7205..394ad8be 100644 --- a/app/src/main/res/layout/fragment_sync.xml +++ b/app/src/main/res/layout/fragment_sync.xml @@ -360,124 +360,6 @@ app:layout_constraintTop_toBottomOf="@+id/sync_playlists_status_label" /> - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + \ No newline at end of file