-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
148 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...src/commonMain/kotlin/com.alorma.compose.settings.sample.shared/internal/LabelCheckbox.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package com.alorma.compose.settings.sample.shared.internal | ||
|
||
import androidx.compose.foundation.clickable | ||
import androidx.compose.material3.Checkbox | ||
import androidx.compose.material3.ListItem | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.semantics.Role | ||
|
||
@Composable | ||
internal fun LabelCheckbox( | ||
item: SampleItem, | ||
isSelected: Boolean, | ||
onSelected: () -> Unit, | ||
) { | ||
ListItem( | ||
modifier = Modifier.clickable( | ||
role = Role.RadioButton, | ||
onClick = onSelected, | ||
onClickLabel = item.title, | ||
), | ||
headlineContent = { Text(text = item.title) }, | ||
supportingContent = { Text(text = item.description) }, | ||
trailingContent = { Checkbox(checked = isSelected, onCheckedChange = null) }, | ||
) | ||
} |
71 changes: 71 additions & 0 deletions
71
...nMain/kotlin/com.alorma.compose.settings.sample.shared/internal/MultiChoiceAlertDialog.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.alorma.compose.settings.sample.shared.internal | ||
|
||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.material3.AlertDialog | ||
import androidx.compose.material3.Text | ||
import androidx.compose.material3.TextButton | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.mutableStateListOf | ||
import androidx.compose.runtime.remember | ||
|
||
@Composable | ||
internal fun MultiChoiceAlertDialog( | ||
selectedItemKeys: List<String> = emptyList(), | ||
onItemsSelected: (List<String>) -> Unit, | ||
items: List<SampleItem> | ||
) { | ||
val userSelectedItems = remember { | ||
mutableStateListOf(*selectedItemKeys.toTypedArray()) | ||
} | ||
|
||
AlertDialog( | ||
onDismissRequest = { onItemsSelected(selectedItemKeys.toSet().toList()) }, | ||
title = { Text(text = "Multi choice") }, | ||
text = { | ||
Column { | ||
items.forEach { sampleItem -> | ||
val isSelected = sampleItem.key in userSelectedItems | ||
LabelCheckbox( | ||
item = sampleItem, | ||
isSelected = isSelected, | ||
onSelected = { | ||
if (userSelectedItems.contains(sampleItem.key)) { | ||
userSelectedItems.remove(sampleItem.key) | ||
} else { | ||
userSelectedItems.add(sampleItem.key) | ||
} | ||
}, | ||
) | ||
} | ||
} | ||
}, | ||
confirmButton = if (userSelectedItems.isEmpty()) { | ||
{ | ||
TextButton( | ||
onClick = { onItemsSelected(emptyList()) }, | ||
) { | ||
Text(text = "Cancel") | ||
} | ||
} | ||
} else { | ||
{ | ||
TextButton( | ||
onClick = { onItemsSelected(userSelectedItems.toSet().toList()) }, | ||
) { | ||
Text(text = "Select") | ||
} | ||
} | ||
}, | ||
dismissButton = if (userSelectedItems.isEmpty()) { | ||
null | ||
} else { | ||
{ | ||
TextButton( | ||
onClick = { onItemsSelected(emptyList()) }, | ||
) { | ||
Text(text = "Clear") | ||
} | ||
} | ||
}, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters