Skip to content

Commit

Permalink
Long press tag to edit
Browse files Browse the repository at this point in the history
  • Loading branch information
MM2-0 committed Oct 20, 2024
1 parent 4f5e80d commit 52bba7f
Show file tree
Hide file tree
Showing 4 changed files with 240 additions and 132 deletions.
253 changes: 129 additions & 124 deletions app/ui/src/main/java/de/mm20/launcher2/ui/common/FavoritesTagSelector.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package de.mm20.launcher2.ui.common

import androidx.compose.animation.AnimatedContent
import androidx.compose.animation.EnterExitState
import androidx.compose.animation.SharedTransitionLayout
import androidx.compose.animation.core.animateFloat
import androidx.compose.foundation.ScrollState
import androidx.compose.foundation.combinedClickable
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
Expand Down Expand Up @@ -54,153 +54,158 @@ fun FavoritesTagSelector(
) {
val sheetManager = LocalBottomSheetManager.current


AnimatedContent(
modifier = Modifier
.fillMaxWidth()
.padding(
top = if (reverse) 8.dp else 4.dp,
bottom = if (reverse) 4.dp else 8.dp,
end = if (editButton) 8.dp else 0.dp
),
targetState = expanded,
) {
if (!it) {
val canScroll by remember {
derivedStateOf { scrollState.canScrollForward || scrollState.canScrollBackward }
}
Row {
Row(
AnimatedContent(
modifier = Modifier
.fillMaxWidth()
.padding(
top = if (reverse) 8.dp else 4.dp,
bottom = if (reverse) 4.dp else 8.dp,
end = if (editButton) 8.dp else 0.dp
),
targetState = expanded,
) {
if (!it) {
val canScroll by remember {
derivedStateOf { scrollState.canScrollForward || scrollState.canScrollBackward }
}
Row {
Row(
modifier = Modifier
.weight(1f)
.consumeAllScrolling()
.horizontalScroll(scrollState)
.padding(end = 12.dp),
) {
FilterChip(
modifier = Modifier
.weight(1f)
.consumeAllScrolling()
.horizontalScroll(scrollState)
.padding(end = 12.dp),
) {
FilterChip(
.padding(start = 16.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
},
label = { Text(stringResource(R.string.favorites)) }
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(start = 16.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
.padding(start = 8.dp),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
label = { Text(stringResource(R.string.favorites)) }
onLongClick = {
sheetManager.showEditTagSheet(tag.tag)
}
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(start = 8.dp),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
)
}
if (canScroll) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
if (canScroll) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(true) }) {
Icon(Icons.Rounded.ExpandMore, null)
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(true) }) {
Icon(Icons.Rounded.ExpandMore, null)
}

}

if (editButton) {
SmallFloatingActionButton(
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() }
) {
Icon(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
}

if (editButton) {
SmallFloatingActionButton(
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() }
) {
Icon(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
}
} else {
Row(
verticalAlignment = if (reverse) Alignment.Top else Alignment.Bottom,
}
} else {
Row(
verticalAlignment = if (reverse) Alignment.Top else Alignment.Bottom,
) {
FlowRow(
modifier = Modifier
.weight(1f)
.padding(end = 12.dp, start = 16.dp),
) {
FlowRow(
FilterChip(
modifier = Modifier
.weight(1f)
.padding(end = 12.dp, start = 16.dp),
) {
FilterChip(
.padding(end = 8.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
},
label = { Text(stringResource(R.string.favorites)) }
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(end = 8.dp),
selected = selectedTag == null,
onClick = { onSelectTag(null) },
leadingIcon = {
Icon(
imageVector = Icons.Rounded.Star,
contentDescription = null,
modifier = Modifier.size(FilterChipDefaults.IconSize),
)
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
label = { Text(stringResource(R.string.favorites)) }
onLongClick = {
sheetManager.showEditTagSheet(tag.tag)
}
)
for (tag in tags) {
TagChip(
modifier = Modifier
.padding(end = 8.dp),
tag = tag,
selected = selectedTag == tag.tag,
onClick = {
if (selectedTag == tag.tag) {
onSelectTag(null)
} else {
onSelectTag(tag.tag)
}
},
)
}
}
}

Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = if (reverse) Arrangement.TopReversed else Arrangement.Bottom,
Column(
modifier = Modifier.fillMaxHeight(),
verticalArrangement = if (reverse) Arrangement.TopReversed else Arrangement.Bottom,
) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(false) }
) {
val rot by transition.animateFloat {
if (it == EnterExitState.Visible) 0f else 180f
}
IconButton(
modifier = Modifier
.rotate(rot),
onClick = { onExpand(false) }
) {
Icon(Icons.Rounded.ExpandLess, null)
}
Icon(Icons.Rounded.ExpandLess, null)
}

if (editButton) {
SmallFloatingActionButton(
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() }
) {
Icon(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
if (editButton) {
SmallFloatingActionButton(
elevation = FloatingActionButtonDefaults.bottomAppBarFabElevation(),
onClick = { sheetManager.showEditFavoritesSheet() }
) {
Icon(
imageVector = Icons.Rounded.Edit,
contentDescription = null
)
}
}
}
}
}
}
}

Loading

0 comments on commit 52bba7f

Please sign in to comment.