From afd30d541e96381df156dcea8ffc56a5d23e1b6c Mon Sep 17 00:00:00 2001 From: bangarumahesh22 Date: Fri, 7 Nov 2025 21:20:38 +0530 Subject: [PATCH 1/2] feat: add smart_shuffle field to CurrentlyPlayingContext This adds support for the smart_shuffle parameter returned by Spotify's API. Changes: - Added smart_shuffle field (Boolean) to CurrentlyPlayingContext class - Added getter method getSmart_shuffle() - Updated constructor to initialize smart_shuffle - Updated toString() method to include smart_shuffle - Added smart_shuffle field and setter in Builder class - Added smart_shuffle parsing in JsonUtil class Fixes #430 --- .../CurrentlyPlayingContext.java | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java b/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java index a146fae98..2c5f31ba6 100644 --- a/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java +++ b/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java @@ -24,6 +24,8 @@ public class CurrentlyPlayingContext extends AbstractModelObject { private final String repeat_state; /** If shuffle is on or off. */ private final Boolean shuffle_state; + /** If smart shuffle is on or off. */ + private final Boolean smart_shuffle; /** The context in which the track is being played. */ private final Context context; /** Unix timestamp when the request was made. */ @@ -45,6 +47,7 @@ private CurrentlyPlayingContext(final Builder builder) { this.device = builder.device; this.repeat_state = builder.repeat_state; this.shuffle_state = builder.shuffle_state; + this.smart_shuffle = builder.smart_shuffle; this.context = builder.context; this.timestamp = builder.timestamp; this.progress_ms = builder.progress_ms; @@ -81,6 +84,15 @@ public Boolean getShuffle_state() { return shuffle_state; } + /** + * Get the smart shuffle state of the device. + * + * @return If smart shuffle is on or off. + */ + public Boolean getSmart_shuffle() { + return smart_shuffle; + } + /** * Get the context from where the currently playing item is played from. * @@ -147,7 +159,7 @@ public Actions getActions() { @Override public String toString() { return "CurrentlyPlayingContext(device=" + device + ", repeat_state=" + repeat_state + ", shuffle_state=" - + shuffle_state + ", context=" + context + ", timestamp=" + timestamp + ", progress_ms=" + progress_ms + + shuffle_state + ", smart_shuffle=" + smart_shuffle + ", context=" + context + ", timestamp=" + timestamp + ", progress_ms=" + progress_ms + ", is_playing=" + is_playing + ", item=" + item + ", currentlyPlayingType=" + currentlyPlayingType + ", actions=" + actions + ")"; } @@ -164,6 +176,7 @@ public static final class Builder extends AbstractModelObject.Builder { private Device device; private String repeat_state; private Boolean shuffle_state; + private Boolean smart_shuffle; private Context context; private Long timestamp; private Integer progress_ms; @@ -212,6 +225,17 @@ public Builder setShuffle_state(Boolean shuffle_state) { return this; } + /** + * The smart shuffle state setter. + * + * @param smart_shuffle If smart shuffle is on or off. + * @return A {@link CurrentlyPlayingContext.Builder}. + */ + public Builder setSmart_shuffle(Boolean smart_shuffle) { + this.smart_shuffle = smart_shuffle; + return this; + } + /** * The playing context setter. * @@ -326,6 +350,10 @@ public CurrentlyPlayingContext createModelObject(JsonObject jsonObject) { hasAndNotNull(jsonObject, "shuffle_state") ? jsonObject.get("shuffle_state").getAsBoolean() : null) + .setSmart_shuffle( + hasAndNotNull(jsonObject, "smart_shuffle") + ? jsonObject.get("smart_shuffle").getAsBoolean() + : null) .setContext( hasAndNotNull(jsonObject, "context") ? new Context.JsonUtil().createModelObject( From fe914823b8244266c017059fd7a5562f92b94980 Mon Sep 17 00:00:00 2001 From: bangarumahesh22 Date: Fri, 7 Nov 2025 22:22:09 +0530 Subject: [PATCH 2/2] Fix indentation for smart_shuffle field to match code style Adjusted indentation of setSmart_shuffle() call and its ternary operator to align with the existing code style used for similar setter methods. This addresses the review feedback from dargmuesli. --- .../miscellaneous/CurrentlyPlayingContext.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java b/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java index 2c5f31ba6..a2ec3e1cf 100644 --- a/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java +++ b/src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java @@ -350,12 +350,10 @@ public CurrentlyPlayingContext createModelObject(JsonObject jsonObject) { hasAndNotNull(jsonObject, "shuffle_state") ? jsonObject.get("shuffle_state").getAsBoolean() : null) - .setSmart_shuffle( - hasAndNotNull(jsonObject, "smart_shuffle") + .setSmart_shuffle( hasAndNotNull(jsonObject, "smart_shuffle") + hasAndNotNull(jsonObject, "smart_shuffle") : ? jsonObject.get("smart_shuffle").getAsBoolean() : null) - .setContext( - hasAndNotNull(jsonObject, "context") ? new Context.JsonUtil().createModelObject( jsonObject.getAsJsonObject("context")) : null)