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

Entire progress bar fix in one commit #34

Merged
merged 1 commit into from
Sep 22, 2014
Merged
Show file tree
Hide file tree
Changes from all 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
50 changes: 22 additions & 28 deletions src/org/odk/collect/android/activities/FormEntryActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -805,40 +805,34 @@ public void updateProgressBar(ODKView odkv) {
event = mFormController.stepToPreviousEvent();
}

boolean onCurrentScreen = false;
FormIndex currentScreenExit = null;
while (event != FormEntryController.EVENT_END_OF_FORM) {
int comparison = mFormController.getFormIndex().compareTo(currentFormIndex);

if (comparison == 0) {
onCurrentScreen = true;
mFormController.stepToNextEvent(true);
currentScreenExit = mFormController.getFormIndex();
mFormController.stepToPreviousEvent();
}
if (onCurrentScreen && mFormController.getFormIndex().equals(currentScreenExit)) {
onCurrentScreen = false;
}

if (event == FormEntryController.EVENT_QUESTION) {
FormEntryPrompt[] prompts = mFormController.getQuestionPrompts();
totalQuestions += prompts.length;
// Current questions are complete only if they're answered.
// Past questions are always complete.
// Future questions are never complete.
if (onCurrentScreen) {
for (FormEntryPrompt prompt : prompts) {
if (prompt.getAnswerValue() != null || prompt.getDataType() == Constants.DATATYPE_NULL) {
completedQuestions++;
}
}
totalQuestions++;

// Questions are counted as complete if any of the following are true:
// - User has already passed the question, regardless of if it's been answered
// - User is currently looking at the question, and it's been answered
// - User is currently looking at a group containing the question, and it's been answered
if (comparison < 0) {
completedQuestions++;
}
else if (comparison < 0) {
// For previous questions, consider all "complete"
completedQuestions += prompts.length;
else {
FormEntryPrompt prompt = mFormController.getQuestionPrompt();
if (prompt.getAnswerValue() != null || prompt.getDataType() == Constants.DATATYPE_NULL) {
if (comparison == 0) {
completedQuestions++;
}
else if (FormIndex.isSubElement(currentFormIndex, mFormController.getFormIndex())) {
completedQuestions++;
}
}
}
}
event = mFormController.stepToNextEvent(false);

// Make sure we visit every question inside every group
event = mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP, false);
}

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

group_skip: do {
event = mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
event = mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
switch (event) {
case FormEntryController.EVENT_QUESTION:
case FormEntryController.EVENT_END_OF_FORM:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void refreshView() {
if (FormEntryActivity.mFormController.getEvent() == FormEntryController.EVENT_REPEAT) {
enclosingGroupRef =
FormEntryActivity.mFormController.getFormIndex().getReference().toString(false);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
} else {
FormIndex startTest = stepIndexOut(currentIndex);
// If we have a 'group' tag, we want to step back until we hit a repeat or the
Expand All @@ -230,14 +230,14 @@ public void refreshView() {
if (FormEntryActivity.mFormController.getEvent() == FormEntryController.EVENT_REPEAT) {
enclosingGroupRef =
FormEntryActivity.mFormController.getFormIndex().getReference().toString(false);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
}
}

int event = FormEntryActivity.mFormController.getEvent();
if (event == FormEntryController.EVENT_BEGINNING_OF_FORM) {
// The beginning of form has no valid prompt to display.
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
mPath.setVisibility(View.GONE);
jumpPreviousButton.setEnabled(false);
} else {
Expand All @@ -261,7 +261,7 @@ public void refreshView() {
// index.
event =
FormEntryActivity.mFormController
.stepToNextEvent(FormController.STEP_OVER_GROUP);
.stepToNextEvent(FormController.STEP_INTO_GROUP);
continue;
}

Expand All @@ -286,7 +286,7 @@ public void refreshView() {
// next event.
event =
FormEntryActivity.mFormController
.stepToNextEvent(FormController.STEP_OVER_GROUP);
.stepToNextEvent(FormController.STEP_INTO_GROUP);
continue;
}

Expand Down Expand Up @@ -329,7 +329,7 @@ public void refreshView() {
break;
}
event =
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP);
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP);
}

HierarchyListAdapter itla = new HierarchyListAdapter(this);
Expand Down
19 changes: 13 additions & 6 deletions src/org/odk/collect/android/logic/FormController.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@ public class FormController {

private boolean mReadOnly;

public static final boolean STEP_INTO_GROUP = true;
public static final boolean STEP_OVER_GROUP = false;
public static final boolean STEP_OVER_GROUP = true;
public static final boolean STEP_INTO_GROUP = false;

/**
* OpenRosa metadata tag names.
Expand Down Expand Up @@ -310,7 +310,6 @@ public boolean saveAnswer(FormIndex index, IAnswerData data) {
return mFormEntryController.saveAnswer(index, data);
}


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

/**
* Navigates forward in the form, expanding any repeats encountered.
*
* @return the next event that should be handled by a view.
*/
public int stepToNextEvent(boolean stepOverGroup) {
return stepToNextEvent(stepOverGroup, true);
}

/**
* Navigates forward in the form.
*
* @return the next event that should be handled by a view.
*/
public int stepToNextEvent(boolean stepOverGroup) {
public int stepToNextEvent(boolean stepOverGroup, boolean expandRepeats) {
if (mFormEntryController.getModel().getEvent() == FormEntryController.EVENT_GROUP && indexIsInFieldList() && stepOverGroup) {
return stepOverGroup();
} else {
int event = mFormEntryController.stepToNextEvent();
int event = mFormEntryController.stepToNextEvent(expandRepeats);
if(event == FormEntryController.EVENT_PROMPT_NEW_REPEAT &&
this.mReadOnly) {
return stepToNextEvent(stepOverGroup);
return stepToNextEvent(stepOverGroup, expandRepeats);
}
return event;
}
Expand Down
2 changes: 1 addition & 1 deletion src/org/odk/collect/android/tasks/SaveToDiskTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ private int validateAnswers(Boolean markCompleted) {

int event;
while ((event =
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_OVER_GROUP)) != FormEntryController.EVENT_END_OF_FORM) {
FormEntryActivity.mFormController.stepToNextEvent(FormController.STEP_INTO_GROUP)) != FormEntryController.EVENT_END_OF_FORM) {
if (event != FormEntryController.EVENT_QUESTION) {
continue;
} else {
Expand Down