在ViewModel
中:
fun validateList(list: List<TestModel>): Single<List<TestModel>> {
return Observable.fromIterable(list)
.toFlowable(BackpressureStrategy.LATEST)
.map { it.jsonString }
.map { it?.let { VerifiableObject(it) } ?: throw IllegalStateException("Json must not be null") }
.flatMapSingle { validate() }
.toList()
.map {
list.mapIndexed { index, testModel ->
(if (it[index] != null) {
//Updating boolean value here
testModel.isVerified = it[index].toString()
} else throw Exception("ERROR")); testModel
}
}
}
fragment:
viewModel. validateList(arrayList)
.doFinally {
showLoading(false)
}
.asyncToUiSingle()
.subscribe({
//Updating UI
adjustCard(it)
}, {
it.printStackTrace()
})
.addTo(disposables)
-TestModel:
data class TestModel(
val title: String,
var isVerified: String? = null,
var reason: String? = null)
在这里,我需要在reason
字段中插入值,一旦任何项目获得错误的值,但异常。我该如何实现?
validate
应用于它,然后将子序列转回原始
onErrorResumeNext
项目:TestModel