Created
April 3, 2020 10:45
-
-
Save wangerekaharun/c5171c13334d2276b8309be12492c083 to your computer and use it in GitHub Desktop.
Inflating toolnbar as a fragement
This file contains hidden or 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
private fun showToolbarContent(isAuthenticated: Boolean, destinationId: Int) { | |
val content = when (destinationId) { | |
R.id.homeFragment -> if (isAuthenticated) FeedbackFragment() else CountdownFragment() | |
R.id.feedFragment -> TitleFragment().also { | |
val args = Bundle() | |
args.putString("title", getString(R.string.feed)) | |
it.arguments = args | |
} | |
R.id.sessionsFragment -> TitleFragment().also { | |
val args = Bundle() | |
args.putString("title", getString(R.string.sessions)) | |
it.arguments = args | |
} | |
R.id.aboutFragment -> TitleFragment().also { | |
val args = Bundle() | |
args.putString("title", getString(R.string.about)) | |
it.arguments = args | |
} | |
else -> null | |
} | |
content?.let { | |
val ft: FragmentTransaction = supportFragmentManager.beginTransaction() | |
if (supportFragmentManager.fragments.size > 0) | |
ft.replace(toolbarContent.id, content).commit() | |
else ft.add(toolbarContent.id, content).commit() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment