Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated SourceRowView to display icons for plugins #141

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
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)
}
}

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