Skip to content

Commit

Permalink
Fixed #895 - Allow saving for routes into the DB
Browse files Browse the repository at this point in the history
Signed-off-by: Amr Hossam <[email protected]>
  • Loading branch information
amrhossamdev committed Mar 9, 2024
1 parent 0efe8dc commit eb08632
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand All @@ -205,6 +207,7 @@ public void onClick(DialogInterface dialog, int which) {
// Show on map
HomeActivity.start(getActivity(), routeId);
break;

}
}
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
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 com.squareup.okhttp.Route;

/**
* Created by azizmb9494 on 2/20/16.
Expand All @@ -25,4 +30,30 @@ public static void addToDB(ObaStop stop) {
}
ObaContract.Stops.insertOrUpdate(stop.getId(), values, true);
}

public static void addRouteToDB(Context ctx, ArrivalInfo arrivalInfo){
ContentValues routeValues = new ContentValues();

routeValues.put(ObaContract.Routes.SHORTNAME, arrivalInfo.getInfo().getShortName());
routeValues.put(ObaContract.Routes.LONGNAME, arrivalInfo.getInfo().getRouteLongName());

if (Application.get().getCurrentRegion() != null) {
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){
ContentValues routeValues = new ContentValues();

routeValues.put(ObaContract.Routes.SHORTNAME, route.getShortName());
routeValues.put(ObaContract.Routes.LONGNAME, route.getLongName());

if (Application.get().getCurrentRegion() != null) {
routeValues.put(ObaContract.Routes.REGION_ID,
Application.get().getCurrentRegion().getId());
}
ObaContract.Routes.insertOrUpdate(ctx, route.getId(), routeValues, true);
}
}

0 comments on commit eb08632

Please sign in to comment.