diff --git a/library/src/main/kotlin/com/drakeet/multitype/MultiTypeAdapter.kt b/library/src/main/kotlin/com/drakeet/multitype/MultiTypeAdapter.kt index 79f0dd6f..20035f32 100644 --- a/library/src/main/kotlin/com/drakeet/multitype/MultiTypeAdapter.kt +++ b/library/src/main/kotlin/com/drakeet/multitype/MultiTypeAdapter.kt @@ -68,6 +68,18 @@ open class MultiTypeAdapter @JvmOverloads constructor( register(clazz.java, delegate) } + fun register(clazz: Class, binder: ItemViewBinder) { + register(clazz, binder as ItemViewDelegate) + } + + inline fun register(binder: ItemViewBinder) { + register(binder as ItemViewDelegate) + } + + fun register(clazz: KClass, binder: ItemViewBinder) { + register(clazz, binder as ItemViewDelegate) + } + internal fun register(type: Type) { types.register(type) type.delegate._adapter = this diff --git a/library/src/main/kotlin/com/drakeet/multitype/OneToManyBuilder.kt b/library/src/main/kotlin/com/drakeet/multitype/OneToManyBuilder.kt index 79ed3d6b..3a848a24 100644 --- a/library/src/main/kotlin/com/drakeet/multitype/OneToManyBuilder.kt +++ b/library/src/main/kotlin/com/drakeet/multitype/OneToManyBuilder.kt @@ -35,6 +35,13 @@ internal class OneToManyBuilder( this.delegates = delegates as Array> } + @SafeVarargs + @CheckResult(suggest = "#withLinker(Linker)") + override fun to(vararg binders: ItemViewBinder) = apply { + @Suppress("UNCHECKED_CAST") + this.delegates = binders as Array> + } + override fun withLinker(linker: Linker) { doRegister(linker) } diff --git a/library/src/main/kotlin/com/drakeet/multitype/OneToManyFlow.kt b/library/src/main/kotlin/com/drakeet/multitype/OneToManyFlow.kt index 69af0fad..4ac4cda1 100644 --- a/library/src/main/kotlin/com/drakeet/multitype/OneToManyFlow.kt +++ b/library/src/main/kotlin/com/drakeet/multitype/OneToManyFlow.kt @@ -33,4 +33,7 @@ interface OneToManyFlow { */ @CheckResult fun to(vararg delegates: ItemViewDelegate): OneToManyEndpoint + + @CheckResult + fun to(vararg delegates: ItemViewBinder): OneToManyEndpoint } diff --git a/sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboActivity.kt b/sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboActivity.kt index d48aecee..4d744f43 100644 --- a/sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboActivity.kt +++ b/sample/src/main/kotlin/com/drakeet/multitype/sample/weibo/WeiboActivity.kt @@ -46,9 +46,9 @@ class WeiboActivity : MenuBaseActivity() { SimpleTextViewBinder(), SimpleImageViewBinder() ).withLinker { _, weibo -> - when { - weibo.content is SimpleText -> 0 - weibo.content is SimpleImage -> 1 + when (weibo.content) { + is SimpleText -> 0 + is SimpleImage -> 1 else -> 0 } }