use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class StepJsonBuilder method getBusStop.
/*
If this method return null the given BusStop is not in TranSapp database and there is
nothing to do to recover this route
*/
@Nullable
private BusStop getBusStop(String departureCode, Context context, Location point) {
String[] split = departureCode.split("-");
String code = split[0];
BusStopHelper helper = new BusStopHelper(context);
BusStop busStop = helper.getBusStopById(code);
if (busStop == null) {
if (split.length != 1) {
Map<String, String> map = new HashMap<>();
map.put("code", code);
TranSappApplication.addLog("OutDated GTFS!", map);
return new BusStop(code, split[1], point.getLatitude(), point.getLongitude(), "");
} else {
List<BusStop> nearest = helper.getNearestBusStops(point.getLatitude(), point.getLongitude(), 10);
for (BusStop stop : nearest) {
String truncName = stop.getName().replaceAll(" |/", "");
String truncData = departureCode.replaceAll(" |/", "");
if (truncData.equals(truncName)) {
return stop;
}
}
Map<String, String> map = new HashMap<>();
map.put("data", departureCode);
TranSappApplication.addLog("Wrong bus stop code/name", map);
}
}
return busStop;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class SuggestionsSearchTask method doInBackground.
@Override
protected List<Suggestion> doInBackground(Void... params) {
BusStopHelper stopHelper = new BusStopHelper(context);
ServiceHelper serviceHelper = new ServiceHelper(context);
List<Suggestion> suggestions = new ArrayList<>();
if (query.toUpperCase().startsWith("L")) {
return suggestions;
}
for (BusStop busStop : stopHelper.getBusStopsSuggestionsById(query.toUpperCase())) {
suggestions.add(busStop);
}
for (Service service : serviceHelper.getServiceSuggestionsById(query.toLowerCase())) {
suggestions.add(service);
}
return suggestions;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class OnBusEngine method setBusStops.
public void setBusStops(List<BusStop> busStops) {
if (bus == null) {
this.busStops = busStops;
return;
}
List<Feature> features = new ArrayList<>();
for (BusStop busStop : busStops) {
if (contains(serviceBusStops, busStop.getId())) {
features.add(new BusStopMarker(busStop));
}
}
busStopSource.setGeoJson(FeatureCollection.fromFeatures(features));
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class BusStopHelper method getAllBusStops.
/**
* Open the database, does a query, close the database and return a list of BusStop that
* contains all the bus stops in the database
*
* @return
*/
public List<BusStop> getAllBusStops() {
// String query="SELECT * FROM stops";
String query = "SELECT * FROM " + DataBaseContract.Stop.TABLE_NAME;
String[] params = new String[] {};
Cursor cursor = this.getReadableDatabase().rawQuery(query, params);
List<BusStop> busStopList = this.cursorToBusStopList(cursor);
this.close();
return busStopList;
}
use of cl.smartcities.isci.transportinspector.backend.BusStop in project androidApp by InspectorIncognito.
the class BusStopHelper method cursorToBusStopList.
/**
* Creates a List<BusStop> based on the Cursor information
*
* @param cursor
* @return
*/
private List<BusStop> cursorToBusStopList(Cursor cursor) {
List<BusStop> busStopList = new ArrayList<>();
while (cursor.moveToNext()) {
String code = cursor.getString(1);
String name = cursor.getString(2);
Double lat = cursor.getDouble(3);
Double lon = cursor.getDouble(4);
String services = cursor.getString(5);
busStopList.add(new BusStop(code, name, lat, lon, services));
}
return busStopList;
}
Aggregations