Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rip out hard coded districts #874

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import com.facebook.testing.screenshot.Screenshot;
import com.facebook.testing.screenshot.ViewHelpers;
import com.thebluealliance.androidclient.models.District;
import com.thebluealliance.androidclient.types.DistrictType;

import org.junit.Test;
import org.junit.runner.RunWith;
Expand All @@ -22,7 +21,6 @@ public class DistrictListElementTest {
private static final District DISTRICT = new District();
static {
DISTRICT.setAbbreviation("ne");
DISTRICT.setEnum(DistrictType.NEW_ENGLAND.ordinal());
DISTRICT.setDisplayName("New England");
DISTRICT.setYear(2016);
DISTRICT.setKey("2016ne");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import com.thebluealliance.androidclient.helpers.DistrictHelper;
import com.thebluealliance.androidclient.listeners.ClickListenerModule;
import com.thebluealliance.androidclient.subscribers.SubscriberModule;
import com.thebluealliance.androidclient.types.DistrictType;
import com.thebluealliance.androidclient.types.ModelType;
import com.thebluealliance.androidclient.views.SlidingTabs;

Expand Down Expand Up @@ -108,14 +107,9 @@ public void onCreateNavigationDrawer() {

private void setupActionBar() {
ActionBar bar = getSupportActionBar();
DistrictType type = DistrictHelper.districtTypeFromKey(mDistrictKey);
if (bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
if (type != DistrictType.NO_DISTRICT) {
setActionBarTitle(String.format(getString(R.string.district_title_format),
mYear,
type.getName()));
}
setActionBarTitle("");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EventSortByTypeAndDateComparator implements Comparator<Event> {
public int compare(Event event, Event event2) {
// Preseason < regional < district < district_cmp < cmp_division < cmp_finals < offseason
if (event.getEventTypeEnum() == event2.getEventTypeEnum()) {
int districtSort = (event.getEventDistrictEnum()).compareTo(event2.getEventDistrictEnum());
int districtSort = (event.getDistrictKey()).compareTo(event2.getDistrictKey());
if (districtSort == 0) {
int eventSort = event.getStartDate().compareTo(event2.getStartDate());
if (eventSort == 0) {
Expand All @@ -26,7 +26,7 @@ public int compare(Event event, Event event2) {
EventType type2 = event2.getEventTypeEnum();
int typeCompare = type1.getSortOrder() - type2.getSortOrder();
if (typeCompare == 0 && event.getEventTypeEnum() == EventType.DISTRICT) {
return (event.getEventDistrictEnum()).compareTo(event2.getEventDistrictEnum());
return (event.getDistrictKey()).compareTo(event2.getDistrictKey());
} else {
return typeCompare;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class EventSortByTypeAndNameComparator implements Comparator<Event> {
public int compare(Event event, Event event2) {
// Preseason < regional < district < district_cmp < cmp_division < cmp_finals < offseason
if (event.getEventTypeEnum() == event2.getEventTypeEnum()) {
int districtSort = event.getEventDistrictEnum().compareTo(event2.getEventDistrictEnum());
int districtSort = event.getDistrictKey().compareTo(event2.getDistrictKey());
int nameSort = event.getShortName().compareTo(event2.getShortName());
if (districtSort == 0) {
return nameSort;
Expand All @@ -22,7 +22,7 @@ public int compare(Event event, Event event2) {
EventType type2 = event2.getEventTypeEnum();
int typeCompare = type1.getSortOrder() - type2.getSortOrder();
if (typeCompare == 0 && event.getEventTypeEnum() == EventType.DISTRICT) {
return event.getEventDistrictEnum().compareTo(event2.getEventDistrictEnum());
return event.getDistrictKey().compareTo(event2.getDistrictKey());
} else {
return typeCompare;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ public class Database extends SQLiteOpenHelper {
+ DistrictsTable.KEY + " TEXT PRIMARY KEY NOT NULL, "
+ DistrictsTable.ABBREV + " TEXT NOT NULL, "
+ DistrictsTable.YEAR + " INTEGER NOT NULL, "
+ DistrictsTable.ENUM + " INTEGER NOT NULL,"
phil-lopreiato marked this conversation as resolved.
Show resolved Hide resolved
+ DistrictsTable.NAME + " TEXT DEFAULT '', "
+ DistrictsTable.LAST_MODIFIED + " TIMESTAMP"
+ ")";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,6 @@ public static District inflateDistrict(Cursor data) {
case DistrictsTable.ABBREV:
district.setAbbreviation(data.getString(i));
break;
case DistrictsTable.ENUM:
district.setEnum(data.getInt(i));
break;
case DistrictsTable.YEAR:
district.setYear(data.getInt(i));
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class DistrictsTable extends ModelTable<District> {

public static final String KEY = "key",
ABBREV = "abbrev",
ENUM = "enum",
YEAR = "year",
NAME = "name",
LAST_MODIFIED = "last_modified";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import com.google.gson.JsonSerializer;

import com.thebluealliance.androidclient.models.District;
import com.thebluealliance.androidclient.types.DistrictType;

import java.lang.reflect.Type;

Expand All @@ -23,7 +22,6 @@ public District deserialize(JsonElement jsonElement, Type type, JsonDeserializat
district.setDisplayName(data.get("display_name").getAsString());
district.setAbbreviation(data.get("abbreviation").getAsString());
district.setYear(data.get("year").getAsInt());
district.setEnum(DistrictType.fromAbbreviation(district.getAbbreviation()).ordinal());
return district;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
package com.thebluealliance.androidclient.helpers;


import com.thebluealliance.androidclient.types.DistrictType;

public final class DistrictHelper {

private DistrictHelper() {
// unused
}

public static boolean validateDistrictKey(String key) {
if (key == null || key.length() <= 4) {
return false;
}
try {
Integer.parseInt(key.substring(0, 4));
String districtAbbrev = key.substring(4);
return DistrictType.fromAbbreviation(districtAbbrev) != DistrictType.NO_DISTRICT;
} catch (NumberFormatException e) {
return false;
}
if (key == null || key.isEmpty()) return false;
return key.matches("^[1-9]\\d{3}[a-z,0-9]+$");
phil-lopreiato marked this conversation as resolved.
Show resolved Hide resolved
}

public static int extractYearFromKey(String key) {
Expand All @@ -33,9 +23,4 @@ public static String extractAbbrevFromKey(String key) {
public static String generateKey(String districtAbbrev, int year) {
return year + districtAbbrev;
}

public static DistrictType districtTypeFromKey(String districtKey) {
String districtAbbrev = extractAbbrevFromKey(districtKey);
return DistrictType.fromAbbreviation(districtAbbrev);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -224,14 +224,14 @@ private static void renderEventListWithComparator(
Comparator<Event> comparator) {
Collections.sort(events, comparator);
EventType lastType = null, currentType;
int lastDistrict = -1, currentDistrict;
String lastDistrict = "", currentDistrict;
for (Event event : events) {
currentType = event.getEventTypeEnum();
currentDistrict = event.getEventDistrictEnum() != null
? event.getEventDistrictEnum().ordinal()
: -1;
currentDistrict = event.getDistrictKey() != null
? event.getDistrictKey()
: "";
if (currentType != lastType
|| (currentType == EventType.DISTRICT && currentDistrict != lastDistrict)) {
|| (currentType == EventType.DISTRICT && !currentDistrict.equals(lastDistrict))) {
String headerTitle;
if (currentType == EventType.DISTRICT) {
headerTitle = context.getString(R.string.district_events_header,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ public class District implements IDistrict, TbaDatabaseModel {

private String key;
private String abbreviation;
private int districtEnum;
private Integer year;
private String displayName;
private int numEvents;
Expand Down Expand Up @@ -54,14 +53,6 @@ public void setLastModified(Long lastModified) {
this.lastModified = lastModified;
}

public int getEnum() {
return districtEnum;
}

public void setEnum(int districtEnum) {
this.districtEnum = districtEnum;
}

public Integer getYear() {
return year;
}
Expand Down Expand Up @@ -92,7 +83,6 @@ public ContentValues getParams(Gson gson) {
ContentValues params = new ContentValues();
params.put(DistrictsTable.KEY, getKey());
params.put(DistrictsTable.ABBREV, getAbbreviation());
params.put(DistrictsTable.ENUM, getEnum());
params.put(DistrictsTable.YEAR, getYear());
params.put(DistrictsTable.NAME, getDisplayName());
params.put(DistrictsTable.LAST_MODIFIED, getLastModified());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.thebluealliance.androidclient.gcm.notifications.NotificationTypes;
import com.thebluealliance.androidclient.helpers.EventHelper;
import com.thebluealliance.androidclient.helpers.ThreadSafeFormatters;
import com.thebluealliance.androidclient.types.DistrictType;
import com.thebluealliance.androidclient.types.EventType;
import com.thebluealliance.androidclient.viewmodels.EventViewModel;
import com.thebluealliance.androidclient.viewmodels.ViewModelRenderer;
Expand Down Expand Up @@ -402,16 +401,11 @@ public EventType getEventTypeEnum() {
: EventType.NONE;
}

public DistrictType getEventDistrictEnum() {
public String getEventDistrictString() {
@Nullable IDistrict district = getDistrict();
return district != null
? DistrictType.fromAbbreviation(district.getAbbreviation())
: DistrictType.NO_DISTRICT;
}

public String getEventDistrictString() {
DistrictType districtType = getEventDistrictEnum();
return districtType.getName();
? district.getDisplayName()
: "";
}

public String getSearchTitles() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package com.thebluealliance.androidclient.helpers;

import com.thebluealliance.androidclient.types.DistrictType;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.RobolectricTestRunner;
Expand Down Expand Up @@ -50,11 +48,4 @@ public void testGenerateKey() {
String key = DistrictHelper.generateKey(abbrev, year);
assertEquals(key, "2015ne");
}

@Test
public void testDistrictTypeFromKey() {
String key = "2015ne";
DistrictType type = DistrictHelper.districtTypeFromKey(key);
assertEquals(type, DistrictType.NEW_ENGLAND);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.thebluealliance.androidclient.models;

import com.thebluealliance.androidclient.datafeed.framework.ModelMaker;
import com.thebluealliance.androidclient.types.DistrictType;

import org.junit.Before;
import org.junit.Test;
Expand All @@ -27,6 +26,5 @@ public void testDistrictModel() {
assertNotNull(district);
assertEquals(district.getDisplayName(), "New England");
assertEquals(district.getAbbreviation(), "ne");
assertEquals(district.getEnum(), DistrictType.NEW_ENGLAND.ordinal());
}
}
Loading