operator enabled validation

This commit is contained in:
spaced4ndy
2024-11-21 13:28:58 +04:00
parent e842fbf074
commit 8ef8cf0776
3 changed files with 38 additions and 12 deletions
@@ -1,6 +1,7 @@
package chat.simplex.common.views.usersettings.networkAndServers
import SectionBottomSpacer
import SectionCustomFooter
import SectionDividerSpaced
import SectionItemView
import SectionItemWithValue
@@ -235,6 +236,12 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) {
) {
Text(stringResource(MR.strings.smp_servers_save), color = if (!saveDisabled) MaterialTheme.colors.onBackground else MaterialTheme.colors.secondary)
}
val serversErr = globalServersError(serverErrors.value)
if (serversErr != null) {
SectionCustomFooter {
ServersErrorFooter(serversErr)
}
}
SectionDividerSpaced()
@@ -679,8 +686,11 @@ private fun ConditionsButton(conditionsAction: UsageConditionsAction) {
}
@Composable
fun ServerErrorsView(errStr: String) {
Row {
fun ServersErrorFooter(errStr: String) {
Row(
Modifier.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(
painterResource(MR.images.ic_error),
contentDescription = stringResource(MR.strings.server_error),
@@ -690,7 +700,12 @@ fun ServerErrorsView(errStr: String) {
.offset(x = 2.sp.toDp())
)
TextIconSpaced()
Text(errStr, color = MaterialTheme.colors.secondary)
Text(
errStr,
color = MaterialTheme.colors.secondary,
lineHeight = 18.sp,
fontSize = 14.sp
)
}
}
@@ -150,12 +150,19 @@ fun OperatorViewLayout(
TextIconSpaced()
Text(operator.tradeName, color = MaterialTheme.colors.onBackground)
}
UseOperatorToggle(currUserServers = currUserServers, userServers = userServers, serverErrors = serverErrors, operatorIndex = operatorIndex, rhId = rhId)
UseOperatorToggle(
scope = scope,
currUserServers = currUserServers,
userServers = userServers,
serverErrors = serverErrors,
operatorIndex = operatorIndex,
rhId = rhId
)
}
val serversErr = globalServersError(serverErrors.value)
if (serversErr != null) {
SectionCustomFooter {
ServerErrorsView(serversErr)
ServersErrorFooter(serversErr)
}
} else {
val footerText = when (val c = operator.conditionsAcceptance) {
@@ -226,7 +233,7 @@ fun OperatorViewLayout(
val smpErr = globalSMPServersError(serverErrors.value)
if (smpErr != null) {
SectionCustomFooter {
ServerErrorsView(smpErr)
ServersErrorFooter(smpErr)
}
}
}
@@ -249,7 +256,7 @@ fun OperatorViewLayout(
val smpErr = globalSMPServersError(serverErrors.value)
if (smpErr != null) {
SectionCustomFooter {
ServerErrorsView(smpErr)
ServersErrorFooter(smpErr)
}
} else {
SectionTextFooter(
@@ -312,7 +319,7 @@ fun OperatorViewLayout(
val xftpErr = globalXFTPServersError(serverErrors.value)
if (xftpErr != null) {
SectionCustomFooter {
ServerErrorsView(xftpErr)
ServersErrorFooter(xftpErr)
}
}
}
@@ -335,7 +342,7 @@ fun OperatorViewLayout(
val xftpErr = globalXFTPServersError(serverErrors.value)
if (xftpErr != null) {
SectionCustomFooter {
ServerErrorsView(xftpErr)
ServersErrorFooter(xftpErr)
}
} else {
SectionTextFooter(
@@ -419,6 +426,7 @@ private fun OperatorInfoView(serverOperator: ServerOperator) {
@Composable
private fun UseOperatorToggle(
scope: CoroutineScope,
currUserServers: MutableState<List<UserOperatorServers>>,
userServers: MutableState<List<UserOperatorServers>>,
serverErrors: MutableState<List<UserServersError>>,
@@ -440,6 +448,7 @@ private fun UseOperatorToggle(
when (val conditionsAcceptance = operator?.conditionsAcceptance) {
is ConditionsAcceptance.Accepted -> {
changeOperatorEnabled(userServers, operatorIndex, true)
scope.launch { validateServers(rhId, userServers, serverErrors) }
}
is ConditionsAcceptance.Required -> {
@@ -456,6 +465,7 @@ private fun UseOperatorToggle(
}
} else {
changeOperatorEnabled(userServers, operatorIndex, true)
scope.launch { validateServers(rhId, userServers, serverErrors) }
}
}
@@ -463,6 +473,7 @@ private fun UseOperatorToggle(
}
} else {
changeOperatorEnabled(userServers, operatorIndex, false)
scope.launch { validateServers(rhId, userServers, serverErrors) }
}
},
)
@@ -90,7 +90,7 @@ fun YourServersViewLayout(
val smpErr = globalSMPServersError(serverErrors.value)
if (smpErr != null) {
SectionCustomFooter {
ServerErrorsView(smpErr)
ServersErrorFooter(smpErr)
}
} else {
SectionTextFooter(
@@ -124,7 +124,7 @@ fun YourServersViewLayout(
val xftpErr = globalXFTPServersError(serverErrors.value)
if (xftpErr != null) {
SectionCustomFooter {
ServerErrorsView(xftpErr)
ServersErrorFooter(xftpErr)
}
} else {
SectionTextFooter(
@@ -161,7 +161,7 @@ fun YourServersViewLayout(
val serversErr = globalServersError(serverErrors.value)
if (serversErr != null) {
SectionCustomFooter {
ServerErrorsView(serversErr)
ServersErrorFooter(serversErr)
}
}
SectionDividerSpaced(maxTopPadding = false, maxBottomPadding = false)