Android MultiStacks
Getting started
Dependency
Add following line to root build.gradle
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
and line to modul level build.gradle
dependencies {
implementation 'com.github.DimaKron:Android-MultiStacks:1.2'
}
Usage
Initialization
Initialize component with Builder in your main navigation activity
multiStacks = MultiStacks.Builder(supportFragmentManager, R.id.containerLayout)
.setState(savedInstanceState)
.setRootFragmentInitializers(fragmentInitializers)
.setSelectedTabIndex(0)
.setTabHistoryEnabled(true)
.setTransactionListener(this)
.build()
Saving state
Override method of navigation activity
override fun onSaveInstanceState(outState: Bundle) {
multiStacks.saveInstanceState(outState)
super.onSaveInstanceState(outState)
}
Back action
Call method to perform back action (close fragment or back to other tab)
...
multiStacks.onBackPressed()
...
Manage
Use following methods for navigation managent
setSelectedTabIndex(Int)
change tabpush(Fragment)
add new fragment to current tabreplace(Fragment)
replace current with new fragmentpopFragments(Int)
remove X last fragments of current stackclearStack(Class?)
remove all fragments of current stack until first or specified fragment
Other features
Unique fragment in stack
Your fragment should implements getIdentifierInStack()
of IMultiStackFragment
interface
Built-in tabs history
Enable tabs history with MultiStack.Builder.setTabHistoryEnabled(true)