From f89c44ef9b8a5fbed6c6175acb11f6e428998b61 Mon Sep 17 00:00:00 2001 From: christianrowlands Date: Tue, 9 Jan 2024 10:28:50 -0500 Subject: [PATCH] Make it easier to click the wifi item to navigate to the details and 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 --- .../ui/wifi/WifiDetailsScreen.kt | 167 +++++++++--------- .../ui/wifi/WifiDetailsViewModel.kt | 8 +- .../networksurvey/ui/wifi/WifiRssiChart.kt | 26 +-- .../res/layout/fragment_wifi_network_item.xml | 9 +- 4 files changed, 93 insertions(+), 117 deletions(-) diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsScreen.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsScreen.kt index 22014bb3..41ba6b47 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsScreen.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsScreen.kt @@ -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 @@ -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 @@ -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) + ) ) ) - ) + } } } } diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsViewModel.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsViewModel.kt index d4f6352b..1f3e5d0f 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsViewModel.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiDetailsViewModel.kt @@ -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. @@ -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") diff --git a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiRssiChart.kt b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiRssiChart.kt index 24f37686..b42f01d1 100644 --- a/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiRssiChart.kt +++ b/networksurvey/src/main/java/com/craxiom/networksurvey/ui/wifi/WifiRssiChart.kt @@ -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(), @@ -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( maxY = MAX_WIFI_RSSI, minY = MIN_WIFI_RSSI, diff --git a/networksurvey/src/main/res/layout/fragment_wifi_network_item.xml b/networksurvey/src/main/res/layout/fragment_wifi_network_item.xml index a7a72f6e..a73e66e9 100644 --- a/networksurvey/src/main/res/layout/fragment_wifi_network_item.xml +++ b/networksurvey/src/main/res/layout/fragment_wifi_network_item.xml @@ -19,8 +19,7 @@ android:layout_weight="1" android:ellipsize="end" android:maxLines="1" - android:text="" - android:textIsSelectable="true" /> + android:text="" /> + android:text="" /> + android:text="" />