@@ -85,6 +85,7 @@ import ee.ria.DigiDoc.ui.component.shared.MessageDialog
8585import ee.ria.DigiDoc.ui.component.shared.TabView
8686import ee.ria.DigiDoc.ui.component.shared.TopBar
8787import ee.ria.DigiDoc.ui.component.shared.dialog.SivaConfirmationDialog
88+ import ee.ria.DigiDoc.ui.component.shared.handler.containerFileOpeningHandler
8889import ee.ria.DigiDoc.ui.theme.Dimensions.SPadding
8990import ee.ria.DigiDoc.ui.theme.Dimensions.XLPadding
9091import ee.ria.DigiDoc.ui.theme.Dimensions.XSPadding
@@ -250,7 +251,99 @@ fun EncryptNavigation(
250251 val showDataFileBottomSheet = remember { mutableStateOf(false ) }
251252 val showRecipientBottomSheet = remember { mutableStateOf(false ) }
252253
254+ val showSivaDialog = remember { mutableStateOf(false ) }
255+ val nestedFile = rememberSaveable { mutableStateOf<File ?>(null ) }
256+
257+ val openNestedContainer: (nestedContainer: File , isSivaConfirmed: Boolean ) -> Unit =
258+ { nestedContainer, isSivaConfirmed ->
259+ scope.launch(IO ) {
260+ try {
261+ val isSigningContainer = nestedContainer.isContainer(context)
262+
263+ if (isSigningContainer) {
264+ signingViewModel.openNestedContainer(
265+ context,
266+ nestedContainer,
267+ sharedContainerViewModel,
268+ isSivaConfirmed,
269+ )
270+
271+ withContext(Main ) {
272+ sharedContainerViewModel.setIsSivaConfirmed(isSivaConfirmed)
273+ navController.navigate(Route .Signing .route)
274+ }
275+ } else {
276+ encryptViewModel.openNestedContainer(
277+ context,
278+ nestedContainer,
279+ sharedContainerViewModel,
280+ )
281+ }
282+ showLoadingScreen.value = false
283+ } catch (ex: Exception ) {
284+ withContext(Main ) {
285+ errorLog(
286+ this .javaClass.simpleName,
287+ " Unable to open nested container" ,
288+ ex,
289+ )
290+ showLoadingScreen.value = false
291+ Toast
292+ .makeText(
293+ context,
294+ ex.localizedMessage,
295+ Toast .LENGTH_LONG ,
296+ ).show()
297+ }
298+ }
299+ }
300+ }
301+
302+ val handleSivaCancel: () -> Unit = {
303+ showSivaDialog.value = false
304+ nestedFile.value?.let { file ->
305+ if (DDOC_MIMETYPE != file.mimeType(context)) {
306+ openNestedContainer(file, false )
307+ }
308+ }
309+ }
310+
311+ val handleSivaConfirmation: () -> Unit = {
312+ showSivaDialog.value = false
313+ nestedFile.value?.let { file ->
314+ openNestedContainer(file, true )
315+ }
316+ }
317+
318+ val handleResult: (Boolean ) -> Unit = { isSivaConfirmed ->
319+ if (isSivaConfirmed) {
320+ handleSivaConfirmation()
321+ } else {
322+ handleSivaCancel()
323+ }
324+ }
325+
253326 val onDataFileClick: (File ) -> Unit = { file ->
327+ showDataFileBottomSheet.value = false
328+ showLoadingScreen.value = true
329+ val result =
330+ sharedContainerViewModel.openCryptoContainerDataFile(
331+ cryptoContainer = cryptoContainer,
332+ dataFile = file,
333+ )
334+ containerFileOpeningHandler(
335+ result = result,
336+ nestedFile = nestedFile,
337+ showSivaDialog = showSivaDialog,
338+ showLoadingScreen = showLoadingScreen,
339+ context = context,
340+ signingViewModel = null ,
341+ encryptViewModel = encryptViewModel,
342+ handleSivaConfirmation = handleSivaConfirmation,
343+ )
344+ }
345+
346+ val onDataFileMoreOptionsActionButtonClick: (File ) -> Unit = { file ->
254347 showDataFileBottomSheet.value = true
255348 clickedFile.value = file
256349 }
@@ -499,7 +592,10 @@ fun EncryptNavigation(
499592 TopBar (
500593 modifier = modifier,
501594 sharedMenuViewModel = sharedMenuViewModel,
502- title = null ,
595+ title =
596+ cryptoContainer
597+ ?.takeIf { it.encrypted || it.decrypted }
598+ ?.let { R .string.signing_container_documents_title },
503599 leftIcon =
504600 when {
505601 isNestedContainer -> R .drawable.ic_m3_arrow_back_48dp_wght400
@@ -578,78 +674,6 @@ fun EncryptNavigation(
578674 ) {
579675 var actionRecipient by remember { mutableStateOf<Addressee ?>(null ) }
580676
581- val showSivaDialog = remember { mutableStateOf(false ) }
582- val nestedFile = rememberSaveable { mutableStateOf<File ?>(null ) }
583-
584- val openNestedContainer: (nestedContainer: File , isSivaConfirmed: Boolean ) -> Unit =
585- { nestedContainer, isSivaConfirmed ->
586- scope.launch(IO ) {
587- try {
588- val isSigningContainer = nestedContainer.isContainer(context)
589-
590- if (isSigningContainer) {
591- signingViewModel.openNestedContainer(
592- context,
593- nestedContainer,
594- sharedContainerViewModel,
595- isSivaConfirmed,
596- )
597-
598- withContext(Main ) {
599- sharedContainerViewModel.setIsSivaConfirmed(isSivaConfirmed)
600- navController.navigate(Route .Signing .route)
601- }
602- } else {
603- encryptViewModel.openNestedContainer(
604- context,
605- nestedContainer,
606- sharedContainerViewModel,
607- )
608- }
609- showLoadingScreen.value = false
610- } catch (ex: Exception ) {
611- withContext(Main ) {
612- errorLog(
613- this .javaClass.simpleName,
614- " Unable to open nested container" ,
615- ex,
616- )
617- showLoadingScreen.value = false
618- Toast
619- .makeText(
620- context,
621- ex.localizedMessage,
622- Toast .LENGTH_LONG ,
623- ).show()
624- }
625- }
626- }
627- }
628-
629- val handleSivaCancel: () -> Unit = {
630- showSivaDialog.value = false
631- nestedFile.value?.let { file ->
632- if (DDOC_MIMETYPE != file.mimeType(context)) {
633- openNestedContainer(file, false )
634- }
635- }
636- }
637-
638- val handleSivaConfirmation: () -> Unit = {
639- showSivaDialog.value = false
640- nestedFile.value?.let { file ->
641- openNestedContainer(file, true )
642- }
643- }
644-
645- val handleResult: (Boolean ) -> Unit = { isSivaConfirmed ->
646- if (isSivaConfirmed) {
647- handleSivaConfirmation()
648- } else {
649- handleSivaCancel()
650- }
651- }
652-
653677 Column (
654678 modifier =
655679 modifier
@@ -685,27 +709,28 @@ fun EncryptNavigation(
685709 text = removeExtensionFromContainerFilename(cryptoContainerName),
686710 )
687711 cryptoContainer?.let {
688- val isNoRecipientsContainer =
689- ! encryptViewModel.isContainerWithoutRecipients(cryptoContainer) &&
690- ! isNestedContainer
691- val title =
692- if (! isNoRecipientsContainer) {
693- stringResource(R .string.crypto_new_title)
694- } else {
695- stringResource(R .string.crypto_view_title)
712+ val isInitialCryptoContainer =
713+ with (encryptViewModel) {
714+ isContainerWithoutRecipients(cryptoContainer) &&
715+ ! isEncryptedContainer(cryptoContainer) &&
716+ ! isDecryptedContainer(cryptoContainer) &&
717+ ! isNestedContainer
696718 }
697- Text (
698- modifier =
699- modifier
700- .padding(bottom = SPadding )
701- .semantics {
702- heading()
703- testTagsAsResourceId = true
704- }.testTag(" encryptionTitle" ),
705- text = title,
706- style = MaterialTheme .typography.headlineMedium,
707- textAlign = TextAlign .Start ,
708- )
719+
720+ if (isInitialCryptoContainer) {
721+ Text (
722+ modifier =
723+ modifier
724+ .padding(bottom = SPadding )
725+ .semantics {
726+ heading()
727+ testTagsAsResourceId = true
728+ }.testTag(" encryptionTitle" ),
729+ text = stringResource(R .string.crypto_new_title),
730+ style = MaterialTheme .typography.headlineMedium,
731+ textAlign = TextAlign .Start ,
732+ )
733+ }
709734 val rightActionButtonName =
710735 if (encryptViewModel.isDecryptButtonShown(cryptoContainer, isNestedContainer)) {
711736 R .string.decrypt_button
@@ -806,6 +831,7 @@ fun EncryptNavigation(
806831 dataFiles = dataFiles,
807832 isMoreOptionsButtonShown = true ,
808833 onClick = onDataFileClick,
834+ onDataFileMoreOptionsActionButtonClick = onDataFileMoreOptionsActionButtonClick,
809835 )
810836 }
811837 } else {
@@ -830,6 +856,8 @@ fun EncryptNavigation(
830856 cryptoContainer,
831857 ),
832858 onClick = onDataFileClick,
859+ onDataFileMoreOptionsActionButtonClick =
860+ onDataFileMoreOptionsActionButtonClick,
833861 )
834862 } else {
835863 CryptoDataFilesLocked (modifier = modifier)
0 commit comments