Simplified handling of fragment operations in android app.
Java Kotlin
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
.idea
app
fragment-manager
gradle/wrapper
kotlin-fragment-manager
.gitignore
LICENSE
README.md
build.gradle
gradle.properties
gradlew
gradlew.bat
settings.gradle

README.md

SimpleFragmentManager

Simplified handling of fragments in android application by using wrapper class around FragmentManager and simple tag stack.

Detailed explanation is in this blog post

SimpleFragmentManager SimpleFragmentManager

Installation

Gradle

implementation 'com.bajicdusko:fragment-manager:1.0.4'

or

implementation 'com.bajicdusko:kotlin-fragment-manager:1.0.4'

Usage example

To simplify the setup, few super classes are created: SFMActivity, SFMFragment and FragmentChannel. By extending these three classes you should be ready in no time.

Create new communication interface by extending FragmentChannel

interface ExampleFragmentChannel : FragmentChannel {
    fun openSecondFragment()
}

Each new fragment handled by SimpleFragmentManager should extend SFMFragment<>

class FirstFragment : SFMFragment<ExampleFragmentChannel>() { 

    ...
    
    fun onButtonClick(){
        fragmentChannel?.openSecondFragment()
    }
}

By creating new activity, just extend SFMActivity

class HomeActivity : SFMActivity(), ExampleFragmentChannel {

    override fun getFrameLayoutContainerId(): Int = R.id.activity_home_fragment_container

    override fun onCreate(savedInstanceState: android.os.Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_home)
        simpleFragmentManager.enableLogs(true)
        simpleFragmentManager.addFragment(FirstFragment.newInstance())
    }
    
    override fun openSecondFragment(){
        simpleFragmentManager.replaceFragment(SecondFragment.newInstance())
    }
}

This is what happens in the background

SequenceDiagram