Search in sources :

Example 1 with Event

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()));
}
Also used : Event(com.thebluealliance.androidclient.models.Event) TeamAvatarUpdateEvent(com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)

Example 2 with Event

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);
}
Also used : Event(com.thebluealliance.androidclient.models.Event) Date(java.util.Date)

Example 3 with Event

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) Event(com.thebluealliance.androidclient.models.Event) District(com.thebluealliance.androidclient.models.District)

Example 4 with 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);
        }
    });
}
Also used : Calendar(java.util.Calendar) Event(com.thebluealliance.androidclient.models.Event)

Example 5 with Event

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);
        }
    });
}
Also used : Event(com.thebluealliance.androidclient.models.Event)

Aggregations

Event (com.thebluealliance.androidclient.models.Event)35 Test (org.junit.Test)8 Team (com.thebluealliance.androidclient.models.Team)6 ArrayList (java.util.ArrayList)5 District (com.thebluealliance.androidclient.models.District)4 Date (java.util.Date)4 JsonObject (com.google.gson.JsonObject)3 TeamAvatarUpdateEvent (com.thebluealliance.androidclient.eventbus.TeamAvatarUpdateEvent)3 Match (com.thebluealliance.androidclient.models.Match)3 EventRenderer (com.thebluealliance.androidclient.renderers.EventRenderer)3 Before (org.junit.Before)3 Cursor (android.database.Cursor)2 Nullable (androidx.annotation.Nullable)2 WorkerThread (androidx.annotation.WorkerThread)2 JsonElement (com.google.gson.JsonElement)2 MatchSortByPlayOrderComparator (com.thebluealliance.androidclient.comparators.MatchSortByPlayOrderComparator)2 EventMatchesEvent (com.thebluealliance.androidclient.eventbus.EventMatchesEvent)2 LiveEventUpdateEvent (com.thebluealliance.androidclient.eventbus.LiveEventUpdateEvent)2 ListGroup (com.thebluealliance.androidclient.listitems.ListGroup)2 DistrictPointBreakdown (com.thebluealliance.androidclient.models.DistrictPointBreakdown)2