-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
📝 Add documentation for BindingAdapters
- Loading branch information
David Sucharda
committed
Jun 30, 2021
1 parent
028164c
commit b70f51c
Showing
5 changed files
with
375 additions
and
57 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,12 @@ import cz.eman.kaal.presentation.adapter.binder.VariableBinder | |
import cz.eman.logger.logError | ||
|
||
/** | ||
* Binds adapter to [RecyclerView] using [BindingRecyclerViewAdapter]. Parameters are used to create this adapter and | ||
* support item clicks, differences and other options. If the adapter already exists it only changes item list in | ||
* the adapter, which happens with Observable or LiveData items. | ||
* Binds adapter to [RecyclerView] using [BindingRecyclerViewAdapter] or [BindingPagingRecyclerViewAdapter] (based on | ||
* the [paging] variable). Parameters are used to create adapter and support item clicks, differences and other options. | ||
* If the adapter already exists it only changes item list in the adapter, which happens with Observable or LiveData | ||
* items. If the adapter is a pager adapter it does nothing. | ||
* | ||
* @author [eMan a.s.](mailto:[email protected]) | ||
* @author eMan a.s. | ||
* @since 0.8.0 | ||
*/ | ||
@BindingAdapter( | ||
|
@@ -46,7 +47,7 @@ fun <T : Any> bindRecyclerView( | |
itemLongClickListener = longClickListener, | ||
limit = limit | ||
) | ||
recyclerView.adapter = buildAdapter(config, paging, differ) | ||
recyclerView.adapter = buildBindingAdapter(config, paging, differ) | ||
} else { | ||
@Suppress("UNCHECKED_CAST") | ||
adapter as BindingRecyclerViewAdapter<T> | ||
|
@@ -55,11 +56,12 @@ fun <T : Any> bindRecyclerView( | |
} | ||
|
||
/** | ||
* Binds adapter to [ViewPager2] using [BindingRecyclerViewAdapter]. Parameters are used to create this adapter and | ||
* support item clicks, differences and other options. If the adapter already exists it only changes item list in | ||
* the adapter, which happens with Observable or LiveData items. | ||
* Binds adapter to [ViewPager2] using [BindingRecyclerViewAdapter] or [BindingPagingRecyclerViewAdapter] (based on | ||
* the [paging] variable). Parameters are used to create adapter and support item clicks, differences and other options. | ||
* If the adapter already exists it only changes item list in the adapter, which happens with Observable or LiveData | ||
* items. If the adapter is a pager adapter it does nothing. | ||
* | ||
* @author [eMan a.s.](mailto:[email protected]) | ||
* @author eMan a.s. | ||
* @since 0.8.0 | ||
*/ | ||
@BindingAdapter( | ||
|
@@ -87,15 +89,31 @@ fun <T : Any> bindViewPager2( | |
itemClickListener = clickListener, | ||
itemLongClickListener = longClickListener, | ||
) | ||
viewPager.adapter = buildAdapter(config, paging, differ) | ||
viewPager.adapter = buildBindingAdapter(config, paging, differ) | ||
} else { | ||
@Suppress("UNCHECKED_CAST") | ||
adapter as BindingRecyclerViewAdapter<T> | ||
adapter.setItems(items) | ||
} | ||
} | ||
|
||
private fun <T : Any> buildAdapter( | ||
/** | ||
* Builds a binding adapter based on the variables. There are three cases at the moment: | ||
* 1) [BindingRecyclerViewAdapter] is created when paging adapter should not be used. | ||
* 2) [BindingPagingRecyclerViewAdapter] is created when paging adapter is used and [differ] variable is not null, since | ||
* paging adapter requires this variable to be set. | ||
* 3) Identifies that paging adapter should be created but [differ] is missing. It logs the error and created | ||
* [BindingRecyclerViewAdapter] which makes sure data are displayed. | ||
* | ||
* @param config common configuration for any biding adapter | ||
* @param paging true when paging adapter should be created else false | ||
* @param differ [DiffUtil] to be used in the adapter | ||
* @author eMan a.s. | ||
* @see BindingRecyclerViewAdapter.build | ||
* @see BindingPagingRecyclerViewAdapter.build | ||
* @since 0.9.0 | ||
*/ | ||
private fun <T : Any> buildBindingAdapter( | ||
config: BindingAdapterConfig<T>, | ||
paging: Boolean, | ||
differ: DiffUtil.ItemCallback<T>? | ||
|
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
Oops, something went wrong.