Skip to content

Commit

Permalink
updated load more arrivals
Browse files Browse the repository at this point in the history
  • Loading branch information
Blackspider03 authored and aaronbrethorst committed Dec 9, 2024
1 parent c65d518 commit 10fad9b
Showing 1 changed file with 18 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public class ArrivalsListLoader extends AsyncTaskLoader<ObaArrivalInfoResponse>
public static final int DEFAULT_MINUTES_AFTER = 65;

private static final int MINUTES_INCREMENT = 60; // minutes

private static final int MAX_MINUTES_AFTER = 1440;
private String mUrl;

public ArrivalsListLoader(Context context, String stopId) {
Expand All @@ -51,11 +51,23 @@ public ArrivalsListLoader(Context context, String stopId) {

@Override
public ObaArrivalInfoResponse loadInBackground() {
ObaArrivalInfoRequest obaArrivalInfoRequest = ObaArrivalInfoRequest.newRequest(getContext(),
mStopId, mMinutesAfter);
// Cache the URL so we have a record of the request w/ params made to the server
mUrl = obaArrivalInfoRequest.getUri().toString();
return obaArrivalInfoRequest.call();
ObaArrivalInfoResponse response;

do {
// Create and execute the request for the specified time window
ObaArrivalInfoRequest obaArrivalInfoRequest = ObaArrivalInfoRequest.newRequest(
getContext(), mStopId, mMinutesAfter);
mUrl = obaArrivalInfoRequest.getUri().toString();
response = obaArrivalInfoRequest.call();

// Check if the arrival info is null or has no entries
if (response.getArrivalInfo() == null || response.getArrivalInfo().length == 0) {
incrementMinutesAfter(); // Extend the time window
}
} while ((response.getArrivalInfo() == null || response.getArrivalInfo().length == 0)
&& mMinutesAfter <= MAX_MINUTES_AFTER); // Continue until arrivals are found or limit reached

return response;
}

@Override
Expand Down

0 comments on commit 10fad9b

Please sign in to comment.