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

Used Dialog Fragment to create Remove Group Dialog #3839

Merged
merged 16 commits into from
Jul 21, 2020

Conversation

SaumiaSinghal
Copy link
Contributor

@SaumiaSinghal SaumiaSinghal commented May 17, 2020

Work towards #3612

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

This PR contains the fix for Remove Response Dialog. I tested it.

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

I shifted the creating of Alert Dialog to Dialog Fragment and wrote tests for the same.

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?

No regression risks.

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

nested-repeats.xml would work (nested-repeats.xml.txt)

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

Copy link
Member

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

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

Small naming change! I think the bigger change to how the activity and fragment communicate can come later.

}

public interface DeleteRepeatDialogCallback {
void deleteGroup();
Copy link
Member

Choose a reason for hiding this comment

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

This should be deleteRepeat because it does not apply to general groups.

Copy link
Member

Choose a reason for hiding this comment

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

By the way, the delete_repeat string resource and other related ones are super confusing because they use the word "Group". I think we should change that but it's a separate thing.

@SaumiaSinghal SaumiaSinghal force-pushed the fix_remove_response_dialog branch from bff2d4e to f88d23a Compare June 8, 2020 15:53
@SaumiaSinghal SaumiaSinghal requested a review from lognaturel June 8, 2020 16:21
Copy link
Member

@lognaturel lognaturel left a comment

Choose a reason for hiding this comment

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

ViewModel structure causes activity leak.

@SaumiaSinghal SaumiaSinghal force-pushed the fix_remove_response_dialog branch 2 times, most recently from 85fce01 to b9910e4 Compare June 16, 2020 17:52
@SaumiaSinghal SaumiaSinghal requested a review from lognaturel June 16, 2020 17:52
@lognaturel
Copy link
Member

PMD issue and then this is ready for QA!

@SaumiaSinghal
Copy link
Contributor Author

Hi @lognaturel! Sorry for the pmd issue, just fixed that.

@mmarciniak90
Copy link
Contributor

@SaumiaSinghal I'm a bit confused. Am I right that this fix concerns only Remove Group dialog not to 'Remove Response'? What about Remove response dialog? Will you fix it as described?

Also, Collect crashes when I click on the Remove Group or Cancel button.

@mmarciniak90
Copy link
Contributor

@getodk-bot unlabel "needs testing"

@SaumiaSinghal SaumiaSinghal changed the title Used Dialog Fragment to create Remove Response Dialog Used Dialog Fragment to create Remove Group Dialog Jun 21, 2020
@SaumiaSinghal
Copy link
Contributor Author

SaumiaSinghal commented Jun 21, 2020

Hi @mmarciniak90! Sorry for the confusing title. This PR concerns the Remove Group dialog. But I didn't get any crash on my device when I pressed Remove Group or Cancel button. I tested it on Android 9, and on the emulator as well. Can you attach the form used?

I will open a PR for Remove Response dialog separately.

@SaumiaSinghal SaumiaSinghal force-pushed the fix_remove_response_dialog branch from 622c28f to 14005c4 Compare June 21, 2020 22:31
@mmarciniak90
Copy link
Contributor

Sure @SaumiaSinghal, here is the form: nested-repeats.xml.txt

And it's a stacktrace from Android 9.0
Screenshot from 2020-06-22 08-57-58

@SaumiaSinghal
Copy link
Contributor Author

Hi @mmarciniak90! Can you test again please? Thanks

@mmarciniak90
Copy link
Contributor

@getodk-bot label "needs testing"

@mmarciniak90
Copy link
Contributor

@SaumiaSinghal I can confirm that crash does not occur but right now when I click on 'Remove Group' accepting button, nothing happens. The group which I try to remove is still there.

@getodk-bot unlabel "needs testing"

@SaumiaSinghal
Copy link
Contributor Author

Hi @mmarciniak90! I tested it again and it works on my device.:/ I'm attaching the video of the screen recorder here.

ezgif com-video-to-gif

@mmarciniak90
Copy link
Contributor

@SaumiaSinghal here is my case:
ezgif com-video-to-gif

}

public static class TestActivity extends FragmentActivity implements DeleteRepeatDialogFragment.DeleteRepeatDialogCallback {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lognaturel I changed the tests a little bit so as to avoid using protected scope for callback. I like this approach better than directly approaching the interface in the fragment.

@SaumiaSinghal
Copy link
Contributor Author

Sorry @mmarciniak90! I missed something. Thanks for attaching the gif. I hope it works fine now.
ezgif com-video-to-gif

@kkrawczyk123
Copy link
Contributor

@SaumiaSinghal I have noticed that when following scenario with don't keep activities turned on:

  1. Display Remove group dialog
  2. Minimize Collect
  3. Go back to Collect

crash is visible, stacktrace:
2020-07-08 11:10:13.753 12515-12515/org.odk.collect.android E/AndroidRuntime: FATAL EXCEPTION: main Process: org.odk.collect.android, PID: 12515 java.lang.RuntimeException: Unable to start activity ComponentInfo{org.odk.collect.android/org.odk.collect.android.activities.FormHierarchyActivity}: java.lang.RuntimeException: Cannot create an instance of class org.odk.collect.android.formentry.FormEntryViewModel at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3270) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016) at android.os.Handler.dispatchMessage(Handler.java:107) at android.os.Looper.loop(Looper.java:214) at android.app.ActivityThread.main(ActivityThread.java:7356) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) Caused by: java.lang.RuntimeException: Cannot create an instance of class org.odk.collect.android.formentry.FormEntryViewModel at androidx.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:221) at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:278) at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:106) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185) at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150) at org.odk.collect.android.formentry.repeats.DeleteRepeatDialogFragment.onAttach(DeleteRepeatDialogFragment.java:29) at androidx.fragment.app.Fragment.performAttach(Fragment.java:2672) at androidx.fragment.app.FragmentStateManager.attach(FragmentStateManager.java:263) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1170) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356) at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434) at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497) at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625) at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2571) at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:236) at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:315) at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106) at org.odk.collect.android.activities.CollectAbstractActivity.onCreate(CollectAbstractActivity.java:45) at org.odk.collect.android.activities.FormHierarchyActivity.onCreate(FormHierarchyActivity.java:126) at android.app.Activity.performCreate(Activity.java:7825) at android.app.Activity.performCreate(Activity.java:7814) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:214)  at android.app.ActivityThread.main(ActivityThread.java:7356)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)  Caused by: java.lang.InstantiationException: java.lang.Class<org.odk.collect.android.formentry.FormEntryViewModel> has no zero argument constructor at java.lang.Class.newInstance(Native Method) at androidx.lifecycle.ViewModelProvider$NewInstanceFactory.create(ViewModelProvider.java:219) at androidx.lifecycle.ViewModelProvider$AndroidViewModelFactory.create(ViewModelProvider.java:278)  at androidx.lifecycle.SavedStateViewModelFactory.create(SavedStateViewModelFactory.java:106)  at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:185)  at androidx.lifecycle.ViewModelProvider.get(ViewModelProvider.java:150)  at org.odk.collect.android.formentry.repeats.DeleteRepeatDialogFragment.onAttach(DeleteRepeatDialogFragment.java:29)  at androidx.fragment.app.Fragment.performAttach(Fragment.java:2672)  at androidx.fragment.app.FragmentStateManager.attach(FragmentStateManager.java:263)  at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1170)  at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1356)  at androidx.fragment.app.FragmentManager.moveFragmentToExpectedState(FragmentManager.java:1434)  at androidx.fragment.app.FragmentManager.moveToState(FragmentManager.java:1497)  at androidx.fragment.app.FragmentManager.dispatchStateChange(FragmentManager.java:2625)  at androidx.fragment.app.FragmentManager.dispatchCreate(FragmentManager.java:2571)  at androidx.fragment.app.FragmentController.dispatchCreate(FragmentController.java:236)  at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:315)  at androidx.appcompat.app.AppCompatActivity.onCreate(AppCompatActivity.java:106)  at org.odk.collect.android.activities.CollectAbstractActivity.onCreate(CollectAbstractActivity.java:45)  at org.odk.collect.android.activities.FormHierarchyActivity.onCreate(FormHierarchyActivity.java:126)  at android.app.Activity.performCreate(Activity.java:7825)  at android.app.Activity.performCreate(Activity.java:7814)  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1306)  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3245)  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3409)  at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:83)  at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:135)  at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95)  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2016)  at android.os.Handler.dispatchMessage(Handler.java:107)  at android.os.Looper.loop(Looper.java:214)  at android.app.ActivityThread.main(ActivityThread.java:7356)  at java.lang.reflect.Method.invoke(Native Method)  at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930) 

The crash is not visible for the same scenario and remove response dialog. It is also not visible on master, Could you please take a look?

@SaumiaSinghal SaumiaSinghal force-pushed the fix_remove_response_dialog branch from 9b9c631 to 02f974f Compare July 8, 2020 17:27
@SaumiaSinghal
Copy link
Contributor Author

Hi @kkrawczyk123! Thanks for reporting the crash. It is fixed now. I tested it.

@mmarciniak90
Copy link
Contributor

mmarciniak90 commented Jul 9, 2020

@SaumiaSinghal I have the latest changes and right now removing the group seems to be broken. Could you please take a look?

ezgif com-video-to-gif(1)

@mmarciniak90
Copy link
Contributor

@getodk-bot unlabel "needs testing"

@lognaturel
Copy link
Member

@SaumiaSinghal are you making sure to run the connected tests for repeat removal after you make a change? Are there tests that catch these regressions? If not, please add coverage as you make the fixes to reduce the risk of future regressions.

@SaumiaSinghal
Copy link
Contributor Author

I'm sorry @mmarciniak90 for multiple testings requests. I really hope everything is fine now.

ezgif com-video-to-gif (3)

@mmarciniak90
Copy link
Contributor

@SaumiaSinghal I noticed one more crash.

Repro steps:

  1. Don't keep activities is turned on
  2. User starts form (nested-repeats.xml)
  3. User adds Friend, puts name
  4. User opens 'Remove group' dialog and minimizes
  5. User returns to Collect and clicks Cancel on dialog
  6. User goes to next view and clicks on Add button to add pet
  7. App crashes

Screenshot from 2020-07-14 14-25-17

ezgif com-video-to-gif(1)

@getodk-bot unlabel "needs testing"

@SaumiaSinghal
Copy link
Contributor Author

@mmarciniak90 I fixed the crash, seems like it was because I was using @Inject Analytics in the fragment, and on coming back to the Activity, it was giving NPE. Sorry for the multiple crashes.

fix_crash

@mmarciniak90
Copy link
Contributor

@getodk-bot label "needs testing"

@mmarciniak90
Copy link
Contributor

Tested with success

Verified on Android: 7.0, 8.1, 9.0

Verified cases:

  • rotate Remove This Group dialog on question view
  • rotate Remove This Group dialog on hierarchy view
  • select Cancel and Remove group
  • minimization with Don't keep activities from both views
  • light/ dark mode
  • verified previously described cases which caused crashes
  • verified previously described bugs

@kkrawczyk123
Copy link
Contributor

Verified on Androids 5.1, 7.1 and 10.

@getodk-bot unlabel "needs testing"
@getodk-bot label "behavior verified"

@grzesiek2010 grzesiek2010 merged commit 8e65915 into getodk:master Jul 21, 2020
@SaumiaSinghal SaumiaSinghal deleted the fix_remove_response_dialog branch July 21, 2020 19:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants