Skip to content

Commit

Permalink
Fix for getodk#3027
Browse files Browse the repository at this point in the history
  • Loading branch information
dimwight committed Jul 22, 2023
1 parent 0a76d47 commit babd953
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
Expand Up @@ -83,7 +83,11 @@
public class FormHierarchyActivity extends LocalizedActivity implements DeleteRepeatDialogFragment.DeleteRepeatDialogCallback {

public static final int RESULT_ADD_REPEAT = 2;

public static final String EXTRA_SESSION_ID = "session_id";

private static FormIndex fieldlistFocusIndex;

/**
* The questions and repeats at the current level.
* Recreated every time {@link #refreshView()} is called.
Expand Down Expand Up @@ -791,12 +795,15 @@ public void onElementClick(HierarchyElement element) {
/**
* Handles clicks on a question. Jumps to the form filling view with the selected question shown.
* If the selected question is in a field list, show the entire field list.
* For #3027, prepare to set the appropriate focus.
*/
void onQuestionClicked(FormIndex index) {
formEntryViewModel.getFormController().jumpToIndex(index);
if (formEntryViewModel.getFormController().indexIsInFieldList()) {
FormController formController = formEntryViewModel.getFormController();
formController.jumpToIndex(index);
if (formController.indexIsInFieldList()) {
setFieldlistFocusIndex(index);
try {
formEntryViewModel.getFormController().stepToPreviousScreenEvent();
formController.stepToPreviousScreenEvent();
} catch (JavaRosaException e) {
Timber.d(e);
createErrorDialog(e.getCause().getMessage());
Expand Down Expand Up @@ -890,4 +897,12 @@ public void deleteGroup() {
goUpLevel();
}
}

public static void setFieldlistFocusIndex(FormIndex index) {
fieldlistFocusIndex = index;
}

public static FormIndex getFieldlistFocusIndex() {
return fieldlistFocusIndex;
}
}
Expand Up @@ -55,6 +55,7 @@
import org.javarosa.form.api.FormEntryCaption;
import org.javarosa.form.api.FormEntryPrompt;
import org.odk.collect.android.R;
import org.odk.collect.android.activities.FormHierarchyActivity;
import org.odk.collect.android.application.Collect;
import org.odk.collect.android.audio.AudioHelper;
import org.odk.collect.android.exception.ExternalParamsException;
Expand Down Expand Up @@ -459,9 +460,18 @@ private void addIntentLaunchButton(Context context, FormEntryPrompt[] questionPr
}

public void setFocus(Context context) {
if (!widgets.isEmpty()) {
widgets.get(0).setFocus(context);
if (widgets.isEmpty()) {
return;
}
QuestionWidget forFocus = widgets.get(0);
FormIndex focusIndex = FormHierarchyActivity.getFieldlistFocusIndex();
for (QuestionWidget widget : widgets) {
if (widget.getFormEntryPrompt().getIndex().equals(focusIndex)) {
forFocus = widget;
}
}
forFocus.setFocus(context);
scrollTo(forFocus);
}

/**
Expand Down

0 comments on commit babd953

Please sign in to comment.