Show own blocked domains as lazy list rows

All own domains were composed at once when the Blocklist tab opened.
The rows keep the look of the card they were in.
This commit is contained in:
2026-10-25 14:50:49 +02:00
parent ac643caf03
commit 17ede339fa
@@ -5,9 +5,11 @@ import android.net.Uri
import android.widget.Toast
import androidx.compose.animation.AnimatedVisibility
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.horizontalScroll
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
import androidx.compose.foundation.layout.fillMaxSize
@@ -15,12 +17,15 @@ import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.layout.width
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.foundation.lazy.itemsIndexed
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.shape.ZeroCornerSize
import androidx.compose.foundation.text.KeyboardActions
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.AssistChip
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.FilledTonalButton
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
@@ -40,6 +45,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.RectangleShape
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
@@ -100,13 +106,19 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
if (url.isNotEmpty() && Blocklist.download(context, url)) urlInput = ""
}
Column(
modifier = modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(16.dp),
verticalArrangement = Arrangement.spacedBy(12.dp),
// Own domains are lazy rows, so hundreds of them are not all composed when the tab opens.
// Together they look like the card they used to be in: same color and shape, split per row.
val cardColor = CardDefaults.cardColors().containerColor
val cardShape = MaterialTheme.shapes.medium
val cardTop = cardShape.copy(bottomStart = ZeroCornerSize, bottomEnd = ZeroCornerSize)
val cardBottom = cardShape.copy(topStart = ZeroCornerSize, topEnd = ZeroCornerSize)
LazyColumn(
modifier = modifier.fillMaxSize(),
contentPadding = PaddingValues(16.dp),
) {
item(key = "summary") {
Column(verticalArrangement = Arrangement.spacedBy(12.dp)) {
Card(Modifier.fillMaxWidth()) {
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
IconBadge(
@@ -144,12 +156,16 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
}
SectionHeader(stringResource(R.string.bl_my), icon = R.drawable.ic_tab_block)
}
}
Card(Modifier.fillMaxWidth()) {
item(key = "custom") {
Column(
Modifier
.animateContentSize(Motion.size)
.padding(vertical = 8.dp)
.padding(top = 12.dp)
.fillMaxWidth()
.background(cardColor, if (custom.isEmpty()) cardShape else cardTop)
.padding(top = 8.dp, bottom = if (custom.isEmpty()) 8.dp else 0.dp)
) {
Row(
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
@@ -188,7 +204,18 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
modifier = Modifier.padding(horizontal = 16.dp, vertical = 8.dp),
)
}
custom.forEach { domain ->
}
}
itemsIndexed(custom, key = { _, domain -> "domain:$domain" }, contentType = { _, _ -> "domain" }) { index, domain ->
val last = index == custom.lastIndex
Column(
Modifier
.animateItem()
.fillMaxWidth()
.background(cardColor, if (last) cardBottom else RectangleShape)
.padding(bottom = if (last) 8.dp else 0.dp)
) {
InsetDivider(16)
Row(
modifier = Modifier.padding(start = 16.dp, end = 4.dp),
@@ -201,8 +228,9 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
}
}
}
}
item(key = "lists") {
Column(Modifier.padding(top = 12.dp), verticalArrangement = Arrangement.spacedBy(12.dp)) {
SectionHeader(
stringResource(R.string.bl_lists),
icon = R.drawable.ic_list,
@@ -300,6 +328,8 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
)
}
}
}
}
}
@Composable