From 68de11d54d0ee3b32a66901fe5e2f8bdc5709c67 Mon Sep 17 00:00:00 2001 From: Edouard Marquez Date: Mon, 17 Jun 2024 18:47:22 +0200 Subject: [PATCH 1/2] Difference between Take a picture / Take a new picture --- packages/smooth_app/lib/l10n/app_en.arb | 6 +++- .../pages/product/edit_ocr/edit_ocr_page.dart | 30 +++++++++++++++---- .../pages/product/product_image_button.dart | 2 ++ .../product/product_image_local_button.dart | 8 +++-- .../pages/product/product_image_viewer.dart | 28 +++++++++++++---- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index f966f3943b4..ad4f361cbfe 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -2158,7 +2158,11 @@ }, "capture": "Capture New", "@capture": { - "description": "Button label for taking a photo" + "description": "Button label for taking a new photo (= there's already one)" + }, + "capture_new_picture": "Take a picture", + "@capture_new_picture": { + "description": "Button label for taking a new photo (= the first one)" }, "choose_from_gallery": "Choose from gallery", "@choose_from_gallery": { diff --git a/packages/smooth_app/lib/pages/product/edit_ocr/edit_ocr_page.dart b/packages/smooth_app/lib/pages/product/edit_ocr/edit_ocr_page.dart index f8862431125..5baab410832 100644 --- a/packages/smooth_app/lib/pages/product/edit_ocr/edit_ocr_page.dart +++ b/packages/smooth_app/lib/pages/product/edit_ocr/edit_ocr_page.dart @@ -151,11 +151,16 @@ class _EditOcrPageState extends State with UpToDateMixin { ); } - Widget _getImageButton(final ProductImageButtonType type) => Padding( + Widget _getImageButton( + final ProductImageButtonType type, + final bool imageExists, + ) => + Padding( padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE), child: type.getButton( product: upToDateProduct, imageField: _helper.getImageField(), + imageExists: imageExists, language: _multilingualHelper.getCurrentLanguage(), isLoggedInMandatory: widget.isLoggedInMandatory, borderWidth: 2, @@ -217,6 +222,8 @@ class _EditOcrPageState extends State with UpToDateMixin { final OpenFoodFactsLanguage language = _multilingualHelper.getCurrentLanguage(); final ImageProvider? imageProvider = transientFile.getImageProvider(); + final bool imageExists = imageProvider != null; + return Align( alignment: AlignmentDirectional.bottomStart, child: Column( @@ -239,10 +246,16 @@ class _EditOcrPageState extends State with UpToDateMixin { mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: _getImageButton(ProductImageButtonType.server), + child: _getImageButton( + ProductImageButtonType.server, + imageExists, + ), ), Expanded( - child: _getImageButton(ProductImageButtonType.local), + child: _getImageButton( + ProductImageButtonType.local, + imageExists, + ), ), ], ), @@ -253,11 +266,16 @@ class _EditOcrPageState extends State with UpToDateMixin { mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: - _getImageButton(ProductImageButtonType.unselect), + child: _getImageButton( + ProductImageButtonType.unselect, + imageExists, + ), ), Expanded( - child: _getImageButton(ProductImageButtonType.edit), + child: _getImageButton( + ProductImageButtonType.edit, + imageExists, + ), ), ], ), diff --git a/packages/smooth_app/lib/pages/product/product_image_button.dart b/packages/smooth_app/lib/pages/product/product_image_button.dart index f977ce74f05..2c6352d9f24 100644 --- a/packages/smooth_app/lib/pages/product/product_image_button.dart +++ b/packages/smooth_app/lib/pages/product/product_image_button.dart @@ -65,6 +65,7 @@ enum ProductImageButtonType { required final OpenFoodFactsLanguage language, required final bool isLoggedInMandatory, final double? borderWidth, + required bool imageExists, }) => switch (this) { ProductImageButtonType.local => ProductImageLocalButton( @@ -73,6 +74,7 @@ enum ProductImageButtonType { language: language, isLoggedInMandatory: isLoggedInMandatory, borderWidth: borderWidth, + imageExists: imageExists, ), ProductImageButtonType.server => ProductImageServerButton( product: product, diff --git a/packages/smooth_app/lib/pages/product/product_image_local_button.dart b/packages/smooth_app/lib/pages/product/product_image_local_button.dart index 4f4a687db3b..049cffa4291 100644 --- a/packages/smooth_app/lib/pages/product/product_image_local_button.dart +++ b/packages/smooth_app/lib/pages/product/product_image_local_button.dart @@ -11,15 +11,19 @@ class ProductImageLocalButton extends ProductImageButton { required super.imageField, required super.language, required super.isLoggedInMandatory, + required this.imageExists, super.borderWidth, }); + final bool imageExists; + @override IconData getIconData() => Icons.add_a_photo; @override - String getLabel(final AppLocalizations appLocalizations) => - appLocalizations.capture; + String getLabel(final AppLocalizations appLocalizations) => imageExists + ? appLocalizations.capture + : appLocalizations.capture_new_picture; @override Future action(final BuildContext context) async { diff --git a/packages/smooth_app/lib/pages/product/product_image_viewer.dart b/packages/smooth_app/lib/pages/product/product_image_viewer.dart index 4b8c84457a3..1f43d5cfd76 100644 --- a/packages/smooth_app/lib/pages/product/product_image_viewer.dart +++ b/packages/smooth_app/lib/pages/product/product_image_viewer.dart @@ -44,11 +44,16 @@ class _ProductImageViewerState extends State initUpToDate(widget.product, context.read()); } - Widget _getImageButton(final ProductImageButtonType type) => Padding( + Widget _getImageButton( + final ProductImageButtonType type, + final bool imageExists, + ) => + Padding( padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE), child: type.getButton( product: upToDateProduct, imageField: widget.imageField, + imageExists: imageExists, language: widget.language, isLoggedInMandatory: widget.isLoggedInMandatory, ), @@ -65,6 +70,7 @@ class _ProductImageViewerState extends State widget.language, ); final ImageProvider? imageProvider = _getTransientFile().getImageProvider(); + final bool imageExists = imageProvider != null; final Iterable selectedLanguages = getProductImageLanguages( upToDateProduct, @@ -193,10 +199,16 @@ class _ProductImageViewerState extends State mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: _getImageButton(ProductImageButtonType.server), + child: _getImageButton( + ProductImageButtonType.server, + imageExists, + ), ), Expanded( - child: _getImageButton(ProductImageButtonType.local), + child: _getImageButton( + ProductImageButtonType.local, + imageExists, + ), ), ], ), @@ -207,10 +219,16 @@ class _ProductImageViewerState extends State mainAxisSize: MainAxisSize.max, children: [ Expanded( - child: _getImageButton(ProductImageButtonType.unselect), + child: _getImageButton( + ProductImageButtonType.unselect, + imageExists, + ), ), Expanded( - child: _getImageButton(ProductImageButtonType.edit), + child: _getImageButton( + ProductImageButtonType.edit, + imageExists, + ), ), ], ), From 35c15d06cf7d2f2b6423ea2879c0d3943c9e0296 Mon Sep 17 00:00:00 2001 From: Pierre Slamich Date: Thu, 20 Jun 2024 17:43:13 +0200 Subject: [PATCH 2/2] Apply suggestions from code review --- packages/smooth_app/lib/l10n/app_en.arb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index ad4f361cbfe..a2598b22eff 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -2156,7 +2156,7 @@ } } }, - "capture": "Capture New", + "capture": "Take a new picture", "@capture": { "description": "Button label for taking a new photo (= there's already one)" },