【发布时间】:2018-06-28 16:50:11
【问题描述】:
我正在使用 rxjava 的 MVVM 架构,我试图从几个查询中获得一个响应,但它什么也没做,甚至不会引发错误
DAO 中的查询方法
@Query("SELECT * FROM Notes WHERE type =:type")
fun getNotes(type: String): Single<List<Note>>
本地数据源
class NotesLocalDataSource private constructor(
private val notesDao: NotesDao
) : NotesDataSource {
override fun getNotes(): Single<Notes> {
return Single.zip(
notesDao.getNotes("typeOne"),
notesDao.getNotes("typeTwo"),
notesDao.getNotes("typeThree"),
notesDao.getNotes("typeFour"),
Function4 { t1, t2, t3, t4 ->
Notes(t1,t2,t3, t4)
})
}
NotesDataSource
interface NotesDataSource {
fun getNotes() : Single<Notes>
}
笔记模型
data class Notes(val typeOne: List<Note>, val typeTwo: List<Note>, val typeThree: List<Note>, val typeFour: List<Note>)
存储库
class NotesRepository(
private val notesLocalDataSource: NotesDataSource
) : NotesDataSource {
override fun getNotes(): Single<Notes> {
return notesLocalDataSource.getNotes()
}
}
视图模型
notesRepository.getNotes().map {
Log.e("TAG","Notes: $it")
}
【问题讨论】:
标签: java android kotlin rx-java android-room