Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: "Take a picture" button now distinguishes "Take a picture" VS "Take a new picture" #5396

Merged
merged 2 commits into from
Jun 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -2158,7 +2158,11 @@
},
"capture": "Capture New",
teolemon marked this conversation as resolved.
Show resolved Hide resolved
"@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 @@ -151,11 +151,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 @@ -217,6 +222,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 @@ -239,10 +246,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 @@ -253,11 +266,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
Loading