Last active
November 4, 2017 18:11
-
-
Save bakawaii/48c285e1062120edd434bedb131ab2b1 to your computer and use it in GitHub Desktop.
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
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