Last active
August 14, 2019 18:53
-
-
Save bernaferrari/9473b4b7869f0fefe4bd3078e5f1737f to your computer and use it in GitHub Desktop.
Simple Groupie sample
This file contains 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 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