Skip to content

Commit ab6e710

Browse files
authored
Merge pull request #159 from simple-login/fix/issue-158
Fixes for #158
2 parents 8e1b7e9 + 24e66cf commit ab6e710

7 files changed

Lines changed: 97 additions & 68 deletions

File tree

app/src/main/java/io/simplelogin/android/home/topbar/SearchTopAppBar.kt

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,6 @@ import androidx.compose.material3.IconButton
1717
import androidx.compose.material3.SearchBarDefaults
1818
import androidx.compose.material3.Text
1919
import androidx.compose.runtime.Composable
20-
import androidx.compose.runtime.getValue
21-
import androidx.compose.runtime.mutableStateOf
22-
import androidx.compose.runtime.saveable.rememberSaveable
23-
import androidx.compose.runtime.setValue
2420
import androidx.compose.ui.Modifier
2521
import androidx.compose.ui.graphics.Color
2622
import androidx.compose.ui.res.stringResource
@@ -34,7 +30,6 @@ fun SearchTopAppBar(
3430
onQueryChange: (String) -> Unit,
3531
onExitSearch: () -> Unit
3632
) {
37-
var expanded by rememberSaveable { mutableStateOf(false) }
3833
DockedSearchBar(
3934
modifier = Modifier
4035
.fillMaxWidth()
@@ -45,21 +40,16 @@ fun SearchTopAppBar(
4540
colors = SearchBarDefaults.colors(
4641
containerColor = Color.Transparent
4742
),
48-
expanded = expanded,
49-
onExpandedChange = {
50-
expanded = it
51-
if (!it) {
52-
onExitSearch()
53-
}
54-
},
43+
expanded = false,
44+
onExpandedChange = { if (!it) onExitSearch() },
5545
inputField = {
5646
SearchBarDefaults.InputField(
5747
modifier = Modifier.fillMaxWidth(),
5848
query = query,
5949
onQueryChange = onQueryChange,
60-
onSearch = { expanded = false },
61-
expanded = expanded,
62-
onExpandedChange = { expanded = it },
50+
onSearch = {},
51+
expanded = false,
52+
onExpandedChange = { if (!it) onExitSearch() },
6353
placeholder = { Text(stringResource(R.string.search_all_aliases)) },
6454
leadingIcon = {
6555
IconButton(onClick = onExitSearch) {

core/designsystem/src/main/java/io/simplelogin/core/designsystem/ModelExtensions.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ import io.simplelogin.core.model.preferences.DefaultPrefix.RANDOM_CHARACTERS
3838
import io.simplelogin.core.model.preferences.DefaultPrefix.RANDOM_WORD
3939
import io.simplelogin.core.model.preferences.DeviceLockType
4040
import io.simplelogin.core.model.preferences.DeviceLockType.BIOMETRIC
41-
import io.simplelogin.core.model.preferences.DeviceLockType.NONE
4241
import io.simplelogin.core.model.preferences.DeviceLockType.PIN
4342
import io.simplelogin.core.model.preferences.LockTimeOut
4443
import io.simplelogin.core.model.preferences.LockTimeOut.FIVE_MINUTES
@@ -105,6 +104,7 @@ fun AliasOptionsDisplay.title(context: Context) = when (this) {
105104
}
106105

107106
fun SwipeAction.title(context: Context) = when (this) {
107+
SwipeAction.NONE -> context.getString(R.string.none)
108108
DISABLE_ENABLE -> context.getString(R.string.disable_enable)
109109
PIN_UNPIN -> context.getString(R.string.pin_unpin)
110110
DELETE -> context.getString(R.string.delete)
@@ -144,7 +144,7 @@ fun ContactCellSelection.title(context: Context) = when (this) {
144144
}
145145

146146
fun DeviceLockType.title(context: Context) = when (this) {
147-
NONE -> context.getString(R.string.none)
147+
DeviceLockType.NONE -> context.getString(R.string.none)
148148
BIOMETRIC -> context.getString(R.string.biometric)
149149
PIN -> context.getString(R.string.pin_code)
150150
}

core/designsystem/src/main/java/io/simplelogin/core/designsystem/OptionRow.kt

Lines changed: 75 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ import androidx.compose.runtime.remember
2424
import androidx.compose.runtime.setValue
2525
import androidx.compose.ui.Alignment
2626
import androidx.compose.ui.Modifier
27+
import androidx.compose.ui.layout.Layout
2728
import androidx.compose.ui.res.painterResource
29+
import androidx.compose.ui.unit.Constraints
2830
import io.simplelogin.core.designsystem.theme.Spacing
2931

3032
@Composable
@@ -39,60 +41,87 @@ fun <T> OptionRow(
3941
) {
4042
var expanded by remember { mutableStateOf(false) }
4143

42-
Row(
44+
Layout(
4345
modifier = modifier
4446
.clickable { expanded = true }
45-
.padding(paddingValues)
46-
) {
47-
Text(
48-
modifier = Modifier.weight(1f),
49-
text = title
50-
)
51-
52-
Box {
53-
Row(
54-
horizontalArrangement = Arrangement.spacedBy(Spacing.small),
55-
verticalAlignment = Alignment.CenterVertically
56-
) {
57-
AnimatedContent(
58-
targetState = selected,
59-
transitionSpec = { fadeIn() togetherWith fadeOut() }
60-
) { targetSelected ->
61-
description(targetSelected)
47+
.padding(paddingValues),
48+
content = {
49+
Text(text = title)
50+
Box {
51+
Row(
52+
horizontalArrangement = Arrangement.spacedBy(Spacing.small),
53+
verticalAlignment = Alignment.CenterVertically
54+
) {
55+
AnimatedContent(
56+
targetState = selected,
57+
transitionSpec = { fadeIn() togetherWith fadeOut() }
58+
) { targetSelected ->
59+
description(targetSelected)
60+
}
61+
Icon(
62+
painter = painterResource(R.drawable.ic_selector),
63+
contentDescription = null
64+
)
6265
}
63-
64-
Icon(
65-
painter = painterResource(R.drawable.ic_selector),
66-
contentDescription = null
67-
)
68-
}
69-
70-
DropdownMenu(
71-
expanded = expanded,
72-
onDismissRequest = { expanded = false }
73-
) {
74-
options.forEachIndexed { index, option ->
75-
DropdownMenuItem(
76-
trailingIcon = {
77-
if (option == selected) {
78-
Icon(
79-
imageVector = Icons.Outlined.Check,
80-
contentDescription = null
81-
)
66+
DropdownMenu(
67+
expanded = expanded,
68+
onDismissRequest = { expanded = false }
69+
) {
70+
options.forEachIndexed { index, option ->
71+
DropdownMenuItem(
72+
trailingIcon = {
73+
if (option == selected) {
74+
Icon(
75+
imageVector = Icons.Outlined.Check,
76+
contentDescription = null
77+
)
78+
}
79+
},
80+
text = { description(option) },
81+
onClick = {
82+
onSelect(option)
83+
expanded = false
8284
}
83-
},
84-
text = { description(option) },
85-
onClick = {
86-
onSelect(option)
87-
expanded = false
85+
)
86+
if (index < options.lastIndex) {
87+
HorizontalDivider()
8888
}
89-
)
90-
91-
if (index < options.lastIndex) {
92-
HorizontalDivider()
9389
}
9490
}
9591
}
9692
}
93+
) { measurables, constraints ->
94+
val (titleM, descM) = measurables
95+
val gap = Spacing.small.roundToPx()
96+
val descPlaceable = descM.measure(Constraints())
97+
val titleNaturalWidth = titleM.maxIntrinsicWidth(constraints.maxHeight)
98+
val useColumn = titleNaturalWidth + gap + descPlaceable.width > constraints.maxWidth
99+
100+
val titlePlaceable = titleM.measure(
101+
if (useColumn) {
102+
Constraints(maxWidth = constraints.maxWidth)
103+
} else {
104+
Constraints(
105+
minWidth = 0,
106+
maxWidth = constraints.maxWidth - descPlaceable.width - gap
107+
)
108+
}
109+
)
110+
111+
if (useColumn) {
112+
layout(constraints.maxWidth, titlePlaceable.height + gap + descPlaceable.height) {
113+
titlePlaceable.place(0, 0)
114+
descPlaceable.place(0, titlePlaceable.height + gap)
115+
}
116+
} else {
117+
val height = maxOf(titlePlaceable.height, descPlaceable.height)
118+
layout(constraints.maxWidth, height) {
119+
titlePlaceable.place(0, (height - titlePlaceable.height) / 2)
120+
descPlaceable.place(
121+
constraints.maxWidth - descPlaceable.width,
122+
(height - descPlaceable.height) / 2
123+
)
124+
}
125+
}
97126
}
98127
}

core/model/src/main/java/io/simplelogin/core/model/preferences/DevicePreferences.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ enum class AliasOptionsDisplay {
4141
}
4242

4343
enum class SwipeAction {
44-
DISABLE_ENABLE, PIN_UNPIN, DELETE
44+
NONE, DISABLE_ENABLE, PIN_UNPIN, DELETE
4545
}
4646

4747
enum class AliasDisplayInfo {

feature/accountsettings/src/main/java/io/simplelogin/feature/accountsettings/AccountSettingsScreen.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,11 @@ private fun LazyListScope.accountSettingsScreenContent(
319319
}
320320
)
321321

322-
userInfo.trialEndTimestamp?.let {
323-
SettingsFooter(text = stringResource(R.string.trial_end_date, it.timeAndFullDate()))
322+
val trialEndTimestamp = userInfo.trialEndTimestamp
323+
if (userInfo.inTrial && trialEndTimestamp != null) {
324+
SettingsFooter(
325+
text = stringResource(R.string.trial_end_date, trialEndTimestamp.timeAndFullDate())
326+
)
324327
SettingsFooter(text = stringResource(R.string.trial_description))
325328
}
326329

feature/aliaslist/src/main/java/io/simplelogin/feature/aliaslist/AliasRow.kt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ fun AliasRow(
8686
}
8787

8888
when (action) {
89+
SwipeAction.NONE -> dismissState.reset()
90+
8991
SwipeAction.DISABLE_ENABLE -> {
9092
if (alias.enabled) {
9193
onAction?.invoke(AliasAction.Disable(alias))
@@ -116,6 +118,8 @@ fun AliasRow(
116118
SwipeToDismissBox(
117119
modifier = modifier,
118120
state = dismissState,
121+
enableDismissFromStartToEnd = swipeFromStartToEndAction != SwipeAction.NONE,
122+
enableDismissFromEndToStart = swipeFromEndToStartAction != SwipeAction.NONE,
119123
backgroundContent = {
120124
val direction = dismissState.dismissDirection
121125
val isSwiping = dismissState.progress > 0.01f
@@ -317,6 +321,7 @@ private fun AliasCellContent(
317321
@Composable
318322
private fun SwipeAction.color(alias: Alias): Color =
319323
when (this) {
324+
SwipeAction.NONE -> Color.Transparent
320325
SwipeAction.PIN_UNPIN -> if (alias.pinned) SlColor.Amber else MaterialTheme.colorScheme.primary
321326
SwipeAction.DISABLE_ENABLE -> if (alias.enabled) Color.Gray else SlColor.Green
322327
SwipeAction.DELETE -> Color.Red
@@ -325,6 +330,8 @@ private fun SwipeAction.color(alias: Alias): Color =
325330
@Composable
326331
private fun SwipeAction.Label(alias: Alias) {
327332
when (this) {
333+
SwipeAction.NONE -> {}
334+
328335
SwipeAction.DISABLE_ENABLE ->
329336
if (alias.enabled) {
330337
SwipeActionLabel(

feature/devicesettings/src/main/java/io/simplelogin/feature/devicesettings/DeviceSettingsViewModel.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class DeviceSettingsViewModel @Inject constructor(
6868
updateDeviceSettings.invoke {
6969
it.copy(swipeFromLeftToRightAction = action)
7070
}
71-
if (action == currentSettings.swipeFromRightToLeftAction) {
71+
if (action != SwipeAction.NONE && action == currentSettings.swipeFromRightToLeftAction) {
7272
updateDeviceSettings.invoke {
7373
it.copy(swipeFromRightToLeftAction = oldSwipeFromLeftToRight)
7474
}
@@ -82,7 +82,7 @@ class DeviceSettingsViewModel @Inject constructor(
8282
updateDeviceSettings.invoke {
8383
it.copy(swipeFromRightToLeftAction = action)
8484
}
85-
if (action == currentSettings.swipeFromLeftToRightAction) {
85+
if (action != SwipeAction.NONE && action == currentSettings.swipeFromLeftToRightAction) {
8686
updateDeviceSettings.invoke {
8787
it.copy(swipeFromLeftToRightAction = oldSwipeFromRightToLeft)
8888
}

0 commit comments

Comments
 (0)