Search in sources :

Example 1 with MatchListElement

use of com.thebluealliance.androidclient.listitems.MatchListElement 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 MatchListElement

use of com.thebluealliance.androidclient.listitems.MatchListElement in project the-blue-alliance-android by the-blue-alliance.

the class MatchInfoSubscriberTest method testParsedData.

@Test
public void testParsedData() {
    List<ListItem> data = DatafeedTestDriver.getParsedData(mSubscriber, mData);
    assertEquals(3, data.size());
    assertTrue(data.get(0) instanceof MatchListElement);
    assertTrue(data.get(1) instanceof ImageListElement);
    Media videoItem = ((Match.MatchVideo) mData.match.getVideos().get(0)).asMedia();
    ImageListElement video = (ImageListElement) data.get(1);
    verify(mRenderer).renderFromModel(mData.match, MatchRenderer.RENDER_MATCH_INFO);
    assertTrue(video.equals(mMediaRenderer.renderFromModel(videoItem, null)));
}
Also used : ImageListElement(com.thebluealliance.androidclient.listitems.ImageListElement) MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement) Media(com.thebluealliance.androidclient.models.Media) ListItem(com.thebluealliance.androidclient.listitems.ListItem) Test(org.junit.Test)

Example 3 with MatchListElement

use of com.thebluealliance.androidclient.listitems.MatchListElement in project the-blue-alliance-android by the-blue-alliance.

the class UpcomingMatchNotification method getView.

@Override
public View getView(Context c, LayoutInflater inflater, View convertView) {
    ViewHolder holder;
    if (convertView == null || !(convertView.getTag() instanceof ViewHolder)) {
        convertView = inflater.inflate(R.layout.list_item_notification_upcoming_match, null, false);
        holder = new ViewHolder();
        holder.header = (TextView) convertView.findViewById(R.id.card_header);
        holder.title = (TextView) convertView.findViewById(R.id.title);
        holder.matchView = (MatchView) convertView.findViewById(R.id.match_details);
        holder.time = (TextView) convertView.findViewById(R.id.notification_time);
        holder.summaryContainer = convertView.findViewById(R.id.summary_container);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }
    holder.header.setText(c.getString(R.string.gameday_ticker_event_title_format, EventHelper.shortName(eventName), EventHelper.getShortCodeForEventKey(eventKey).toUpperCase()));
    holder.title.setText(c.getString(R.string.notification_upcoming_match_gameday_title, MatchHelper.getMatchTitleFromMatchKey(c, matchKey)));
    holder.time.setText(getNotificationTimeString(c));
    holder.summaryContainer.setOnClickListener(new GamedayTickerClickListener(c, this));
    new MatchListElement(redTeams, blueTeams, matchKey, JSONHelper.isNull(matchTime) ? -1 : matchTime.getAsLong(), null).getView(c, inflater, holder.matchView);
    return convertView;
}
Also used : GamedayTickerClickListener(com.thebluealliance.androidclient.listeners.GamedayTickerClickListener) MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement)

Example 4 with MatchListElement

use of com.thebluealliance.androidclient.listitems.MatchListElement in project the-blue-alliance-android by the-blue-alliance.

the class MatchRendererTest method testRenderFromModel.

@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);
    }
}
Also used : MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement) RenderArgs(com.thebluealliance.androidclient.renderers.MatchRenderer.RenderArgs) RenderType(com.thebluealliance.androidclient.renderers.MatchRenderer.RenderType) Test(org.junit.Test)

Example 5 with MatchListElement

use of com.thebluealliance.androidclient.listitems.MatchListElement in project the-blue-alliance-android by the-blue-alliance.

the class MatchRendererTest method testRenderFromKey.

@Test
public void testRenderFromKey() {
    when(mDatafeed.fetchMatch(mMatchKey)).thenReturn(Observable.just(mMatch));
    MatchListElement element = mRenderer.renderFromKey(mMatchKey, ModelType.MATCH, null);
    RenderArgs expectedArgs = MatchRenderer.argsFromMode(RENDER_DEFAULT);
    assertMatch(element, mMatch, expectedArgs);
}
Also used : MatchListElement(com.thebluealliance.androidclient.listitems.MatchListElement) RenderArgs(com.thebluealliance.androidclient.renderers.MatchRenderer.RenderArgs) Test(org.junit.Test)

Aggregations

MatchListElement (com.thebluealliance.androidclient.listitems.MatchListElement)9 GamedayTickerClickListener (com.thebluealliance.androidclient.listeners.GamedayTickerClickListener)4 Test (org.junit.Test)4 RenderArgs (com.thebluealliance.androidclient.renderers.MatchRenderer.RenderArgs)2 WorkerThread (androidx.annotation.WorkerThread)1 JsonObject (com.google.gson.JsonObject)1 ImageListElement (com.thebluealliance.androidclient.listitems.ImageListElement)1 ListItem (com.thebluealliance.androidclient.listitems.ListItem)1 Media (com.thebluealliance.androidclient.models.Media)1 RenderType (com.thebluealliance.androidclient.renderers.MatchRenderer.RenderType)1 IMatchAlliancesContainer (com.thebluealliance.api.model.IMatchAlliancesContainer)1 IMatchVideo (com.thebluealliance.api.model.IMatchVideo)1 Nullable (javax.annotation.Nullable)1