diff --git a/lib/l10n/app_localizations.dart b/lib/l10n/app_localizations.dart index acd68f9..e128ff6 100644 --- a/lib/l10n/app_localizations.dart +++ b/lib/l10n/app_localizations.dart @@ -460,7 +460,7 @@ abstract class AppLocalizations { /// No description provided for @documentValidationNoSignaturesLabel. /// /// In sk, this message translates to: - /// **'Dokument neobsahuje **žiadny podpis**'** + /// **'Dokument zatiaľ neobsahuje **žiadny podpis**'** String get documentValidationNoSignaturesLabel; /// No description provided for @documentValidationHasInvalidSignaturesLabel. @@ -469,6 +469,12 @@ abstract class AppLocalizations { /// **'Dokument obsahuje **neplatné podpisy**'** String get documentValidationHasInvalidSignaturesLabel; + /// No description provided for @documentValidationHasIndeterminateSignatureLabel. + /// + /// In sk, this message translates to: + /// **'Dokument obsahuje **neznámy podpis**'** + String get documentValidationHasIndeterminateSignatureLabel; + /// No description provided for @documentValidationHasValidSignaturesLabel. /// /// In sk, this message translates to: diff --git a/lib/l10n/app_localizations_sk.dart b/lib/l10n/app_localizations_sk.dart index 9ab732e..75f425a 100644 --- a/lib/l10n/app_localizations_sk.dart +++ b/lib/l10n/app_localizations_sk.dart @@ -238,11 +238,14 @@ class AppLocalizationsSk extends AppLocalizations { String get documentValidationLoadingLabel => 'Prebieha overovanie podpisov'; @override - String get documentValidationNoSignaturesLabel => 'Dokument neobsahuje **žiadny podpis**'; + String get documentValidationNoSignaturesLabel => 'Dokument zatiaľ neobsahuje **žiadny podpis**'; @override String get documentValidationHasInvalidSignaturesLabel => 'Dokument obsahuje **neplatné podpisy**'; + @override + String get documentValidationHasIndeterminateSignatureLabel => 'Dokument obsahuje **neznámy podpis**'; + @override String documentValidationHasValidSignaturesLabel(num count) { String _temp0 = intl.Intl.pluralLogic( diff --git a/lib/l10n/app_sk.arb b/lib/l10n/app_sk.arb index 3dfb839..9c60a98 100644 --- a/lib/l10n/app_sk.arb +++ b/lib/l10n/app_sk.arb @@ -74,8 +74,9 @@ "documentVisualizationCannotVisualizeTypeError": "Neviem vizualizovať {type} typ.", "documentValidationLoadingLabel": "Prebieha overovanie podpisov", - "documentValidationNoSignaturesLabel": "Dokument neobsahuje **žiadny podpis**", + "documentValidationNoSignaturesLabel": "Dokument zatiaľ neobsahuje **žiadny podpis**", "documentValidationHasInvalidSignaturesLabel": "Dokument obsahuje **neplatné podpisy**", + "documentValidationHasIndeterminateSignatureLabel": "Dokument obsahuje **neznámy podpis**", "documentValidationHasValidSignaturesLabel": "{count, plural, one {Dokument obsahuje **1 podpis**} few {Dokument obsahuje **{count} podpisy**} many {Dokument obsahuje {count} podpisov**} other {Dokument obsahuje **{count} podpisov**}}", "documentValidationSignaturesHeading": "Podpisy v dokumente", diff --git a/lib/ui/fragment/document_validation_fragment.dart b/lib/ui/fragment/document_validation_fragment.dart index 5a80193..64d18f8 100644 --- a/lib/ui/fragment/document_validation_fragment.dart +++ b/lib/ui/fragment/document_validation_fragment.dart @@ -1,6 +1,7 @@ import 'package:autogram_sign/autogram_sign.dart' show DocumentValidationResponseBody, + DocumentValidationResponseBody$Signatures$Item, DocumentValidationResponseBody$Signatures$ItemValidationResult; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; @@ -71,8 +72,9 @@ class _DocumentValidationFragmentState ), DocumentValidationSuccessState state => DocumentValidationStrip( value: DocumentValidationStripValue.value( - validCount: state.response.validSignaturesCount ?? 0, - invalidCount: state.response.invalidSignaturesCount ?? 0, + failedCount: state.response.failedCount, + indeterminateCount: state.response.indeterminateCount, + passedCount: state.response.passedCount, ), onTap: () { widget.onShowDocumentValidationInfoRequested.call(state.response); @@ -87,10 +89,18 @@ class _DocumentValidationFragmentState /// A set of extensions on [DocumentValidationResponseBody]. extension _DocumentValidationResponseBodyExtensions on DocumentValidationResponseBody { - int? get validSignaturesCount => signatures - ?.where((s) => s.validationResult == _ValidationResult.totalPassed) + List get signaturesOrEmpty => + (signatures ?? []); + + int get failedCount => signaturesOrEmpty + .where((s) => s.validationResult == _ValidationResult.totalFailed) + .length; + + int get indeterminateCount => signaturesOrEmpty + .where((s) => s.validationResult == _ValidationResult.indeterminate) .length; - int? get invalidSignaturesCount => signatures - ?.where((s) => s.validationResult != _ValidationResult.totalPassed) + + int get passedCount => signaturesOrEmpty + .where((s) => s.validationResult == _ValidationResult.totalPassed) .length; } diff --git a/lib/ui/widgets/document_validation_strip.dart b/lib/ui/widgets/document_validation_strip.dart index cf9b172..75c8988 100644 --- a/lib/ui/widgets/document_validation_strip.dart +++ b/lib/ui/widgets/document_validation_strip.dart @@ -24,26 +24,38 @@ class DocumentValidationStrip extends StatelessWidget { @override Widget build(BuildContext context) { - final data = (value.isLoading, value.validCount, value.invalidCount); + final data = ( + value.isLoading, + value.failedCount, + value.indeterminateCount, + value.passedCount + ); final isLoading = value.isLoading; - final hasSignatures = (value.validCount > 0 || value.invalidCount > 0); - + final hasSignatures = + (value.failedCount + value.indeterminateCount + value.passedCount) > 0; final strings = context.strings; - - final String text = switch (data) { - (true, _, _) => strings.documentValidationLoadingLabel, - (false, _, > 0) => strings.documentValidationHasInvalidSignaturesLabel, - (false, > 0, _) => - strings.documentValidationHasValidSignaturesLabel(value.validCount), - (false, 0, 0) => strings.documentValidationNoSignaturesLabel, - (_, _, _) => "" // technically invalid case - }; - final Color backgroundColor = switch (data) { - (true, _, _) => const Color(0xFF126DFF), - (false, _, > 0) => const Color(0xFFC3112B), - (false, > 0, _) => const Color(0xFF078814), - (false, 0, 0) => const Color(0xFF126DFF), - (_, _, _) => Colors.transparent, + final (String text, Color backgroundColor) = switch (data) { + (true, _, _, _) => ( + strings.documentValidationLoadingLabel, + const Color(0xFF126DFF) + ), + (false, 0, 0, 0) => ( + strings.documentValidationNoSignaturesLabel, + const Color(0xFF126DFF), + ), + (false, > 0, _, _) => ( + strings.documentValidationHasInvalidSignaturesLabel, + const Color(0xFFC3112B), + ), + (false, _, > 0, _) => ( + strings.documentValidationHasIndeterminateSignatureLabel, + const Color(0xFFbd730c), + ), + (false, 0, 0, > 0) => ( + strings.documentValidationHasValidSignaturesLabel(value.passedCount), + const Color(0xFF078814), + ), + (_, _, _, _) => ("", Colors.transparent), // technically invalid case }; const foregroundColor = Colors.white; final icon = (hasSignatures ? Icons.arrow_right_alt_outlined : Icons.close); @@ -79,24 +91,31 @@ class DocumentValidationStrip extends StatelessWidget { /// Value for [DocumentValidationStrip] widget. class DocumentValidationStripValue { final bool isLoading; - final int validCount; - final int invalidCount; + final int failedCount; + final int indeterminateCount; + final int passedCount; final Object? error; const DocumentValidationStripValue.loading() : isLoading = true, - validCount = 0, - invalidCount = 0, + failedCount = 0, + indeterminateCount = 0, + passedCount = 0, error = null; const DocumentValidationStripValue.value({ - required this.validCount, - required this.invalidCount, + required this.failedCount, + required this.indeterminateCount, + required this.passedCount, }) : isLoading = false, error = null; const DocumentValidationStripValue.none() - : this.value(validCount: 0, invalidCount: 0); + : this.value( + failedCount: 0, + indeterminateCount: 0, + passedCount: 0, + ); } @widgetbook.UseCase( @@ -116,21 +135,27 @@ Widget previewLoadingDocumentValidationStrip(BuildContext context) { type: DocumentValidationStrip, ) Widget previewOtherDocumentValidationStrip(BuildContext context) { - final validCount = context.knobs.list( - label: 'Valid count', + final passedCount = context.knobs.list( + label: 'Passed count', + options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], + initialOption: 0, + ); + final indeterminateCount = context.knobs.list( + label: 'Indeterminate count', options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], initialOption: 0, ); - final invalidCount = context.knobs.list( - label: 'Invalid count', + final failedCount = context.knobs.list( + label: 'Failed count', options: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], initialOption: 0, ); return DocumentValidationStrip( value: DocumentValidationStripValue.value( - validCount: validCount, - invalidCount: invalidCount, + failedCount: failedCount, + indeterminateCount: indeterminateCount, + passedCount: passedCount, ), ); }