Search in sources :

Example 1 with ControllerChangeType

use of com.bluelinelabs.conductor.ControllerChangeType in project Conductor by bluelinelabs.

the class ParentController method addChild.

private void addChild(final int index) {
    @IdRes final int frameId = getResources().getIdentifier("child_content_" + (index + 1), "id", getActivity().getPackageName());
    final ViewGroup container = (ViewGroup) getView().findViewById(frameId);
    final Router childRouter = getChildRouter(container).setPopsLastView(true);
    if (!childRouter.hasRootController()) {
        ChildController childController = new ChildController("Child Controller #" + index, ColorUtil.getMaterialColor(getResources(), index), false);
        childController.addLifecycleListener(new LifecycleListener() {

            @Override
            public void onChangeEnd(@NonNull Controller controller, @NonNull ControllerChangeHandler changeHandler, @NonNull ControllerChangeType changeType) {
                if (!isBeingDestroyed()) {
                    if (changeType == ControllerChangeType.PUSH_ENTER && !hasShownAll) {
                        if (index < NUMBER_OF_CHILDREN - 1) {
                            addChild(index + 1);
                        } else {
                            hasShownAll = true;
                        }
                    } else if (changeType == ControllerChangeType.POP_EXIT) {
                        if (index > 0) {
                            removeChild(index - 1);
                        } else {
                            getRouter().popController(ParentController.this);
                        }
                    }
                }
            }
        });
        childRouter.setRoot(RouterTransaction.with(childController).pushChangeHandler(new FadeChangeHandler()).popChangeHandler(new FadeChangeHandler()));
    }
}
Also used : ControllerChangeHandler(com.bluelinelabs.conductor.ControllerChangeHandler) FadeChangeHandler(com.bluelinelabs.conductor.changehandler.FadeChangeHandler) IdRes(android.support.annotation.IdRes) ViewGroup(android.view.ViewGroup) ControllerChangeType(com.bluelinelabs.conductor.ControllerChangeType) Router(com.bluelinelabs.conductor.Router) Controller(com.bluelinelabs.conductor.Controller) BaseController(com.bluelinelabs.conductor.demo.controllers.base.BaseController)

Aggregations

IdRes (android.support.annotation.IdRes)1 ViewGroup (android.view.ViewGroup)1 Controller (com.bluelinelabs.conductor.Controller)1 ControllerChangeHandler (com.bluelinelabs.conductor.ControllerChangeHandler)1 ControllerChangeType (com.bluelinelabs.conductor.ControllerChangeType)1 Router (com.bluelinelabs.conductor.Router)1 FadeChangeHandler (com.bluelinelabs.conductor.changehandler.FadeChangeHandler)1 BaseController (com.bluelinelabs.conductor.demo.controllers.base.BaseController)1