Skip to content

Commit

Permalink
chore: "Take a picture" button now distinguishes "Take a picture" VS …
Browse files Browse the repository at this point in the history
…"Take a new picture" (#5396)

* Difference between Take a picture / Take a new picture

* Apply suggestions from code review

---------

Co-authored-by: Pierre Slamich <pierre.slamich@gmail.com>
  • Loading branch information
g123k and teolemon committed Jun 20, 2024
1 parent b322c68 commit 7ee3a26
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 15 deletions.
8 changes: 6 additions & 2 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2203,9 +2203,13 @@
}
}
},
"capture": "Capture New",
"capture": "Take a new picture",
"@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": {
Expand Down
30 changes: 24 additions & 6 deletions packages/smooth_app/lib/pages/product/edit_ocr/edit_ocr_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,16 @@ class _EditOcrPageState extends State<EditOcrPage> 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,
Expand Down Expand Up @@ -223,6 +228,8 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
final OpenFoodFactsLanguage language =
_multilingualHelper.getCurrentLanguage();
final ImageProvider? imageProvider = transientFile.getImageProvider();
final bool imageExists = imageProvider != null;

return Align(
alignment: AlignmentDirectional.bottomStart,
child: Column(
Expand All @@ -245,10 +252,16 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: _getImageButton(ProductImageButtonType.server),
child: _getImageButton(
ProductImageButtonType.server,
imageExists,
),
),
Expanded(
child: _getImageButton(ProductImageButtonType.local),
child: _getImageButton(
ProductImageButtonType.local,
imageExists,
),
),
],
),
Expand All @@ -259,11 +272,16 @@ class _EditOcrPageState extends State<EditOcrPage> with UpToDateMixin {
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child:
_getImageButton(ProductImageButtonType.unselect),
child: _getImageButton(
ProductImageButtonType.unselect,
imageExists,
),
),
Expanded(
child: _getImageButton(ProductImageButtonType.edit),
child: _getImageButton(
ProductImageButtonType.edit,
imageExists,
),
),
],
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -73,6 +74,7 @@ enum ProductImageButtonType {
language: language,
isLoggedInMandatory: isLoggedInMandatory,
borderWidth: borderWidth,
imageExists: imageExists,
),
ProductImageButtonType.server => ProductImageServerButton(
product: product,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> action(final BuildContext context) async {
Expand Down
28 changes: 23 additions & 5 deletions packages/smooth_app/lib/pages/product/product_image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,16 @@ class _ProductImageViewerState extends State<ProductImageViewer>
initUpToDate(widget.product, context.read<LocalDatabase>());
}

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,
),
Expand All @@ -65,6 +70,7 @@ class _ProductImageViewerState extends State<ProductImageViewer>
widget.language,
);
final ImageProvider? imageProvider = _getTransientFile().getImageProvider();
final bool imageExists = imageProvider != null;
final Iterable<OpenFoodFactsLanguage> selectedLanguages =
getProductImageLanguages(
upToDateProduct,
Expand Down Expand Up @@ -193,10 +199,16 @@ class _ProductImageViewerState extends State<ProductImageViewer>
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: _getImageButton(ProductImageButtonType.server),
child: _getImageButton(
ProductImageButtonType.server,
imageExists,
),
),
Expanded(
child: _getImageButton(ProductImageButtonType.local),
child: _getImageButton(
ProductImageButtonType.local,
imageExists,
),
),
],
),
Expand All @@ -207,10 +219,16 @@ class _ProductImageViewerState extends State<ProductImageViewer>
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: _getImageButton(ProductImageButtonType.unselect),
child: _getImageButton(
ProductImageButtonType.unselect,
imageExists,
),
),
Expanded(
child: _getImageButton(ProductImageButtonType.edit),
child: _getImageButton(
ProductImageButtonType.edit,
imageExists,
),
),
],
),
Expand Down

0 comments on commit 7ee3a26

Please sign in to comment.