Block code styling
This commit is contained in:
@ -5,10 +5,7 @@ import kotlinx.serialization.json.Json
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
@Serializable
|
@Serializable
|
||||||
class BlockRule(
|
class BlockRule(val aor: String = "", val pattern: String) {
|
||||||
val aor: String = "",
|
|
||||||
val pattern: String
|
|
||||||
) {
|
|
||||||
fun matches(uri: String): Boolean {
|
fun matches(uri: String): Boolean {
|
||||||
if (uri.contains(pattern, ignoreCase = true)) return true
|
if (uri.contains(pattern, ignoreCase = true)) return true
|
||||||
return try {
|
return try {
|
||||||
|
|||||||
@ -16,9 +16,7 @@ class Blocked (
|
|||||||
|
|
||||||
fun add() {
|
fun add() {
|
||||||
BaresipService.blocked.add(this)
|
BaresipService.blocked.add(this)
|
||||||
val aorBlocked = BaresipService.blocked.filter {
|
val aorBlocked = BaresipService.blocked.filter { it.aor == this.aor && it.request == this.request }
|
||||||
it.aor == this.aor && it.request == this.request
|
|
||||||
}
|
|
||||||
if (aorBlocked.size > blockedSize) {
|
if (aorBlocked.size > blockedSize) {
|
||||||
val oldestToRemove = aorBlocked.first()
|
val oldestToRemove = aorBlocked.first()
|
||||||
BaresipService.blocked.remove(oldestToRemove)
|
BaresipService.blocked.remove(oldestToRemove)
|
||||||
|
|||||||
@ -93,18 +93,13 @@ private fun BlockedScreen(navController: NavController, request: String, aor: St
|
|||||||
|
|
||||||
DisposableEffect(lifecycleOwner) {
|
DisposableEffect(lifecycleOwner) {
|
||||||
val observer = LifecycleEventObserver { _, event ->
|
val observer = LifecycleEventObserver { _, event ->
|
||||||
if (event == Lifecycle.Event.ON_RESUME)
|
if (event == Lifecycle.Event.ON_RESUME) refreshTrigger++
|
||||||
refreshTrigger++
|
|
||||||
}
|
}
|
||||||
lifecycleOwner.lifecycle.addObserver(observer)
|
lifecycleOwner.lifecycle.addObserver(observer)
|
||||||
onDispose {
|
onDispose { lifecycleOwner.lifecycle.removeObserver(observer) }
|
||||||
lifecycleOwner.lifecycle.removeObserver(observer)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
BackHandler(enabled = true) {
|
BackHandler(enabled = true) { navController.navigateUp() }
|
||||||
navController.navigateUp()
|
|
||||||
}
|
|
||||||
|
|
||||||
Scaffold(
|
Scaffold(
|
||||||
modifier = Modifier.fillMaxSize().imePadding(),
|
modifier = Modifier.fillMaxSize().imePadding(),
|
||||||
@ -117,12 +112,7 @@ private fun BlockedScreen(navController: NavController, request: String, aor: St
|
|||||||
},
|
},
|
||||||
content = { contentPadding ->
|
content = { contentPadding ->
|
||||||
if (isBlockedLoaded)
|
if (isBlockedLoaded)
|
||||||
BlockedContent(
|
BlockedContent(LocalContext.current, navController, contentPadding, account, blocked)
|
||||||
LocalContext.current,
|
|
||||||
navController,
|
|
||||||
contentPadding,
|
|
||||||
account, blocked
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -167,9 +157,7 @@ private fun TopAppBar(
|
|||||||
),
|
),
|
||||||
windowInsets = WindowInsets(0, 0, 0, 0),
|
windowInsets = WindowInsets(0, 0, 0, 0),
|
||||||
navigationIcon = {
|
navigationIcon = {
|
||||||
IconButton(
|
IconButton(onClick = { navController.navigateUp() }) {
|
||||||
onClick = { navController.navigateUp() }
|
|
||||||
) {
|
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
imageVector = Icons.AutoMirrored.Filled.ArrowBack,
|
||||||
contentDescription = "Back",
|
contentDescription = "Back",
|
||||||
@ -177,9 +165,7 @@ private fun TopAppBar(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
actions = {
|
actions = {
|
||||||
IconButton(
|
IconButton(onClick = { expanded = !expanded }) {
|
||||||
onClick = { expanded = !expanded }
|
|
||||||
) {
|
|
||||||
Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu")
|
Icon(imageVector = Icons.Filled.Menu, contentDescription = "Menu")
|
||||||
}
|
}
|
||||||
CustomElements.DropdownMenu(
|
CustomElements.DropdownMenu(
|
||||||
@ -275,12 +261,11 @@ private fun Blocked(
|
|||||||
.clickable(
|
.clickable(
|
||||||
enabled = !peerUri.contains("anonymous") && peerUri != unknown,
|
enabled = !peerUri.contains("anonymous") && peerUri != unknown,
|
||||||
onClick = {
|
onClick = {
|
||||||
message.value = String.format(ctx.getString(R.string.blocked_contact_question),
|
message.value = String.format(
|
||||||
peerUri)
|
ctx.getString(R.string.blocked_contact_question), peerUri
|
||||||
|
)
|
||||||
lastButtonText.value = ctx.getString(R.string.add_contact)
|
lastButtonText.value = ctx.getString(R.string.add_contact)
|
||||||
lastAction.value = {
|
lastAction.value = { navController.navigate("contact/$peerUri/new") }
|
||||||
navController.navigate("contact/$peerUri/new")
|
|
||||||
}
|
|
||||||
showDialog.value = true
|
showDialog.value = true
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -288,7 +273,8 @@ private fun Blocked(
|
|||||||
Text(
|
Text(
|
||||||
text = "\u2022",
|
text = "\u2022",
|
||||||
modifier = Modifier.padding(start = 8.dp, end = 4.dp),
|
modifier = Modifier.padding(start = 8.dp, end = 4.dp),
|
||||||
fontSize = 18.sp)
|
fontSize = 18.sp
|
||||||
|
)
|
||||||
Text(
|
Text(
|
||||||
text = Utils.friendlyUri(ctx, peerUri, acc),
|
text = Utils.friendlyUri(ctx, peerUri, acc),
|
||||||
fontSize = 18.sp,
|
fontSize = 18.sp,
|
||||||
|
|||||||
@ -93,9 +93,7 @@ fun BlockingScreen(navController: NavController, viewModel: AccountViewModel, ua
|
|||||||
Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) {
|
Column(modifier = Modifier.background(MaterialTheme.colorScheme.background)) {
|
||||||
Spacer(Modifier.statusBarsPadding())
|
Spacer(Modifier.statusBarsPadding())
|
||||||
TopAppBar(
|
TopAppBar(
|
||||||
title = {
|
title = { Text(text = stringResource(R.string.blocking), fontWeight = FontWeight.Bold) },
|
||||||
Text(text = stringResource(R.string.blocking), fontWeight = FontWeight.Bold)
|
|
||||||
},
|
|
||||||
colors = TopAppBarDefaults.topAppBarColors(
|
colors = TopAppBarDefaults.topAppBarColors(
|
||||||
containerColor = MaterialTheme.colorScheme.primary,
|
containerColor = MaterialTheme.colorScheme.primary,
|
||||||
navigationIconContentColor = MaterialTheme.colorScheme.onPrimary,
|
navigationIconContentColor = MaterialTheme.colorScheme.onPrimary,
|
||||||
@ -156,7 +154,8 @@ fun BlockingContent(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.Start
|
horizontalArrangement = Arrangement.Start
|
||||||
) {
|
) {
|
||||||
Text(text = blockUnknownTitle,
|
Text(
|
||||||
|
text = blockUnknownTitle,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.clickable {
|
.clickable {
|
||||||
@ -187,7 +186,8 @@ fun BlockingContent(
|
|||||||
verticalAlignment = Alignment.CenterVertically,
|
verticalAlignment = Alignment.CenterVertically,
|
||||||
horizontalArrangement = Arrangement.Start
|
horizontalArrangement = Arrangement.Start
|
||||||
) {
|
) {
|
||||||
Text(text = blockHiddenTitle,
|
Text(
|
||||||
|
text = blockHiddenTitle,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.weight(1f)
|
.weight(1f)
|
||||||
.clickable {
|
.clickable {
|
||||||
@ -247,9 +247,7 @@ fun BlockingContent(
|
|||||||
verticalArrangement = Arrangement.spacedBy(4.dp),
|
verticalArrangement = Arrangement.spacedBy(4.dp),
|
||||||
) {
|
) {
|
||||||
items(rules) { rule ->
|
items(rules) { rule ->
|
||||||
Row(
|
Row(verticalAlignment = Alignment.CenterVertically) {
|
||||||
verticalAlignment = Alignment.CenterVertically,
|
|
||||||
) {
|
|
||||||
Text(
|
Text(
|
||||||
text = "\u2022",
|
text = "\u2022",
|
||||||
modifier = Modifier.padding(start = 8.dp, end = 8.dp),
|
modifier = Modifier.padding(start = 8.dp, end = 8.dp),
|
||||||
|
|||||||
Reference in New Issue
Block a user