Search in sources :

Example 1 with StateBundle

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    NonConfigurationInstance nonConfigurationInstance = (NonConfigurationInstance) getLastCustomNonConfigurationInstance();
    if (nonConfigurationInstance != null) {
        serviceManager = nonConfigurationInstance.serviceManager;
        serviceTree = serviceManager.getServiceTree();
    } else {
        serviceTree = new ServiceTree();
        serviceTree.createRootNode(TAG);
        serviceManager = new NestSupportServiceManager(serviceTree, TAG);
        serviceManager.setRestoredStates(savedInstanceState != null ? savedInstanceState.getParcelable("SERVICE_BUNDLE") : new StateBundle());
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    backstack = Navigator.configure().setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).create(this, root)).setStateClearStrategy(new PreserveTreeScopesStrategy(serviceTree)).install(this, root, HistoryBuilder.single(MainKey.create()));
}
Also used : PreserveTreeScopesStrategy(com.zhuinden.simplestackdemonestedstack.util.PreserveTreeScopesStrategy) NestSupportServiceManager(com.zhuinden.simplestackdemonestedstack.util.NestSupportServiceManager) ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 2 with StateBundle

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

the class CloudSyncView method toBundle.

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

Example 3 with StateBundle

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

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    NonConfigurationInstance nonConfigurationInstance = (NonConfigurationInstance) getLastCustomNonConfigurationInstance();
    if (nonConfigurationInstance != null) {
        serviceManager = nonConfigurationInstance.serviceManager;
        serviceTree = serviceManager.getServiceTree();
    } else {
        serviceTree = new ServiceTree();
        serviceTree.createRootNode(TAG);
        serviceManager = new ServiceManager(serviceTree, TAG);
    }
    serviceManager.setRestoredStates(savedInstanceState != null ? savedInstanceState.getParcelable(ServiceManager.SERVICE_STATES) : new StateBundle());
    Navigator.configure().setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).create(this, root)).install(this, root, HistoryBuilder.single(A.create()));
}
Also used : ServiceManager(com.zhuinden.simpleservicesexample.utils.ServiceManager) ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 4 with StateBundle

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

the class NestSupportServiceManager 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;
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 5 with StateBundle

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

the class TasksPresenter method toBundle.

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

Aggregations

StateBundle (com.zhuinden.statebundle.StateBundle)44 Test (org.junit.Test)17 Parcelable (android.os.Parcelable)12 TestKey (com.zhuinden.simplestack.helpers.TestKey)11 ArrayList (java.util.ArrayList)10 ServiceTree (com.zhuinden.servicetree.ServiceTree)8 Nonnull (javax.annotation.Nonnull)6 NonNull (android.support.annotation.NonNull)5 Bundleable (com.zhuinden.simplestack.Bundleable)4 ServiceProvider (com.zhuinden.simplestack.helpers.ServiceProvider)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 Nullable (javax.annotation.Nullable)4 SparseArray (android.util.SparseArray)2 AbstractMap (java.util.AbstractMap)2 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2 Context (android.content.Context)1 View (android.view.View)1