Here I am using in gradle latest updated library
compile 'com.polidea.rxandroidble:rxandroidble:1.2.2'
to
compile 'com.polidea.rxandroidble2:rxandroidble:1.7.1'
As per new updations Subscription is now Disposable and SubscriptionList is now CompositeDisposable and unsubscribe is dispose.
But dispose is not disconnecting my hardware.
HashMap<String, ConnectionEntry> mConnections = new HashMap<>();
public Observable<RxBleConnection> getConnection(String mac) {
if (mConnections.containsKey(mac)) {
return mConnections.get(mac).getConnectionObservable();
} else {
if (isBluetoothEnabled()) {
ConnectionEntry entry = new ConnectionEntry();
RxBleDevice rxBleDevice = mRxBleClient.getBleDevice(mac);
Observable<RxBleConnection> connectionObservable = rxBleDevice
.establishConnection(false)
.takeUntil(entry.getDisconnectTriggerSubject())
.compose(new ConnectionSharingAdapter());
entry.setConnectionObservable(connectionObservable);
mConnections.put(mac, entry);
return connectionObservable;
}
}
return null;
}
public void triggerDisconnect(String mac) {
ConnectionEntry entry = mConnections.get(mac);
if (entry != null) {
synchronized (entry.getSubscriptions()) {
for (Disposable s : entry.getSubscriptions()) {
if (s != null && !s.isDisposed()) {
s.dispose();
}
}
}
entry.getSubscriptions().clear();
entry.setConnectionObservable(null);
entry.getDisconnectTriggerSubject();
entry.removeFlags();
mConnections.remove(mac);
Log.d(TAG, "Connection for " + mac + " removed");
}
}