ViewBinding reflection¶
Quick start¶
Define reflectViewBinding
.
abstract class ReflectBaseActivity1<VB : ViewBinding, VM : ViewModel> : AppCompatActivity() {
// ViewBinding
protected val mBinding: VB by lazy {
reflectViewBinding()
}
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(mBinding.root)
}
}
Extend ReflectBaseActivity1
.
class ReflectActivity1 : ReflectBaseActivity1<ActivityMyBinding, ReflectViewModel1>() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
mBinding.personRv.adapter = VbAdapter2(persons)
mBinding.personRv.layoutManager = LinearLayoutManager(this)
}
}
Reduce recursion¶
reflectViewBinding
provides a base
parameter that allows you to reduce the number of recursive searches.
abstract class ReflectBaseActivity1<VB : ViewBinding, VM : ViewModel> : AppCompatActivity() {
// ViewBinding
protected val mBinding: VB by lazy {
reflectViewBinding(ReflectBaseActivity1::class.java)
}
}
Proguard rules¶
-keep public interface androidx.viewbinding.ViewBinding
-keep class * implements androidx.viewbinding.ViewBinding{
*;
}
-keep class * extends com.ave.vastgui.tools.activity.VastActivity { *;}