mirror of
https://github.com/kalarina-bit/Sparkledns.git
synced 2026-11-22 07:36:09 +00:00
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:
@@ -5,9 +5,11 @@ import android.net.Uri
|
|||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.compose.animation.AnimatedVisibility
|
import androidx.compose.animation.AnimatedVisibility
|
||||||
import androidx.compose.animation.animateContentSize
|
import androidx.compose.animation.animateContentSize
|
||||||
|
import androidx.compose.foundation.background
|
||||||
import androidx.compose.foundation.horizontalScroll
|
import androidx.compose.foundation.horizontalScroll
|
||||||
import androidx.compose.foundation.layout.Arrangement
|
import androidx.compose.foundation.layout.Arrangement
|
||||||
import androidx.compose.foundation.layout.Column
|
import androidx.compose.foundation.layout.Column
|
||||||
|
import androidx.compose.foundation.layout.PaddingValues
|
||||||
import androidx.compose.foundation.layout.Row
|
import androidx.compose.foundation.layout.Row
|
||||||
import androidx.compose.foundation.layout.Spacer
|
import androidx.compose.foundation.layout.Spacer
|
||||||
import androidx.compose.foundation.layout.fillMaxSize
|
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.padding
|
||||||
import androidx.compose.foundation.layout.size
|
import androidx.compose.foundation.layout.size
|
||||||
import androidx.compose.foundation.layout.width
|
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.rememberScrollState
|
||||||
|
import androidx.compose.foundation.shape.ZeroCornerSize
|
||||||
import androidx.compose.foundation.text.KeyboardActions
|
import androidx.compose.foundation.text.KeyboardActions
|
||||||
import androidx.compose.foundation.text.KeyboardOptions
|
import androidx.compose.foundation.text.KeyboardOptions
|
||||||
import androidx.compose.foundation.verticalScroll
|
|
||||||
import androidx.compose.material3.AssistChip
|
import androidx.compose.material3.AssistChip
|
||||||
import androidx.compose.material3.Card
|
import androidx.compose.material3.Card
|
||||||
|
import androidx.compose.material3.CardDefaults
|
||||||
import androidx.compose.material3.FilledTonalButton
|
import androidx.compose.material3.FilledTonalButton
|
||||||
import androidx.compose.material3.HorizontalDivider
|
import androidx.compose.material3.HorizontalDivider
|
||||||
import androidx.compose.material3.Icon
|
import androidx.compose.material3.Icon
|
||||||
@@ -40,6 +45,7 @@ import androidx.compose.runtime.saveable.rememberSaveable
|
|||||||
import androidx.compose.runtime.setValue
|
import androidx.compose.runtime.setValue
|
||||||
import androidx.compose.ui.Alignment
|
import androidx.compose.ui.Alignment
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
|
import androidx.compose.ui.graphics.RectangleShape
|
||||||
import androidx.compose.ui.platform.LocalContext
|
import androidx.compose.ui.platform.LocalContext
|
||||||
import androidx.compose.ui.res.painterResource
|
import androidx.compose.ui.res.painterResource
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
@@ -100,13 +106,19 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
|
|||||||
if (url.isNotEmpty() && Blocklist.download(context, url)) urlInput = ""
|
if (url.isNotEmpty() && Blocklist.download(context, url)) urlInput = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
Column(
|
// Own domains are lazy rows, so hundreds of them are not all composed when the tab opens.
|
||||||
modifier = modifier
|
// Together they look like the card they used to be in: same color and shape, split per row.
|
||||||
.fillMaxSize()
|
val cardColor = CardDefaults.cardColors().containerColor
|
||||||
.verticalScroll(rememberScrollState())
|
val cardShape = MaterialTheme.shapes.medium
|
||||||
.padding(16.dp),
|
val cardTop = cardShape.copy(bottomStart = ZeroCornerSize, bottomEnd = ZeroCornerSize)
|
||||||
verticalArrangement = Arrangement.spacedBy(12.dp),
|
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()) {
|
Card(Modifier.fillMaxWidth()) {
|
||||||
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
|
Row(Modifier.padding(16.dp), verticalAlignment = Alignment.CenterVertically) {
|
||||||
IconBadge(
|
IconBadge(
|
||||||
@@ -144,12 +156,16 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
SectionHeader(stringResource(R.string.bl_my), icon = R.drawable.ic_tab_block)
|
SectionHeader(stringResource(R.string.bl_my), icon = R.drawable.ic_tab_block)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Card(Modifier.fillMaxWidth()) {
|
item(key = "custom") {
|
||||||
Column(
|
Column(
|
||||||
Modifier
|
Modifier
|
||||||
.animateContentSize(Motion.size)
|
.padding(top = 12.dp)
|
||||||
.padding(vertical = 8.dp)
|
.fillMaxWidth()
|
||||||
|
.background(cardColor, if (custom.isEmpty()) cardShape else cardTop)
|
||||||
|
.padding(top = 8.dp, bottom = if (custom.isEmpty()) 8.dp else 0.dp)
|
||||||
) {
|
) {
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(horizontal = 12.dp, vertical = 4.dp),
|
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),
|
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)
|
InsetDivider(16)
|
||||||
Row(
|
Row(
|
||||||
modifier = Modifier.padding(start = 16.dp, end = 4.dp),
|
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(
|
SectionHeader(
|
||||||
stringResource(R.string.bl_lists),
|
stringResource(R.string.bl_lists),
|
||||||
icon = R.drawable.ic_list,
|
icon = R.drawable.ic_list,
|
||||||
@@ -300,6 +328,8 @@ fun BlocklistScreen(modifier: Modifier = Modifier) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
|
|||||||
Reference in New Issue
Block a user