Search in sources :

Example 1 with DefaultStateChanger

use of com.zhuinden.simplestack.navigator.DefaultStateChanger 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 2 with DefaultStateChanger

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

the class BackstackDelegateActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    ButterKnife.bind(this);
    backstackDelegate = new BackstackDelegate(null);
    //
    backstackDelegate.onCreate(//
    savedInstanceState, //
    getLastCustomNonConfigurationInstance(), HistoryBuilder.single(FirstKey.create()));
    defaultStateChanger = DefaultStateChanger.configure().setStatePersistenceStrategy(new DefaultStateChanger.StatePersistenceStrategy() {

        @Override
        public void persistViewToState(@NonNull Object previousKey, @NonNull View previousView) {
            backstackDelegate.persistViewToState(previousView);
        }

        @Override
        public void restoreViewFromState(@NonNull Object newKey, @NonNull View newView) {
            backstackDelegate.restoreViewFromState(newView);
        }
    }).create(this, root);
    backstackDelegate.setStateChanger(defaultStateChanger);
}
Also used : BackstackDelegate(com.zhuinden.simplestack.BackstackDelegate) DefaultStateChanger(com.zhuinden.simplestack.navigator.DefaultStateChanger) BindView(butterknife.BindView) View(android.view.View)

Aggregations

BindView (butterknife.BindView)2 DefaultStateChanger (com.zhuinden.simplestack.navigator.DefaultStateChanger)2 Bundle (android.os.Bundle)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 View (android.view.View)1 FrameLayout (android.widget.FrameLayout)1 ButterKnife (butterknife.ButterKnife)1 Backstack (com.zhuinden.simplestack.Backstack)1 BackstackDelegate (com.zhuinden.simplestack.BackstackDelegate)1 HistoryBuilder (com.zhuinden.simplestack.HistoryBuilder)1 Navigator (com.zhuinden.simplestack.navigator.Navigator)1 Disposable (io.reactivex.disposables.Disposable)1