Search in sources :

Example 6 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);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    binding.navigation.setOnNavigationItemSelectedListener(item -> {
        Backstack backstack = Navigator.getBackstack(this);
        switch(item.getItemId()) {
            case R.id.navigation_home:
                backstack.setHistory(History.of(HomeKey.create()), StateChange.REPLACE);
                return true;
            case R.id.navigation_dashboard:
                backstack.setHistory(History.of(DashboardKey.create()), StateChange.REPLACE);
                return true;
            case R.id.navigation_notifications:
                backstack.setHistory(History.of(NotificationKey.create()), StateChange.REPLACE);
                return true;
        }
        return false;
    });
    fragmentStateChanger = new DefaultFragmentStateChanger(getSupportFragmentManager(), R.id.container);
    Navigator.configure().setStateChanger(new SimpleStateChanger(this)).install(this, binding.container, History.single(HomeKey.create()));
}
Also used : DefaultFragmentStateChanger(com.zhuinden.simplestackextensions.fragments.DefaultFragmentStateChanger) Backstack(com.zhuinden.simplestack.Backstack) SimpleStateChanger(com.zhuinden.simplestack.SimpleStateChanger)

Example 7 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);
    binding = ActivityMainBinding.inflate(getLayoutInflater());
    setContentView(binding.getRoot());
    binding.navigation.setOnNavigationItemSelectedListener(item -> {
        Backstack backstack = Navigator.getBackstack(this);
        switch(item.getItemId()) {
            case R.id.navigation_home:
                backstack.setHistory(History.of(HomeKey.create()), StateChange.REPLACE);
                return true;
            case R.id.navigation_dashboard:
                backstack.setHistory(History.of(DashboardKey.create()), StateChange.REPLACE);
                return true;
            case R.id.navigation_notifications:
                backstack.setHistory(History.of(NotificationKey.create()), StateChange.REPLACE);
                return true;
        }
        return false;
    });
    Navigator.install(this, binding.container, History.single(HomeKey.create()));
}
Also used : Backstack(com.zhuinden.simplestack.Backstack)

Example 8 with Backstack

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

the class BackstackHost method initialize.

Backstack initialize(boolean isInitializeDeferred) {
    if (backstack == null) {
        backstack = new Backstack();
        backstack.setKeyFilter(keyFilter);
        backstack.setKeyParceler(keyParceler);
        backstack.setStateClearStrategy(stateClearStrategy);
        if (scopedServices != null) {
            backstack.setScopedServices(scopedServices);
        }
        if (globalServices != null) {
            backstack.setGlobalServices(globalServices);
        }
        if (globalServiceFactory != null) {
            backstack.setGlobalServices(globalServiceFactory);
        }
        backstack.setup(initialKeys);
        for (Backstack.CompletionListener completionListener : stateChangeCompletionListeners) {
            backstack.addStateChangeCompletionListener(completionListener);
        }
        if (savedInstanceState != null) {
            backstack.fromBundle(savedInstanceState.<StateBundle>getParcelable("NAVIGATOR_STATE_BUNDLE"));
        }
    }
    if (!isInitializeDeferred) {
        backstack.setStateChanger(stateChanger);
    }
    return backstack;
}
Also used : Backstack(com.zhuinden.simplestack.Backstack)

Example 9 with Backstack

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

the class NewWordFragment method onViewCreated.

@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
    super.onViewCreated(view, savedInstanceState);
    Backstack backstack = Navigator.getBackstack(requireContext());
    actionHandler = backstack.lookupService(ActionHandler.class.getName());
    view.findViewById(R.id.buttonAddNewWord).setOnClickListener(v -> {
        String word = view.<TextView>findViewById(R.id.textInputNewWord).getText().toString().trim();
        actionHandler.onAddWordClicked(word);
    });
}
Also used : Backstack(com.zhuinden.simplestack.Backstack)

Example 10 with Backstack

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

the class WordListKey method bindServices.

@Override
public void bindServices(@Nonnull ServiceBinder serviceBinder) {
    final Backstack backstack = serviceBinder.getBackstack();
    WordController wordController = new WordController(backstack);
    serviceBinder.addService(WordController.class.getName(), wordController);
    serviceBinder.addAlias(WordListFragment.DataProvider.class.getName(), wordController);
    serviceBinder.addAlias(WordListFragment.ActionHandler.class.getName(), wordController);
    serviceBinder.addAlias(NewWordFragment.ActionHandler.class.getName(), wordController);
    serviceBinder.addService("WordEventEmitter", wordController.getEventEmitter());
}
Also used : Backstack(com.zhuinden.simplestack.Backstack)

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