These are chat archives for ReactiveX/RxJava

Aug 2018
Aug 08 2018 06:10
@dmstocking thanks for the feedback ! No problem with kotlin I’m also an Android programmer pimarily ^^
That’s the path I was thinking to take (and put the cancel as an error on my single); Just wanted some feedbacks on how was my solutions as I’m not expert in RX ^^. The full story is that we were given a proprietary SDK to interact with a BT device, this SDK work based on one listener with around 40 methods to override and implements, and we can put only one listener on the SDK. I want to hide this stuff by wrapping it into RX calls to be more readable/maintenable once used on the app (actually it’s a Flutter plugin but same problem). And the SDK doesn’t allow simultanous calls so once you cancel something you need to wait until it’s successfuly cancelled and you have receive the right callback from the SDK.
I know the solution of the token inside the create is not perfect, but I have to comply with the SDK I have and make it work ^^
I’ll go that way and see how it goes :)
Aug 08 2018 22:26
Still trying to understand how to scan for a limited time then return a list to work with. I am using the RxAndroidBle to scan for all BLE devices. I am trying to look for all devices starting with ABC for example. When I create a test by emitting values using Observable.intervalRange, everything works perfectly. If I don't try to constrain the RxAndroidBle.scanBleDevices function by using a .take() and just subscribe to the results, that works as expected. When I try to build up a list of BLE devices it finds and then return it though, it doesn't work (nothing ever gets returned).
I call the function like this:
          List<String> bleDevicesWithMyPrefix = Scanner.create(context).scanForPrefix("ABC").blockingGet();
Aug 08 2018 22:33
     fun scanForPrefix(prefix: String): Single<MutableList<String?>> {
            return scanAllDevices()
            .take(15, TimeUnit.SECONDS, timeoutScheduler)
            .map { }
            .filter { inspectScanResult(it,prefix) }
          private fun scanAllDevices(): Observable<ScanResult>
        = rxBleClient.scanBleDevices(
Aug 08 2018 22:39
The test I set up works perfectly. It looks like this:
           //Begin test code
var emittedList: List<String> = listOf("MMM", "OOO", "ABC", "ABCDEF", "ZZZ", "ABC", "RRRRRRR", "ZZABC")

private fun scanAllDevicesTEST(): Observable<ScanResult> {

    return Observable
            .intervalRange(0, emittedList.size.toLong(), 0, 200, TimeUnit.MILLISECONDS, timeoutScheduler)
            .map { index -> ScanResult(MyDevice(emittedList[index.toInt()]), 4, 10, ScanCallbackType.CALLBACK_TYPE_ALL_MATCHES, MyRecord()) }

So I am confused why it works for the test which emits values just like the real thing does, and not for the real thing. Again, if I don't do a take, and subscribe instead, then the scanAllDevices code does scan correctly. I just can't allow it to scan forever and I need one complete list. Not something that gets sent back an element at a time.
Aug 08 2018 22:46
For example, doing this I do get the BLE devices scanned successfully. I just cannot use them coming back async. I need a complete list or as much of a list as can be found in a specified time period. Note that the scanner takes less than a second to get all of the values when it is working, but I gave it up to 15 just to take out that variable. Here is the code that does at least scan.
    private fun scanAllDevices(context: Context) {

    val rxBleClient = RxBleClient.create(context);

             ScanSettings.Builder ()
                    .setScanMode(ScanSettings.SCAN_MODE_LOW_POWER) // change if needed
                    .setCallbackType(ScanSettings.CALLBACK_TYPE_ALL_MATCHES) // change if needed
                val rxBleDevice = rxBleClient.getBleDevice(scanResult.getBleDevice().getMacAddress());
                Logger.d(TAG, "The device has name ${}")