Skip to content

Commit

Permalink
Populate shared info for privacy in external surveys
Browse files Browse the repository at this point in the history
Signed-off-by: Amr Hossam <[email protected]>
  • Loading branch information
amrhossamdev committed Aug 15, 2024
1 parent 6918bd6 commit ce118d0
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ private void updateSurveyData() {

switch (externalSurveyResult) {
case SurveyUtils.EXTERNAL_SURVEY_WITHOUT_HERO_QUESTION:
SurveyViewUtils.showSharedInfoDetailsTextView(context,surveyView,questionsList.get(0).getContent().getEmbedded_data_fields());
SurveyViewUtils.showExternalSurveyButtons(surveyView);
handleOpenExternalSurvey(surveyView, questionsList.get(0).getContent().getUrl());
break;
case SurveyUtils.EXTERNAL_SURVEY_WITH_HERO_QUESTION:
SurveyViewUtils.showSharedInfoDetailsTextView(context,surveyView,questionsList.get(1).getContent().getEmbedded_data_fields());
SurveyViewUtils.showHeroQuestionButtons(surveyView);
handleNextButton(surveyView, externalSurveyResult, questionsList.size() > 1 ? questionsList.get(1).getContent().getUrl() : "");
break;
Expand Down Expand Up @@ -145,7 +147,7 @@ public void handleNextButton(View view, int externalSurveyResult, String externa
Button nextBtn = view.findViewById(R.id.nextBtn);
nextBtn.setOnClickListener(view1 -> {
if (externalSurveyResult == 2) {
showExternalSurveyDialog(externalSurveyUrl);
openExternalSurvey(externalSurveyUrl);
} else {
submitSurveyAnswers(mStudyResponse.getSurveys().get(curSurveyIndex), true);
}
Expand All @@ -155,30 +157,17 @@ public void handleNextButton(View view, int externalSurveyResult, String externa
public void handleOpenExternalSurvey(View view, String url) {
Button externalSurveyBtn = view.findViewById(R.id.openExternalSurveyBtn);
externalSurveyBtn.setOnClickListener(view1 -> {
showExternalSurveyDialog(url);
openExternalSurvey(url);
});
}

private void showExternalSurveyDialog(String url) {
AlertDialog.Builder builder = new AlertDialog.Builder(context);
// TODO remove external survey dialog
builder.setTitle("OneBusAway Survey");
builder.setMessage("Are you sure you want to proceed? we will share this information \n BLA BLA BLA BLA BLA");

builder.setPositiveButton("GO !", (dialog, which) -> {
handleCompleteSurvey();
Intent intent = new Intent(context, SurveyWebViewActivity.class);
intent.putExtra("url", url);
context.startActivity(intent);
});

builder.setNegativeButton("CANCEL", (dialog, which) -> {
// TODO perform survey dismiss
dialog.cancel();
});

AlertDialog dialog = builder.create();
dialog.show();
private void openExternalSurvey(String url){
Intent intent = new Intent(context, SurveyWebViewActivity.class);
intent.putExtra("url",url);
context.startActivity(intent);
handleCompleteSurvey();
}


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

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.UUID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,16 @@
import org.onebusaway.android.R;
import org.onebusaway.android.io.request.survey.model.StudyResponse;

import java.util.List;

public class SurveyViewUtils {

public static void showHeroQuestionButtons(View surveyView) {
showCloseBtn(surveyView);
Button next = surveyView.findViewById(R.id.nextBtn);
next.setVisibility(View.VISIBLE);
}

public static void showExternalSurveyButtons(View surveyView) {
showCloseBtn(surveyView);
Button openExternalSurveyBtn = surveyView.findViewById(R.id.openExternalSurveyBtn);
Expand All @@ -55,7 +58,7 @@ public static void showQuestion(Context context, View rootView, StudyResponse.Su
showCheckBoxQuestion(context, rootView, heroQuestion);
break;
case SurveyUtils.EXTERNAL_SURVEY:
showExternalSurveyView(rootView,heroQuestion);
showExternalSurveyView(rootView, heroQuestion);
break;
case SurveyUtils.LABEL:
break;
Expand Down Expand Up @@ -186,4 +189,21 @@ private static CheckBox createCheckBox(Context ctx, StudyResponse.Surveys.Questi
return createButton(ctx, question, position, CheckBox.class);
}

public static void showSharedInfoDetailsTextView(Context context,View surveyView, List<String> questions) {
if (questions.isEmpty()) return;
TextView sharedInfoTextView = surveyView.findViewById(R.id.shared_info_tv);
StringBuilder surveySharedInfo = new StringBuilder();
surveySharedInfo.append(context.getString(R.string.sharing_survey_info_message));

for (int i = 0; i < questions.size(); i++) {
surveySharedInfo.append(questions.get(i).replace("_", " "));
if (i < questions.size() - 1) {
surveySharedInfo.append(", ");
}
}
sharedInfoTextView.setVisibility(View.VISIBLE);
sharedInfoTextView.setText(surveySharedInfo);

}

}
123 changes: 72 additions & 51 deletions onebusaway-android/src/main/res/layout/item_survey.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,29 +30,28 @@
<Button
android:id="@+id/openExternalSurveyBtn"
android:layout_width="90dp"
android:visibility="gone"
android:layout_height="35dp"
android:background="@drawable/round_custom_button"
android:drawableStart="@drawable/baseline_open_in_new_24"
android:paddingStart="16dp"
android:visibility="gone"
android:paddingEnd="16dp"
android:drawableStart="@drawable/baseline_open_in_new_24"
android:layout_marginEnd="8dp"
android:background="@drawable/round_custom_button"
android:text="@string/go"
android:textColor="@android:color/white"
app:layout_constraintBottom_toBottomOf="@+id/survey_question_tv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="@+id/survey_question_tv" />
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/close_btn"
app:layout_constraintTop_toTopOf="parent" />

<ImageButton
android:id="@+id/close_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="8dp"
android:visibility="gone"
android:layout_marginEnd="8dp"
android:background="@null"
android:contentDescription="@string/dismiss_survey"
android:src="@drawable/ic_close"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand Down Expand Up @@ -83,77 +82,99 @@
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:text="@string/you_can_select_multiple_options_for_this_pool"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/nextBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/survey_question_tv"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@+id/survey_question_tv" />

<EditText
android:id="@+id/editText"
android:layout_width="0dp"

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:hint="@string/write_your_answer_here"
android:importantForAutofill="no"
android:inputType="text"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/nextBtn"
app:layout_constraintBottom_toTopOf="@+id/shared_info_tv"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/survey_question_tv"
app:layout_constraintVertical_bias="0.0" />
app:layout_constraintTop_toBottomOf="@+id/checkBoxLabel"
app:layout_constraintVertical_bias="0.0">


<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@+id/nextBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/survey_question_tv"
app:layout_constraintVertical_bias="0.0" />
<EditText
android:id="@+id/editText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:hint="@string/write_your_answer_here"
android:importantForAutofill="no"
android:inputType="text"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />


<RadioGroup
android:id="@+id/radioGroup"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:visibility="gone"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />

<LinearLayout
android:id="@+id/checkBoxContainer"

<LinearLayout
android:id="@+id/checkBoxContainer"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
</androidx.constraintlayout.widget.ConstraintLayout>


<TextView
android:id="@+id/shared_info_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:layout_marginBottom="8dp"
android:orientation="vertical"
android:visibility="gone"
app:layout_constraintBottom_toTopOf="@+id/nextBtn"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintEnd_toStartOf="@+id/openExternalSurveyBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/checkBoxLabel"
app:layout_constraintVertical_bias="0.0" />
tools:text="This survey will share your location and current stop" />


<Button
android:id="@+id/nextBtn"
android:layout_width="120dp"
android:layout_height="35dp"
android:visibility="gone"
android:layout_marginBottom="16dp"
android:background="@drawable/round_custom_button"
android:text="@string/pager_button_next"
android:textAllCaps="false"
android:textColor="@android:color/white"
android:visibility="gone"
app:cornerRadius="20dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
Expand Down
1 change: 1 addition & 0 deletions onebusaway-android/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1256,4 +1256,5 @@
<string name="go">GO !</string>
<string name="submitted_successfully">Submitted Successfully</string>
<string name="please_fill_all_the_questions">Please fill all the questions</string>
<string name="sharing_survey_info_message">"This survey will share your "</string>
</resources>

0 comments on commit ce118d0

Please sign in to comment.