Search in sources :

Example 1 with BusStopHelper

use of cl.smartcities.isci.transportinspector.database.BusStopHelper 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 BusStopHelper

use of cl.smartcities.isci.transportinspector.database.BusStopHelper 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 BusStopHelper

use of cl.smartcities.isci.transportinspector.database.BusStopHelper in project androidApp by InspectorIncognito.

the class FavouritesManger method getFavouriteBusStops.

static List<BusStop> getFavouriteBusStops(Context context) {
    FavoriteHelper helper = new FavoriteHelper(context);
    BusStopHelper busStopHelper = new BusStopHelper(context);
    List<String> busStops = helper.getFavoriteBusStops();
    List<BusStop> favouriteBusStops = new ArrayList<>();
    if (!busStops.isEmpty()) {
        List<BusStop> favourites = busStopHelper.getAllBusStopsIn(busStops.toArray(new String[busStops.size()]));
        favouriteBusStops.addAll(favourites);
    }
    return favouriteBusStops;
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) FavoriteHelper(cl.smartcities.isci.transportinspector.database.FavoriteHelper) ArrayList(java.util.ArrayList) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop)

Example 4 with BusStopHelper

use of cl.smartcities.isci.transportinspector.database.BusStopHelper in project androidApp by InspectorIncognito.

the class BusStopPlugin method moveCenterInAndOpen.

public void moveCenterInAndOpen(String id) {
    if (selectedBusStop != null) {
        if (selectedBusStop.getStringProperty(Marker.PROPERTY_ID).equals(id)) {
            MapboxUtil.animateCameraToSelection(selectedBusStop, animatorSet, mapboxMap);
            return;
        } else {
            deselectSelectedBusStop();
        }
    }
    Feature busStopFeature = getFeature(id, busStopFeatures, BusStopMarker.PROPERTY_ID);
    BusStopClickHandler handler = new BusStopClickHandler(getContext().getResources(), periodicRequestHandler, BusStopPlugin.this);
    if (busStopFeature == null) {
        BusStopHelper helper = new BusStopHelper(getContext());
        ArrayList<BusStop> busStops = new ArrayList<>();
        busStops.add(helper.getBusStopById(id));
        updateBusStopSource(busStops);
        busStopFeature = busStopFeatures.getFeatures().get(0);
    }
    busStopFeatureClick(busStopFeature, handler);
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) ArrayList(java.util.ArrayList) BusStopClickHandler(cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Feature(com.mapbox.services.commons.geojson.Feature)

Example 5 with BusStopHelper

use of cl.smartcities.isci.transportinspector.database.BusStopHelper in project androidApp by InspectorIncognito.

the class BusStep method getNearestBusStop.

@Nullable
private BusStop getNearestBusStop(Location point) {
    BusStopHelper helper = new BusStopHelper(TranSappApplication.getAppContext());
    List<BusStop> buses = helper.getNearestBusStops(point.getLatitude(), point.getLongitude(), 1);
    if (buses.isEmpty()) {
        return null;
    }
    return buses.get(0);
}
Also used : BusStopHelper(cl.smartcities.isci.transportinspector.database.BusStopHelper) BusStop(cl.smartcities.isci.transportinspector.backend.BusStop) Nullable(android.support.annotation.Nullable)

Aggregations

BusStopHelper (cl.smartcities.isci.transportinspector.database.BusStopHelper)6 BusStop (cl.smartcities.isci.transportinspector.backend.BusStop)5 ArrayList (java.util.ArrayList)3 Nullable (android.support.annotation.Nullable)2 ServiceHelper (cl.smartcities.isci.transportinspector.database.ServiceHelper)2 Service (cl.smartcities.isci.transportinspector.backend.Service)1 FavoriteHelper (cl.smartcities.isci.transportinspector.database.FavoriteHelper)1 RouteHelper (cl.smartcities.isci.transportinspector.database.RouteHelper)1 BusStopClickHandler (cl.smartcities.isci.transportinspector.map.model.busStop.BusStopClickHandler)1 Feature (com.mapbox.services.commons.geojson.Feature)1 HashMap (java.util.HashMap)1