Search in sources :

Example 6 with StateBundle

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

the class AddOrEditTaskPresenter method toBundle.

@Override
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 7 with StateBundle

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

the class FirstView method toBundle.

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

Example 8 with StateBundle

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

the class MortarDemoApplication method getSystemService.

@Override
public Object getSystemService(String name) {
    if (serviceTree == null) {
        serviceTree = new ServiceTree();
        serviceTree.registerRootService(DaggerService.SERVICE_NAME, DaggerSingletonComponent.builder().rootModule(new RootModule(serviceTree)).build());
        serviceTree.registerRootService(NodeStateManager.SERVICE_STATES, new StateBundle());
    // MortarScope.buildRootScope()
    //.withService(ObjectGraphService.SERVICE_NAME, ObjectGraph.create(new RootModule()))
    //.build("Root");
    }
    if (serviceTree.hasRootService(name)) {
        return serviceTree.getRootService(name);
    }
    if (TreeNodes.NODE_TAG.equals(name)) {
        return serviceTree.getTreeRoot();
    }
    return super.getSystemService(name);
}
Also used : ServiceTree(com.zhuinden.servicetree.ServiceTree) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 9 with StateBundle

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

the class NodeStateManager method restoreStatesForNode.

public void restoreStatesForNode(ServiceTree.Node node) {
    StateBundle rootBundle = serviceTree.getRootService(SERVICE_STATES);
    StateBundle localBundle = rootBundle.getBundle(node.getKey().toString());
    Log.i(TAG, "Restoring state for [" + node.getKey().toString() + "] with bundle [" + localBundle + "]");
    for (ServiceTree.Node.Entry entry : node.getBoundServices()) {
        Log.i(TAG, "Restoring state for service [" + entry.getName() + "]");
        if (entry.getService() instanceof Bundleable) {
            ((Bundleable) entry.getService()).fromBundle(localBundle == null ? null : localBundle.getBundle(entry.getName()));
        }
    }
}
Also used : Bundleable(com.zhuinden.simplestack.Bundleable) StateBundle(com.zhuinden.statebundle.StateBundle)

Example 10 with StateBundle

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

the class BackstackManager method persistViewToState.

// ----- viewstate persistence
/**
     * Provides the means to save the provided view's hierarchy state
     * and its optional StateBundle via {@link Bundleable} into a {@link SavedState}.
     *
     * @param view the view that belongs to a certain key
     */
public void persistViewToState(@Nullable View view) {
    if (view != null) {
        Object key = KeyContextWrapper.getKey(view.getContext());
        if (key == null) {
            throw new IllegalArgumentException("The view [" + view + "] contained no key!");
        }
        SparseArray<Parcelable> viewHierarchyState = new SparseArray<>();
        view.saveHierarchyState(viewHierarchyState);
        StateBundle bundle = null;
        if (view instanceof Bundleable) {
            bundle = ((Bundleable) view).toBundle();
        }
        SavedState previousSavedState = //
        SavedState.builder().setKey(//
        key).setViewHierarchyState(//
        viewHierarchyState).setBundle(//
        bundle).build();
        keyStateMap.put(key, previousSavedState);
    }
}
Also used : SparseArray(android.util.SparseArray) Parcelable(android.os.Parcelable) StateBundle(com.zhuinden.statebundle.StateBundle)

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