Skip to content

Commit 019837a

Browse files
committed
feat(ui): enhance GpsItem
1 parent b905d3c commit 019837a

File tree

1 file changed

+64
-41
lines changed
  • ui/src/main/java/com/github/umercodez/sensorspot/ui/screens/sensors/components

1 file changed

+64
-41
lines changed

ui/src/main/java/com/github/umercodez/sensorspot/ui/screens/sensors/components/GpsItem.kt

Lines changed: 64 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,21 @@ import androidx.compose.foundation.layout.padding
77
import androidx.compose.foundation.layout.width
88
import androidx.compose.foundation.shape.RoundedCornerShape
99
import androidx.compose.material3.ButtonDefaults
10+
import androidx.compose.material3.Card
11+
import androidx.compose.material3.CardDefaults
1012
import androidx.compose.material3.ListItem
1113
import androidx.compose.material3.ListItemDefaults
1214
import androidx.compose.material3.MaterialTheme
15+
import androidx.compose.material3.Surface
1316
import androidx.compose.material3.Switch
1417
import androidx.compose.material3.Text
1518
import androidx.compose.material3.TextButton
1619
import androidx.compose.runtime.Composable
1720
import androidx.compose.ui.Alignment
1821
import androidx.compose.ui.Modifier
1922
import androidx.compose.ui.draw.clip
23+
import androidx.compose.ui.graphics.Color
24+
import androidx.compose.ui.text.font.FontWeight
2025
import androidx.compose.ui.tooling.preview.Preview
2126
import androidx.compose.ui.unit.dp
2227
import com.github.umercodez.sensorspot.ui.SensorSpotTheme
@@ -32,48 +37,64 @@ fun GpsItem(
3237
locationPermissionGranted: Boolean = false,
3338
onGrantLocationPermissionClick: (() -> Unit)? = null
3439
) {
35-
ListItem(
40+
Card(
3641
modifier = modifier
3742
.fillMaxWidth()
38-
.padding(5.dp)
39-
.clip(RoundedCornerShape(16.dp)),
40-
headlineContent = {
41-
Row(
42-
verticalAlignment = Alignment.CenterVertically,
43-
) {
44-
Text("GPS")
45-
Spacer(Modifier.width(10.dp))
46-
if (!locationPermissionGranted) {
47-
TextButton(
48-
onClick = { onGrantLocationPermissionClick?.invoke() },
49-
colors = ButtonDefaults.textButtonColors(
50-
contentColor = MaterialTheme.colorScheme.error
51-
)
52-
) {
53-
Text("Grant Permission")
43+
.padding(horizontal = 10.dp, vertical = 5.dp),
44+
shape = RoundedCornerShape(16.dp),
45+
elevation = CardDefaults.cardElevation(defaultElevation = 2.dp),
46+
colors = CardDefaults.cardColors(
47+
containerColor = MaterialTheme.colorScheme.surfaceContainer
48+
)
49+
) {
50+
ListItem(
51+
modifier = modifier
52+
.fillMaxWidth()
53+
.padding(5.dp)
54+
.clip(RoundedCornerShape(16.dp)),
55+
headlineContent = {
56+
Row(
57+
verticalAlignment = Alignment.CenterVertically,
58+
) {
59+
Text(
60+
text = "GPS",
61+
style = MaterialTheme.typography.titleMedium,
62+
fontWeight = FontWeight.SemiBold
63+
)
64+
Spacer(Modifier.width(10.dp))
65+
if (!locationPermissionGranted) {
66+
TextButton(
67+
onClick = { onGrantLocationPermissionClick?.invoke() },
68+
colors = ButtonDefaults.textButtonColors(
69+
contentColor = MaterialTheme.colorScheme.error
70+
)
71+
) {
72+
Text("Grant Permission")
73+
}
5474
}
55-
}
5675

57-
}
58-
},
59-
supportingContent = {
60-
Text(
61-
text = if (dedicatedTopics) "topic = ${mqttTopic}/gps" else "type = android.gps",
62-
color = MaterialTheme.colorScheme.onSurface
63-
)
64-
},
76+
}
77+
},
78+
supportingContent = {
79+
Text(
80+
text = if (dedicatedTopics) "topic = ${mqttTopic}/gps" else "type = android.gps",
81+
style = MaterialTheme.typography.bodyLarge,
82+
color = MaterialTheme.colorScheme.onSurface
83+
)
84+
},
6585

66-
trailingContent = {
67-
Switch(
68-
checked = checked,
69-
onCheckedChange = onCheckedChange,
70-
enabled = locationPermissionGranted
86+
trailingContent = {
87+
Switch(
88+
checked = checked,
89+
onCheckedChange = onCheckedChange,
90+
enabled = locationPermissionGranted
91+
)
92+
},
93+
colors = ListItemDefaults.colors(
94+
containerColor = Color.Transparent
7195
)
72-
},
73-
colors = ListItemDefaults.colors(
74-
containerColor = MaterialTheme.colorScheme.surfaceContainer
7596
)
76-
)
97+
}
7798

7899

79100
}
@@ -82,11 +103,13 @@ fun GpsItem(
82103
@Composable
83104
fun GpsItemPreview() {
84105
SensorSpotTheme{
85-
GpsItem(
86-
checked = true,
87-
onCheckedChange = {},
88-
locationPermissionGranted = true,
89-
onGrantLocationPermissionClick = {}
90-
)
106+
Surface {
107+
GpsItem(
108+
checked = true,
109+
onCheckedChange = {},
110+
locationPermissionGranted = true,
111+
onGrantLocationPermissionClick = {}
112+
)
113+
}
91114
}
92115
}

0 commit comments

Comments
 (0)