Skip to content

Commit

Permalink
feat: 3897 - mutilingual gallery and swipeable images - read only (#3917
Browse files Browse the repository at this point in the history
)

New file:
* `image_field_extension.dart`: moved code from `product_cards_helper.dart`

Deleted files:
* `product_image_unswipeable_view.dart`
* `smooth_images_sliver_list.dart`
* `smooth_images_view.dart`

Impacted files:
* `image_upload_card.dart`: minor refactoring
* `language_selector.dart`: added an optional foreground color (use case: explicit white for images on a black background)
* `new_crop_page.dart`: minor refactoring
* `nutrition_page_loaded.dart: now using a new special case constructor of `ProductImageSwipeableView` instead of now deleted `ProductImageUnswipeableView`
* `product_cards_helper.dart`: added language-related methods; refactored
* `product_image_carousel.dart`: minor refactoring
* `product_image_data.dart`: added language
* `product_image_gallery_view.dart`: simplified the display of the 4 images; added the language selector on top; refactored the title
* `product_image_swipeable_view.dart`: now handles the "mono imagefield" case; now manages languages; minor refactoring
* `product_image_viewer.dart`: added the language selector; removed the irrelevant `Scaffold`
  • Loading branch information
monsieurtanuki authored Apr 29, 2023
1 parent 9ed1cdc commit 558034f
Show file tree
Hide file tree
Showing 14 changed files with 373 additions and 371 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/product_image_data.dart';
import 'package:smooth_app/database/local_database.dart';
import 'package:smooth_app/database/transient_file.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/helpers/image_field_extension.dart';
import 'package:smooth_app/pages/image_crop_page.dart';
import 'package:smooth_app/pages/product/product_image_gallery_view.dart';
import 'package:smooth_app/query/product_query.dart';
Expand Down Expand Up @@ -49,9 +49,8 @@ class _ImageUploadCardState extends State<ImageUploadCard> {
),
icon: const Icon(Icons.add_a_photo),
label: Text(
getProductImageButtonText(
widget.productImageData.imageField.getProductImageButtonText(
appLocalizations,
widget.productImageData.imageField,
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ProductImageCarousel extends StatelessWidget {
ProductImageData(
imageUrl: alternateImageUrl,
imageField: ImageField.OTHER,
language: null,
),
];
} else {
Expand Down
11 changes: 3 additions & 8 deletions packages/smooth_app/lib/data_models/product_image_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,13 @@ import 'package:openfoodfacts/openfoodfacts.dart';
class ProductImageData {
const ProductImageData({
required this.imageField,
this.imageUrl,
required this.imageUrl,
required this.language,
});

factory ProductImageData.from(ProductImage image, String barcode) {
return ProductImageData(
imageField: image.field,
imageUrl: ImageHelper.buildUrl(barcode, image),
);
}

final ImageField imageField;
final String? imageUrl;
final OpenFoodFactsLanguage? language;

/// Try to convert [imageUrl] to specified [size].
/// Note that url for specified [size] might not exist on API.
Expand Down

This file was deleted.

This file was deleted.

19 changes: 16 additions & 3 deletions packages/smooth_app/lib/generic_lib/widgets/language_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class LanguageSelector extends StatelessWidget {
required this.setLanguage,
this.selectedLanguages,
this.displayedLanguage,
this.foregroundColor,
});

/// What to do when the language is selected.
Expand All @@ -23,6 +24,8 @@ class LanguageSelector extends StatelessWidget {
/// Initial language displayed, before even calling the dialog.
final OpenFoodFactsLanguage? displayedLanguage;

final Color? foregroundColor;

static const Languages _languages = Languages();

@override
Expand All @@ -46,14 +49,24 @@ class LanguageSelector extends StatelessWidget {
},
borderRadius: ANGULAR_BORDER_RADIUS,
child: ListTile(
leading: const Icon(Icons.language),
leading: Icon(
Icons.language,
color: foregroundColor,
),
title: Text(
'$nameInLanguage ($nameInEnglish)',
softWrap: false,
overflow: TextOverflow.fade,
style: Theme.of(context).textTheme.bodyMedium,
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: foregroundColor) ??
TextStyle(color: foregroundColor),
),
trailing: Icon(
Icons.arrow_drop_down,
color: foregroundColor,
),
trailing: const Icon(Icons.arrow_drop_down),
),
);
}
Expand Down
73 changes: 73 additions & 0 deletions packages/smooth_app/lib/helpers/image_field_extension.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';

extension ImageFieldSmoothieExtension on ImageField {
static const List<ImageField> orderedMain = <ImageField>[
ImageField.FRONT,
ImageField.INGREDIENTS,
ImageField.NUTRITION,
ImageField.PACKAGING,
];

String? getImageFieldUrl(final Product product) {
switch (this) {
case ImageField.FRONT:
return product.imageFrontUrl;
case ImageField.INGREDIENTS:
return product.imageIngredientsUrl;
case ImageField.NUTRITION:
return product.imageNutritionUrl;
case ImageField.PACKAGING:
return product.imagePackagingUrl;
case ImageField.OTHER:
return null;
}
}

String getProductImageButtonText(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.front_photo;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients_photo;
case ImageField.NUTRITION:
return appLocalizations.nutrition_facts_photo;
case ImageField.PACKAGING:
return appLocalizations.packaging_information_photo;
case ImageField.OTHER:
return appLocalizations.more_photos;
}
}

/// Returns a verbose description of the image field.
String getImagePageTitle(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.front_packaging_photo_title;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients_photo_title;
case ImageField.NUTRITION:
return appLocalizations.nutritional_facts_photo_title;
case ImageField.PACKAGING:
return appLocalizations.recycling_photo_title;
case ImageField.OTHER:
return appLocalizations.other_interesting_photo_title;
}
}

/// Returns a compact description of the image field.
String getProductImageTitle(final AppLocalizations appLocalizations) {
switch (this) {
case ImageField.FRONT:
return appLocalizations.product;
case ImageField.INGREDIENTS:
return appLocalizations.ingredients;
case ImageField.NUTRITION:
return appLocalizations.nutrition;
case ImageField.PACKAGING:
return appLocalizations.packaging_information;
case ImageField.OTHER:
return appLocalizations.more_photos;
}
}
}
Loading

0 comments on commit 558034f

Please sign in to comment.