Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

would it make sense to rename the variable mBatteryLabel since it is not just for battery level anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice point, but I think the related PR in radar-commons-android was already closed a long time ago, I just missed closing it here.

If I add this again now, it will likely introduce another merge conflict in the ktor-coroutines PR, which already has quite a few conflicts and probably needs some rework as well. I’m thinking of picking that up a bit later.

Would it be okay if we add this functionality at that time instead?

}
}

private fun updateSourceName() {
// \u2014 == —
sourceNameCache.applyIfChanged(sourceName ?: "\u2014") {
Expand Down