mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-07-11 18:28:52 +00:00
validation footers
This commit is contained in:
+6
-15
@@ -3873,12 +3873,11 @@ sealed class UserServersError {
|
||||
@Serializable @SerialName("duplicateServer") data class DuplicateServer(val protocol: ServerProtocol, val duplicateServer: String, val duplicateHost: String): UserServersError()
|
||||
|
||||
val globalError: String?
|
||||
get() = when (this) {
|
||||
is NoServers -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError })
|
||||
is StorageMissing -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError })
|
||||
is ProxyMissing -> protocol.toGlobalError({ this.globalSMPError }, { this.globalXFTPError })
|
||||
else -> null
|
||||
get() = when (this.protocol_) {
|
||||
ServerProtocol.SMP -> globalSMPError
|
||||
ServerProtocol.XFTP -> globalXFTPError
|
||||
}
|
||||
|
||||
private val protocol_: ServerProtocol
|
||||
get() = when (this) {
|
||||
is NoServers -> this.protocol
|
||||
@@ -3886,6 +3885,7 @@ sealed class UserServersError {
|
||||
is ProxyMissing -> this.protocol
|
||||
is DuplicateServer -> this.protocol
|
||||
}
|
||||
|
||||
val globalSMPError: String?
|
||||
get() = if (this.protocol_ == ServerProtocol.SMP) {
|
||||
when (this) {
|
||||
@@ -3903,6 +3903,7 @@ sealed class UserServersError {
|
||||
} else {
|
||||
null
|
||||
}
|
||||
|
||||
val globalXFTPError: String?
|
||||
get() = if (this.protocol_ == ServerProtocol.XFTP) {
|
||||
when (this) {
|
||||
@@ -3924,16 +3925,6 @@ sealed class UserServersError {
|
||||
private fun userStr(user: UserRef): String {
|
||||
return String.format(generalGetString(MR.strings.for_chat_profile), user.localDisplayName)
|
||||
}
|
||||
|
||||
private fun ServerProtocol.toGlobalError(
|
||||
smpHandler: () -> String?,
|
||||
xftpHandler: () -> String?
|
||||
): String? {
|
||||
return when (this) {
|
||||
ServerProtocol.SMP -> smpHandler()
|
||||
ServerProtocol.XFTP -> xftpHandler()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Serializable
|
||||
|
||||
+2
-2
@@ -52,7 +52,7 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) {
|
||||
val proxyPort = remember { derivedStateOf { appPrefs.networkProxy.state.value.port } }
|
||||
ModalView(
|
||||
close = {
|
||||
if (currUserServers.value == userServers.value) {
|
||||
if (!serversCanBeSaved(currUserServers.value, userServers.value, serverErrors.value)) {
|
||||
close()
|
||||
} else {
|
||||
showUnsavedChangesAlert(
|
||||
@@ -227,7 +227,7 @@ fun ModalData.NetworkAndServersView(close: () -> Unit) {
|
||||
}
|
||||
}
|
||||
|
||||
val saveDisabled = userServers.value == currUserServers.value
|
||||
val saveDisabled = !serversCanBeSaved(currUserServers.value, userServers.value, serverErrors.value)
|
||||
|
||||
SectionItemView(
|
||||
{ scope.launch { saveServers(rhId = currentRemoteHost?.remoteHostId, currUserServers, userServers) } },
|
||||
|
||||
+29
-40
@@ -152,16 +152,23 @@ fun OperatorViewLayout(
|
||||
}
|
||||
UseOperatorToggle(currUserServers = currUserServers, userServers = userServers, serverErrors = serverErrors, operatorIndex = operatorIndex, rhId = rhId)
|
||||
}
|
||||
val footerText = when (val c = operator.conditionsAcceptance) {
|
||||
is ConditionsAcceptance.Accepted -> if (c.acceptedAt != null) {
|
||||
String.format(generalGetString(MR.strings.operator_conditions_accepted_on), localTimestamp(c.acceptedAt))
|
||||
} else null
|
||||
is ConditionsAcceptance.Required -> if (operator.enabled && c.deadline != null) {
|
||||
String.format(generalGetString(MR.strings.operator_conditions_accepted_after), localTimestamp(c.deadline))
|
||||
} else null
|
||||
}
|
||||
if (footerText != null) {
|
||||
SectionTextFooter(footerText)
|
||||
val serversErr = globalServersError(serverErrors.value)
|
||||
if (serversErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(serversErr)
|
||||
}
|
||||
} else {
|
||||
val footerText = when (val c = operator.conditionsAcceptance) {
|
||||
is ConditionsAcceptance.Accepted -> if (c.acceptedAt != null) {
|
||||
String.format(generalGetString(MR.strings.operator_conditions_accepted_on), localTimestamp(c.acceptedAt))
|
||||
} else null
|
||||
is ConditionsAcceptance.Required -> if (operator.enabled && c.deadline != null) {
|
||||
String.format(generalGetString(MR.strings.operator_conditions_accepted_after), localTimestamp(c.deadline))
|
||||
} else null
|
||||
}
|
||||
if (footerText != null) {
|
||||
SectionTextFooter(footerText)
|
||||
}
|
||||
}
|
||||
|
||||
if (operator.enabled) {
|
||||
@@ -216,10 +223,10 @@ fun OperatorViewLayout(
|
||||
}
|
||||
|
||||
}
|
||||
val smpErrors = globalSMPServersError(serverErrors.value)
|
||||
if (smpErrors != null) {
|
||||
val smpErr = globalSMPServersError(serverErrors.value)
|
||||
if (smpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(smpErrors)
|
||||
ServerErrorsView(smpErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -239,10 +246,10 @@ fun OperatorViewLayout(
|
||||
}
|
||||
}
|
||||
}
|
||||
val smpErrors = globalSMPServersError(serverErrors.value)
|
||||
if (smpErrors != null) {
|
||||
val smpErr = globalSMPServersError(serverErrors.value)
|
||||
if (smpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(smpErrors)
|
||||
ServerErrorsView(smpErr)
|
||||
}
|
||||
} else {
|
||||
SectionTextFooter(
|
||||
@@ -302,10 +309,10 @@ fun OperatorViewLayout(
|
||||
)
|
||||
}
|
||||
}
|
||||
val xftpErrors = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErrors != null) {
|
||||
val xftpErr = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(xftpErrors)
|
||||
ServerErrorsView(xftpErr)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -325,10 +332,10 @@ fun OperatorViewLayout(
|
||||
}
|
||||
}
|
||||
}
|
||||
val xftpErrors = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErrors != null) {
|
||||
val xftpErr = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(xftpErrors)
|
||||
ServerErrorsView(xftpErr)
|
||||
}
|
||||
} else {
|
||||
SectionTextFooter(
|
||||
@@ -359,24 +366,6 @@ fun OperatorViewLayout(
|
||||
}
|
||||
}
|
||||
}
|
||||
val xftpErrors = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErrors != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(xftpErrors)
|
||||
}
|
||||
} else {
|
||||
SectionTextFooter(
|
||||
remember(currentUser?.displayName) {
|
||||
buildAnnotatedString {
|
||||
append(generalGetString(MR.strings.xftp_servers_per_user) + " ")
|
||||
withStyle(SpanStyle(fontWeight = FontWeight.Bold)) {
|
||||
append(currentUser?.displayName ?: "")
|
||||
}
|
||||
append(".")
|
||||
}
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
SectionDividerSpaced()
|
||||
|
||||
+12
-6
@@ -87,10 +87,10 @@ fun YourServersViewLayout(
|
||||
}
|
||||
}
|
||||
}
|
||||
val smpErrors = globalSMPServersError(serverErrors.value)
|
||||
if (smpErrors != null) {
|
||||
val smpErr = globalSMPServersError(serverErrors.value)
|
||||
if (smpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(smpErrors)
|
||||
ServerErrorsView(smpErr)
|
||||
}
|
||||
} else {
|
||||
SectionTextFooter(
|
||||
@@ -121,10 +121,10 @@ fun YourServersViewLayout(
|
||||
}
|
||||
}
|
||||
}
|
||||
val xftpErrors = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErrors != null) {
|
||||
val xftpErr = globalXFTPServersError(serverErrors.value)
|
||||
if (xftpErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(xftpErrors)
|
||||
ServerErrorsView(xftpErr)
|
||||
}
|
||||
} else {
|
||||
SectionTextFooter(
|
||||
@@ -158,6 +158,12 @@ fun YourServersViewLayout(
|
||||
iconColor = if (testing.value) MaterialTheme.colors.secondary else MaterialTheme.colors.primary
|
||||
)
|
||||
}
|
||||
val serversErr = globalServersError(serverErrors.value)
|
||||
if (serversErr != null) {
|
||||
SectionCustomFooter {
|
||||
ServerErrorsView(serversErr)
|
||||
}
|
||||
}
|
||||
SectionDividerSpaced(maxTopPadding = false, maxBottomPadding = false)
|
||||
|
||||
SectionView {
|
||||
|
||||
Reference in New Issue
Block a user