Skip to content

Commit

Permalink
fragment
Browse files Browse the repository at this point in the history
  • Loading branch information
AranAndroid009 committed Apr 27, 2021
1 parent 7e39dbd commit ac9a0d5
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.aranandroid.mvvm.base.v


import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import androidx.fragment.app.FragmentActivity
import androidx.lifecycle.ViewModelProviders
import com.aranandroid.mvvm.base.vm.BaseViewModel
import java.lang.reflect.ParameterizedType
import java.lang.reflect.Type


open class BaseFragmentActivity<VM : BaseViewModel,ViewDataBinding : androidx.databinding.ViewDataBinding?>(
layoutId: Int
) : FragmentActivity() {
val viewModel by lazy {
ViewModelProviders.of(this)
.get(getClass() as Class<VM>)
}

val binding by lazy {
DataBindingUtil.setContentView<ViewDataBinding>(
this,
layoutId
)
}

fun getClass(): Type? {
return (javaClass.genericSuperclass as ParameterizedType).actualTypeArguments[0] as Class<VM?>
}


}

0 comments on commit ac9a0d5

Please sign in to comment.