These are chat archives for ReactiveX/RxJava

9th
Aug 2018
Ignacio Baca Moreno-Torres
@ibaca
Aug 09 2018 05:21
Not sure, but add various ".doOnNext" to log element to see which operator is not doing what you expect
erge123
@erge123
Aug 09 2018 07:48
@songyunlu
Darrin
@darrinps
Aug 09 2018 21:00
Thanks for the suggestion. I did try that, and didn't see any .doOnNext methods ever get hit anywhere. Anyway, I figured out how to do what I want, but I still am not certain why what I had did not work. What I came up with looks like this:
    button_scan3.setOnClickListener {
        Log.d(TAG, "\n\nFiring up Scanner3")

        val scanner = SuiteScanner.create(this.applicationContext)
        val set = mutableSetOf<String>()

        scanner.scanForAllBLEDevices3("ABC")
                .doOnComplete { Log.d(TAG, "Completed...Scanner3")
                    for(name in set ) {
                        Log.d(TAG, "BLE Device: $name")
                    }
                }
                .subscribe { scanResult ->
                    val rxBleDevice = scanResult.getBleDevice()
                    Log.d(TAG, "The device has name ${rxBleDevice.name}")
                    val name = rxBleDevice.name
                    if (name != null) {
                        set.add(name)
                    }
                }

    }                                                                                                                                                                                                                                                                                                                                                                                                                                           

    fun scanForAllBLEDevices3(prefix: String): Observable<ScanResult> {

    Log.w(TAG, "We are in scanForAllBLEDevices3.")

    return rxBleScanner()
            .take(2, TimeUnit.SECONDS, timeoutScheduler)
            .observeOn(Schedulers.io())
            .filter { device -> inspectScanResult(device.bleDevice.name, prefix) }
}


private fun inspectScanResult(foundDevice: String?, prefix: String): Boolean {
    Log.d(TAG, " Inspecting: $foundDevice")

    if(foundDevice == null) {
        return false
    }

    return (foundDevice.startsWith(prefix))
}
So I'll just do what needs to be done in the onComplete()