Replace Local and In Library badge text with icons

Fixes #5725
This commit is contained in:
arkon
2023-02-12 17:22:34 -05:00
parent e052bdef96
commit 3a2dc46ff0
3 changed files with 76 additions and 7 deletions

View File

@@ -4,6 +4,9 @@ import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.RowScope
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.text.InlineTextContent
import androidx.compose.foundation.text.appendInlineContent
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
@@ -12,6 +15,10 @@ import androidx.compose.ui.draw.clip
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.graphics.Shape
import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.Placeholder
import androidx.compose.ui.text.PlaceholderVerticalAlign
import androidx.compose.ui.text.buildAnnotatedString
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
@@ -45,3 +52,47 @@ fun Badge(
style = MaterialTheme.typography.bodySmall,
)
}
@Composable
fun Badge(
imageVector: ImageVector,
color: Color = MaterialTheme.colorScheme.secondary,
iconColor: Color = MaterialTheme.colorScheme.onSecondary,
shape: Shape = RectangleShape,
) {
val iconContentPlaceholder = "[icon]"
val text = buildAnnotatedString {
appendInlineContent(iconContentPlaceholder)
}
val inlineContent = mapOf(
Pair(
iconContentPlaceholder,
InlineTextContent(
Placeholder(
width = MaterialTheme.typography.bodySmall.fontSize,
height = MaterialTheme.typography.bodySmall.fontSize,
placeholderVerticalAlign = PlaceholderVerticalAlign.Center,
),
) {
Icon(
imageVector = imageVector,
tint = iconColor,
contentDescription = null,
)
},
),
)
Text(
text = text,
inlineContent = inlineContent,
modifier = Modifier
.clip(shape)
.background(color)
.padding(horizontal = 3.dp, vertical = 1.dp),
color = iconColor,
fontWeight = FontWeight.Medium,
maxLines = 1,
style = MaterialTheme.typography.bodySmall,
)
}