Comments (12)
Thanks for testing the lib! I'll push sone updates asap.
from android-ble-library.
What result would you expect in that case? In both success
and fail
callbacks, the BluetoothDevice
is @NonNull
. Should I add another callback for invalid state? Remove the annotation in fail
or 'success' (set to @Nullable
)? Right now it reports success
, as you are indeed disconnected.
It's only this one case when the BluetoohtDevice
may be null.
from android-ble-library.
The BluetoothDevice
could also be set in the BlueManager's constructor, instead of calling it in connect(..)
. But that would break a lot when upgrading to the next version. What do you think?
from android-ble-library.
From disconnect javadoc
Does nothing if device was not connected.
In this case, I'd expect the call to do nothing, since we are not connected.
Does doing nothing also invoke fail? I'm not sure if that's what I'd expect, but I understand that you'd rather invoke one of the two, tho I find done is more appropriate in this case.
First option would be to remove the @nonnull annotation from BluetoothDevice and set it to @nullable. That'd fix kotlin expectations, tho it's a breaking change that should be added to release notes.
As a second, more complex approach, would you consider an approach similar to RxJava's Maybe? It either emits onSuccess, onError or onComplete
From its javadoc: onSuccess, onError and onComplete are mutually exclusive events
onComplete's name might be misleading and developers might think it's invoked after done, so maybe something like ignored or skipped
I'd maybe go for the 1st approach. Adding a ignored callback means increasing the complexity of the library. Is there any usecase for such a callback?
Regarding the BluetoothDevice as a parameter to BleManager, that'd also break the possibility connect to multiple devices with a single BleManager. I don't know how desirable that is or if people are using it that way.
If it's not desirable to reuse a BleManager for multiple devices, then I'd definitely enforce it as a constructor parameter to avoid unexpected issues. Otherwise, I'd leave it as it.
from android-ble-library.
I've already started implementing invalid
callback to each request. It would only be called when connect
was never called and BluetoothDevice
is null. At least so far. That would also include Sleep request (which doesn't need BluetoothDevice
, actually, but for consistency. And I left @NonNull
in both done
and fail
callbacks. That way, I think, is the most "backwards compatible", as you don't need to make any changes, you don't need to handle the new invalid
callback and you are guaranteed that success
and fail
will indeed have non-null parameter.
RxJava approach also seems good, but that would break everything.
Btw, how does the lib work with Kotlin? I tried to make it Kotlin-firendly, but actually never tried it with it.
from android-ble-library.
Thanks for the quick response!
There are no differences when using it from kotlin, It's straightforward.
The thing is, if a parameter is annotated as @nonnull BluetootDevice, kotlin's type is BluetoothDevice, whereas if it's @nullable the type is BluetoothDevice?, which is different from the non-question mark type. If a non-null parameter receives null, it's a runtime error because it's not of the type it expects.
from android-ble-library.
But there are those thing that make a library more Kotlin'y, like @Nullable
or @NonNull
that, that you already mentioned, that are converted to optional or not optional fields, but also callbacks as a last parameter can be open, etc. I just wonder if anything could be improved to make it better before going to final version.
from android-ble-library.
sorry I misunderstood your question
I haven't found any issues, but I'm not that experienced with Kotlin
I know of two interop guides, but I guess you already checked that
https://kotlinlang.org/docs/reference/java-to-kotlin-interop.html
https://android.github.io/kotlin-guides/interop.html
from android-ble-library.
Ok, this issue should be fixed with the new PR. Would you like to have a look at it before I merge?
from android-ble-library.
I'm taking a look but I don't expect to be of help, it's a complex code
from android-ble-library.
Released in beta3.
from android-ble-library.
It's fixed, congrats and thanks!!
from android-ble-library.
Related Issues (20)
- Assert failed: phy_cnt < 3. More than three phys provided HOT 2
- Mismatch Java version in sample apps and the library HOT 2
- Server closes all connections with error 0x101 HOT 1
- Android is moving bluetooth scan client to opportunistic more than it should HOT 2
- Send data over 10k charcter HOT 2
- Connection retries block on the main thread HOT 8
- Connection state is not updated when cancelled during the thread sleep time HOT 1
- NullPointerException in BleManagerHandler$3.onConnectionStateChange
- Devices are not reconnecting after upgrade from 2.6.1 to 2.7.0 HOT 3
- Question about support of this lib and the new one HOT 1
- Is there any adaptation for Android 14? HOT 1
- What would cause GATT services to be invalidated on previously bonded peripherals? HOT 2
- Null reference exception when calling disconnect HOT 2
- Sometimes onServiceDiscoverd is not called when connecting. HOT 1
- Samsung Tab S6 Lite: Connection Parameter Negotiation HOT 1
- Catch SecurityException from setCharacteristicNotification HOT 2
- NullPointerException android.bluetooth.BluetoothGattServer.cancelConnection(android.bluetooth.BluetoothDevice)' on a null object reference HOT 3
- Library DefaultMtuSplitter is splitting incorrectly for android OS 14 HOT 8
- How to Catch Exception with RequestFailedException HOT 1
- Ask a question, thank you HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-ble-library.