Android-MultiStacks

Additional

Language
Kotlin
Version
1.4 (Feb 2, 2021)
Created
Jan 21, 2020
Updated
Feb 2, 2021 (Retired)
Owner
DimaKron
Contributor
DimaKron
1
Activity
Badge
Generate
Download
Source code

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 tab
  • push(Fragment) add new fragment to current tab
  • replace(Fragment) replace current with new fragment
  • popFragments(Int) remove X last fragments of current stack
  • clearStack(Class?) remove all fragments of current stack until first or specified fragment

Other features

Unique fragment in stack

Your fragment should implements getIdentifierInStack() of IMultiStackFragmentinterface

Built-in tabs history

Enable tabs history with MultiStack.Builder.setTabHistoryEnabled(true)