Skip to content

Commit

Permalink
✨ Implement deselect selected symbols
Browse files Browse the repository at this point in the history
  • Loading branch information
sukchan-0811 committed Nov 2, 2023
1 parent 3bc31ea commit 8571c12
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import com.example.speechbuddy.ui.SpeechBuddyTheme
@Composable
fun SelectedSymbolsBox(
selectedSymbols: List<Symbol>,
onClear: (Symbol) -> Unit,
onClearAll: () -> Unit,
modifier: Modifier = Modifier
) {
Expand All @@ -59,7 +60,7 @@ fun SelectedSymbolsBox(
horizontalArrangement = Arrangement.spacedBy(10.dp)
) {
items(selectedSymbols) { symbol ->
SelectedSymbolUi(symbol = symbol, onClear = {})
SelectedSymbolUi(symbol = symbol, onClear = { onClear(symbol) })
}
}
}
Expand All @@ -78,7 +79,7 @@ fun SelectedSymbolsBox(
shape = RoundedCornerShape(5.dp),
colors = ButtonDefaults.buttonColors(
containerColor = MaterialTheme.colorScheme.tertiary,
contentColor = MaterialTheme.colorScheme.onTertiary,
contentColor = MaterialTheme.colorScheme.onTertiary
),
contentPadding = PaddingValues(2.dp)
) {
Expand Down Expand Up @@ -106,6 +107,6 @@ fun SelectedSymbolsBoxPreview() {
val selectedSymbols = List(size = 10, init = { previewSymbol })

SpeechBuddyTheme {
SelectedSymbolsBox(selectedSymbols = selectedSymbols, onClearAll = {})
SelectedSymbolsBox(selectedSymbols = selectedSymbols, onClear = {}, onClearAll = {})
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ fun SymbolSearchTextFieldPreview() {
SpeechBuddyTheme {
SymbolSearchTextField(
value = "검색어",
onValueChange = {},
onValueChange = {}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,21 @@ fun SymbolSelectionScreen(
Surface(modifier = modifier.fillMaxSize()) {
Column(
modifier = Modifier
.padding(start = 24.dp, top = 80.dp, end = 24.dp, bottom = 80.dp)
.padding(horizontal = 24.dp, vertical = 100.dp)
.fillMaxSize(),
verticalArrangement = Arrangement.spacedBy(20.dp)
) {
/* TODO: ViewModel 연결 */
SymbolSearchTextField(
value = viewModel.queryInput,
onValueChange = { viewModel.setQuery(it) })
onValueChange = { viewModel.setQuery(it) }
)

SelectedSymbolsBox(
selectedSymbols = viewModel.selectedSymbols,
onClearAll = { viewModel.clearAll() })
onClear = { viewModel.clear(it) },
onClearAll = { viewModel.clearAll() }
)

Box(
modifier = Modifier
Expand All @@ -64,11 +67,13 @@ fun SymbolSelectionScreen(
is Symbol -> SymbolUi(
symbol = entry,
onSelect = { viewModel.selectSymbol(entry) },
onFavoriteChange = {})
onFavoriteChange = { viewModel.toggleFavorite(entry, it) }
)

is Category -> CategoryUi(
category = entry,
onSelect = { viewModel.selectCategory(entry) })
onSelect = { viewModel.selectCategory(entry) }
)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ fun SymbolUi(
symbol: Symbol,
modifier: Modifier = Modifier,
onSelect: () -> Unit,
onFavoriteChange: () -> Unit
onFavoriteChange: (Boolean) -> Unit
) {
Card(
onClick = onSelect,
Expand All @@ -62,7 +62,7 @@ fun SymbolUi(
Box(contentAlignment = Alignment.TopEnd) {
IconToggleButton(
checked = symbol.isFavorite,
onCheckedChange = { onFavoriteChange() },
onCheckedChange = onFavoriteChange,
modifier = Modifier
.size(24.dp)
.padding(4.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ class SymbolSelectionViewModel @Inject internal constructor() : ViewModel() {
queryInput = input
}

fun clear(symbol: Symbol) {
val mutableSelectedSymbols = selectedSymbols.toMutableList()
mutableSelectedSymbols.remove(symbol)
selectedSymbols = mutableSelectedSymbols.toList()
}

fun clearAll() {
selectedSymbols = listOf()
entries = initialEntries
Expand All @@ -80,6 +86,10 @@ class SymbolSelectionViewModel @Inject internal constructor() : ViewModel() {
entries = secondaryEntries
}

fun toggleFavorite(symbol: Symbol, value: Boolean) {
/* TODO */
}

fun selectCategory(category: Category) {
/* TODO */
}
Expand Down

0 comments on commit 8571c12

Please sign in to comment.