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

Migrate to RxJava 3 #5

Merged
merged 18 commits into from
Mar 29, 2022
Merged
Show file tree
Hide file tree
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
12 changes: 6 additions & 6 deletions dependencies.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
ext {
rxJavaVersion = '2.2.17'
rxJavaVersion = '3.1.4'
sourceCompatibilityVersion = JavaVersion.VERSION_1_8
targetCompatibilityVersion = JavaVersion.VERSION_1_8
shadowPluginVersion = '7.1.2'
daggerVersion = '2.41'
libs = [
/* Library-only dependencies */
rxjava : "io.reactivex.rxjava2:rxjava:$rxJavaVersion",
rxandroid : 'io.reactivex.rxjava2:rxandroid:2.1.1',
rxrelay : 'com.jakewharton.rxrelay2:rxrelay:2.1.1',
rxjava : "io.reactivex.rxjava3:rxjava:$rxJavaVersion",
rxandroid : 'io.reactivex.rxjava3:rxandroid:3.0.0',
rxrelay : 'com.jakewharton.rxrelay3:rxrelay:3.0.1',
junit : 'org.junit.jupiter:junit-jupiter:5.8.1',
groovy : ['org.codehaus.groovy:groovy:3.0.9', 'org.codehaus.groovy:groovy-test:3.0.9'],
spock : 'org.spockframework:spock-core:2.0-groovy-3.0',
Expand All @@ -17,8 +17,8 @@ ext {
/* Shared library-sample apps dependencies */
annotations : "androidx.annotation:annotation:1.1.0",
/* Sample apps-only dependencies */
rxjava_replayingshare : 'com.jakewharton.rx2:replaying-share:2.2.0',
rxjava_binding : 'com.jakewharton.rxbinding3:rxbinding:3.1.0',
rxjava_replayingshare : 'com.jakewharton.rx3:replaying-share:3.0.0',
rxjava_binding : 'com.jakewharton.rxbinding4:rxbinding:4.0.0',
appcompat : 'androidx.appcompat:appcompat:1.1.0',
material_design : 'com.google.android.material:material:1.0.0'
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@
import java.util.Set;
import java.util.UUID;

import io.reactivex.Observable;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.subjects.ReplaySubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.functions.Predicate;
import io.reactivex.rxjava3.subjects.ReplaySubject;

/**
* A mocked {@link RxBleClient}. Callers supply device parameters such as services,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,19 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Single;
import io.reactivex.SingleSource;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.internal.functions.Functions;
import io.reactivex.subjects.CompletableSubject;
import io.reactivex.subjects.SingleSubject;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.core.SingleSource;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.functions.Predicate;
import io.reactivex.rxjava3.internal.functions.Functions;
import io.reactivex.rxjava3.subjects.CompletableSubject;
import io.reactivex.rxjava3.subjects.SingleSubject;

public class RxBleConnectionMock implements RxBleConnection {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@
import java.util.List;
import java.util.Map;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;

import io.reactivex.Observable;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.subjects.BehaviorSubject;
import io.reactivex.subjects.ReplaySubject;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.disposables.Disposable;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Supplier;
import io.reactivex.rxjava3.subjects.BehaviorSubject;
import io.reactivex.rxjava3.subjects.ReplaySubject;

import static io.nrbtech.rxandroidble.RxBleConnection.RxBleConnectionState.CONNECTED;
import static io.nrbtech.rxandroidble.RxBleConnection.RxBleConnectionState.CONNECTING;
Expand Down Expand Up @@ -272,9 +273,9 @@ public void addAdvertisedUUID(UUID advertisedUUID) {

@Override
public Observable<RxBleConnection> establishConnection(boolean autoConnect) {
return Observable.defer(new Callable<Observable<RxBleConnection>>() {
return Observable.defer(new Supplier<ObservableSource<? extends RxBleConnection>>() {
@Override
public Observable<RxBleConnection> call() {
public ObservableSource<? extends RxBleConnection> get() {
if (isConnected.compareAndSet(false, true)) {
return RxBleDeviceMock.this.emitConnectionWithoutCompleting()
.doOnSubscribe(new Consumer<Disposable>() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import io.nrbtech.rxandroidble.RxBleClient
import io.nrbtech.rxandroidble.RxBleConnection
import io.nrbtech.rxandroidble.scan.ScanFilter
import io.nrbtech.rxandroidble.scan.ScanSettings
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.PublishSubject
import spock.lang.Specification

public class RxBleClientMockLegacyTest extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import io.nrbtech.rxandroidble.RxBleConnection
import io.nrbtech.rxandroidble.internal.ScanResultInterface
import io.nrbtech.rxandroidble.scan.ScanFilter
import io.nrbtech.rxandroidble.scan.ScanSettings
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.subjects.PublishSubject
import spock.lang.Specification

public class RxBleClientMockTest extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import io.nrbtech.rxandroidble.exceptions.BleGattCharacteristicException
import io.nrbtech.rxandroidble.exceptions.BleGattDescriptorException
import io.nrbtech.rxandroidble.mockrxandroidble.callbacks.results.RxBleGattReadResultMock
import io.nrbtech.rxandroidble.mockrxandroidble.callbacks.results.RxBleGattWriteResultMock
import io.reactivex.Observable
import io.reactivex.subjects.PublishSubject
import io.reactivex.rxjava3.core.Observable
import io.reactivex.rxjava3.subjects.PublishSubject
import spock.lang.Specification

public class RxBleConnectionMockTest extends Specification {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,11 @@
import bleshadow.dagger.Provides;
import bleshadow.javax.inject.Named;
import bleshadow.javax.inject.Provider;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.functions.Function;
import io.reactivex.plugins.RxJavaPlugins;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.plugins.RxJavaPlugins;
import io.reactivex.rxjava3.schedulers.Schedulers;

@ClientScope
@Component(modules = {ClientComponent.ClientModule.class})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@

import bleshadow.javax.inject.Inject;
import io.nrbtech.rxandroidble.internal.RxBleLog;
import io.reactivex.Observable;
import io.reactivex.ObservableEmitter;
import io.reactivex.ObservableOnSubscribe;
import io.reactivex.Observer;
import io.reactivex.functions.Cancellable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableEmitter;
import io.reactivex.rxjava3.core.ObservableOnSubscribe;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.functions.Cancellable;
import io.reactivex.rxjava3.schedulers.Schedulers;

/**
* Observes Bluetooth adapter state. This responds to user interactions as well as system controlled state changes.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import java.util.Set;
import java.util.UUID;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;


public abstract class RxBleClient {
Expand Down Expand Up @@ -171,7 +171,7 @@ public static void updateLogOptions(LogOptions logOptions) {
* - If the device is in {@link State#BLUETOOTH_NOT_AVAILABLE} then this {@link Observable} will complete because any other checks
* will not be performed as devices are not expected to obtain bluetooth capabilities during runtime
*
* To get the initial {@link State} and then observe changes you can use: `observeStateChanges().startWith(getState())`.
* To get the initial {@link State} and then observe changes you can use: `observeStateChanges().startWithItem(getState())`.
*
* @return the observable
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,20 +39,20 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;

import bleshadow.dagger.Lazy;
import bleshadow.javax.inject.Inject;
import bleshadow.javax.inject.Named;
import io.reactivex.Maybe;
import io.reactivex.MaybeSource;
import io.reactivex.Observable;
import io.reactivex.ObservableSource;
import io.reactivex.Scheduler;
import io.reactivex.functions.Action;
import io.reactivex.functions.Consumer;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.rxjava3.core.Maybe;
import io.reactivex.rxjava3.core.MaybeSource;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableSource;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.functions.Action;
import io.reactivex.rxjava3.functions.Consumer;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.functions.Predicate;
import io.reactivex.rxjava3.functions.Supplier;

class RxBleClientImpl extends RxBleClient {

Expand Down Expand Up @@ -151,9 +151,9 @@ public Set<RxBleDevice> getConnectedPeripherals() {

@Override
public Observable<ScanResult> scanBleDevices(final ScanSettings scanSettings, final ScanFilter... scanFilters) {
return Observable.defer(new Callable<ObservableSource<? extends ScanResult>>() {
return Observable.defer(new Supplier<ObservableSource<? extends ScanResult>>() {
@Override
public Observable<ScanResult> call() {
public Observable<ScanResult> get() {
scanPreconditionVerifier.verify(scanSettings.shouldCheckLocationProviderState());
final ScanSetup scanSetup = scanSetupBuilder.build(scanSettings, scanFilters);
final Operation<RxBleInternalScanResult> scanOperation = scanSetup.scanOperation;
Expand All @@ -180,9 +180,9 @@ public BackgroundScanner getBackgroundScanner() {
@Override
@Deprecated
public Observable<RxBleScanResult> scanBleDevices(@Nullable final UUID... filterServiceUUIDs) {
return Observable.defer(new Callable<ObservableSource<? extends RxBleScanResult>>() {
return Observable.defer(new Supplier<ObservableSource<? extends RxBleScanResult>>() {
@Override
public ObservableSource<? extends RxBleScanResult> call() {
public ObservableSource<? extends RxBleScanResult> get() {
scanPreconditionVerifier.verify(true);
return initializeScan(filterServiceUUIDs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import io.reactivex.Completable;
import io.reactivex.Observable;
import io.reactivex.ObservableTransformer;
import io.reactivex.Scheduler;
import io.reactivex.Single;
import io.reactivex.rxjava3.core.Completable;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.ObservableTransformer;
import io.reactivex.rxjava3.core.Scheduler;
import io.reactivex.rxjava3.core.Single;

/**
* The BLE connection handle, supporting GATT operations. Operations are enqueued and the library makes sure that they are not
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import io.nrbtech.rxandroidble.internal.connection.RxBleGattCallback;
import io.nrbtech.rxandroidble.internal.serialization.ConnectionOperationQueue;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.core.Scheduler;

/**
* Represents a custom operation that will be enqueued for future execution within the client instance.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import io.nrbtech.rxandroidble.exceptions.BleGattCallbackTimeoutException;
import io.nrbtech.rxandroidble.exceptions.BleGattException;

import io.reactivex.Observable;
import io.reactivex.rxjava3.core.Observable;


public interface RxBleDevice {
Expand All @@ -20,7 +20,7 @@ public interface RxBleDevice {
* Observe changes to connection state of the device's {@link android.bluetooth.BluetoothGatt}.
* This Observable will never emit errors.
*
* If you would like to have the initial state as well you can use observeConnectionStateChanges().startWith(getConnectionState())
* If you would like to have the initial state as well you can use observeConnectionStateChanges().startWithItem(getConnectionState())
*
* NOTE: This is a convenience function for easy state changes monitoring of an individual peripheral that may be useful in the UI.
* It is not meant to be a trigger for reconnecting a particular device—for this purpose one should react on the errors emitted from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
import java.util.UUID;
import java.util.concurrent.Callable;

import io.reactivex.Observable;
import io.reactivex.Single;
import io.reactivex.functions.Function;
import io.reactivex.functions.Predicate;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Single;
import io.reactivex.rxjava3.functions.Function;
import io.reactivex.rxjava3.functions.Predicate;

/**
* Service discovery result containing list of services and characteristics within the services.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import io.nrbtech.rxandroidble.internal.connection.RxBleGattCallback;
import io.nrbtech.rxandroidble.internal.serialization.ConnectionOperationQueue;

import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.Scheduler;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;
import io.reactivex.rxjava3.core.Scheduler;

/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@


/**
* An exception being emitted from an {@link io.reactivex.Observable} returned by the function
* An exception being emitted from an {@link io.reactivex.rxjava3.core.Observable} returned by the function
* {@link io.nrbtech.rxandroidble.RxBleDevice#establishConnection(boolean)} or other establishConnection() overloads when this kind
* of observable was already subscribed and {@link io.nrbtech.rxandroidble.RxBleConnection} is currently being established or active.
*
* <p>
* To prevent this exception from being emitted one must either:<br>
* * always unsubscribe from the above mentioned Observable before subscribing again<br>
* * {@link io.reactivex.Observable#share()} or {@link io.reactivex.Observable#publish()} the above mentioned
* * {@link io.reactivex.rxjava3.core.Observable#share()} or {@link io.reactivex.rxjava3.core.Observable#publish()} the above mentioned
* Observable so it will be subscribed only once
* </p>
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

import java.nio.ByteBuffer;

import io.reactivex.Emitter;
import io.reactivex.Flowable;
import io.reactivex.functions.Consumer;
import io.reactivex.rxjava3.core.Emitter;
import io.reactivex.rxjava3.core.Flowable;
import io.reactivex.rxjava3.functions.Consumer;

/**
* TODO It may be possible to introduce backpressure here.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

import bleshadow.javax.inject.Inject;
import bleshadow.javax.inject.Named;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.core.Observer;

/**
* An Observable that emits false if an attempt to scan with {@link io.nrbtech.rxandroidble.RxBleClient#scanBleDevices(UUID...)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import android.bluetooth.BluetoothDevice;

import com.jakewharton.rxrelay2.BehaviorRelay;
import com.jakewharton.rxrelay3.BehaviorRelay;
import io.nrbtech.rxandroidble.ClientComponent;
import io.nrbtech.rxandroidble.ClientComponent.NamedSchedulers;
import io.nrbtech.rxandroidble.RxBleConnection;
Expand All @@ -20,7 +20,7 @@
import bleshadow.dagger.Module;
import bleshadow.dagger.Provides;
import bleshadow.javax.inject.Named;
import io.reactivex.Scheduler;
import io.reactivex.rxjava3.core.Scheduler;

@Module(subcomponents = ConnectionComponent.class)
public abstract class DeviceModule {
Expand Down
Loading