pull/83/head
kunfei 5 years ago
parent 4768161e25
commit f2e11bb69a
  1. 9
      app/src/main/java/io/legado/app/utils/ViewModelKt.kt

@ -3,14 +3,15 @@ package io.legado.app.utils
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModel import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProviders import androidx.lifecycle.ViewModelProvider
fun <T : ViewModel> AppCompatActivity.getViewModel(clazz: Class<T>) = ViewModelProviders.of(this).get(clazz) fun <T : ViewModel> AppCompatActivity.getViewModel(clazz: Class<T>) =
ViewModelProvider(this).get(clazz)
fun <T : ViewModel> Fragment.getViewModel(clazz: Class<T>) = ViewModelProviders.of(this).get(clazz) fun <T : ViewModel> Fragment.getViewModel(clazz: Class<T>) = ViewModelProvider(this).get(clazz)
/** /**
* 与activity数据同步 * 与activity数据同步
*/ */
fun <T : ViewModel> Fragment.getViewModelOfActivity(clazz: Class<T>) = fun <T : ViewModel> Fragment.getViewModelOfActivity(clazz: Class<T>) =
ViewModelProviders.of(requireActivity()).get(clazz) ViewModelProvider(requireActivity()).get(clazz)
Loading…
Cancel
Save