Skip to content

Commit

Permalink
Merge branch 'develop' into fix/3980
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored May 23, 2023
2 parents 401634b + 96426b2 commit bfdce6d
Show file tree
Hide file tree
Showing 10 changed files with 230 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
to allow setting breakpoints, to provide hot reload, etc.
-->
<uses-permission android:name="android.permission.INTERNET"/>
</manifest>
</manifest>
57 changes: 30 additions & 27 deletions packages/smooth_app/lib/generic_lib/widgets/language_selector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,33 +39,36 @@ class LanguageSelector extends StatelessWidget {
}
final String nameInEnglish = _languages.getNameInEnglish(language);
final String nameInLanguage = _languages.getNameInLanguage(language);
return InkWell(
onTap: () async {
final OpenFoodFactsLanguage? language = await openLanguageSelector(
context,
selectedLanguages: selectedLanguages,
);
await setLanguage(language);
},
borderRadius: ANGULAR_BORDER_RADIUS,
child: ListTile(
leading: Icon(
Icons.language,
color: foregroundColor,
),
title: Text(
'$nameInLanguage ($nameInEnglish)',
softWrap: false,
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: foregroundColor) ??
TextStyle(color: foregroundColor),
),
trailing: Icon(
Icons.arrow_drop_down,
color: foregroundColor,
return Material(
type: MaterialType.transparency,
child: InkWell(
onTap: () async {
final OpenFoodFactsLanguage? language = await openLanguageSelector(
context,
selectedLanguages: selectedLanguages,
);
await setLanguage(language);
},
borderRadius: ANGULAR_BORDER_RADIUS,
child: ListTile(
leading: Icon(
Icons.language,
color: foregroundColor,
),
title: Text(
'$nameInLanguage ($nameInEnglish)',
softWrap: false,
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.bodyMedium
?.copyWith(color: foregroundColor) ??
TextStyle(color: foregroundColor),
),
trailing: Icon(
Icons.arrow_drop_down,
color: foregroundColor,
),
),
),
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/smooth_html_widget.dart';
import 'package:smooth_app/pages/product/add_nutrition_button.dart';
import 'package:smooth_app/pages/product/add_ocr_button.dart';
import 'package:smooth_app/pages/product/add_packaging_button.dart';
import 'package:smooth_app/pages/product/add_simple_input_button.dart';
import 'package:smooth_app/pages/product/ocr_helper.dart';
import 'package:smooth_app/pages/product/ocr_ingredients_helper.dart';
import 'package:smooth_app/pages/product/ocr_packaging_helper.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/services/smooth_services.dart';

Expand All @@ -31,33 +30,11 @@ class KnowledgePanelActionCard extends StatelessWidget {
Widget build(BuildContext context) {
final List<Widget> actionWidgets = <Widget>[];
for (final String action in element.actions) {
final AbstractSimpleInputPageHelper? simpleInputPageHelper =
_getSimpleInputPageHelper(action);
if (simpleInputPageHelper != null) {
actionWidgets.add(
AddSimpleInputButton(
product: product,
helper: simpleInputPageHelper,
),
);
continue;
}
final OcrHelper? ocrHelper = _getOcrHelper(action);
if (ocrHelper != null) {
actionWidgets.add(
AddOCRButton(
product: product,
helper: ocrHelper,
),
);
continue;
}
switch (action) {
case KnowledgePanelActionElement.ACTION_ADD_NUTRITION_FACTS:
actionWidgets.add(AddNutritionButton(product));
break;
default:
Logs.e('unknown knowledge panel action: $action');
final Widget? button = _getButton(action);
if (button != null) {
actionWidgets.add(button);
} else {
Logs.e('unknown knowledge panel action: $action');
}
}
return Column(
Expand All @@ -71,6 +48,33 @@ class KnowledgePanelActionCard extends StatelessWidget {
);
}

Widget? _getButton(final String action) {
final AbstractSimpleInputPageHelper? simpleInputPageHelper =
_getSimpleInputPageHelper(action);
if (simpleInputPageHelper != null) {
return AddSimpleInputButton(
product: product,
helper: simpleInputPageHelper,
);
}
if (_isPackaging(action)) {
return AddPackagingButton(
product: product,
);
}
if (_isIngredient(action)) {
return AddOCRButton(
product: product,
helper: OcrIngredientsHelper(),
);
}
if (action == KnowledgePanelActionElement.ACTION_ADD_NUTRITION_FACTS) {
return AddNutritionButton(product);
}
Logs.e('unknown knowledge panel action: $action');
return null;
}

AbstractSimpleInputPageHelper? _getSimpleInputPageHelper(
final String action,
) {
Expand All @@ -89,17 +93,27 @@ class KnowledgePanelActionCard extends StatelessWidget {
return null;
}

OcrHelper? _getOcrHelper(
bool _isIngredient(
final String action,
) {
switch (action) {
case KnowledgePanelActionElement.ACTION_ADD_INGREDIENTS_TEXT:
case _ACTION_ADD_INGREDIENTS_IMAGE:
return OcrIngredientsHelper();
return true;
default:
return false;
}
}

bool _isPackaging(
final String action,
) {
switch (action) {
case _ACTION_ADD_PACKAGING_IMAGE:
case _ACTION_ADD_PACKAGING_TEXT:
return OcrPackagingHelper();
return true;
default:
return false;
}
return null;
}
}
8 changes: 8 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@
"@add_product_information_button_label": {},
"new_product": "New Product",
"@new_product": {},
"new_product_dialog_title": "You have just found a new product!",
"@new_product_dialog_title": {
"description": "Please keep it short, like 50 characters. Title of the dialog when the user searched for an unknown barcode."
},
"new_product_dialog_description": "Please take photos of the packaging to add this product to our common database",
"@new_product_dialog_description": {
"description": "Please keep it short, like less than 100 characters. Explanatory text of the dialog when the user searched for an unknown barcode."
},
"front_packaging_photo_button_label": "Product front photo",
"@front_packaging_photo_button_label": {},
"confirm_front_packaging_photo_button_label": "Confirm upload of Product front photo",
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 @@ -487,6 +487,14 @@
"@add_product_information_button_label": {},
"new_product": "Nouveau produit",
"@new_product": {},
"new_product_dialog_title": "Vous avez trouvé un nouveau produit !",
"@new_product_dialog_title": {
"description": "Please keep it short, like 50 characters. Title of the dialog when the user searched for an unknown barcode."
},
"new_product_dialog_description": "Merci de prendre des photos pour ajouter ce produit à notre base de données commune.",
"@new_product_dialog_description": {
"description": "Please keep it short, like less than 100 characters. Explanatory text of the dialog when the user searched for an unknown barcode."
},
"front_packaging_photo_button_label": "Photo frontale du produit",
"@front_packaging_photo_button_label": {},
"confirm_front_packaging_photo_button_label": "Confirmer le téleversement de la photo frontale du produit",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,9 +235,7 @@ class UserPreferencesTitle extends StatelessWidget {
),
child: Text(
label,
style: Theme.of(context).textTheme.displaySmall?.copyWith(
height: 2.5,
),
style: Theme.of(context).textTheme.displayLarge,
),
),
);
Expand Down
37 changes: 37 additions & 0 deletions packages/smooth_app/lib/pages/product/add_packaging_button.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/product/common/product_refresher.dart';
import 'package:smooth_app/pages/product/edit_new_packagings.dart';
import 'package:smooth_app/pages/product/ocr_packaging_helper.dart';

/// "Add (new) packaging" button for user contribution.
class AddPackagingButton extends StatelessWidget {
const AddPackagingButton({
required this.product,
});

final Product product;

@override
Widget build(BuildContext context) => addPanelButton(
OcrPackagingHelper().getAddButtonLabel(AppLocalizations.of(context)),
onPressed: () async {
// ignore: use_build_context_synchronously
if (!await ProductRefresher().checkIfLoggedIn(context)) {
return;
}
// ignore: use_build_context_synchronously
await Navigator.push<void>(
context,
MaterialPageRoute<void>(
builder: (BuildContext context) => EditNewPackagings(
product: product,
),
fullscreenDialog: true,
),
);
},
);
}
Loading

0 comments on commit bfdce6d

Please sign in to comment.