Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ import ee.ria.DigiDoc.cryptolib.Addressee
import ee.ria.DigiDoc.ui.component.crypto.bottombar.EncryptBottomBar
import ee.ria.DigiDoc.ui.component.crypto.bottomsheet.RecipientBottomSheet
import ee.ria.DigiDoc.ui.component.menu.SettingsMenuBottomSheet
import ee.ria.DigiDoc.ui.component.shared.ContentLoadingScreen
import ee.ria.DigiDoc.ui.component.shared.InvisibleElement
import ee.ria.DigiDoc.ui.component.shared.LoadingScreen
import ee.ria.DigiDoc.ui.component.shared.MessageDialog
import ee.ria.DigiDoc.ui.component.shared.PreventResize
import ee.ria.DigiDoc.ui.component.shared.Recipient
Expand Down Expand Up @@ -128,7 +128,7 @@ fun EncryptRecipientScreen(

val cryptoContainer by sharedContainerViewModel.cryptoContainer.asFlow().collectAsState(null)

val showLoading = remember { mutableStateOf(false) }
val isEncrypting by encryptRecipientViewModel.isEncrypting.collectAsState()
val isSettingsMenuBottomSheetVisible = rememberSaveable { mutableStateOf(false) }

val recipientAddedSuccess = remember { mutableStateOf(false) }
Expand Down Expand Up @@ -227,6 +227,15 @@ fun EncryptRecipientScreen(
}
}

LaunchedEffect(encryptRecipientViewModel.encryptedContainer) {
encryptRecipientViewModel.encryptedContainer.asFlow().collect { encrypted ->
encrypted?.let {
sharedContainerViewModel.setCryptoContainer(it, true)
encryptRecipientViewModel.resetEncryptedContainer()
}
}
}

LaunchedEffect(encryptRecipientViewModel.errorState) {
encryptRecipientViewModel.errorState.asFlow().collect { error ->
error?.let {
Expand Down Expand Up @@ -259,12 +268,17 @@ fun EncryptRecipientScreen(
}.testTag("encryptRecipientsScreen"),
snackbarHost = { StatusSnackbarHost() },
topBar = {
if (!expanded) {
if (!expanded || isEncrypting) {
TopBar(
modifier = modifier,
sharedMenuViewModel = sharedMenuViewModel,
title = null,
showRightSideIcons = !isEncrypting,
onLeftButtonClick = {
if (isEncrypting) {
encryptRecipientViewModel.cancelEncryption()
encryptionButtonEnabled.value = true
}
navController.navigateUp()
},
onRightSecondaryButtonClick = {
Expand All @@ -277,15 +291,12 @@ fun EncryptRecipientScreen(
if (cryptoContainer != null) {
EncryptBottomBar(
modifier = modifier,
isEncryptButtonEnabled = encryptionButtonEnabled.value,
isEncryptButtonEnabled = encryptionButtonEnabled.value && !isEncrypting,
onEncryptClick = {
if (encryptionButtonEnabled.value) {
encryptionButtonEnabled.value = false
showLoading.value = true
scope.launch(Main) {
encryptRecipientViewModel.encryptContainer(sharedContainerViewModel)
showLoading.value = false
}
expanded = false
encryptRecipientViewModel.encrypt(cryptoContainer)
}
},
)
Expand Down Expand Up @@ -588,8 +599,8 @@ fun EncryptRecipientScreen(
)
}

if (showLoading.value == true) {
LoadingScreen(modifier = modifier)
if (isEncrypting) {
ContentLoadingScreen(modifier = modifier, contentPadding = paddingValues)
}

RecipientBottomSheet(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ import ee.ria.DigiDoc.ui.theme.extendedColorScheme
@Composable
fun ColoredRecipientStatusText(
text: String,
status: RecipientDecryptionStatus,
modifier: Modifier = Modifier,
expired: Boolean = false,
) {
val tagBackgroundColor =
if (!expired) {
MaterialTheme.extendedColorScheme.successContainer
} else {
MaterialTheme.colorScheme.errorContainer
when (status) {
RecipientDecryptionStatus.NOT_ENCRYPTED -> MaterialTheme.colorScheme.surfaceVariant
RecipientDecryptionStatus.EXPIRED -> MaterialTheme.colorScheme.errorContainer
RecipientDecryptionStatus.VALID -> MaterialTheme.extendedColorScheme.successContainer
}

val tagContentColor =
if (!expired) {
MaterialTheme.extendedColorScheme.onSuccessContainer
} else {
MaterialTheme.colorScheme.onErrorContainer
when (status) {
RecipientDecryptionStatus.NOT_ENCRYPTED -> MaterialTheme.colorScheme.onSurface
RecipientDecryptionStatus.EXPIRED -> MaterialTheme.colorScheme.onErrorContainer
RecipientDecryptionStatus.VALID -> MaterialTheme.extendedColorScheme.onSuccessContainer
}

FlowRow(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,10 @@ import ee.ria.DigiDoc.ui.component.crypto.bottomsheet.RecipientBottomSheet
import ee.ria.DigiDoc.ui.component.menu.SettingsMenuBottomSheet
import ee.ria.DigiDoc.ui.component.settings.EditValueDialog
import ee.ria.DigiDoc.ui.component.shared.ContainerNameView
import ee.ria.DigiDoc.ui.component.shared.ContentLoadingScreen
import ee.ria.DigiDoc.ui.component.shared.CryptoDataFileItem
import ee.ria.DigiDoc.ui.component.shared.CryptoDataFilesLocked
import ee.ria.DigiDoc.ui.component.shared.InvisibleElement
import ee.ria.DigiDoc.ui.component.shared.LoadingScreen
import ee.ria.DigiDoc.ui.component.shared.MessageDialog
import ee.ria.DigiDoc.ui.component.shared.StatusSnackbarHost
import ee.ria.DigiDoc.ui.component.shared.TabView
Expand Down Expand Up @@ -163,6 +163,13 @@ fun EncryptNavigation(

val isNestedContainer = sharedContainerViewModel.isNestedContainer(cryptoContainer)

val isUnencryptedCryptoContainer =
with(encryptViewModel) {
!isEncryptedContainer(cryptoContainer) &&
!isDecryptedContainer(cryptoContainer) &&
!isNestedContainer
}

val containerEncryptedSuccess = remember { mutableStateOf(false) }
val containerEncryptedSuccessText = stringResource(id = R.string.crypto_create_success)
val containerDecryptedSuccess = remember { mutableStateOf(false) }
Expand All @@ -171,6 +178,7 @@ fun EncryptNavigation(
val emptyFileInContainerText = stringResource(id = R.string.crypto_empty_file_message)

val showLoadingScreen = remember { mutableStateOf(false) }
val isEncrypting by encryptRecipientViewModel.isEncrypting.collectAsState()

val openRemoveFileDialog = rememberSaveable { mutableStateOf(false) }
val fileRemoved = stringResource(id = R.string.file_removed)
Expand Down Expand Up @@ -376,11 +384,7 @@ fun EncryptNavigation(
val onEncryptClick = {
if (encryptionButtonEnabled.value) {
encryptionButtonEnabled.value = false
showLoadingScreen.value = true
scope.launch(Main) {
encryptRecipientViewModel.encryptContainer(sharedContainerViewModel)
showLoadingScreen.value = false
}
encryptRecipientViewModel.encrypt(cryptoContainer)
}
}

Expand Down Expand Up @@ -411,8 +415,11 @@ fun EncryptNavigation(
fileToSave.value = null
}

BackHandler {
if (!isNestedContainer && encryptViewModel.isEncryptedContainer(cryptoContainer)) {
val handleClose = {
if (isEncrypting) {
encryptRecipientViewModel.cancelEncryption()
encryptionButtonEnabled.value = true
} else if (!isNestedContainer && encryptViewModel.isEncryptedContainer(cryptoContainer)) {
showContainerCloseConfirmationDialog.value = true
} else {
handleBackButtonClick(
Expand All @@ -423,6 +430,10 @@ fun EncryptNavigation(
}
}

BackHandler {
handleClose()
}

DisposableEffect(shouldResetContainer) {
onDispose {
if (shouldResetContainer == true) {
Expand Down Expand Up @@ -458,6 +469,15 @@ fun EncryptNavigation(
}
}

LaunchedEffect(encryptRecipientViewModel.encryptedContainer) {
encryptRecipientViewModel.encryptedContainer.asFlow().collect { encrypted ->
encrypted?.let {
sharedContainerViewModel.setCryptoContainer(it, true)
encryptRecipientViewModel.resetEncryptedContainer()
}
}
}

LaunchedEffect(encryptRecipientViewModel.errorState) {
encryptRecipientViewModel.errorState.asFlow().collect { error ->
error?.let {
Expand Down Expand Up @@ -567,21 +587,18 @@ fun EncryptNavigation(
?.let { R.string.signing_container_documents_title },
leftIcon =
when {
isEncrypting -> R.drawable.ic_m3_arrow_back_48dp_wght400
isNestedContainer -> R.drawable.ic_m3_arrow_back_48dp_wght400
else -> R.drawable.ic_m3_close_48dp_wght400
},
leftIconContentDescription = R.string.crypto_close_container_title,
onLeftButtonClick = {
if (!isNestedContainer && encryptViewModel.isEncryptedContainer(cryptoContainer)) {
showContainerCloseConfirmationDialog.value = true
leftIconContentDescription =
if (isEncrypting) {
R.string.cancel_button
} else {
handleBackButtonClick(
navController,
encryptViewModel,
sharedContainerViewModel,
)
}
},
R.string.crypto_close_container_title
},
showRightSideIcons = !isEncrypting,
onLeftButtonClick = handleClose,
onRightSecondaryButtonClick = {
isSettingsMenuBottomSheetVisible.value = true
},
Expand Down Expand Up @@ -621,7 +638,7 @@ fun EncryptNavigation(
),
isShareButtonShown = encryptViewModel.isShareButtonShown(cryptoContainer),
onEncryptClick = onEncryptClick,
encryptionButtonEnabled = encryptionButtonEnabled.value,
encryptionButtonEnabled = encryptionButtonEnabled.value && !isEncrypting,
)
}
},
Expand Down Expand Up @@ -678,15 +695,7 @@ fun EncryptNavigation(
text = removeExtensionFromContainerFilename(cryptoContainerName),
)
cryptoContainer?.let {
val isInitialCryptoContainer =
with(encryptViewModel) {
isContainerWithoutRecipients(cryptoContainer) &&
!isEncryptedContainer(cryptoContainer) &&
!isDecryptedContainer(cryptoContainer) &&
!isNestedContainer
}

if (isInitialCryptoContainer) {
if (isUnencryptedCryptoContainer) {
Text(
modifier =
modifier
Expand Down Expand Up @@ -839,6 +848,8 @@ fun EncryptNavigation(
recipientsLoading,
onRecipientItemClick,
!encryptViewModel.isCDOC1Container(cryptoContainer),
encryptViewModel.isEncryptedContainer(cryptoContainer) ||
encryptViewModel.isDecryptedContainer(cryptoContainer),
)
},
),
Expand Down Expand Up @@ -1047,10 +1058,7 @@ fun EncryptNavigation(
EncryptContainerBottomSheet(
modifier = modifier,
showSheet = showContainerBottomSheet,
isEditContainerButtonShown =
!isNestedContainer &&
!encryptViewModel.isEncryptedContainer(cryptoContainer) &&
!encryptViewModel.isDecryptedContainer(cryptoContainer),
isEditContainerButtonShown = isUnencryptedCryptoContainer,
openEditContainerNameDialog = openEditContainerNameDialog,
isSaveButtonShown = (
encryptViewModel.isEncryptedContainer(cryptoContainer) ||
Expand All @@ -1077,8 +1085,8 @@ fun EncryptNavigation(
onRecipientRemove = { actionRecipient = it },
)

if (showLoadingScreen.value) {
LoadingScreen(modifier = modifier)
if (showLoadingScreen.value || isEncrypting) {
ContentLoadingScreen(modifier = modifier)
}

if (showContainerCloseConfirmationDialog.value) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ fun RecipientComponent(
recipientsLoadingContentDescription: String,
onClick: (Addressee) -> Unit,
isCDOC2Container: Boolean = false,
isEncryptedOrDecrypted: Boolean = false,
) {
val recipientText = stringResource(R.string.crypto_recipient_title)
val buttonName = stringResource(id = R.string.button_name)
Expand Down Expand Up @@ -114,43 +115,34 @@ fun RecipientComponent(
formatCompanyName(recipient.identifier, recipient.serialNumber)
}
val certTypeText = getRecipientCertTypeText(LocalContext.current, recipient.certType)
var expired = false
var certValidTo =
recipient.validTo
?.let {
dateFormat.format(
it,
)
}?.let {
stringResource(
R.string.crypto_cert_valid_to,
it,
)
} ?: ""
val formattedValidTo = recipient.validTo?.let { dateFormat.format(it) }

val decryptionValidToText =
if (isCDOC2Container) {
certValidTo = ""

recipient.validTo?.let { validToDate ->
val formattedDate = dateFormat.format(validToDate)
if (validToDate.before(Date())) {
expired = true
stringResource(
R.string.crypto_decryption_expired,
formattedDate,
)
} else {
stringResource(
R.string.crypto_decryption_valid_to,
formattedDate,
)
}
} ?: ""
val certValidTo =
if (!isCDOC2Container && formattedValidTo != null) {
stringResource(R.string.crypto_cert_valid_to, formattedValidTo)
} else {
""
}

val decryptionStatus =
when {
!isCDOC2Container || formattedValidTo == null -> null
!isEncryptedOrDecrypted -> RecipientDecryptionStatus.NOT_ENCRYPTED
recipient.validTo?.before(Date()) == true -> RecipientDecryptionStatus.EXPIRED
else -> RecipientDecryptionStatus.VALID
}

val decryptionValidToText =
when (decryptionStatus) {
RecipientDecryptionStatus.NOT_ENCRYPTED ->
stringResource(R.string.crypto_recipient_expires_on, formattedValidTo.orEmpty())
RecipientDecryptionStatus.EXPIRED ->
stringResource(R.string.crypto_decryption_expired, formattedValidTo.orEmpty())
RecipientDecryptionStatus.VALID ->
stringResource(R.string.crypto_decryption_valid_to, formattedValidTo.orEmpty())
null -> ""
}

Card(
modifier =
modifier
Expand Down Expand Up @@ -237,10 +229,10 @@ fun RecipientComponent(
color = MaterialTheme.colorScheme.onSurfaceVariant,
style = MaterialTheme.typography.bodyMedium,
)
if (decryptionValidToText.isNotEmpty()) {
if (decryptionStatus != null) {
ColoredRecipientStatusText(
text = decryptionValidToText,
expired = expired,
status = decryptionStatus,
modifier =
modifier
.padding(vertical = SBorder)
Expand Down
Loading
Loading