Last active
May 29, 2020 03:35
-
-
Save ktvipin27/31dc38f6bf16b33051f2cd0639764af5 to your computer and use it in GitHub Desktop.
BaseActivity for the demo of template creation.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class BaseActivity<D : ViewDataBinding, V : BaseViewModel> : AppCompatActivity(){ | |
@get:LayoutRes | |
protected abstract val layoutId: Int | |
protected abstract val viewModelClass: Class<V> | |
internal val viewModel:V by lazy { ViewModelProvider(this).get(viewModelClass) } | |
internal lateinit var binding: D | |
private set | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
viewModel.onActivityCreated(intent.extras) | |
binding = DataBindingUtil.setContentView(this, layoutId) | |
binding.setVariable(BR.viewModel, viewModel) | |
binding.lifecycleOwner = this | |
onCreated(savedInstanceState,intent.extras) | |
} | |
open fun onCreated(savedInstanceState: Bundle?, extras: Bundle?) { } | |
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { | |
super.onActivityResult(requestCode, resultCode, data) | |
viewModel.onActivityResult(requestCode, resultCode, data) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment