Last active
November 14, 2019 07:34
-
-
Save NsAveek/178962ff4eff1e6a4ed0df73cc7f764b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const val addFragment = 1 | |
const val replaceFragment = 2 | |
private inline fun generateFragmentTransaction(fragmentToReplaceOrAdd : Fragment, addOrReplace: Int) : FragmentTransaction { | |
return when(addOrReplace) { | |
addFragment -> supportFragmentManager.beginTransaction().add(R.id.container_frame, fragmentToReplaceOrAdd) | |
else -> supportFragmentManager.beginTransaction().replace(R.id.container_frame, fragmentToReplaceOrAdd) | |
} | |
} | |
private fun fragmentAddOrReplacer(name : String, transaction : ()-> FragmentTransaction){ | |
transaction().apply { | |
addToBackStack(name).commit() | |
} | |
} | |
private fun openFragmentA() { | |
fragmentAddOrReplacer("sampleFragment") { generateFragmentTransaction(FragmentA.newInstance(), replaceFragment) } | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment