Search in sources :

Example 1 with IMatchVideo

use of com.thebluealliance.api.model.IMatchVideo in project the-blue-alliance-android by the-blue-alliance.

the class MatchRenderer method renderFromModel.

/**
 * Renders a MatchListElement for displaying this match. ASSUMES 3v3 match structure with
 * red/blue alliances Use different render methods for other structures
 */
@WorkerThread
@Override
@Nullable
public MatchListElement renderFromModel(Match match, Integer renderMode) {
    RenderArgs args = argsFromMode(renderMode);
    @Nullable IMatchAlliancesContainer alliances = match.getAlliances();
    @Nullable List<IMatchVideo> videos = match.getVideos();
    String key = match.getKey();
    if (key.isEmpty()) {
        return null;
    }
    String redScore = (alliances == null) ? "-1" : Integer.toString(alliances.getRed().getScore());
    String blueScore = (alliances == null) ? "-1" : Integer.toString(alliances.getBlue().getScore());
    if (Integer.parseInt(redScore) < 0)
        redScore = "?";
    if (Integer.parseInt(blueScore) < 0)
        blueScore = "?";
    String youTubeVideoKey = null;
    if (videos != null) {
        for (IMatchVideo video : videos) {
            if ("youtube".equals(video.getType())) {
                youTubeVideoKey = video.getKey();
                break;
            }
        }
    }
    String[] redAlliance, blueAlliance;
    // Add teams based on alliance size (or none if there isn't for some reason)
    List<String> redTeams = (alliances != null) ? alliances.getRed().getTeamKeys() : null;
    if (redTeams != null && redTeams.size() == 3) {
        redAlliance = new String[] { redTeams.get(0).substring(3), redTeams.get(1).substring(3), redTeams.get(2).substring(3) };
    } else if (redTeams != null && redTeams.size() == 2) {
        redAlliance = new String[] { redTeams.get(0).substring(3), redTeams.get(1).substring(3) };
    } else {
        redAlliance = new String[] { "", "", "" };
    }
    List<String> blueTeams = (alliances != null) ? alliances.getBlue().getTeamKeys() : null;
    if (blueTeams != null && blueTeams.size() == 3) {
        blueAlliance = new String[] { blueTeams.get(0).substring(3), blueTeams.get(1).substring(3), blueTeams.get(2).substring(3) };
    } else if (blueTeams != null && blueTeams.size() == 2) {
        blueAlliance = new String[] { blueTeams.get(0).substring(3), blueTeams.get(1).substring(3) };
    } else {
        blueAlliance = new String[] { "", "", "" };
    }
    long matchTime = match.getTime() != null ? match.getTime() : -1;
    int redExtraRp = 0;
    int blueExtraRp = 0;
    if (match.getYear() >= 2016) {
        JsonObject scoreBreakdown = JSONHelper.getasJsonObject(match.getScoreBreakdown());
        JsonObject redScoreBreakdown = null;
        if (scoreBreakdown.has("red")) {
            redScoreBreakdown = scoreBreakdown.get("red").getAsJsonObject();
        }
        JsonObject blueScoreBreakdown = null;
        if (scoreBreakdown.has("blue")) {
            blueScoreBreakdown = scoreBreakdown.get("blue").getAsJsonObject();
        }
        String rpName1 = null;
        String rpName2 = null;
        switch(match.getYear()) {
            case 2016:
                rpName1 = "teleopDefensesBreached";
                rpName2 = "teleopTowerCaptured";
                break;
            case 2017:
                rpName1 = "kPaRankingPointAchieved";
                rpName2 = "rotorRankingPointAchieved";
                break;
            case 2018:
                rpName1 = "autoQuestRankingPoint";
                rpName2 = "faceTheBossRankingPoint";
                break;
            case 2019:
                rpName1 = "habDockingRankingPoint";
                rpName2 = "completeRocketRankingPoint";
                break;
            case 2020:
                rpName1 = "shieldOperationalRankingPoint";
                rpName2 = "shieldEnergizedRankingPoint";
                break;
        }
        if (rpName1 != null) {
            if (redScoreBreakdown != null && redScoreBreakdown.get(rpName1).getAsBoolean()) {
                redExtraRp++;
            }
            if (blueScoreBreakdown != null && blueScoreBreakdown.get(rpName1).getAsBoolean()) {
                blueExtraRp++;
            }
        }
        if (rpName2 != null) {
            if (redScoreBreakdown != null && redScoreBreakdown.get(rpName2).getAsBoolean()) {
                redExtraRp++;
            }
            if (blueScoreBreakdown != null && blueScoreBreakdown.get(rpName2).getAsBoolean()) {
                blueExtraRp++;
            }
        }
    }
    return new MatchListElement(youTubeVideoKey, match.getTitle(mResources, true), redAlliance, blueAlliance, redScore, blueScore, match.getWinningAlliance(), key, matchTime, match.getSelectedTeam(), args.showVideo, args.showHeaders, args.showMatchTitle, args.clickable, redExtraRp, blueExtraRp);
}
Also used : MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement) IMatchAlliancesContainer(com.thebluealliance.api.model.IMatchAlliancesContainer) JsonObject(com.google.gson.JsonObject) IMatchVideo(com.thebluealliance.api.model.IMatchVideo) Nullable(javax.annotation.Nullable) WorkerThread(androidx.annotation.WorkerThread) Nullable(javax.annotation.Nullable)

Example 2 with IMatchVideo

use of com.thebluealliance.api.model.IMatchVideo in project the-blue-alliance-android by the-blue-alliance.

the class MatchTest method testMatchModel.

@Test
public void testMatchModel() {
    assertNotNull(mMatch);
    assertEquals(mMatch.getKey(), "2014cmp_f1m1");
    assertEquals(mMatch.getMatchNumber().intValue(), 1);
    assertEquals(mMatch.getSetNumber().intValue(), 1);
    assertEquals(mMatch.getEventKey(), "2014cmp");
    assertNotNull(mMatch.getTime());
    assertEquals(mMatch.getTime().intValue(), 1398551880);
    assertNotNull(mMatch.getVideos());
    assertNotNull(mMatch.getAlliances());
    List<IMatchVideo> videos = mMatch.getVideos();
    assertEquals(videos.size(), 2);
    IMatchVideo video1 = videos.get(0);
    assertEquals(video1.getType(), "youtube");
    assertEquals(video1.getKey(), "jdJutaggCMk");
    IMatchAlliancesContainer alliances = mMatch.getAlliances();
    IMatchAlliance blueAlliance = alliances.getBlue();
    assertEquals(blueAlliance.getScore().intValue(), 361);
    List<String> blueTeams = blueAlliance.getTeamKeys();
    assertEquals(blueTeams.size(), 3);
    assertEquals(blueTeams.get(0), "frc469");
}
Also used : IMatchAlliancesContainer(com.thebluealliance.api.model.IMatchAlliancesContainer) IMatchAlliance(com.thebluealliance.api.model.IMatchAlliance) IMatchVideo(com.thebluealliance.api.model.IMatchVideo) Test(org.junit.Test)

Example 3 with IMatchVideo

use of com.thebluealliance.api.model.IMatchVideo in project the-blue-alliance-android by the-blue-alliance.

the class MatchInfoSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    mDataToBind.add(mRenderer.renderFromModel(mAPIData.match, MatchRenderer.RENDER_MATCH_INFO));
    mMatchTitle = mAPIData.match.getTitle(mResources);
    mMatchKey = mAPIData.match.getKey();
    List<IMatchVideo> matchVideos = mAPIData.match.getVideos();
    for (int i = 0; matchVideos != null && i < matchVideos.size(); i++) {
        Match.MatchVideo video = (Match.MatchVideo) matchVideos.get(i);
        if (MediaType.fromString(video.getType()) != MediaType.NONE) {
            Media media = video.asMedia();
            mDataToBind.add(mMediaRenderer.renderFromModel(media, null));
        }
    }
    updateActionBarTitle(mAPIData.event.getShortName());
}
Also used : Media(com.thebluealliance.androidclient.models.Media) IMatchVideo(com.thebluealliance.api.model.IMatchVideo) IMatchVideo(com.thebluealliance.api.model.IMatchVideo) Match(com.thebluealliance.androidclient.models.Match)

Aggregations

IMatchVideo (com.thebluealliance.api.model.IMatchVideo)3 IMatchAlliancesContainer (com.thebluealliance.api.model.IMatchAlliancesContainer)2 WorkerThread (androidx.annotation.WorkerThread)1 JsonObject (com.google.gson.JsonObject)1 MatchListElement (com.thebluealliance.androidclient.listitems.MatchListElement)1 Match (com.thebluealliance.androidclient.models.Match)1 Media (com.thebluealliance.androidclient.models.Media)1 IMatchAlliance (com.thebluealliance.api.model.IMatchAlliance)1 Nullable (javax.annotation.Nullable)1 Test (org.junit.Test)1