Search in sources :

Example 6 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityBackground.

@Test
public void testLifecycleWithActivityBackground() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)));
    assertCalls(expectedCallState, controller);
    activityProxy.pause();
    Bundle bundle = new Bundle();
    activityProxy.saveInstanceState(bundle);
    expectedCallState.saveInstanceStateCalls++;
    expectedCallState.saveViewStateCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.resume();
    assertCalls(expectedCallState, controller);
}
Also used : Bundle(android.os.Bundle) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 7 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method setup.

@Before
public void setup() {
    createActivityController(null, true);
    currentCallState = new CallState(false);
}
Also used : CallState(com.bluelinelabs.conductor.util.CallState) Before(org.junit.Before)

Example 8 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testChildLifecycle2.

@Test
public void testChildLifecycle2() {
    Controller parent = new TestController();
    router.pushController(RouterTransaction.with(parent).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    TestController child = new TestController();
    attachLifecycleListener(child);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, child);
    Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.setRoot(RouterTransaction.with(child).pushChangeHandler(getPushHandler(expectedCallState, child)).popChangeHandler(getPopHandler(expectedCallState, child)));
    assertCalls(expectedCallState, child);
    router.popCurrentController();
    expectedCallState.detachCalls++;
    expectedCallState.destroyViewCalls++;
    expectedCallState.contextUnavailableCalls++;
    expectedCallState.destroyCalls++;
    assertCalls(expectedCallState, child);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 9 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityConfigurationChange.

@Test
public void testLifecycleWithActivityConfigurationChange() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)).tag("root"));
    assertCalls(expectedCallState, controller);
    activityProxy.getActivity().isChangingConfigurations = true;
    Bundle bundle = new Bundle();
    activityProxy.saveInstanceState(bundle);
    expectedCallState.saveViewStateCalls++;
    expectedCallState.saveInstanceStateCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.pause();
    assertCalls(expectedCallState, controller);
    activityProxy.stop(true);
    expectedCallState.detachCalls++;
    expectedCallState.destroyViewCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.destroy();
    expectedCallState.contextUnavailableCalls++;
    assertCalls(expectedCallState, controller);
    createActivityController(bundle, false);
    controller = (TestController) router.getControllerWithTag("root");
    expectedCallState.contextAvailableCalls++;
    expectedCallState.restoreInstanceStateCalls++;
    expectedCallState.restoreViewStateCalls++;
    expectedCallState.changeStartCalls++;
    expectedCallState.createViewCalls++;
    // Lifecycle listener isn't attached during restore, grab the current views from the controller for this stuff...
    currentCallState.restoreInstanceStateCalls = controller.currentCallState.restoreInstanceStateCalls;
    currentCallState.restoreViewStateCalls = controller.currentCallState.restoreViewStateCalls;
    currentCallState.changeStartCalls = controller.currentCallState.changeStartCalls;
    currentCallState.changeEndCalls = controller.currentCallState.changeEndCalls;
    currentCallState.createViewCalls = controller.currentCallState.createViewCalls;
    currentCallState.attachCalls = controller.currentCallState.attachCalls;
    currentCallState.contextAvailableCalls = controller.currentCallState.contextAvailableCalls;
    assertCalls(expectedCallState, controller);
    activityProxy.start().resume();
    currentCallState.changeEndCalls = controller.currentCallState.changeEndCalls;
    currentCallState.attachCalls = controller.currentCallState.attachCalls;
    expectedCallState.changeEndCalls++;
    expectedCallState.attachCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.resume();
    assertCalls(expectedCallState, controller);
}
Also used : Bundle(android.os.Bundle) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 10 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerTests method testOptionsMenuForChild.

@Test
public void testOptionsMenuForChild() {
    TestController parent = new TestController();
    TestController child = new TestController();
    router.pushController(RouterTransaction.with(parent));
    parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID)).setRoot(RouterTransaction.with(child));
    CallState childExpectedCallState = new CallState(true);
    CallState parentExpectedCallState = new CallState(true);
    // Ensure that calling onCreateOptionsMenu w/o declaring that we have one doesn't do anything
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure calling onCreateOptionsMenu with a menu works
    child.setHasOptionsMenu(true);
    // Ensure it'll still get called back next time onCreateOptionsMenu is called
    router.onCreateOptionsMenu(null, null);
    childExpectedCallState.createOptionsMenuCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we stop getting them when we hide it
    child.setOptionsMenuHidden(true);
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we get the callback them when we un-hide it
    child.setOptionsMenuHidden(false);
    router.onCreateOptionsMenu(null, null);
    childExpectedCallState.createOptionsMenuCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we don't get the callback when we no longer have a menu
    child.setHasOptionsMenu(false);
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Aggregations

CallState (com.bluelinelabs.conductor.util.CallState)15 TestController (com.bluelinelabs.conductor.util.TestController)14 Test (org.junit.Test)14 ViewGroup (android.view.ViewGroup)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)1 LifecycleListener (com.bluelinelabs.conductor.Controller.LifecycleListener)1 Before (org.junit.Before)1