Show tags in item detail views

This commit is contained in:
MM20 2022-09-24 21:46:07 +02:00
parent 21bdbb2f0a
commit 2c307693f2
No known key found for this signature in database
GPG Key ID: 0B61A8F2DEAFA389
8 changed files with 89 additions and 9 deletions

View File

@ -4,7 +4,6 @@ import androidx.compose.animation.*
import androidx.compose.animation.core.snap
import androidx.compose.animation.core.tween
import androidx.compose.foundation.layout.*
import androidx.compose.material.ExperimentalMaterialApi
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.rounded.*
import androidx.compose.material3.MaterialTheme
@ -35,7 +34,6 @@ import de.mm20.launcher2.ui.locals.LocalGridIconSize
import de.mm20.launcher2.ui.locals.LocalSnackbarHostState
import de.mm20.launcher2.ui.modifier.scale
import kotlinx.coroutines.launch
import kotlin.math.min
import kotlin.math.pow
import kotlin.math.roundToInt
@ -62,7 +60,22 @@ fun AppItem(
.weight(1f)
.padding(16.dp)
) {
Text(text = app.labelOverride ?: app.label, style = MaterialTheme.typography.titleMedium)
Text(
text = app.labelOverride ?: app.label,
style = MaterialTheme.typography.titleMedium
)
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp, bottom = 4.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
app.version?.let {
Text(
text = stringResource(R.string.app_info_version, it),
@ -75,16 +88,16 @@ fun AppItem(
Text(
text = app.`package`,
style = MaterialTheme.typography.bodySmall,
modifier = Modifier.padding(top = 4.dp),
modifier = Modifier.padding(top = 1.dp),
maxLines = 1,
overflow = TextOverflow.Ellipsis
overflow = TextOverflow.Ellipsis,
)
FlowRow(
modifier = Modifier
.padding(top = 16.dp)
.padding(top = 12.dp)
.animateContentSize(),
mainAxisSpacing = 16.dp,
mainAxisSpacing = 12.dp,
crossAxisSpacing = 0.dp
) {
val notifications by viewModel.notifications.collectAsState(initial = emptyList())
@ -290,8 +303,8 @@ fun AppItem(
message = context.getString(R.string.msg_item_hidden, app.label),
actionLabel = context.getString(R.string.action_undo),
duration = SnackbarDuration.Short,
)
if(result == SnackbarResult.ActionPerformed) {
)
if (result == SnackbarResult.ActionPerformed) {
viewModel.unhide()
}
}

View File

@ -88,6 +88,17 @@ fun CalendarItem(
style = MaterialTheme.typography.bodySmall
)
}
AnimatedVisibility(showDetails) {
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp, bottom = 4.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
}
}
}
AnimatedVisibility(showDetails) {

View File

@ -5,6 +5,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.compose.ui.geometry.Rect
import androidx.core.app.ActivityOptionsCompat
import de.mm20.launcher2.badges.BadgeRepository
import de.mm20.launcher2.customattrs.CustomAttributesRepository
import de.mm20.launcher2.favorites.FavoritesRepository
import de.mm20.launcher2.icons.IconRepository
import de.mm20.launcher2.icons.LauncherIcon
@ -22,6 +23,7 @@ abstract class SearchableItemVM(
protected val favoritesRepository: FavoritesRepository by inject()
protected val badgeRepository: BadgeRepository by inject()
protected val iconRepository: IconRepository by inject()
protected val customAttributesRepository: CustomAttributesRepository by inject()
val isPinned = favoritesRepository.isPinned(searchable)
fun pin() {
@ -47,6 +49,10 @@ abstract class SearchableItemVM(
return iconRepository.getIcon(searchable, size)
}
fun getTags(): Flow<List<String>> {
return customAttributesRepository.getTags(searchable)
}
open fun launch(context: Context, bounds: Rect? = null): Boolean {
val view = (context as? AppCompatActivity)?.window?.decorView

View File

@ -94,6 +94,17 @@ fun ContactItem(
overflow = TextOverflow.Ellipsis
)
}
AnimatedVisibility(showDetails) {
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
}
}
}

View File

@ -88,6 +88,15 @@ fun FileItem(
}
AnimatedVisibility(showDetails) {
Column {
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp, bottom = 4.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
Text(
text = stringResource(
R.string.file_meta_type,

View File

@ -69,6 +69,18 @@ fun AppShortcutItem(
maxLines = 1,
overflow = TextOverflow.Ellipsis
)
AnimatedVisibility(showDetails) {
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp, bottom = 2.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
}
val textSpace by transition.animateDp(label = "textSpace") {
if (it) 4.dp else 2.dp
}

View File

@ -60,6 +60,15 @@ fun WebsiteItem(
text = website.label,
style = MaterialTheme.typography.titleLarge
)
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 2.dp, bottom = 2.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
Text(
modifier = Modifier.padding(vertical = 8.dp),
text = website.description,

View File

@ -61,6 +61,15 @@ fun WikipediaItem(
text = wikipedia.label,
style = MaterialTheme.typography.titleLarge
)
val tags by remember(viewModel) { viewModel.getTags() }.collectAsState(emptyList())
if (tags.isNotEmpty()) {
Text(
modifier = Modifier.padding(top = 1.dp, bottom = 4.dp),
text = tags.joinToString(separator = " #", prefix = "#"),
color = MaterialTheme.colorScheme.secondary,
style = MaterialTheme.typography.labelSmall
)
}
Text(
modifier = Modifier.padding(top = 4.dp),
text = stringResource(id = R.string.wikipedia_source),