@Parcelize is busted it seems - for now just use IDE generated code

This commit is contained in:
geeksville 2020-02-10 16:34:01 -08:00
parent a3198d3931
commit 9a0da9ef67
3 changed files with 106 additions and 13 deletions

View file

@ -1,9 +1,8 @@
# High priority
MVP features required for first public alpha
* show nodeinfo list on gui - one card per node
* make nodeinfo card not look like ass
* when a text arrives, move that node info card to the bottom on the window - put the text to the left of the card. with a small arrow/distance/shortname
* parcels are busted - something wrong with the Parcelize kotlin magic
* all chat in the app defaults to group chat
* make my android app show mesh state
* add app icon
@ -84,4 +83,5 @@ Don't leave device discoverable. Don't let unpaired users do things with device
* have phone use our local node number as its node number (instead of hardwired)
* if radio disconnects, we need to requeue a new connect attempt in RadioService
* don't do mesh based algoritm for node id assignment (initially) - instead just store in flash - possibly even in the initial alpha release do this hack
* show connection state on gui
* show connection state on gui
* parcels are busted - something wrong with the Parcelize kotlin magic

View file

@ -132,7 +132,9 @@ class MainActivity : AppCompatActivity(), Logging {
requestPermission()
val filter = IntentFilter()
filter.addAction("")
filter.addAction(MeshService.ACTION_MESH_CONNECTED)
filter.addAction(MeshService.ACTION_NODE_CHANGE)
filter.addAction(MeshService.ACTION_RECEIVED_DATA)
registerReceiver(meshServiceReceiver, filter)
}
@ -161,7 +163,7 @@ class MainActivity : AppCompatActivity(), Logging {
}
MeshService.ACTION_RECEIVED_DATA -> {
warn("TODO rxopaqe")
warn("TODO rxdata")
val sender = intent.getStringExtra(EXTRA_SENDER)!!
val payload = intent.getByteArrayExtra(EXTRA_PAYLOAD)!!
val typ = intent.getIntExtra(EXTRA_TYP, -1)

View file

@ -8,6 +8,7 @@ import android.content.*
import android.graphics.Color
import android.os.Build
import android.os.IBinder
import android.os.Parcel
import android.os.Parcelable
import androidx.annotation.RequiresApi
import androidx.core.app.NotificationCompat
@ -22,28 +23,108 @@ import com.geeksville.util.exceptionReporter
import com.geeksville.util.toOneLineString
import com.geeksville.util.toRemoteExceptions
import com.google.protobuf.ByteString
import kotlinx.android.parcel.Parcelize
import java.nio.charset.Charset
class RadioNotConnectedException() : Exception("Can't find radio")
// model objects that directly map to the corresponding protobufs
@Parcelize
data class MeshUser(val id: String, val longName: String, val shortName: String) :
Parcelable
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readString()!!,
parcel.readString()!!,
parcel.readString()!!
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeString(id)
parcel.writeString(longName)
parcel.writeString(shortName)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<MeshUser> {
override fun createFromParcel(parcel: Parcel): MeshUser {
return MeshUser(parcel)
}
override fun newArray(size: Int): Array<MeshUser?> {
return arrayOfNulls(size)
}
}
}
@Parcelize
data class Position(val latitude: Double, val longitude: Double, val altitude: Int) :
Parcelable
Parcelable {
constructor(parcel: Parcel) : this(
parcel.readDouble(),
parcel.readDouble(),
parcel.readInt()
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeDouble(latitude)
parcel.writeDouble(longitude)
parcel.writeInt(altitude)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<Position> {
override fun createFromParcel(parcel: Parcel): Position {
return Position(parcel)
}
override fun newArray(size: Int): Array<Position?> {
return arrayOfNulls(size)
}
}
}
@Parcelize
data class NodeInfo(
val num: Int, // This is immutable, and used as a key
var user: MeshUser? = null,
var position: Position? = null,
var lastSeen: Long? = null
) : Parcelable
) : Parcelable {
constructor(parcel: Parcel) : this(
parcel.readInt(),
parcel.readParcelable(MeshUser::class.java.classLoader),
parcel.readParcelable(Position::class.java.classLoader),
parcel.readValue(Long::class.java.classLoader) as? Long
) {
}
override fun writeToParcel(parcel: Parcel, flags: Int) {
parcel.writeInt(num)
parcel.writeParcelable(user, flags)
parcel.writeParcelable(position, flags)
parcel.writeValue(lastSeen)
}
override fun describeContents(): Int {
return 0
}
companion object CREATOR : Parcelable.Creator<NodeInfo> {
override fun createFromParcel(parcel: Parcel): NodeInfo {
return NodeInfo(parcel)
}
override fun newArray(size: Int): Array<NodeInfo?> {
return arrayOfNulls(size)
}
}
}
/**
* Handles all the communication with android apps. Also keeps an internal model
@ -113,6 +194,16 @@ class MeshService : Service(), Logging {
private fun broadcastNodeChange(info: NodeInfo) {
debug("Broadcasting node change $info")
val intent = Intent(ACTION_NODE_CHANGE)
/*
if (info.user == null)
info.user = MeshUser("x", "y", "z")
if (info.position == null)
info.position = Position(1.5, 1.6, 3)
*/
intent.putExtra(EXTRA_NODEINFO, info)
explicitBroadcast(intent)
}
@ -298,7 +389,7 @@ class MeshService : Service(), Logging {
nodeDBbyID[userId] = info
// parcelable is busted
// broadcastNodeChange(info)
broadcastNodeChange(info)
}
/// Generate a new mesh packet builder with our node as the sender, and the specified node num