Skip to content

Commit

Permalink
improved minor implementations on RxBLE. Fix to API 33
Browse files Browse the repository at this point in the history
  • Loading branch information
hpsaturn committed Jan 28, 2025
1 parent 93ecea7 commit c5ff052
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 27 deletions.
8 changes: 4 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':libtoolscommon')

implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.12.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.multidex:multidex:2.0.1'

Expand All @@ -66,7 +66,7 @@ dependencies {
implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
implementation 'com.jakewharton.rx2:replaying-share:2.2.0'
implementation 'com.polidea.rxandroidble2:rxandroidble:1.17.2'
implementation 'com.polidea.rxandroidble2:rxandroidble:1.19.0'

implementation 'com.github.pwittchen:reactivewifi-rx2:0.3.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
Expand All @@ -76,7 +76,7 @@ dependencies {
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'org.osmdroid:osmdroid-android:6.1.5'

implementation 'com.google.android.gms:play-services-location:21.3.0' // Smartlocation fails with higher version
implementation 'com.google.android.gms:play-services-location:20.0.0' // Smartlocation fails with higher version
implementation 'com.github.jemshit:DiscreteScrollView:1.5.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.DialogFragment;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
Expand All @@ -25,7 +26,7 @@
/**
* Created by Antonio Vanegas @hpsaturn on 7/1/18.
*/
public abstract class BaseActivity extends RxAppCompatActivity {
public abstract class BaseActivity extends AppCompatActivity {

public static String TAG = BaseActivity.class.getSimpleName();

Expand Down
29 changes: 14 additions & 15 deletions app/src/main/java/hpsaturn/pollutionreporter/common/BLEHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,32 @@

public class BLEHandler {

private static String TAG = BLEHandler.class.getSimpleName();
private static final String TAG = BLEHandler.class.getSimpleName();

private Context ctx;
private OnBLEConnectionListener listener;
private String address;
private final Context ctx;
private final OnBLEConnectionListener listener;
private final String address;

private UUID serviceId = UUID.fromString("c8d1d262-861f-4082-947e-f383a259aaf3");
private UUID charactSensorDataUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae01");
private UUID charactConfigUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae02");
private UUID charactStatusUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae03");
private final UUID serviceId = UUID.fromString("c8d1d262-861f-4082-947e-f383a259aaf3");
private final UUID charactSensorDataUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae01");
private final UUID charactConfigUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae02");
private final UUID charactStatusUuid = UUID.fromString("b0f332a8-a5aa-4f3f-bb43-f99e7791ae03");

private PublishSubject<Boolean> disconnectTriggerSubject = PublishSubject.create();
private final PublishSubject<Boolean> disconnectTriggerSubject = PublishSubject.create();
private Subscription connectionSubscription;
private Observable<RxBleConnection> connectionObservable;
private Disposable scanDisposable;
private RxBleClient rxBleClient;
private RxBleDevice bleDevice;
private final CompositeDisposable compositeDisposable = new CompositeDisposable();

public BLEHandler(Context ctx, String address, OnBLEConnectionListener listener) {
this.ctx = ctx;
this.address = address;
this.listener = listener;
RxBleClient rxBleClient = AppData.getRxBleClient(ctx);
bleDevice = rxBleClient.getBleDevice(address);
connectionObservable = prepareConnectionObservable();

}

public interface OnBLEConnectionListener {
Expand Down Expand Up @@ -75,10 +78,6 @@ public interface OnBLEConnectionListener {


public void connect() {
rxBleClient = AppData.getRxBleClient(ctx);
bleDevice = rxBleClient.getBleDevice(address);
connectionObservable = prepareConnectionObservable();


if (isConnected()) {
triggerDisconnect();
Expand Down Expand Up @@ -116,7 +115,7 @@ public void setupNotification() {
if (isConnected()) {
final Disposable disposable = connectionObservable
.flatMap(rxBleConnection -> rxBleConnection.setupNotification(charactSensorDataUuid))
.doOnNext(notificationObservable -> { notificationHasBeenSetUp(); })
.doOnNext(notificationObservable -> notificationHasBeenSetUp())
.flatMap(notificationObservable -> notificationObservable)
.observeOn(AndroidSchedulers.mainThread())
.subscribe(this::onNotificationReceived, this::onNotificationSetupFailure);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,14 @@ private void actionRequestBLEPermission(){
Logger.i(TAG, "[PERM] request BLE permission" );
if(!getMain().isBLEGranted()) getMain().showDisclosureFragment(R.string.msg_ble_title,R.string.msg_ble_desc,R.drawable.ic_cpu);
else {
if (!PermissionUtil.hasLocationPermission(getContext())) getMain().requestBluetoothPermission();
if (!PermissionUtil.hasLocationPermission(requireContext())) getMain().requestBluetoothPermission();
else getMain().performBLEScan();
}
}

public void executeScan(){
Logger.i(TAG, "[BLE] perform device scanning.." );
getActivity().runOnUiThread(this::actionScan);
actionScan();
}

private void actionScan() {
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:8.2.2'
classpath 'com.google.gms:google-services:4.4.2'
classpath 'com.google.firebase:firebase-crashlytics-gradle:3.0.2'
classpath 'com.google.gms:google-services:4.3.13'
classpath 'com.google.firebase:firebase-crashlytics-gradle:2.9.1'
}
}

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ org.gradle.jvmargs=-Xmx3096m -Dfile.encoding=UTF-8 \
--add-exports=jdk.compiler/com.sun.tools.javac.code=ALL-UNNAMED \
--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED

mCompileSdkVersion=34
mCompileSdkVersion=33
mMinSdkVersion=23
mTargetSdkVersion=34
mTargetSdkVersion=33
mVersionCode=619
mVersionName=0.9.0
android.useAndroidX=true
Expand Down
2 changes: 1 addition & 1 deletion libtoolscommon
Submodule libtoolscommon updated 1 files
+0 −1 build.gradle

0 comments on commit c5ff052

Please sign in to comment.