From 4b8489d6e598db84ff0b15135a52a481ff06de6c Mon Sep 17 00:00:00 2001 From: monsieurtanuki Date: Fri, 25 Oct 2024 07:55:37 +0200 Subject: [PATCH] feat: 5428 - page dedicated to prices (#5730) * feat: 5428 - page dedicated to prices New file: * `prices_home_page.dart`: Home page of Prices Impacted file: * `user_preferences_account.dart`: replaced the whole prices items with a single item linking to new page `PricesHomePage` * minor fix * Moved to top page Prices and Donation New files: * `user_preferences_donation.dart`: Display of "Donation" for the preferences page. * `user_preferences_prices.dart`: Display of "Prices" for the preferences page. Deleted file: * `prices_home_page.dart` Impacted files: * `app_en.arb`: added a short label for "donation" * `user_preferences_account.dart`: removed link to `PricesHomePage` * `user_preferences_contribute.dart`: removed the "donation" item * `user_preferences_page.dart`: added "donation" and "prices" as preferences --- packages/smooth_app/lib/l10n/app_en.arb | 2 + .../preferences/user_preferences_account.dart | 108 ----------- .../user_preferences_contribute.dart | 10 - .../user_preferences_donation.dart | 42 +++++ .../preferences/user_preferences_page.dart | 20 ++ .../preferences/user_preferences_prices.dart | 174 ++++++++++++++++++ 6 files changed, 238 insertions(+), 118 deletions(-) create mode 100644 packages/smooth_app/lib/pages/preferences/user_preferences_donation.dart create mode 100644 packages/smooth_app/lib/pages/preferences/user_preferences_prices.dart diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 2887e976840..5381887348d 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -355,6 +355,8 @@ "@contribute_develop_text_2": {}, "contribute_develop_dev_mode_title": "DEV Mode?", "contribute_develop_dev_mode_subtitle": "Activate the DEV Mode", + "contribute_donate_title": "Donate", + "@contribute_donate_title": {}, "contribute_donate_header": "Donate to Open Food Facts", "@contribute_donate_header": {}, "contribute_enroll_alpha": "Enroll in internal alpha version", diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart index 8a951e8e08d..0548121d344 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_account.dart @@ -1,4 +1,3 @@ -import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:openfoodfacts/openfoodfacts.dart'; import 'package:provider/provider.dart'; @@ -17,12 +16,6 @@ import 'package:smooth_app/pages/preferences/lazy_counter_widget.dart'; import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart'; import 'package:smooth_app/pages/preferences/user_preferences_page.dart'; -import 'package:smooth_app/pages/prices/get_prices_model.dart'; -import 'package:smooth_app/pages/prices/price_user_button.dart'; -import 'package:smooth_app/pages/prices/prices_page.dart'; -import 'package:smooth_app/pages/prices/prices_proofs_page.dart'; -import 'package:smooth_app/pages/prices/prices_users_page.dart'; -import 'package:smooth_app/pages/prices/product_price_add_page.dart'; import 'package:smooth_app/pages/product/common/product_query_page_helper.dart'; import 'package:smooth_app/pages/user_management/login_page.dart'; import 'package:smooth_app/query/paged_product_query.dart'; @@ -217,92 +210,6 @@ class UserPreferencesAccount extends AbstractUserPreferences { lazyCounter: const LazyCounterUserSearch(UserSearchType.TO_BE_COMPLETED), ), - _getListTile( - PriceUserButton.showUserTitle( - user: ProductQuery.getWriteUser().userId, - context: context, - ), - () async => PriceUserButton.showUserPrices( - user: ProductQuery.getWriteUser().userId, - context: context, - ), - CupertinoIcons.money_dollar_circle, - lazyCounter: LazyCounterPrices(ProductQuery.getWriteUser().userId), - ), - _getListTile( - appLocalizations.user_search_proofs_title, - () async => Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) => const PricesProofsPage( - selectProof: false, - ), - ), - ), - Icons.receipt, - ), - _getListTile( - appLocalizations.prices_add_a_receipt, - () async => ProductPriceAddPage.showProductPage( - context: context, - proofType: ProofType.receipt, - ), - Icons.add_shopping_cart, - ), - _getListTile( - appLocalizations.prices_add_price_tags, - () async => ProductPriceAddPage.showProductPage( - context: context, - proofType: ProofType.priceTag, - ), - Icons.add_shopping_cart, - ), - _getListTile( - appLocalizations.all_search_prices_latest_title, - () async => Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) => PricesPage( - GetPricesModel( - parameters: GetPricesParameters() - ..orderBy = >[ - const OrderBy( - field: GetPricesOrderField.created, - ascending: false, - ), - ] - ..pageSize = GetPricesModel.pageSize - ..pageNumber = 1, - displayOwner: true, - displayProduct: true, - uri: OpenPricesAPIClient.getUri( - path: 'prices', - uriHelper: ProductQuery.uriPricesHelper, - ), - title: appLocalizations.all_search_prices_latest_title, - lazyCounterPrices: const LazyCounterPrices(null), - ), - ), - ), - ), - CupertinoIcons.money_dollar_circle, - lazyCounter: const LazyCounterPrices(null), - ), - _getListTile( - appLocalizations.all_search_prices_top_user_title, - () async => Navigator.of(context).push( - MaterialPageRoute( - builder: (BuildContext context) => const PricesUsersPage(), - ), - ), - Icons.account_box, - ), - _getPriceListTile( - appLocalizations.all_search_prices_top_location_title, - 'locations', - ), - _getPriceListTile( - appLocalizations.all_search_prices_top_product_title, - 'products', - ), _buildProductQueryTile( productQuery: PagedToBeCompletedProductQuery( productType: ProductType.food, @@ -356,21 +263,6 @@ class UserPreferencesAccount extends AbstractUserPreferences { ]; } - UserPreferencesItem _getPriceListTile( - final String title, - final String path, - ) => - _getListTile( - title, - () async => LaunchUrlHelper.launchURL( - OpenPricesAPIClient.getUri( - path: path, - uriHelper: ProductQuery.uriPricesHelper, - ).toString(), - ), - Icons.open_in_new, - ); - Future _confirmLogout() async => showDialog( context: context, builder: (BuildContext context) { diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart index d0e438e2c1c..f5478fe4ca7 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_contribute.dart @@ -94,16 +94,6 @@ class UserPreferencesContribute extends AbstractUserPreferences { () async => _share(appLocalizations.contribute_share_content), Icons.adaptive.share, ), - _getListTile( - appLocalizations.contribute_donate_header, - () async => LaunchUrlHelper.launchURL( - AppLocalizations.of(context).donate_url, - ), - Icons.volunteer_activism, - icon: - UserPreferencesListTile.getTintedIcon(Icons.open_in_new, context), - externalLink: true, - ), if (GlobalVars.appStore.getEnrollInBetaURL() != null) _getListTile( appLocalizations.contribute_enroll_alpha, diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_donation.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_donation.dart new file mode 100644 index 00000000000..92d580480f2 --- /dev/null +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_donation.dart @@ -0,0 +1,42 @@ +import 'package:flutter/material.dart'; +import 'package:smooth_app/helpers/launch_url_helper.dart'; +import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_page.dart'; + +/// Display of "Donation" for the preferences page. +class UserPreferencesDonation extends AbstractUserPreferences { + UserPreferencesDonation({ + required super.context, + required super.userPreferences, + required super.appLocalizations, + required super.themeData, + }); + + @override + PreferencePageType getPreferencePageType() => PreferencePageType.DONATION; + + @override + String getTitleString() => appLocalizations.contribute_donate_title; + + @override + String getSubtitleString() => appLocalizations.contribute_donate_header; + + @override + IconData getLeadingIconData() => Icons.volunteer_activism; + + @override + Icon? getForwardIcon() => UserPreferencesListTile.getTintedIcon( + Icons.open_in_new, + context, + ); + + @override + Future runHeaderAction() async => LaunchUrlHelper.launchURL( + appLocalizations.donate_url, + ); + + @override + List getChildren() => []; +} diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_page.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_page.dart index 17c6ab20c79..984a1de4481 100644 --- a/packages/smooth_app/lib/pages/preferences/user_preferences_page.dart +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_page.dart @@ -18,9 +18,11 @@ import 'package:smooth_app/pages/preferences/user_preferences_account.dart'; import 'package:smooth_app/pages/preferences/user_preferences_connect.dart'; import 'package:smooth_app/pages/preferences/user_preferences_contribute.dart'; import 'package:smooth_app/pages/preferences/user_preferences_dev_mode.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_donation.dart'; import 'package:smooth_app/pages/preferences/user_preferences_faq.dart'; import 'package:smooth_app/pages/preferences/user_preferences_food.dart'; import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_prices.dart'; import 'package:smooth_app/pages/preferences/user_preferences_settings.dart'; import 'package:smooth_app/pages/preferences/user_preferences_widgets.dart'; import 'package:smooth_app/themes/theme_provider.dart'; @@ -34,6 +36,8 @@ enum PreferencePageType { SETTINGS('settings'), CONTRIBUTE('contribute'), FAQ('faq'), + DONATION('donation'), + PRICES('prices'), CONNECT('connect'); const PreferencePageType(this.tag); @@ -101,6 +105,20 @@ enum PreferencePageType { appLocalizations: appLocalizations, themeData: themeData, ); + case PreferencePageType.DONATION: + return UserPreferencesDonation( + context: context, + userPreferences: userPreferences, + appLocalizations: appLocalizations, + themeData: themeData, + ); + case PreferencePageType.PRICES: + return UserPreferencesPrices( + context: context, + userPreferences: userPreferences, + appLocalizations: appLocalizations, + themeData: themeData, + ); case PreferencePageType.CONNECT: return UserPreferencesConnect( context: context, @@ -117,6 +135,8 @@ enum PreferencePageType { [ PreferencePageType.ACCOUNT, PreferencePageType.FOOD, + PreferencePageType.PRICES, + PreferencePageType.DONATION, PreferencePageType.SETTINGS, PreferencePageType.CONTRIBUTE, PreferencePageType.FAQ, diff --git a/packages/smooth_app/lib/pages/preferences/user_preferences_prices.dart b/packages/smooth_app/lib/pages/preferences/user_preferences_prices.dart new file mode 100644 index 00000000000..80178b7383d --- /dev/null +++ b/packages/smooth_app/lib/pages/preferences/user_preferences_prices.dart @@ -0,0 +1,174 @@ +import 'package:flutter/cupertino.dart'; +import 'package:flutter/material.dart'; +import 'package:openfoodfacts/openfoodfacts.dart'; +import 'package:smooth_app/helpers/launch_url_helper.dart'; +import 'package:smooth_app/pages/preferences/abstract_user_preferences.dart'; +import 'package:smooth_app/pages/preferences/lazy_counter.dart'; +import 'package:smooth_app/pages/preferences/lazy_counter_widget.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_item.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart'; +import 'package:smooth_app/pages/preferences/user_preferences_page.dart'; +import 'package:smooth_app/pages/prices/get_prices_model.dart'; +import 'package:smooth_app/pages/prices/price_user_button.dart'; +import 'package:smooth_app/pages/prices/prices_page.dart'; +import 'package:smooth_app/pages/prices/prices_proofs_page.dart'; +import 'package:smooth_app/pages/prices/prices_users_page.dart'; +import 'package:smooth_app/pages/prices/product_price_add_page.dart'; +import 'package:smooth_app/query/product_query.dart'; + +/// Display of "Prices" for the preferences page. +class UserPreferencesPrices extends AbstractUserPreferences { + UserPreferencesPrices({ + required super.context, + required super.userPreferences, + required super.appLocalizations, + required super.themeData, + }); + + @override + PreferencePageType getPreferencePageType() => PreferencePageType.PRICES; + + @override + String getTitleString() => appLocalizations.prices_generic_title; + + @override + IconData getLeadingIconData() => CupertinoIcons.money_dollar_circle; + + @override + List getChildren() { + final String userId = ProductQuery.getWriteUser().userId; + final bool isConnected = OpenFoodAPIConfiguration.globalUser != null; + return [ + if (isConnected) + _getListTile( + PriceUserButton.showUserTitle( + user: userId, + context: context, + ), + () async => PriceUserButton.showUserPrices( + user: userId, + context: context, + ), + CupertinoIcons.money_dollar_circle, + lazyCounter: LazyCounterPrices(userId), + ), + if (isConnected) + _getListTile( + appLocalizations.user_search_proofs_title, + () async => Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => const PricesProofsPage( + selectProof: false, + ), + ), + ), + Icons.receipt, + ), + _getListTile( + appLocalizations.prices_add_a_receipt, + () async => ProductPriceAddPage.showProductPage( + context: context, + proofType: ProofType.receipt, + ), + Icons.add_shopping_cart, + ), + _getListTile( + appLocalizations.prices_add_price_tags, + () async => ProductPriceAddPage.showProductPage( + context: context, + proofType: ProofType.priceTag, + ), + Icons.add_shopping_cart, + ), + _getListTile( + appLocalizations.all_search_prices_latest_title, + () async => Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => PricesPage( + GetPricesModel( + parameters: GetPricesParameters() + ..orderBy = >[ + const OrderBy( + field: GetPricesOrderField.created, + ascending: false, + ), + ] + ..pageSize = GetPricesModel.pageSize + ..pageNumber = 1, + displayOwner: true, + displayProduct: true, + uri: OpenPricesAPIClient.getUri( + path: 'prices', + uriHelper: ProductQuery.uriPricesHelper, + ), + title: appLocalizations.all_search_prices_latest_title, + lazyCounterPrices: const LazyCounterPrices(null), + ), + ), + ), + ), + CupertinoIcons.money_dollar_circle, + lazyCounter: const LazyCounterPrices(null), + ), + _getListTile( + appLocalizations.all_search_prices_top_user_title, + () async => Navigator.of(context).push( + MaterialPageRoute( + builder: (BuildContext context) => const PricesUsersPage(), + ), + ), + Icons.account_box, + ), + _getPriceListTile( + appLocalizations.all_search_prices_top_location_title, + 'locations', + ), + _getPriceListTile( + appLocalizations.all_search_prices_top_product_title, + 'products', + ), + ]; + } + + UserPreferencesItem _getPriceListTile( + final String title, + final String path, + ) => + _getListTile( + title, + () async => LaunchUrlHelper.launchURL( + OpenPricesAPIClient.getUri( + path: path, + uriHelper: ProductQuery.uriPricesHelper, + ).toString(), + ), + Icons.open_in_new, + ); + + UserPreferencesItem _getListTile( + final String title, + final VoidCallback onTap, + final IconData leading, { + final LazyCounter? lazyCounter, + }) => + UserPreferencesItemSimple( + labels: [title], + builder: (_) => Card( + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15), + ), + elevation: 5, + color: Theme.of(context).cardColor, + child: UserPreferencesListTile( + title: Text(title), + onTap: onTap, + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(15), + ), + leading: UserPreferencesListTile.getTintedIcon(leading, context), + trailing: + lazyCounter == null ? null : LazyCounterWidget(lazyCounter), + ), + ), + ); +}