Skip to content

Commit

Permalink
Make it easier to click the wifi item to navigate to the details and …
Browse files Browse the repository at this point in the history
…make the details view selectable

I made it easier to click on the wifi item in the list by removing the select-ability of the text.
I also sped up the chart update interval to 1 second instead of 2
  • Loading branch information
christianrowlands committed Jan 9, 2024
1 parent 573c9d4 commit f89c44e
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.LazyListScope
import androidx.compose.foundation.lazy.rememberLazyListState
import androidx.compose.foundation.text.selection.SelectionContainer
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.MaterialTheme
Expand Down Expand Up @@ -65,99 +66,80 @@ private fun LazyListScope.chartItems(
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceAround
) {
Card(
modifier = Modifier
.fillMaxWidth(),
shape = MaterialTheme.shapes.large,
colors = CardDefaults.elevatedCardColors()
) {
Row(
SelectionContainer {
Card(
modifier = Modifier
.padding(vertical = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceEvenly
shape = MaterialTheme.shapes.large,
colors = CardDefaults.elevatedCardColors()
) {
Column(
horizontalAlignment = Alignment.CenterHorizontally
Row(
modifier = Modifier
.padding(vertical = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceEvenly
) {
Text(
text = if (hiddenSsid) HIDDEN_SSID_PLACEHOLDER else viewModel.wifiNetwork.ssid,
style = MaterialTheme.typography.titleMedium.copy(
color = Color(
LocalContext.current.getColor(
if (hiddenSsid) R.color.red else R.color.colorAccent
Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = if (hiddenSsid) HIDDEN_SSID_PLACEHOLDER else viewModel.wifiNetwork.ssid,
style = MaterialTheme.typography.titleMedium.copy(
color = Color(
LocalContext.current.getColor(
if (hiddenSsid) R.color.red else R.color.colorAccent
)
)
)
)
)
Text(
text = "SSID",
style = MaterialTheme.typography.labelMedium
)
Text(
text = "SSID",
style = MaterialTheme.typography.labelMedium
)
}

Column(
horizontalAlignment = Alignment.CenterHorizontally
) {
Text(
text = if (rssi == UNKNOWN_RSSI) "Unknown" else "${rssi.toInt()} dBm",
style = MaterialTheme.typography.titleMedium.copy(color = signalStrengthColor)
)
Text(
text = "Signal Strength",
style = MaterialTheme.typography.labelMedium
)
}
}

Column(
horizontalAlignment = Alignment.CenterHorizontally
Row(
modifier = Modifier
.padding(horizontal = padding, vertical = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = if (rssi == UNKNOWN_RSSI) "Unknown" else "${rssi.toInt()} dBm",
style = MaterialTheme.typography.titleMedium.copy(color = signalStrengthColor)
)
Text(
text = "Signal Strength",
style = MaterialTheme.typography.labelMedium
)
Column {
Text(
text = "BSSID: ${viewModel.wifiNetwork.bssid}",
style = MaterialTheme.typography.titleMedium
)
}
}
}

Row(
modifier = Modifier
.padding(horizontal = padding, vertical = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween
) {
Column {
Row(
modifier = Modifier
.padding(start = padding, end = padding, bottom = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = "BSSID: ${viewModel.wifiNetwork.bssid}",
text = viewModel.wifiNetwork.encryptionType,
style = MaterialTheme.typography.titleMedium
)
}
}

Row(
modifier = Modifier
.padding(start = padding, end = padding, bottom = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.SpaceBetween
) {
Text(
text = viewModel.wifiNetwork.encryptionType,
style = MaterialTheme.typography.titleMedium
)
}

Row(
modifier = Modifier
.padding(start = padding, end = padding, bottom = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.Start
) {
Text(
text = "Channel: ${viewModel.wifiNetwork.channel?.toString() ?: "Unknown"}",
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.width(padding * 2))
Text(
text = "${viewModel.wifiNetwork.frequency?.toString() ?: "Unknown"} MHz",
style = MaterialTheme.typography.titleMedium
)
}

if (viewModel.wifiNetwork.passpoint != null && viewModel.wifiNetwork.passpoint == true) {

Row(
modifier = Modifier
Expand All @@ -167,13 +149,34 @@ private fun LazyListScope.chartItems(
horizontalArrangement = Arrangement.Start
) {
Text(
text = "Passpoint",
style = MaterialTheme.typography.titleMedium.copy(
color = Color(
LocalContext.current.getColor(R.color.colorAccent)
text = "Channel: ${viewModel.wifiNetwork.channel?.toString() ?: "Unknown"}",
style = MaterialTheme.typography.titleMedium
)
Spacer(modifier = Modifier.width(padding * 2))
Text(
text = "${viewModel.wifiNetwork.frequency?.toString() ?: "Unknown"} MHz",
style = MaterialTheme.typography.titleMedium
)
}

if (viewModel.wifiNetwork.passpoint != null && viewModel.wifiNetwork.passpoint == true) {

Row(
modifier = Modifier
.padding(start = padding, end = padding, bottom = padding / 2)
.fillMaxWidth(),
verticalAlignment = Alignment.Top,
horizontalArrangement = Arrangement.Start
) {
Text(
text = "Passpoint",
style = MaterialTheme.typography.titleMedium.copy(
color = Color(
LocalContext.current.getColor(R.color.colorAccent)
)
)
)
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ import kotlin.reflect.KProperty
const val UNKNOWN_RSSI = -200f
const val MAX_WIFI_RSSI = -20f
const val MIN_WIFI_RSSI = -100f
private const val CHART_WIDTH = 60
private const val UPDATE_FREQUENCY = 2000L
private const val CHART_WIDTH = 120
private const val UPDATE_FREQUENCY = 1000L

/**
* The view model for the Wifi Details screen.
Expand Down Expand Up @@ -92,8 +92,8 @@ internal class WifiDetailsViewModel : ViewModel() {
if (rssi == UNKNOWN_RSSI && latestChartRssi.value != UNKNOWN_RSSI) {
unknownRssiCount++

if (unknownRssiCount <= 2) {
// Ignore the first couple times the RSSI is missing from the scan results since it
if (unknownRssiCount <= 1) {
// Ignore the first time the RSSI is missing from the scan results since it
// appears to be a common occurrence where a network is not found in a scan result.
// even though it is close to the device.
Timber.i("Ignoring the RSSI value of $rssi for ${wifiNetwork.ssid} since it is missing from the scan results")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ internal fun WifiRssiChart(
@Composable
private fun ComposeChart(modelProducer: CartesianChartModelProducer) {
ProvideChartStyle(rememberChartStyle(chartColors)) {
//val defaultLines = currentChartStyle.lineLayer.lines
CartesianChartHost(
modelProducer = modelProducer,
marker = rememberMarker(),
Expand All @@ -54,40 +53,17 @@ private fun ComposeChart(modelProducer: CartesianChartModelProducer) {
),
startAxis =
rememberStartAxis(
guideline = null,
horizontalLabelPosition = VerticalAxis.HorizontalLabelPosition.Inside,
itemPlacer = remember { AxisItemPlacer.Vertical.default({ _ -> 5 }) },
),
/*bottomAxis =
rememberBottomAxis(
titleComponent =
rememberTextComponent(
background = rememberShapeComponent(Shapes.pillShape, color2),
color = Color.White,
padding = axisTitlePadding,
margins = bottomAxisTitleMargins,
typeface = Typeface.MONOSPACE,
),
title = stringResource(R.string.y_axis_time),
),*/
fadingEdges = rememberFadingEdges(),
)
)
}
}

private const val COLOR_2_CODE = 0xff9db591

private val lineColor = Color(0xFF03A9F4)
private val color2 = Color(COLOR_2_CODE)
private val chartColors = listOf(lineColor, color2)
private val lineSpec = listOf(
lineSpec(
thickness = 4.dp,
backgroundShader = null,
shader = DynamicShaders.color(Color.DarkGray),
),
)
private val chartColors = listOf(lineColor)
private val axisValueOverrider = AxisValueOverrider.fixed<LineCartesianLayerModel>(
maxY = MAX_WIFI_RSSI,
minY = MIN_WIFI_RSSI,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
android:layout_weight="1"
android:ellipsize="end"
android:maxLines="1"
android:text=""
android:textIsSelectable="true" />
android:text="" />

<TextView
android:id="@+id/wifi_signal_strength"
Expand All @@ -43,8 +42,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/xx_small_margin"
android:text=""
android:textIsSelectable="true" />
android:text="" />

<TextView
android:id="@+id/encryption_type"
Expand Down Expand Up @@ -105,8 +103,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/xx_small_margin"
android:text=""
android:textIsSelectable="true" />
android:text="" />

</LinearLayout>

Expand Down

0 comments on commit f89c44e

Please sign in to comment.