Search in sources :

Example 6 with Match

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

the class ScoreNotification method parseMessageData.

@Override
public void parseMessageData() throws JsonParseException {
    JsonObject jsonData = JSONHelper.getasJsonObject(messageData);
    if (!jsonData.has("match")) {
        throw new JsonParseException("Notification data does not contain 'match");
    }
    JsonObject match = jsonData.get("match").getAsJsonObject();
    this.match = mGson.fromJson(match, Match.class);
    this.matchKey = this.match.getKey();
    this.eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey);
    if (!jsonData.has("event_name")) {
        throw new JsonParseException("Notification data does not contain 'event_name");
    }
    eventName = jsonData.get("event_name").getAsString();
}
Also used : JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) Match(com.thebluealliance.androidclient.models.Match)

Example 7 with Match

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

the class ModelInflater method inflateMatch.

/**
 * Inflate a match model from a single row of a cursor returned by a database query.
 *
 * @param data Cursor of data. Ensure that it's not null and is pointing to a valid row
 * @return Match model containing the fields as defined in the cursor
 */
public static Match inflateMatch(Cursor data, Gson gson) {
    Match match = new Match();
    for (int i = 0; i < data.getColumnCount(); i++) {
        switch(data.getColumnName(i)) {
            case MatchesTable.KEY:
                match.setKey(data.getString(i));
                match.setCompLevel(MatchType.fromKey(match.getKey()).getCompLevel());
                break;
            case MatchesTable.TIME:
                match.setTime(data.getLong(i));
                break;
            case MatchesTable.ALLIANCES:
                match.setAlliances(gson.fromJson(data.getString(i), MatchAlliancesContainer.class));
                break;
            case MatchesTable.WINNER:
                match.setWinningAlliance(data.getString(i));
                break;
            case MatchesTable.VIDEOS:
                match.setVideos(gson.fromJson(data.getString(i), new TypeToken<List<Match.MatchVideo>>() {
                }.getType()));
                break;
            case MatchesTable.MATCHNUM:
                match.setMatchNumber(data.getInt(i));
                break;
            case MatchesTable.SETNUM:
                match.setSetNumber(data.getInt(i));
                break;
            case MatchesTable.BREAKDOWN:
                match.setScoreBreakdown(data.getString(i));
                break;
            case MatchesTable.LAST_MODIFIED:
                match.setLastModified(data.getLong(i));
                break;
            case MatchesTable.EVENT:
                match.setEventKey(data.getString(i));
                break;
            default:
        }
    }
    return match;
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) MatchAlliancesContainer(com.thebluealliance.androidclient.models.MatchAlliancesContainer) Match(com.thebluealliance.androidclient.models.Match)

Example 8 with Match

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

the class MatchListAdapter method getChildView.

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    if (groupPosition >= mGroups.size() || childPosition >= mGroups.get(groupPosition).children.size()) {
        // Can't render due to bounds errors
        return new LabelValueListItem("Match", "Unable to render").getView(mActivity, mInflater, convertView);
    }
    RenderableModel child = mGroups.get(groupPosition).children.get(childPosition);
    if (child instanceof Match) {
        ((Match) child).setSelectedTeam(mTeamKey);
    }
    ListItem renderedChild = child.render(mRendererSupplier);
    if (renderedChild != null) {
        return renderedChild.getView(mActivity, mInflater, convertView);
    } else {
        return new LabelValueListItem("Match", "Unable to render").getView(mActivity, mInflater, convertView);
    }
}
Also used : LabelValueListItem(com.thebluealliance.androidclient.listitems.LabelValueListItem) ListItem(com.thebluealliance.androidclient.listitems.ListItem) LabelValueListItem(com.thebluealliance.androidclient.listitems.LabelValueListItem) RenderableModel(com.thebluealliance.androidclient.interfaces.RenderableModel) Match(com.thebluealliance.androidclient.models.Match)

Example 9 with Match

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

the class ScoreNotificationTest method testDbWrite.

@Test
public void testDbWrite() {
    mNotification.parseMessageData();
    mNotification.updateDataLocally();
    Match match = mNotification.getMatch();
    verify(mWriter).write(eq(match), anyLong());
}
Also used : Match(com.thebluealliance.androidclient.models.Match) Test(org.junit.Test)

Example 10 with Match

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

the class MatchHelperTest method markMatchesPlayed.

private static void markMatchesPlayed(List<Match> matches, int start, int end) {
    for (int i = start; i < matches.size() && i < end; i++) {
        Match match = matches.get(i);
        when(match.hasBeenPlayed()).thenReturn(true);
    }
}
Also used : Match(com.thebluealliance.androidclient.models.Match)

Aggregations

Match (com.thebluealliance.androidclient.models.Match)23 JsonObject (com.google.gson.JsonObject)8 MatchType (com.thebluealliance.androidclient.types.MatchType)6 Test (org.junit.Test)6 LayoutInflater (android.view.LayoutInflater)5 View (android.view.View)5 FrameLayout (android.widget.FrameLayout)5 ArrayList (java.util.ArrayList)4 Event (com.thebluealliance.androidclient.models.Event)3 Nullable (androidx.annotation.Nullable)2 JsonParseException (com.google.gson.JsonParseException)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 MatchAlliancesContainer (com.thebluealliance.androidclient.models.MatchAlliancesContainer)2 Team (com.thebluealliance.androidclient.models.Team)2 List (java.util.List)2 Cursor (android.database.Cursor)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 WorkerThread (androidx.annotation.WorkerThread)1 MatchSortByDisplayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByDisplayOrderComparator)1