-
Notifications
You must be signed in to change notification settings - Fork 54
/
MultiStateBinding.kt
41 lines (35 loc) · 1.15 KB
/
MultiStateBinding.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.zy.demo.base
import android.content.Context
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.viewbinding.ViewBinding
import com.zy.multistatepage.MultiState
import com.zy.multistatepage.MultiStateContainer
import java.lang.reflect.ParameterizedType
/**
* @author: yanz
*/
abstract class MultiStateBinding<VB : ViewBinding> : MultiState() {
lateinit var viewBinding: VB
override fun onCreateView(
context: Context,
inflater: LayoutInflater,
container: MultiStateContainer
): View {
val parameterizedType = javaClass.genericSuperclass as ParameterizedType
val clazz = parameterizedType.actualTypeArguments[0] as Class<*>
val inflate = clazz.getDeclaredMethod(
"inflate",
LayoutInflater::class.java,
ViewGroup::class.java,
Boolean::class.java
)
viewBinding = inflate.invoke(null, inflate, container, false) as VB
return viewBinding.root
}
override fun onViewCreated(view: View) {
onMultiStateViewCreate()
}
abstract fun onMultiStateViewCreate()
}