Skip to content

Commit

Permalink
Merge branch 'ZelKami-episode-types'
Browse files Browse the repository at this point in the history
  • Loading branch information
UweTrottmann committed Jun 7, 2024
2 parents 568ba5c + b3f906f commit 5fa0ae0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/TmdbHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.uwetrottmann.tmdb2.entities.PersonCrewCredit;
import com.uwetrottmann.tmdb2.entities.RatingObject;
import com.uwetrottmann.tmdb2.entities.Trending;
import com.uwetrottmann.tmdb2.enumerations.EpisodeType;
import com.uwetrottmann.tmdb2.enumerations.MediaType;
import com.uwetrottmann.tmdb2.enumerations.Status;
import com.uwetrottmann.tmdb2.enumerations.VideoType;
Expand Down Expand Up @@ -180,6 +181,16 @@ public static GsonBuilder getGsonBuilder() {
return trending;
});

builder.registerTypeAdapter(EpisodeType.class,
(JsonDeserializer<EpisodeType>) (jsonElement, type, jsonDeserializationContext) -> {
String value = jsonElement.getAsString();
if (value != null) {
return EpisodeType.fromValue(value);
} else {
return null;
}
});

return builder;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.uwetrottmann.tmdb2.entities;

import com.uwetrottmann.tmdb2.enumerations.EpisodeType;
import java.util.Date;

public class BaseTvEpisode extends BaseTvEpisodeRatingObject {
Expand All @@ -16,5 +17,6 @@ public class BaseTvEpisode extends BaseTvEpisodeRatingObject {

public Date air_date;
public Integer episode_number;
public EpisodeType episode_type;

}
29 changes: 29 additions & 0 deletions src/main/java/com/uwetrottmann/tmdb2/enumerations/EpisodeType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package com.uwetrottmann.tmdb2.enumerations;

import java.util.HashMap;
import java.util.Map;

public enum EpisodeType {
STANDARD("standard"),
MID_SEASON_FINALE("mid_season"),
FINALE("finale");

private final String value;

EpisodeType(String value) { this.value = value; }

private static final Map<String, EpisodeType> STRING_MAPPING = new HashMap<>();

static {
for (EpisodeType via : EpisodeType.values()) {
STRING_MAPPING.put(via.toString().toUpperCase(), via);
}
}

public static EpisodeType fromValue(String value) {
return STRING_MAPPING.get(value.toUpperCase());
}

@Override
public String toString() { return value; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ public static void assertTvSeason(TvSeason tvSeason) {
assertThat(tvSeason.episodes).isNotEmpty();
for (TvEpisode tvEpisode : tvSeason.episodes) {
assertTvEpisode(tvEpisode);
assertThat(tvEpisode.episode_type).isNotNull();
}
}

Expand Down

0 comments on commit 5fa0ae0

Please sign in to comment.