Search in sources :

Example 1 with EventRankingsEvent

use of com.thebluealliance.androidclient.eventbus.EventRankingsEvent in project the-blue-alliance-android by the-blue-alliance.

the class RankingsListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    if (mAPIData == null || mAPIData.getRankings() == null || mAPIData.getRankings().isEmpty()) {
        return;
    }
    List<IRankingItem> rankings = mAPIData.getRankings();
    List<IRankingSortOrder> sortOrders = mAPIData.getSortOrderInfo();
    List<IRankingSortOrder> extraStats = mAPIData.getExtraStatsInfo();
    IRankingSortOrder firstSortInfo = sortOrders.remove(0);
    for (int i = 0; i < rankings.size(); i++) {
        IRankingItem row = rankings.get(i);
        /* Assume that the list of lists has rank first and team # second, always */
        String teamKey = row.getTeamKey();
        String rankingString;
        String rankingSummary;
        String record;
        @Nullable ITeamRecord teamRecord = row.getRecord();
        if (teamRecord != null) {
            record = "(" + RankingItem.TeamRecord.buildRecordString(teamRecord) + ")";
        } else {
            record = "";
        }
        // Remove the first sort item so we don't show duplicates
        Double firstSort = row.getSortOrders().remove(0);
        rankingSummary = mResources.getString(R.string.rank_item_summary, firstSortInfo.getName(), formatSortOrder(firstSortInfo, firstSort));
        rankingString = buildRankingString(row, sortOrders, extraStats, mResources, BOLD_TITLES | LINE_BREAKS);
        Team team = mDb.getTeamsTable().get(teamKey);
        String nickname;
        if (team != null) {
            nickname = team.getNickname();
        } else {
            nickname = "Team " + teamKey.substring(3);
        }
        mDataToBind.add(new TeamRankingViewModel(teamKey, nickname, // team number
        teamKey.substring(3), // rank
        row.getRank(), record, rankingSummary, rankingString));
    }
    mEventBus.post(new EventRankingsEvent(generateTopRanksString(mAPIData)));
}
Also used : ITeamRecord(com.thebluealliance.api.model.ITeamRecord) IRankingItem(com.thebluealliance.api.model.IRankingItem) EventRankingsEvent(com.thebluealliance.androidclient.eventbus.EventRankingsEvent) IRankingSortOrder(com.thebluealliance.api.model.IRankingSortOrder) Team(com.thebluealliance.androidclient.models.Team) RankingFormatter.buildRankingString(com.thebluealliance.androidclient.helpers.RankingFormatter.buildRankingString) TeamRankingViewModel(com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel) Nullable(javax.annotation.Nullable)

Aggregations

EventRankingsEvent (com.thebluealliance.androidclient.eventbus.EventRankingsEvent)1 RankingFormatter.buildRankingString (com.thebluealliance.androidclient.helpers.RankingFormatter.buildRankingString)1 Team (com.thebluealliance.androidclient.models.Team)1 TeamRankingViewModel (com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel)1 IRankingItem (com.thebluealliance.api.model.IRankingItem)1 IRankingSortOrder (com.thebluealliance.api.model.IRankingSortOrder)1 ITeamRecord (com.thebluealliance.api.model.ITeamRecord)1 Nullable (javax.annotation.Nullable)1