Skip to content

Commit

Permalink
[TASK] retries now accessible via RxSPP & RxOBEX connect
Browse files Browse the repository at this point in the history
  • Loading branch information
ddibiasi committed Dec 6, 2019
1 parent 4fb3bf7 commit 1a5515a
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 15 deletions.
9 changes: 4 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation"org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.core:core-ktx:1.0.2'
implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'androidx.core:core-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
androidTestImplementation 'androidx.test:runner:1.2.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
// Rx
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
implementation 'io.reactivex.rxjava2:rxjava:2.2.13'
Expand All @@ -62,7 +62,6 @@ dependencies {
implementation 'com.uber.autodispose:autodispose-android-archcomponents:1.3.0'
implementation 'com.uber.autodispose:autodispose-rxlifecycle:1.3.0'
// Funker
// implementation 'com.github.ddibiasi:Funker:0.0.4'
implementation project(path: ':funker')
}

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package nl.dibiasi.funkertest

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.runner.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.3.61'
repositories {
google()
jcenter()
maven { url 'https://jitpack.io' }
}
dependencies {
classpath 'com.android.tools.build:gradle:3.5.1'
classpath 'com.android.tools.build:gradle:3.5.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ open class BluetoothConnection(val blDevice: BluetoothDevice) {

/**
* Cancels running discovery and tries to connect to the device.
* @param retries How many times should be tried to connect to device. (Low end computer tend to not respond immediately)
* @param retries How many times should be tried to connect to device. (Low end computer tend to not respond immediately). If set to -1, it will try indefinitely.
*
*/
fun connect(uuid: UUID, retries: Int = 5, timeoutInMillis: Int = 1000) {
Expand All @@ -46,7 +46,7 @@ open class BluetoothConnection(val blDevice: BluetoothDevice) {
}
val bluetoothSocket = bluetoothSocket!!
var count = 0
while (!bluetoothSocket.isConnected && count < retries) {
while (!bluetoothSocket.isConnected && (count < retries || retries == -1)) {
try {
bluetoothSocket.connect()
} catch (e: IOException) {
Expand Down
6 changes: 3 additions & 3 deletions funker/src/main/java/at/dibiasi/funker/obex/RxOBEX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ class RxOBEX(val device: BluetoothDevice) : BluetoothConnection(device) {

/**
* Cancels running discovery and tries to connect to the device.
* @param retries
*/
fun connect(): Completable {
fun connect(retries: Int = 5): Completable {
return Completable.create { source ->
try {
connect(obexFiletransferUUID)
connect(uuid = obexFiletransferUUID, retries = retries)
source.onComplete()
} catch (e: Exception) {
source.onError(e)
}
}
}


/**
* @return returns somehow important bytes. couldn't find any documentation.
*
Expand Down
5 changes: 3 additions & 2 deletions funker/src/main/java/at/dibiasi/funker/rfcomm/RxSpp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ class RxSpp(val device: BluetoothDevice) : BluetoothConnection(device) {

/**
* Cancels running discovery and tries to connect to the device.
* @param retries
*/
fun connect(): Completable {
fun connect(retries: Int = 5): Completable {
return Completable.create { source ->
try {
connect(sppUuid)
connect(uuid = sppUuid, retries = retries)
source.onComplete()
} catch (e: java.lang.Exception) {
source.onError(e)
Expand Down

0 comments on commit 1a5515a

Please # to comment.