diff --git a/README.md b/README.md index dc85d2d..cc74cfc 100644 --- a/README.md +++ b/README.md @@ -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( +fun cat2AdapterDelegate(itemClickedListener : (Cat) -> Unit) = adapterDelegateViewBinding( { layoutInflater, root -> ItemCatBinding.inflate(layoutInflater, root, false) } ) { binding.name.setOnClickListener { - Log.d("Click", "Click on $item") + itemClickedListener(item) } bind { binding.name.text = item.name @@ -95,7 +95,7 @@ adapterDelegate ( } ``` -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: diff --git a/kotlin-dsl-layoutcontainer/src/main/AndroidManifest.xml b/kotlin-dsl-layoutcontainer/src/main/AndroidManifest.xml index 34f1e1f..8a9c884 100644 --- a/kotlin-dsl-layoutcontainer/src/main/AndroidManifest.xml +++ b/kotlin-dsl-layoutcontainer/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ + package="com.hannesdorfmann.adapterdelegates4.dsl.layoutcontainer"/> diff --git a/kotlin-dsl-viewbinding/src/main/AndroidManifest.xml b/kotlin-dsl-viewbinding/src/main/AndroidManifest.xml index 49070b3..ccd5a2f 100644 --- a/kotlin-dsl-viewbinding/src/main/AndroidManifest.xml +++ b/kotlin-dsl-viewbinding/src/main/AndroidManifest.xml @@ -1 +1 @@ - + diff --git a/kotlin-dsl-viewbinding/src/main/java/com/hannesdorfmann/adapterdelegates4/dsl/ViewBindingListAdapterDelegateDsl.kt b/kotlin-dsl-viewbinding/src/main/java/com/hannesdorfmann/adapterdelegates4/dsl/ViewBindingListAdapterDelegateDsl.kt index add3b8e..f12c284 100644 --- a/kotlin-dsl-viewbinding/src/main/java/com/hannesdorfmann/adapterdelegates4/dsl/ViewBindingListAdapterDelegateDsl.kt +++ b/kotlin-dsl-viewbinding/src/main/java/com/hannesdorfmann/adapterdelegates4/dsl/ViewBindingListAdapterDelegateDsl.kt @@ -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 adapterDelegateViewBinding( noinline viewBinding: (layoutInflater: LayoutInflater, parent: ViewGroup) -> V, @@ -107,7 +107,7 @@ internal class DslViewBindingListAdapterDelegate( /** * ViewHolder that is used internally if you use [adapterDelegateViewBinding] DSL to create your AdapterDelegate * - * @since 4.1.0 + * @since 4.3.0 */ class AdapterDelegateViewBindingViewHolder( val binding: V, view: View = binding.root @@ -141,7 +141,7 @@ class AdapterDelegateViewBindingViewHolder( /** * Get the context. * - * @since 4.1.1 + * @since 4.3.0 */ val context: Context = view.context @@ -153,7 +153,7 @@ class AdapterDelegateViewBindingViewHolder( * @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) @@ -170,7 +170,7 @@ class AdapterDelegateViewBindingViewHolder( * @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) @@ -187,7 +187,7 @@ class AdapterDelegateViewBindingViewHolder( * @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 { @@ -205,7 +205,7 @@ class AdapterDelegateViewBindingViewHolder( * @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) @@ -324,9 +324,4 @@ class AdapterDelegateViewBindingViewHolder( } _onViewDetachedFromWindow = block } - - /** - * Convenience method find a given view with the given id inside the layout - */ - fun findViewById(@IdRes id: Int): V = itemView.findViewById(id) as V } diff --git a/kotlin-dsl/src/main/AndroidManifest.xml b/kotlin-dsl/src/main/AndroidManifest.xml index a4c20c3..34f1e1f 100644 --- a/kotlin-dsl/src/main/AndroidManifest.xml +++ b/kotlin-dsl/src/main/AndroidManifest.xml @@ -1,2 +1,2 @@ + package="com.hannesdorfmann.adapterdelegates4.dsl"/>