Skip to content

3.1.0

Compare
Choose a tag to compare
@gotev gotev released this 22 Mar 22:55
· 46 commits to master since this release

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 combines onClick and withAdapterItem:
    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 using arrayOf, listOf, spread operator or toTypedArray
    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()
            }
        )
    }