File tree Expand file tree Collapse file tree 1 file changed +33
-0
lines changed
mvvm/src/main/java/com/aranandroid/mvvm/base/v Expand file tree Collapse file tree 1 file changed +33
-0
lines changed Original file line number Diff line number Diff line change 1+ package com.aranandroid.mvvm.base.v
2+
3+
4+ import androidx.appcompat.app.AppCompatActivity
5+ import androidx.databinding.DataBindingUtil
6+ import androidx.fragment.app.FragmentActivity
7+ import androidx.lifecycle.ViewModelProviders
8+ import com.aranandroid.mvvm.base.vm.BaseViewModel
9+ import java.lang.reflect.ParameterizedType
10+ import java.lang.reflect.Type
11+
12+
13+ open class BaseFragmentActivity <VM : BaseViewModel ,ViewDataBinding : androidx.databinding.ViewDataBinding ?>(
14+ layoutId : Int
15+ ) : FragmentActivity() {
16+ val viewModel by lazy {
17+ ViewModelProviders .of(this )
18+ .get(getClass() as Class <VM >)
19+ }
20+
21+ val binding by lazy {
22+ DataBindingUtil .setContentView<ViewDataBinding >(
23+ this ,
24+ layoutId
25+ )
26+ }
27+
28+ fun getClass (): Type ? {
29+ return (javaClass.genericSuperclass as ParameterizedType ).actualTypeArguments[0 ] as Class <VM ?>
30+ }
31+
32+
33+ }
You can’t perform that action at this time.
0 commit comments