我使用Flowable.combineLatest(query,params)
来监听查询更改和一些参数更改,但现在我想引入分页和监听偏移量更改,但这里的问题是,当查询更改时,我需要重置偏移量。想知道如何使用RxAndroid实现这一点?基本上我们观察3个或更多的对象( query,offset,connectionChange)我想要实现的是监听任何可观察对象的变化+当query发生变化时更新offset的值
发布于 2020-12-11 19:31:31
要查看值来自何处,您必须以某种方式标记这些值,这需要逐个源进行转换。例如:
data class Tuple<T>(val value: T, val index: Long) { ... }
Flowable.defer {
var indices: Array<Long>(4) { 0 }
var latests: Array<Long>(4) { 0 }
Flowable.combineLatest(
source1.map { Tuple(it, indices[0]++) },
source2.map { Tuple(it, indices[1]++) },
source3.map { Tuple(it, indices[2]++) },
source4.map { Tuple(it, indices[3]++) },
{ tuple1, tuple2, tuple3, tuple4 ->
if (tuple1.index != latests[0]) {
// first source changed
}
if (tuple2.index != latests[1]) {
// second source changed
}
if (tuple3.index != latests[2]) {
// third source changed
}
if (tuple4.index != latests[3]) {
// fourth source changed
}
latests[0] = tuple1.index
latests[1] = tuple2.index
latests[2] = tuple3.index
latests[3] = tuple4.index
}
)
}
发布于 2020-12-09 05:13:42
发布于 2020-12-09 05:59:18
在将item发送到query
可流动对象之后,您可以显式地链接另一个调用。在注册Flowable
之前注册doAfterNext
可能是最简单的方法。
fun observePublishers(query: Flowable<List<String>>, connectionState: Flowable<Boolean>, offset: Flowable<Int>) {
val newQuery = query.doAfterNext {
index = 0
}
Flowable.combineLatest(newQuery, connectionState, offset) { queryResult, hasConnection, offsetValue ->
}.subscribe {
}
}
https://stackoverflow.com/questions/65172763
复制相似问题