From cefc122acbbadda8a5c919bb6cc49ef6407303ff Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 09:36:08 -0800 Subject: [PATCH 01/19] Use existing FormController variable which can't be null --- .../activities/FormHierarchyActivity.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index a3481bf4afb..4eb79b6a186 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -103,11 +103,9 @@ public void onClick(View v) { jumpBeginningButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - FormController fc = Collect.getInstance().getFormController(); - if (fc != null) { - fc.getTimerLogger().exitView(); - fc.jumpToIndex(FormIndex.createBeginningOfFormIndex()); - } + formController.getTimerLogger().exitView(); + formController.jumpToIndex(FormIndex.createBeginningOfFormIndex()); + setResult(RESULT_OK); finish(); } @@ -117,11 +115,9 @@ public void onClick(View v) { jumpEndButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { - FormController fc = Collect.getInstance().getFormController(); - if (fc != null) { - fc.getTimerLogger().exitView(); - fc.jumpToIndex(FormIndex.createEndOfFormIndex()); - } + formController.getTimerLogger().exitView(); + formController.jumpToIndex(FormIndex.createEndOfFormIndex()); + setResult(RESULT_OK); finish(); } From a563e9979c2ef137b3cb94f3735b34579c6cea06 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 09:46:40 -0800 Subject: [PATCH 02/19] Extract configureButtons method --- .../activities/FormHierarchyActivity.java | 54 +++++++++---------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 4eb79b6a186..338f2a43cd4 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -23,7 +23,6 @@ import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; import android.view.View; -import android.view.View.OnClickListener; import android.widget.Button; import android.widget.TextView; @@ -92,37 +91,10 @@ public void onCreate(Bundle savedInstanceState) { path = findViewById(R.id.pathtext); jumpPreviousButton = findViewById(R.id.jumpPreviousButton); - jumpPreviousButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - goUpLevel(); - } - }); - jumpBeginningButton = findViewById(R.id.jumpBeginningButton); - jumpBeginningButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - formController.getTimerLogger().exitView(); - formController.jumpToIndex(FormIndex.createBeginningOfFormIndex()); - - setResult(RESULT_OK); - finish(); - } - }); - jumpEndButton = findViewById(R.id.jumpEndButton); - jumpEndButton.setOnClickListener(new OnClickListener() { - @Override - public void onClick(View v) { - formController.getTimerLogger().exitView(); - formController.jumpToIndex(FormIndex.createEndOfFormIndex()); - - setResult(RESULT_OK); - finish(); - } - }); + configureButtons(formController); refreshView(); // Kinda slow, but works. This scrolls to the last question the user was looking at. @@ -141,6 +113,30 @@ public void onClick(View v) { } } + + /** + * Configure the navigation buttons at the bottom of the screen. + */ + void configureButtons(FormController formController) { + jumpPreviousButton.setOnClickListener(v -> goUpLevel()); + + jumpBeginningButton.setOnClickListener(v -> { + formController.getTimerLogger().exitView(); + formController.jumpToIndex(FormIndex.createBeginningOfFormIndex()); + + setResult(RESULT_OK); + finish(); + }); + + jumpEndButton.setOnClickListener(v -> { + formController.getTimerLogger().exitView(); + formController.jumpToIndex(FormIndex.createEndOfFormIndex()); + + setResult(RESULT_OK); + finish(); + }); + } + private boolean shouldScrollToTheGivenIndex(FormIndex formIndex, FormController formController) { return startIndex.equals(formIndex) || (formController.indexIsInFieldList(startIndex) && formIndex.toString().startsWith(startIndex.toString())); From 505d4a0fc25bfc9977ec45b5233faa661692c819 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 09:59:58 -0800 Subject: [PATCH 03/19] Override configureButtons in view-only hiearchy --- .../activities/ViewFormHierarchyActivity.java | 29 ++++++++----------- 1 file changed, 12 insertions(+), 17 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java index 0dca2e12523..64f8fa8f69a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java @@ -14,7 +14,6 @@ package org.odk.collect.android.activities; -import android.os.Bundle; import android.support.v4.content.ContextCompat; import android.support.v7.widget.LinearLayoutManager; import android.view.View; @@ -25,6 +24,7 @@ import org.odk.collect.android.adapters.HierarchyListAdapter; import org.odk.collect.android.application.Collect; import org.odk.collect.android.exception.JavaRosaException; +import org.odk.collect.android.logic.FormController; import org.odk.collect.android.logic.HierarchyElement; import java.util.ArrayList; @@ -32,26 +32,21 @@ import timber.log.Timber; public class ViewFormHierarchyActivity extends FormHierarchyActivity { - + /** + * A view-only hierarchy doesn't allow the user to jump into the form-filling view so the + * buttons to jump to the beginning and to the end of the form are hidden. There is an extra + * button that allows the user to exit to the previous activity. + */ @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); + void configureButtons(FormController formController) { + formController.stepToOuterScreenEvent(); - // super.onCreate() can call finish() if it finds the FormController to be null - // in that case, we want to shortcut this method, and let the Activity finish itself - if (isFinishing()) { - return; - } - - Collect.getInstance().getFormController().stepToOuterScreenEvent(); + jumpPreviousButton.setOnClickListener(v -> goUpLevel()); Button exitButton = findViewById(R.id.exitButton); - exitButton.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - setResult(RESULT_OK); - finish(); - } + exitButton.setOnClickListener(v -> { + setResult(RESULT_OK); + finish(); }); exitButton.setVisibility(View.VISIBLE); From 914ca44b88399a7f632ebdb60bd0dfa1d870d5b5 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 10:00:59 -0800 Subject: [PATCH 04/19] Remove step to top of form or group in view-only hierarchy Introduced at https://github.com/grzesiek2010/collect/blob/2ecb17048d6ef1f6779dce5276a7c7e623d218b7/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java#L116 with the view-only mode. Would be useful if current index could be set when the view-only activity is opened but that doesn't seem possible since the activity is not launched from form filling. --- .../collect/android/activities/ViewFormHierarchyActivity.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java index 64f8fa8f69a..6320cdf7c0a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java @@ -39,8 +39,6 @@ public class ViewFormHierarchyActivity extends FormHierarchyActivity { */ @Override void configureButtons(FormController formController) { - formController.stepToOuterScreenEvent(); - jumpPreviousButton.setOnClickListener(v -> goUpLevel()); Button exitButton = findViewById(R.id.exitButton); From 0a61206a4d87808e631f5afbb139ee5d0688bddb Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 10:10:31 -0800 Subject: [PATCH 05/19] Move the click behavior to the base class and add comment --- .../activities/EditFormHierarchyActivity.java | 65 ------------------- .../activities/FormHierarchyActivity.java | 61 ++++++++++++++++- 2 files changed, 60 insertions(+), 66 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java index 8084cab94df..e8f756b711d 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java @@ -14,77 +14,12 @@ package org.odk.collect.android.activities; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.LinearLayoutManager; import android.view.KeyEvent; -import org.javarosa.core.model.FormIndex; -import org.odk.collect.android.R; -import org.odk.collect.android.adapters.HierarchyListAdapter; import org.odk.collect.android.application.Collect; -import org.odk.collect.android.exception.JavaRosaException; import org.odk.collect.android.logic.FormController; -import org.odk.collect.android.logic.HierarchyElement; - -import java.util.ArrayList; - -import timber.log.Timber; public class EditFormHierarchyActivity extends FormHierarchyActivity { - - @Override - public void onElementClick(HierarchyElement element) { - int position = formList.indexOf(element); - FormIndex index = element.getFormIndex(); - if (index == null) { - goUpLevel(); - return; - } - - switch (element.getType()) { - case EXPANDED: - element.setType(COLLAPSED); - ArrayList children = element.getChildren(); - for (int i = 0; i < children.size(); i++) { - formList.remove(position + 1); - } - element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_minimized)); - break; - case COLLAPSED: - element.setType(EXPANDED); - ArrayList children1 = element.getChildren(); - for (int i = 0; i < children1.size(); i++) { - Timber.i("adding child: %s", children1.get(i).getFormIndex()); - formList.add(position + 1 + i, children1.get(i)); - - } - element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_maximized)); - break; - case QUESTION: - Collect.getInstance().getFormController().jumpToIndex(index); - if (Collect.getInstance().getFormController().indexIsInFieldList()) { - try { - Collect.getInstance().getFormController().stepToPreviousScreenEvent(); - } catch (JavaRosaException e) { - Timber.d(e); - createErrorDialog(e.getCause().getMessage()); - return; - } - } - setResult(RESULT_OK); - finish(); - return; - case CHILD: - Collect.getInstance().getFormController().jumpToIndex(element.getFormIndex()); - setResult(RESULT_OK); - refreshView(); - return; - } - - recyclerView.setAdapter(new HierarchyListAdapter(formList, this::onElementClick)); - ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0); - } - @Override public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 338f2a43cd4..62dfdb2013e 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -34,6 +34,7 @@ import org.odk.collect.android.R; import org.odk.collect.android.adapters.HierarchyListAdapter; import org.odk.collect.android.application.Collect; +import org.odk.collect.android.exception.JavaRosaException; import org.odk.collect.android.logic.FormController; import org.odk.collect.android.logic.HierarchyElement; import org.odk.collect.android.utilities.FormEntryPromptUtils; @@ -336,7 +337,65 @@ public void refreshView() { } } - protected abstract void onElementClick(HierarchyElement element); + /** + * Handles clicks on a specific row in the hierarchy view. Clicking on a: + * - group makes it toggle between expanded and collapsed + * - question jumps to the form filling view with that question shown. If the question is in a + * field list, shows that entire field list. + * - group's child element causes this hierarchy view to be refreshed with that element's + * questions shown + */ + public void onElementClick(HierarchyElement element) { + int position = formList.indexOf(element); + FormIndex index = element.getFormIndex(); + if (index == null) { + goUpLevel(); + return; + } + + switch (element.getType()) { + case EXPANDED: + element.setType(COLLAPSED); + ArrayList children = element.getChildren(); + for (int i = 0; i < children.size(); i++) { + formList.remove(position + 1); + } + element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_minimized)); + break; + case COLLAPSED: + element.setType(EXPANDED); + ArrayList children1 = element.getChildren(); + for (int i = 0; i < children1.size(); i++) { + Timber.i("adding child: %s", children1.get(i).getFormIndex()); + formList.add(position + 1 + i, children1.get(i)); + + } + element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_maximized)); + break; + case QUESTION: + Collect.getInstance().getFormController().jumpToIndex(index); + if (Collect.getInstance().getFormController().indexIsInFieldList()) { + try { + Collect.getInstance().getFormController().stepToPreviousScreenEvent(); + } catch (JavaRosaException e) { + Timber.d(e); + createErrorDialog(e.getCause().getMessage()); + return; + } + } + setResult(RESULT_OK); + finish(); + return; + case CHILD: + Collect.getInstance().getFormController().jumpToIndex(element.getFormIndex()); + setResult(RESULT_OK); + refreshView(); + return; + } + + recyclerView.setAdapter(new HierarchyListAdapter(formList, this::onElementClick)); + ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0); + } /** * Creates and displays dialog with the given errorMsg. From 561f8eab748e9a677dd193dd8c981c26e35201ad Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 10:19:27 -0800 Subject: [PATCH 06/19] Extract method to handle question click --- .../activities/FormHierarchyActivity.java | 32 ++++++++++++------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 62dfdb2013e..ed4f0771a8f 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -373,18 +373,7 @@ public void onElementClick(HierarchyElement element) { element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_maximized)); break; case QUESTION: - Collect.getInstance().getFormController().jumpToIndex(index); - if (Collect.getInstance().getFormController().indexIsInFieldList()) { - try { - Collect.getInstance().getFormController().stepToPreviousScreenEvent(); - } catch (JavaRosaException e) { - Timber.d(e); - createErrorDialog(e.getCause().getMessage()); - return; - } - } - setResult(RESULT_OK); - finish(); + onQuestionClicked(index); return; case CHILD: Collect.getInstance().getFormController().jumpToIndex(element.getFormIndex()); @@ -397,6 +386,25 @@ public void onElementClick(HierarchyElement element) { ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0); } + /** + * 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. + */ + private void onQuestionClicked(FormIndex index) { + Collect.getInstance().getFormController().jumpToIndex(index); + if (Collect.getInstance().getFormController().indexIsInFieldList()) { + try { + Collect.getInstance().getFormController().stepToPreviousScreenEvent(); + } catch (JavaRosaException e) { + Timber.d(e); + createErrorDialog(e.getCause().getMessage()); + return; + } + } + setResult(RESULT_OK); + finish(); + } + /** * Creates and displays dialog with the given errorMsg. */ From f02a54ee4bcbc122246385a3c023df14bb7c3dfd Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 10:26:30 -0800 Subject: [PATCH 07/19] Put default back button behavior in base class --- .../activities/EditFormHierarchyActivity.java | 13 +--- .../activities/FormHierarchyActivity.java | 20 +++++- .../activities/ViewFormHierarchyActivity.java | 72 ++++--------------- 3 files changed, 34 insertions(+), 71 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java index e8f756b711d..3c5d0c32af1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java @@ -20,16 +20,5 @@ import org.odk.collect.android.logic.FormController; public class EditFormHierarchyActivity extends FormHierarchyActivity { - @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - switch (keyCode) { - case KeyEvent.KEYCODE_BACK: - FormController fc = Collect.getInstance().getFormController(); - if (fc != null) { - fc.getTimerLogger().exitView(); - fc.jumpToIndex(startIndex); - } - } - return super.onKeyDown(keyCode, event); - } + } diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index ed4f0771a8f..f57eb64c4f1 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -22,6 +22,7 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; +import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.TextView; @@ -390,7 +391,7 @@ 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. */ - private void onQuestionClicked(FormIndex index) { + void onQuestionClicked(FormIndex index) { Collect.getInstance().getFormController().jumpToIndex(index); if (Collect.getInstance().getFormController().indexIsInFieldList()) { try { @@ -405,6 +406,23 @@ private void onQuestionClicked(FormIndex index) { finish(); } + /** + * When the device back button is pressed, go back to the previous activity, NOT the previous + * level in the hierarchy as the "Go Up" button does. + */ + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + switch (keyCode) { + case KeyEvent.KEYCODE_BACK: + FormController fc = Collect.getInstance().getFormController(); + if (fc != null) { + fc.getTimerLogger().exitView(); + fc.jumpToIndex(startIndex); + } + } + return super.onKeyDown(keyCode, event); + } + /** * Creates and displays dialog with the given errorMsg. */ diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java index 6320cdf7c0a..039bfe620da 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/ViewFormHierarchyActivity.java @@ -14,22 +14,13 @@ package org.odk.collect.android.activities; -import android.support.v4.content.ContextCompat; -import android.support.v7.widget.LinearLayoutManager; +import android.view.KeyEvent; import android.view.View; import android.widget.Button; import org.javarosa.core.model.FormIndex; import org.odk.collect.android.R; -import org.odk.collect.android.adapters.HierarchyListAdapter; -import org.odk.collect.android.application.Collect; -import org.odk.collect.android.exception.JavaRosaException; import org.odk.collect.android.logic.FormController; -import org.odk.collect.android.logic.HierarchyElement; - -import java.util.ArrayList; - -import timber.log.Timber; public class ViewFormHierarchyActivity extends FormHierarchyActivity { /** @@ -53,55 +44,20 @@ void configureButtons(FormController formController) { jumpEndButton.setVisibility(View.GONE); } + /** + * A view-only hierarchy doesn't allow the user to click on individual questions to jump into + * the form-filling view. + */ @Override - public void onElementClick(HierarchyElement element) { - int position = formList.indexOf(element); - FormIndex index = element.getFormIndex(); - if (index == null) { - goUpLevel(); - return; - } - - switch (element.getType()) { - case EXPANDED: - element.setType(COLLAPSED); - ArrayList children = element.getChildren(); - for (int i = 0; i < children.size(); i++) { - formList.remove(position + 1); - } - element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_minimized)); - break; - case COLLAPSED: - element.setType(EXPANDED); - ArrayList children1 = element.getChildren(); - for (int i = 0; i < children1.size(); i++) { - Timber.i("adding child: %s", children1.get(i).getFormIndex()); - formList.add(position + 1 + i, children1.get(i)); - - } - element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_maximized)); - break; - case QUESTION: - Collect.getInstance().getFormController().jumpToIndex(index); - if (Collect.getInstance().getFormController().indexIsInFieldList()) { - try { - Collect.getInstance().getFormController().stepToPreviousScreenEvent(); - } catch (JavaRosaException e) { - Timber.d(e); - createErrorDialog(e.getCause().getMessage()); - return; - } - } - setResult(RESULT_OK); - return; - case CHILD: - Collect.getInstance().getFormController().jumpToIndex(element.getFormIndex()); - setResult(RESULT_OK); - refreshView(); - return; - } + void onQuestionClicked(FormIndex index) { + // Do nothing + } - recyclerView.setAdapter(new HierarchyListAdapter(formList, this::onElementClick)); - ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0); + /** + * A view-only hierarchy should not log an audit event when the user exits the activity. + */ + @Override + public boolean onKeyDown(int keyCode, KeyEvent event) { + return super.onKeyDown(keyCode, event); } } From 9280d8d61224fc8d65039045d9f96d25efcf0d63 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 10:40:22 -0800 Subject: [PATCH 08/19] Make the FormHierarchyActivity the default and remove edit --- collect_app/src/main/AndroidManifest.xml | 2 +- .../activities/EditFormHierarchyActivity.java | 24 ------------------- .../android/activities/FormEntryActivity.java | 4 ++-- .../activities/FormHierarchyActivity.java | 20 ++++++++++++++-- 4 files changed, 21 insertions(+), 29 deletions(-) delete mode 100644 collect_app/src/main/java/org/odk/collect/android/activities/EditFormHierarchyActivity.java diff --git a/collect_app/src/main/AndroidManifest.xml b/collect_app/src/main/AndroidManifest.xml index ae95c4ed85b..d3b90fff7b5 100644 --- a/collect_app/src/main/AndroidManifest.xml +++ b/collect_app/src/main/AndroidManifest.xml @@ -195,8 +195,8 @@ the specific language governing permissions and limitations under the License. + - Date: Mon, 5 Nov 2018 10:50:29 -0800 Subject: [PATCH 09/19] Rename and comment view-only hierarchy class --- collect_app/src/main/AndroidManifest.xml | 2 +- .../android/activities/FormEntryActivity.java | 2 +- ...y.java => ViewOnlyFormHierarchyActivity.java} | 16 +++++++++------- 3 files changed, 11 insertions(+), 9 deletions(-) rename collect_app/src/main/java/org/odk/collect/android/activities/{ViewFormHierarchyActivity.java => ViewOnlyFormHierarchyActivity.java} (73%) diff --git a/collect_app/src/main/AndroidManifest.xml b/collect_app/src/main/AndroidManifest.xml index d3b90fff7b5..2820c39836a 100644 --- a/collect_app/src/main/AndroidManifest.xml +++ b/collect_app/src/main/AndroidManifest.xml @@ -196,7 +196,7 @@ the specific language governing permissions and limitations under the License. - + Date: Mon, 5 Nov 2018 10:58:54 -0800 Subject: [PATCH 10/19] Use enum for element types --- .../android/activities/FormHierarchyActivity.java | 15 +++++---------- .../collect/android/logic/HierarchyElement.java | 15 +++++++++++---- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index ccb1a96468d..ff73df004ff 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -64,11 +64,6 @@ * Buttons at the bottom of the screen allow users to navigate the form. */ public class FormHierarchyActivity extends CollectAbstractActivity { - protected static final int CHILD = 1; - protected static final int EXPANDED = 2; - protected static final int COLLAPSED = 3; - protected static final int QUESTION = 4; - List formList; TextView path; @@ -295,7 +290,7 @@ public void refreshView() { String answerDisplay = FormEntryPromptUtils.getAnswerText(fp, this, formController); formList.add( new HierarchyElement(FormEntryPromptUtils.markQuestionIfIsRequired(label, fp.isRequired()), answerDisplay, null, - QUESTION, fp.getIndex())); + HierarchyElement.Type.QUESTION, fp.getIndex())); } break; case FormEntryController.EVENT_GROUP: @@ -323,7 +318,7 @@ public void refreshView() { HierarchyElement group = new HierarchyElement(getLabel(fc), null, ContextCompat .getDrawable(this, R.drawable.expander_ic_minimized), - COLLAPSED, fc.getIndex()); + HierarchyElement.Type.COLLAPSED, fc.getIndex()); formList.add(group); } String repeatLabel = getLabel(fc); @@ -337,7 +332,7 @@ public void refreshView() { repeatLabel += " (" + (fc.getMultiplicity() + 1) + ")\u200E"; // Add this group name to the drop down list for this repeating group. HierarchyElement h = formList.get(formList.size() - 1); - h.addChild(new HierarchyElement(repeatLabel, null, null, CHILD, fc.getIndex())); + h.addChild(new HierarchyElement(repeatLabel, null, null, HierarchyElement.Type.CHILD, fc.getIndex())); break; } event = @@ -372,7 +367,7 @@ public void onElementClick(HierarchyElement element) { switch (element.getType()) { case EXPANDED: - element.setType(COLLAPSED); + element.setType(HierarchyElement.Type.COLLAPSED); ArrayList children = element.getChildren(); for (int i = 0; i < children.size(); i++) { formList.remove(position + 1); @@ -380,7 +375,7 @@ public void onElementClick(HierarchyElement element) { element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_minimized)); break; case COLLAPSED: - element.setType(EXPANDED); + element.setType(HierarchyElement.Type.EXPANDED); ArrayList children1 = element.getChildren(); for (int i = 0; i < children1.size(); i++) { Timber.i("adding child: %s", children1.get(i).getFormIndex()); diff --git a/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java b/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java index fcca05fe41b..cc1363e0542 100644 --- a/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java +++ b/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java @@ -23,13 +23,13 @@ public class HierarchyElement { private final ArrayList children = new ArrayList<>(); - private int type; + private Type type; private final FormIndex formIndex; private final String primaryText; private final String secondaryText; private Drawable icon; - public HierarchyElement(String primaryText, String secondaryText, Drawable icon, int type, FormIndex formIndex) { + public HierarchyElement(String primaryText, String secondaryText, Drawable icon, Type type, FormIndex formIndex) { this.primaryText = primaryText; this.secondaryText = secondaryText; this.icon = icon; @@ -57,11 +57,11 @@ public FormIndex getFormIndex() { return formIndex; } - public int getType() { + public Type getType() { return type; } - public void setType(int newType) { + public void setType(Type newType) { type = newType; } @@ -72,4 +72,11 @@ public ArrayList getChildren() { public void addChild(HierarchyElement h) { children.add(h); } + + public enum Type { + CHILD, + EXPANDED, + COLLAPSED, + QUESTION; + } } From 5f58bb24583e008734dbf142fce3be4845d63c49 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 11:21:36 -0800 Subject: [PATCH 11/19] Clarify meaning of the element list --- .../activities/FormHierarchyActivity.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index ff73df004ff..e8a78d6145b 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -64,7 +64,12 @@ * Buttons at the bottom of the screen allow users to navigate the form. */ public class FormHierarchyActivity extends CollectAbstractActivity { - List formList; + /** + * The questions and repeats at the current level. If a repeat is expanded, also includes the + * instances of that repeat. Recreated every time {@link #refreshView()} is called. Modified + * by the expand/collapse behavior in {@link #onElementClick(HierarchyElement)}. + */ + private List elementsToDisplay; TextView path; FormIndex startIndex; @@ -115,9 +120,9 @@ public void onCreate(Bundle savedInstanceState) { emptyView.setVisibility(View.GONE); recyclerView.post(() -> { int position = 0; - for (HierarchyElement hierarchyElement : formList) { + for (HierarchyElement hierarchyElement : elementsToDisplay) { if (shouldScrollToTheGivenIndex(hierarchyElement.getFormIndex(), formController)) { - position = formList.indexOf(hierarchyElement); + position = elementsToDisplay.indexOf(hierarchyElement); break; } } @@ -185,7 +190,7 @@ public void refreshView() { // display // everything enclosed within that group. String contextGroupRef = ""; - formList = new ArrayList<>(); + elementsToDisplay = new ArrayList<>(); // If we're currently at a repeat node, record the name of the node and step to the next // node to display. @@ -288,7 +293,7 @@ public void refreshView() { // show the question if it is an editable field. // or if it is read-only and the label is not blank. String answerDisplay = FormEntryPromptUtils.getAnswerText(fp, this, formController); - formList.add( + elementsToDisplay.add( new HierarchyElement(FormEntryPromptUtils.markQuestionIfIsRequired(label, fp.isRequired()), answerDisplay, null, HierarchyElement.Type.QUESTION, fp.getIndex())); } @@ -319,7 +324,7 @@ public void refreshView() { new HierarchyElement(getLabel(fc), null, ContextCompat .getDrawable(this, R.drawable.expander_ic_minimized), HierarchyElement.Type.COLLAPSED, fc.getIndex()); - formList.add(group); + elementsToDisplay.add(group); } String repeatLabel = getLabel(fc); if (fc.getFormElement().getChildren().size() == 1 && fc.getFormElement().getChild(0) instanceof GroupDef) { @@ -331,7 +336,7 @@ public void refreshView() { } repeatLabel += " (" + (fc.getMultiplicity() + 1) + ")\u200E"; // Add this group name to the drop down list for this repeating group. - HierarchyElement h = formList.get(formList.size() - 1); + HierarchyElement h = elementsToDisplay.get(elementsToDisplay.size() - 1); h.addChild(new HierarchyElement(repeatLabel, null, null, HierarchyElement.Type.CHILD, fc.getIndex())); break; } @@ -339,7 +344,7 @@ public void refreshView() { formController.stepToNextEvent(FormController.STEP_INTO_GROUP); } - recyclerView.setAdapter(new HierarchyListAdapter(formList, this::onElementClick)); + recyclerView.setAdapter(new HierarchyListAdapter(elementsToDisplay, this::onElementClick)); // set the controller back to the current index in case the user hits 'back' formController.jumpToIndex(currentIndex); @@ -358,7 +363,7 @@ public void refreshView() { * questions shown */ public void onElementClick(HierarchyElement element) { - int position = formList.indexOf(element); + int position = elementsToDisplay.indexOf(element); FormIndex index = element.getFormIndex(); if (index == null) { goUpLevel(); @@ -370,7 +375,7 @@ public void onElementClick(HierarchyElement element) { element.setType(HierarchyElement.Type.COLLAPSED); ArrayList children = element.getChildren(); for (int i = 0; i < children.size(); i++) { - formList.remove(position + 1); + elementsToDisplay.remove(position + 1); } element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_minimized)); break; @@ -379,7 +384,7 @@ public void onElementClick(HierarchyElement element) { ArrayList children1 = element.getChildren(); for (int i = 0; i < children1.size(); i++) { Timber.i("adding child: %s", children1.get(i).getFormIndex()); - formList.add(position + 1 + i, children1.get(i)); + elementsToDisplay.add(position + 1 + i, children1.get(i)); } element.setIcon(ContextCompat.getDrawable(this, R.drawable.expander_ic_maximized)); @@ -394,7 +399,7 @@ public void onElementClick(HierarchyElement element) { return; } - recyclerView.setAdapter(new HierarchyListAdapter(formList, this::onElementClick)); + recyclerView.setAdapter(new HierarchyListAdapter(elementsToDisplay, this::onElementClick)); ((LinearLayoutManager) recyclerView.getLayoutManager()).scrollToPositionWithOffset(position, 0); } From 65733090aa4e7f0d7bb3682d92edb889bb7fbb60 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 11:27:20 -0800 Subject: [PATCH 12/19] Clarify meaning of path field --- .../activities/FormHierarchyActivity.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index e8a78d6145b..4ee21bb9eec 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -70,7 +70,12 @@ public class FormHierarchyActivity extends CollectAbstractActivity { * by the expand/collapse behavior in {@link #onElementClick(HierarchyElement)}. */ private List elementsToDisplay; - TextView path; + + /** + * The label shown at the top of a hierarchy screen for a repeat instance. Set by + * {@link #getCurrentPath()}. + */ + private TextView groupPathTextView; FormIndex startIndex; private FormIndex currentIndex; @@ -106,7 +111,7 @@ public void onCreate(Bundle savedInstanceState) { setTitle(formController.getFormTitle()); - path = findViewById(R.id.pathtext); + groupPathTextView = findViewById(R.id.pathtext); jumpPreviousButton = findViewById(R.id.jumpPreviousButton); jumpBeginningButton = findViewById(R.id.jumpBeginningButton); @@ -166,6 +171,9 @@ protected void goUpLevel() { refreshView(); } + /** + * Builds a string representing the path of the current group. Each level is separated by a <. + */ private String getCurrentPath() { FormController formController = Collect.getInstance().getFormController(); FormIndex index = formController.getFormIndex(); @@ -232,11 +240,11 @@ public void refreshView() { formController.stepToNextEvent(FormController.STEP_INTO_GROUP); contextGroupRef = formController.getFormIndex().getReference().getParentRef().toString(true); - path.setVisibility(View.GONE); + groupPathTextView.setVisibility(View.GONE); jumpPreviousButton.setEnabled(false); } else { - path.setVisibility(View.VISIBLE); - path.setText(getCurrentPath()); + groupPathTextView.setVisibility(View.VISIBLE); + groupPathTextView.setText(getCurrentPath()); jumpPreviousButton.setEnabled(true); } From 2bd51d9317f3bd9f095601a3e3578726c03283d6 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 11:31:35 -0800 Subject: [PATCH 13/19] Clarify meaning of startIndex field --- .../collect/android/activities/FormHierarchyActivity.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 4ee21bb9eec..446d634f02a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -77,7 +77,12 @@ public class FormHierarchyActivity extends CollectAbstractActivity { */ private TextView groupPathTextView; - FormIndex startIndex; + /** + * The index of the question or the field list the FormController was set to when the hierarchy + * was accessed. Used to jump the user back to where they were if applicable. + */ + private FormIndex startIndex; + private FormIndex currentIndex; protected Button jumpPreviousButton; protected Button jumpBeginningButton; @@ -106,7 +111,6 @@ public void onCreate(Bundle savedInstanceState) { return; } - // We use a static FormEntryController to make jumping faster. startIndex = formController.getFormIndex(); setTitle(formController.getFormTitle()); From beb151de7e3d9dc3c621325a4e25fa5f6f7c3429 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 11:41:39 -0800 Subject: [PATCH 14/19] Explain code that scrolls hierarchy to last edited question --- .../android/activities/FormHierarchyActivity.java | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 446d634f02a..394fe88d97a 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -124,13 +124,18 @@ public void onCreate(Bundle savedInstanceState) { configureButtons(formController); refreshView(); - // Kinda slow, but works. This scrolls to the last question the user was looking at. + // Scroll to the last question the user was looking at + // TODO: avoid another iteration through all displayed elements if (recyclerView != null && recyclerView.getAdapter() != null && recyclerView.getAdapter().getItemCount() > 0) { emptyView.setVisibility(View.GONE); recyclerView.post(() -> { int position = 0; + // Iterate over all the elements currently displayed looking for a match with the + // startIndex which can either represent a question or a field list. for (HierarchyElement hierarchyElement : elementsToDisplay) { - if (shouldScrollToTheGivenIndex(hierarchyElement.getFormIndex(), formController)) { + FormIndex indexToCheck = hierarchyElement.getFormIndex(); + if (startIndex.equals(indexToCheck) + || (formController.indexIsInFieldList(startIndex) && indexToCheck.toString().startsWith(startIndex.toString()))) { position = elementsToDisplay.indexOf(hierarchyElement); break; } @@ -164,11 +169,6 @@ void configureButtons(FormController formController) { }); } - private boolean shouldScrollToTheGivenIndex(FormIndex formIndex, FormController formController) { - return startIndex.equals(formIndex) - || (formController.indexIsInFieldList(startIndex) && formIndex.toString().startsWith(startIndex.toString())); - } - protected void goUpLevel() { Collect.getInstance().getFormController().stepToOuterScreenEvent(); From 2d45af19fabb38c9afd2936bf9c5727d4fc4b04a Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 12:00:13 -0800 Subject: [PATCH 15/19] Explain refreshView and currentIndex The removed comment was incorrect -- startIndex is used when the back button is pressed. --- .../activities/FormHierarchyActivity.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 394fe88d97a..014e7513240 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -58,6 +58,9 @@ * Tapping on a repeat instance shows all the questions in that repeat instance using the display * rules above. * + * Tapping on a question sets the app-wide current question to that question and terminates the + * activity, returning to {@link FormEntryActivity}. + * * Although the user gets the impression of navigating "into" a repeat, the view is refreshed in * {@link #refreshView()} rather than another activity/fragment being added to the backstack. * @@ -83,7 +86,14 @@ public class FormHierarchyActivity extends CollectAbstractActivity { */ private FormIndex startIndex; + /** + * The index of the question that is being displayed in the hierarchy. On first launch, it is + * the same as {@link #startIndex}. It can then become the index of a repeat instance. + * TODO: Is keeping this as a field necessary? I believe what it is used for is to send the user + * to edit a question that caused an error in the hierarchy. + */ private FormIndex currentIndex; + protected Button jumpPreviousButton; protected Button jumpBeginningButton; protected Button jumpEndButton; @@ -192,6 +202,11 @@ private String getCurrentPath() { return ODKView.getGroupsPath(groups.toArray(new FormEntryCaption[groups.size()])); } + /** + * Rebuilds the view to reflect the elements that should be displayed based on the + * FormController's current index. This index is either set prior to the activity opening or + * mutated by {@link #onElementClick(HierarchyElement)} if a repeat instance was tapped. + */ public void refreshView() { try { FormController formController = Collect.getInstance().getFormController(); @@ -358,7 +373,6 @@ public void refreshView() { recyclerView.setAdapter(new HierarchyListAdapter(elementsToDisplay, this::onElementClick)); - // set the controller back to the current index in case the user hits 'back' formController.jumpToIndex(currentIndex); } catch (Exception e) { Timber.e(e); From eabe0ee2cffe37085350a0a120a8045d505ce8cf Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 12:24:58 -0800 Subject: [PATCH 16/19] Comment HierarchyElement class --- .../android/logic/HierarchyElement.java | 65 ++++++++++++++++++- 1 file changed, 62 insertions(+), 3 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java b/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java index cc1363e0542..979a619d7af 100644 --- a/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java +++ b/collect_app/src/main/java/org/odk/collect/android/logic/HierarchyElement.java @@ -15,21 +15,57 @@ package org.odk.collect.android.logic; import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; import org.javarosa.core.model.FormIndex; import java.util.ArrayList; +/** + * Represents a question or repeat to be shown in + * {@link org.odk.collect.android.activities.FormHierarchyActivity}. + */ public class HierarchyElement { + /** + * Repeat instances (always of type {@link Type#CHILD}) if this element is a repeat + * ({@link Type#COLLAPSED} or {@link Type#EXPANDED}). Not relevant otherwise. + */ private final ArrayList children = new ArrayList<>(); + /** + * The type and state of this element. See {@link Type}. + */ + @NonNull private Type type; + + /** + * The form index of this element. + */ + @NonNull private final FormIndex formIndex; + + /** + * The primary text this element should be displayed with. + */ + @NonNull private final String primaryText; + + /** + * The secondary text this element should be displayed with. + */ + @Nullable private final String secondaryText; + + /** + * The collapsed or expanded icon if this element is a repeat ({@link Type#COLLAPSED} or + * {@link Type#EXPANDED}). Not relevant otherwise. + */ + @Nullable private Drawable icon; - public HierarchyElement(String primaryText, String secondaryText, Drawable icon, Type type, FormIndex formIndex) { + public HierarchyElement(@NonNull String primaryText, @Nullable String secondaryText, + @Nullable Drawable icon, @NonNull Type type, @NonNull FormIndex formIndex) { this.primaryText = primaryText; this.secondaryText = secondaryText; this.icon = icon; @@ -37,31 +73,36 @@ public HierarchyElement(String primaryText, String secondaryText, Drawable icon, this.formIndex = formIndex; } + @NonNull public String getPrimaryText() { return primaryText; } + @Nullable public String getSecondaryText() { return secondaryText; } + @Nullable public Drawable getIcon() { return icon; } - public void setIcon(Drawable icon) { + public void setIcon(@Nullable Drawable icon) { this.icon = icon; } + @NonNull public FormIndex getFormIndex() { return formIndex; } + @NonNull public Type getType() { return type; } - public void setType(Type newType) { + public void setType(@NonNull Type newType) { type = newType; } @@ -73,10 +114,28 @@ public void addChild(HierarchyElement h) { children.add(h); } + /** + * The type and state of this element. + */ public enum Type { + /** + * A repeat instance. + */ CHILD, + + /** + * A repeat that should be displayed as expanded. + */ EXPANDED, + + /** + * A repeat that should be displayed as collapsed. + */ COLLAPSED, + + /** + * A question. + */ QUESTION; } } From 2c5a70142c99cebd75cc906f51c188983e7ce940 Mon Sep 17 00:00:00 2001 From: lognaturel Date: Mon, 5 Nov 2018 19:29:01 -0800 Subject: [PATCH 17/19] Remove unreachable null block The @NonNull annotations in HierarchyElement make this impossible. The null check was added in https://github.com/opendatakit/collect/blob/77f4f2eadc5302c9968e9cb332fb090018e9681f/src/org/odk/collect/android/activities/FormHierarchyActivity.java#L308 and I am pretty sure that it was needed only because of the .. entry added with an explicitly null index (https://github.com/opendatakit/collect/blob/77f4f2eadc5302c9968e9cb332fb090018e9681f/src/org/odk/collect/android/activities/FormHierarchyActivity.java#L186) --- .../odk/collect/android/activities/FormHierarchyActivity.java | 4 ---- 1 file changed, 4 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 014e7513240..6768738f7ff 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -391,10 +391,6 @@ public void refreshView() { public void onElementClick(HierarchyElement element) { int position = elementsToDisplay.indexOf(element); FormIndex index = element.getFormIndex(); - if (index == null) { - goUpLevel(); - return; - } switch (element.getType()) { case EXPANDED: From 0657bbf5744afc93d2e1165956a0a26bddb084fb Mon Sep 17 00:00:00 2001 From: Kevin Cooper Date: Mon, 19 Nov 2018 12:59:31 -0500 Subject: [PATCH 18/19] Refactor to prevent audits from ViewOnlyFormHierarchyActivity --- .../activities/FormHierarchyActivity.java | 20 ++++++++++--------- .../ViewOnlyFormHierarchyActivity.java | 4 ++-- 2 files changed, 13 insertions(+), 11 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index 6768738f7ff..c9700616200 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -449,16 +449,18 @@ void onQuestionClicked(FormIndex index) { * level in the hierarchy as the "Go Up" button does. */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - switch (keyCode) { - case KeyEvent.KEYCODE_BACK: - FormController fc = Collect.getInstance().getFormController(); - if (fc != null) { - fc.getTimerLogger().exitView(); - fc.jumpToIndex(startIndex); - } + public void onBackPressed() { + FormController formController = Collect.getInstance().getFormController(); + if (formController != null) { + formController.getTimerLogger().exitView(); + formController.jumpToIndex(startIndex); } - return super.onKeyDown(keyCode, event); + + onBackPressedWithoutLogger(); + } + + protected void onBackPressedWithoutLogger() { + super.onBackPressed(); } /** diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java index 8584d8b3556..e7d9f9a6f57 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java @@ -59,7 +59,7 @@ void onQuestionClicked(FormIndex index) { * Prevents logging an audit event when the user exits the activity. */ @Override - public boolean onKeyDown(int keyCode, KeyEvent event) { - return super.onKeyDown(keyCode, event); + public void onBackPressed() { + onBackPressedWithoutLogger(); } } From 11e26de2cccc2fdc255ff30d071c0836130419b4 Mon Sep 17 00:00:00 2001 From: Shobhit Agarwal Date: Wed, 21 Nov 2018 10:57:57 +0530 Subject: [PATCH 19/19] Remove unused imports --- .../odk/collect/android/activities/FormHierarchyActivity.java | 1 - .../android/activities/ViewOnlyFormHierarchyActivity.java | 1 - 2 files changed, 2 deletions(-) diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java index c9700616200..2cb95a3f750 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/FormHierarchyActivity.java @@ -22,7 +22,6 @@ import android.support.v7.widget.LinearLayoutManager; import android.support.v7.widget.RecyclerView; import android.support.v7.widget.Toolbar; -import android.view.KeyEvent; import android.view.View; import android.widget.Button; import android.widget.TextView; diff --git a/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java b/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java index e7d9f9a6f57..f3017ac6d3d 100644 --- a/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java +++ b/collect_app/src/main/java/org/odk/collect/android/activities/ViewOnlyFormHierarchyActivity.java @@ -14,7 +14,6 @@ package org.odk.collect.android.activities; -import android.view.KeyEvent; import android.view.View; import android.widget.Button;