Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: issue-863 implement invalidate to better refresh experience #1217

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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();
}
}
Loading