Skip to content

Commit

Permalink
feat: allow sending stop location
Browse files Browse the repository at this point in the history
Signed-off-by: Amr Hossam <[email protected]>
  • Loading branch information
amrhossamdev authored and aaronbrethorst committed Oct 13, 2024
1 parent a74c0c0 commit 5cac9e6
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,24 @@ public Builder setSurveyId(int surveyId) {
return this;
}

public Builder setStopLatitude(double stopLatitude) {
try {
mPostData.appendQueryParameter("stop_latitude", String.valueOf(stopLatitude));
} catch (Exception e) {
e.printStackTrace();
}
return this;
}

public Builder setStopLongitude(double stopLongitude) {
try {
mPostData.appendQueryParameter("stop_longitude", String.valueOf(stopLongitude));
} catch (Exception e) {
e.printStackTrace();
}
return this;
}

public Builder setResponses(JSONArray responses) {
try {
mPostData.appendQueryParameter("responses", responses.toString());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,9 @@ private void sendSurveySubmission(String apiUrl, String userIdentifier, int surv
ObaSubmitSurveyRequest request = new ObaSubmitSurveyRequest.Builder(context, apiUrl)
.setUserIdentifier(userIdentifier)
.setSurveyId(surveyId)
.setStopIdentifier(SurveyUtils.getCurrentStopIdentifier(currentStop,isVisibleOnStops))
.setStopIdentifier(SurveyUtils.getCurrentStopIdentifier(currentStop, isVisibleOnStops))
.setStopLatitude(SurveyUtils.getCurrentStopLatitude(currentStop, isVisibleOnStops))
.setStopLongitude(SurveyUtils.getCurrentStopLongitude(currentStop, isVisibleOnStops))
.setResponses(requestBody)
.setListener(submitSurveyRequestListener).build();
new Thread(request::call).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ public static boolean isValidEmbeddedDataList(ArrayList<String> embeddedDataList

/**
* Converts an array of route IDs to an ArrayList.
*
* @param routes An array of route IDs.
* @return An ArrayList containing the route IDs from the input array.
*/
Expand All @@ -435,17 +436,37 @@ public static ArrayList<String> getRoutesIDList(String[] routes) {
* Returns the stop identifier if the stop is non-null, has a valid ID,
* and is marked as visible; otherwise, returns null.
*
* @param currentStop The current stop object.
* @param visibleOnStops Indicates if the stop is visible.
* @param currentStop The current stop object.
* @param visibleOnStops Indicates if the stop is visible.
* @return The stop identifier or null if conditions are not met.
*/
public static String getCurrentStopIdentifier(ObaStop currentStop, boolean visibleOnStops) {
return (currentStop != null && currentStop.getId() != null && visibleOnStops)
? currentStop.getId()
: null;
return (currentStop != null && currentStop.getId() != null && visibleOnStops) ? currentStop.getId() : null;
}

/**
* Returns the current stop latitude if the stop is non-null and visible.
*
* @param currentStop The current stop object.
* @param visibleOnStops Indicates if the stop is visible.
* @return The current stop latitude or 0 if the stop is null or not visible.
*/

public static double getCurrentStopLatitude(ObaStop currentStop, boolean visibleOnStops) {
if (currentStop == null || !visibleOnStops) return 0;
return currentStop.getLatitude();
}

/**
* Returns the current stop longitude if the stop is non-null and visible.
*
* @param currentStop The current stop object.
* @param visibleOnStops Indicates if the stop is visible.
* @return The current stop longitude or 0 if the stop is null or not visible.
*/

public static double getCurrentStopLongitude(ObaStop currentStop, boolean visibleOnStops) {
if (currentStop == null || !visibleOnStops) return 0;
return currentStop.getLongitude();
}
}

0 comments on commit 5cac9e6

Please sign in to comment.