Skip to content

Commit

Permalink
Updated SourceRowView to show icons
Browse files Browse the repository at this point in the history
  • Loading branch information
this-Aditya committed May 10, 2024
1 parent 7f381ff commit db65dc2
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion app/src/main/java/org/radarcns/detail/SourceRowView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ class SourceRowView internal constructor(
private val batteryLevelCache = ChangeRunner<Float>()
private val sourceNameCache = ChangeRunner<String>()
private val statusCache = ChangeRunner<SourceStatusListener.Status>()
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()

Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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") {
Expand Down

0 comments on commit db65dc2

Please sign in to comment.