Skip to content

Commit

Permalink
Fix binary incompatibility about ItemViewBinder (#294)
Browse files Browse the repository at this point in the history
Fixed #293
  • Loading branch information
drakeet authored Dec 11, 2019
1 parent 72a7296 commit f6fc067
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
12 changes: 12 additions & 0 deletions library/src/main/kotlin/com/drakeet/multitype/MultiTypeAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,18 @@ open class MultiTypeAdapter @JvmOverloads constructor(
register(clazz.java, delegate)
}

fun <T> register(clazz: Class<T>, binder: ItemViewBinder<T, *>) {
register(clazz, binder as ItemViewDelegate<T, *>)
}

inline fun <reified T : Any> register(binder: ItemViewBinder<T, *>) {
register(binder as ItemViewDelegate<T, *>)
}

fun <T : Any> register(clazz: KClass<T>, binder: ItemViewBinder<T, *>) {
register(clazz, binder as ItemViewDelegate<T, *>)
}

internal fun <T> register(type: Type<T>) {
types.register(type)
type.delegate._adapter = this
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ internal class OneToManyBuilder<T>(
this.delegates = delegates as Array<ItemViewDelegate<T, *>>
}

@SafeVarargs
@CheckResult(suggest = "#withLinker(Linker)")
override fun to(vararg binders: ItemViewBinder<T, *>) = apply {
@Suppress("UNCHECKED_CAST")
this.delegates = binders as Array<ItemViewDelegate<T, *>>
}

override fun withLinker(linker: Linker<T>) {
doRegister(linker)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,7 @@ interface OneToManyFlow<T> {
*/
@CheckResult
fun to(vararg delegates: ItemViewDelegate<T, *>): OneToManyEndpoint<T>

@CheckResult
fun to(vararg delegates: ItemViewBinder<T, *>): OneToManyEndpoint<T>
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down

0 comments on commit f6fc067

Please sign in to comment.