use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.
the class TeamAtEventActivity method updateEventSelector.
private void updateEventSelector(int selectedPosition) {
if (selectedPosition < 0 || selectedPosition >= mEventsParticipated.size()) {
return;
}
Event selectedEvent = mEventsParticipated.get(selectedPosition);
mEventSelectorSubtitle.setText(getString(R.string.team_at_event_actionbar_subtitle, selectedEvent.getYear(), selectedEvent.getShortName()));
}
use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.
the class TBAApiTest method testParseEvent.
@org.junit.Test
public void testParseEvent() {
String eventJson = "{\"key\": \"2014ctgro\", \"end_date\": \"2014-03-09\", \"name\": \"Groton District Event\", \"short_name\": \"Groton\", \"facebook_eid\": null, \"official\": true, \"location\": \"Groton, CT, USA\", \"event_code\": \"ctgro\", \"year\": 2014, \"event_type_string\": \"District\", \"start_date\": \"2014-03-08\", \"event_type\": 1}";
Event event = JSONHelper.getGson().fromJson(eventJson, Event.class);
// now, assert that all the properties are there
assertEquals(event.getKey(), "2014ctgro");
assertEquals(event.getStartDate().getTime(), new Date(114, 2, 8).getTime());
assertEquals(event.getEndDate().getTime(), new Date(114, 2, 9).getTime());
assertEquals(event.getName(), "Groton District Event");
assertEquals(event.getShortName(), "Groton");
assertEquals(event.getAddress(), "Groton, CT, USA");
assertEquals(event.getEventTypeEnum(), EventType.DISTRICT);
}
use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.
the class EventDeserializer method deserialize.
@Override
public Event deserialize(final JsonElement json, Type typeOf, JsonDeserializationContext context) throws JsonParseException {
final JsonObject object;
try {
object = json.getAsJsonObject();
} catch (JsonSyntaxException | IllegalStateException ex) {
TbaLogger.w("Failed to parse json: " + json.toString());
return null;
}
final Event event = new Event();
if (object.has("key")) {
String key = object.get("key").getAsString();
int year = EventHelper.getYear(key);
event.setKey(key);
event.setYear(year);
}
if (object.has("name")) {
event.setName(object.get("name").getAsString());
}
if (isNull(object.get("address"))) {
event.setAddress("");
} else {
event.setAddress(object.get("address").getAsString());
}
if (isNull(object.get("location_name"))) {
event.setLocationName("");
} else {
event.setLocationName(object.get("location_name").getAsString());
}
if (isNull(object.get("city")) || isNull(object.get("state_prov")) || isNull(object.get("country"))) {
event.setLocation("");
} else {
event.setLocation(object.get("city").getAsString() + ", " + object.get("state_prov").getAsString() + ", " + object.get("country").getAsString());
event.setCity(object.get("city").getAsString());
}
if (object.has("event_type")) {
event.setEventType(object.get("event_type").getAsInt());
}
if (isNull(object.get("start_date"))) {
event.setStartDate("");
} else {
event.setStartDate(object.get("start_date").getAsString());
}
if (!isNull(object.get("week"))) {
event.setWeek(object.get("week").getAsInt() + 1);
} else {
event.setCompetitionWeekFromStartDate();
}
if (isNull(object.get("end_date"))) {
event.setEndDate("");
} else {
event.setEndDate(object.get("end_date").getAsString());
}
// If it is null, simply use the event name as the short name
if (isNull(object.get("short_name"))) {
event.setShortName("");
} else {
event.setShortName(object.get("short_name").getAsString());
}
if (!isNull(object.get("website"))) {
event.setWebsite(object.get("website").getAsString());
}
if (object.has("webcasts")) {
event.setWebcasts(object.get("webcasts").toString());
}
JsonElement district = object.get("district");
if (isNull(district)) {
event.setDistrict(null);
} else {
District districtModel = context.deserialize(object.get("district"), District.class);
event.setDistrict(districtModel);
event.setDistrictKey(districtModel.getKey());
}
return event;
}
use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.
the class APICache method fetchEventsInMonth.
public Observable<List<Event>> fetchEventsInMonth(int year, int month) {
return Observable.create((observer) -> {
try {
Calendar cal = Calendar.getInstance();
cal.clear();
cal.set(year, month, 1);
String start = Long.toString(cal.getTimeInMillis());
cal.add(Calendar.MONTH, 1);
cal.add(Calendar.DAY_OF_MONTH, -1);
String end = Long.toString(cal.getTimeInMillis());
String where = String.format("%1$s >= ? AND %2$s <= ?", EventsTable.START, EventsTable.START);
List<Event> events = mDb.getEventsTable().getForQuery(null, where, new String[] { start, end });
observer.onNext(events);
observer.onCompleted();
} catch (Exception e) {
observer.onError(e);
}
});
}
use of com.thebluealliance.androidclient.models.Event in project the-blue-alliance-android by the-blue-alliance.
the class APICache method fetchEvent.
public Observable<Event> fetchEvent(String eventKey) {
return Observable.create((observer) -> {
try {
Event event = mDb.getEventsTable().get(eventKey);
observer.onNext(event);
observer.onCompleted();
} catch (Exception e) {
observer.onError(e);
}
});
}
Aggregations