feat: add node colors (#618)

master
Andre K 2023-04-13 17:54:52 -03:00 zatwierdzone przez GitHub
rodzic dc596e25a2
commit a8be41d158
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
2 zmienionych plików z 18 dodań i 2 usunięć

Wyświetl plik

@ -1,5 +1,6 @@
package com.geeksville.mesh
import android.graphics.Color
import android.os.Parcelable
import com.geeksville.mesh.util.bearing
import com.geeksville.mesh.util.latLongToMeter
@ -153,6 +154,15 @@ data class NodeInfo(
var environmentMetrics: EnvironmentMetrics? = null,
) : Parcelable {
val colors: Pair<Int, Int>
get() { // returns foreground and background @ColorInt for each 'num'
val r = (num and 0xFF0000) shr 16
val g = (num and 0x00FF00) shr 8
val b = num and 0x0000FF
val brightness = ((r * 0.299) + (g * 0.587) + (b * 0.114)) / 255
return Pair(if (brightness > 0.5) Color.BLACK else Color.WHITE, Color.rgb(r, g, b))
}
val batteryLevel get() = deviceMetrics?.batteryLevel
val voltage get() = deviceMetrics?.voltage
val batteryStr get() = if (batteryLevel in 1..100) String.format("%d%%", batteryLevel) else ""

Wyświetl plik

@ -1,5 +1,6 @@
package com.geeksville.mesh.ui
import android.content.res.ColorStateList
import android.os.Bundle
import android.text.method.LinkMovementMethod
import android.view.LayoutInflater
@ -205,8 +206,13 @@ class UsersFragment : ScreenFragment("Users"), Logging {
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val n = nodes[position]
val user = n.user
holder.chipNode.text = user?.shortName ?: "UNK"
val name = user?.longName ?: "Unknown node"
val (textColor, nodeColor) = n.colors
with(holder.chipNode) {
text = user?.shortName ?: "UNK"
chipBackgroundColor = ColorStateList.valueOf(nodeColor)
setTextColor(textColor)
}
val name = user?.longName ?: getString(R.string.unknown_username)
holder.nodeNameView.text = name
val pos = n.validPosition