mirror of
https://github.com/nextcloud/android.git
synced 2024-11-22 05:05:31 +03:00
ViewModelFactory: fix compile errors for viewmodel-ktx changes
Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
parent
8cb866a474
commit
14fbc2ab78
1 changed files with 4 additions and 9 deletions
|
@ -37,8 +37,8 @@ class ViewModelFactory @Inject constructor(
|
|||
private val viewModelProviders: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
|
||||
) : ViewModelProvider.Factory {
|
||||
|
||||
override fun <T : ViewModel?> create(modelClass: Class<T>): T {
|
||||
var vmProvider: Provider<ViewModel>? = viewModelProviders.get(modelClass)
|
||||
override fun <T : ViewModel> create(modelClass: Class<T>): T {
|
||||
var vmProvider: Provider<ViewModel>? = viewModelProviders[modelClass]
|
||||
|
||||
if (vmProvider == null) {
|
||||
for (entry in viewModelProviders.entries) {
|
||||
|
@ -53,12 +53,7 @@ class ViewModelFactory @Inject constructor(
|
|||
throw IllegalArgumentException("${modelClass.simpleName} view model class is not supported")
|
||||
}
|
||||
|
||||
@Suppress("TooGenericExceptionCaught", "TooGenericExceptionThrown", "UNCHECKED_CAST")
|
||||
try {
|
||||
val vm = vmProvider.get() as T
|
||||
return vm
|
||||
} catch (e: Exception) {
|
||||
throw RuntimeException(e)
|
||||
}
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
return vmProvider.get() as T
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue