Skip to content

Commit

Permalink
Updating readme
Browse files Browse the repository at this point in the history
  • Loading branch information
sockeqwe committed Mar 9, 2020
1 parent 4da596f commit 1f2ba5f
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 19 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,11 @@ fun catAdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegateLay
In case you want to use ViewBinding\DataBinding use `adapterDelegateViewBinding` instead of `adapterDelegate` like this:

```kotlin
fun cat2AdapterDelegate() = adapterDelegateViewBinding<Cat, DisplayableItem, ItemCatBinding>(
fun cat2AdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegateViewBinding<Cat, DisplayableItem, ItemCatBinding>(
{ layoutInflater, root -> ItemCatBinding.inflate(layoutInflater, root, false) }
) {
binding.name.setOnClickListener {
Log.d("Click", "Click on $item")
itemClickedListener(item)
}
bind {
binding.name.text = item.name
Expand Down Expand Up @@ -95,7 +95,7 @@ adapterDelegate<Cat, Animal> (
}
```

The same `on` parameter is available for `adapterDelegateLayoutContainer()` DSL.
The same `on` parameter is available for `adapterDelegateLayoutContainer()` and `adapterDelegateViewBinding()` DSL.

### Compose your Adapter
Finally, you can compose your `RecyclerView Adapter` by registering your AdapterDelegates like this:
Expand Down
2 changes: 1 addition & 1 deletion kotlin-dsl-layoutcontainer/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hannesdorfmann.adapterdelegates4.dsl"/>
package="com.hannesdorfmann.adapterdelegates4.dsl.layoutcontainer"/>
2 changes: 1 addition & 1 deletion kotlin-dsl-viewbinding/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<manifest package="com.hannesdorfmann.adapterdelegates4.dsl" />
<manifest package="com.hannesdorfmann.adapterdelegates4.dsl.viewbinding" />
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ import com.hannesdorfmann.adapterdelegates4.AdapterDelegate
* Simple DSL builder to create an [AdapterDelegate] that is backed by a [List] as dataset.
* This DSL builds on top of [ViewBinding] so that no findViewById is needed anymore.
*
* @param viewBinding ViewBinding for this adapter delegate.
* @param viewBinding return a [ViewBinding] for this adapter delegate.
* @param on The check that should be run if the AdapterDelegate is for the corresponding Item in the datasource.
* In other words its the implementation of [AdapterDelegate.isForViewType].
* @param block The DSL block. Specify here what to do when the ViewHolder gets created. Think of it as some kind of
* initializer block. For example, you would setup a click listener on a Ui widget in that block followed by specifying
* what to do once the ViewHolder binds to the data by specifying a bind block for
* @since 4.1.0
* @since 4.3.0
*/
inline fun <reified I : T, T, V : ViewBinding> adapterDelegateViewBinding(
noinline viewBinding: (layoutInflater: LayoutInflater, parent: ViewGroup) -> V,
Expand Down Expand Up @@ -107,7 +107,7 @@ internal class DslViewBindingListAdapterDelegate<I : T, T, V : ViewBinding>(
/**
* ViewHolder that is used internally if you use [adapterDelegateViewBinding] DSL to create your AdapterDelegate
*
* @since 4.1.0
* @since 4.3.0
*/
class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
val binding: V, view: View = binding.root
Expand Down Expand Up @@ -141,7 +141,7 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
/**
* Get the context.
*
* @since 4.1.1
* @since 4.3.0
*/
val context: Context = view.context

Expand All @@ -153,7 +153,7 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
* @return The string data associated with the resource, stripped of styled
* text information.
*
* @since 4.1.1
* @since 4.3.0
*/
fun getString(@StringRes resId: Int): String {
return context.getString(resId)
Expand All @@ -170,7 +170,7 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
* @return The string data associated with the resource, formatted and
* stripped of styled text information.
*
* @since 4.1.1
* @since 4.3.0
*/
fun getString(@StringRes resId: Int, vararg formatArgs: Any): String {
return context.getString(resId, *formatArgs)
Expand All @@ -187,7 +187,7 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
* @throws android.content.res.Resources.NotFoundException if the given ID
* does not exist.
*
* @since 4.1.1
* @since 4.3.0
*/
@ColorInt
fun getColor(@ColorRes id: Int): Int {
Expand All @@ -205,7 +205,7 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
* @throws android.content.res.Resources.NotFoundException if the given ID
* does not exist.
*
* @since 4.1.1
* @since 4.3.0
*/
fun getDrawable(@DrawableRes id: Int): Drawable? {
return ContextCompat.getDrawable(context, id)
Expand Down Expand Up @@ -324,9 +324,4 @@ class AdapterDelegateViewBindingViewHolder<T, V: ViewBinding>(
}
_onViewDetachedFromWindow = block
}

/**
* Convenience method find a given view with the given id inside the layout
*/
fun <V : View> findViewById(@IdRes id: Int): V = itemView.findViewById(id) as V
}
2 changes: 1 addition & 1 deletion kotlin-dsl/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hannesdorfmann.adapterdelegates4"/>
package="com.hannesdorfmann.adapterdelegates4.dsl"/>

0 comments on commit 1f2ba5f

Please sign in to comment.