Releases: gotev/recycler-adapter
4.1.1
4.1.0
New features
- When the rendering canvas is empty, you can specify
onEmptyCanvas
renderable items. This is useful for example if you have complex UIs which may result in no items to be shown and you want an easy way of detecting that scenario to display an empty state or something else without tons of ifs. Big thanks to @mike5v 🎉
Updates
- Gradle 7.0.2
4.0.0
Breaking changes
- Removed all the deprecated features in 3.0.0, 3.1.2, 3.2.0
syncWithItems
is now using AndroidDiffUtil
and accepts aList
instead ofArrayList
. This also tangibly improves performance.
Fixes
- Diffing bug in PagingAdapter
Upgrades
- Kotlin from
1.4.10
to1.4.32
- Lifecycle to
2.3.1
- RecyclerView to
1.2.1
- Stopped using deprecated Kotlin Android Extensions
- Stopped using jcenter
3.2.0
3.1.2
New features and improvements
RenderableItems
are now iterable and can accept also lists of null items, adding only the non-null ones- Fixed an internal function which can now return null. This could have caused setEmptyItem malfunctioning.
Deprecations
setEmptyItem
. Prefer re-rendering the list when needed instead of relying on setEmptyItem. Check AsyncLoadingActivity in the example app.
Why deprecating this feature?
Because it does not allow to handle different situations in which your list may be empty. Imagine this scenario: you go to a screen and then make an API call which returns you a list of stuff.
- When you land on the page and before you make the API call, your list is empty
- After you execute the API call successfully, your list may be empty
- Some error happens during your API call and your list is empty, but you have to notify the user about the error
So, you actually have 3 different empty states which means different things. By using setEmptyItem
you cannot cover those 3 different scenarios. Removing that feature and using new render features, you can. Check AsyncLoadingActivity
example.
Demo App
- Added fetcher and AsyncLoadingActivity to demonstrate new extended rendering capabilities
- Refactorings and improvements
3.1.1
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() } ) }
3.0.0
All the AdapterItems written for RecyclerAdapter 2.10.x are 100% compatible with 3.0.0 without any change.
Breaking changes
- removed
RecyclerAdapter.createRecycledViewPool
It's better to use plainRecyclerView.RecycledViewPool()
and pass it around to all the shared Recycler Views - removed internal support for selection groups. They can be achieved without that support, which was cumbersome. Updated examples in the demo app.
- moved
lockScrollingWhileInserting
as an external extension - moved
enableDragDrop
as an external extension - removed
getItemPosition
. It's now achieved withrecyclerAdapter.adapterItems.indexOf(item)
- removed
getItemAtPosition
. It's now achieved withrecyclerAdapter.adapterItems.getOrNull(item)
- removed
sort
. It's now achieved withrecyclerAdapter.modifyItemsAndRender { it.sorted() }
andrecyclerAdapter.modifyItemsAndRender { it.sortedDescending() }
. Check the readme for more details. - removed
removeAllItemsWithClass
,getLastItemWithClass
,removeLastItemWithClass
methods andRemoveListener
. It's now achieved withmodifyItemsAndRender
extension. Check the demo app for replacement details and examples.
Deprecations
- AdapterItem's
getLayoutId
. UsegetView(parent: ViewGroup) = parent.inflating(id)
instead - AdapterItem View Holder's
getAdapterItem()
. UsewithAdapterItem<SomeItem> { }
instead
New features and improvements
- You can get a copy of the internal list with
recyclerAdapter.adapterItems
. Modifying that list won't affect the internal one. - added
RecyclerAdapter.modifyItemsAndRender
extension which gives freedom to manipulate the internal list and render it back. It's the replacement forsort
,removeAllItemsWithClass
,getLastItemWithClass
,removeLastItemWithClass
methods RecyclerView.withSharedViewPool
andRecyclerView.setupWithPrefetchingLinearLayoutAndSharedViewPool
extensions now accepts aRecyclerView.RecycledViewPool
as parameter. If not specified, it will continue to use the global shared pool as in 2.x- You can
swap
two items in the RecyclerAdapter - Improved internal handling of the empty item
- added getView(parent: ViewGroup) which allows to both inflate XML views by using
parent.inflating(id)
or to create them completely programmatically - added
Int.dp(context)
to favor programmatic views and be able to write24.dp(context)
- added
withAdapterItem<SomeItem> { }
to replace error prone and cumbersome(getAdapterItem() as? SomeItem)?.apply { }
- enhanced release script, which now build and adds the demo app in the release
- dropped support for Android API < 21
Updates
- Kotlin
1.4.10