kable icon indicating copy to clipboard operation
kable copied to clipboard

Feature request: Parcelable Advertisement on Android

Open eddieSullivan opened this issue 1 year ago • 2 comments

I wonder if you would consider making the AndroidAdvertisement implement Parcelable?

The Android native ScanResult implements the Parcelable interface, so I think this should be possible, though I don't know if there are internal details of the Advertisement implementation that make it more difficult.

The use case is an android view that shows a list of devices in range, implemented using Jetpack Compose. I would like to be able to seamlessly handle app configuration changes using rememberSaveable.

Yes, I could store the list of advertisements in a global singleton, outside of the view hierarchy, but that feels less in line with Android architectural idioms.

eddieSullivan avatar Dec 12 '23 15:12 eddieSullivan

And the same thing would be nice for Peripheral. Android's BluetoothDevice implements Parcelable.

eddieSullivan avatar Dec 12 '23 15:12 eddieSullivan

Sounds like a good feature to have. 👍

I'm currently pretty busy on other projects at the moment, but I'll try to find some time to work on this.

PRs are also welcome. 😁

twyatt avatar Dec 12 '23 17:12 twyatt

And the same thing would be nice for Peripheral. Android's BluetoothDevice implements Parcelable.

Having Kable's AndroidAdvertisement be Parcelable can be done, but unfortunately: I don't see a feasible way to do the same for AndroidPeripheral. As AnroidPeripheral is stateful (holds onto a connection) which cannot be written to a Parcel. Having Peripheral be stateful was done to make it have a more intuitive API.

Android's BluetoothDevice is Parcelable because it is stateless (is a thin wrapper around a BLE address), and from that stateless object, a BluetoothGatt is created (which holds the underlying connection).

twyatt avatar Mar 10 '24 00:03 twyatt

@eddieSullivan, #652 makes AndroidAdvertisement Parcelable.

You can test it with:

repositories {
    maven("https://oss.sonatype.org/content/repositories/snapshots")
}

dependencies {
    implementation("com.juul.kable:core:0.29.1-issue-610-1-SNAPSHOT")
}

twyatt avatar Mar 12 '24 17:03 twyatt

Shipped in 0.30.0.

twyatt avatar Mar 21 '24 18:03 twyatt