diff --git a/app/src/main/java/com/nextcloud/talk/controllers/MagicBottomNavigationController.java b/app/src/main/java/com/nextcloud/talk/controllers/MagicBottomNavigationController.java index 11a400a4e..50d03bf3f 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/MagicBottomNavigationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/MagicBottomNavigationController.java @@ -73,15 +73,4 @@ public class MagicBottomNavigationController extends BottomNavigationController } return controller; } - - /** - * Supplied Controller must match a MenuItemId as defined in {@link BottomNavigationMenuItem} or - * an {@link IllegalArgumentException} will be thrown. - * - * @param controller - */ - public void navigateTo(Controller controller) { - BottomNavigationMenuItem item = BottomNavigationMenuItem.getEnum(controller.getClass()); - navigateTo(item.getMenuResId(), controller); - } } diff --git a/app/src/main/java/com/nextcloud/talk/controllers/base/bottomnavigation/BottomNavigationController.java b/app/src/main/java/com/nextcloud/talk/controllers/base/bottomnavigation/BottomNavigationController.java index d50de6adb..4ff920a46 100644 --- a/app/src/main/java/com/nextcloud/talk/controllers/base/bottomnavigation/BottomNavigationController.java +++ b/app/src/main/java/com/nextcloud/talk/controllers/base/bottomnavigation/BottomNavigationController.java @@ -123,6 +123,20 @@ public abstract class BottomNavigationController extends BaseController { /* Setup the BottomNavigationView with the constructor supplied Menu resource */ bottomNavigationView.inflateMenu(getMenuResource()); + bottomNavigationView.setOnNavigationItemSelectedListener( + new BottomNavigationView.OnNavigationItemSelectedListener() { + @Override + public boolean onNavigationItemSelected(@NonNull MenuItem item) { + navigateTo(item.getItemId(), getControllerFor(item.getItemId())); + return true; + } + }); + } + + @Override + protected void onAttach(@NonNull View view) { + super.onAttach(view); + /* Fresh start, setup everything */ if (routerSavedStateBundles == null) { Menu menu = bottomNavigationView.getMenu(); @@ -154,21 +168,6 @@ public abstract class BottomNavigationController extends BaseController { childRouter.rebindIfNeeded(); lastActiveChildRouter = childRouter; } - - bottomNavigationView.setOnNavigationItemSelectedListener( - new BottomNavigationView.OnNavigationItemSelectedListener() { - @Override - public boolean onNavigationItemSelected(@NonNull MenuItem item) { - if (currentlySelectedItemId != item.getItemId()) { - BottomNavigationController.this.destroyChildRouter(BottomNavigationController.this.getChildRouter(currentlySelectedItemId), currentlySelectedItemId); - currentlySelectedItemId = item.getItemId(); - BottomNavigationController.this.configureRouter(BottomNavigationController.this.getChildRouter(currentlySelectedItemId), currentlySelectedItemId); - } else { - BottomNavigationController.this.resetCurrentBackstack(); - } - return true; - } - }); } /** @@ -219,11 +218,9 @@ public abstract class BottomNavigationController extends BaseController { * BottomNavigationController#getControllerFor(int)}, using a {@link FadeChangeHandler}. */ protected void resetCurrentBackstack() { - if (lastActiveChildRouter != null) { - lastActiveChildRouter.setRoot(RouterTransaction.with(this.getControllerFor(currentlySelectedItemId)) - .pushChangeHandler(new FadeChangeHandler()) - .popChangeHandler(new FadeChangeHandler())); - } + lastActiveChildRouter.setRoot(RouterTransaction.with(this.getControllerFor(currentlySelectedItemId)) + .pushChangeHandler(new FadeChangeHandler()) + .popChangeHandler(new FadeChangeHandler())); } /** @@ -350,7 +347,7 @@ public abstract class BottomNavigationController extends BaseController { * The childRouter should handleBack, * as this BottomNavigationController doesn't have a back step sensible to the user. */ - return lastActiveChildRouter != null && lastActiveChildRouter.handleBack(); + return lastActiveChildRouter.handleBack(); } /**