From 328140bd885a399f7c3b840d4ce60b400d785cd4 Mon Sep 17 00:00:00 2001 From: Ashish Goel Date: Wed, 13 Sep 2017 18:09:40 +0530 Subject: [PATCH 1/3] =?UTF-8?q?Added=20rest=20call=20to=20get=20the=20obje?= =?UTF-8?q?ct=20currently=20being=20played=20on=20the=20user=E2=80=99s=20S?= =?UTF-8?q?potify=20account.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- release.gradle | 4 +- .../webapi/android/SpotifyService.java | 19 +++++++ .../android/models/CurrentlyPlaying.java | 51 +++++++++++++++++++ .../models/CurrentlyPlayingContext.java | 50 ++++++++++++++++++ 4 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java create mode 100644 spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlayingContext.java diff --git a/release.gradle b/release.gradle index b53f0934..d35e6f4a 100644 --- a/release.gradle +++ b/release.gradle @@ -31,9 +31,9 @@ jacoco { toolVersion = "0.7.1.201405082137" } -def coverageSourceDirs = ['src/main/java' ] +def coverageSourceDirs = ['src/main/java'] -task jacocoTestReport(type:JacocoReport, dependsOn: "test") { +task jacocoTestReport(type: JacocoReport, dependsOn: "test") { group = "Reporting" description = "Generate Jacoco coverage reports" diff --git a/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java b/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java index 5caedb70..e0a99296 100644 --- a/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java +++ b/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java @@ -14,6 +14,7 @@ import kaaes.spotify.webapi.android.models.AudioFeaturesTracks; import kaaes.spotify.webapi.android.models.CategoriesPager; import kaaes.spotify.webapi.android.models.Category; +import kaaes.spotify.webapi.android.models.CurrentlyPlaying; import kaaes.spotify.webapi.android.models.FeaturedPlaylists; import kaaes.spotify.webapi.android.models.NewReleases; import kaaes.spotify.webapi.android.models.Pager; @@ -1810,4 +1811,22 @@ public interface SpotifyService { @GET("/me/top/tracks") void getTopTracks(@QueryMap Map options, Callback> callback); + /** + * Get the object currently being played on the user’s Spotify account. + * + * @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + * endpoint documentation + * @param callback Callback method + */ + @GET("/me/player/currently-playing") + void getCurrentlyPlaying(@Query("market") String market, Callback callback); + + /** + * Get the object currently being played on the user’s Spotify account. + * + * @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. + * endpoint documentation + */ + @GET("/me/player/currently-playing") + CurrentlyPlaying getCurrentlyPlaying(@Query("market") String market); } diff --git a/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java new file mode 100644 index 00000000..23e389d2 --- /dev/null +++ b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java @@ -0,0 +1,51 @@ +package kaaes.spotify.webapi.android.models; + +import android.os.Parcel; +import android.os.Parcelable; + +/** + * Created by sd2_rails on 9/13/17. + */ + +public class CurrentlyPlaying implements Parcelable { + + CurrentlyPlayingContext context; + public Integer timestamp; + public Integer progress_ms; + public boolean is_playing; + public Track item; + + protected CurrentlyPlaying(Parcel in) { + context = in.readParcelable(CurrentlyPlayingContext.class.getClassLoader()); + timestamp = (Integer) in.readValue(Integer.class.getClassLoader()); + progress_ms = (Integer) in.readValue(Integer.class.getClassLoader()); + is_playing = in.readByte() != 0; + item = in.readParcelable(Track.class.getClassLoader()); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeParcelable(context, flags); + dest.writeValue(timestamp); + dest.writeValue(progress_ms); + dest.writeByte((byte) (is_playing ? 1 : 0)); + dest.writeParcelable(item, flags); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public CurrentlyPlaying createFromParcel(Parcel in) { + return new CurrentlyPlaying(in); + } + + @Override + public CurrentlyPlaying[] newArray(int size) { + return new CurrentlyPlaying[size]; + } + }; +} diff --git a/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlayingContext.java b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlayingContext.java new file mode 100644 index 00000000..a307ac37 --- /dev/null +++ b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlayingContext.java @@ -0,0 +1,50 @@ +package kaaes.spotify.webapi.android.models; + +import android.os.Parcel; +import android.os.Parcelable; + +import java.util.Map; + +/** + * Created by sd2_rails on 9/13/17. + */ + +public class CurrentlyPlayingContext implements Parcelable { + + public String uri; + public String href; + public Map external_urls; + public String type; + + protected CurrentlyPlayingContext(Parcel in) { + uri = in.readString(); + href = in.readString(); + external_urls = in.readHashMap(Map.class.getClassLoader()); + type = in.readString(); + } + + @Override + public void writeToParcel(Parcel dest, int flags) { + dest.writeString(uri); + dest.writeString(href); + dest.writeMap(this.external_urls); + dest.writeString(type); + } + + @Override + public int describeContents() { + return 0; + } + + public static final Creator CREATOR = new Creator() { + @Override + public CurrentlyPlayingContext createFromParcel(Parcel in) { + return new CurrentlyPlayingContext(in); + } + + @Override + public CurrentlyPlayingContext[] newArray(int size) { + return new CurrentlyPlayingContext[size]; + } + }; +} From 6b3e1ff8a3e2145d2733508cff0c73c14fb8cc8e Mon Sep 17 00:00:00 2001 From: Ashish Goel Date: Wed, 13 Sep 2017 18:54:00 +0530 Subject: [PATCH 2/3] made timestamp as string --- .../spotify/webapi/android/models/CurrentlyPlaying.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java index 23e389d2..03ff7b18 100644 --- a/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java +++ b/spotify-api/src/main/java/kaaes/spotify/webapi/android/models/CurrentlyPlaying.java @@ -10,14 +10,14 @@ public class CurrentlyPlaying implements Parcelable { CurrentlyPlayingContext context; - public Integer timestamp; + public String timestamp; public Integer progress_ms; public boolean is_playing; public Track item; protected CurrentlyPlaying(Parcel in) { context = in.readParcelable(CurrentlyPlayingContext.class.getClassLoader()); - timestamp = (Integer) in.readValue(Integer.class.getClassLoader()); + timestamp = in.readString(); progress_ms = (Integer) in.readValue(Integer.class.getClassLoader()); is_playing = in.readByte() != 0; item = in.readParcelable(Track.class.getClassLoader()); @@ -26,7 +26,7 @@ protected CurrentlyPlaying(Parcel in) { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeParcelable(context, flags); - dest.writeValue(timestamp); + dest.writeString(timestamp); dest.writeValue(progress_ms); dest.writeByte((byte) (is_playing ? 1 : 0)); dest.writeParcelable(item, flags); From 94bcc7725f814ed31d4879a8dc6c1e37d8801317 Mon Sep 17 00:00:00 2001 From: Ashish Goel Date: Wed, 13 Sep 2017 19:16:05 +0530 Subject: [PATCH 3/3] fixed SONAR errors and warnings --- .../main/java/kaaes/spotify/webapi/android/SpotifyService.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java b/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java index e0a99296..ea3cb893 100644 --- a/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java +++ b/spotify-api/src/main/java/kaaes/spotify/webapi/android/SpotifyService.java @@ -1441,7 +1441,6 @@ public interface SpotifyService { * Get the current user's followed artists. * * @param callback Callback method. - * @return An empty result * @see Get User's Followed Artists */ @GET("/me/following?type=artist") @@ -1464,7 +1463,6 @@ public interface SpotifyService { * @param options Optional parameters. For list of supported parameters see * endpoint documentation * @param callback Callback method. - * @return An empty result * @see Get User's Followed Artists */ @GET("/me/following?type=artist") @@ -1826,6 +1824,7 @@ public interface SpotifyService { * * @param market Optional. An ISO 3166-1 alpha-2 country code. Provide this parameter if you want to apply Track Relinking. * endpoint documentation + * @return Currently Playing Object */ @GET("/me/player/currently-playing") CurrentlyPlaying getCurrentlyPlaying(@Query("market") String market);