Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correctly populate recent routes list #1175

Merged
merged 1 commit into from
Mar 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,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.
Expand All @@ -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);
}
}
Loading