Search in sources :

Example 1 with Media

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());
}
Also used : TeamInfoBinder(com.thebluealliance.androidclient.binders.TeamInfoBinder) Media(com.thebluealliance.androidclient.models.Media) MediaType(com.thebluealliance.androidclient.types.MediaType) Team(com.thebluealliance.androidclient.models.Team)

Example 2 with Media

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());
}
Also used : Media(com.thebluealliance.androidclient.models.Media) Test(org.junit.Test)

Example 3 with Media

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());
}
Also used : JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) Media(com.thebluealliance.androidclient.models.Media) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 4 with Media

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;
}
Also used : Media(com.thebluealliance.androidclient.models.Media) JsonObject(com.google.gson.JsonObject)

Example 5 with 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;
}
Also used : Media(com.thebluealliance.androidclient.models.Media)

Aggregations

Media (com.thebluealliance.androidclient.models.Media)10 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 Team (com.thebluealliance.androidclient.models.Team)2 MediaType (com.thebluealliance.androidclient.types.MediaType)2 Context (android.content.Context)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 TeamInfoBinder (com.thebluealliance.androidclient.binders.TeamInfoBinder)1 TeamAvatarUpdateEvent (com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)1 ImageListElement (com.thebluealliance.androidclient.listitems.ImageListElement)1 ListItem (com.thebluealliance.androidclient.listitems.ListItem)1 MatchListElement (com.thebluealliance.androidclient.listitems.MatchListElement)1 Match (com.thebluealliance.androidclient.models.Match)1 IMatchVideo (com.thebluealliance.api.model.IMatchVideo)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1