Skip to content

Commit d427dd0

Browse files
committed
Merge pull request #34 from dimagi/progress-bar-fix-copy
Entire progress bar fix in one commit
2 parents d3b4ef1 + b3ee562 commit d427dd0

4 files changed

Lines changed: 42 additions & 41 deletions

File tree

src/org/odk/collect/android/activities/FormEntryActivity.java

Lines changed: 22 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -805,40 +805,34 @@ public void updateProgressBar(ODKView odkv) {
805805
event = mFormController.stepToPreviousEvent();
806806
}
807807

808-
boolean onCurrentScreen = false;
809-
FormIndex currentScreenExit = null;
810808
while (event != FormEntryController.EVENT_END_OF_FORM) {
811809
int comparison = mFormController.getFormIndex().compareTo(currentFormIndex);
812810

813-
if (comparison == 0) {
814-
onCurrentScreen = true;
815-
mFormController.stepToNextEvent(true);
816-
currentScreenExit = mFormController.getFormIndex();
817-
mFormController.stepToPreviousEvent();
818-
}
819-
if (onCurrentScreen && mFormController.getFormIndex().equals(currentScreenExit)) {
820-
onCurrentScreen = false;
821-
}
822-
823811
if (event == FormEntryController.EVENT_QUESTION) {
824-
FormEntryPrompt[] prompts = mFormController.getQuestionPrompts();
825-
totalQuestions += prompts.length;
826-
// Current questions are complete only if they're answered.
827-
// Past questions are always complete.
828-
// Future questions are never complete.
829-
if (onCurrentScreen) {
830-
for (FormEntryPrompt prompt : prompts) {
831-
if (prompt.getAnswerValue() != null || prompt.getDataType() == Constants.DATATYPE_NULL) {
832-
completedQuestions++;
833-
}
834-
}
812+
totalQuestions++;
813+
814+
// Questions are counted as complete if any of the following are true:
815+
// - User has already passed the question, regardless of if it's been answered
816+
// - User is currently looking at the question, and it's been answered
817+
// - User is currently looking at a group containing the question, and it's been answered
818+
if (comparison < 0) {
819+
completedQuestions++;
835820
}
836-
else if (comparison < 0) {
837-
// For previous questions, consider all "complete"
838-
completedQuestions += prompts.length;
821+
else {
822+
FormEntryPrompt prompt = mFormController.getQuestionPrompt();
823+
if (prompt.getAnswerValue() != null || prompt.getDataType() == Constants.DATATYPE_NULL) {
824+
if (comparison == 0) {
825+
completedQuestions++;
826+
}
827+
else if (FormIndex.isSubElement(currentFormIndex, mFormController.getFormIndex())) {
828+
completedQuestions++;
829+
}
830+
}
839831
}
840832
}
841-
event = mFormController.stepToNextEvent(false);
833+
834+
// Make sure we visit every question inside every group
835+
event = mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP, false);
842836
}
843837

844838
// Set form back to correct state & actually update bar
@@ -1345,7 +1339,7 @@ private void showNextView(boolean resuming) {
13451339
try{
13461340

13471341
group_skip: do {
1348-
event = mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
1342+
event = mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
13491343
switch (event) {
13501344
case FormEntryController.EVENT_QUESTION:
13511345
case FormEntryController.EVENT_END_OF_FORM:

src/org/odk/collect/android/activities/FormHierarchyActivity.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ public void refreshView() {
206206
if (FormEntryActivity.mFormController.getEvent() == FormEntryController.EVENT_REPEAT) {
207207
enclosingGroupRef =
208208
FormEntryActivity.mFormController.getFormIndex().getReference().toString(false);
209-
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
209+
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
210210
} else {
211211
FormIndex startTest = stepIndexOut(currentIndex);
212212
// If we have a 'group' tag, we want to step back until we hit a repeat or the
@@ -230,14 +230,14 @@ public void refreshView() {
230230
if (FormEntryActivity.mFormController.getEvent() == FormEntryController.EVENT_REPEAT) {
231231
enclosingGroupRef =
232232
FormEntryActivity.mFormController.getFormIndex().getReference().toString(false);
233-
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
233+
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
234234
}
235235
}
236236

237237
int event = FormEntryActivity.mFormController.getEvent();
238238
if (event == FormEntryController.EVENT_BEGINNING_OF_FORM) {
239239
// The beginning of form has no valid prompt to display.
240-
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
240+
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
241241
mPath.setVisibility(View.GONE);
242242
jumpPreviousButton.setEnabled(false);
243243
} else {
@@ -261,7 +261,7 @@ public void refreshView() {
261261
// index.
262262
event =
263263
FormEntryActivity.mFormController
264-
.stepToNextEvent(FormController.STEP_OVER_GROUP);
264+
.stepToNextEvent(FormController.STEP_INTO_GROUP);
265265
continue;
266266
}
267267

@@ -286,7 +286,7 @@ public void refreshView() {
286286
// next event.
287287
event =
288288
FormEntryActivity.mFormController
289-
.stepToNextEvent(FormController.STEP_OVER_GROUP);
289+
.stepToNextEvent(FormController.STEP_INTO_GROUP);
290290
continue;
291291
}
292292

@@ -329,7 +329,7 @@ public void refreshView() {
329329
break;
330330
}
331331
event =
332-
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
332+
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
333333
}
334334

335335
HierarchyListAdapter itla = new HierarchyListAdapter(this);

src/org/odk/collect/android/logic/FormController.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public class FormController {
5656

5757
private boolean mReadOnly;
5858

59-
public static final boolean STEP_INTO_GROUP = true;
60-
public static final boolean STEP_OVER_GROUP = false;
59+
public static final boolean STEP_OVER_GROUP = true;
60+
public static final boolean STEP_INTO_GROUP = false;
6161

6262
/**
6363
* OpenRosa metadata tag names.
@@ -310,7 +310,6 @@ public boolean saveAnswer(FormIndex index, IAnswerData data) {
310310
return mFormEntryController.saveAnswer(index, data);
311311
}
312312

313-
314313
/**
315314
* saveAnswer attempts to save the current answer into the data model without doing any
316315
* constraint checking. Only use this if you know what you're doing. For normal form filling you
@@ -324,20 +323,28 @@ public boolean saveAnswer(IAnswerData data) {
324323
return mFormEntryController.saveAnswer(data);
325324
}
326325

326+
/**
327+
* Navigates forward in the form, expanding any repeats encountered.
328+
*
329+
* @return the next event that should be handled by a view.
330+
*/
331+
public int stepToNextEvent(boolean stepOverGroup) {
332+
return stepToNextEvent(stepOverGroup, true);
333+
}
327334

328335
/**
329336
* Navigates forward in the form.
330337
*
331338
* @return the next event that should be handled by a view.
332339
*/
333-
public int stepToNextEvent(boolean stepOverGroup) {
340+
public int stepToNextEvent(boolean stepOverGroup, boolean expandRepeats) {
334341
if (mFormEntryController.getModel().getEvent() == FormEntryController.EVENT_GROUP && indexIsInFieldList() && stepOverGroup) {
335342
return stepOverGroup();
336343
} else {
337-
int event = mFormEntryController.stepToNextEvent();
344+
int event = mFormEntryController.stepToNextEvent(expandRepeats);
338345
if(event == FormEntryController.EVENT_PROMPT_NEW_REPEAT &&
339346
this.mReadOnly) {
340-
return stepToNextEvent(stepOverGroup);
347+
return stepToNextEvent(stepOverGroup, expandRepeats);
341348
}
342349
return event;
343350
}

src/org/odk/collect/android/tasks/SaveToDiskTask.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ private int validateAnswers(Boolean markCompleted) {
389389

390390
int event;
391391
while ((event =
392-
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP)) != FormEntryController.EVENT_END_OF_FORM) {
392+
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP)) != FormEntryController.EVENT_END_OF_FORM) {
393393
if (event != FormEntryController.EVENT_QUESTION) {
394394
continue;
395395
} else {

0 commit comments

Comments
 (0)