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 @@ -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
Expand All @@ -34,7 +30,6 @@ fun SearchTopAppBar(
onQueryChange: (String) -> Unit,
onExitSearch: () -> Unit
) {
var expanded by rememberSaveable { mutableStateOf(false) }
DockedSearchBar(
modifier = Modifier
.fillMaxWidth()
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -39,60 +41,87 @@ fun <T> 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
)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ enum class AliasOptionsDisplay {
}

enum class SwipeAction {
DISABLE_ENABLE, PIN_UNPIN, DELETE
NONE, DISABLE_ENABLE, PIN_UNPIN, DELETE
}

enum class AliasDisplayInfo {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ fun AliasRow(
}

when (action) {
SwipeAction.NONE -> dismissState.reset()

SwipeAction.DISABLE_ENABLE -> {
if (alias.enabled) {
onAction?.invoke(AliasAction.Disable(alias))
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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)
}
Expand Down
Loading