Skip to content

Commit ef1ca78

Browse files
committed
Use cross instead of back icon and make top bar more flexible
1 parent 62024d7 commit ef1ca78

File tree

10 files changed

+54
-4
lines changed

10 files changed

+54
-4
lines changed

app/src/main/kotlin/io/homeassistant/companion/android/onboarding/locationforsecureconnection/LocationForSecureConnectionScreen.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ internal fun LocationForSecureConnectionScreen(
9393
) {
9494
Scaffold(
9595
modifier = modifier,
96-
topBar = { HATopBar(onBackClick = onBackClick, onHelpClick = onHelpClick) },
96+
topBar = { HATopBar(onHelpClick = onHelpClick, onCloseClick = onBackClick) },
9797
contentWindowInsets = WindowInsets.safeDrawing,
9898
) { contentPadding ->
9999
LocationForSecureConnectionContent(

app/src/main/kotlin/io/homeassistant/companion/android/onboarding/locationforsecureconnection/LocationForSecureConnectionViewModel.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class LocationForSecureConnectionViewModel @VisibleForTesting constructor(
3838
fun allowInsecureConnection(allowInsecureConnection: Boolean) {
3939
viewModelScope.launch {
4040
try {
41-
serverManager.integrationRepository(serverId).setAllowInsecureConnection(allowInsecureConnection)
41+
// serverManager.integrationRepository(serverId).setAllowInsecureConnection(allowInsecureConnection)
4242
} catch (e: Exception) {
4343
Timber.e(
4444
e,

app/src/screenshotTest/kotlin/io/homeassistant/companion/android/onboarding/locationforsecureconnection/LocationForSecureConnectionScreenshotTest.kt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,21 @@ class LocationForSecureConnectionScreenshotTest {
2020
}
2121
}
2222

23+
@PreviewTest
24+
@HAPreviews
25+
@Composable
26+
fun `LocationForSecureConnection with back navigation`() {
27+
HAThemeForPreview {
28+
LocationForSecureConnectionScreen(
29+
onAllowInsecureConnection = { _ -> },
30+
onHelpClick = {},
31+
onBackClick = {},
32+
onShowSnackbar = { _, _ -> true },
33+
initialAllowInsecureConnection = null,
34+
)
35+
}
36+
}
37+
2338
@PreviewTest
2439
@HAPreviews
2540
@Composable

common/src/main/kotlin/io/homeassistant/companion/android/common/compose/composable/HATopBar.kt

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import androidx.compose.foundation.layout.height
55
import androidx.compose.material.icons.Icons
66
import androidx.compose.material.icons.automirrored.outlined.HelpOutline
77
import androidx.compose.material.icons.automirrored.rounded.ArrowBack
8+
import androidx.compose.material.icons.filled.Close
89
import androidx.compose.material3.ExperimentalMaterial3Api
910
import androidx.compose.material3.Icon
1011
import androidx.compose.material3.IconButton
@@ -23,16 +24,22 @@ import io.homeassistant.companion.android.common.compose.theme.LocalHAColorSchem
2324
* Generic top bar for Home Assistant screens with optional buttons
2425
* - if onHelpClick is not null, a help button will be added
2526
* - if onBackClick is not null, a back button will be added
27+
* - if onCloseClick is not null, a close button will be added
28+
*
29+
* Note: onBackClick and onCloseClick are mutually exclusive and cannot be set together.
2630
*/
27-
@OptIn(ExperimentalMaterial3Api::class)
2831
@Composable
2932
fun HATopBar(
3033
modifier: Modifier = Modifier,
3134
title: @Composable () -> Unit = {},
3235
onHelpClick: (() -> Unit)? = null,
3336
onBackClick: (() -> Unit)? = null,
37+
onCloseClick: (() -> Unit)? = null,
3438
) {
35-
TopAppBar(
39+
require(onBackClick == null || onCloseClick == null) {
40+
"onBackClick and onCloseClick are mutually exclusive and cannot be set together"
41+
}
42+
HATopBar(
3643
title = title,
3744
navigationIcon = {
3845
onBackClick?.let {
@@ -43,6 +50,14 @@ fun HATopBar(
4350
)
4451
}
4552
}
53+
onCloseClick?.let {
54+
IconButton(onClick = onCloseClick) {
55+
Icon(
56+
imageVector = Icons.Default.Close,
57+
contentDescription = stringResource(commonR.string.close),
58+
)
59+
}
60+
}
4661
},
4762
actions = {
4863
onHelpClick?.let {
@@ -54,6 +69,26 @@ fun HATopBar(
5469
}
5570
}
5671
},
72+
modifier = modifier,
73+
)
74+
}
75+
76+
@OptIn(ExperimentalMaterial3Api::class)
77+
@Composable
78+
fun HATopBar(
79+
modifier: Modifier = Modifier,
80+
title: @Composable () -> Unit = {},
81+
navigationIcon: (@Composable () -> Unit)? = null,
82+
actions: (@Composable () -> Unit)? = null,
83+
) {
84+
TopAppBar(
85+
title = title,
86+
navigationIcon = {
87+
navigationIcon?.invoke()
88+
},
89+
actions = {
90+
actions?.invoke()
91+
},
5792
colors = TopAppBarColors(
5893
containerColor = LocalHAColorScheme.current.colorSurfaceDefault,
5994
// TODO validate that we use colorOnNeutralQuiet

0 commit comments

Comments
 (0)