use of com.bluelinelabs.conductor.Router in project talk-android by nextcloud.
the class BottomNavigationController method navigateTo.
/**
* Navigate to the supplied {@link Controller}, while setting the menuItemId as selected on the
* {@link BottomNavigationView}.
*
* @param itemId {@link MenuItem} ID
* @param controller {@link Controller} matching the itemId
*/
protected void navigateTo(int itemId, @NonNull Controller controller) {
if (currentlySelectedItemId != itemId) {
destroyChildRouter(lastActiveChildRouter, currentlySelectedItemId);
/* Ensure correct Checked state based on new selection */
Menu menu = bottomNavigationView.getMenu();
for (int i = 0; i < menu.size(); i++) {
MenuItem menuItem = menu.getItem(i);
if (menuItem.isChecked() && menuItem.getItemId() != itemId) {
menuItem.setChecked(false);
} else if (menuItem.getItemId() == itemId) {
menuItem.setChecked(true);
}
}
currentlySelectedItemId = itemId;
Router childRouter = getChildRouter(currentlySelectedItemId);
if (configureRouter(childRouter, currentlySelectedItemId)) {
/* Determine if a Controller of same class already exists in the backstack */
Controller backstackController;
int size = childRouter.getBackstackSize();
for (int i = 0; i < size; i++) {
backstackController = childRouter.getBackstack().get(i).controller();
if (BottomNavigationUtils.equals(backstackController.getClass(), controller.getClass())) {
/* Match found at root - so just set new root */
if (i == size - 1) {
childRouter.setRoot(RouterTransaction.with(controller));
} else {
/* Match found at i - pop until we're at the matching Controller */
for (int j = size; j < i; j--) {
childRouter.popCurrentController();
}
/* Replace the existing matching Controller with the new */
childRouter.replaceTopController(RouterTransaction.with(controller));
}
}
}
}
} else {
resetCurrentBackstack();
}
}
use of com.bluelinelabs.conductor.Router in project Conductor by bluelinelabs.
the class StateSaveTests method createActivityController.
public void createActivityController(Bundle savedInstanceState) {
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
Router router = Conductor.attachRouter(activityController.get(), new FrameLayout(activityController.get()), savedInstanceState);
TestController controller = new TestController();
router.setRoot(RouterTransaction.with(controller));
pager = new FakePager(new FrameLayout(activityController.get()));
pager.setOffscreenPageLimit(1);
pagerAdapter = new RouterPagerAdapter(controller) {
@Override
public void configureRouter(@NonNull Router router, int position) {
if (!router.hasRootController()) {
router.setRoot(RouterTransaction.with(new TestController()));
}
}
@Override
public int getCount() {
return 20;
}
};
pager.setAdapter(pagerAdapter);
}
use of com.bluelinelabs.conductor.Router in project Conductor by bluelinelabs.
the class RouterPagerAdapter method destroyItem.
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Router router = (Router) object;
Bundle savedState = new Bundle();
router.saveInstanceState(savedState);
savedPages.put(position, savedState);
savedPageHistory.remove((Integer) position);
savedPageHistory.add(position);
ensurePagesSaved();
host.removeChildRouter(router);
visibleRouters.remove(position);
}
use of com.bluelinelabs.conductor.Router in project Conductor by bluelinelabs.
the class LifecycleHandler method onActivityResult.
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
String instanceId = activityRequestMap.get(requestCode);
if (instanceId != null) {
for (Router router : getRouters()) {
router.onActivityResult(instanceId, requestCode, resultCode, data);
}
}
}
use of com.bluelinelabs.conductor.Router in project Conductor by bluelinelabs.
the class ControllerPagerAdapter method destroyItem.
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
Router router = ((Controller) object).getRouter();
if (savesState) {
Bundle savedState = new Bundle();
router.saveInstanceState(savedState);
savedPages.put(position, savedState);
}
visiblePageIds.remove(position);
host.removeChildRouter(router);
}
Aggregations