diff --git a/lib/features/document_bulk_action/view/widgets/confirm_bulk_modify_label_dialog.dart b/lib/features/document_bulk_action/view/widgets/confirm_bulk_modify_label_dialog.dart index 0bead34..98fbb4d 100644 --- a/lib/features/document_bulk_action/view/widgets/confirm_bulk_modify_label_dialog.dart +++ b/lib/features/document_bulk_action/view/widgets/confirm_bulk_modify_label_dialog.dart @@ -4,11 +4,9 @@ import 'package:paperless_mobile/core/widgets/dialog_utils/dialog_confirm_button import 'package:paperless_mobile/generated/l10n/app_localizations.dart'; class ConfirmBulkModifyLabelDialog extends StatelessWidget { - final int selectionCount; final String content; const ConfirmBulkModifyLabelDialog({ super.key, - required this.selectionCount, required this.content, }); diff --git a/lib/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart b/lib/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart index 1f82d2e..2d2a7a6 100644 --- a/lib/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart +++ b/lib/features/document_bulk_action/view/widgets/fullscreen_bulk_edit_label_page.dart @@ -1,10 +1,9 @@ import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:paperless_api/paperless_api.dart'; -import 'package:paperless_mobile/core/widgets/dialog_utils/dialog_cancel_button.dart'; -import 'package:paperless_mobile/core/widgets/dialog_utils/dialog_confirm_button.dart'; import 'package:paperless_mobile/core/widgets/form_fields/fullscreen_selection_form.dart'; import 'package:paperless_mobile/extensions/dart_extensions.dart'; +import 'package:paperless_mobile/features/document_bulk_action/view/widgets/confirm_bulk_modify_label_dialog.dart'; import 'package:paperless_mobile/generated/l10n/app_localizations.dart'; class FullscreenBulkEditLabelPage extends StatefulWidget { @@ -14,8 +13,8 @@ class FullscreenBulkEditLabelPage extends StatefulWidget { final int? Function(DocumentModel document) labelMapper; final Widget leadingIcon; final void Function(int? id) onSubmit; - final Function(String name) Function(int count) removeStringFnBuilder; - final String Function(String name) Function(int count) assignStringFnBuilder; + final String Function(int count) removeMessageBuilder; + final String Function(int count, String name) assignMessageBuilder; FullscreenBulkEditLabelPage({ super.key, @@ -25,8 +24,8 @@ class FullscreenBulkEditLabelPage extends StatefulWidget { required this.leadingIcon, required this.hintText, required this.onSubmit, - required this.removeStringFnBuilder, - required this.assignStringFnBuilder, + required this.removeMessageBuilder, + required this.assignMessageBuilder, }) : assert(selection.isNotEmpty); @override @@ -87,45 +86,14 @@ class _FullscreenBulkEditLabelPageState selectionCount: _labels.length, floatingActionButton: !hideFab ? FloatingActionButton.extended( - onPressed: () async { - if (_selection == null) { - Navigator.pop(context); - } else { - final shouldPerformAction = await showDialog( - context: context, - builder: (context) => _buildConfirmDialog(context), - // if _selection.labelId is null: show dialog asking to remove label from widget.selection.length documents - // else show dialog asking to assign label to widget.selection.length documents - ) ?? - false; - if (shouldPerformAction) { - widget.onSubmit(_selection!.label); - Navigator.pop(context); - } - } - }, + onPressed: _onSubmit, label: Text(S.of(context)!.apply), - icon: Icon(Icons.done), + icon: const Icon(Icons.done), ) : null, ); } - AlertDialog _buildConfirmDialog(BuildContext context) { - return AlertDialog( - title: Text(S.of(context)!.confirmAction), - content: Text( - S.of(context)!.areYouSureYouWantToContinue, - ), - actions: const [ - DialogCancelButton(), - DialogConfirmButton( - style: DialogConfirmButtonStyle.danger, - ), - ], - ); - } - Widget _buildItem(Label label) { Widget? trailingIcon; if (_initialValues.length > 1 && @@ -151,6 +119,39 @@ class _FullscreenBulkEditLabelPageState }, ); } + + void _onSubmit() async { + if (_selection == null) { + Navigator.pop(context); + } else { + bool shouldPerformAction; + if (_selection!.label == null) { + shouldPerformAction = await showDialog( + context: context, + builder: (context) => ConfirmBulkModifyLabelDialog( + content: widget.removeMessageBuilder(widget.selection.length), + ), + ) ?? + false; + } else { + final labelName = widget.options[_selection!.label]!.name; + shouldPerformAction = await showDialog( + context: context, + builder: (context) => ConfirmBulkModifyLabelDialog( + content: widget.assignMessageBuilder( + widget.selection.length, + '"$labelName"', + ), + ), + ) ?? + false; + } + if (shouldPerformAction) { + widget.onSubmit(_selection!.label); + Navigator.pop(context); + } + } + } } class LabelSelection { diff --git a/lib/features/documents/view/widgets/selection/document_selection_sliver_app_bar.dart b/lib/features/documents/view/widgets/selection/document_selection_sliver_app_bar.dart index c6c1d86..b3513de 100644 --- a/lib/features/documents/view/widgets/selection/document_selection_sliver_app_bar.dart +++ b/lib/features/documents/view/widgets/selection/document_selection_sliver_app_bar.dart @@ -88,21 +88,18 @@ class DocumentSelectionSliverAppBar extends StatelessWidget { onSubmit: context .read() .bulkModifyCorrespondent, - assignStringFnBuilder: (int count) { - return (String name) => S + assignMessageBuilder: (int count, String name) { + return S .of(context)! .bulkEditCorrespondentAssignMessage( name, count, ); }, - removeStringFnBuilder: (int count) { - return (String name) => S + removeMessageBuilder: (int count) { + return S .of(context)! - .bulkEditCorrespondentRemoveMessage( - name, - count, - ); + .bulkEditCorrespondentRemoveMessage(count); }, ); }, @@ -138,21 +135,18 @@ class DocumentSelectionSliverAppBar extends StatelessWidget { onSubmit: context .read() .bulkModifyDocumentType, - assignStringFnBuilder: (int count) { - return (String name) => S + assignMessageBuilder: (int count, String name) { + return S .of(context)! .bulkEditDocumentTypeAssignMessage( count, name, ); }, - removeStringFnBuilder: (int count) { - return (String name) => S + removeMessageBuilder: (int count) { + return S .of(context)! - .bulkEditDocumentTypeRemoveMessage( - count, - name, - ); + .bulkEditDocumentTypeRemoveMessage(count); }, ); }, @@ -187,21 +181,18 @@ class DocumentSelectionSliverAppBar extends StatelessWidget { onSubmit: context .read() .bulkModifyStoragePath, - assignStringFnBuilder: (int count) { - return (String name) => S + assignMessageBuilder: (int count, String name) { + return S .of(context)! .bulkEditStoragePathAssignMessage( count, name, ); }, - removeStringFnBuilder: (int count) { - return (String name) => S + removeMessageBuilder: (int count) { + return S .of(context)! - .bulkEditStoragePathRemoveMessage( - count, - name, - ); + .bulkEditStoragePathRemoveMessage(count); }, ); }, diff --git a/lib/l10n/intl_cs.arb b/lib/l10n/intl_cs.arb index 376c0ec..e0aaae0 100644 --- a/lib/l10n/intl_cs.arb +++ b/lib/l10n/intl_cs.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_de.arb b/lib/l10n/intl_de.arb index 90a78f4..b9c3f43 100644 --- a/lib/l10n/intl_de.arb +++ b/lib/l10n/intl_de.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{Diese Operation wird den Korrespondent {correspondent} dem ausgewählten Dokument zuweisen.} other{Diese Operation wird den Korrespondent {correspondent} den {count} ausgewählten Dokumenten zuweisen.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{Diese Operation wird den Dokumenttyp {docType} dem ausgewählten Dokument zuweisen.} other{Diese Operation wird den Dokumenttyp {docType} den {count} ausgewählten Dokumenten zuweisen.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{Diese Operation wird den Speicherpfad {path} dem ausgewählten Dokument zuweisen.} other{Diese Operation wird den Speicherpfad {path} den {count} ausgewählten Dokumenten zuweisen.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{Diese Operation wird den Korrespondent {correspondent} vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Korrespondenten {correspondent} von {count} ausgewählten Dokumenten entfernen.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{Diese Operation wird den Dokumenttyp {docType} vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Dokumenttyp {docType} von {count} ausgewählten Dokumenten entfernen.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{Diese Operation wird den Speicherpfad {path} vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Speicherpfad {path} von {count} ausgewählten Dokumenten entfernen.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{Diese Operation wird den Korrespondent vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Korrespondent von {count} ausgewählten Dokumenten entfernen.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{Diese Operation wird den Dokumenttyp vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Dokumenttyp von {count} ausgewählten Dokumenten entfernen.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{Diese Operation wird den Speicherpfad vom ausgewählten Dokument entfernen.} other{Diese Operation wird den Speicherpfad von {count} ausgewählten Dokumenten entfernen.}}", "anyTag": "Irgendeines", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_en.arb b/lib/l10n/intl_en.arb index 5e903de..0f16bd8 100644 --- a/lib/l10n/intl_en.arb +++ b/lib/l10n/intl_en.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_fr.arb b/lib/l10n/intl_fr.arb index cbf2e5a..d7ee77a 100644 --- a/lib/l10n/intl_fr.arb +++ b/lib/l10n/intl_fr.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_pl.arb b/lib/l10n/intl_pl.arb index c3d09e3..bbeff5e 100644 --- a/lib/l10n/intl_pl.arb +++ b/lib/l10n/intl_pl.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_ru.arb b/lib/l10n/intl_ru.arb index 730e6ca..1c320de 100644 --- a/lib/l10n/intl_ru.arb +++ b/lib/l10n/intl_ru.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered" diff --git a/lib/l10n/intl_tr.arb b/lib/l10n/intl_tr.arb index fd3d289..871936b 100644 --- a/lib/l10n/intl_tr.arb +++ b/lib/l10n/intl_tr.arb @@ -719,9 +719,9 @@ "bulkEditCorrespondentAssignMessage": "{count, plural, one{This operation will assign the correspondent {correspondent} to the selected document.} other{This operation will assign the correspondent {correspondent} to {count} selected documents.}}", "bulkEditDocumentTypeAssignMessage": "{count, plural, one{This operation will assign the document type {docType} to the selected document.} other{This operation will assign the documentType {docType} to {count} selected documents.}}", "bulkEditStoragePathAssignMessage": "{count, plural, one{This operation will assign the storage path {path} to the selected document.} other{This operation will assign the storage path {path} to {count} selected documents.}}", - "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent {correspondent} from the selected document.} other{This operation will remove the correspondent {correspondent} from {count} selected documents.}}", - "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type {docType} from the selected document.} other{This operation will remove the document type {docType} from {count} selected documents.}}", - "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path {path} from the selected document.} other{This operation will remove the storage path {path} from {count} selected documents.}}", + "bulkEditCorrespondentRemoveMessage": "{count, plural, one{This operation will remove the correspondent from the selected document.} other{This operation will remove the correspondent from {count} selected documents.}}", + "bulkEditDocumentTypeRemoveMessage": "{count, plural, one{This operation will remove the document type from the selected document.} other{This operation will remove the document type from {count} selected documents.}}", + "bulkEditStoragePathRemoveMessage": "{count, plural, one{This operation will remove the storage path from the selected document.} other{This operation will remove the storage path from {count} selected documents.}}", "anyTag": "Any", "@anyTag": { "description": "Label shown when any tag should be filtered"