Nikola Milovic
02/27/2020, 3:17 PMkioba
02/27/2020, 6:05 PMkioba
02/27/2020, 6:12 PMloadDrillTypes
if the stream fails it closes we can’t iterate on the documents any more. We need to move the loop insude the try:
fun loadDrillTypes(): Observable<DrillsType> =
Observable.create<DrillsType> { emitter ->
firebaseFirestore.collection("drilltypes")
.get()
.addOnSuccessListener { documents ->
try {
for (document in documents) {
val doc = document.toObject(DrillsType::class.java)
emitter.onNext(doc)
}
} catch (e: Exception) {
emitter.onError(e)
}
emitter.onComplete()
}
.addOnFailureListener { exception ->
Log.w("TAG", "Error getting documents: ", exception)
emitter.onError(exception)
}
}
kioba
02/27/2020, 6:16 PMremoteDataSource
.loadDrillTypes()
.flatMap { data ->
getImageUrl(data.drillType_imageUrl)
.map{
data.copy(drillType_imageUrl = it)
}
}
Nikola Milovic
02/27/2020, 9:18 PMMatej Drobnič
02/28/2020, 6:18 AMpg
02/28/2020, 8:02 AMNikola Milovic
02/28/2020, 9:46 PMfun loadFullDrillType(): Observable<DrillsType> {
return loadDrillTypeWithRawImageUrl().flatMapSingle { rawImageUrl ->
loadImageUrl(rawImageUrl.drillType_imageUrl).map {
return@map rawImageUrl.copy(drillType_imageUrl = it)
}
}
}
Also used your @kioba try and catch fix for callbacks and documents.
Thanks everyone ❤️
Didn't know that there was such a concise and simple solution to this problem.Nikola Milovic
02/29/2020, 4:05 PMMatej Drobnič
02/29/2020, 4:38 PMonError
method of original subscriber