Skip to content

Commit

Permalink
feat: 5428 - page dedicated to prices (#5730)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
monsieurtanuki authored Oct 25, 2024
1 parent 3fde3e6 commit 4b8489d
Show file tree
Hide file tree
Showing 6 changed files with 238 additions and 118 deletions.
2 changes: 2 additions & 0 deletions packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:openfoodfacts/openfoodfacts.dart';
import 'package:provider/provider.dart';
Expand All @@ -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';
Expand Down Expand Up @@ -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<void>(
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<void>(
builder: (BuildContext context) => PricesPage(
GetPricesModel(
parameters: GetPricesParameters()
..orderBy = <OrderBy<GetPricesOrderField>>[
const OrderBy<GetPricesOrderField>(
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<void>(
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,
Expand Down Expand Up @@ -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<bool?> _confirmLogout() async => showDialog<bool>(
context: context,
builder: (BuildContext context) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
@@ -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<void> runHeaderAction() async => LaunchUrlHelper.launchURL(
appLocalizations.donate_url,
);

@override
List<UserPreferencesItem> getChildren() => <UserPreferencesItem>[];
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -34,6 +36,8 @@ enum PreferencePageType {
SETTINGS('settings'),
CONTRIBUTE('contribute'),
FAQ('faq'),
DONATION('donation'),
PRICES('prices'),
CONNECT('connect');

const PreferencePageType(this.tag);
Expand Down Expand Up @@ -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,
Expand All @@ -117,6 +135,8 @@ enum PreferencePageType {
<PreferencePageType>[
PreferencePageType.ACCOUNT,
PreferencePageType.FOOD,
PreferencePageType.PRICES,
PreferencePageType.DONATION,
PreferencePageType.SETTINGS,
PreferencePageType.CONTRIBUTE,
PreferencePageType.FAQ,
Expand Down
Loading

0 comments on commit 4b8489d

Please sign in to comment.