Search in sources :

Example 21 with StateBundle

use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.

the class BackstackDelegateTest method onCreateRestoresBackstackKeys.

@Test
public void onCreateRestoresBackstackKeys() {
    BackstackDelegate backstackDelegate = new BackstackDelegate(null);
    TestKey testKey = new TestKey("hello");
    final TestKey restoredKey = new TestKey("world");
    ArrayList<Parcelable> restoredKeys = new ArrayList<Parcelable>() {

        {
            add(restoredKey);
        }
    };
    StateBundle stateBundle = new StateBundle();
    stateBundle.putParcelableArrayList(BackstackManager.getHistoryTag(), restoredKeys);
    Mockito.when(savedInstanceState.getParcelable(backstackDelegate.getHistoryTag())).thenReturn(stateBundle);
    backstackDelegate.onCreate(savedInstanceState, null, HistoryBuilder.single(testKey));
    assertThat(backstackDelegate.getBackstack()).isNotNull();
    backstackDelegate.setStateChanger(stateChanger);
    assertThat(backstackDelegate.getBackstack().getHistory()).containsExactly(restoredKey);
}
Also used : ArrayList(java.util.ArrayList) Parcelable(android.os.Parcelable) StateBundle(com.zhuinden.statebundle.StateBundle) Test(org.junit.Test)

Example 22 with StateBundle

use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.

the class BackstackManagerTest method afterClearAndRestorationTheInitialKeysShouldBeRestoredAndNotOverwrittenByRestoredState.

@Test
public void afterClearAndRestorationTheInitialKeysShouldBeRestoredAndNotOverwrittenByRestoredState() {
    TestKey initial = new TestKey("initial");
    TestKey restored = new TestKey("restored");
    ArrayList<Parcelable> history = new ArrayList<>();
    history.add(restored);
    StateBundle stateBundle = new StateBundle();
    stateBundle.putParcelableArrayList(BackstackManager.getHistoryTag(), history);
    BackstackManager backstackManager = new BackstackManager();
    backstackManager.setup(HistoryBuilder.single(initial));
    backstackManager.fromBundle(stateBundle);
    backstackManager.setStateChanger(stateChanger);
    Backstack backstack = backstackManager.getBackstack();
    backstack.goBack();
    assertThat(backstack.getHistory()).isEmpty();
    backstack.setStateChanger(stateChanger, Backstack.INITIALIZE);
    assertThat(backstack.getHistory()).doesNotContain(restored);
    assertThat(backstack.getHistory()).containsExactly(initial);
}
Also used : ArrayList(java.util.ArrayList) Parcelable(android.os.Parcelable) StateBundle(com.zhuinden.statebundle.StateBundle) Test(org.junit.Test)

Example 23 with StateBundle

use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.

the class ViewPresenter method toBundle.

@NonNull
@Override
public final StateBundle toBundle() {
    StateBundle stateBundle = new StateBundle();
    onSave(stateBundle);
    this.stateBundle = new StateBundle(stateBundle);
    return stateBundle;
}
Also used : StateBundle(com.zhuinden.statebundle.StateBundle) NonNull(android.support.annotation.NonNull)

Example 24 with StateBundle

use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.

the class AddOrEditTaskPresenter method toBundle.

public StateBundle toBundle() {
    StateBundle bundle = new StateBundle();
    bundle.putString("title", title);
    bundle.putString("description", description);
    return bundle;
}
Also used : StateBundle(com.zhuinden.statebundle.StateBundle)

Example 25 with StateBundle

use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.

the class TasksPresenter method toBundle.

@Override
@NonNull
public StateBundle toBundle() {
    StateBundle bundle = new StateBundle();
    bundle.putString("FILTERING", filterType.getValue().name());
    return bundle;
}
Also used : StateBundle(com.zhuinden.statebundle.StateBundle) NonNull(android.support.annotation.NonNull)

Aggregations

StateBundle (com.zhuinden.statebundle.StateBundle)25 ServiceTree (com.zhuinden.servicetree.ServiceTree)8 Parcelable (android.os.Parcelable)5 NonNull (android.support.annotation.NonNull)5 Bundleable (com.zhuinden.simplestack.Bundleable)4 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 SparseArray (android.util.SparseArray)1 NodeClearManager (com.example.mortar.nodes.NodeClearManager)1 NodeCreationManager (com.example.mortar.nodes.NodeCreationManager)1 NodeStateManager (com.example.mortar.nodes.NodeStateManager)1 Key (com.zhuinden.simpleservicesexample.application.Key)1 ServiceManager (com.zhuinden.simpleservicesexample.utils.ServiceManager)1 Key (com.zhuinden.simplestackdemonestedstack.application.Key)1 NestSupportServiceManager (com.zhuinden.simplestackdemonestedstack.util.NestSupportServiceManager)1 PreserveTreeScopesStrategy (com.zhuinden.simplestackdemonestedstack.util.PreserveTreeScopesStrategy)1 List (java.util.List)1