Search in sources :

Example 1 with TeamRankingViewModel

use of com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel 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)

Example 2 with TeamRankingViewModel

use of com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel in project the-blue-alliance-android by the-blue-alliance.

the class EventRankingsFragment method initializeAdapterCreator.

@Override
public void initializeAdapterCreator(SmartAdapter.MultiAdaptersCreator creator) {
    creator.map(TeamRankingViewModel.class, TeamRankingItemView.class);
    creator.listener((actionId, item, position, view) -> {
        if (actionId == Interactions.TEAM_RANKING_CLICKED && item instanceof TeamRankingViewModel) {
            TeamRankingViewModel ranking = (TeamRankingViewModel) item;
            startActivity(TeamAtEventActivity.newInstance(getContext(), mEventKey, ranking.getTeamKey()));
            /* Track the call */
            AnalyticsHelper.sendClickUpdate(getActivity(), "team@event_click", "EventRankingsFragment", mEventKey);
        } else if (actionId == Interactions.EXPAND_TEAM_RANKING && view instanceof TeamRankingItemView) {
            TeamRankingItemView itemView = (TeamRankingItemView) view;
            itemView.toggleRankingsExpanded();
        }
    });
}
Also used : TeamRankingViewModel(com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel) TeamRankingItemView(com.thebluealliance.androidclient.itemviews.TeamRankingItemView)

Aggregations

TeamRankingViewModel (com.thebluealliance.androidclient.viewmodels.TeamRankingViewModel)2 EventRankingsEvent (com.thebluealliance.androidclient.eventbus.EventRankingsEvent)1 RankingFormatter.buildRankingString (com.thebluealliance.androidclient.helpers.RankingFormatter.buildRankingString)1 TeamRankingItemView (com.thebluealliance.androidclient.itemviews.TeamRankingItemView)1 Team (com.thebluealliance.androidclient.models.Team)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