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 @@ -44,14 +44,14 @@ import com.github.kr328.clash.ui.theme.TabbyThemeWrapper
import kotlinx.serialization.Serializable

@Serializable
internal data class EditableTextList(val title: Int, val initialValues: List<String>?) : NavKey
internal data class EditableTextList(val title: Int, val initialValues: Set<String>?) : NavKey

internal fun EntryProviderScope<NavKey>.editableTextListScreenEntry(
internal fun EntryProviderScope<NavKey>.editableTextSetScreenEntry(
onDismiss: () -> Unit,
onApply: (List<String>?) -> Unit,
onApply: (Set<String>?) -> Unit,
) {
entry<EditableTextList> { key ->
EditableTextListScreen(
EditableTextSetScreen(
title = key.title,
initialValues = key.initialValues,
onDismiss = onDismiss,
Expand All @@ -61,11 +61,11 @@ internal fun EntryProviderScope<NavKey>.editableTextListScreenEntry(
}

@Composable
private fun EditableTextListScreen(
private fun EditableTextSetScreen(
@StringRes title: Int,
initialValues: List<String>?,
initialValues: Set<String>?,
onDismiss: () -> Unit,
onApply: (List<String>?) -> Unit,
onApply: (Set<String>?) -> Unit,
) {
val values = remember(initialValues) { initialValues.orEmpty().toMutableStateList() }
var showAddDialog by remember { mutableStateOf(false) }
Expand Down Expand Up @@ -110,7 +110,7 @@ private fun EditableTextListScreen(
) {
TextButton(onClick = { onApply(null) }) { Text(stringResource(CommonR.string.reset)) }
TextButton(onClick = onDismiss) { Text(stringResource(CommonR.string.cancel)) }
TextButton(onClick = { onApply(values.toList()) }) {
TextButton(onClick = { onApply(values.toSet()) }) {
Text(stringResource(CommonR.string.ok))
}
}
Expand All @@ -122,7 +122,7 @@ private fun EditableTextListScreen(
title = title,
onDismiss = { showAddDialog = false },
onConfirm = { newValue ->
if (newValue.isNotBlank()) {
if (newValue.isNotBlank() && !values.contains(newValue)) {
values.add(newValue)
}
showAddDialog = false
Expand Down Expand Up @@ -171,10 +171,10 @@ private fun SingleTextInputDialog(
@PreviewWrapper(TabbyThemeWrapper::class)
@PreviewTabby
@Composable
private fun EditableTextListScreenPreview() {
EditableTextListScreen(
private fun EditableTextSetScreenPreview() {
EditableTextSetScreen(
title = R.string.sniff_http_ports,
initialValues = listOf("80", "8080"),
initialValues = setOf("80", "8080"),
onDismiss = {},
onApply = {},
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ internal fun MetaFeatureSettingsScreen(
},
onOpenEditableTextList = { title, initialValues, onApply ->
currentEditableTextListOnApply = onApply
backStack.addIfNotLast(EditableTextList(title, initialValues))
backStack.addIfNotLast(EditableTextList(title, initialValues?.toSet()))
},
)

Expand All @@ -152,13 +152,13 @@ internal fun MetaFeatureSettingsScreen(
)
}
}
editableTextListScreenEntry(
editableTextSetScreenEntry(
onDismiss = {
currentEditableTextListOnApply = null
backStack.removeLastOrNull()
},
onApply = { newValues ->
currentEditableTextListOnApply?.invoke(newValues)
currentEditableTextListOnApply?.invoke(newValues?.toList())
currentEditableTextListOnApply = null
backStack.removeLastOrNull()
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ internal fun OverrideSettingsScreen(
},
onOpenEditableTextList = { title, initialValues, onApply ->
currentEditableTextListOnApply = onApply
backStack.addIfNotLast(EditableTextList(title, initialValues))
backStack.addIfNotLast(EditableTextList(title, initialValues?.toSet()))
},
)
}
Expand All @@ -113,13 +113,13 @@ internal fun OverrideSettingsScreen(
backStack.removeLastOrNull()
},
)
editableTextListScreenEntry(
editableTextSetScreenEntry(
onDismiss = {
currentEditableTextListOnApply = null
backStack.removeLastOrNull()
},
onApply = { newValues ->
currentEditableTextListOnApply?.invoke(newValues)
currentEditableTextListOnApply?.invoke(newValues?.toList())
currentEditableTextListOnApply = null
backStack.removeLastOrNull()
},
Expand Down