feat: add some icons

This commit is contained in:
Fabian Christoffel
2023-06-26 11:35:36 +02:00
parent f3d56ba59c
commit 23b0f52fa1
13 changed files with 142 additions and 32 deletions

View File

@@ -20,6 +20,7 @@ interface Action {
interface Measurement {
fun getLabel(): String
fun getIcon(): Int?
fun getFormattedValue(): String
}
@@ -73,6 +74,18 @@ class DeviceListAdapter(
deviceNameView.text = result.name ?: "<N/A>"
macAddressView.text = result.address
signalStrengthView.text = "${result.rssi ?: "-"} dBm"
var signalStrengthIcon = R.drawable.signal_strength_weak
if (result.rssi >= -55) {
signalStrengthIcon = R.drawable.signal_strength_strong
} else if (result.rssi >= -80) {
signalStrengthIcon = R.drawable.signal_strength_medium
}
signalStrengthView.setCompoundDrawablesWithIntrinsicBounds(
0,
0,
signalStrengthIcon,
0
)
statusView.text = result.status
deviceActions.setOnClickListener {
val popup = PopupMenu(context, deviceActions)
@@ -103,12 +116,19 @@ class DeviceListAdapter(
parent: ViewGroup
): View {
val measurement = measurements[position]
val measurementView = convertView ?: LayoutInflater.from(parent.context)
.inflate(R.layout.row_measurements_list, parent, false)
measurementView.findViewById<TextView>(R.id.measurement_label).text =
measurements[position].getLabel()
val labelView = measurementView.findViewById<TextView>(R.id.measurement_label)
labelView.text = measurement.getLabel()
labelView.setCompoundDrawablesWithIntrinsicBounds(
measurement.getIcon() ?: 0,
0,
0,
0
)
measurementView.findViewById<TextView>(R.id.measurement_value).text =
measurements[position].getFormattedValue()
measurement.getFormattedValue()
measurementView.layoutParams.height = measurementsRowHeight
return measurementView
}

View File

@@ -50,6 +50,47 @@ fun decodeDemoPayload(bytes: ByteArray): DemoPayload {
return DemoPayload(ts, pressure, temp)
}
private fun demoPayloadToMeasurements(payload: DemoPayload): List<Measurement> {
return listOf(object : Measurement {
override fun getLabel(): String {
return "TS"
}
override fun getFormattedValue(): String {
return "${payload.sysTs} (${payload.ts})"
}
override fun getIcon(): Int? {
return R.drawable.baseline_access_time_24
}
}, object : Measurement {
override fun getLabel(): String {
return "Temperature"
}
override fun getFormattedValue(): String {
return "${payload.temperature} °C"
}
override fun getIcon(): Int? {
return R.drawable.baseline_device_thermostat_24
}
}, object : Measurement {
override fun getLabel(): String {
return "Pressure"
}
override fun getFormattedValue(): String {
return "${payload.pressure} hPa"
}
override fun getIcon(): Int? {
return R.drawable.baseline_compress_24
}
})
}
enum class DeviceStatus {
DISCOVERED, CONNECTED, BONDED, SUBSCRIBED
}
@@ -142,31 +183,7 @@ class KirbyDevice(
return emptyList()
}
val latest = measurements.last()
return listOf(object : Measurement {
override fun getLabel(): String {
return "TS"
}
override fun getFormattedValue(): String {
return "${latest.sysTs} (${latest.ts})"
}
}, object : Measurement {
override fun getLabel(): String {
return "Temperature"
}
override fun getFormattedValue(): String {
return "${latest.temperature} °C"
}
}, object : Measurement {
override fun getLabel(): String {
return "Pressure"
}
override fun getFormattedValue(): String {
return "${latest.pressure} hPa"
}
})
return demoPayloadToMeasurements(latest)
}
override fun getActions(): List<Action> {

View File

@@ -326,7 +326,7 @@ class MainActivity : AppCompatActivity() {
@SuppressLint("MissingPermission")
class DummyListEntry(override val address: String) : DeviceListEntry {
override var rssi: Int = 99
override var rssi: Int = -30
override val name: String = "Device 123"
override val status: String
@@ -369,6 +369,10 @@ class DummyListEntry(override val address: String) : DeviceListEntry {
override fun getFormattedValue(): String {
return "21.2 °C"
}
override fun getIcon(): Int? {
return R.drawable.baseline_device_thermostat_24
}
}, object : Measurement {
override fun getLabel(): String {
return "Pressure"
@@ -377,6 +381,10 @@ class DummyListEntry(override val address: String) : DeviceListEntry {
override fun getFormattedValue(): String {
return "232 bar"
}
override fun getIcon(): Int? {
return R.drawable.baseline_compress_24
}
})
}
}

View File

@@ -0,0 +1,6 @@
<vector android:height="20dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M11.99,2C6.47,2 2,6.48 2,12s4.47,10 9.99,10C17.52,22 22,17.52 22,12S17.52,2 11.99,2zM12,20c-4.42,0 -8,-3.58 -8,-8s3.58,-8 8,-8 8,3.58 8,8 -3.58,8 -8,8z"/>
<path android:fillColor="@android:color/white" android:pathData="M12.5,7H11v6l5.25,3.15 0.75,-1.23 -4.5,-2.67z"/>
</vector>

View File

@@ -0,0 +1,6 @@
<vector android:height="20dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M8,19h3v3h2v-3h3l-4,-4 -4,4zM16,4h-3L13,1h-2v3L8,4l4,4 4,-4zM4,9v2h16L20,9L4,9z"/>
<path android:fillColor="@android:color/white" android:pathData="M4,12h16v2H4z"/>
</vector>

View File

@@ -0,0 +1,5 @@
<vector android:height="20dp" android:tint="#000000"
android:viewportHeight="24" android:viewportWidth="24"
android:width="20dp" xmlns:android="http://schemas.android.com/apk/res/android">
<path android:fillColor="@android:color/white" android:pathData="M15,13L15,5c0,-1.66 -1.34,-3 -3,-3S9,3.34 9,5v8c-1.21,0.91 -2,2.37 -2,4 0,2.76 2.24,5 5,5s5,-2.24 5,-5c0,-1.63 -0.79,-3.09 -2,-4zM11,5c0,-0.55 0.45,-1 1,-1s1,0.45 1,1h-1v1h1v2h-1v1h1v2h-2L11,5z"/>
</vector>

View File

@@ -0,0 +1,17 @@
<vector android:height="16dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@color/greyDarker"
android:pathData="M17,4h3v16h-3zM5,14h3v6L5,20zM11,9h3v11h-3z" />
<path
android:fillColor="@android:color/black"
android:pathData="M5,14h3v6H5V14z" />
<path
android:fillColor="@android:color/black"
android:pathData="M5,14h3v6H5V14zM11,9h3v11h-3V9z" />
</vector>

View File

@@ -0,0 +1,12 @@
<vector android:height="16dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@color/black"
android:pathData="M17,4h3v16h-3zM5,14h3v6L5,20zM11,9h3v11h-3z" />
</vector>

View File

@@ -0,0 +1,15 @@
<vector android:height="16dp"
android:viewportHeight="24"
android:viewportWidth="24"
android:width="16dp"
xmlns:android="http://schemas.android.com/apk/res/android">
<path
android:fillColor="@color/greyDarker"
android:pathData="M17,4h3v16h-3zM5,14h3v6L5,20zM11,9h3v11h-3z" />
<path
android:fillColor="@android:color/black"
android:pathData="M5,14h3v6H5V14z" />
</vector>

View File

@@ -66,9 +66,11 @@
android:id="@+id/signal_strength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="2dp"
android:textSize="14sp"
app:layout_constraintTop_toTopOf="parent"
app:drawableEndCompat="@drawable/signal_strength_medium"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="-100 dBm" />
</androidx.constraintlayout.widget.ConstraintLayout>

View File

@@ -9,9 +9,11 @@
android:id="@+id/measurement_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawablePadding="2dp"
android:textSize="18sp"
app:layout_constraintTop_toTopOf="parent"
app:drawableStartCompat="@drawable/baseline_device_thermostat_24"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Temperature" />
<TextView

View File

@@ -3,4 +3,5 @@
<color name="black">#FF000000</color>
<color name="white">#FFFFFFFF</color>
<color name="grey">#ECECEC</color>
<color name="greyDarker">#D5D5D5</color>
</resources>