Skip to content

Commit

Permalink
feat: issue-863 implement invalidate to better refresh experience
Browse files Browse the repository at this point in the history
  • Loading branch information
intent-kacper-cyranowski committed Jun 24, 2024
1 parent 8893a5e commit 8cdf9f3
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions android/src/main/java/com/bleplx/adapter/BleModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.bleplx.adapter.utils.UUIDConverter;
import com.bleplx.adapter.utils.mapper.RxBleDeviceToDeviceMapper;
import com.bleplx.adapter.utils.mapper.RxScanResultToScanResultMapper;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.polidea.rxandroidble2.NotificationSetupMode;
import com.polidea.rxandroidble2.RxBleAdapterStateObservable;
import com.polidea.rxandroidble2.RxBleClient;
Expand All @@ -56,7 +57,8 @@
import io.reactivex.functions.Action;
import io.reactivex.schedulers.Schedulers;

public class BleModule implements BleAdapter {
public class BleModule extends ReactContextBaseJavaModule implements BleAdapter {
public static final String NAME = "Ble";

private final ErrorConverter errorConverter = new ErrorConverter();

Expand Down Expand Up @@ -99,6 +101,12 @@ public class BleModule implements BleAdapter {

private int currentLogLevel = RxBleLog.NONE;

@Override
@NonNull
public String getName() {
return NAME;
}

public BleModule(Context context) {
this.context = context;
bluetoothManager = (BluetoothManager) context.getSystemService(Context.BLUETOOTH_SERVICE);
Expand All @@ -118,6 +126,15 @@ public void createClient(String restoreStateIdentifier,
}
}

private void clearActiveConnections() {
pendingTransactions.removeAllSubscriptions();
connectingDevices.removeAllSubscriptions();
connectedDevices.clear();
activeConnections.clear();
discoveredDevices.clear();

}

@Override
public void destroyClient() {
if (adapterStateChangesSubscription != null) {
Expand All @@ -128,15 +145,10 @@ public void destroyClient() {
scanSubscription.dispose();
scanSubscription = null;
}
pendingTransactions.removeAllSubscriptions();
connectingDevices.removeAllSubscriptions();

clearActiveConnections();
discoveredServices.clear();
discoveredCharacteristics.clear();
discoveredDescriptors.clear();
connectedDevices.clear();
activeConnections.clear();
discoveredDevices.clear();

rxBleClient = null;
IdGenerator.clear();
Expand Down Expand Up @@ -1566,4 +1578,9 @@ private void cleanServicesAndCharacteristicsForDevice(@NonNull Device device) {
}
}
}

@Override
public void invalidate() {
clearActiveConnections();
}
}

0 comments on commit 8cdf9f3

Please sign in to comment.