diff --git a/app/src/main/java/org/radarcns/detail/SourceRowView.kt b/app/src/main/java/org/radarcns/detail/SourceRowView.kt index c6c1910..c92977e 100644 --- a/app/src/main/java/org/radarcns/detail/SourceRowView.kt +++ b/app/src/main/java/org/radarcns/detail/SourceRowView.kt @@ -53,6 +53,8 @@ class SourceRowView internal constructor( private val batteryLevelCache = ChangeRunner() private val sourceNameCache = ChangeRunner() private val statusCache = ChangeRunner() + private var pluginImageResource: Int = -1 + private var imageResourceRef: (SourceStatusListener.Status) -> Int = provider::imageResource private val splitRegex = this.mainActivity.getString(R.string.filter_split_regex).toRegex() @@ -149,7 +151,7 @@ class SourceRowView internal constructor( private fun updateSourceStatus() { statusCache.applyIfChanged(sourceState?.status ?: SourceStatusListener.Status.DISCONNECTED) { status -> logger.info("Source status is {}", status) - + updateSourceIcon(status) mStatusIcon.setImageResource(when(status) { SourceStatusListener.Status.CONNECTED -> R.drawable.avd_connected_circle SourceStatusListener.Status.DISCONNECTED -> R.drawable.baseline_circle_red_700_24dp @@ -163,6 +165,10 @@ class SourceRowView internal constructor( private fun updateBattery() { batteryLevelCache.applyIfChanged(sourceState?.batteryLevel ?: Float.NaN) { + if (pluginImageResource != -1) { + mBatteryLabel.setImageResource(pluginImageResource) + return@applyIfChanged + } mBatteryLabel.setImageResource(when { it.isNaN() -> R.drawable.baseline_battery_unknown_gray_24dp it < 0.1 -> R.drawable.baseline_battery_alert_red_700_24dp @@ -174,6 +180,13 @@ class SourceRowView internal constructor( } } + private fun updateSourceIcon(status: SourceStatusListener.Status) { + pluginImageResource = imageResourceRef(status) + if (pluginImageResource != -1) { + mBatteryLabel.setImageResource(pluginImageResource) + } + } + private fun updateSourceName() { // \u2014 == — sourceNameCache.applyIfChanged(sourceName ?: "\u2014") {