Search in sources :

Example 1 with Router

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();
    }
}
Also used : Router(com.bluelinelabs.conductor.Router) MenuItem(android.view.MenuItem) Menu(android.view.Menu) Controller(com.bluelinelabs.conductor.Controller) BaseController(com.nextcloud.talk.controllers.base.BaseController)

Example 2 with Router

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);
}
Also used : FrameLayout(android.widget.FrameLayout) TestController(com.bluelinelabs.conductor.support.util.TestController) Activity(android.app.Activity) Router(com.bluelinelabs.conductor.Router) FakePager(com.bluelinelabs.conductor.support.util.FakePager)

Example 3 with Router

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);
}
Also used : Bundle(android.os.Bundle) Router(com.bluelinelabs.conductor.Router)

Example 4 with Router

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);
        }
    }
}
Also used : ActivityHostedRouter(com.bluelinelabs.conductor.ActivityHostedRouter) Router(com.bluelinelabs.conductor.Router)

Example 5 with Router

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);
}
Also used : Bundle(android.os.Bundle) Router(com.bluelinelabs.conductor.Router) Controller(com.bluelinelabs.conductor.Controller)

Aggregations

Router (com.bluelinelabs.conductor.Router)12 Bundle (android.os.Bundle)5 Controller (com.bluelinelabs.conductor.Controller)4 ActivityHostedRouter (com.bluelinelabs.conductor.ActivityHostedRouter)3 Menu (android.view.Menu)2 MenuItem (android.view.MenuItem)2 RouterTransaction (com.bluelinelabs.conductor.RouterTransaction)2 Activity (android.app.Activity)1 IdRes (android.support.annotation.IdRes)1 ViewGroup (android.view.ViewGroup)1 FrameLayout (android.widget.FrameLayout)1 ControllerChangeHandler (com.bluelinelabs.conductor.ControllerChangeHandler)1 ControllerChangeType (com.bluelinelabs.conductor.ControllerChangeType)1 FadeChangeHandler (com.bluelinelabs.conductor.changehandler.FadeChangeHandler)1 BaseController (com.bluelinelabs.conductor.demo.controllers.base.BaseController)1 FakePager (com.bluelinelabs.conductor.support.util.FakePager)1 TestController (com.bluelinelabs.conductor.support.util.TestController)1 BaseController (com.nextcloud.talk.controllers.base.BaseController)1