Skip to content

Commit ca75112

Browse files
authored
Merge pull request #311 from open-eid/MOPPAND-1718
Decryption expired check and colored label in RecipientComponent UI.
2 parents 1aba2e6 + fd7685a commit ca75112

File tree

7 files changed

+43
-15
lines changed

7 files changed

+43
-15
lines changed

app/src/main/kotlin/ee/ria/DigiDoc/ui/component/crypto/ColoredRecipientStatusText.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,18 @@ import androidx.compose.ui.platform.testTag
3030
import ee.ria.DigiDoc.ui.component.shared.TagBadge
3131
import ee.ria.DigiDoc.ui.theme.Green_2_50
3232
import ee.ria.DigiDoc.ui.theme.Green_2_700
33+
import ee.ria.DigiDoc.ui.theme.Red50
34+
import ee.ria.DigiDoc.ui.theme.Red800
3335

3436
@OptIn(ExperimentalLayoutApi::class)
3537
@Composable
3638
fun ColoredRecipientStatusText(
3739
text: String,
3840
modifier: Modifier = Modifier,
41+
expired: Boolean = false,
3942
) {
40-
val tagBackgroundColor = Green_2_50
41-
val tagContentColor = Green_2_700
43+
val tagBackgroundColor = if (!expired) Green_2_50 else Red50
44+
val tagContentColor = if (!expired) Green_2_700 else Red800
4245

4346
FlowRow(
4447
modifier = modifier,

app/src/main/kotlin/ee/ria/DigiDoc/ui/component/crypto/EncryptNavigation.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ fun EncryptNavigation(
789789
leftActionButtonName = R.string.sign_button,
790790
rightActionButtonName = rightActionButtonName,
791791
leftActionButtonContentDescription = R.string.sign_button,
792-
rightActionButtonContentDescription = R.string.decrypt_button_accessibility,
792+
rightActionButtonContentDescription = rightActionButtonName,
793793
onLeftActionButtonClick = onSignActionClick,
794794
onRightActionButtonClick = {
795795
if (encryptViewModel.isDecryptButtonShown(cryptoContainer, isNestedContainer)) {

app/src/main/kotlin/ee/ria/DigiDoc/ui/component/crypto/RecipientComponent.kt

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ import ee.ria.DigiDoc.utilsLib.container.NameUtil.formatCompanyName
7272
import ee.ria.DigiDoc.utilsLib.container.NameUtil.formatName
7373
import ee.ria.DigiDoc.utilsLib.date.DateUtil.dateFormat
7474
import ee.ria.DigiDoc.utilsLib.validator.PersonalCodeValidator
75+
import java.util.Date
7576

7677
@OptIn(ExperimentalComposeUiApi::class)
7778
@Composable
@@ -83,7 +84,6 @@ fun RecipientComponent(
8384
onClick: (Addressee) -> Unit,
8485
isCDOC2Container: Boolean = false,
8586
) {
86-
val context = LocalContext.current
8787
val recipientText = stringResource(R.string.crypto_recipient_title)
8888
val buttonName = stringResource(id = R.string.button_name)
8989

@@ -114,6 +114,7 @@ fun RecipientComponent(
114114
formatCompanyName(recipient.identifier, recipient.serialNumber)
115115
}
116116
val certTypeText = getRecipientCertTypeText(LocalContext.current, recipient.certType)
117+
var expired = false
117118
var certValidTo =
118119
recipient.validTo
119120
?.let {
@@ -130,17 +131,22 @@ fun RecipientComponent(
130131
val decryptionValidToText =
131132
if (isCDOC2Container) {
132133
certValidTo = ""
133-
recipient.validTo
134-
?.let {
135-
dateFormat.format(
136-
it,
134+
135+
recipient.validTo?.let { validToDate ->
136+
val formattedDate = dateFormat.format(validToDate)
137+
if (validToDate.before(Date())) {
138+
expired = true
139+
stringResource(
140+
R.string.crypto_decryption_expired,
141+
formattedDate,
137142
)
138-
}?.let {
143+
} else {
139144
stringResource(
140145
R.string.crypto_decryption_valid_to,
141-
it,
146+
formattedDate,
142147
)
143-
} ?: ""
148+
}
149+
} ?: ""
144150
} else {
145151
""
146152
}
@@ -234,6 +240,7 @@ fun RecipientComponent(
234240
if (decryptionValidToText.isNotEmpty()) {
235241
ColoredRecipientStatusText(
236242
text = decryptionValidToText,
243+
expired = expired,
237244
modifier =
238245
modifier
239246
.padding(vertical = SBorder)

app/src/main/kotlin/ee/ria/DigiDoc/ui/component/shared/ContainerNameView.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ import androidx.compose.ui.ExperimentalComposeUiApi
5252
import androidx.compose.ui.Modifier
5353
import androidx.compose.ui.graphics.toArgb
5454
import androidx.compose.ui.graphics.vector.ImageVector
55-
import androidx.compose.ui.platform.LocalContext
5655
import androidx.compose.ui.platform.testTag
5756
import androidx.compose.ui.res.stringResource
5857
import androidx.compose.ui.res.vectorResource
@@ -87,9 +86,12 @@ fun ContainerNameView(
8786
onRightActionButtonClick: () -> Unit = {},
8887
onMoreOptionsActionButtonClick: () -> Unit = {},
8988
) {
90-
val context = LocalContext.current
9189
val leftActionButtonContentDescriptionText = stringResource(leftActionButtonContentDescription)
92-
val rightActionButtonContentDescriptionText = stringResource(rightActionButtonContentDescription)
90+
91+
var rightActionButtonContentDescriptionText = ""
92+
if (showRightActionButton) {
93+
rightActionButtonContentDescriptionText = stringResource(rightActionButtonContentDescription)
94+
}
9395

9496
val containerTitleText = stringResource(R.string.container_title)
9597

app/src/main/kotlin/ee/ria/DigiDoc/viewmodel/EncryptViewModel.kt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ import ee.ria.DigiDoc.viewmodel.shared.SharedContainerViewModel
4545
import kotlinx.coroutines.Dispatchers.Main
4646
import kotlinx.coroutines.withContext
4747
import java.io.File
48+
import java.util.Date
4849
import javax.inject.Inject
4950

5051
@HiltViewModel
@@ -99,7 +100,20 @@ class EncryptViewModel
99100
fun isDecryptButtonShown(
100101
cryptoContainer: CryptoContainer?,
101102
isNestedContainer: Boolean,
102-
): Boolean = isEncryptedContainer(cryptoContainer) && !isNestedContainer
103+
): Boolean {
104+
val base = isEncryptedContainer(cryptoContainer) && !isNestedContainer
105+
if (!base) return false
106+
107+
val now = Date()
108+
val allExpired =
109+
cryptoContainer
110+
?.recipients
111+
?.all { recipient ->
112+
recipient.validTo?.before(now) == true
113+
} ?: false
114+
115+
return !allExpired
116+
}
103117

104118
fun isEncryptButtonShown(
105119
cryptoContainer: CryptoContainer?,

app/src/main/res/values-et/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<string name="crypto_container_added_recipients_title">Lisatud adressaadid</string>
164164
<string name="crypto_recipient_title">Adressaat</string>
165165
<string name="crypto_decryption_valid_to">Dekrüpteerimine võimalik kuni %1$s</string>
166+
<string name="crypto_decryption_expired">Dekrüpteerimise võimalus aegus %1$s</string>
166167
<string name="crypto_cert_valid_to">(kehtiv kuni %1$s)</string>
167168
<string name="crypto_documents_title">Ümbriku failid</string>
168169
<string name="crypto_encrypted_documents_title">Krüpteeritud failid</string>

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,7 @@
163163
<string name="crypto_container_added_recipients_title">Added recipients</string>
164164
<string name="crypto_recipient_title">Recipient</string>
165165
<string name="crypto_decryption_valid_to">Decryption until %1$s</string>
166+
<string name="crypto_decryption_expired">Decryption expired %1$s</string>
166167
<string name="crypto_cert_valid_to">(valid to %1$s)</string>
167168
<string name="crypto_documents_title">Container files</string>
168169
<string name="crypto_encrypted_documents_title">Encrypted files</string>

0 commit comments

Comments
 (0)