Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
refactor(currently-playing-context): sort properties as returned by t…
…he api
  • Loading branch information
dargmuesli committed Nov 9, 2025
commit 5cc766f6500f722509885e6f0dfcde778009856f
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ 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. */
Expand All @@ -40,21 +38,23 @@ public class CurrentlyPlayingContext extends AbstractModelObject {
private final CurrentlyPlayingType currentlyPlayingType;
/** Allows to update the user interface based on which playback actions are available. */
private final Actions actions;
/** If smart shuffle is on or off. */
private final Boolean smart_shuffle;

private CurrentlyPlayingContext(final Builder builder) {
super(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;
this.is_playing = builder.is_playing;
this.item = builder.item;
this.currentlyPlayingType = builder.currentlyPlayingType;
this.actions = builder.actions;
this.smart_shuffle = builder.smart_shuffle;
}

/**
Expand Down Expand Up @@ -159,9 +159,9 @@ public Actions getActions() {
@Override
public String toString() {
return "CurrentlyPlayingContext(device=" + device + ", repeat_state=" + repeat_state + ", shuffle_state="
+ shuffle_state + ", smart_shuffle=" + smart_shuffle + ", context=" + context + ", timestamp=" + timestamp
+ ", progress_ms=" + progress_ms + ", is_playing=" + is_playing + ", item=" + item + ", currentlyPlayingType="
+ currentlyPlayingType + ", actions=" + actions + ")";
+ shuffle_state + ", context=" + context + ", timestamp=" + timestamp + ", progress_ms=" + progress_ms
+ ", is_playing=" + is_playing + ", item=" + item + ", currentlyPlayingType=" + currentlyPlayingType
+ ", actions=" + actions + ", smart_shuffle=" + smart_shuffle + ")";
}

@Override
Expand All @@ -176,14 +176,14 @@ 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;
private Boolean is_playing;
private IPlaylistItem item;
private CurrentlyPlayingType currentlyPlayingType;
private Actions actions;
private Boolean smart_shuffle;

/**
* Default constructor.
Expand Down Expand Up @@ -224,16 +224,6 @@ public Builder setShuffle_state(Boolean shuffle_state) {
this.shuffle_state = shuffle_state;
return this;
}
/**
* The smart shuffle 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.
Expand Down Expand Up @@ -312,6 +302,17 @@ public Builder setActions(Actions actions) {
return this;
}

/**
* The smart shuffle 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;
}

@Override
public CurrentlyPlayingContext build() {
return new CurrentlyPlayingContext(this);
Expand Down Expand Up @@ -349,10 +350,6 @@ 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(
Expand Down Expand Up @@ -388,6 +385,10 @@ public CurrentlyPlayingContext createModelObject(JsonObject jsonObject) {
? new Actions.JsonUtil().createModelObject(
jsonObject.getAsJsonObject("actions"))
: null)
.setSmart_shuffle(
hasAndNotNull(jsonObject, "smart_shuffle")
? jsonObject.get("smart_shuffle").getAsBoolean()
: null)
.build();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
"volume_percent": 100
},
"shuffle_state": false,
"smart_shuffle": false,
"repeat_state": "off",
"timestamp": 1516669848357,
"context": {
Expand Down Expand Up @@ -184,5 +183,6 @@
"toggling_shuffle": true
}
},
"is_playing": true
"is_playing": true,
"smart_shuffle": false
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ public void shouldReturnDefault(final CurrentlyPlayingContext currentlyPlayingCo
currentlyPlayingContext.getRepeat_state());
assertFalse(
currentlyPlayingContext.getShuffle_state());
assertFalse(
currentlyPlayingContext.getSmart_shuffle());
assertNull(
currentlyPlayingContext.getContext());
assertEquals(
Expand All @@ -97,6 +95,8 @@ public void shouldReturnDefault(final CurrentlyPlayingContext currentlyPlayingCo
assertEquals(
2,
currentlyPlayingContext.getActions().getDisallows().getDisallowedActions().size());
assertFalse(
currentlyPlayingContext.getSmart_shuffle());
}

@Test
Expand All @@ -117,8 +117,6 @@ public void shouldReturnDefaultEpisode(final CurrentlyPlayingContext currentlyPl
currentlyPlayingContext.getRepeat_state());
assertFalse(
currentlyPlayingContext.getShuffle_state());
assertFalse(
currentlyPlayingContext.getSmart_shuffle());
assertNotNull(
currentlyPlayingContext.getContext());
assertEquals(
Expand All @@ -144,6 +142,8 @@ public void shouldReturnDefaultEpisode(final CurrentlyPlayingContext currentlyPl
assertEquals(
4,
currentlyPlayingContext.getActions().getDisallows().getDisallowedActions().size());
assertFalse(
currentlyPlayingContext.getSmart_shuffle());
}

@Test
Expand Down