我目前正在使用 Android-ReactiveLocation 库(Github)。(代码LastKnownLocationObservable
)按预期工作。我正在使用 a从数据库中获取附近的电台,并且(因为领域)我正在从数据中创建一个模型。所以我有一个项目列表,我正在创建新的Observable 。flatMap
flatMap
Observable.from(data)
然后我想对位置进行排序,过滤它们并将它们分组。
.toSortedList()
.flatMap { Observable.from(it) }
.filter { it.distance <= (maxDistance.toDouble() * 1000) }
.groupBy { //Group the stations in categories
if (it.distance <= maxDistance && it.favorite) {
"nearbyFavorite"
} else if (it.favorite) {
"outOfReachFavorite"
} else {
"nearby"
}
}
但是,当我订阅 Observable 时,永远不会调用 onComplete。Observable 只是停在toSortedList()
.
订阅:
.subscribe(object: Subscriber<GroupedObservable<String, NearbyLocationItem>>() {
override fun onNext(p0: GroupedObservable<String, NearbyLocationItem>?) {
val locationItems = ArrayList<NearbyLocationItem>()
p0.subscribe { loc ->
locationItems.add(loc)
}
locations.put(p0.key, locationItems)
}
override fun onCompleted() {
Log.d(javaClass.simpleName, "Never called")
}
override fun onError(p0: Throwable?) {
}
}