Skip to content

Instantly share code, notes, and snippets.

@autrilla
Created March 26, 2016 22:01
Show Gist options
  • Select an option

  • Save autrilla/83f2a9af4b9c1c88fc79 to your computer and use it in GitHub Desktop.

Select an option

Save autrilla/83f2a9af4b9c1c88fc79 to your computer and use it in GitHub Desktop.
private fun updateProbes() {
temperatureProbeService.listTemperatureProbes()
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.flatMapIterable { probes -> probes }
.flatMap { probe ->
val temperature = temperatureProbeService.lastTemperature(probe.serialNumber)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
Observable.zip(Observable.just(probe), temperature, {one, two -> Pair(one, two)})
}.subscribe({ probeTemperature ->
println("Found probe ${probeTemperature.first.serialNumber} with last recorded " +
"temperature of ${probeTemperature.second.temperature} at " +
"${probeTemperature.second.time}") },
{ e ->
Snackbar.make(findViewById(android.R.id.content)!!,
getString(R.string.error_no_internet), Snackbar.LENGTH_LONG)
.show()
},
{ println("Done refreshing"); swipeRefreshLayout.isRefreshing = false })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment