Search in sources :

Example 1 with Controller

use of com.bluelinelabs.conductor.Controller in project talk-android by nextcloud.

the class BaseController method setTitle.

protected void setTitle() {
    Controller parentController = getParentController();
    while (parentController != null) {
        if (parentController instanceof BaseController && ((BaseController) parentController).getTitle() != null) {
            return;
        }
        parentController = parentController.getParentController();
    }
    String title = getTitle();
    ActionBar actionBar = getActionBar();
    if (title != null && actionBar != null) {
        actionBar.setTitle(title);
    }
}
Also used : Controller(com.bluelinelabs.conductor.Controller) ActionBar(android.support.v7.app.ActionBar)

Example 2 with Controller

use of com.bluelinelabs.conductor.Controller 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 3 with Controller

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

the class ControllerLifecycleSubjectHelper method create.

public static BehaviorSubject<ControllerEvent> create(Controller controller) {
    ControllerEvent initialState;
    if (controller.isBeingDestroyed() || controller.isDestroyed()) {
        throw new OutsideLifecycleException("Cannot bind to Controller lifecycle when outside of it.");
    } else if (controller.isAttached()) {
        initialState = ControllerEvent.ATTACH;
    } else if (controller.getView() != null) {
        initialState = ControllerEvent.CREATE_VIEW;
    } else if (controller.getActivity() != null) {
        initialState = ControllerEvent.CONTEXT_AVAILABLE;
    } else {
        initialState = ControllerEvent.CREATE;
    }
    final BehaviorSubject<ControllerEvent> subject = BehaviorSubject.create(initialState);
    controller.addLifecycleListener(new LifecycleListener() {

        @Override
        public void preContextAvailable(@NonNull Controller controller) {
            subject.onNext(ControllerEvent.CONTEXT_AVAILABLE);
        }

        @Override
        public void preCreateView(@NonNull Controller controller) {
            subject.onNext(ControllerEvent.CREATE_VIEW);
        }

        @Override
        public void preAttach(@NonNull Controller controller, @NonNull View view) {
            subject.onNext(ControllerEvent.ATTACH);
        }

        @Override
        public void preDetach(@NonNull Controller controller, @NonNull View view) {
            subject.onNext(ControllerEvent.DETACH);
        }

        @Override
        public void preDestroyView(@NonNull Controller controller, @NonNull View view) {
            subject.onNext(ControllerEvent.DESTROY_VIEW);
        }

        @Override
        public void preContextUnavailable(@NonNull Controller controller, @NonNull Context context) {
            subject.onNext(ControllerEvent.CONTEXT_UNAVAILABLE);
        }

        @Override
        public void preDestroy(@NonNull Controller controller) {
            subject.onNext(ControllerEvent.DESTROY);
        }
    });
    return subject;
}
Also used : Context(android.content.Context) OutsideLifecycleException(com.trello.rxlifecycle.OutsideLifecycleException) LifecycleListener(com.bluelinelabs.conductor.Controller.LifecycleListener) Controller(com.bluelinelabs.conductor.Controller) View(android.view.View)

Example 4 with Controller

use of com.bluelinelabs.conductor.Controller 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)

Example 5 with Controller

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

the class TargetTitleEntryController method optionPicked.

@OnClick(R.id.btn_use_title)
void optionPicked() {
    Controller targetController = getTargetController();
    if (targetController != null) {
        ((TargetTitleEntryControllerListener) targetController).onTitlePicked(editText.getText().toString());
        getRouter().popController(this);
    }
}
Also used : Controller(com.bluelinelabs.conductor.Controller) BaseController(com.bluelinelabs.conductor.demo.controllers.base.BaseController) OnClick(butterknife.OnClick)

Aggregations

Controller (com.bluelinelabs.conductor.Controller)9 Router (com.bluelinelabs.conductor.Router)4 Bundle (android.os.Bundle)2 ActionBar (android.support.v7.app.ActionBar)2 BaseController (com.bluelinelabs.conductor.demo.controllers.base.BaseController)2 Context (android.content.Context)1 IdRes (android.support.annotation.IdRes)1 Menu (android.view.Menu)1 MenuItem (android.view.MenuItem)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 OnClick (butterknife.OnClick)1 LifecycleListener (com.bluelinelabs.conductor.Controller.LifecycleListener)1 ControllerChangeHandler (com.bluelinelabs.conductor.ControllerChangeHandler)1 ControllerChangeType (com.bluelinelabs.conductor.ControllerChangeType)1 FadeChangeHandler (com.bluelinelabs.conductor.changehandler.FadeChangeHandler)1 BaseController (com.nextcloud.talk.controllers.base.BaseController)1 BottomNavigationController (com.nextcloud.talk.controllers.base.bottomnavigation.BottomNavigationController)1 OutsideLifecycleException (com.trello.rxlifecycle.OutsideLifecycleException)1 Constructor (java.lang.reflect.Constructor)1