Search in sources :

Example 1 with Award

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

the class AwardsListSubscriber method parseData.

@Override
public void parseData() {
    mDataToBind.clear();
    Map<String, Team> teams = Utilities.getMapForPlatform(String.class, Team.class);
    ArrayList<Award> sortedAwards = new ArrayList<>(mAPIData);
    Collections.sort(sortedAwards, AWARD_COMPARATOR);
    for (int i = 0; i < sortedAwards.size(); i++) {
        Award award = sortedAwards.get(i);
        if (award.getRecipientList() == null)
            continue;
        for (IAwardRecipient winner : award.getRecipientList()) {
            if (winner != null && winner.getTeamKey() != null) {
                String teamKey = winner.getTeamKey();
                Team team = mDb.getTeamsTable().get(teamKey);
                teams.put(teamKey, team);
            }
        }
        AwardRenderer.RenderArgs args = new AwardRenderer.RenderArgs(teams, mTeamKey);
        mDataToBind.add(mRenderer.renderFromModel(award, args));
    }
}
Also used : IAwardRecipient(com.thebluealliance.api.model.IAwardRecipient) Award(com.thebluealliance.androidclient.models.Award) ArrayList(java.util.ArrayList) Team(com.thebluealliance.androidclient.models.Team) AwardRenderer(com.thebluealliance.androidclient.renderers.AwardRenderer)

Example 2 with Award

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

the class AwardListWriterTest method testAwardListWriter.

@Test
public void testAwardListWriter() {
    mWriter.write(mAwards, 0L);
    SQLiteDatabase db = mDb.getWritableDatabase();
    for (Award award : mAwards) {
        verify(db).insert(Database.TABLE_AWARDS, null, award.getParams(mGson));
    }
}
Also used : SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Award(com.thebluealliance.androidclient.models.Award) Test(org.junit.Test)

Example 3 with Award

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

the class AwardsTableTest method testUpdate.

@Test
public void testUpdate() {
    Award result = DbTableTestDriver.testUpdate(mTable, mAwards.get(0), award -> award.setName("This is an award"), mGson);
    assertNotNull(result);
    assertEquals("This is an award", result.getName());
}
Also used : Award(com.thebluealliance.androidclient.models.Award) Test(org.junit.Test)

Example 4 with Award

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

the class TBAApiTest method testParseAwardNoTeam.

@org.junit.Test
public void testParseAwardNoTeam() {
    String json = "{\n" + "    \"event_key\": \"2010sc\",\n" + "    \"name\": \"FIRST Dean's List Finalist Award\",\n" + "    \"recipient_list\": [\n" + "      {\n" + "        \"team_number\": null,\n" + "        \"awardee\": \"Brandon Dean\"\n" + "      },\n" + "      {\n" + "        \"team_number\": null,\n" + "        \"awardee\": \"Megan Shew\"\n" + "      }\n" + "    ],\n" + "    \"year\": 2010\n" + "  }";
    Award award = JSONHelper.getGson().fromJson(json, Award.class);
    assertEquals(award.getEventKey(), "2010sc");
    assertEquals(award.getName(), "FIRST Dean's List Finalist Award");
    assertEquals(award.getYear().intValue(), 2010);
/*
        JsonArray recips = award.getWinners();
        String[] winners = {"Brandon Dean", "Megan Shew"};
        assertNotNull(recips);
        assertEquals(recips.size(), 2);
        for (int i = 0; i < 2; i++) {
            assertEquals(winners[i], recips.get(i).getAsJsonObject().get("awardee").getAsString());
        }*/
}
Also used : Award(com.thebluealliance.androidclient.models.Award)

Example 5 with Award

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

the class AwardsTable method getTeamAtEventAwards.

public List<Award> getTeamAtEventAwards(String teamNumber, String eventKey) {
    Cursor cursor = mDb.rawQuery("SELECT * FROM `" + Database.TABLE_AWARDS + "` WHERE `" + EVENTKEY + "` = ? AND `" + WINNERS + "` LIKE '%\"team_key\":\"frc" + teamNumber + "\"%'", new String[] { eventKey });
    List<Award> models = new ArrayList<>(cursor == null ? 0 : cursor.getCount());
    if (cursor == null || !cursor.moveToFirst()) {
        return models;
    }
    do {
        models.add(inflate(cursor));
    } while (cursor.moveToNext());
    return models;
}
Also used : Award(com.thebluealliance.androidclient.models.Award) ArrayList(java.util.ArrayList) Cursor(android.database.Cursor)

Aggregations

Award (com.thebluealliance.androidclient.models.Award)11 Test (org.junit.Test)4 CardedAwardListElement (com.thebluealliance.androidclient.listitems.CardedAwardListElement)3 ListItem (com.thebluealliance.androidclient.listitems.ListItem)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 JsonObject (com.google.gson.JsonObject)1 Team (com.thebluealliance.androidclient.models.Team)1 AwardRenderer (com.thebluealliance.androidclient.renderers.AwardRenderer)1 IAwardRecipient (com.thebluealliance.api.model.IAwardRecipient)1 List (java.util.List)1