Search column: add possibility to add content before and after card contents
This commit is contained in:
parent
e3a466685c
commit
bcd144e8a1
@ -72,7 +72,7 @@ fun SearchColumn(
|
|||||||
items = apps.toImmutableList(),
|
items = apps.toImmutableList(),
|
||||||
columns = columns,
|
columns = columns,
|
||||||
showLabels = showLabels,
|
showLabels = showLabels,
|
||||||
reverse = reverse,
|
reverse = reverse
|
||||||
)
|
)
|
||||||
ListResults(appShortcuts.toImmutableList(), reverse)
|
ListResults(appShortcuts.toImmutableList(), reverse)
|
||||||
val uc = unitConverter
|
val uc = unitConverter
|
||||||
@ -113,17 +113,47 @@ fun LazyListScope.GridResults(
|
|||||||
columns: Int,
|
columns: Int,
|
||||||
reverse: Boolean,
|
reverse: Boolean,
|
||||||
showLabels: Boolean,
|
showLabels: Boolean,
|
||||||
|
before: (@Composable () -> Unit)? = null,
|
||||||
|
after: (@Composable () -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (items.isEmpty()) return
|
if (items.isEmpty()) return
|
||||||
|
|
||||||
|
if (before != null) {
|
||||||
|
item(contentType = "ListItemsBefore") {
|
||||||
|
PartialCardRow(isFirst = true, isLast = false, reverse = reverse) {
|
||||||
|
before()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val rows = ceil(items.size / columns.toFloat()).toInt()
|
val rows = ceil(items.size / columns.toFloat()).toInt()
|
||||||
items(rows) {
|
items(rows) {
|
||||||
GridRow(
|
PartialCardRow(
|
||||||
items = items.subList(it * columns, (it * columns + columns).coerceAtMost(items.size)),
|
isFirst = it == 0 && before == null,
|
||||||
columns = columns,
|
isLast = it == rows - 1 && after == null,
|
||||||
showLabels = showLabels,
|
reverse = reverse
|
||||||
isFirst = if (reverse) it == rows - 1 else it == 0,
|
) {
|
||||||
isLast = if (reverse) it == 0 else it == rows - 1
|
GridRow(
|
||||||
)
|
modifier = Modifier.padding(
|
||||||
|
top = if (if (reverse) it == rows - 1 else it == 0) 4.dp else 0.dp,
|
||||||
|
bottom = if (if (reverse) it == 0 else it == rows - 1) 2.dp else 0.dp,
|
||||||
|
),
|
||||||
|
items = items.subList(
|
||||||
|
it * columns,
|
||||||
|
(it * columns + columns).coerceAtMost(items.size)
|
||||||
|
),
|
||||||
|
columns = columns,
|
||||||
|
showLabels = showLabels,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (after != null) {
|
||||||
|
item(contentType = "ListItemsAfter") {
|
||||||
|
PartialCardRow(isFirst = false, isLast = true, reverse = reverse) {
|
||||||
|
after()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -133,42 +163,22 @@ fun GridRow(
|
|||||||
items: ImmutableList<Searchable>,
|
items: ImmutableList<Searchable>,
|
||||||
columns: Int,
|
columns: Int,
|
||||||
showLabels: Boolean,
|
showLabels: Boolean,
|
||||||
isFirst: Boolean,
|
|
||||||
isLast: Boolean,
|
|
||||||
) {
|
) {
|
||||||
Box(
|
|
||||||
|
Row(
|
||||||
modifier = modifier
|
modifier = modifier
|
||||||
.clipToBounds()
|
|
||||||
) {
|
) {
|
||||||
PartialLauncherCard(
|
for (item in items) {
|
||||||
modifier = Modifier.padding(
|
GridItem(
|
||||||
start = 8.dp,
|
modifier = Modifier
|
||||||
end = 8.dp,
|
.weight(1f)
|
||||||
top = if (isFirst) 4.dp else 0.dp,
|
.padding(4.dp, 8.dp),
|
||||||
bottom = if (isLast) 4.dp else 0.dp,
|
item = item,
|
||||||
),
|
showLabels = showLabels
|
||||||
isTop = isFirst,
|
)
|
||||||
isBottom = isLast,
|
}
|
||||||
) {
|
for (i in 0 until columns - items.size) {
|
||||||
Row(
|
Spacer(modifier = Modifier.weight(1f))
|
||||||
modifier = Modifier.padding(
|
|
||||||
top = if (isFirst) 4.dp else 0.dp,
|
|
||||||
bottom = if (isLast) 2.dp else 0.dp,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
for (item in items) {
|
|
||||||
GridItem(
|
|
||||||
modifier = Modifier
|
|
||||||
.weight(1f)
|
|
||||||
.padding(4.dp, 8.dp),
|
|
||||||
item = item,
|
|
||||||
showLabels = showLabels
|
|
||||||
)
|
|
||||||
}
|
|
||||||
for (i in 0 until columns - items.size) {
|
|
||||||
Spacer(modifier = Modifier.weight(1f))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -176,14 +186,38 @@ fun GridRow(
|
|||||||
fun LazyListScope.ListResults(
|
fun LazyListScope.ListResults(
|
||||||
items: ImmutableList<Searchable>,
|
items: ImmutableList<Searchable>,
|
||||||
reverse: Boolean,
|
reverse: Boolean,
|
||||||
|
before: (@Composable () -> Unit)? = null,
|
||||||
|
after: (@Composable () -> Unit)? = null,
|
||||||
) {
|
) {
|
||||||
if (items.isEmpty()) return
|
if (items.isEmpty()) return
|
||||||
|
if (before != null) {
|
||||||
|
item(contentType = "ListItemsBefore") {
|
||||||
|
PartialCardRow(isFirst = true, isLast = false, reverse = reverse) {
|
||||||
|
before()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
items(items.size) {
|
items(items.size) {
|
||||||
ListRow(
|
PartialCardRow(
|
||||||
item = items[it],
|
isFirst = it == 0 && before == null,
|
||||||
isFirst = if (reverse) it == items.size - 1 else it == 0,
|
isLast = it == items.lastIndex && after == null,
|
||||||
isLast = if (reverse) it == 0 else it == items.size - 1
|
reverse = reverse
|
||||||
)
|
) {
|
||||||
|
ListRow(
|
||||||
|
modifier = Modifier.padding(
|
||||||
|
top = if (if (reverse) it == items.size - 1 else it == 0) 8.dp else 4.dp,
|
||||||
|
bottom = if (if (reverse) it == 0 else it == items.size - 1) 8.dp else 4.dp,
|
||||||
|
),
|
||||||
|
item = items[it],
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (after != null) {
|
||||||
|
item(contentType = "ListItemsAfter") {
|
||||||
|
PartialCardRow(isFirst = false, isLast = true, reverse = reverse) {
|
||||||
|
after()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,38 +225,18 @@ fun LazyListScope.ListResults(
|
|||||||
fun ListRow(
|
fun ListRow(
|
||||||
modifier: Modifier = Modifier,
|
modifier: Modifier = Modifier,
|
||||||
item: Searchable,
|
item: Searchable,
|
||||||
isFirst: Boolean,
|
|
||||||
isLast: Boolean,
|
|
||||||
) {
|
) {
|
||||||
Box(
|
Box(
|
||||||
modifier = modifier
|
modifier = modifier.padding(
|
||||||
.clipToBounds()
|
start = 8.dp,
|
||||||
|
end = 8.dp,
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
PartialLauncherCard(
|
ListItem(
|
||||||
modifier = Modifier.padding(
|
modifier = Modifier
|
||||||
start = 8.dp,
|
.fillMaxWidth(),
|
||||||
end = 8.dp,
|
item = item
|
||||||
top = if (isFirst) 4.dp else 0.dp,
|
)
|
||||||
bottom = if (isLast) 4.dp else 0.dp,
|
|
||||||
),
|
|
||||||
isTop = isFirst,
|
|
||||||
isBottom = isLast,
|
|
||||||
) {
|
|
||||||
Box(
|
|
||||||
modifier = Modifier.padding(
|
|
||||||
start = 8.dp,
|
|
||||||
end = 8.dp,
|
|
||||||
top = if (isFirst) 8.dp else 4.dp,
|
|
||||||
bottom = if (isLast) 8.dp else 4.dp,
|
|
||||||
)
|
|
||||||
) {
|
|
||||||
ListItem(
|
|
||||||
modifier = Modifier
|
|
||||||
.fillMaxWidth(),
|
|
||||||
item = item
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -239,3 +253,32 @@ fun LazyListScope.SingleResult(content: @Composable (() -> Unit)?) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
fun PartialCardRow(
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
isFirst: Boolean,
|
||||||
|
isLast: Boolean,
|
||||||
|
reverse: Boolean,
|
||||||
|
content: @Composable () -> Unit
|
||||||
|
) {
|
||||||
|
val isTop = isFirst && !reverse || isLast && reverse
|
||||||
|
val isBottom = isLast && !reverse || isFirst && reverse
|
||||||
|
Box(
|
||||||
|
modifier = modifier
|
||||||
|
.clipToBounds()
|
||||||
|
) {
|
||||||
|
PartialLauncherCard(
|
||||||
|
modifier = Modifier.padding(
|
||||||
|
start = 8.dp,
|
||||||
|
end = 8.dp,
|
||||||
|
top = if (isTop) 4.dp else 0.dp,
|
||||||
|
bottom = if (isBottom) 4.dp else 0.dp,
|
||||||
|
),
|
||||||
|
isTop = isTop,
|
||||||
|
isBottom = isBottom,
|
||||||
|
) {
|
||||||
|
content()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user