More routing fixes (SFO->Millbrae, weekdays)
This commit is contained in:
parent
e7ec1f5978
commit
311adc9efc
@ -2,6 +2,8 @@ package com.dougkeen.bart;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.commons.lang3.math.NumberUtils;
|
||||||
|
|
||||||
import android.app.ListActivity;
|
import android.app.ListActivity;
|
||||||
import android.content.ContentValues;
|
import android.content.ContentValues;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
@ -170,6 +172,8 @@ public class ViewDeparturesActivity extends ListActivity {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean mIgnoreDepartureDirection = false;
|
||||||
|
|
||||||
private void fetchLatestDepartures() {
|
private void fetchLatestDepartures() {
|
||||||
if (!hasWindowFocus())
|
if (!hasWindowFocus())
|
||||||
return;
|
return;
|
||||||
@ -180,7 +184,8 @@ public class ViewDeparturesActivity extends ListActivity {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
mGetDeparturesTask = new GetRealTimeDeparturesTask() {
|
mGetDeparturesTask = new GetRealTimeDeparturesTask(
|
||||||
|
mIgnoreDepartureDirection) {
|
||||||
@Override
|
@Override
|
||||||
public void onResult(RealTimeDepartures result) {
|
public void onResult(RealTimeDepartures result) {
|
||||||
mDepartureFetchIsPending = false;
|
mDepartureFetchIsPending = false;
|
||||||
@ -249,6 +254,13 @@ public class ViewDeparturesActivity extends ListActivity {
|
|||||||
if (result.getDepartures().isEmpty()) {
|
if (result.getDepartures().isEmpty()) {
|
||||||
result.includeDoubleTransferRoutes();
|
result.includeDoubleTransferRoutes();
|
||||||
}
|
}
|
||||||
|
if (result.getDepartures().isEmpty() && !mIgnoreDepartureDirection) {
|
||||||
|
// Let's try again, ignoring direction (this sometimes comes up when
|
||||||
|
// you travel between Millbrae and SFO)
|
||||||
|
mIgnoreDepartureDirection = true;
|
||||||
|
scheduleDepartureFetch(50);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (result.getDepartures().isEmpty()) {
|
if (result.getDepartures().isEmpty()) {
|
||||||
final TextView textView = (TextView) findViewById(android.R.id.empty);
|
final TextView textView = (TextView) findViewById(android.R.id.empty);
|
||||||
textView.setText(R.string.no_data_message);
|
textView.setText(R.string.no_data_message);
|
||||||
@ -359,6 +371,23 @@ public class ViewDeparturesActivity extends ListActivity {
|
|||||||
int localAverageLength = mLatestScheduleInfo.getAverageTripLength();
|
int localAverageLength = mLatestScheduleInfo.getAverageTripLength();
|
||||||
|
|
||||||
int departuresCount = mDeparturesAdapter.getCount();
|
int departuresCount = mDeparturesAdapter.getCount();
|
||||||
|
|
||||||
|
// Let's get smallest interval between departures
|
||||||
|
int smallestDepartureInterval = 0;
|
||||||
|
long previousDepartureTime = 0;
|
||||||
|
for (int departureIndex = 0; departureIndex < departuresCount; departureIndex++) {
|
||||||
|
Departure departure = mDeparturesAdapter.getItem(departureIndex);
|
||||||
|
if (previousDepartureTime == 0) {
|
||||||
|
previousDepartureTime = departure.getMeanEstimate();
|
||||||
|
} else if (smallestDepartureInterval == 0) {
|
||||||
|
smallestDepartureInterval = (int) (departure.getMeanEstimate() - previousDepartureTime);
|
||||||
|
} else {
|
||||||
|
smallestDepartureInterval = Math
|
||||||
|
.min(smallestDepartureInterval,
|
||||||
|
(int) (departure.getMeanEstimate() - previousDepartureTime));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int lastSearchIndex = 0;
|
int lastSearchIndex = 0;
|
||||||
int tripCount = mLatestScheduleInfo.getTrips().size();
|
int tripCount = mLatestScheduleInfo.getTrips().size();
|
||||||
boolean departureUpdated = false;
|
boolean departureUpdated = false;
|
||||||
@ -377,9 +406,10 @@ public class ViewDeparturesActivity extends ListActivity {
|
|||||||
- departure.getMeanEstimate());
|
- departure.getMeanEstimate());
|
||||||
final long millisUntilTripDeparture = trip.getDepartureTime()
|
final long millisUntilTripDeparture = trip.getDepartureTime()
|
||||||
- System.currentTimeMillis();
|
- System.currentTimeMillis();
|
||||||
final int equalityTolerance = (departure.getOrigin() != null) ? Math
|
final int equalityTolerance = (departure.getOrigin() != null) ? NumberUtils
|
||||||
.max(departure.getOrigin().departureEqualityTolerance,
|
.max(departure.getOrigin().departureEqualityTolerance,
|
||||||
ScheduleItem.SCHEDULE_ITEM_DEPARTURE_EQUALS_TOLERANCE)
|
ScheduleItem.SCHEDULE_ITEM_DEPARTURE_EQUALS_TOLERANCE,
|
||||||
|
smallestDepartureInterval)
|
||||||
: ScheduleItem.SCHEDULE_ITEM_DEPARTURE_EQUALS_TOLERANCE;
|
: ScheduleItem.SCHEDULE_ITEM_DEPARTURE_EQUALS_TOLERANCE;
|
||||||
if (departure.getOrigin() != null
|
if (departure.getOrigin() != null
|
||||||
&& departure.getOrigin().longStationLinger
|
&& departure.getOrigin().longStationLinger
|
||||||
|
@ -35,6 +35,13 @@ public abstract class GetRealTimeDeparturesTask extends
|
|||||||
|
|
||||||
private List<Route> mRoutes;
|
private List<Route> mRoutes;
|
||||||
|
|
||||||
|
private final boolean ignoreDirection;
|
||||||
|
|
||||||
|
public GetRealTimeDeparturesTask(boolean ignoreDirection) {
|
||||||
|
super();
|
||||||
|
this.ignoreDirection = ignoreDirection;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected RealTimeDepartures doInBackground(StationPair... paramsArray) {
|
protected RealTimeDepartures doInBackground(StationPair... paramsArray) {
|
||||||
// Always expect one param
|
// Always expect one param
|
||||||
@ -60,7 +67,7 @@ public abstract class GetRealTimeDeparturesTask extends
|
|||||||
String xml = null;
|
String xml = null;
|
||||||
try {
|
try {
|
||||||
String url;
|
String url;
|
||||||
if (params.getOrigin().endOfLine) {
|
if (ignoreDirection || params.getOrigin().endOfLine) {
|
||||||
url = String.format(ETD_URL_NO_DIRECTION,
|
url = String.format(ETD_URL_NO_DIRECTION,
|
||||||
params.getOrigin().abbreviation);
|
params.getOrigin().abbreviation);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
Reference in New Issue
Block a user