Skip to content

Instantly share code, notes, and snippets.

@pandulapeter
Created February 20, 2018 13:50
Show Gist options
  • Save pandulapeter/455d5ab609868cf036625f8fd15b580c to your computer and use it in GitHub Desktop.
Save pandulapeter/455d5ab609868cf036625f8fd15b580c to your computer and use it in GitHub Desktop.
Example usage of BundleDelegate
class MusicPlayerFragment : Fragment() {
private val playlistId by lazy { arguments.playlistId }
private val songIndex by lazy { arguments.songIndex }
companion object {
private var Bundle.playlistId by BundleDelegate.String("key_playlist_id")
private var Bundle.songIndex by BundleDelegate.Int("key_song_index")
fun newInstance(playlistId: String, songIndex: Int) = MusicPlayerFragment().apply {
arguments = Bundle().apply {
this.playlistId = playlistId
this.songIndex = songIndex
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment