Skip to content

Instantly share code, notes, and snippets.

@dzungvu
Created June 15, 2021 08:03
Show Gist options
  • Save dzungvu/0cedd043801c628fc79fe71ac2d17292 to your computer and use it in GitHub Desktop.
Save dzungvu/0cedd043801c628fc79fe71ac2d17292 to your computer and use it in GitHub Desktop.
class TraverseLayoutInterceptorCompositor(
private val interceptors: Map<Class<out View>, TraverseLayoutInterceptor<out View>>
) : TraverseLayoutInterceptor<View> {
override fun interceptAttrs(view: View, attrs: AttributeSet) {
(peekInterceptor(view) as? TraverseLayoutInterceptor<View>)?.run {
interceptAttrs(view, attrs)
} ?: Log.d("InterceptorCompositor", "Get view interceptor failure")
}
private fun peekInterceptor(view: View) =
interceptors[view::class.java] ?: searchAssignableInterceptor(view)
private fun searchAssignableInterceptor(view: View): TraverseLayoutInterceptor<out View>? {
interceptors.forEach { (clz, interceptor) ->
if (clz.isAssignableFrom(view::class.java)) {
return interceptor
}
}
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment