diff --git a/app/src/main/java/io/simplelogin/android/home/topbar/SearchTopAppBar.kt b/app/src/main/java/io/simplelogin/android/home/topbar/SearchTopAppBar.kt index e19bed63..7fcf5dc1 100644 --- a/app/src/main/java/io/simplelogin/android/home/topbar/SearchTopAppBar.kt +++ b/app/src/main/java/io/simplelogin/android/home/topbar/SearchTopAppBar.kt @@ -17,10 +17,6 @@ import androidx.compose.material3.IconButton import androidx.compose.material3.SearchBarDefaults import androidx.compose.material3.Text import androidx.compose.runtime.Composable -import androidx.compose.runtime.getValue -import androidx.compose.runtime.mutableStateOf -import androidx.compose.runtime.saveable.rememberSaveable -import androidx.compose.runtime.setValue import androidx.compose.ui.Modifier import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.stringResource @@ -34,7 +30,6 @@ fun SearchTopAppBar( onQueryChange: (String) -> Unit, onExitSearch: () -> Unit ) { - var expanded by rememberSaveable { mutableStateOf(false) } DockedSearchBar( modifier = Modifier .fillMaxWidth() @@ -45,21 +40,16 @@ fun SearchTopAppBar( colors = SearchBarDefaults.colors( containerColor = Color.Transparent ), - expanded = expanded, - onExpandedChange = { - expanded = it - if (!it) { - onExitSearch() - } - }, + expanded = false, + onExpandedChange = { if (!it) onExitSearch() }, inputField = { SearchBarDefaults.InputField( modifier = Modifier.fillMaxWidth(), query = query, onQueryChange = onQueryChange, - onSearch = { expanded = false }, - expanded = expanded, - onExpandedChange = { expanded = it }, + onSearch = {}, + expanded = false, + onExpandedChange = { if (!it) onExitSearch() }, placeholder = { Text(stringResource(R.string.search_all_aliases)) }, leadingIcon = { IconButton(onClick = onExitSearch) { diff --git a/core/designsystem/src/main/java/io/simplelogin/core/designsystem/ModelExtensions.kt b/core/designsystem/src/main/java/io/simplelogin/core/designsystem/ModelExtensions.kt index 4c1db9ec..8b2aca83 100644 --- a/core/designsystem/src/main/java/io/simplelogin/core/designsystem/ModelExtensions.kt +++ b/core/designsystem/src/main/java/io/simplelogin/core/designsystem/ModelExtensions.kt @@ -38,7 +38,6 @@ import io.simplelogin.core.model.preferences.DefaultPrefix.RANDOM_CHARACTERS import io.simplelogin.core.model.preferences.DefaultPrefix.RANDOM_WORD import io.simplelogin.core.model.preferences.DeviceLockType import io.simplelogin.core.model.preferences.DeviceLockType.BIOMETRIC -import io.simplelogin.core.model.preferences.DeviceLockType.NONE import io.simplelogin.core.model.preferences.DeviceLockType.PIN import io.simplelogin.core.model.preferences.LockTimeOut import io.simplelogin.core.model.preferences.LockTimeOut.FIVE_MINUTES @@ -105,6 +104,7 @@ fun AliasOptionsDisplay.title(context: Context) = when (this) { } fun SwipeAction.title(context: Context) = when (this) { + SwipeAction.NONE -> context.getString(R.string.none) DISABLE_ENABLE -> context.getString(R.string.disable_enable) PIN_UNPIN -> context.getString(R.string.pin_unpin) DELETE -> context.getString(R.string.delete) @@ -144,7 +144,7 @@ fun ContactCellSelection.title(context: Context) = when (this) { } fun DeviceLockType.title(context: Context) = when (this) { - NONE -> context.getString(R.string.none) + DeviceLockType.NONE -> context.getString(R.string.none) BIOMETRIC -> context.getString(R.string.biometric) PIN -> context.getString(R.string.pin_code) } diff --git a/core/designsystem/src/main/java/io/simplelogin/core/designsystem/OptionRow.kt b/core/designsystem/src/main/java/io/simplelogin/core/designsystem/OptionRow.kt index b93352bb..81db7e63 100644 --- a/core/designsystem/src/main/java/io/simplelogin/core/designsystem/OptionRow.kt +++ b/core/designsystem/src/main/java/io/simplelogin/core/designsystem/OptionRow.kt @@ -24,7 +24,9 @@ import androidx.compose.runtime.remember import androidx.compose.runtime.setValue import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.layout.Layout import androidx.compose.ui.res.painterResource +import androidx.compose.ui.unit.Constraints import io.simplelogin.core.designsystem.theme.Spacing @Composable @@ -39,60 +41,87 @@ fun OptionRow( ) { var expanded by remember { mutableStateOf(false) } - Row( + Layout( modifier = modifier .clickable { expanded = true } - .padding(paddingValues) - ) { - Text( - modifier = Modifier.weight(1f), - text = title - ) - - Box { - Row( - horizontalArrangement = Arrangement.spacedBy(Spacing.small), - verticalAlignment = Alignment.CenterVertically - ) { - AnimatedContent( - targetState = selected, - transitionSpec = { fadeIn() togetherWith fadeOut() } - ) { targetSelected -> - description(targetSelected) + .padding(paddingValues), + content = { + Text(text = title) + Box { + Row( + horizontalArrangement = Arrangement.spacedBy(Spacing.small), + verticalAlignment = Alignment.CenterVertically + ) { + AnimatedContent( + targetState = selected, + transitionSpec = { fadeIn() togetherWith fadeOut() } + ) { targetSelected -> + description(targetSelected) + } + Icon( + painter = painterResource(R.drawable.ic_selector), + contentDescription = null + ) } - - Icon( - painter = painterResource(R.drawable.ic_selector), - contentDescription = null - ) - } - - DropdownMenu( - expanded = expanded, - onDismissRequest = { expanded = false } - ) { - options.forEachIndexed { index, option -> - DropdownMenuItem( - trailingIcon = { - if (option == selected) { - Icon( - imageVector = Icons.Outlined.Check, - contentDescription = null - ) + DropdownMenu( + expanded = expanded, + onDismissRequest = { expanded = false } + ) { + options.forEachIndexed { index, option -> + DropdownMenuItem( + trailingIcon = { + if (option == selected) { + Icon( + imageVector = Icons.Outlined.Check, + contentDescription = null + ) + } + }, + text = { description(option) }, + onClick = { + onSelect(option) + expanded = false } - }, - text = { description(option) }, - onClick = { - onSelect(option) - expanded = false + ) + if (index < options.lastIndex) { + HorizontalDivider() } - ) - - if (index < options.lastIndex) { - HorizontalDivider() } } } } + ) { measurables, constraints -> + val (titleM, descM) = measurables + val gap = Spacing.small.roundToPx() + val descPlaceable = descM.measure(Constraints()) + val titleNaturalWidth = titleM.maxIntrinsicWidth(constraints.maxHeight) + val useColumn = titleNaturalWidth + gap + descPlaceable.width > constraints.maxWidth + + val titlePlaceable = titleM.measure( + if (useColumn) { + Constraints(maxWidth = constraints.maxWidth) + } else { + Constraints( + minWidth = 0, + maxWidth = constraints.maxWidth - descPlaceable.width - gap + ) + } + ) + + if (useColumn) { + layout(constraints.maxWidth, titlePlaceable.height + gap + descPlaceable.height) { + titlePlaceable.place(0, 0) + descPlaceable.place(0, titlePlaceable.height + gap) + } + } else { + val height = maxOf(titlePlaceable.height, descPlaceable.height) + layout(constraints.maxWidth, height) { + titlePlaceable.place(0, (height - titlePlaceable.height) / 2) + descPlaceable.place( + constraints.maxWidth - descPlaceable.width, + (height - descPlaceable.height) / 2 + ) + } + } } } diff --git a/core/model/src/main/java/io/simplelogin/core/model/preferences/DevicePreferences.kt b/core/model/src/main/java/io/simplelogin/core/model/preferences/DevicePreferences.kt index b92652df..964e0088 100644 --- a/core/model/src/main/java/io/simplelogin/core/model/preferences/DevicePreferences.kt +++ b/core/model/src/main/java/io/simplelogin/core/model/preferences/DevicePreferences.kt @@ -41,7 +41,7 @@ enum class AliasOptionsDisplay { } enum class SwipeAction { - DISABLE_ENABLE, PIN_UNPIN, DELETE + NONE, DISABLE_ENABLE, PIN_UNPIN, DELETE } enum class AliasDisplayInfo { diff --git a/feature/accountsettings/src/main/java/io/simplelogin/feature/accountsettings/AccountSettingsScreen.kt b/feature/accountsettings/src/main/java/io/simplelogin/feature/accountsettings/AccountSettingsScreen.kt index cbcc3f33..cc65bcdf 100644 --- a/feature/accountsettings/src/main/java/io/simplelogin/feature/accountsettings/AccountSettingsScreen.kt +++ b/feature/accountsettings/src/main/java/io/simplelogin/feature/accountsettings/AccountSettingsScreen.kt @@ -319,8 +319,11 @@ private fun LazyListScope.accountSettingsScreenContent( } ) - userInfo.trialEndTimestamp?.let { - SettingsFooter(text = stringResource(R.string.trial_end_date, it.timeAndFullDate())) + val trialEndTimestamp = userInfo.trialEndTimestamp + if (userInfo.inTrial && trialEndTimestamp != null) { + SettingsFooter( + text = stringResource(R.string.trial_end_date, trialEndTimestamp.timeAndFullDate()) + ) SettingsFooter(text = stringResource(R.string.trial_description)) } diff --git a/feature/aliaslist/src/main/java/io/simplelogin/feature/aliaslist/AliasRow.kt b/feature/aliaslist/src/main/java/io/simplelogin/feature/aliaslist/AliasRow.kt index b74b5b29..6a26facb 100644 --- a/feature/aliaslist/src/main/java/io/simplelogin/feature/aliaslist/AliasRow.kt +++ b/feature/aliaslist/src/main/java/io/simplelogin/feature/aliaslist/AliasRow.kt @@ -86,6 +86,8 @@ fun AliasRow( } when (action) { + SwipeAction.NONE -> dismissState.reset() + SwipeAction.DISABLE_ENABLE -> { if (alias.enabled) { onAction?.invoke(AliasAction.Disable(alias)) @@ -116,6 +118,8 @@ fun AliasRow( SwipeToDismissBox( modifier = modifier, state = dismissState, + enableDismissFromStartToEnd = swipeFromStartToEndAction != SwipeAction.NONE, + enableDismissFromEndToStart = swipeFromEndToStartAction != SwipeAction.NONE, backgroundContent = { val direction = dismissState.dismissDirection val isSwiping = dismissState.progress > 0.01f @@ -317,6 +321,7 @@ private fun AliasCellContent( @Composable private fun SwipeAction.color(alias: Alias): Color = when (this) { + SwipeAction.NONE -> Color.Transparent SwipeAction.PIN_UNPIN -> if (alias.pinned) SlColor.Amber else MaterialTheme.colorScheme.primary SwipeAction.DISABLE_ENABLE -> if (alias.enabled) Color.Gray else SlColor.Green SwipeAction.DELETE -> Color.Red @@ -325,6 +330,8 @@ private fun SwipeAction.color(alias: Alias): Color = @Composable private fun SwipeAction.Label(alias: Alias) { when (this) { + SwipeAction.NONE -> {} + SwipeAction.DISABLE_ENABLE -> if (alias.enabled) { SwipeActionLabel( diff --git a/feature/devicesettings/src/main/java/io/simplelogin/feature/devicesettings/DeviceSettingsViewModel.kt b/feature/devicesettings/src/main/java/io/simplelogin/feature/devicesettings/DeviceSettingsViewModel.kt index 092fd1fe..0404dd80 100644 --- a/feature/devicesettings/src/main/java/io/simplelogin/feature/devicesettings/DeviceSettingsViewModel.kt +++ b/feature/devicesettings/src/main/java/io/simplelogin/feature/devicesettings/DeviceSettingsViewModel.kt @@ -68,7 +68,7 @@ class DeviceSettingsViewModel @Inject constructor( updateDeviceSettings.invoke { it.copy(swipeFromLeftToRightAction = action) } - if (action == currentSettings.swipeFromRightToLeftAction) { + if (action != SwipeAction.NONE && action == currentSettings.swipeFromRightToLeftAction) { updateDeviceSettings.invoke { it.copy(swipeFromRightToLeftAction = oldSwipeFromLeftToRight) } @@ -82,7 +82,7 @@ class DeviceSettingsViewModel @Inject constructor( updateDeviceSettings.invoke { it.copy(swipeFromRightToLeftAction = action) } - if (action == currentSettings.swipeFromLeftToRightAction) { + if (action != SwipeAction.NONE && action == currentSettings.swipeFromLeftToRightAction) { updateDeviceSettings.invoke { it.copy(swipeFromLeftToRightAction = oldSwipeFromRightToLeft) }