diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/ArrivalsListFragment.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/ArrivalsListFragment.java index a3d363755..13b275ebb 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/ArrivalsListFragment.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/ArrivalsListFragment.java @@ -829,6 +829,8 @@ public void showRouteOnMap(ArrivalInfo arrivalInfo) { if (mListener != null) { handled = mListener.onShowRouteOnMapSelected(arrivalInfo); } + // Save to recent routes + DBUtil.addRouteToDB(getActivity(),arrivalInfo); // If the event hasn't been handled by the listener, start a new activity if (!handled) { HomeActivity.start(getActivity(), arrivalInfo.getInfo().getRouteId()); @@ -1429,6 +1431,10 @@ private void goToTrip(ArrivalInfo stop) { } private void goToTripDetails(ArrivalInfo stop) { + + // Save to recent routes + DBUtil.addRouteToDB(getActivity(),stop); + TripDetailsActivity.start(getActivity(), stop.getInfo().getTripId(), stop.getInfo().getStopId(), TripDetailsListFragment.SCROLL_MODE_STOP); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/ui/SearchResultsFragment.java b/onebusaway-android/src/main/java/org/onebusaway/android/ui/SearchResultsFragment.java index 5d4f6af9f..f8c6403e8 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/ui/SearchResultsFragment.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/ui/SearchResultsFragment.java @@ -44,6 +44,7 @@ import org.onebusaway.android.io.request.ObaStopsForLocationRequest; import org.onebusaway.android.io.request.ObaStopsForLocationResponse; import org.onebusaway.android.util.ArrayAdapter; +import org.onebusaway.android.util.DBUtil; import org.onebusaway.android.util.LocationUtils; import org.onebusaway.android.util.UIUtils; @@ -196,6 +197,7 @@ private void clickRoute(ObaRoute route) { builder.setItems(R.array.search_route_options, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int which) { + DBUtil.addRouteToDB(getActivity(),route); switch (which) { case 0: // Show on list @@ -205,6 +207,7 @@ public void onClick(DialogInterface dialog, int which) { // Show on map HomeActivity.start(getActivity(), routeId); break; + } } }); diff --git a/onebusaway-android/src/main/java/org/onebusaway/android/util/DBUtil.java b/onebusaway-android/src/main/java/org/onebusaway/android/util/DBUtil.java index f49bd7bd2..fa19d8d83 100644 --- a/onebusaway-android/src/main/java/org/onebusaway/android/util/DBUtil.java +++ b/onebusaway-android/src/main/java/org/onebusaway/android/util/DBUtil.java @@ -1,10 +1,14 @@ package org.onebusaway.android.util; import org.onebusaway.android.app.Application; +import org.onebusaway.android.io.elements.ObaRoute; import org.onebusaway.android.io.elements.ObaStop; import org.onebusaway.android.provider.ObaContract; +import org.onebusaway.android.ui.ArrivalInfo; import android.content.ContentValues; +import android.content.Context; +import android.text.TextUtils; /** * Created by azizmb9494 on 2/20/16. @@ -25,4 +29,46 @@ public static void addToDB(ObaStop stop) { } ObaContract.Stops.insertOrUpdate(stop.getId(), values, true); } + + public static void addRouteToDB(Context ctx, ArrivalInfo arrivalInfo){ + if (Application.get().getCurrentRegion() == null) return; + + ContentValues routeValues = new ContentValues(); + + String shortName = arrivalInfo.getInfo().getShortName(); + String longName = arrivalInfo.getInfo().getRouteLongName(); + + if (TextUtils.isEmpty(longName)) { + longName = UIUtils.formatDisplayText(arrivalInfo.getInfo().getHeadsign()); + } + + routeValues.put(ObaContract.Routes.SHORTNAME, shortName); + routeValues.put(ObaContract.Routes.LONGNAME, longName); + routeValues.put(ObaContract.Routes.REGION_ID, Application.get().getCurrentRegion().getId()); + + ObaContract.Routes.insertOrUpdate(ctx, arrivalInfo.getInfo().getRouteId(), routeValues, true); + } + + public static void addRouteToDB(Context ctx, ObaRoute route){ + if (Application.get().getCurrentRegion() == null) return; + + ContentValues routeValues = new ContentValues(); + + String shortName = route.getShortName(); + String longName = route.getLongName(); + + if (TextUtils.isEmpty(shortName)) { + shortName = longName; + } + if (TextUtils.isEmpty(longName) || shortName.equals(longName)) { + longName = route.getDescription(); + } + + routeValues.put(ObaContract.Routes.SHORTNAME, shortName); + routeValues.put(ObaContract.Routes.LONGNAME, longName); + routeValues.put(ObaContract.Routes.URL, route.getUrl()); + routeValues.put(ObaContract.Routes.REGION_ID, Application.get().getCurrentRegion().getId()); + + ObaContract.Routes.insertOrUpdate(ctx, route.getId(), routeValues, true); + } }