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

feat: Less annoying floating spam #6190

Merged
merged 4 commits into from
Jan 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/background/background_task.dart
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ abstract class BackgroundTask {
final String message,
final AlignmentGeometry alignment,
)) {
SmoothFloatingMessage(message: message).show(
SmoothFloatingMessage.loading(message: message).show(
context,
duration: SnackBarDuration.medium,
alignment: alignment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,7 @@ class BackgroundTaskDetails extends BackgroundTaskBarcode
@override
(String, AlignmentGeometry)? getFloatingMessage(
final AppLocalizations appLocalizations) =>
(
appLocalizations.product_task_background_schedule,
AlignmentDirectional.center,
);
null;

/// Returns a new background task about changing a product.
static BackgroundTaskDetails _getNewTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ class BackgroundTaskImage extends BackgroundTaskUpload {
@override
(String, AlignmentGeometry)? getFloatingMessage(
final AppLocalizations appLocalizations) =>
(
appLocalizations.image_upload_queued,
AlignmentDirectional.center,
);
null;

/// Returns a new background task about changing a product.
static BackgroundTaskImage _getNewTask(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ abstract class BackgroundTaskPrice extends BackgroundTask {
final AppLocalizations appLocalizations) =>
(
appLocalizations.add_price_queued,
AlignmentDirectional.center,
AlignmentDirectional.bottomCenter,
);

@protected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class BackgroundTaskUnselect extends BackgroundTaskBarcode
final AppLocalizations appLocalizations) =>
(
appLocalizations.product_task_background_schedule,
AlignmentDirectional.topCenter,
AlignmentDirectional.bottomCenter,
);

/// Returns a new background task about unselecting a product image.
Expand Down
21 changes: 18 additions & 3 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,14 @@
"@edit_product_label": {
"description": "Edit product button label"
},
"edit_product_pending_operations_banner_title": "Uploading your edits…",
"@edit_product_pending_operations_banner_title": {
"description": "When a product has pending edits (being sent to the server), there is a message on the edit page (here is the title of the message)."
},
"edit_product_pending_operations_banner_message": "Your edits are being **sent in the background** (or later in case of error).\nYou can continue editing other product fields.",
"@edit_product_pending_operations_banner_message": {
"description": "When a product has pending edits (being sent to the server), there is a message on the edit page. Please keep the ** syntax to make the text bold."
},
"edit_product_label_short": "Edit",
"@edit_product_label_short": {
"description": "Edit product button short label (only the verb)"
Expand Down Expand Up @@ -3550,7 +3558,14 @@
"knowledge_panel_nutriscore_banner_incorrect_score_title": "Why is this Nutri-Score different from the one on the package?",
"knowledge_panel_nutriscore_banner_incorrect_score_message": "There are two possible explanations:\nThe list of ingredients and/or nutrition facts are not up-to-date.\n\nWe provide the \"New calculation\" of the Nutri-Score (or V2). Please check that you have the banner \"New calculation\" on the package.",
"knowledge_panel_nutriscore_banner_incorrect_score_button1": "Check ingredients",
"knowledge_panel_nutriscore_banner_incorrect_score_button2": "Check nutrition facts"


"knowledge_panel_nutriscore_banner_incorrect_score_button2": "Check nutrition facts",
"url_not_supported": "Unfortunately, we can't open the URL:\n{url}",
"@url_not_supported": {
"description": "Error message when the app can't open a URL",
"placeholders": {
"url": {
"type": "String"
}
}
}
}
21 changes: 19 additions & 2 deletions packages/smooth_app/lib/l10n/app_fr.arb
Original file line number Diff line number Diff line change
Expand Up @@ -1398,6 +1398,14 @@
"@edit_product_label": {
"description": "Edit product button label"
},
"edit_product_pending_operations_banner_title": "Envoi de vos modifications…",
"@edit_product_pending_operations_banner_title": {
"description": "When a product has pending edits (being sent to the server), there is a message on the edit page (here is the title of the message)."
},
"edit_product_pending_operations_banner_message": "Vos modifications sont en cours d'envoi en **arrière-plan** (ou plus tard en cas d'erreur).\nVous pouvez continuer d'éditer d'autres champs du produit.",
"@edit_product_pending_operations_banner_message": {
"description": "When a product has pending edits (being sent to the server), there is a message on the edit page. Please keep the ** syntax to make the text bold."
},
"edit_product_label_short": "Modifier",
"@edit_product_label_short": {
"description": "Edit product button short label (only the verb)"
Expand Down Expand Up @@ -3433,7 +3441,7 @@
"@product_page_action_bar_item_disable": {
"description": "Accessibility label to disable action (= make it invisible)"
},
"product_page_pending_operations_banner_title": "Téléversement de vos modifications…",
"product_page_pending_operations_banner_title": "Envoi de vos modifications…",
"@product_page_pending_operations_banner_title": {
"description": "When a product has pending edits (being sent to the server), there is a message on the product page (here is the title of the message)."
},
Expand Down Expand Up @@ -3556,5 +3564,14 @@
"knowledge_panel_nutriscore_banner_incorrect_score_title": "Pourquoi ce Nutri-Score est-il différent de celui présent sur l'emballage ?",
"knowledge_panel_nutriscore_banner_incorrect_score_message": "Il y a deux explications possibles :\nLa liste des ingrédients et/ou le tableau nutritionnel ne sont pas à jour.\n\nNous affichons le \"Nouveau calcul\" du Nutri-Score (ou V2). Vérifiez que le libellé \"Nouveau calcul\" est bien sur l'emballage.",
"knowledge_panel_nutriscore_banner_incorrect_score_button1": "Vérifier les ingredients",
"knowledge_panel_nutriscore_banner_incorrect_score_button2": "Vérifier le tableau nutritionnel"
"knowledge_panel_nutriscore_banner_incorrect_score_button2": "Vérifier le tableau nutritionnel",
"url_not_supported": "Malheureusement, nous ne pouvez pas ouvrir l'adresse :\n{url}",
"@url_not_supported": {
"description": "Error message when the app can't open a URL",
"placeholders": {
"url": {
"type": "String"
}
}
}
}
2 changes: 1 addition & 1 deletion packages/smooth_app/lib/pages/navigator/app_navigator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ class AppRoutes {

static String get SIGNUP => '/${_InternalAppRoutes.SIGNUP_PAGE}';

// Open an external link (where path is relative to the OFF website)
// Open an external link
static String EXTERNAL(String path) =>
'/${_InternalAppRoutes.EXTERNAL_PAGE}?path=${Uri.encodeFull(path)}';
}
65 changes: 44 additions & 21 deletions packages/smooth_app/lib/pages/navigator/external_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_custom_tabs/flutter_custom_tabs.dart' as tabs;
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:go_router/go_router.dart';
import 'package:http/http.dart' as http;
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:path/path.dart' as path;
import 'package:smooth_app/generic_lib/duration_constants.dart';
import 'package:smooth_app/helpers/launch_url_helper.dart';
import 'package:smooth_app/pages/navigator/app_navigator.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/services/smooth_services.dart';
import 'package:smooth_app/widgets/smooth_floating_message.dart';
import 'package:url_launcher/url_launcher.dart';

/// This screen is only used for deep links!
Expand Down Expand Up @@ -37,32 +40,37 @@ class _ExternalPageState extends State<ExternalPage> {
super.initState();

WidgetsBinding.instance.addPostFrameCallback((_) async {
// First let's try with https://{country}.openfoodfacts.org
final OpenFoodFactsCountry country = ProductQuery.getCountry();
try {
String? url;

String? url;
url = path.join(
'https://${country.offTag}.openfoodfacts.org',
widget.path,
);
if (widget.path.startsWith('http')) {
url = widget.path;
} else {
// First let's try with https://{country}.openfoodfacts.org
final OpenFoodFactsCountry country = ProductQuery.getCountry();

if (await _testUrl(url)) {
url = null;
}
url = path.join(
'https://${country.offTag}.openfoodfacts.org',
widget.path,
);

// If that's not OK, let's try with world.openfoodfacts.org?lc={language}
if (url == null) {
final OpenFoodFactsLanguage language = ProductQuery.getLanguage();
if (await _testUrl(url)) {
url = null;
}

url = path.join(
'https://world.openfoodfacts.org',
widget.path,
);
// If that's not OK, let's try with world.openfoodfacts.org?lc={language}
if (url == null) {
final OpenFoodFactsLanguage language = ProductQuery.getLanguage();

url = '$url?lc=${language.offTag}';
}
url = path.join(
'https://world.openfoodfacts.org',
widget.path,
);

url = '$url?lc=${language.offTag}';
}
}

try {
if (Platform.isAndroid) {
/// Custom tabs
WidgetsFlutterBinding.ensureInitialized();
Expand All @@ -81,6 +89,17 @@ class _ExternalPageState extends State<ExternalPage> {
}
} catch (e) {
Logs.e('Unable to open an external link', ex: e);
if (mounted) {
SmoothFloatingMessage(
message:
AppLocalizations.of(context).url_not_supported(widget.path),
type: SmoothFloatingMessageType.error,
).show(
context,
duration: SnackBarDuration.long,
alignment: Alignment.bottomCenter,
);
}
} finally {
if (mounted) {
final bool success = AppNavigator.of(context).pop();
Expand All @@ -96,7 +115,11 @@ class _ExternalPageState extends State<ExternalPage> {

@override
Widget build(BuildContext context) {
return const Scaffold();
return const Scaffold(
body: Center(
child: CircularProgressIndicator.adaptive(),
),
);
}

/// Check if an URL exist
Expand Down
53 changes: 45 additions & 8 deletions packages/smooth_app/lib/pages/product/edit_product_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:smooth_app/generic_lib/design_constants.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_back_button.dart';
import 'package:smooth_app/generic_lib/widgets/smooth_list_tile_card.dart';
import 'package:smooth_app/helpers/analytics_helper.dart';
import 'package:smooth_app/helpers/color_extension.dart';
import 'package:smooth_app/helpers/product_cards_helper.dart';
import 'package:smooth_app/pages/navigator/app_navigator.dart';
import 'package:smooth_app/pages/onboarding/currency_selector_helper.dart';
Expand All @@ -22,15 +23,17 @@ import 'package:smooth_app/pages/product/edit_product_barcode.dart';
import 'package:smooth_app/pages/product/gallery_view/product_image_gallery_view.dart';
import 'package:smooth_app/pages/product/nutrition_page_loaded.dart';
import 'package:smooth_app/pages/product/product_field_editor.dart';
import 'package:smooth_app/pages/product/product_page/new_product_page_loading_indicator.dart';
import 'package:smooth_app/pages/product/product_type_extensions.dart';
import 'package:smooth_app/pages/product/simple_input_page.dart';
import 'package:smooth_app/pages/product/simple_input_page_helpers.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/resources/app_animations.dart';
import 'package:smooth_app/resources/app_icons.dart' as icons;
import 'package:smooth_app/themes/smooth_theme.dart';
import 'package:smooth_app/themes/smooth_theme_colors.dart';
import 'package:smooth_app/themes/theme_provider.dart';
import 'package:smooth_app/widgets/smooth_app_bar.dart';
import 'package:smooth_app/widgets/smooth_banner.dart';
import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Page where we can indirectly edit all data about a product.
Expand Down Expand Up @@ -69,6 +72,9 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
final String productBrand =
getProductBrands(upToDateProduct, appLocalizations);

final bool hasUploadIndicator = UpToDateChanges(localDatabase)
.hasNotTerminatedOperations(upToDateProduct.barcode!);

return SmoothScaffold(
backgroundColor: lightTheme
? theme.extension<SmoothColorsThemeExtension>()!.primaryLight
Expand Down Expand Up @@ -147,7 +153,10 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
top: SMALL_SPACE,
start: MEDIUM_SPACE,
end: MEDIUM_SPACE,
bottom: MEDIUM_SPACE + MediaQuery.viewPaddingOf(context).bottom,
bottom: MEDIUM_SPACE +
(!hasUploadIndicator
? MediaQuery.viewPaddingOf(context).bottom
: 0.0),
),
controller: _controller,
children: <Widget>[
Expand Down Expand Up @@ -308,12 +317,8 @@ class _EditProductPageState extends State<EditProductPage> with UpToDateMixin {
),
),
),
bottomNavigationBar: UpToDateChanges(localDatabase)
.hasNotTerminatedOperations(upToDateProduct.barcode!)
? const ProductPageLoadingIndicator(
addSafeArea: true,
)
: null,
bottomNavigationBar:
hasUploadIndicator ? const _EditPageLoadingIndicator() : null,
);
}

Expand Down Expand Up @@ -408,3 +413,35 @@ class _ListTitleItem extends SmoothListTileCard {
),
);
}

class _EditPageLoadingIndicator extends StatelessWidget {
const _EditPageLoadingIndicator();

@override
Widget build(BuildContext context) {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final SmoothColorsThemeExtension extension =
context.extension<SmoothColorsThemeExtension>();

final bool lightTheme = context.lightTheme();

return SmoothBanner(
icon: CloudUploadAnimation(
size: MediaQuery.sizeOf(context).width * 0.10,
),
iconAlignment: AlignmentDirectional.center,
iconBackgroundColor: lightTheme ? extension.primaryBlack : Colors.black,
title: appLocalizations.edit_product_pending_operations_banner_title,
titleColor: lightTheme ? null : Colors.white,
titleBackgroundColor:
lightTheme ? extension.primaryMedium : Colors.black26,
contentBackgroundColor: lightTheme
? extension.primaryMedium.lighten()
: extension.primaryUltraBlack,
contentColor: lightTheme ? null : Colors.grey[200],
topShadow: true,
content: appLocalizations.edit_product_pending_operations_banner_message,
addSafeArea: true,
);
}
}
Loading
Loading