ViewModelFactory: fix compile errors for viewmodel-ktx changes

Signed-off-by: Álvaro Brey Vilas <alvaro.brey@nextcloud.com>
This commit is contained in:
Álvaro Brey Vilas 2021-12-15 18:45:06 +01:00
parent 8cb866a474
commit 14fbc2ab78
No known key found for this signature in database
GPG key ID: 2585783189A62105

View file

@ -37,8 +37,8 @@ class ViewModelFactory @Inject constructor(
private val viewModelProviders: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>> private val viewModelProviders: Map<Class<out ViewModel>, @JvmSuppressWildcards Provider<ViewModel>>
) : ViewModelProvider.Factory { ) : ViewModelProvider.Factory {
override fun <T : ViewModel?> create(modelClass: Class<T>): T { override fun <T : ViewModel> create(modelClass: Class<T>): T {
var vmProvider: Provider<ViewModel>? = viewModelProviders.get(modelClass) var vmProvider: Provider<ViewModel>? = viewModelProviders[modelClass]
if (vmProvider == null) { if (vmProvider == null) {
for (entry in viewModelProviders.entries) { for (entry in viewModelProviders.entries) {
@ -53,12 +53,7 @@ class ViewModelFactory @Inject constructor(
throw IllegalArgumentException("${modelClass.simpleName} view model class is not supported") throw IllegalArgumentException("${modelClass.simpleName} view model class is not supported")
} }
@Suppress("TooGenericExceptionCaught", "TooGenericExceptionThrown", "UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
try { return vmProvider.get() as T
val vm = vmProvider.get() as T
return vm
} catch (e: Exception) {
throw RuntimeException(e)
}
} }
} }