@Test public void testRenderFromModel() { @RenderType int[] types = {RENDER_DEFAULT, RENDER_NOTIFICATION, RENDER_MATCH_INFO}; for (int i = 0; i < types.length; i++) { MatchListElement element = mRenderer.renderFromModel(mMatch, types[i]); RenderArgs expectedArgs = MatchRenderer.argsFromMode(types[i]); assertMatch(element, mMatch, expectedArgs); } }
@WorkerThread @Override public @Nullable 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; 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); }
MatchRenderer implements ModelRenderer<Match, Integer> { @WorkerThread @Override public @Nullable 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; 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); } }
MatchRenderer implements ModelRenderer<Match, Integer> { @WorkerThread @Override public @Nullable 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; 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); } MatchRenderer(APICache datafeed, Resources resources); }
MatchRenderer implements ModelRenderer<Match, Integer> { @WorkerThread @Override public @Nullable 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; 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); } MatchRenderer(APICache datafeed, Resources resources); @WorkerThread @Override @Nullable MatchListElement renderFromKey(String key, ModelType type, Integer args); @WorkerThread @Override @Nullable MatchListElement renderFromModel(Match match, Integer renderMode); @VisibleForTesting static RenderArgs argsFromMode(@RenderType Integer type); }
MatchRenderer implements ModelRenderer<Match, Integer> { @WorkerThread @Override public @Nullable 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; 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); } MatchRenderer(APICache datafeed, Resources resources); @WorkerThread @Override @Nullable MatchListElement renderFromKey(String key, ModelType type, Integer args); @WorkerThread @Override @Nullable MatchListElement renderFromModel(Match match, Integer renderMode); @VisibleForTesting static RenderArgs argsFromMode(@RenderType Integer type); static final int RENDER_DEFAULT; static final int RENDER_MATCH_INFO; static final int RENDER_NOTIFICATION; }