Search in sources :

Example 1 with District

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

the class DistrictsTableTest method testUpdate.

@Test
public void testUpdate() {
    District result = DbTableTestDriver.testUpdate(mTable, mDistricts.get(0), district -> district.setDisplayName("Test Dist"), mGson);
    assertNotNull(result);
    assertEquals("Test Dist", result.getDisplayName());
}
Also used : District(com.thebluealliance.androidclient.models.District) Test(org.junit.Test)

Example 2 with District

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

the class DistrictDeserializer method deserialize.

@Override
public District deserialize(JsonElement jsonElement, Type type, JsonDeserializationContext jsonDeserializationContext) throws JsonParseException {
    JsonObject data = jsonElement.getAsJsonObject();
    District district = new District();
    district.setKey(data.get("key").getAsString());
    district.setDisplayName(data.get("display_name").getAsString());
    district.setAbbreviation(data.get("abbreviation").getAsString());
    district.setYear(data.get("year").getAsInt());
    return district;
}
Also used : JsonObject(com.google.gson.JsonObject) District(com.thebluealliance.androidclient.models.District)

Example 3 with District

use of com.thebluealliance.androidclient.models.District 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 District

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

the class AddDistrictKeys method call.

@Override
public List<District> call(List<District> districts) {
    if (districts == null) {
        return null;
    }
    for (int i = 0; i < districts.size(); i++) {
        District district = districts.get(i);
        String key = DistrictHelper.generateKey(district.getAbbreviation(), mYear);
        district.setKey(key);
        district.setYear(mYear);
    }
    return districts;
}
Also used : District(com.thebluealliance.androidclient.models.District)

Example 5 with District

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

the class APICache method fetchDistrict.

public Observable<District> fetchDistrict(String districtKey) {
    return Observable.create((observer) -> {
        try {
            District district = mDb.getDistrictsTable().get(districtKey);
            observer.onNext(district);
            observer.onCompleted();
        } catch (Exception e) {
            observer.onError(e);
        }
    });
}
Also used : District(com.thebluealliance.androidclient.models.District)

Aggregations

District (com.thebluealliance.androidclient.models.District)12 Event (com.thebluealliance.androidclient.models.Event)4 Test (org.junit.Test)3 JsonObject (com.google.gson.JsonObject)2 ContentValues (android.content.ContentValues)1 SharedPreferences (android.content.SharedPreferences)1 SQLiteDatabase (android.database.sqlite.SQLiteDatabase)1 NonNull (androidx.annotation.NonNull)1 Nullable (androidx.annotation.Nullable)1 WorkerThread (androidx.annotation.WorkerThread)1 JsonElement (com.google.gson.JsonElement)1 JsonSyntaxException (com.google.gson.JsonSyntaxException)1 AddDistrictKeys (com.thebluealliance.androidclient.datafeed.maps.AddDistrictKeys)1 ListItem (com.thebluealliance.androidclient.listitems.ListItem)1 ApiStatus (com.thebluealliance.androidclient.models.ApiStatus)1 Team (com.thebluealliance.androidclient.models.Team)1 DistrictRenderer (com.thebluealliance.androidclient.renderers.DistrictRenderer)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1