@Override public List<SimpleSection<NextbusItem>> loadInBackground() { final List<SimpleSection<NextbusItem>> nextbusItems = new ArrayList<>(); // Get home campus for result ordering final String userHome = RutgersUtils.getHomeCampus(getContext()); final boolean nbHome = userHome.equals(getContext().getString(R.string.campus_nb_full)); try { // Get all route & stop information final List<RouteStub> nbRoutes = NextbusAPI.getAllRoutes(NextbusAPI.AGENCY_NB); final List<StopStub> nbStops = NextbusAPI.getAllStops(NextbusAPI.AGENCY_NB); final List<RouteStub> nwkRoutes = NextbusAPI.getAllRoutes(NextbusAPI.AGENCY_NWK); final List<StopStub> nwkStops = NextbusAPI.getAllStops(NextbusAPI.AGENCY_NWK); if (nbHome) { nextbusItems.add(loadRoutes(NextbusAPI.AGENCY_NB, nbRoutes)); nextbusItems.add(loadStops(NextbusAPI.AGENCY_NB, nbStops)); nextbusItems.add(loadRoutes(NextbusAPI.AGENCY_NWK, nwkRoutes)); nextbusItems.add(loadStops(NextbusAPI.AGENCY_NWK, nwkStops)); } else { nextbusItems.add(loadRoutes(NextbusAPI.AGENCY_NWK, nwkRoutes)); nextbusItems.add(loadStops(NextbusAPI.AGENCY_NWK, nwkStops)); nextbusItems.add(loadRoutes(NextbusAPI.AGENCY_NB, nbRoutes)); nextbusItems.add(loadStops(NextbusAPI.AGENCY_NB, nbStops)); } } catch (JsonSyntaxException | IOException e) { LOGE(TAG, e.getMessage()); } return nextbusItems; }
@Override public List<SimpleSection<StopStub>> loadInBackground() { // Stops is the return value it will hold headers as well as stops final List<SimpleSection<StopStub>> stops = new ArrayList<>(); // Nearby stops are one of the sections in stops final List<StopStub> nearbyStops = new ArrayList<>(); stops.add(new SimpleSection<>(getContext().getString(R.string.nearby_bus_header), nearbyStops)); // Check for location services if (location != null) { if (BuildConfig.DEBUG) LOGD(TAG, "Current location: " + location.toString()); LOGI(TAG, "Updating nearby active stops"); try { // Get nearby stops from the api final List<StopGroup> nbNearbyStops = NextbusAPI.getActiveStopsByTitleNear( NextbusAPI.AGENCY_NB, (float) location.getLatitude(), (float) location.getLongitude()); final List<StopGroup> nwkNearbyStops = NextbusAPI.getActiveStopsByTitleNear( NextbusAPI.AGENCY_NWK, (float) location.getLatitude(), (float) location.getLongitude()); if (nbNearbyStops.isEmpty() && nwkNearbyStops.isEmpty()) { // If there aren't any results, put a "no stops nearby" message // addNearbyRow(1, new RMenuItemRow(noneNearbyString)); } else { // Add all the stops for (StopGroup stopGroup : nbNearbyStops) nearbyStops.add(new StopStub(stopGroup)); for (StopGroup stopGroup : nwkNearbyStops) nearbyStops.add(new StopStub(stopGroup)); } } catch (JsonSyntaxException | IOException e) { LOGE(TAG, e.getMessage()); } } else { LOGW(TAG, "Couldn't get location, can't find nearby stops"); // addNearbyRow(1, new RMenuItemRow(getString(R.string.failed_location))); } // Get home campus for result ordering final String userHome = RutgersUtils.getHomeCampus(getContext()); final boolean nbHome = userHome.equals(getContext().getString(R.string.campus_nb_full)); try { // Get active stops final List<StopStub> nbActiveStops = NextbusAPI.getActiveStops(NextbusAPI.AGENCY_NB); final List<StopStub> nwkActiveStops = NextbusAPI.getActiveStops(NextbusAPI.AGENCY_NWK); if (nbHome) { stops.add(loadAgency(NextbusAPI.AGENCY_NB, nbActiveStops)); stops.add(loadAgency(NextbusAPI.AGENCY_NWK, nwkActiveStops)); } else { stops.add(loadAgency(NextbusAPI.AGENCY_NWK, nwkActiveStops)); stops.add(loadAgency(NextbusAPI.AGENCY_NB, nbActiveStops)); } } catch (JsonSyntaxException | IOException e) { LOGE(TAG, e.getMessage()); } return stops; }