Cleanup code.
This commit is contained in:
parent
a807141a91
commit
c7e8582778
1 changed files with 76 additions and 68 deletions
|
|
@ -7,6 +7,7 @@
|
||||||
|
|
||||||
package io.element.android.features.messages.impl.crypto.identity
|
package io.element.android.features.messages.impl.crypto.identity
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.Modifier
|
import androidx.compose.ui.Modifier
|
||||||
import androidx.compose.ui.res.stringResource
|
import androidx.compose.ui.res.stringResource
|
||||||
|
|
@ -35,79 +36,86 @@ fun IdentityChangeStateView(
|
||||||
val identityChangeViolation = state.roomMemberIdentityStateChanges.firstOrNull {
|
val identityChangeViolation = state.roomMemberIdentityStateChanges.firstOrNull {
|
||||||
it.identityState.isAViolation()
|
it.identityState.isAViolation()
|
||||||
}
|
}
|
||||||
if (identityChangeViolation != null) {
|
when (identityChangeViolation?.identityState) {
|
||||||
ComposerAlertMolecule(
|
IdentityState.PinViolation -> ViolationAlert(
|
||||||
|
identityChangeViolation = identityChangeViolation,
|
||||||
|
onLinkClick = onLinkClick,
|
||||||
|
textId = CommonStrings.crypto_identity_change_pin_violation_new,
|
||||||
|
isCritical = false,
|
||||||
|
submitTextId = CommonStrings.action_ok,
|
||||||
|
onSubmitClick = { state.eventSink(IdentityChangeEvent.PinIdentity(identityChangeViolation.identityRoomMember.userId)) },
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
avatar = identityChangeViolation.identityRoomMember.avatarData,
|
|
||||||
content = buildAnnotatedString {
|
|
||||||
val learnMoreStr = stringResource(CommonStrings.action_learn_more)
|
|
||||||
val displayName = identityChangeViolation.identityRoomMember.displayNameOrDefault
|
|
||||||
val userIdStr = stringResource(
|
|
||||||
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
|
|
||||||
identityChangeViolation.identityRoomMember.userId,
|
|
||||||
)
|
|
||||||
val fullText = if (identityChangeViolation.identityState == IdentityState.PinViolation) {
|
|
||||||
stringResource(
|
|
||||||
id = CommonStrings.crypto_identity_change_pin_violation_new,
|
|
||||||
displayName,
|
|
||||||
userIdStr,
|
|
||||||
learnMoreStr,
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
stringResource(
|
|
||||||
id = CommonStrings.crypto_identity_change_verification_violation_new,
|
|
||||||
displayName,
|
|
||||||
userIdStr,
|
|
||||||
learnMoreStr,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
append(fullText)
|
|
||||||
val userIdStartIndex = fullText.indexOf(userIdStr)
|
|
||||||
addStyle(
|
|
||||||
style = SpanStyle(
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
),
|
|
||||||
start = userIdStartIndex,
|
|
||||||
end = userIdStartIndex + userIdStr.length,
|
|
||||||
)
|
|
||||||
val learnMoreStartIndex = fullText.lastIndexOf(learnMoreStr)
|
|
||||||
addStyle(
|
|
||||||
style = SpanStyle(
|
|
||||||
textDecoration = TextDecoration.Underline,
|
|
||||||
fontWeight = FontWeight.Bold,
|
|
||||||
color = ElementTheme.colors.textPrimary
|
|
||||||
),
|
|
||||||
start = learnMoreStartIndex,
|
|
||||||
end = learnMoreStartIndex + learnMoreStr.length,
|
|
||||||
)
|
|
||||||
addLink(
|
|
||||||
url = LinkAnnotation.Url(
|
|
||||||
url = LearnMoreConfig.IDENTITY_CHANGE_URL,
|
|
||||||
linkInteractionListener = {
|
|
||||||
onLinkClick(LearnMoreConfig.IDENTITY_CHANGE_URL, true)
|
|
||||||
}
|
|
||||||
),
|
|
||||||
start = learnMoreStartIndex,
|
|
||||||
end = learnMoreStartIndex + learnMoreStr.length,
|
|
||||||
)
|
|
||||||
},
|
|
||||||
submitText = if (identityChangeViolation.identityState == IdentityState.VerificationViolation) {
|
|
||||||
stringResource(CommonStrings.crypto_identity_change_withdraw_verification_action)
|
|
||||||
} else {
|
|
||||||
stringResource(CommonStrings.action_ok)
|
|
||||||
},
|
|
||||||
onSubmitClick = {
|
|
||||||
if (identityChangeViolation.identityState == IdentityState.VerificationViolation) {
|
|
||||||
state.eventSink(IdentityChangeEvent.WithdrawVerification(identityChangeViolation.identityRoomMember.userId))
|
|
||||||
} else {
|
|
||||||
state.eventSink(IdentityChangeEvent.PinIdentity(identityChangeViolation.identityRoomMember.userId))
|
|
||||||
}
|
|
||||||
},
|
|
||||||
isCritical = identityChangeViolation.identityState == IdentityState.VerificationViolation,
|
|
||||||
)
|
)
|
||||||
|
IdentityState.VerificationViolation -> ViolationAlert(
|
||||||
|
identityChangeViolation = identityChangeViolation,
|
||||||
|
onLinkClick = onLinkClick,
|
||||||
|
textId = CommonStrings.crypto_identity_change_verification_violation_new,
|
||||||
|
isCritical = true,
|
||||||
|
submitTextId = CommonStrings.crypto_identity_change_withdraw_verification_action,
|
||||||
|
onSubmitClick = { state.eventSink(IdentityChangeEvent.WithdrawVerification(identityChangeViolation.identityRoomMember.userId)) },
|
||||||
|
modifier = modifier,
|
||||||
|
)
|
||||||
|
else -> Unit
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Composable
|
||||||
|
private fun ViolationAlert(
|
||||||
|
identityChangeViolation: RoomMemberIdentityStateChange,
|
||||||
|
onLinkClick: (String, Boolean) -> Unit,
|
||||||
|
@StringRes textId: Int,
|
||||||
|
isCritical: Boolean,
|
||||||
|
@StringRes submitTextId: Int,
|
||||||
|
onSubmitClick: () -> Unit,
|
||||||
|
modifier: Modifier = Modifier,
|
||||||
|
) {
|
||||||
|
ComposerAlertMolecule(
|
||||||
|
modifier = modifier,
|
||||||
|
avatar = identityChangeViolation.identityRoomMember.avatarData,
|
||||||
|
content = buildAnnotatedString {
|
||||||
|
val learnMoreStr = stringResource(CommonStrings.action_learn_more)
|
||||||
|
val displayName = identityChangeViolation.identityRoomMember.displayNameOrDefault
|
||||||
|
val userIdStr = stringResource(
|
||||||
|
CommonStrings.crypto_identity_change_pin_violation_new_user_id,
|
||||||
|
identityChangeViolation.identityRoomMember.userId,
|
||||||
|
)
|
||||||
|
val fullText = stringResource(textId, displayName, userIdStr, learnMoreStr)
|
||||||
|
append(fullText)
|
||||||
|
val userIdStartIndex = fullText.indexOf(userIdStr)
|
||||||
|
addStyle(
|
||||||
|
style = SpanStyle(
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
),
|
||||||
|
start = userIdStartIndex,
|
||||||
|
end = userIdStartIndex + userIdStr.length,
|
||||||
|
)
|
||||||
|
val learnMoreStartIndex = fullText.lastIndexOf(learnMoreStr)
|
||||||
|
addStyle(
|
||||||
|
style = SpanStyle(
|
||||||
|
textDecoration = TextDecoration.Underline,
|
||||||
|
fontWeight = FontWeight.Bold,
|
||||||
|
color = ElementTheme.colors.textPrimary
|
||||||
|
),
|
||||||
|
start = learnMoreStartIndex,
|
||||||
|
end = learnMoreStartIndex + learnMoreStr.length,
|
||||||
|
)
|
||||||
|
addLink(
|
||||||
|
url = LinkAnnotation.Url(
|
||||||
|
url = LearnMoreConfig.IDENTITY_CHANGE_URL,
|
||||||
|
linkInteractionListener = {
|
||||||
|
onLinkClick(LearnMoreConfig.IDENTITY_CHANGE_URL, true)
|
||||||
|
}
|
||||||
|
),
|
||||||
|
start = learnMoreStartIndex,
|
||||||
|
end = learnMoreStartIndex + learnMoreStr.length,
|
||||||
|
)
|
||||||
|
},
|
||||||
|
submitText = stringResource(submitTextId),
|
||||||
|
onSubmitClick = onSubmitClick,
|
||||||
|
isCritical = isCritical,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
@PreviewsDayNight
|
@PreviewsDayNight
|
||||||
@Composable
|
@Composable
|
||||||
internal fun IdentityChangeStateViewPreview(
|
internal fun IdentityChangeStateViewPreview(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue