Skip to content

Commit

Permalink
fix: Correct selection of menu item in Navigation drawer (#1416)
Browse files Browse the repository at this point in the history
  • Loading branch information
kush-mish authored and iamareebjamal committed Jan 6, 2019
1 parent 32fcb1f commit 712aa5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,14 @@ public void setEventId(long eventId) {
this.eventId = eventId;
}

void back() {
int back() {
int count = fragmentManager.getBackStackEntryCount();
fragmentManager.popBackStack();
lastSelectedNavItemId = R.id.nav_dashboard;
dashboardActive = true;
if(count == 1) {
lastSelectedNavItemId = R.id.nav_dashboard;
dashboardActive = true;
}
return lastSelectedNavItemId;
}

@SuppressWarnings({"PMD.CyclomaticComplexity", "PMD.StdCyclomaticComplexity"})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ public void onBackPressed() {
else if (eventId == -1)
finish();
else {
fragmentNavigator.back();
binding.navView.getMenu().findItem(R.id.nav_dashboard).setChecked(true);
getSupportActionBar().setTitle(R.string.dashboard);
int lastSelectedNavItemId = fragmentNavigator.back();
binding.navView.getMenu().findItem(lastSelectedNavItemId).setChecked(true);
getSupportActionBar().setTitle(lastSelectedNavItemId);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public void testBack() {

inOrder.verify(fragmentManager).popBackStack();

when(fragmentManager.getBackStackEntryCount()).thenReturn(1);

fragmentNavigator.back();

assertTrue(fragmentNavigator.isDashboardActive());
Expand Down

0 comments on commit 712aa5b

Please sign in to comment.