use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class BackstackManagerTest method afterClearAndRestorationTheFilteredAreNotRestored.
@Test
public void afterClearAndRestorationTheFilteredAreNotRestored() {
final TestKey initial = new TestKey("initial");
final TestKey restored = new TestKey("restored");
final TestKey filtered = new TestKey("filtered");
ArrayList<Parcelable> history = new ArrayList<>();
history.add(restored);
history.add(filtered);
StateBundle stateBundle = new StateBundle();
stateBundle.putParcelableArrayList(BackstackManager.getHistoryTag(), history);
BackstackManager backstackManager = new BackstackManager();
backstackManager.setKeyFilter(new KeyFilter() {
@NonNull
@Override
public List<Object> filterHistory(@NonNull List<Object> restoredKeys) {
restoredKeys.remove(filtered);
return restoredKeys;
}
});
backstackManager.setup(HistoryBuilder.single(initial));
backstackManager.fromBundle(stateBundle);
backstackManager.setStateChanger(stateChanger);
Backstack backstack = backstackManager.getBackstack();
assertThat(backstack.getHistory()).contains(restored);
assertThat(backstack.getHistory()).doesNotContain(filtered);
//// would restore properly
backstackManager = new BackstackManager();
backstackManager.setup(HistoryBuilder.single(initial));
backstackManager.fromBundle(stateBundle);
backstackManager.setStateChanger(stateChanger);
backstack = backstackManager.getBackstack();
assertThat(backstack.getHistory()).contains(restored, filtered);
//// if both are filtered, restore initial
backstackManager = new BackstackManager();
backstackManager.setKeyFilter(new KeyFilter() {
@NonNull
@Override
public List<Object> filterHistory(@NonNull List<Object> restoredKeys) {
restoredKeys.remove(restored);
restoredKeys.remove(filtered);
return restoredKeys;
}
});
backstackManager.setup(HistoryBuilder.single(initial));
backstackManager.fromBundle(stateBundle);
backstackManager.setStateChanger(stateChanger);
backstack = backstackManager.getBackstack();
assertThat(backstack.getHistory()).doesNotContain(restored, filtered);
assertThat(backstack.getHistory()).contains(initial);
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class NodeStateManager method persistStates.
public StateBundle persistStates() {
final StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
serviceTree.traverseTree(ServiceTree.Walk.PRE_ORDER, true, new ServiceTree.Walk() {
@Override
public void execute(@NonNull ServiceTree.Node node, @NonNull CancellationToken cancellationToken) {
StateBundle localBundle = rootBundle.getBundle(node.getKey().toString());
if (localBundle == null) {
localBundle = new StateBundle();
}
for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
Log.i(TAG, "Persisting state for [" + entry.getName() + "] in [" + node.getKey().toString() + "]");
if (entry.getService() instanceof Bundleable) {
localBundle.putBundle(entry.getName(), ((Bundleable) entry.getService()).toBundle());
}
}
rootBundle.putBundle(node.getKey().toString(), localBundle);
}
});
return rootBundle;
}
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;
}
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;
}
use of com.zhuinden.statebundle.StateBundle in project simple-stack by Zhuinden.
the class ServiceManager method persistStates.
public StateBundle persistStates() {
StateBundle serviceStates = new StateBundle();
serviceTree.traverseTree(ServiceTree.Walk.PRE_ORDER, (node, cancellationToken) -> {
StateBundle keyBundle = new StateBundle();
for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
if (entry.getService() instanceof Bundleable) {
keyBundle.putParcelable(entry.getName(), ((Bundleable) entry.getService()).toBundle());
}
}
serviceStates.putParcelable(node.getKey().toString(), keyBundle);
});
return serviceStates;
}
Aggregations