refactor: migrate nodeDB to Room database (#717)

This commit is contained in:
Andre K 2023-09-05 08:19:26 -03:00 committed by GitHub
parent 99d7147efe
commit 83722159be
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
14 changed files with 742 additions and 148 deletions

View file

@ -2,20 +2,25 @@ package com.geeksville.mesh
import android.graphics.Color
import android.os.Parcelable
import androidx.room.Embedded
import androidx.room.Entity
import androidx.room.PrimaryKey
import com.geeksville.mesh.MeshProtos.User
import com.geeksville.mesh.util.GPSFormat
import com.geeksville.mesh.util.bearing
import com.geeksville.mesh.util.latLongToMeter
import com.geeksville.mesh.util.anonymize
import kotlinx.parcelize.Parcelize
import kotlinx.serialization.Serializable
/**
* Room [Embedded], [Entity] and [PrimaryKey] annotations and imports can be removed when only using the API.
* For details check the AIDL interface in [com.geeksville.mesh.IMeshService]
*/
//
// model objects that directly map to the corresponding protobufs
//
@Serializable
@Parcelize
data class MeshUser(
val id: String,
@ -41,7 +46,6 @@ data class MeshUser(
else hwModel.name.replace('_', '-').replace('p', '.').lowercase()
}
@Serializable
@Parcelize
data class Position(
val latitude: Double,
@ -94,7 +98,6 @@ data class Position(
}
@Serializable
@Parcelize
data class DeviceMetrics(
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
@ -122,7 +125,6 @@ data class DeviceMetrics(
}
}
@Serializable
@Parcelize
data class EnvironmentMetrics(
val time: Int = currentTime(), // default to current time in secs (NOT MILLISECONDS!)
@ -154,16 +156,22 @@ data class EnvironmentMetrics(
}
}
@Serializable
@Parcelize
@Entity(tableName = "NodeInfo")
data class NodeInfo(
@PrimaryKey(autoGenerate = false)
val num: Int, // This is immutable, and used as a key
@Embedded(prefix = "user_")
var user: MeshUser? = null,
@Embedded(prefix = "position_")
var position: Position? = null,
var snr: Float = Float.MAX_VALUE,
var rssi: Int = Int.MAX_VALUE,
var lastHeard: Int = 0, // the last time we've seen this node in secs since 1970
@Embedded(prefix = "devMetrics_")
var deviceMetrics: DeviceMetrics? = null,
val channel: Int = 0,
@Embedded(prefix = "envMetrics_")
var environmentMetrics: EnvironmentMetrics? = null,
) : Parcelable {