Last active
April 12, 2023 06:41
Revisions
-
RobLewis revised this gist
Jun 26, 2018 . No changes.There are no files selected for viewing
-
RobLewis created this gist
Jun 26, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ package net.grlewis.cufftest; import android.bluetooth.BluetoothGatt; import com.polidea.rxandroidble2.RxBleCustomOperation; import com.polidea.rxandroidble2.internal.connection.RxBleGattCallback; import io.reactivex.Observable; import io.reactivex.Scheduler; import io.reactivex.annotations.NonNull; public class GetGattOperation implements RxBleCustomOperation<BluetoothGatt> { private BluetoothGatt gatt; // How this works: // You call rxBleConnection.queue( <instance of this class> ) // It returns an Observable<T>--call it Observable A // The queue manager calls the .asObservable() method below, // which returns another Observable<T>--call it Observable B // It is placed in the queue for execution // When it's time to run this operation, ConnectionOperationQueue will // subscribe to Observable B (here, Observable.just( bluetoothGatt )) // Emissions from this Observable B (here, the bluetoothGatt) are forwarded to the Observable A returned by the .queue() method // Instances can be queued and received via a subscription to Observable A: // rxBleConnection.queue( new GetGattOperation() ).subscribe( gatt -> {} ); @Override // returns "Observable B" (see above) public @NonNull Observable<BluetoothGatt> asObservable( BluetoothGatt bluetoothGatt, RxBleGattCallback rxBleGattCallback, Scheduler scheduler) throws Throwable { gatt = bluetoothGatt; return Observable.just( bluetoothGatt ); // return Observable B (emits Gatt then completes) } public BluetoothGatt getGatt( ) { return gatt; } }