I am using RxJava 2.* and I want to merge the results of two observables (one from retrofit and another from room) by using zip operator(feel free to suggest better).
Model objects that come from remote server are different from the one coming out of Room Database.
- I want to map the objects from Remote into that of local
- Merge those two results
- Display the result.
My remote API looks like this :
interface CategoryService{
@GET("categories")
fun getCategories(): Observable<List<Category>>
}
And my Room DAO query looks like this :
@Query("SELECT * FROM categories ORDER BY id")
abstract fun categories(): Observable<List<KmagCategory>>
I have converted Observable> into Observable> like this :
val newCategoryList : Observable<List<KmagCategory>> =settingService.getCategories().flatMap { list ->
Observable.fromIterable(list)
.map { item -> KmagCategory(item.id, item.title, item.slug, item.isFav) }
.toList()
.toObservable()
}
But when I try to zip these two observables like this :
val combinedObservable : Observable<List<KmagCategory>> = Observables.zip(KMagApp.database?.categories()?.categories()!!,newSetting)