Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hint text to QueryRequestUIController #2668

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/res/layout/query_prompt_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@
android:gravity="center|left"
android:layout_height="wrap_content" />

<ImageButton
android:id="@+id/prompt_hint_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@android:color/transparent"
android:singleLine="true"
android:visibility="gone"
app:srcCompat="@drawable/icon_info_outline_lightcool" />

<Spinner
android:id="@+id/prompt_spinner"
Expand Down
30 changes: 30 additions & 0 deletions app/src/org/commcare/activities/QueryRequestUiController.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.javarosa.core.services.locale.Localizer
import java.text.ParseException
import java.util.*
import kotlin.collections.ArrayList
import org.commcare.views.dialogs.StandardAlertDialog;
import android.content.DialogInterface

@ManagedUi(R.layout.http_request_layout)
class QueryRequestUiController(
Expand Down Expand Up @@ -133,6 +135,8 @@ class QueryRequestUiController(
LayoutInflater.from(queryRequestActivity)
.inflate(R.layout.query_prompt_layout, promptsLayout, false)
setLabelText(promptView, queryPrompt)
setHintPlaceholder(promptView, queryPrompt)

val inputView = buildPromptInputView(promptView, queryPrompt, isLastPrompt)
setUpBarCodeScanButton(promptView, promptId, queryPrompt)
promptsLayout.addView(promptView)
Expand Down Expand Up @@ -407,6 +411,32 @@ class QueryRequestUiController(
return Localizer.processArguments(displayData.name, arrayOf("")).trim { it <= ' ' }
}

private fun setHintPlaceholder(promptView: View, queryPrompt: QueryPrompt) {
val hintText = getHintText(queryPrompt)
if (hintText != "") {
val promptHelpButton = promptView.findViewById<View>(R.id.prompt_hint_button)
promptHelpButton.visibility = View.VISIBLE

promptHelpButton.setOnClickListener {
queryRequestActivity.showAlertDialog(StandardAlertDialog.getBasicAlertDialog(
queryRequestActivity,
"Hint",
hintText,
DialogInterface.OnClickListener { dialog, id ->
dialog.dismiss()
}
))
}
}
}

private fun getHintText(queryPrompt: QueryPrompt): String {
val displayData = queryPrompt.display.evaluate()
val hintText = displayData.hintText ?: return "";

return Localizer.processArguments(hintText, arrayOf("")).trim { it <= ' ' }
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to call Localizer. processArguments here as calling queryPrompt.display.evaluate() should evaluate any localised strings itself.

}

// Thrown when we are setting an invalid value to the prompt,
// for ex- trying to set multiple values to a single valued prompt
class InvalidPromptValueException(message: String) : Throwable(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ query.id=Patient ID
query.state=State
query.district=District
query.date=Date
query.date.hint=dd/mm/YYYY
case_sharing.exactly_one_group=The case sharing settings for your user are incorrect. This user must be in exactly one case sharing group. Please contact your supervisor.
cchq.case=Case
cchq.referral=Referral
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,11 @@
<text>
<locale id="query.date"/>
</text>
<hint>
<text>
<locale id="query.date.hint"/>
</text>
</hint>
</display>
</prompt>
<prompt key="invalid" input="foobar">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import android.widget.LinearLayout;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.ImageButton;

import org.commcare.CommCareApplication;
import org.commcare.CommCareTestApplication;
Expand Down Expand Up @@ -217,6 +218,12 @@ public void reloadQueryActivityStateTest() {
EditText patientName = promptsLayout.getChildAt(0).findViewById(R.id.prompt_et);
assertEquals("francisco", patientName.getText().toString());

ImageButton imageButtonWithoutHint = promptsLayout.getChildAt(0).findViewById(R.id.prompt_hint_button);
assertEquals(8, imageButtonWithoutHint.getVisibility());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use the constants from view class here like View.VISIBLE instead of using raw int values, but looks good otherwise.


ImageButton imageButtonWithHint = promptsLayout.getChildAt(4).findViewById(R.id.prompt_hint_button);
assertEquals(0, imageButtonWithHint.getVisibility());

Spinner stateSpinner = promptsLayout.getChildAt(2).findViewById(R.id.prompt_spinner);
assertEquals(2, stateSpinner.getSelectedItemPosition());

Expand Down