Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ private fun ConnectedHomeContent(
val idleReset = remember { MutableStateFlow(false) }
val resetPending by (teslaResetPending ?: idleReset).collectAsState()
val pinned = controlById(pinnedControlId)
val driveEnabled = connectionStatus == ConnectionStatus.Connected

BoxWithConstraints(modifier = Modifier.fillMaxSize()) {
val landscape = maxWidth > maxHeight
Expand Down Expand Up @@ -208,7 +209,8 @@ private fun ConnectedHomeContent(
onClimate = onClimate,
onAutomations = onAutomations,
onControls = onControls,
onDrive = onDrive
onDrive = onDrive,
driveEnabled = driveEnabled
)
} else {
PortraitContent(
Expand All @@ -228,7 +230,8 @@ private fun ConnectedHomeContent(
onClimate = onClimate,
onAutomations = onAutomations,
onControls = onControls,
onDrive = onDrive
onDrive = onDrive,
driveEnabled = driveEnabled
)
}
}
Expand Down Expand Up @@ -302,7 +305,8 @@ private fun PortraitContent(
onClimate: () -> Unit,
onAutomations: () -> Unit,
onControls: () -> Unit,
onDrive: () -> Unit
onDrive: () -> Unit,
driveEnabled: Boolean
) {
Column(modifier = Modifier.fillMaxWidth()) {
WidgetGrid(car = car, useImperial = useImperial, fillHeight = false, onBattery = onBattery, onClimate = onClimate)
Expand Down Expand Up @@ -339,7 +343,7 @@ private fun PortraitContent(
onClick = onControls
)
Spacer(modifier = Modifier.height(12.dp))
DriveButton(onDrive)
DriveButton(onDrive, driveEnabled)
Spacer(modifier = Modifier.height(12.dp))
Box(modifier = Modifier.align(Alignment.CenterHorizontally)) {
DebugDataSourceMenu(connectionStatus, activeSourceType, onSelectDataSource, onConnect, onDisconnect)
Expand All @@ -364,7 +368,8 @@ private fun LandscapeContent(
onClimate: () -> Unit,
onAutomations: () -> Unit,
onControls: () -> Unit,
onDrive: () -> Unit
onDrive: () -> Unit,
driveEnabled: Boolean
) {
Row(
modifier = Modifier
Expand Down Expand Up @@ -425,7 +430,7 @@ private fun LandscapeContent(
PinnedButton(action = action, bleManager = bleManager)
Spacer(modifier = Modifier.height(12.dp))
}
DriveButton(onDrive)
DriveButton(onDrive, driveEnabled)
}
}
}
Expand Down Expand Up @@ -501,12 +506,13 @@ private fun PinnedButton(action: ControlAction, bleManager: DashKitBleManager?)
}

@Composable
private fun DriveButton(onDrive: () -> Unit) {
private fun DriveButton(onDrive: () -> Unit, enabled: Boolean) {
ActionButton(
label = stringResource(R.string.home_drive),
icon = Icons.Rounded.DirectionsCar,
accent = true,
onClick = onDrive
onClick = onDrive,
enabled = enabled
)
}

Expand Down Expand Up @@ -594,14 +600,19 @@ private fun ActionButton(
label: String,
icon: ImageVector,
accent: Boolean,
onClick: () -> Unit
onClick: () -> Unit,
enabled: Boolean = true
) {
val containerColor = if (accent) AccentColor else DarkColors.Surface
Button(
onClick = onClick,
enabled = enabled,
shape = RoundedCornerShape(16.dp),
colors = ButtonDefaults.buttonColors(
containerColor = if (accent) AccentColor else DarkColors.Surface,
contentColor = Color.White
containerColor = containerColor,
contentColor = Color.White,
disabledContainerColor = containerColor.copy(alpha = 0.5f),
disabledContentColor = Color.White.copy(alpha = 0.5f)
),
modifier = Modifier
.fillMaxWidth()
Expand Down
10 changes: 9 additions & 1 deletion dashpilot-ios/dashpilot/UI/HomeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,12 @@ struct HomeView: View {
}

private var driveButton: some View {
ActionButton(label: "Drive", icon: "car.fill", accent: true) {
ActionButton(
label: "Drive",
icon: "car.fill",
accent: true,
enabled: connectionVM.connectionStatus == .connected
) {
let dashboard = selectedDashboard()
navigationPath.append(
AppRoute.dashboard(type: dashboard.type.rawValue, url: dashboard.url)
Expand Down Expand Up @@ -405,6 +410,7 @@ private struct ActionButton: View {
let label: LocalizedStringKey
let icon: String
var accent: Bool = false
var enabled: Bool = true
let action: () -> Void

var body: some View {
Expand All @@ -421,5 +427,7 @@ private struct ActionButton: View {
}
.background(accent ? Color.dashAccent : Color.dashSurface)
.clipShape(RoundedRectangle(cornerRadius: DashMetrics.corner))
.disabled(!enabled)
.opacity(enabled ? 1.0 : 0.5)
}
}
Loading