use of com.thebluealliance.androidclient.models.Media in project the-blue-alliance-android by the-blue-alliance.
the class TeamInfoSubscriber method parseData.
@Override
public void parseData() {
mDataToBind = new TeamInfoBinder.Model();
Map<MediaType, String> socialMediaByType = Utilities.getMapForPlatform(MediaType.class, String.class);
Team team = mAPIData.team;
List<Media> socialMedia = mAPIData.socialMedia;
mDataToBind.teamKey = team.getKey();
mDataToBind.fullName = team.getName();
mDataToBind.nickname = team.getNickname();
mDataToBind.teamNumber = team.getTeamNumber();
mDataToBind.location = team.getLocation();
if (team.getWebsite() != null) {
mDataToBind.website = team.getWebsite();
} else {
mDataToBind.website = "";
}
if (team.getMotto() != null) {
mDataToBind.motto = team.getMotto();
} else {
mDataToBind.motto = "";
}
// Separate social medias by type
mDataToBind.socialMedia = socialMediaByType;
for (int i = 0; socialMedia != null && i < socialMedia.size(); i++) {
Media media = socialMedia.get(i);
MediaType mediaType = MediaType.fromString(media.getType());
socialMediaByType.put(mediaType, media.getForeignKey());
}
// CMP Pit Location Stuff
mDataToBind.showPitLocation = PitLocationHelper.shouldShowPitLocation(mAppConfig);
mDataToBind.pitLocation = PitLocationHelper.getPitLocation(mContext, team.getKey());
}
use of com.thebluealliance.androidclient.models.Media in project the-blue-alliance-android by the-blue-alliance.
the class MediasTableTest method testUpdate.
@Test
public void testUpdate() {
Media result = DbTableTestDriver.testUpdate(mTable, mMedias.get(0), media -> media.setDetails("meow"), mGson);
assertNotNull(result);
assertEquals("meow", result.getDetails());
}
use of com.thebluealliance.androidclient.models.Media in project the-blue-alliance-android by the-blue-alliance.
the class TBAApiTest method testParseMedia.
@org.junit.Test
public void testParseMedia() {
String mediaJson = "[" + " {" + " \"type\": \"cdphotothread\"," + " \"details\": {" + " \"image_partial\": \"fe3/fe38d320428adf4f51ac969efb3db32c_l.jpg\"" + " }," + " \"foreign_key\": \"39894\"" + " }," + " {" + " \"type\": \"youtube\"," + " \"details\": {}," + " \"foreign_key\": \"RpSgUrsghv4\"" + " }" + "]";
ArrayList<Media> medias = new ArrayList<>();
JsonArray mediaArray = JSONHelper.getasJsonArray(mediaJson);
for (JsonElement media : mediaArray) {
medias.add(JSONHelper.getGson().fromJson(media, Media.class));
}
assertEquals(medias.size(), mediaArray.size());
assertEquals(medias.size(), 2);
Media cd = medias.get(0);
Media yt = medias.get(1);
assertEquals(cd.getForeignKey(), "39894");
assertEquals(MediaType.fromString(cd.getType()), MediaType.CD_PHOTO_THREAD);
assertEquals(cd.getDetailsJson(), JSONHelper.getasJsonObject("{\"image_partial\": \"fe3/fe38d320428adf4f51ac969efb3db32c_l" + ".jpg\"}"));
assertEquals(MediaType.fromString(yt.getType()), MediaType.YOUTUBE);
assertEquals(yt.getForeignKey(), "RpSgUrsghv4");
assertEquals(yt.getDetailsJson(), new JsonObject());
}
use of com.thebluealliance.androidclient.models.Media in project the-blue-alliance-android by the-blue-alliance.
the class MediaDeserializer method deserialize.
@Override
public Media deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
JsonObject object = json.getAsJsonObject();
Media media = new Media();
if (object.has("type")) {
media.setType(object.get("type").getAsString());
}
if (object.has("foreign_key")) {
media.setForeignKey(object.get("foreign_key").getAsString());
} else if (object.has("key")) {
// allow us to also deserialize medias coming from the match endpoint
media.setForeignKey(object.get("key").getAsString());
}
media.setBase64Image("");
if (object.has("details")) {
JsonObject detailsObject = object.get("details").getAsJsonObject();
if (detailsObject.has("base64Image")) {
media.setBase64Image(detailsObject.get("base64Image").toString());
detailsObject.remove("base64Image");
}
media.setDetails(detailsObject.toString());
}
return media;
}
use of com.thebluealliance.androidclient.models.Media in project the-blue-alliance-android by the-blue-alliance.
the class TeamMediaKeyAdder method call.
@Override
public List<Media> call(List<Media> medias) {
if (medias == null)
return null;
for (Media media : medias) {
media.setYear(mYear);
media.setTeamKey(mTeamKey);
}
return medias;
}
Aggregations