Skip to content

Commit

Permalink
Difference between Take a picture / Take a new picture
Browse files Browse the repository at this point in the history
  • Loading branch information
g123k committed Jun 17, 2024
1 parent 65ce9c4 commit e24f4d9
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 14 deletions.
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 @@ -2134,7 +2134,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": {
Expand Down
30 changes: 24 additions & 6 deletions packages/smooth_app/lib/pages/product/edit_ocr_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -148,11 +148,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 @@ -214,6 +219,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 @@ -236,10 +243,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 @@ -250,11 +263,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 e24f4d9

Please sign in to comment.