Skip to content

Commit

Permalink
feat: support sending all route IDs for external survey embedded data
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 Sep 1, 2024
1 parent 8bfc981 commit e12fef5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -313,10 +313,13 @@ private Intent createOpenExternalSurveyIntent(String url, ArrayList<String> embe
intent.putExtra("url", url);
// If visible on stops, pass the current stop ID and route ID if available
if (isVisibleOnStops && currentStop != null) {

intent.putExtra("stop_id", currentStop.getId());
//TODO send all routes ids
if (currentStop.getRouteIds().length > 0) {
intent.putExtra("route_id", currentStop.getRouteIds()[0]);

String[] routeIds = currentStop.getRouteIds();

if (routeIds != null && routeIds.length > 0) {
intent.putStringArrayListExtra("route_ids", SurveyUtils.getRoutesIDList(routeIds));
}
}
if (SurveyUtils.isValidEmbeddedDataList(embeddedDataList)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SurveyWebViewActivity : AppCompatActivity() {
private lateinit var toolbar: androidx.appcompat.widget.Toolbar
private lateinit var mGoogleApiClient: GoogleApiClient
private var mStopID: String? = null
private var mRouteID: String? = null
private var mRouteIDList: ArrayList<String>? = null

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand All @@ -50,8 +50,8 @@ class SurveyWebViewActivity : AppCompatActivity() {
val url = intent.getStringExtra("url") as String
val embeddedValuesList = intent.getStringArrayListExtra("embedded_data") as? ArrayList<String> ?: arrayListOf()
mStopID = intent.getStringExtra("stop_id")
mRouteID = intent.getStringExtra("route_id")

mRouteIDList = intent.getStringArrayListExtra("route_ids") as? ArrayList<String> ?: arrayListOf()
Log.d("Routes",mRouteIDList.toString())
val newURl = getEmbeddedLink(url, embeddedValuesList)

Log.d("ExternalSurveyData", embeddedValuesList.toString())
Expand Down Expand Up @@ -167,8 +167,18 @@ class SurveyWebViewActivity : AppCompatActivity() {
return mStopID ?: "NA"
}

/**
* Retrieves a comma-separated string of route IDs from the list.
*
* If `mRouteIDList` is not null and contains elements, it converts the list
* to a comma-separated.
*
* @return A comma-separated string of route IDs or "NA" if the list is null or empty.
*/
private fun getRouteID(): String {
return mRouteID ?: "NA"
return mRouteIDList?.takeIf { it.isNotEmpty() }
?.joinToString(separator = ",")
?: "NA"
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.onebusaway.android.ui.survey.SurveyPreferences;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

Expand Down Expand Up @@ -415,4 +416,15 @@ public static boolean isValidEmbeddedDataList(ArrayList<String> embeddedDataList
return embeddedDataList != null && !embeddedDataList.isEmpty();
}

/**
* 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.
*/
public static ArrayList<String> getRoutesIDList(String[] routes) {
return new ArrayList<>(Arrays.asList(routes));
}



}

0 comments on commit e12fef5

Please sign in to comment.