3.1.0
New features and improvements
-
withAdapterItem
is now an inline extension -
added
onClick
extension in RecyclerAdapterViewHolder (a throttling click listener to prevent double clicks). You can use it on your views:yourView.onClick { }
-
added
onClickWith
, which combinesonClick
andwithAdapterItem
:
This:itemView.setOnClickListener { withAdapterItem<TextWithToggleItem> { // do something } }
can be rewritten as:
itemView.onClickWith<TextWithToggleItem> { // do something }
-
added
RenderableItems
DSL. It allows a functional-declarative approach without usingarrayOf
,listOf
,spread operator
ortoTypedArray
Example:render { +Items.leaveBehind("swipe to left to leave behind", "option") (0..random.nextInt(200) + 50).map { if (it % 2 == 0) +Items.Card.titleSubtitle("Item $it", "subtitle $it") else +Items.Card.labelWithToggle("Toggle $it") } }
Example 2:
private fun singleSelectionGroup(): RenderableItems = renderableItems { val selectedItem = groupAselected.firstOrNull() (1..3).map { number -> +Items.switch( label = "Option $number", onClick = { item -> val selected = listOf(item) onGroupChangedSelection("Group A", selected) groupAselected = selected render(selectionGroups()) } ).apply { selected = equals(selectedItem) } } } private fun selectionGroups() = renderableItems { +Items.label(getString(R.string.single_selection)) +singleSelectionGroup() +Items.label(getString(R.string.multiple_selection)) +multipleSelectionGroup() +Items.button( text = getString(R.string.show_selections), onClick = { val selectedA = groupAselected.asString() val selectedB = groupBselected.asString() AlertDialog.Builder(this@GroupsSelectionActivity) .setTitle("Selected items") .setMessage( "${getString(R.string.single_selection)}:\n$selectedA\n\n" + "${getString(R.string.multiple_selection)}:\n$selectedB" ) .setPositiveButton("Ok", null) .show() } ) }