Search in sources :

Example 1 with DistrictPointBreakdown

use of com.thebluealliance.androidclient.models.DistrictPointBreakdown in project the-blue-alliance-android by the-blue-alliance.

the class TeamAtDistrictBreakdownSubscriber method parseData.

@Override
public synchronized void parseData() {
    mDataToBind.clear();
    List<IDistrictEventPoints> eventBreakdowns = mAPIData.getEventPoints();
    if (eventBreakdowns == null) {
        return;
    }
    for (IDistrictEventPoints eventData : eventBreakdowns) {
        Event event = mDb.getEventsTable().get(eventData.getEventKey());
        DistrictPointBreakdown breakdown = (DistrictPointBreakdown) eventData;
        ListGroup eventGroup = new ListGroup(event == null ? eventData.getEventKey() : event.getName());
        if (breakdown.getQualPoints() > -1) {
            eventGroup.children.add(breakdown.renderQualPoints(mResources));
        }
        if (breakdown.getElimPoints() > -1) {
            eventGroup.children.add(breakdown.renderElimPoints(mResources));
        }
        if (breakdown.getAlliancePoints() > -1) {
            eventGroup.children.add(breakdown.renderAlliancePoints(mResources));
        }
        if (breakdown.getAwardPoints() > -1) {
            eventGroup.children.add(breakdown.renderAwardPoints(mResources));
        }
        if (breakdown.getTotal() > -1) {
            eventGroup.children.add(breakdown.renderTotalPoints(mResources));
        }
        mDataToBind.add(eventGroup);
    }
}
Also used : IDistrictEventPoints(com.thebluealliance.api.model.IDistrictEventPoints) ListGroup(com.thebluealliance.androidclient.listitems.ListGroup) Event(com.thebluealliance.androidclient.models.Event) DistrictPointBreakdown(com.thebluealliance.androidclient.models.DistrictPointBreakdown)

Example 2 with DistrictPointBreakdown

use of com.thebluealliance.androidclient.models.DistrictPointBreakdown in project the-blue-alliance-android by the-blue-alliance.

the class DistrictPointsListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    JsonObject rankingsData = mAPIData.getAsJsonObject();
    if (!rankingsData.has("points")) {
        return;
    }
    JsonObject points = rankingsData.get("points").getAsJsonObject();
    String districtKey = "";
    Event event = mDb.getEventsTable().get(mEventKey);
    if (event != null) {
        boolean isDistrict = (event.getDistrict() != null);
        ((Type) mDataToBind).isDistrict = isDistrict;
        if (isDistrict) {
            districtKey = event.getDistrict().getKey();
        }
    }
    ArrayList<DistrictPointBreakdown> pointBreakdowns = new ArrayList<>();
    for (Map.Entry<String, JsonElement> teamPoints : points.entrySet()) {
        Team team = mDb.getTeamsTable().get(teamPoints.getKey());
        DistrictPointBreakdown b = mGson.fromJson(teamPoints.getValue(), DistrictPointBreakdown.class);
        b.setTeamKey(teamPoints.getKey());
        b.setTeamName(team != null ? team.getNickname() : "Team " + teamPoints.getKey().substring(3));
        b.setDistrictKey(districtKey);
        pointBreakdowns.add(b);
    }
    Collections.sort(pointBreakdowns, new PointBreakdownComparater());
    for (int i = 0; i < pointBreakdowns.size(); i++) {
        pointBreakdowns.get(i).setRank(i + 1);
        mDataToBind.add(mRenderer.renderFromModel(pointBreakdowns.get(i), null));
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) JsonElement(com.google.gson.JsonElement) Event(com.thebluealliance.androidclient.models.Event) Team(com.thebluealliance.androidclient.models.Team) PointBreakdownComparater(com.thebluealliance.androidclient.comparators.PointBreakdownComparater) DistrictPointBreakdown(com.thebluealliance.androidclient.models.DistrictPointBreakdown) Map(java.util.Map)

Aggregations

DistrictPointBreakdown (com.thebluealliance.androidclient.models.DistrictPointBreakdown)2 Event (com.thebluealliance.androidclient.models.Event)2 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 PointBreakdownComparater (com.thebluealliance.androidclient.comparators.PointBreakdownComparater)1 ListGroup (com.thebluealliance.androidclient.listitems.ListGroup)1 Team (com.thebluealliance.androidclient.models.Team)1 IDistrictEventPoints (com.thebluealliance.api.model.IDistrictEventPoints)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1