From a1b6097f112430c7a1ead6c9bc8c572d8669026f Mon Sep 17 00:00:00 2001 From: Diamond <33725716+DiamondMiner88@users.noreply.github.com> Date: Sat, 16 Apr 2022 22:15:35 -0700 Subject: [PATCH] wip: better ploogin cards --- .../manager/ui/components/PluginsList.kt | 3 +- .../ui/components/plugins/PluginCard.kt | 44 +++++++++++++++---- 2 files changed, 38 insertions(+), 9 deletions(-) diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/components/PluginsList.kt b/app/src/main/kotlin/com/aliucord/manager/ui/components/PluginsList.kt index 7788f3c..ca86335 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/components/PluginsList.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/components/PluginsList.kt @@ -37,9 +37,10 @@ fun PluginsList() = Column( if (plugins.isNotEmpty()) { OutlinedTextField( - modifier = Modifier.fillMaxWidth(), + maxLines = 1, value = search, onValueChange = { search = it }, + modifier = Modifier.fillMaxWidth(), label = { Text(stringResource(R.string.search)) }, trailingIcon = { Icon(Icons.Default.Search, stringResource(R.string.search_plugins)) }, keyboardOptions = KeyboardOptions(autoCorrect = false, imeAction = ImeAction.Search), diff --git a/app/src/main/kotlin/com/aliucord/manager/ui/components/plugins/PluginCard.kt b/app/src/main/kotlin/com/aliucord/manager/ui/components/plugins/PluginCard.kt index a4cd9d7..14eef84 100644 --- a/app/src/main/kotlin/com/aliucord/manager/ui/components/plugins/PluginCard.kt +++ b/app/src/main/kotlin/com/aliucord/manager/ui/components/plugins/PluginCard.kt @@ -7,11 +7,13 @@ package com.aliucord.manager.ui.components.plugins import androidx.compose.foundation.layout.* import androidx.compose.foundation.selection.toggleable +import androidx.compose.foundation.text.ClickableText import androidx.compose.material.icons.Icons import androidx.compose.material.icons.filled.Delete import androidx.compose.material3.* import androidx.compose.runtime.* import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.alpha import androidx.compose.ui.platform.LocalUriHandler import androidx.compose.ui.res.painterResource import androidx.compose.ui.res.stringResource @@ -35,6 +37,7 @@ fun PluginCard( modifier = Modifier.padding(12.dp) ) { var isEnabled by remember { mutableStateOf(true) } + val uriHandler = LocalUriHandler.current // Header Row( @@ -54,10 +57,33 @@ fun PluginCard( } ) - // Author(s) - Text( - "By ${plugin.manifest.authors.joinToString { it.name }}", - style = MaterialTheme.typography.labelMedium + // Authors + val authors = buildAnnotatedString { + pushStyle(SpanStyle(color = MaterialTheme.colorScheme.secondary)) + append("By ") + + val authors = plugin.manifest.authors + authors.forEachIndexed { i, author -> + withStyle(SpanStyle(color = MaterialTheme.colorScheme.primary)) { + val start = this@buildAnnotatedString.length + append(author.name) + addStringAnnotation("authorId", author.id.toString(), start, start + author.name.length) + } + if (authors.size < i) + append(',') + } + } + ClickableText( + text = authors, + style = MaterialTheme.typography.labelMedium, + onClick = { + authors.getStringAnnotations("authorId", it, it) + .firstOrNull() + ?.let { (id) -> + val url = "https://discord.com/users/$id" + uriHandler.openUri(url) + } + } ) } @@ -70,17 +96,19 @@ fun PluginCard( ) } + Divider(modifier = Modifier.alpha(0.1f)) + // Description Text( text = plugin.manifest.description, - modifier = Modifier.heightIn(min = 50.dp), - style = MaterialTheme.typography.bodyMedium + style = MaterialTheme.typography.bodyMedium, + modifier = Modifier + .heightIn(max = 60.dp, min = 20.dp) + .padding(top = 10.dp), ) // Buttons Row(Modifier.fillMaxWidth()) { - val uriHandler = LocalUriHandler.current - IconButton( onClick = { uriHandler.openUri(