Search in sources :

Example 21 with Match

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

the class MyTbaModelRenderer method renderFromKey.

@WorkerThread
@Override
@Nullable
public ListElement renderFromKey(String key, ModelType type, Void args) {
    String text;
    switch(type) {
        case EVENT:
            Event event = mDatafeed.fetchEvent(key).toBlocking().first();
            if (event == null) {
                return new ModelListElement(key, key, type);
            }
            return mEventRenderer.renderFromModel(event, true);
        case TEAM:
            Team team = mDatafeed.fetchTeam(key).toBlocking().first();
            if (team == null) {
                return new ModelListElement(key, key, type);
            }
            return mTeamRenderer.renderFromModel(team, TeamRenderer.RENDER_MYTBA_DETAILS);
        case MATCH:
            Match match = mDatafeed.fetchMatch(key).toBlocking().first();
            if (match == null) {
                return new ModelListElement(key, key, type);
            }
            return mMatchRenderer.renderFromModel(match, MatchRenderer.RENDER_DEFAULT);
        case EVENTTEAM:
            String teamKey = EventTeamHelper.getTeamKey(key);
            String eventKey = EventTeamHelper.getEventKey(key);
            Team eTeam = mDatafeed.fetchTeam(teamKey).toBlocking().first();
            Event eEvent = mDatafeed.fetchEvent(eventKey).toBlocking().first();
            if (eTeam == null || eEvent == null) {
                text = String.format("%1$s @ %2$s", teamKey, eventKey);
                return new ModelListElement(text, key, type);
            }
            text = String.format("%1$s @ %2$d %3$s", eTeam.getNickname(), eEvent.getYear(), eEvent.getShortName());
            return new ModelListElement(text, key, type);
        case DISTRICT:
            DistrictListElement element = mDistrictRenderer.renderFromKey(key, ModelType.DISTRICT, new DistrictRenderer.RenderArgs(0, true));
            if (element == null) {
                return new ModelListElement(key, key, type);
            }
            return element;
        default:
            return null;
    }
}
Also used : Event(com.thebluealliance.androidclient.models.Event) ModelListElement(com.thebluealliance.androidclient.listitems.ModelListElement) Team(com.thebluealliance.androidclient.models.Team) DistrictListElement(com.thebluealliance.androidclient.listitems.DistrictListElement) Match(com.thebluealliance.androidclient.models.Match) WorkerThread(androidx.annotation.WorkerThread) Nullable(androidx.annotation.Nullable)

Example 22 with Match

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

the class MatchDeserializer method deserialize.

@Override
public Match deserialize(final JsonElement json, Type typeOf, JsonDeserializationContext context) throws JsonParseException {
    final JsonObject object = json.getAsJsonObject();
    final Match match = new Match();
    if (object.has("key")) {
        String matchKey = object.get("key").getAsString();
        String eventKey = MatchHelper.getEventKeyFromMatchKey(matchKey);
        match.setKey(matchKey);
        match.setEventKey(eventKey);
    }
    if (object.has("comp_level")) {
        match.setCompLevel(object.get("comp_level").getAsString());
    }
    if (object.has("match_number")) {
        match.setMatchNumber(object.get("match_number").getAsInt());
    }
    if (object.has("set_number")) {
        match.setSetNumber(object.get("set_number").getAsInt());
    }
    if (object.has(ALLIANCE_TAG) && object.get(ALLIANCE_TAG).isJsonObject()) {
        match.setAlliances(context.deserialize(object.get(ALLIANCE_TAG), MatchAlliancesContainer.class));
    }
    if (object.has("winning_alliance")) {
        match.setWinningAlliance(object.get("winning_alliance").getAsString());
    }
    if (!isNull(object.get("time"))) {
        match.setTime(object.get("time").getAsLong());
    }
    if (object.has("videos") && object.get("videos").isJsonArray()) {
        match.setVideos(context.deserialize(object.get("videos"), new TypeToken<List<Match.MatchVideo>>() {
        }.getType()));
    }
    if (object.has("score_breakdown") && object.get("score_breakdown").isJsonObject()) {
        match.setScoreBreakdown(object.get("score_breakdown").toString());
    }
    return match;
}
Also used : JsonObject(com.google.gson.JsonObject) List(java.util.List) MatchAlliancesContainer(com.thebluealliance.androidclient.models.MatchAlliancesContainer) Match(com.thebluealliance.androidclient.models.Match)

Example 23 with Match

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

the class MatchesTable method getTeamAtEventMatches.

public List<Match> getTeamAtEventMatches(String teamKey, String eventKey) {
    Cursor cursor = mDb.rawQuery("SELECT * FROM `" + Database.TABLE_MATCHES + "` WHERE `" + EVENT + "` = ? AND `" + ALLIANCES + "` LIKE '%\"" + teamKey + "\"%'", new String[] { eventKey });
    List<Match> 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 : ArrayList(java.util.ArrayList) Cursor(android.database.Cursor) 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