Skip to content

Instantly share code, notes, and snippets.

@bernaferrari
Last active August 14, 2019 18:53
Show Gist options
  • Save bernaferrari/9473b4b7869f0fefe4bd3078e5f1737f to your computer and use it in GitHub Desktop.
Save bernaferrari/9473b4b7869f0fefe4bd3078e5f1737f to your computer and use it in GitHub Desktop.
Simple Groupie sample
class MainActivity : AppCompatActivity() {
private val groupAdapter = GroupAdapter<ViewHolder>()
// Hold a reference to the updating group, so we can, well, update it
private var updatingGroup = Section()
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
groupAdapter.apply {
setOnItemClickListener(...)
setOnItemLongClickListener(...)
}
populateAdapter()
recyclerView.apply {
layoutManager = LinearLayoutManager(this)
adapter = groupAdapter
}
}
private fun populateAdapter() {
// Full bleed item
groupAdapter += Section(HeaderItem(R.string.full_bleed_item)).apply {
add(FullBleedCardItem(R.color.purple_200))
}
// Update in place group
groupAdapter += Section().apply {
val updatingHeader = HeaderItem(
R.string.updating_group,
R.string.updating_group_subtitle,
R.drawable.shuffle,
onShuffleClicked)
setHeader(updatingHeader)
updatingGroup.update(updatableItems)
add(updatingGroup)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment