Skip to content

Commit 40a0b44

Browse files
author
Momme Raap
committed
feat: add smart_shuffle parameter to CurrentlyPlayingContext (#430)
1 parent 4e85634 commit 40a0b44

File tree

4 files changed

+37
-4
lines changed

4 files changed

+37
-4
lines changed

src/main/java/se/michaelthelin/spotify/model_objects/miscellaneous/CurrentlyPlayingContext.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public class CurrentlyPlayingContext extends AbstractModelObject {
2424
private final String repeat_state;
2525
/** If shuffle is on or off. */
2626
private final Boolean shuffle_state;
27+
/** If smart shuffle is on or off. */
28+
private final Boolean smart_shuffle;
2729
/** The context in which the track is being played. */
2830
private final Context context;
2931
/** Unix timestamp when the request was made. */
@@ -45,6 +47,7 @@ private CurrentlyPlayingContext(final Builder builder) {
4547
this.device = builder.device;
4648
this.repeat_state = builder.repeat_state;
4749
this.shuffle_state = builder.shuffle_state;
50+
this.smart_shuffle = builder.smart_shuffle;
4851
this.context = builder.context;
4952
this.timestamp = builder.timestamp;
5053
this.progress_ms = builder.progress_ms;
@@ -81,6 +84,15 @@ public Boolean getShuffle_state() {
8184
return shuffle_state;
8285
}
8386

87+
/**
88+
* Get smart shuffle state of the device.
89+
*
90+
* @return If smart shuffle is on or off.
91+
*/
92+
public Boolean getSmart_shuffle() {
93+
return smart_shuffle;
94+
}
95+
8496
/**
8597
* Get the context from where the currently playing item is played from.
8698
*
@@ -147,9 +159,9 @@ public Actions getActions() {
147159
@Override
148160
public String toString() {
149161
return "CurrentlyPlayingContext(device=" + device + ", repeat_state=" + repeat_state + ", shuffle_state="
150-
+ shuffle_state + ", context=" + context + ", timestamp=" + timestamp + ", progress_ms=" + progress_ms
151-
+ ", is_playing=" + is_playing + ", item=" + item + ", currentlyPlayingType=" + currentlyPlayingType
152-
+ ", actions=" + actions + ")";
162+
+ shuffle_state + ", smart_shuffle=" + smart_shuffle + ", context=" + context + ", timestamp=" + timestamp
163+
+ ", progress_ms=" + progress_ms + ", is_playing=" + is_playing + ", item=" + item + ", currentlyPlayingType="
164+
+ currentlyPlayingType + ", actions=" + actions + ")";
153165
}
154166

155167
@Override
@@ -164,6 +176,7 @@ public static final class Builder extends AbstractModelObject.Builder {
164176
private Device device;
165177
private String repeat_state;
166178
private Boolean shuffle_state;
179+
private Boolean smart_shuffle;
167180
private Context context;
168181
private Long timestamp;
169182
private Integer progress_ms;
@@ -211,6 +224,16 @@ public Builder setShuffle_state(Boolean shuffle_state) {
211224
this.shuffle_state = shuffle_state;
212225
return this;
213226
}
227+
/**
228+
* The smart shuffle setter.
229+
*
230+
* @param smart_shuffle If smart shuffle is on or off.
231+
* @return A {@link CurrentlyPlayingContext.Builder}.
232+
*/
233+
public Builder setSmart_shuffle(Boolean smart_shuffle) {
234+
this.smart_shuffle = smart_shuffle;
235+
return this;
236+
}
214237

215238
/**
216239
* The playing context setter.
@@ -326,6 +349,10 @@ public CurrentlyPlayingContext createModelObject(JsonObject jsonObject) {
326349
hasAndNotNull(jsonObject, "shuffle_state")
327350
? jsonObject.get("shuffle_state").getAsBoolean()
328351
: null)
352+
.setSmart_shuffle(
353+
hasAndNotNull(jsonObject, "smart_shuffle")
354+
? jsonObject.get("smart_shuffle").getAsBoolean()
355+
: null)
329356
.setContext(
330357
hasAndNotNull(jsonObject, "context")
331358
? new Context.JsonUtil().createModelObject(

src/test/fixtures/requests/data/player/GetInformationAboutUsersCurrentPlaybackRequest.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,6 @@
9292
}
9393
},
9494
"repeat_state": "off",
95-
"shuffle_state": false
95+
"shuffle_state": false,
96+
"smart_shuffle": false
9697
}

src/test/fixtures/requests/data/player/GetInformationAboutUsersCurrentPlaybackRequest_Episode.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"volume_percent": 100
1010
},
1111
"shuffle_state": false,
12+
"smart_shuffle": false,
1213
"repeat_state": "off",
1314
"timestamp": 1516669848357,
1415
"context": {

src/test/java/se/michaelthelin/spotify/requests/data/player/GetInformationAboutUsersCurrentPlaybackRequestTest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ public void shouldReturnDefault(final CurrentlyPlayingContext currentlyPlayingCo
7373
currentlyPlayingContext.getRepeat_state());
7474
assertFalse(
7575
currentlyPlayingContext.getShuffle_state());
76+
assertFalse(
77+
currentlyPlayingContext.getSmart_shuffle());
7678
assertNull(
7779
currentlyPlayingContext.getContext());
7880
assertEquals(
@@ -115,6 +117,8 @@ public void shouldReturnDefaultEpisode(final CurrentlyPlayingContext currentlyPl
115117
currentlyPlayingContext.getRepeat_state());
116118
assertFalse(
117119
currentlyPlayingContext.getShuffle_state());
120+
assertFalse(
121+
currentlyPlayingContext.getSmart_shuffle());
118122
assertNotNull(
119123
currentlyPlayingContext.getContext());
120124
assertEquals(

0 commit comments

Comments
 (0)