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;
}
}
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;
}
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;
}
Aggregations