Skip to content

Commit

Permalink
Merge branch 'develop' into fix/6041
Browse files Browse the repository at this point in the history
  • Loading branch information
monsieurtanuki authored Dec 16, 2024
2 parents 064e0f5 + 6ab0079 commit f01e5ed
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/crowdin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
uses: actions/checkout@v4

- name: crowdin action
uses: crowdin/github-action@v2.4.0
uses: crowdin/github-action@v2.5.0
continue-on-error: true
with:
# Upload sources to Crowdin
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# Changelog

## [4.17.1](https://github.com/openfoodfacts/smooth-app/compare/v4.17.0...v4.17.1) (2024-12-12)


### Features

* 6001 - cached impact-co2.svg ([#6005](https://github.com/openfoodfacts/smooth-app/issues/6005)) ([3e7468a](https://github.com/openfoodfacts/smooth-app/commit/3e7468ac4592cc716ac787ea2d5b546ec30efdbd))
* 6025 - settings for the folksonomy server ([#6027](https://github.com/openfoodfacts/smooth-app/issues/6027)) ([736f08c](https://github.com/openfoodfacts/smooth-app/commit/736f08c8ac41fac5f33b62d666eb6e19413dabe0))


### Bug Fixes

* Improvements for small screens ([#6036](https://github.com/openfoodfacts/smooth-app/issues/6036)) ([43fe60a](https://github.com/openfoodfacts/smooth-app/commit/43fe60afbd75539924ae2b0ee3c840cb63f2dd3a))


### Miscellaneous Chores

* release 4.17.1 ([ddbdb29](https://github.com/openfoodfacts/smooth-app/commit/ddbdb2927217488167bdf08d8f88a546939156a8))

## [4.17.0](https://github.com/openfoodfacts/smooth-app/compare/v4.16.0...v4.17.0) (2024-12-04)


Expand Down
27 changes: 18 additions & 9 deletions packages/smooth_app/lib/cards/category_cards/svg_safe_network.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,16 +136,25 @@ class _SvgSafeNetworkState extends State<SvgSafeNetwork> {
}
}
if (snapshot.error != null) {
if (snapshot.error.toString().contains("Failed host lookup: '")) {
Logs.w(
'Failed host lookup for "$_url"',
ex: snapshot.error,
);
} else if (snapshot.error
.toString()
.contains('Connection timed out')) {
String? findWarningLabel() {
const List<String> warningLabels = <String>[
'Failed host lookup',
'Connection timed out',
'Connection reset by peer',
];
final String error = snapshot.error.toString();
for (final String warningLabel in warningLabels) {
if (error.contains(warningLabel)) {
return warningLabel;
}
}
return null;
}

final String? warningLabel = findWarningLabel();
if (warningLabel != null) {
Logs.w(
'Connection timed out for "$_url"',
'$warningLabel for "$_url"',
ex: snapshot.error,
);
} else {
Expand Down
78 changes: 64 additions & 14 deletions packages/smooth_app/lib/pages/prices/prices_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import 'package:smooth_app/pages/prices/get_prices_model.dart';
import 'package:smooth_app/pages/prices/price_meta_product.dart';
import 'package:smooth_app/pages/prices/prices_page.dart';
import 'package:smooth_app/pages/prices/product_price_add_page.dart';
import 'package:smooth_app/query/product_query.dart';
import 'package:smooth_app/resources/app_icons.dart' as icons;
import 'package:smooth_app/themes/smooth_theme_colors.dart';
import 'package:smooth_app/themes/theme_provider.dart';
Expand Down Expand Up @@ -71,20 +72,7 @@ class PricesCard extends StatelessWidget {
children: <Widget>[
Padding(
padding: const EdgeInsets.symmetric(horizontal: SMALL_SPACE),
child: SmoothLargeButtonWithIcon(
text: appLocalizations.prices_view_prices,
icon: CupertinoIcons.tag_fill,
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => PricesPage(
GetPricesModel.product(
product: PriceMetaProduct.product(product),
context: context,
),
),
),
),
),
child: _PricesCardViewButton(product),
),
Padding(
padding: const EdgeInsets.all(SMALL_SPACE),
Expand Down Expand Up @@ -130,3 +118,65 @@ class _PricesCardTitleIcon extends StatelessWidget {
);
}
}

class _PricesCardViewButton extends StatefulWidget {
const _PricesCardViewButton(this.product);

final Product product;

@override
State<_PricesCardViewButton> createState() => _PricesCardViewButtonState();
}

class _PricesCardViewButtonState extends State<_PricesCardViewButton> {
late final GetPricesModel _model;
late final Future<MaybeError<GetPricesResult>> _prices = _showProductPrices();

@override
Widget build(BuildContext context) =>
FutureBuilder<MaybeError<GetPricesResult>>(
future: _prices,
builder: (
final BuildContext context,
final AsyncSnapshot<MaybeError<GetPricesResult>> snapshot,
) {
final AppLocalizations appLocalizations =
AppLocalizations.of(context);
GetPricesResult? pricesResult;
if (snapshot.hasData && !snapshot.data!.isError) {
pricesResult = snapshot.data!.value;
}
return Badge(
isLabelVisible: pricesResult?.total != null,
backgroundColor: Colors.blue.shade900,
label: Text(
'${pricesResult?.total}',
style: const TextStyle(color: Colors.white),
),
child: SmoothLargeButtonWithIcon(
text: appLocalizations.prices_view_prices,
icon: CupertinoIcons.tag_fill,
onPressed: () async => Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (BuildContext context) => PricesPage(
_model,
pricesResult: pricesResult,
),
),
),
),
);
},
);

Future<MaybeError<GetPricesResult>> _showProductPrices() async {
_model = GetPricesModel.product(
product: PriceMetaProduct.product(widget.product),
context: context,
);
return OpenPricesAPIClient.getPrices(
_model.parameters,
uriHelper: ProductQuery.uriPricesHelper,
);
}
}
12 changes: 10 additions & 2 deletions packages/smooth_app/lib/pages/prices/prices_page.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:auto_size_text/auto_size_text.dart';
import 'package:flutter/material.dart';
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
import 'package:smooth_app/data_models/preferences/user_preferences.dart';
import 'package:smooth_app/generic_lib/design_constants.dart';
Expand All @@ -16,9 +17,13 @@ import 'package:smooth_app/widgets/smooth_scaffold.dart';

/// Page that displays the latest prices according to a model.
class PricesPage extends StatelessWidget {
const PricesPage(this.model);
const PricesPage(
this.model, {
this.pricesResult,
});

final GetPricesModel model;
final GetPricesResult? pricesResult;

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -47,7 +52,10 @@ class PricesPage extends StatelessWidget {
),
],
),
body: ProductPricesList(model),
body: ProductPricesList(
model,
pricesResult: pricesResult,
),
floatingActionButton: model.addButton == null
? null
: FloatingActionButton.extended(
Expand Down
25 changes: 14 additions & 11 deletions packages/smooth_app/lib/pages/prices/product_prices_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,20 @@ import 'package:smooth_app/query/product_query.dart';
/// List of the latest prices for a given model.
class ProductPricesList extends StatefulWidget {
const ProductPricesList(
this.model,
);
this.model, {
this.pricesResult,
});

final GetPricesModel model;
final GetPricesResult? pricesResult;

@override
State<ProductPricesList> createState() => _ProductPricesListState();
}

class _ProductPricesListState extends State<ProductPricesList>
with TraceableClientMixin {
late final Future<MaybeError<GetPricesResult>> _prices =
_showProductPrices(widget.model.parameters);
late final Future<MaybeError<GetPricesResult>> _prices = _showProductPrices();

// TODO(monsieurtanuki): add a refresh gesture
// TODO(monsieurtanuki): add a "download the next 10" items
Expand Down Expand Up @@ -135,11 +136,13 @@ class _ProductPricesListState extends State<ProductPricesList>
},
);

static Future<MaybeError<GetPricesResult>> _showProductPrices(
final GetPricesParameters parameters,
) async =>
OpenPricesAPIClient.getPrices(
parameters,
uriHelper: ProductQuery.uriPricesHelper,
);
Future<MaybeError<GetPricesResult>> _showProductPrices() async {
if (widget.pricesResult != null) {
return MaybeError<GetPricesResult>.value(widget.pricesResult!);
}
return OpenPricesAPIClient.getPrices(
widget.model.parameters,
uriHelper: ProductQuery.uriPricesHelper,
);
}
}
2 changes: 1 addition & 1 deletion version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.17.0
4.17.1

0 comments on commit f01e5ed

Please sign in to comment.