use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class CloudSyncView method toBundle.
@Override
public StateBundle toBundle() {
StateBundle bundle = new StateBundle();
bundle.putString("HELLO", "WORLD");
StateBundle innerBundle = new StateBundle();
innerBundle.putString("KAPPA", "KAPPA");
bundle.putBundle("GOOMBA", innerBundle);
return bundle;
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class NestSupportServiceManager method setupServices.
public void setupServices(StateChange stateChange, boolean isFromCompositeKey) {
StateBundle states = serviceTree.getNode(rootKey).getService(SERVICE_STATES);
for (Object _previousKey : stateChange.getPreviousState()) {
Key previousKey = (Key) _previousKey;
if (!stateChange.getNewState().contains(previousKey)) {
activeKeys.remove(previousKey);
if (!isFromCompositeKey) {
ServiceTree.Node previousNode = serviceTree.getNode(previousKey);
if (states != null) {
serviceTree.traverseSubtree(previousNode, ServiceTree.Walk.POST_ORDER, (node, cancellationToken) -> {
states.remove(node.getKey().toString());
});
}
serviceTree.removeNodeAndChildren(previousNode);
}
}
}
for (Object _newKey : stateChange.getNewState()) {
Key newKey = (Key) _newKey;
activeKeys.remove(newKey);
if (newKey == stateChange.topNewState()) {
activeKeys.add(newKey);
}
if (!isFromCompositeKey) {
buildServices(states, newKey);
}
}
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class NodeStateManager method clearStatesForKey.
public void clearStatesForKey(Object previousKey) {
final StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
serviceTree.traverseSubtree(serviceTree.getNode(previousKey), ServiceTree.Walk.POST_ORDER, new ServiceTree.Walk() {
@Override
public void execute(@NonNull ServiceTree.Node node, @NonNull CancellationToken cancellationToken) {
Log.i(TAG, "Removing state for [" + node.getKey().toString() + "]");
rootBundle.remove(node.getKey().toString());
}
});
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class BackstackManager method toBundle.
/**
* Persists the backstack history and view state into a StateBundle.
*
* @return the state bundle
*/
@NonNull
@Override
public StateBundle toBundle() {
StateBundle stateBundle = new StateBundle();
ArrayList<Parcelable> history = new ArrayList<>();
for (Object key : backstack.getHistory()) {
history.add(keyParceler.toParcelable(key));
}
stateBundle.putParcelableArrayList(getHistoryTag(), history);
ArrayList<ParcelledState> states = new ArrayList<>();
for (SavedState savedState : keyStateMap.values()) {
ParcelledState parcelledState = new ParcelledState();
parcelledState.parcelableKey = keyParceler.toParcelable(savedState.getKey());
parcelledState.viewHierarchyState = savedState.getViewHierarchyState();
parcelledState.bundle = savedState.getBundle();
states.add(parcelledState);
}
stateBundle.putParcelableArrayList(getStatesTag(), states);
return stateBundle;
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class BackstackDelegateTest method testRestoreViewFromState.
@Test
public void testRestoreViewFromState() {
BackstackDelegate backstackDelegate = new BackstackDelegate(null);
TestKey key = new TestKey("hello");
backstackDelegate.onCreate(null, null, HistoryBuilder.single(key));
backstackDelegate.setStateChanger(stateChanger);
Mockito.when(view.getContext()).thenReturn(context);
StateBundle stateBundle = new StateBundle();
Mockito.when(((Bundleable) view).toBundle()).thenReturn(stateBundle);
// noinspection ResourceType
Mockito.when(context.getSystemService(KeyContextWrapper.TAG)).thenReturn(key);
backstackDelegate.persistViewToState(view);
backstackDelegate.restoreViewFromState(view);
((Bundleable) Mockito.verify(view, Mockito.times(1))).fromBundle(stateBundle);
}
Aggregations