Skip to content

Commit

Permalink
feat: openfoodfacts#2169 - new simple input page for "Categories"
Browse files Browse the repository at this point in the history
Impacted files:
* `app_en.arb`: added 2 translations (and fixed 1)
* `app_fr.arb`: added 2 translations
* `edit_product_page.dart`: added an item for "edit categories"
* `Podfile.lock`: wtf
* `simple_input_page_helpers.dart`: implementation for "categories"; refactored with an "in language" abstraction
  • Loading branch information
monsieurtanuki committed Jun 7, 2022
1 parent 74f6668 commit bf9e93b
Show file tree
Hide file tree
Showing 5 changed files with 109 additions and 11 deletions.
6 changes: 6 additions & 0 deletions packages/smooth_app/ios/Podfile.lock
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PODS:
- audioplayers (0.0.1):
- Flutter
- camera (0.0.1):
- Flutter
- data_importer (0.0.1):
Expand Down Expand Up @@ -113,6 +115,7 @@ PODS:
- Flutter

DEPENDENCIES:
- audioplayers (from `.symlinks/plugins/audioplayers/ios`)
- camera (from `.symlinks/plugins/camera/ios`)
- data_importer (from `.symlinks/plugins/data_importer/ios`)
- device_info_plus (from `.symlinks/plugins/device_info_plus/ios`)
Expand Down Expand Up @@ -155,6 +158,8 @@ SPEC REPOS:
- TOCropViewController

EXTERNAL SOURCES:
audioplayers:
:path: ".symlinks/plugins/audioplayers/ios"
camera:
:path: ".symlinks/plugins/camera/ios"
data_importer:
Expand Down Expand Up @@ -195,6 +200,7 @@ EXTERNAL SOURCES:
:path: ".symlinks/plugins/url_launcher_ios/ios"

SPEC CHECKSUMS:
audioplayers: 455322b54050b30ea4b1af7cd9e9d105f74efa8c
camera: 9993f92f2c793e87b65e35f3a23c70582afb05b1
data_importer: ab8c74aaf553878170aed03c03626d5820c5cb1f
device_info_plus: e5c5da33f982a436e103237c0c85f9031142abed
Expand Down
10 changes: 9 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -891,10 +891,18 @@
"@edit_product_form_item_stores_title": {
"description": "Product edition - Stores - Title"
},
"edit_product_form_item_stores_hint": "label",
"edit_product_form_item_stores_hint": "store",
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_categories_title": "Categories",
"@edit_product_form_item_categories_title": {
"description": "Product edition - Categories - Title"
},
"edit_product_form_item_categories_hint": "category",
"@edit_product_form_item_categories_hint": {
"description": "Product edition - Categories - input textfield hint"
},
"edit_product_form_item_exit_confirmation": "Do you want to save your changes before leaving this page?",
"edit_product_form_item_ingredients_title": "Ingredients & Origins",
"@edit_product_form_item_ingredients_title": {
Expand Down
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,14 @@
"@edit_product_form_item_stores_hint": {
"description": "Product edition - Stores - input textfield hint"
},
"edit_product_form_item_categories_title": "Catégories",
"@edit_product_form_item_categories_title": {
"description": "Product edition - Categories - Title"
},
"edit_product_form_item_categories_hint": "catégorie",
"@edit_product_form_item_categories_hint": {
"description": "Product edition - Categories - input textfield hint"
},
"edit_product_form_item_exit_confirmation": "Voulez-vous sauver vos modifications avant de quitter cette page ?",
"edit_product_form_item_ingredients_title": "Ingrédients & Origines",
"@edit_product_form_item_ingredients_title": {
Expand Down
3 changes: 3 additions & 0 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,9 @@ class _EditProductPageState extends State<EditProductPage> {
_getSimpleListTileItem(
SimpleInputPageStoreHelper(_product, appLocalizations),
),
_getSimpleListTileItem(
SimpleInputPageCategoryHelper(_product, appLocalizations),
),
_ListTitleItem(
title:
appLocalizations.edit_product_form_item_nutrition_facts_title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,9 +119,10 @@ class SimpleInputPageStoreHelper extends AbstractSimpleInputPageHelper {
}
}

/// Implementation for "Labels" of an [AbstractSimpleInputPageHelper].
class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper {
SimpleInputPageLabelHelper(
/// Abstraction, for "in language" field, of an [AbstractSimpleInputPageHelper].
abstract class AbstractSimpleInputPageInLanguageHelper
extends AbstractSimpleInputPageHelper {
AbstractSimpleInputPageInLanguageHelper(
final Product product,
final AppLocalizations appLocalizations,
) : super(
Expand All @@ -131,15 +132,34 @@ class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper {

final Map<String, String> _termToTags = <String, String>{};

/// Returns the value of the tags list of field for a product.
///
/// E.g. `product.categoriesTags`
@protected
List<String>? getTags();

/// Returns the value of the translations of a field for a product.
///
/// E.g. `product.categoriesTagsInLanguages`
@protected
Map<OpenFoodFactsLanguage, List<String>>? getInLanguages();

/// Sets the value of a field for a product.
///
/// e.g. `product.categories = value`
@protected
void setValue(final Product changedProduct, final String value);

@override
List<String> initTerms() {
if (product.labelsTags != null && product.labelsTagsInLanguages != null) {
final List<String>? translations =
product.labelsTagsInLanguages![_language];
if (translations != null &&
translations.length == product.labelsTags!.length) {
final List<String>? tags = getTags();
final Map<OpenFoodFactsLanguage, List<String>>? inLanguages =
getInLanguages();
if (tags != null && inLanguages != null) {
final List<String>? translations = inLanguages[_language];
if (translations != null && translations.length == tags.length) {
for (int i = 0; i < translations.length; i++) {
_termToTags[translations[i]] = product.labelsTags![i];
_termToTags[translations[i]] = tags[i];
}
return List<String>.from(translations);
}
Expand All @@ -159,8 +179,31 @@ class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper {
}
result.write(tag);
}
changedProduct.labels = result.toString();
setValue(changedProduct, result.toString());
}
}

/// Implementation for "Labels" of an [AbstractSimpleInputPageHelper].
class SimpleInputPageLabelHelper
extends AbstractSimpleInputPageInLanguageHelper {
SimpleInputPageLabelHelper(
final Product product,
final AppLocalizations appLocalizations,
) : super(
product,
appLocalizations,
);

@override
List<String>? getTags() => product.labelsTags;

@override
Map<OpenFoodFactsLanguage, List<String>>? getInLanguages() =>
product.labelsTagsInLanguages;

@override
void setValue(final Product changedProduct, final String value) =>
changedProduct.labels = value;

@override
String getTitle() => appLocalizations.edit_product_form_item_labels_title;
Expand All @@ -172,3 +215,33 @@ class SimpleInputPageLabelHelper extends AbstractSimpleInputPageHelper {
@override
String getAddHint() => appLocalizations.edit_product_form_item_labels_hint;
}

/// Implementation for "Categories" of an [AbstractSimpleInputPageHelper].
class SimpleInputPageCategoryHelper
extends AbstractSimpleInputPageInLanguageHelper {
SimpleInputPageCategoryHelper(
final Product product,
final AppLocalizations appLocalizations,
) : super(
product,
appLocalizations,
);

@override
List<String>? getTags() => product.categoriesTags;

@override
Map<OpenFoodFactsLanguage, List<String>>? getInLanguages() =>
product.categoriesTagsInLanguages;

@override
void setValue(final Product changedProduct, final String value) =>
changedProduct.categories = value;

@override
String getTitle() => appLocalizations.edit_product_form_item_categories_title;

@override
String getAddHint() =>
appLocalizations.edit_product_form_item_categories_hint;
}

0 comments on commit bf9e93b

Please sign in to comment.