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 @@ -39,6 +39,7 @@ class IdCardDataCreator {
pin1RetryCount: Int = 3,
pin2RetryCount: Int = 3,
pukRetryCount: Int = 3,
pin1CodeChanged: Boolean = true,
pin2CodeChanged: Boolean = true,
): IdCardData =
IdCardData(
Expand All @@ -49,6 +50,7 @@ class IdCardDataCreator {
pin1RetryCount = pin1RetryCount,
pin2RetryCount = pin2RetryCount,
pukRetryCount = pukRetryCount,
pin1CodeChanged = pin1CodeChanged,
pin2CodeChanged = pin2CodeChanged,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ class IdCardViewModelTest {
3,
3,
true,
true,
)

`when`(idCardService.data(anyOrNull())).thenReturn(idCardData)
Expand Down Expand Up @@ -280,6 +281,7 @@ class IdCardViewModelTest {
3,
3,
true,
true,
)

`when`(idCardService.data(anyOrNull())).thenReturn(idCardData)
Expand Down Expand Up @@ -342,6 +344,7 @@ class IdCardViewModelTest {
2,
3,
true,
true,
)

`when`(idCardService.data(anyOrNull())).thenReturn(idCardData)
Expand Down Expand Up @@ -409,6 +412,7 @@ class IdCardViewModelTest {
1,
3,
true,
true,
)

`when`(idCardService.data(anyOrNull())).thenReturn(idCardData)
Expand Down Expand Up @@ -476,6 +480,7 @@ class IdCardViewModelTest {
0,
3,
true,
true,
)

`when`(idCardService.data(anyOrNull())).thenReturn(idCardData)
Expand Down Expand Up @@ -541,6 +546,7 @@ class IdCardViewModelTest {
3,
0,
3,
true,
false,
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ fun DecryptScreen(
isValidToDecrypt = { isValid ->
isValidToDecrypt = isValid
},
onCourierCardDetected = {},
decryptAction = { action ->
decryptAction = {
isDecrypting = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,10 @@ fun SignatureInputScreen(
isValidToSign = { isValid ->
isValidToSign = isValid
},
onCourierCardDetected = {},
onCourierCardDialogDismissed = {
navController.navigateUp()
},
signAction = { action ->
signAction = {
isSigning = true
Expand Down Expand Up @@ -408,6 +412,9 @@ fun SignatureInputScreen(
isValidToSign = { isValid ->
isValidToSign = isValid
},
onCourierCardDialogDismissed = {
navController.navigateUp()
},
signAction = { action ->
signAction = action
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,10 @@ fun MyEidScreen(
val isPin2Blocked = idCardData?.pin2RetryCount == 0
val isPukBlocked = idCardData?.pukRetryCount == 0
val isPin2Activated = idCardData?.pin2CodeChanged == true
val isCourierCard = idCardData?.personalData != null && idCardData?.pin1CodeChanged == false

val alphaForPin1BlockedState = getAlphaForBlockedState(isPin1Blocked && isPukBlocked)
val alphaForPin2BlockedState = getAlphaForBlockedState(isPin2Blocked && isPukBlocked)
val alphaForPin1BlockedState = getAlphaForBlockedState((isPin1Blocked && isPukBlocked) || isCourierCard)
val alphaForPin2BlockedState = getAlphaForBlockedState((isPin2Blocked && isPukBlocked) || isCourierCard)
val alphaForPukBlockedState = getAlphaForBlockedState(isPukBlocked)

val selectedMyEidTabIndex = rememberSaveable { mutableIntStateOf(0) }
Expand Down Expand Up @@ -378,6 +379,7 @@ fun MyEidScreen(
),
isPinBlocked = isPin1Blocked,
isPukBlocked = isPukBlocked,
isNotActivated = isCourierCard,
forgotPinText =
if (isPin1Blocked) {
stringResource(
Expand Down Expand Up @@ -434,6 +436,12 @@ fun MyEidScreen(
style = MaterialTheme.typography.bodySmall,
)
}
if (isCourierCard) {
CourierCardWarningText(
modifier = modifier,
testTag = "myEidCourierCardPin1DescriptionText",
)
}
}
}
item {
Expand All @@ -459,6 +467,7 @@ fun MyEidScreen(
),
isPinBlocked = isPin2Blocked,
isPukBlocked = isPukBlocked,
isNotActivated = isCourierCard,
forgotPinText =
if (isPin2Blocked) {
stringResource(
Expand All @@ -484,7 +493,12 @@ fun MyEidScreen(
},
)

if (!isPin2Activated) {
if (isCourierCard) {
CourierCardWarningText(
modifier = modifier,
testTag = "myEidCourierCardPin2DescriptionText",
)
} else if (!isPin2Activated) {
Text(
modifier =
modifier
Expand Down Expand Up @@ -670,4 +684,36 @@ fun MyEidScreen(
)
}

@Composable
private fun CourierCardWarningText(
modifier: Modifier,
testTag: String,
) {
val message = stringResource(R.string.id_card_courier_warning_message)
val linkText = stringResource(R.string.id_card_courier_activate_button)
val linkUrl = stringResource(R.string.id_card_courier_activate_url)
val linkWord = stringResource(R.string.link)
HrefDynamicText(
modifier =
modifier
.fillMaxWidth()
.focusable(true)
.testTag(testTag)
.semantics {
contentDescription = "$message $linkText, $linkWord, $linkUrl"
},
text1 = message,
text2 = null,
linkText = linkText,
linkUrl = linkUrl,
newLineBeforeLink = true,
textStyle =
TextStyle(
color = MaterialTheme.colorScheme.error,
fontSize = MaterialTheme.typography.bodySmall.fontSize,
textAlign = TextAlign.Start,
),
)
}

fun getAlphaForBlockedState(isBlocked: Boolean) = if (!isBlocked) 1f else 0.7f
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fun MyEidPinAndCertificateView(
linkUrl: String = "",
isPinBlocked: Boolean = false,
isPukBlocked: Boolean = false,
isNotActivated: Boolean = false,
showForgotPin: Boolean = true,
forgotPinText: String = "",
onForgotPinClick: (() -> Unit)? = null,
Expand Down Expand Up @@ -130,6 +131,7 @@ fun MyEidPinAndCertificateView(
modifier =
modifier
.weight(1f)
.padding(vertical = XSPadding)
.focusable()
.semantics(mergeDescendants = true) {
this.contentDescription = "$title. $subtitle".lowercase()
Expand Down Expand Up @@ -179,7 +181,7 @@ fun MyEidPinAndCertificateView(
verticalAlignment = Alignment.CenterVertically,
) {
OutlinedButton(
enabled = !isPukBlocked,
enabled = !isPukBlocked && !isNotActivated,
onClick = onForgotPinClick,
modifier =
modifier
Expand Down Expand Up @@ -209,7 +211,7 @@ fun MyEidPinAndCertificateView(
}

Button(
enabled = !isPinBlocked,
enabled = !isPinBlocked && !isNotActivated,
onClick = onChangePinClick ?: {},
modifier =
modifier
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* Copyright 2017 - 2026 Riigi Infosüsteemi Amet
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/

@file:Suppress("PackageName", "FunctionName")

package ee.ria.DigiDoc.ui.component.shared.dialog

import androidx.compose.foundation.background
import androidx.compose.foundation.focusable
import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.wrapContentHeight
import androidx.compose.foundation.layout.wrapContentWidth
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material3.BasicAlertDialog
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Surface
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.remember
import androidx.compose.ui.ExperimentalComposeUiApi
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.focus.FocusRequester
import androidx.compose.ui.focus.focusRequester
import androidx.compose.ui.platform.testTag
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.semantics.semantics
import androidx.compose.ui.semantics.testTagsAsResourceId
import androidx.compose.ui.text.style.TextAlign
import ee.ria.DigiDoc.R
import ee.ria.DigiDoc.ui.component.shared.CancelAndOkButtonRow
import ee.ria.DigiDoc.ui.component.shared.InvisibleElement
import ee.ria.DigiDoc.ui.theme.Dimensions.SPadding
import ee.ria.DigiDoc.ui.theme.buttonRoundCornerShape
import kotlinx.coroutines.delay

@OptIn(ExperimentalMaterial3Api::class, ExperimentalComposeUiApi::class)
@Composable
fun CourierCardActivationDialog(
modifier: Modifier = Modifier,
onDismiss: () -> Unit,
) {
val focusRequester = remember { FocusRequester() }
Box(modifier = modifier.fillMaxSize()) {
BasicAlertDialog(
modifier =
Modifier
.clip(buttonRoundCornerShape)
.background(MaterialTheme.colorScheme.surface),
onDismissRequest = onDismiss,
) {
LaunchedEffect(Unit) {
delay(100)
focusRequester.requestFocus()
}
Surface(
modifier =
Modifier
.padding(SPadding)
.wrapContentHeight()
.wrapContentWidth()
.verticalScroll(rememberScrollState()),
) {
Column(
modifier =
Modifier
.semantics { testTagsAsResourceId = true }
.testTag("courierCardActivationDialogContainer"),
) {
Text(
modifier =
Modifier
.padding(SPadding)
.fillMaxWidth()
.focusRequester(focusRequester)
.focusable(),
text = stringResource(R.string.id_card_courier_must_activate_to_sign),
style = MaterialTheme.typography.bodyLarge,
color = MaterialTheme.colorScheme.onBackground,
textAlign = TextAlign.Start,
)
CancelAndOkButtonRow(
okButtonTestTag = "courierCardDialogOkButton",
cancelButtonTestTag = "courierCardDialogCancelButton",
cancelButtonClick = {},
okButtonClick = onDismiss,
cancelButtonTitle = R.string.cancel_button,
okButtonTitle = R.string.ok_button,
cancelButtonContentDescription = stringResource(R.string.cancel_button).lowercase(),
okButtonContentDescription = stringResource(R.string.ok_button).lowercase(),
showCancelButton = false,
)
}
}
}
InvisibleElement(modifier = Modifier)
}
}
Loading
Loading