feat: Add role to NodeInfo (#1174)

This commit is contained in:
James Rich 2024-08-10 06:17:51 -05:00 committed by GitHub
parent 8afa5f9313
commit 2109426243
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 540 additions and 2 deletions

View file

@ -29,10 +29,17 @@ data class MeshUser(
val shortName: String,
val hwModel: MeshProtos.HardwareModel,
val isLicensed: Boolean = false,
@ColumnInfo(name = "role", defaultValue = "0")
val role: Int = 0,
) : Parcelable {
override fun toString(): String {
return "MeshUser(id=${id.anonymize}, longName=${longName.anonymize}, shortName=${shortName.anonymize}, hwModel=${hwModelString}, isLicensed=${isLicensed})"
return "MeshUser(id=${id.anonymize}, " +
"longName=${longName.anonymize}, " +
"shortName=${shortName.anonymize}, " +
"hwModel=$hwModelString, " +
"isLicensed=$isLicensed, " +
"role=$role)"
}
/** Create our model object from a protobuf.
@ -43,6 +50,7 @@ data class MeshUser(
p.shortName,
p.hwModel,
p.isLicensed,
p.roleValue
)
fun toProto(): MeshProtos.User =
@ -52,6 +60,7 @@ data class MeshUser(
.setShortName(shortName)
.setHwModel(hwModel)
.setIsLicensed(isLicensed)
.setRoleValue(role)
.build()
/** a string version of the hardware model, converted into pretty lowercase and changing _ to -, and p to dot

View file

@ -32,8 +32,9 @@ import com.geeksville.mesh.database.entity.QuickChatAction
AutoMigration (from = 5, to = 6),
AutoMigration (from = 6, to = 7),
AutoMigration (from = 7, to = 8),
AutoMigration (from = 8, to = 9),
],
version = 8,
version = 9,
exportSchema = true,
)
@TypeConverters(Converters::class)

View file

@ -52,6 +52,7 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.tooling.preview.PreviewParameter
import androidx.compose.ui.unit.dp
import com.geeksville.mesh.ConfigProtos
import com.geeksville.mesh.ConfigProtos.Config.DeviceConfig
import com.geeksville.mesh.MeshProtos
import com.geeksville.mesh.NodeInfo
import com.geeksville.mesh.R
@ -252,6 +253,13 @@ fun NodeInfo(
style = style,
)
}
val role = thatNodeInfo.user?.role
role?.let {
Text(
text = DeviceConfig.Role.forNumber(it).name,
fontSize = MaterialTheme.typography.button.fontSize
)
}
val nodeId = thatNodeInfo.user?.id
if (nodeId != null) {
Text(text = nodeId, fontSize = MaterialTheme.typography.button.fontSize)