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

Fix #1762: NavigationDrawer cancel switch profile always mark home #1816

Closed

Conversation

prayutsu
Copy link
Contributor

@prayutsu prayutsu commented Sep 5, 2020

Explanation

Fixes #1762
Earlier, always home menu item got marked in the nav menu after canceling the switch profile dialog box. This is now fixed to show the correct corresponding menu item.

Quick Updates-

  • All the newly added test cases are passing on Espresso -
    Screenshot from 2021-01-12 20-32-03

  • All the newly added test cases need to be fixed for robolectric.

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The PR follows the style guide.
  • The PR does not contain any unnecessary auto-generated code from Android Studio.
  • The PR is made from a branch that's not called "develop".
  • The PR is made from a branch that is up-to-date with "develop".
  • The PR's branch is based on "develop" and not on any other branch.
  • The PR is assigned to an appropriate reviewer in both the Assignees and the Reviewers sections.

ezgif com-gif-

@prayutsu
Copy link
Contributor Author

prayutsu commented Sep 5, 2020

@anandwana001 PTAL

Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

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

@prayutsu we need to take a deep look into this why we are having this issue, what sort of things causing this failure and also need to write proper test cases which fails without fix and passes with the fix.

@anandwana001 anandwana001 assigned prayutsu and unassigned anandwana001 Sep 6, 2020
@anandwana001
Copy link
Contributor

anandwana001 commented Sep 10, 2020

@rt4914 Currently, we are facing issues on all test cases regarding NavigationDrawerTestActivityTest and this PR will require to add test cases especially for the navigation drawer.

I think we need to block this PR till we solve #1968 for NavigationDrawerTestActivityTest

@prayutsu
Copy link
Contributor Author

@rt4914 Currently, we are facing issues on all test cases regarding NavigationDrawerTestActivityTest and this PR will require to add test cases especially for the navigation drawer.

I think we need to block this PR till we solve #973 for NavigationDrawerTestActivityTest

Okay, so I'll work on other pending issues then.

@anandwana001
Copy link
Contributor

@prayutsu By the time the test file is getting fixed, you can work on this issue other than writing test cases.
Let me know if you need any help.

@prayutsu
Copy link
Contributor Author

prayutsu commented Sep 19, 2020

@anandwana001 Everything seems to work fine. The only problem is in the last case (please see the video in description) that is Administrator Controls->Switch Profile->Cancel->Rotate Device.
If we don't rotate the device everything seems but just after rotating the phone, switch profile is marked.

@prayutsu
Copy link
Contributor Author

prayutsu commented Sep 19, 2020

@anandwana001 I have updated the video in the description of the PR, please have a look at that.

@anandwana001
Copy link
Contributor

@anandwana001 I have updated the video in the description of the PR, please have a look at that.

That's an issue we have to solve.
Could you please mention what should be the approaches you think we can solve this issue? We can pick a the best one from that. I will also look into this issue today and will update you.

@prayutsu
Copy link
Contributor Author

@anandwana001 I have updated the video in the description of the PR, please have a look at that.

That's an issue we have to solve.
Could you please mention what should be the approaches you think we can solve this issue? We can pick a the best one from that. I will also look into this issue today and will update you.

Sure

@anandwana001
Copy link
Contributor

@prayutsu You need to update the branch with develop before working more on this PR as we had updated the package names.

@prayutsu
Copy link
Contributor Author

@anandwana001 @rt4914 Please have a look.
navigation-drawer-fixed

Copy link
Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Thanks @prayutsu! I really like the new proto usage. Left some comments to see if we can leverage it to make some potential improvements that would have been harder before.

ExitProfileDialogArguments.newBuilder()
.setRestoreLastCheckedMenuItem(restoreLastCheckedMenuItem)
.setIsAdministratorControlsSelected(isAdministratorControlsSelected)
.setLastCheckedMenuItemId(lastCheckedMenuItemId).build()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
.setLastCheckedMenuItemId(lastCheckedMenuItemId).build()
.setLastCheckedMenuItemId(lastCheckedMenuItemId)
.build()

ktlint doesn't enforce this correctly, but continuation for call chains like this should be broken up such that each operation at the same logical "level" should also be at the same syntactical "level" (meaning on its own line in this case).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 291 to 294
NavigationDrawerItem.HOME.value -> 0
NavigationDrawerItem.OPTIONS.value -> 1
NavigationDrawerItem.HELP.value -> 2
NavigationDrawerItem.DOWNLOADS.value -> 3
Copy link
Member

Choose a reason for hiding this comment

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

So now that we're using a proto, could we also use an enum to represent the last checked menu item? That provides type safety vs. passing an integer around.

We may be able to share the draw item enum & the menu item enum as well (e.g. just have 1 proto enum to define both so that we can include it in argument protos).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// The id of the menu item that was checked before the Exit Profile Dialog appears.
int32 last_checked_menu_item_id = 1;
}
Copy link
Member

Choose a reason for hiding this comment

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

Add EOF newline.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Comment on lines 15 to 18
bool is_administrator_controls_selected = 2;

// The id of the menu item that was checked before the Exit Profile Dialog appears.
int32 last_checked_menu_item_id = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to consolidate these into a single value the represents the place from which we opened the exit profile dialog?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


// Represents the arguments associated with ExitProfileDialogFragment.
message ExitProfileDialogArguments {
// The last checked menu item needs to be restored or not.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// The last checked menu item needs to be restored or not.
// Whether the last checked menu item needs to be restored or not.

Ditto elsewhere when documenting booleans.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

// Fragment/Activity or not.
bool is_administrator_controls_selected = 2;

// The id of the menu item that was checked before the Exit Profile Dialog appears.
Copy link
Member

Choose a reason for hiding this comment

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

Menu item from where? Suggest being specific here.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

mentioned menu item from Navigation Drawer.


// Represents the arguments associated with ExitProfileDialogFragment.
message ExitProfileDialogArguments {
// The last checked menu item needs to be restored or not.
Copy link
Member

Choose a reason for hiding this comment

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

This documentation comment overall may benefit from more context: what does 'restore' mean & what menu is being described here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Provided more context on what does restore actually mean.

option java_package = "org.oppia.android.app.model";
option java_multiple_files = true;

// Represents the arguments associated with ExitProfileDialogFragment.
Copy link
Member

Choose a reason for hiding this comment

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

Suggest instead: The fragment arguments passed to instances of ExitProfileDialogFragment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@BenHenning BenHenning assigned prayutsu and unassigned BenHenning Feb 4, 2021
Copy link
Contributor Author

@prayutsu prayutsu left a comment

Choose a reason for hiding this comment

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

PTAL @BenHenning, I have tried making some changes, and I need some good name suggestions as mentioned below.

package org.oppia.android.app.drawer

sealed class Argument {
class LastCheckedMenuItem(val navigationDrawerItem: NavigationDrawerItem) : Argument()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need suggestion for a better name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also, please suggest a good KDoc.

3 -> NavigationDrawerItem.DOWNLOADS
4 -> NavigationDrawerItem.SWITCH_PROFILE
else -> NavigationDrawerItem.HOME
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How should we handle else branch here?

}

enum LastCheckedMenuItem {
HOME_MENU_ITEM_UNSPECIFIED = 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Need suggestion for the documentation comment.

@prayutsu prayutsu assigned BenHenning and unassigned prayutsu Feb 5, 2021
3 -> NavigationDrawerItem.DOWNLOADS
4 -> NavigationDrawerItem.SWITCH_PROFILE
else -> NavigationDrawerItem.HOME
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

How should we handle else branch here?

)
else -> Argument.LastCheckedMenuItem(
getNavigationDrawerItem(
exitProfileDialogArguments.lastCheckedMenuItemValue
Copy link
Contributor Author

@prayutsu prayutsu Feb 5, 2021

Choose a reason for hiding this comment

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

Should we create a constant with value - 2, so that it looks cleaner and expressive?
Or do we have a better way to handle it?

@chrk2205
Copy link
Contributor

chrk2205 commented Feb 7, 2021

@prayutsu @BenHenning @rt4914 @anandwana001
For this bug, we can check the previous marked item and mark it whenever the cancel is clicked

I tried to solve this bug,
In the markMenuCloseDrawer() we can simply mark the previously selected item by using this function
if (previousMenuItemId != null) { val k: Int = previousMenuItemId!! if (k == 0) { getFooterViewModel().isAdministratorControlsSelected.set(true) binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.SWITCH_PROFILE.ordinal ).isChecked = false drawerLayout.closeDrawers() } else { binding.fragmentDrawerNavView.menu.getItem( NavigationDrawerItem.valueFromNavId(k).ordinal ).isChecked = true drawerLayout.closeDrawers() } }

with this solution issue #2650 will not arise
thanks

@prayutsu
Copy link
Contributor Author

prayutsu commented Feb 7, 2021

@chrk2205 I think this works really well, and now I am thinking that we were passing arguments from the NavigationDrawerFragmentPresenter to the ExitProfileDialogFragment and then again passing it to NavigationDrawerFragmentPresenter, which actually doesn't make sense as we already have our information in the NavigationDrawerFragmentPresenter. We should just invoke the function and give it a more meaningful name.
However, this doesn't solve the issue completely and we'll still need to make some changes to avoid some more bugs.

Screenrecorder-2021-02-08-00-14-47-901.mp4
  1. When we click outside the dialog box, then the dialog box disappears and Switch Profile remains checked. And now there are 2 possibilities -

    • We may not want the dialog box to disappear on clicking outside, then this can be easily handled.
    • If we want the dialog box to disappear on clicking outside the dialog box, then we may want to trigger the same behavior as the cancel button.
      Note that this issue is present in the current implementation also.
  2. If we go to Administrator Controls, the open NavDrawer, then click on Switch Profile and then change the configuration, then Administrator Controls also get checked. If we click the cancel button, then also it remains checked.

    • We'll need to figure out a good strategy to do this, as this can be a little tricky.
      Note that this issue is not present in the current implementation.
  3. We also want to make sure that whenever we isAdministratorControlsSelected is set to true, we should make all the other menuItems uncheckable.

  4. We'll also be required to give the variables good names.

@BenHenning WDYT?

@rt4914 rt4914 self-assigned this Feb 8, 2021
@chrk2205
Copy link
Contributor

chrk2205 commented Feb 8, 2021

@prayutsu
for Bug 1
you can use setCancelable=false to stop the alert dialog from closing on the background click
If this doesn't work the alternative is to use the onDestroy function to mark the previous item instead of onNegativButtonClicked

@prayutsu
Copy link
Contributor Author

prayutsu commented Feb 8, 2021

@chrk2205 I guess we'll have to use setCanceledOnTouchOutside(false), I guess this is not hard, but the second bug is a bit tricky.

@rt4914
Copy link
Contributor

rt4914 commented Feb 8, 2021

@chrk2205 Your suggestions does sound correct too. @prayutsu Can you try to optimise as per his suggestions?

@rt4914 rt4914 removed their assignment Feb 8, 2021
Copy link
Member

@BenHenning BenHenning left a comment

Choose a reason for hiding this comment

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

Took a high-level pass @prayutsu. I think I need some clarification on the desired behavior before I can go further thoughts on the specifics.

message ExitProfileDialogArguments {
// Whether the last checked navigation drawer menu item needs to be restored(highlighted) or
// not after cancelling the Exit Profile Dialog.
bool restore_last_checked_menu_item = 1;
Copy link
Member

Choose a reason for hiding this comment

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

Can this be true if admin_controls_or_nav_drawer_items is not of type last_checked_menu_item? Can you enumerate via a reply all the different behaviors we expect to be supported by this proto? I think that will better help me understand if it's structured in a way that can satisfy those requirements.

@@ -0,0 +1,6 @@
package org.oppia.android.app.drawer

sealed class Argument {
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need a sealed class if we have a proto with a oneof? That should satisfy the same need.

@BenHenning
Copy link
Member

Re: the discussion, I think it's preferable to keep the tab state management in the navigation drawer itself as much as possible. However given the issues around the drawer not knowing if navigation succeeded, I think we need some way to confirm the navigation before changing the status.

@BenHenning BenHenning assigned prayutsu and unassigned BenHenning Feb 8, 2021
@prayutsu
Copy link
Contributor Author

prayutsu commented Feb 9, 2021

@rt4914 As there are a lot of changes that need to be reverted, should I consider making a new PR?

@rt4914
Copy link
Contributor

rt4914 commented Feb 9, 2021

@rt4914 As there are a lot of changes that need to be reverted, should I consider making a new PR?

@prayutsu Yeah sure.

@prayutsu
Copy link
Contributor Author

prayutsu commented Feb 9, 2021

Closing this PR as created a new PR simplifying the implementation #2671

@prayutsu prayutsu closed this Feb 9, 2021
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.

NavigationDrawer cancel switch profile always mark home
7 participants