From d026ffdb1fe518dc06e2b9fc6dda849cc3a7a9a8 Mon Sep 17 00:00:00 2001 From: Sachin S P Date: Wed, 11 Oct 2023 16:54:46 +0530 Subject: [PATCH] added delete functionality for document page Signed-off-by: Sachin S P --- .../api_services/DocumentDetailsApi.java | 6 +- lib/l10n/app_ar.arb | 3 +- lib/l10n/app_en.arb | 3 +- lib/l10n/app_fr.arb | 3 +- lib/l10n/app_hi.arb | 3 +- lib/l10n/app_kn.arb | 3 +- lib/l10n/app_ta.arb | 3 +- lib/provider/global_provider.dart | 6 ++ lib/provider/registration_task_provider.dart | 4 + .../widgets/document_upload_control.dart | 85 ++++++++++++++++--- 10 files changed, 99 insertions(+), 20 deletions(-) diff --git a/android/app/src/main/java/io/mosip/registration_client/api_services/DocumentDetailsApi.java b/android/app/src/main/java/io/mosip/registration_client/api_services/DocumentDetailsApi.java index 0dca071fc..7dbd76776 100644 --- a/android/app/src/main/java/io/mosip/registration_client/api_services/DocumentDetailsApi.java +++ b/android/app/src/main/java/io/mosip/registration_client/api_services/DocumentDetailsApi.java @@ -38,7 +38,11 @@ public void addDocument(@NonNull String fieldId, @NonNull String docType, @NonNu @Override public void removeDocument(@NonNull String fieldId, @NonNull Long pageIndex, @NonNull DocumentDataPigeon.Result result) { - + try { + this.registrationService.getRegistrationDto().removeDocument(fieldId, pageIndex.intValue()); + } catch (Exception e) { + Log.e(getClass().getSimpleName(), "Remove Document failed!" + Arrays.toString(e.getStackTrace())); + } } @Override diff --git a/lib/l10n/app_ar.arb b/lib/l10n/app_ar.arb index 328971690..29fe49f6f 100644 --- a/lib/l10n/app_ar.arb +++ b/lib/l10n/app_ar.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"فشل مزامنة تفاصيل المستخدم", "id_schema_sync_failed":"فشل مزامنة IDSchema", "master_data_sync_failed":"فشل مزامنة البيانات الرئيسية", - "network_error": "لم يتم العثور على شبكة!" + "network_error": "لم يتم العثور على شبكة!", + "delete": "يمسح" } \ No newline at end of file diff --git a/lib/l10n/app_en.arb b/lib/l10n/app_en.arb index b46beb218..fc54033bd 100644 --- a/lib/l10n/app_en.arb +++ b/lib/l10n/app_en.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"User Details Sync Failed", "id_schema_sync_failed":"IDSchena Sync Failed", "master_data_sync_failed":"Master Data Sync Failed", - "network_error": "No network found!" + "network_error": "No network found!", + "delete": "DELETE" } \ No newline at end of file diff --git a/lib/l10n/app_fr.arb b/lib/l10n/app_fr.arb index 63a7fb0ed..b279d3b15 100644 --- a/lib/l10n/app_fr.arb +++ b/lib/l10n/app_fr.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"Échec de la synchronisation des détails de l'utilisateur", "id_schema_sync_failed":"Échec de la synchronisation IDSchema", "master_data_sync_failed":"Échec de la synchronisation des données principales", - "network_error": "Aucun réseau trouvé!" + "network_error": "Aucun réseau trouvé!", + "delete": "SUPPRIMER" } \ No newline at end of file diff --git a/lib/l10n/app_hi.arb b/lib/l10n/app_hi.arb index 399daeea1..5c186aca6 100644 --- a/lib/l10n/app_hi.arb +++ b/lib/l10n/app_hi.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"उपयोगकर्ता विवरण सिंक्रनाइज़ेशन विफल रहा", "id_schema_sync_failed":"IDSchena सिंक्रनाइज़ेशन विफल रहा", "master_data_sync_failed":"मास्टर डेटा सिंक्रनाइज़ेशन विफल", - "network_error": "कोई नेटवर्क नहीं मिला!" + "network_error": "कोई नेटवर्क नहीं मिला!", + "delete": "मिटाना" } \ No newline at end of file diff --git a/lib/l10n/app_kn.arb b/lib/l10n/app_kn.arb index 9ceabad3b..6aa5992a1 100644 --- a/lib/l10n/app_kn.arb +++ b/lib/l10n/app_kn.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"ಬಳಕೆದಾರ ವಿವರಗಳ ಸಿಂಕ್ ವಿಫಲವಾಗಿದೆ", "id_schema_sync_failed":"IDSchena ಸಿಂಕ್ ವಿಫಲವಾಗಿದೆ", "master_data_sync_failed":"ಮಾಸ್ಟರ್ ಡೇಟಾ ಸಿಂಕ್ ವಿಫಲವಾಗಿದೆ", - "network_error": "ಯಾವುದೇ ನೆಟ್ವರ್ಕ್ ಸಿಗಲಿಲ್ಲ!" + "network_error": "ಯಾವುದೇ ನೆಟ್ವರ್ಕ್ ಸಿಗಲಿಲ್ಲ!", + "delete": "ಅಳಿಸಿ" } \ No newline at end of file diff --git a/lib/l10n/app_ta.arb b/lib/l10n/app_ta.arb index 1fe1f0910..1cbeb9888 100644 --- a/lib/l10n/app_ta.arb +++ b/lib/l10n/app_ta.arb @@ -51,5 +51,6 @@ "user_details_sync_failed":"பயனர் விவரங்கள் ஒத்திசைவு தோல்வியுற்றது", "id_schema_sync_failed":"IDSchena Sync Failed", "master_data_sync_failed":"Master Data Sync தோல்வியுற்றது", - "network_error": "நெட்வொர்க் இல்லை!" + "network_error": "நெட்வொர்க் இல்லை!", + "delete": "அழி" } \ No newline at end of file diff --git a/lib/provider/global_provider.dart b/lib/provider/global_provider.dart index c451fb3fd..51701e5fc 100644 --- a/lib/provider/global_provider.dart +++ b/lib/provider/global_provider.dart @@ -71,6 +71,12 @@ class GlobalProvider with ChangeNotifier { notifyListeners(); } + removeScannedPages(String field,Uint8List? value, List listOfValue) { + _scannedPages[field] = listOfValue; + _scannedPages[field]!.remove(value); + notifyListeners(); + } + void clearScannedPages() { _scannedPages.clear(); notifyListeners(); diff --git a/lib/provider/registration_task_provider.dart b/lib/provider/registration_task_provider.dart index 89eca86c1..c37e04aac 100644 --- a/lib/provider/registration_task_provider.dart +++ b/lib/provider/registration_task_provider.dart @@ -171,4 +171,8 @@ class RegistrationTaskProvider with ChangeNotifier { getScannedDocument(String fieldId) async { return document.getScannedPages(fieldId); } + + removeDocument(String fieldId, int pageIndex) async { + await document.removeDocument(fieldId, pageIndex); + } } diff --git a/lib/ui/process_ui/widgets/document_upload_control.dart b/lib/ui/process_ui/widgets/document_upload_control.dart index ca0b25ff1..8fb75a017 100644 --- a/lib/ui/process_ui/widgets/document_upload_control.dart +++ b/lib/ui/process_ui/widgets/document_upload_control.dart @@ -9,6 +9,7 @@ import 'package:registration_client/model/upload_document_data.dart'; import 'package:registration_client/pigeon/document_pigeon.dart'; import 'package:registration_client/provider/registration_task_provider.dart'; import 'package:registration_client/ui/scanner/scanner.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import '../../../model/field.dart'; import '../../../provider/global_provider.dart'; @@ -33,8 +34,9 @@ class _DocumentUploadControlState extends State { context.read().scannedPages[widget.field.id]; if (scannedPagesMap != null) { + imageBytesList.clear(); setState(() { - imageBytesList = scannedPagesMap; + imageBytesList.addAll(scannedPagesMap); }); } @@ -57,7 +59,7 @@ class _DocumentUploadControlState extends State { } List poaList = []; - List imageBytesList = []; // list of image bytes + List imageBytesList = List.empty(growable: true); // list of image bytes _getAddDocumentProvider(Field e, Uint8List myBytes) { context @@ -76,20 +78,29 @@ class _DocumentUploadControlState extends State { _getAddDocumentProvider(e, myBytes); } + _getRemoveDocumentProvider(Field e, int index){ + context.read().removeDocument(e.id!, index); + } + _setScannedPages(Field e, List listOfScannedDoc) { context.read().setScannedPages(e.id!, listOfScannedDoc); } + _setRemoveScannedPages(Field e, Uint8List? item, List listOfScannedDoc){ + context.read().removeScannedPages(e.id!,item,listOfScannedDoc); + } + _setValueInMap() { context.read().fieldInputValue[widget.field.id!] = doc; } Future getScannedDocuments(Field e) async { try { + imageBytesList.clear(); final listOfScannedDoc = await DocumentApi().getScannedPages(e.id!); _setScannedPages(e, listOfScannedDoc); setState(() { - imageBytesList = listOfScannedDoc; + imageBytesList.addAll(listOfScannedDoc); doc.listofImages = imageBytesList; }); if (doc.title.isNotEmpty) { @@ -139,6 +150,18 @@ class _DocumentUploadControlState extends State { .getDocumentValues(fieldName, langCode, applicantType); } + void _deleteImage(Field e, Uint8List? item) async { + for(int i =0;i<=imageBytesList.length;i++){ + if(imageBytesList[i] == item){ + setState(() { + imageBytesList.remove(item); + }); + await _getRemoveDocumentProvider(e, i); + _setRemoveScannedPages(e, item, imageBytesList); + } + } + } + @override Widget build(BuildContext context) { bool isMobile = MediaQuery.of(context).size.width < 750; @@ -269,15 +292,33 @@ class _DocumentUploadControlState extends State { ), imageBytesList.isNotEmpty ? SizedBox( - height: 80, + height: 110, child: ListView( scrollDirection: Axis.horizontal, children: imageBytesList.map((item) { return Card( - child: SizedBox( - height: 70, - width: 90, - child: Image.memory(item!), + child: Column( + children: [ + SizedBox( + height: 70, + width: 100, + child: Image.memory(item!), + ), + const SizedBox(height: 10,), + GestureDetector( + onTap: (){ + _deleteImage(widget.field,item); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.delete_forever_outlined,color: Colors.red,size: 14,), + const SizedBox(width: 5,), + Text(AppLocalizations.of(context)!.delete,style: TextStyle(fontSize: 13,color: Colors.red)), + ], + ), + ) + ], ), ); }).toList(), @@ -425,15 +466,33 @@ class _DocumentUploadControlState extends State { ), imageBytesList.isNotEmpty ? SizedBox( - height: 80, + height: 110, child: ListView( scrollDirection: Axis.horizontal, children: imageBytesList.map((item) { return Card( - child: SizedBox( - height: 70, - width: 90, - child: Image.memory(item!), + child: Column( + children: [ + SizedBox( + height: 70, + width: 100, + child: Image.memory(item!), + ), + const SizedBox(height: 10,), + GestureDetector( + onTap: (){ + _deleteImage(widget.field,item); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Icon(Icons.delete_forever_outlined,color: Colors.red,size: 14,), + const SizedBox(width: 5,), + Text(AppLocalizations.of(context)!.delete,style: TextStyle(fontSize: 13,color: Colors.red)), + ], + ), + ) + ], ), ); }).toList(),