fix IndexOutOfBoundsException

This commit is contained in:
johan12345
2021-09-05 15:01:46 +02:00
parent 2e4167689d
commit fd1f05888a

View File

@@ -201,12 +201,16 @@ class ChargepriceViewModel(application: Application, chargepriceApiKey: String)
} else if (cpMeta.status == Status.LOADING) {
value = Resource.loading(null)
} else {
value =
Resource.success(cpMeta.data!!.chargePoints.filter {
it.plug == getChargepricePlugType(
chargepoint
) && it.power == chargepoint.power
}[0])
val result = cpMeta.data!!.chargePoints.filter {
it.plug == getChargepricePlugType(
chargepoint
) && it.power == chargepoint.power
}.elementAtOrNull(0)
value = if (result != null) {
Resource.success(result)
} else {
Resource.error("matching chargepoint not found", null)
}
}
}
}