Skip to content

Instantly share code, notes, and snippets.

@bakawaii
Last active November 4, 2017 18:11
Show Gist options
  • Save bakawaii/48c285e1062120edd434bedb131ab2b1 to your computer and use it in GitHub Desktop.
Save bakawaii/48c285e1062120edd434bedb131ab2b1 to your computer and use it in GitHub Desktop.
class SampleFragment: Fragment() {
data class Args(val title: String? = null, val content: String? = null, val showButton: Boolean = false)
companion object {
private const val ARG_TITLE = "ARG_TITLE"
private const val ARG_CONTENT = "ARG_CONTENT"
private const val ARG_SHOW_BUTTON = "ARG_SHOW_BUTTON"
fun newInstance(args: Args) = SampleFragment().apply {
arguments = getBundle(args)
}
fun getBundle(args: Args) = Bundle().apply {
putString(ARG_TITLE, args.title)
putString(ARG_CONTENT, args.content)
putBoolean(ARG_SHOW_BUTTON, args.showButton)
}
}
private val mArgs by lazy {
arguments?.let {
Args(
arguments.getString(ARG_TITLE),
arguments.getString(ARG_CONTENT),
arguments.getBoolean(ARG_SHOW_BUTTON) == true)
} ?: Args()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment