Skip to content

Commit

Permalink
Refactor and Survey Handling
Browse files Browse the repository at this point in the history
- Refactored survey manager
- Handled showing surveys on the map.
- Handled embedded data in external surveys.

Signed-off-by: Amr Hossam <[email protected]>
  • Loading branch information
amrhossamdev committed Aug 22, 2024
1 parent 576d41d commit 5102170
Show file tree
Hide file tree
Showing 9 changed files with 291 additions and 72 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.onebusaway.android.io.request.survey;

import org.onebusaway.android.io.request.survey.submit.SubmitSurveyRequestListener;

public interface SurveyListener extends StudyRequestListener, SubmitSurveyRequestListener {
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import java.io.Serializable;
import java.lang.Integer;
import java.lang.String;
import java.util.ArrayList;
import java.util.List;

public class StudyResponse implements Serializable {
Expand Down Expand Up @@ -184,7 +185,7 @@ public static class Content implements Serializable {
private String label_text;
private List<String> options;
private String url;
private List<String> embedded_data_fields;
private ArrayList<String> embedded_data_fields;
private String survey_provider;

private String type;
Expand Down Expand Up @@ -213,7 +214,7 @@ public String getUrl() {
return url;
}

public List<String> getEmbedded_data_fields() {
public ArrayList<String> getEmbedded_data_fields() {
return embedded_data_fields;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,8 @@
import org.onebusaway.android.io.elements.Occupancy;
import org.onebusaway.android.io.elements.OccupancyState;
import org.onebusaway.android.io.request.ObaArrivalInfoResponse;
import org.onebusaway.android.io.request.survey.StudyRequestListener;
import org.onebusaway.android.io.request.survey.SurveyListener;
import org.onebusaway.android.io.request.survey.model.SubmitSurveyResponse;
import org.onebusaway.android.io.request.survey.submit.SubmitSurveyRequestListener;
import org.onebusaway.android.map.MapParams;
import org.onebusaway.android.provider.ObaContract;
import org.onebusaway.android.report.ui.InfrastructureIssueActivity;
Expand All @@ -99,8 +98,7 @@
// We don't use the ListFragment because the support library's version of
// the ListFragment doesn't work well with our header.
//
public class ArrivalsListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<ObaArrivalInfoResponse>, ArrivalsListHeader.Controller, SubmitSurveyRequestListener,
StudyRequestListener {
public class ArrivalsListFragment extends ListFragment implements LoaderManager.LoaderCallbacks<ObaArrivalInfoResponse>, ArrivalsListHeader.Controller, SurveyListener {

private static final String TAG = "ArrivalsListFragment";

Expand Down Expand Up @@ -1766,7 +1764,7 @@ private Dialog createOccupancyDialog() {
private void initSurveyManager(){
// Avoiding doing multiple calls when updating the stop arrivals list
if(isSurveyManagerInitialized) return;
surveyManager = new SurveyManager(requireContext(),true,this,this);
surveyManager = new SurveyManager(requireContext(),this,true);
surveyManager.requestSurveyData();
surveyManager.setCurrentStop(mStop);
surveyManager.initSurveyArrivalsHeaderView(getLayoutInflater());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
import org.onebusaway.android.io.elements.ObaRoute;
import org.onebusaway.android.io.elements.ObaStop;
import org.onebusaway.android.io.request.ObaArrivalInfoResponse;
import org.onebusaway.android.io.request.survey.SurveyListener;
import org.onebusaway.android.io.request.survey.model.StudyResponse;
import org.onebusaway.android.io.request.survey.model.SubmitSurveyResponse;
import org.onebusaway.android.io.request.weather.ObaWeatherRequest;
import org.onebusaway.android.io.request.weather.models.ObaWeatherResponse;
import org.onebusaway.android.io.request.weather.WeatherRequestListener;
Expand All @@ -48,6 +51,7 @@
import org.onebusaway.android.travelbehavior.constants.TravelBehaviorConstants;
import org.onebusaway.android.travelbehavior.utils.TravelBehaviorUtils;
import org.onebusaway.android.tripservice.TripService;
import org.onebusaway.android.ui.survey.SurveyManager;
import org.onebusaway.android.ui.weather.RegionCallback;
import org.onebusaway.android.ui.weather.WeatherUtils;
import org.onebusaway.android.util.FragmentUtils;
Expand Down Expand Up @@ -139,7 +143,8 @@ public class HomeActivity extends AppCompatActivity
implements BaseMapFragment.OnFocusChangedListener,
BaseMapFragment.OnProgressBarChangedListener,
ArrivalsListFragment.Listener, NavigationDrawerCallbacks, WeatherRequestListener , RegionCallback,
ObaRegionsTask.Callback {
ObaRegionsTask.Callback, SurveyListener {


interface SlidingPanelController {

Expand Down Expand Up @@ -189,6 +194,8 @@ interface SlidingPanelController {

CardView weatherView;

View mSurveyView;

View mDonationView;

private FloatingActionButton mFabMyLocation;
Expand Down Expand Up @@ -276,6 +283,7 @@ interface SlidingPanelController {

private ObaWeatherResponse weatherResponse;

private SurveyManager surveyManager;
/**
* Starts the MapActivity with a particular stop focused with the center of
* the map at a particular point.
Expand Down Expand Up @@ -425,6 +433,11 @@ public void onCreate(Bundle savedInstanceState) {
}
}
initWeatherView();

// Show survey
if(Application.get().getCurrentRegion() != null){
setupSurvey();
}
}

@Override
Expand Down Expand Up @@ -2131,4 +2144,35 @@ private AlertDialog buildDismissDonationsDialog() {

return builder.create();
}
private void setupSurvey() {
mSurveyView = findViewById(R.id.surveyView);
initSurveyManager(mSurveyView);
}

private void initSurveyManager(View surveyView){
surveyManager = new SurveyManager(this, this, false);
surveyManager.setSurveyView(surveyView);
surveyManager.requestSurveyData();
}

@Override
public void onSurveyResponseReceived(StudyResponse response) {
surveyManager.onSurveyResponseReceived(response);
}

@Override
public void onSurveyFail() {
surveyManager.onSurveyFail();
}

@Override
public void onSubmitSurveyResponseReceived(SubmitSurveyResponse response) {
surveyManager.onSubmitSurveyResponseReceived(response);
}

@Override
public void onSubmitSurveyFail() {
surveyManager.onSubmitSurveyFail();
}

}
Loading

0 comments on commit 5102170

Please sign in to comment.