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

Menu buttons for FormHierarchy #2763

Merged
merged 23 commits into from
Jan 23, 2019
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
1bd5b54
Create stub options menu for FormHierarchy
cooperka Nov 14, 2018
986f1ab
Add 'add' button
cooperka Nov 14, 2018
e494465
Add 'go up' button
cooperka Nov 14, 2018
0c82a13
Factor out static createDeleteRepeatConfirmDialog util
cooperka Nov 16, 2018
57d2b3c
Add 'delete' button
cooperka Nov 18, 2018
f3a3713
Use ?iconColor for new icon fills
cooperka Nov 19, 2018
8e6ba71
Never show add/delete buttons on ViewOnlyFormHierarchy
cooperka Nov 20, 2018
25a6c43
Don't show delete button while picker is active
cooperka Nov 27, 2018
7dcbd7d
Make sure 'go up' icon is always second from the edge
cooperka Nov 27, 2018
4b65181
Make 'up' arrow thicker like the 'jump' arrow
cooperka Nov 27, 2018
02c1647
Clean up form_hierarchy_menu formatting
cooperka Dec 17, 2018
dc963a4
Fix a few PMD rule violations
cooperka Dec 17, 2018
6951d48
Fix unintentionally overloaded method name
cooperka Dec 17, 2018
c48fbde
PR fix: Clean up menu button toggling logic
cooperka Jan 10, 2019
2b93931
PR fix: Clarify getRepeatPromptIndex logic
cooperka Jan 10, 2019
c6cb175
PR fix: Rename showDeleteRepeatConfirmDialog
cooperka Jan 10, 2019
6b6fd8d
PR fix: Clean up screenIndex == null logic
cooperka Jan 10, 2019
4b77e0a
PR fix: More accurately detect beginning of form
cooperka Jan 16, 2019
f9da285
Use screenIndex instead of currIndex to detect beginning
cooperka Jan 18, 2019
48629a6
Handle deleting last indexed repeat group item
cooperka Jan 20, 2019
7955b3d
Handle deleting last remaining repeat group item
cooperka Jan 21, 2019
35cd0b1
Fix crash when trying to get ref to end of form
cooperka Jan 22, 2019
2182652
Check isGroupSizeLocked before showing add/delete buttons
cooperka Jan 22, 2019
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
Prev Previous commit
Next Next commit
Handle deleting last remaining repeat group item
Now that it's possible to see the repeat picker in this state,
due to the last commit.
  • Loading branch information
cooperka committed Jan 23, 2019
commit 7955b3d321fc7afaf0178bad5121481ba52558d3
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,17 @@ public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.menu_delete_child:
DialogUtils.showDeleteRepeatConfirmDialog(this, () -> {
goUpLevel();
if (didDeleteLastRepeatItem()) {
// goUpLevel would put us in a weird state after deleting the last item;
// just go back one event instead.
//
// TODO: This works well in most cases, but if there are 2 repeats in a row,
// and you delete an item from the second repeat, it will send you into the
// first repeat instead of going back a level as expected.
goToPreviousEvent();
} else {
goUpLevel();
}
}, null);
return true;

Expand Down Expand Up @@ -291,6 +301,39 @@ void configureButtons(FormController formController) {
});
}

/**
* After having deleted the current index,
* returns true if the current index was the only item in the repeat group.
*/
private boolean didDeleteLastRepeatItem() {
FormController formController = Collect.getInstance().getFormController();
FormIndex index = formController.getFormIndex();
int event = formController.getEvent(index);

// If we're on item 0, but we will be prompted to add another item next,
// it must be the last remaining item.
return event == FormEntryController.EVENT_PROMPT_NEW_REPEAT
&& index.getElementMultiplicity() == 0;
}

/**
* Similar to {@link #goUpLevel}, but makes a less significant step backward.
* This is only used when the caller knows where to go back to,
* e.g. after deleting the final remaining item in a repeat group.
*/
private void goToPreviousEvent() {
FormController formController = Collect.getInstance().getFormController();
try {
formController.stepToPreviousScreenEvent();
} catch (JavaRosaException e) {
Timber.d(e);
createErrorDialog(e.getCause().getMessage());
return;
}

refreshView();
}

/**
* Navigates "up" in the form hierarchy.
*/
Expand Down