Search in sources :

Example 1 with BusStop

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;
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) HashMap(java.util.HashMap) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Nullable(android.support.annotation.Nullable)

Example 2 with 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;
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) ArrayList(java.util.ArrayList) Service(cl.smartcities.isci.transportinspector.backend.Service) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) ServiceHelper(cl.smartcities.isci.transportinspector.database.ServiceHelper)

Example 3 with BusStop

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));
}
Also used : ArrayList(java.util.ArrayList) BusStopMarker(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 4 with BusStop

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;
}
Also used : Cursor(android.database.Cursor) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 5 with BusStop

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;
}
Also used : ArrayList(java.util.ArrayList) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Aggregations

BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)27 ArrayList (java.util.ArrayList)13 Feature (com.mapbox.services.commons.geojson.Feature)8 BusStopMarker (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopMarker)6 BusStopHelper (cl.smartcities.isci.transportinspector.database.BusStopHelper)5 Cursor (android.database.Cursor)4 View (android.view.View)3 Bus (cl.smartcities.isci.transportinspector.backend.Bus)3 Test (org.junit.Test)3 Bitmap (android.graphics.Bitmap)2 Nullable (android.support.annotation.Nullable)2 TextView (android.widget.TextView)2 FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)2 GridHelper (cl.smartcities.isci.transportinspector.database.GridHelper)2 DetectedActivity (com.google.android.gms.location.DetectedActivity)2 Context (android.content.Context)1 Intent (android.content.Intent)1 Typeface (android.graphics.Typeface)1 Location (android.location.Location)1 Pair (android.support.v4.util.Pair)1