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

FormHierarchy cleanup #2730

Merged
merged 19 commits into from
Nov 21, 2018

Conversation

lognaturel
Copy link
Member

@smoyth and @cooperka have let me know that they are interested in taking on #809 which @smoyth wrote a spec for, approved by the TSC. @shobhitagarwal1612 had previously built a prototype at #1271.

A big challenge is that the code is structured in unexpected ways. This PR performs some cleanup and documents the current structure (which will hopefully be changed soon).

Most commits are just moving things around or adding comments. I added commit details to describe my reasoning on bigger changes. In particular, 914ca44 and 2c5a701 may present some risk. @grzesiek2010, that first one was introduced in 029afa3 so maybe you have some memory of why.

What has been done to verify that this works as intended?

Filled out All Widgets and groups-repeats.xml.txt forms, jumped at different points in the form and particular into and from repeats. Sent the finalized forms and did the same from View Sent Form (view-only variant of the hierarchy).

Why is this the best possible solution? Were any other approaches considered?

A potentially slightly controversial refactor is in commits a563e99 to 9280d8d: I change the split between a hierarchy view that allows edits and one that doesn't. The prior split wasn't ideal because there was a lot of redundancy which made it hard to see what was different between the two. It also separated the really important click handler from the rest of the implementation. The approach I took was to introduce some methods which could be overridden to block all edit behavior. I think that makes it very clear what the view-only behavior is.

The possibly risky commits 914ca44 and 2c5a701 could be omitted. I included them because they really seemed like unnecessary code.

How does this change affect users? Describe intentional changes to behavior and behavior that could have accidentally been affected by code changes. In other words, what are the regression risks?

There should be no changes for the user. The biggest sources of risk are:

  • I changed the split between editable and view-only hierarchy activities so there could be some error there
  • I took out code to jump to the top of the hierarchy when opening the read-only view. I can't think of a way for that not to be the case by default
  • I took out a check for a null index when the user clicks on a row. Again, I can't imagine a case where that would happen.

Do we need any specific form for testing your changes? If so, please attach one.

No.

Does this change require updates to documentation? If so, please file an issue here and include the link below.

No.

Before submitting this PR, please make sure you have:

  • run ./gradlew checkAll and confirmed all checks still pass OR confirm CircleCI build passes and run ./gradlew connectedDebugAndroidTest locally.
  • verified that any code or assets from external sources are properly credited in comments and/or in the about file.
  • verified that any new UI elements use theme colors. UI Components Style guidelines

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.
The removed comment was incorrect -- startIndex is used when the back button is pressed.
@cooperka
Copy link
Contributor

cooperka commented Nov 7, 2018

This cleanup is extremely helpful, thank you @lognaturel! Reading your commits is like reading a book 📖

@smoyte
Copy link

smoyte commented Nov 7, 2018

LOL. A real page turner! I couldn't put it down! "Lyrical, incisive, and downright witty, Martin expertly leads us through a gauntlet of code smells and anti-patterns in one of the most engaging pull requests in recent memory."

Copy link
Contributor

@shobhitagarwal1612 shobhitagarwal1612 left a comment

Choose a reason for hiding this comment

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

Everything looks so clean and well defined. The commit messages were really helpful to quickly understand the changes without much effort.

I noticed a small bug with the help of the comments that should be easy to fix. Thanks for adding those comments everywhere @lognaturel!

*/
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
return super.onKeyDown(keyCode, event);
Copy link
Contributor

@shobhitagarwal1612 shobhitagarwal1612 Nov 8, 2018

Choose a reason for hiding this comment

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

Calling the super method would call FormHierarchyActivity's onKeyDown(), resulting in logging of an audit event.
We can add a check for determining whether the activity is ViewOnlyFormHierarchyActivity or not by using local variable or using instanceOf.

Overriding onBackPressed() instead of onKeyDown() since we are only tracking the back button can further simplify the readability of code

Copy link
Contributor

Choose a reason for hiding this comment

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

@shobhitagarwal1612 since lognaturel is out I made this fix here: cooperka@a6d1843

I can't push to her branch but I assume you can as a Member.

git remote add cooperka https://github.com/cooperka/collect.git
git fetch cooperka
git cherry-pick a6d1843

if (index == null) {
goUpLevel();
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Removing this null check looks safe to me too.

@@ -39,8 +39,6 @@
*/
@Override
void configureButtons(FormController formController) {
formController.stepToOuterScreenEvent();
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@shobhitagarwal1612 shobhitagarwal1612 merged commit 5d2a69c into getodk:master Nov 21, 2018
@lognaturel
Copy link
Member Author

Thanks, all!

@lognaturel lognaturel deleted the form-hierarchy-cleanup branch November 27, 2018 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants