Search in sources :

Example 1 with Backstack

use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.

the class MainActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    CustomApplication.get(this).initialize();
    CustomApplication.get(this).getComponent().inject(this);
    databaseManager.init(this);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    Backstack backstack = Navigator.configure().setDeferredInitialization(true).setStateChanger(DefaultStateChanger.configure().setExternalStateChanger(this).setViewChangeCompletionListener(this).create(this, root)).install(this, root, HistoryBuilder.single(TasksKey.create()));
    backstackHolder.setBackstack(backstack);
    MainScopeListener mainScopeListener = (MainScopeListener) getSupportFragmentManager().findFragmentByTag("MAIN_SCOPE_LISTENER");
    if (mainScopeListener == null) {
        mainScopeListener = new MainScopeListener();
        getSupportFragmentManager().beginTransaction().add(mainScopeListener, "MAIN_SCOPE_LISTENER").commit();
    }
    mainView.onCreate();
}
Also used : Backstack(com.zhuinden.simplestack.Backstack)

Example 2 with Backstack

use of com.zhuinden.simplestack.Backstack 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);
    defaultStateChanger = DefaultStateChanger.create(this, root);
    Backstack backstack = Navigator.configure().setStateChanger(new NoOpStateChanger()).setDeferredInitialization(true).install(this, root, HistoryBuilder.single(FirstKey.create()));
    disposable = RxStackObservable.create(backstack).subscribe(stateChange -> {
        if (stateChange.topNewState().equals(stateChange.topPreviousState())) {
            return;
        }
        defaultStateChanger.performViewChange(stateChange.topPreviousState(), stateChange.topNewState(), stateChange, () -> {
        });
    });
    Navigator.executeDeferredInitialization(this);
}
Also used : Disposable(io.reactivex.disposables.Disposable) Bundle(android.os.Bundle) DefaultStateChanger(com.zhuinden.simplestack.navigator.DefaultStateChanger) Backstack(com.zhuinden.simplestack.Backstack) ButterKnife(butterknife.ButterKnife) Navigator(com.zhuinden.simplestack.navigator.Navigator) FrameLayout(android.widget.FrameLayout) HistoryBuilder(com.zhuinden.simplestack.HistoryBuilder) AppCompatActivity(android.support.v7.app.AppCompatActivity) BindView(butterknife.BindView) Backstack(com.zhuinden.simplestack.Backstack)

Example 3 with Backstack

use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.

the class NestSupportServiceManager method buildServicesForKey.

private void buildServicesForKey(StateBundle states, Key newKey, ServiceTree.Node node) {
    newKey.bindServices(node);
    restoreServiceStateForKey(states, newKey, node);
    if (newKey instanceof Composite) {
        for (Object _nestedKey : ((Composite) newKey).keys()) {
            Key nestedKey = (Key) _nestedKey;
            ServiceTree.Node nestedNode = serviceTree.createChildNode(node, nestedKey);
            buildServicesForKey(states, (Key) _nestedKey, nestedNode);
        }
    }
    if (newKey.hasNestedStack()) {
        Backstack nestedStack = serviceTree.getNode(newKey).<BackstackManager>getService(Key.NESTED_STACK).getBackstack();
        for (Object _childKey : nestedStack.getInitialParameters()) {
            buildServices(states, (Key) _childKey);
        }
    }
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) ServiceTree(com.zhuinden.servicetree.ServiceTree) Key(com.zhuinden.simplestackdemonestedstack.application.Key)

Example 4 with Backstack

use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.

the class NestSupportServiceManager method handleBack.

public boolean handleBack(Context context) {
    ServiceTree serviceTree = ServiceLocator.getService(context, ServiceLocator.SERVICE_TREE);
    Object lastKey = activeKeys.get(activeKeys.size() - 1);
    Backstack backstack = Navigator.getBackstack(context);
    class Cancellation {

        private boolean cancelled;
    }
    Cancellation cancellation = new Cancellation();
    serviceTree.traverseChain(serviceTree.getNode(lastKey), (node, cancellationToken) -> {
        Object _key = node.getKey();
        if (_key instanceof Key) {
            // ROOT is defined by Activity's TAG
            Key key = (Key) _key;
            if (key.hasNestedStack()) {
                BackstackManager backstackManager = serviceTree.getNode(key).getService(Key.NESTED_STACK);
                if (backstackManager.getBackstack().goBack()) {
                    cancellation.cancelled = true;
                    cancellationToken.cancel();
                }
            }
        }
    });
    if (cancellation.cancelled) {
        return true;
    }
    return backstack.goBack();
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) BackstackManager(com.zhuinden.simplestack.BackstackManager) ServiceTree(com.zhuinden.servicetree.ServiceTree) Key(com.zhuinden.simplestackdemonestedstack.application.Key)

Example 5 with Backstack

use of com.zhuinden.simplestack.Backstack in project simple-stack by Zhuinden.

the class WordListFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    final Backstack backstack = Navigator.getBackstack(requireContext());
    dataProvider = backstack.lookupService(DataProvider.class.getName());
    actionHandler = backstack.lookupService(ActionHandler.class.getName());
    controllerEvents = backstack.lookupService("WordEventEmitter");
    RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
    recyclerView.setLayoutManager(new LinearLayoutManager(requireContext(), LinearLayoutManager.VERTICAL, false));
    recyclerView.setAdapter(adapter);
    view.findViewById(R.id.buttonGoToAddNewWord).setOnClickListener(v -> actionHandler.onAddNewWordClicked());
    dataProvider.getWordList().observe(getViewLifecycleOwner(), words -> adapter.updateWords(words));
}
Also used : Backstack(com.zhuinden.simplestack.Backstack) RecyclerView(androidx.recyclerview.widget.RecyclerView) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager)

Aggregations

Backstack (com.zhuinden.simplestack.Backstack)10 ServiceTree (com.zhuinden.servicetree.ServiceTree)2 Key (com.zhuinden.simplestackdemonestedstack.application.Key)2 Bundle (android.os.Bundle)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 FrameLayout (android.widget.FrameLayout)1 LinearLayoutManager (androidx.recyclerview.widget.LinearLayoutManager)1 RecyclerView (androidx.recyclerview.widget.RecyclerView)1 BindView (butterknife.BindView)1 ButterKnife (butterknife.ButterKnife)1 BackstackManager (com.zhuinden.simplestack.BackstackManager)1 HistoryBuilder (com.zhuinden.simplestack.HistoryBuilder)1 SimpleStateChanger (com.zhuinden.simplestack.SimpleStateChanger)1 DefaultStateChanger (com.zhuinden.simplestack.navigator.DefaultStateChanger)1 Navigator (com.zhuinden.simplestack.navigator.Navigator)1 DefaultFragmentStateChanger (com.zhuinden.simplestackextensions.fragments.DefaultFragmentStateChanger)1 Disposable (io.reactivex.disposables.Disposable)1