Add TagChip component
This commit is contained in:
parent
32bee8684e
commit
a811113602
@ -12,13 +12,11 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
|||||||
import androidx.compose.foundation.layout.fillMaxWidth
|
import androidx.compose.foundation.layout.fillMaxWidth
|
||||||
import androidx.compose.foundation.layout.height
|
import androidx.compose.foundation.layout.height
|
||||||
import androidx.compose.foundation.layout.padding
|
import androidx.compose.foundation.layout.padding
|
||||||
import androidx.compose.foundation.layout.requiredHeight
|
|
||||||
import androidx.compose.material.icons.Icons
|
import androidx.compose.material.icons.Icons
|
||||||
import androidx.compose.material.icons.rounded.Edit
|
import androidx.compose.material.icons.rounded.Edit
|
||||||
import androidx.compose.material.icons.rounded.ExpandLess
|
import androidx.compose.material.icons.rounded.ExpandLess
|
||||||
import androidx.compose.material.icons.rounded.ExpandMore
|
import androidx.compose.material.icons.rounded.ExpandMore
|
||||||
import androidx.compose.material.icons.rounded.Star
|
import androidx.compose.material.icons.rounded.Star
|
||||||
import androidx.compose.material.icons.rounded.Tag
|
|
||||||
import androidx.compose.material3.FilterChip
|
import androidx.compose.material3.FilterChip
|
||||||
import androidx.compose.material3.FloatingActionButtonDefaults
|
import androidx.compose.material3.FloatingActionButtonDefaults
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@ -57,7 +55,7 @@ fun FavoritesTagSelector(
|
|||||||
bottom = if (reverse) 4.dp else 8.dp,
|
bottom = if (reverse) 4.dp else 8.dp,
|
||||||
end = if (editButton) 8.dp else 0.dp
|
end = if (editButton) 8.dp else 0.dp
|
||||||
)
|
)
|
||||||
then
|
then
|
||||||
if (editButton && expanded) Modifier.height(IntrinsicSize.Min) else Modifier,
|
if (editButton && expanded) Modifier.height(IntrinsicSize.Min) else Modifier,
|
||||||
horizontalArrangement = Arrangement.End,
|
horizontalArrangement = Arrangement.End,
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
@ -85,17 +83,11 @@ fun FavoritesTagSelector(
|
|||||||
label = { Text(stringResource(R.string.favorites)) }
|
label = { Text(stringResource(R.string.favorites)) }
|
||||||
)
|
)
|
||||||
for (tag in tags) {
|
for (tag in tags) {
|
||||||
FilterChip(
|
TagChip(
|
||||||
modifier = Modifier.padding(start = 8.dp),
|
modifier = Modifier.padding(start = 8.dp),
|
||||||
|
tag = tag,
|
||||||
selected = selectedTag == tag.tag,
|
selected = selectedTag == tag.tag,
|
||||||
onClick = { onSelectTag(tag.tag) },
|
onClick = { onSelectTag(tag.tag) },
|
||||||
leadingIcon = {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Rounded.Tag,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
},
|
|
||||||
label = { Text(tag.label) }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
if (canScroll) {
|
if (canScroll) {
|
||||||
@ -124,17 +116,11 @@ fun FavoritesTagSelector(
|
|||||||
label = { Text(stringResource(R.string.favorites)) }
|
label = { Text(stringResource(R.string.favorites)) }
|
||||||
)
|
)
|
||||||
for (tag in tags) {
|
for (tag in tags) {
|
||||||
FilterChip(
|
TagChip(
|
||||||
modifier = Modifier.padding(end = 8.dp),
|
modifier = Modifier.padding(end = 8.dp),
|
||||||
|
tag = tag,
|
||||||
selected = selectedTag == tag.tag,
|
selected = selectedTag == tag.tag,
|
||||||
onClick = { onSelectTag(tag.tag) },
|
onClick = { onSelectTag(tag.tag) },
|
||||||
leadingIcon = {
|
|
||||||
Icon(
|
|
||||||
imageVector = Icons.Rounded.Tag,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
},
|
|
||||||
label = { Text(tag.label) }
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
57
app/ui/src/main/java/de/mm20/launcher2/ui/common/TagChip.kt
Normal file
57
app/ui/src/main/java/de/mm20/launcher2/ui/common/TagChip.kt
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
package de.mm20.launcher2.ui.common
|
||||||
|
|
||||||
|
import androidx.compose.foundation.clickable
|
||||||
|
import androidx.compose.material.icons.Icons
|
||||||
|
import androidx.compose.material.icons.rounded.Close
|
||||||
|
import androidx.compose.material.icons.rounded.Tag
|
||||||
|
import androidx.compose.material3.FilterChip
|
||||||
|
import androidx.compose.material3.FilterChipDefaults
|
||||||
|
import androidx.compose.material3.Icon
|
||||||
|
import androidx.compose.material3.SelectableChipColors
|
||||||
|
import androidx.compose.material3.SelectableChipElevation
|
||||||
|
import androidx.compose.material3.Text
|
||||||
|
import androidx.compose.runtime.Composable
|
||||||
|
import androidx.compose.ui.Modifier
|
||||||
|
import de.mm20.launcher2.search.data.Tag
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun TagChip(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
tag: Tag,
|
||||||
|
selected: Boolean = false,
|
||||||
|
onClick: () -> Unit = {},
|
||||||
|
clearable: Boolean = false,
|
||||||
|
onClear: (() -> Unit)? = null,
|
||||||
|
colors: SelectableChipColors = FilterChipDefaults.filterChipColors(),
|
||||||
|
elevation: SelectableChipElevation? = FilterChipDefaults.filterChipElevation(),
|
||||||
|
) {
|
||||||
|
FilterChip(
|
||||||
|
modifier = modifier,
|
||||||
|
selected = selected,
|
||||||
|
onClick = onClick,
|
||||||
|
leadingIcon = {
|
||||||
|
Icon(
|
||||||
|
imageVector = Icons.Rounded.Tag,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
},
|
||||||
|
label = {
|
||||||
|
Text(
|
||||||
|
tag.label
|
||||||
|
)
|
||||||
|
},
|
||||||
|
colors = colors,
|
||||||
|
elevation = elevation,
|
||||||
|
trailingIcon = if (clearable) {
|
||||||
|
{
|
||||||
|
Icon(
|
||||||
|
modifier = Modifier.clickable {
|
||||||
|
onClear?.invoke()
|
||||||
|
},
|
||||||
|
imageVector = Icons.Rounded.Close,
|
||||||
|
contentDescription = null
|
||||||
|
)
|
||||||
|
}
|
||||||
|
} else null
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -91,6 +91,7 @@ import de.mm20.launcher2.badges.Badge
|
|||||||
import de.mm20.launcher2.icons.LauncherIcon
|
import de.mm20.launcher2.icons.LauncherIcon
|
||||||
import de.mm20.launcher2.search.SavableSearchable
|
import de.mm20.launcher2.search.SavableSearchable
|
||||||
import de.mm20.launcher2.ui.R
|
import de.mm20.launcher2.ui.R
|
||||||
|
import de.mm20.launcher2.ui.common.TagChip
|
||||||
import de.mm20.launcher2.ui.component.BottomSheetDialog
|
import de.mm20.launcher2.ui.component.BottomSheetDialog
|
||||||
import de.mm20.launcher2.ui.component.MissingPermissionBanner
|
import de.mm20.launcher2.ui.component.MissingPermissionBanner
|
||||||
import de.mm20.launcher2.ui.component.ShapedLauncherIcon
|
import de.mm20.launcher2.ui.component.ShapedLauncherIcon
|
||||||
@ -101,7 +102,6 @@ import de.mm20.launcher2.ui.component.dragndrop.rememberLazyDragAndDropGridState
|
|||||||
import de.mm20.launcher2.ui.component.dragndrop.rememberLazyDragAndDropListState
|
import de.mm20.launcher2.ui.component.dragndrop.rememberLazyDragAndDropListState
|
||||||
import de.mm20.launcher2.ui.ktx.toPixels
|
import de.mm20.launcher2.ui.ktx.toPixels
|
||||||
import de.mm20.launcher2.ui.locals.LocalGridSettings
|
import de.mm20.launcher2.ui.locals.LocalGridSettings
|
||||||
import kotlinx.coroutines.currentCoroutineContext
|
|
||||||
import kotlin.math.roundToInt
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
@ -532,9 +532,13 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
|
|||||||
Icon(Icons.Rounded.Create, null)
|
Icon(Icons.Rounded.Create, null)
|
||||||
},
|
},
|
||||||
contentPadding = PaddingValues(
|
contentPadding = PaddingValues(
|
||||||
start = MenuDefaults.DropdownMenuItemContentPadding.calculateStartPadding(LocalLayoutDirection.current),
|
start = MenuDefaults.DropdownMenuItemContentPadding.calculateStartPadding(
|
||||||
end = MenuDefaults.DropdownMenuItemContentPadding.calculateEndPadding(LocalLayoutDirection.current),
|
LocalLayoutDirection.current
|
||||||
top = if(availableTags.isNotEmpty()) 8.dp else 0.dp,
|
),
|
||||||
|
end = MenuDefaults.DropdownMenuItemContentPadding.calculateEndPadding(
|
||||||
|
LocalLayoutDirection.current
|
||||||
|
),
|
||||||
|
top = if (availableTags.isNotEmpty()) 8.dp else 0.dp,
|
||||||
),
|
),
|
||||||
text = {
|
text = {
|
||||||
Box {
|
Box {
|
||||||
@ -546,7 +550,9 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
|
|||||||
}
|
}
|
||||||
BasicTextField(
|
BasicTextField(
|
||||||
value = newTag,
|
value = newTag,
|
||||||
onValueChange = { newTag = it.replace(",", "") },
|
onValueChange = {
|
||||||
|
newTag = it.replace(",", "")
|
||||||
|
},
|
||||||
textStyle = LocalTextStyle.current.copy(
|
textStyle = LocalTextStyle.current.copy(
|
||||||
color = LocalContentColor.current
|
color = LocalContentColor.current
|
||||||
),
|
),
|
||||||
@ -573,7 +579,7 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
|
|||||||
contentDescription = null
|
contentDescription = null
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
onClick = { }
|
onClick = { }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -595,34 +601,22 @@ fun ReorderFavoritesGrid(viewModel: EditFavoritesSheetVM, paddingValues: Padding
|
|||||||
) { tag ->
|
) { tag ->
|
||||||
DraggableItem(state = rowState, key = tag.key) { dragged ->
|
DraggableItem(state = rowState, key = tag.key) { dragged ->
|
||||||
|
|
||||||
FilterChip(
|
TagChip(
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.padding(end = 12.dp)
|
.padding(end = 12.dp)
|
||||||
.pointerInput(null) {
|
.pointerInput(null) {
|
||||||
val coroutineContext =
|
|
||||||
currentCoroutineContext()
|
|
||||||
|
|
||||||
},
|
},
|
||||||
|
tag = tag,
|
||||||
selected = tag.tag == hoveredTag,
|
selected = tag.tag == hoveredTag,
|
||||||
onClick = {},
|
|
||||||
label = { Text(tag.label) },
|
|
||||||
leadingIcon = {
|
|
||||||
Icon(Icons.Rounded.Tag, null)
|
|
||||||
},
|
|
||||||
trailingIcon = {
|
|
||||||
Icon(
|
|
||||||
modifier = Modifier.clickable {
|
|
||||||
viewModel.unpinTag(tag)
|
|
||||||
},
|
|
||||||
imageVector = Icons.Rounded.Close,
|
|
||||||
contentDescription = null
|
|
||||||
)
|
|
||||||
},
|
|
||||||
elevation = if (dragged) FilterChipDefaults.elevatedFilterChipElevation() else FilterChipDefaults.filterChipElevation(),
|
elevation = if (dragged) FilterChipDefaults.elevatedFilterChipElevation() else FilterChipDefaults.filterChipElevation(),
|
||||||
colors = if (dragged) FilterChipDefaults.elevatedFilterChipColors()
|
colors = if (dragged) FilterChipDefaults.elevatedFilterChipColors()
|
||||||
else FilterChipDefaults.filterChipColors(
|
else FilterChipDefaults.filterChipColors(
|
||||||
containerColor = MaterialTheme.colorScheme.surface
|
containerColor = MaterialTheme.colorScheme.surface
|
||||||
)
|
),
|
||||||
|
clearable = true,
|
||||||
|
onClear = {
|
||||||
|
viewModel.unpinTag(tag)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user