diff --git a/packages/smooth_app/lib/l10n/app_en.arb b/packages/smooth_app/lib/l10n/app_en.arb index 864d25ddbc0..76490e006cd 100644 --- a/packages/smooth_app/lib/l10n/app_en.arb +++ b/packages/smooth_app/lib/l10n/app_en.arb @@ -774,7 +774,11 @@ "recently_seen_products": "History", "clear": "Clear", "@clear": { - "description": "Clears a product list" + "description": "Clears a product list (short label)" + }, + "clear_long": "Empty the list", + "@clear_long": { + "description": "Clears a product list (long label)" }, "really_clear": "Do you really want to delete this list?", "@Plural": {}, diff --git a/packages/smooth_app/lib/l10n/app_fr.arb b/packages/smooth_app/lib/l10n/app_fr.arb index 4f2800604bd..5505d901f57 100644 --- a/packages/smooth_app/lib/l10n/app_fr.arb +++ b/packages/smooth_app/lib/l10n/app_fr.arb @@ -776,6 +776,10 @@ "@clear": { "description": "Clears a product list" }, + "clear_long": "Vider la liste", + "@clear_long": { + "description": "Clears a product list (long label)" + }, "really_clear": "Voulez-vous vraiment supprimer cette liste ?", "@Plural": {}, "pct_match": "{percent}% de correspondance", diff --git a/packages/smooth_app/lib/pages/all_product_list_page.dart b/packages/smooth_app/lib/pages/all_product_list_page.dart index e0ee8ff1fa3..da18d9e0cc7 100644 --- a/packages/smooth_app/lib/pages/all_product_list_page.dart +++ b/packages/smooth_app/lib/pages/all_product_list_page.dart @@ -8,7 +8,6 @@ import 'package:smooth_app/generic_lib/design_constants.dart'; import 'package:smooth_app/pages/preferences/user_preferences_list_tile.dart'; import 'package:smooth_app/pages/product/common/product_list_popup_items.dart'; import 'package:smooth_app/pages/product/common/product_query_page_helper.dart'; -import 'package:smooth_app/pages/product_list_user_dialog_helper.dart'; /// Page that lists all product lists. class AllProductListModal extends StatelessWidget { @@ -18,7 +17,7 @@ class AllProductListModal extends StatelessWidget { final ProductList currentList; - final List hardcodedProductLists = [ + final List _hardcodedProductLists = [ ProductList.scanSession(), ProductList.scanHistory(), ProductList.history(), @@ -31,7 +30,7 @@ class AllProductListModal extends StatelessWidget { final List userLists = daoProductList.getUserLists(); final List productLists = - List.from(hardcodedProductLists); + List.from(_hardcodedProductLists); for (final String userList in userLists) { productLists.add(ProductList.user(userList)); } @@ -62,39 +61,42 @@ class AllProductListModal extends StatelessWidget { subtitle: Text( appLocalizations.user_list_length(productsLength), ), - trailing: PopupMenuButton( + trailing: PopupMenuButton( itemBuilder: (BuildContext context) { - return >[ - _shareMenu( - appLocalizations, - daoProductList, - localDatabase, - context, - productList, - ), - _openInWebMenu( - appLocalizations, - daoProductList, - localDatabase, - context, - productList, - ), - if (productsLength > 0) - _clearListMenu( - appLocalizations, - daoProductList, - localDatabase, - context, - productList, - ), - if (productList.isEditable) - _deleteListMenu( - appLocalizations, - daoProductList, - context, - productList, - ), + final bool enableRename = + productList.listType == ProductListType.USER; + final List list = + [ + if (enableRename) ProductListPopupRename(), + ProductListPopupShare(), + ProductListPopupOpenInWeb(), + if (productsLength > 0) ProductListPopupClear(), + if (productList.isEditable) ProductListPopupDelete(), ]; + final List> + result = + >[]; + for (final ProductListPopupItem item in list) { + result.add( + PopupMenuItem( + value: item.getEntry(), + child: ListTile( + leading: Icon(item.getIconData()), + title: Text(item.getTitle(appLocalizations)), + contentPadding: EdgeInsets.zero, + onTap: () async { + Navigator.of(context).pop(); + await item.doSomething( + productList: productList, + localDatabase: localDatabase, + context: context, + ); + }, + ), + ), + ); + } + return result; }, icon: const Icon(Icons.more_vert), ), @@ -119,112 +121,4 @@ class AllProductListModal extends StatelessWidget { ), ); } - - PopupMenuItem _shareMenu( - AppLocalizations appLocalizations, - DaoProductList daoProductList, - LocalDatabase localDatabase, - BuildContext context, - ProductList productList, - ) { - final ProductListPopupShare popupShare = ProductListPopupShare(); - return PopupMenuItem( - value: PopupMenuEntries.shareList, - child: ListTile( - leading: const Icon(Icons.share), - title: Text(popupShare.getTitle(appLocalizations)), - contentPadding: EdgeInsets.zero, - onTap: () { - Navigator.of(context).pop(); - popupShare.doSomething( - productList: productList, - localDatabase: localDatabase, - context: context, - ); - }, - ), - ); - } - - PopupMenuItem _openInWebMenu( - AppLocalizations appLocalizations, - DaoProductList daoProductList, - LocalDatabase localDatabase, - BuildContext context, - ProductList productList, - ) { - final ProductListPopupOpenInWeb webItem = ProductListPopupOpenInWeb(); - return PopupMenuItem( - value: PopupMenuEntries.openListInBrowser, - child: ListTile( - leading: const Icon(Icons.public), - title: Text(webItem.getTitle(appLocalizations)), - contentPadding: EdgeInsets.zero, - onTap: () { - Navigator.of(context).pop(); - webItem.doSomething( - productList: productList, - localDatabase: localDatabase, - context: context, - ); - }, - ), - ); - } - - PopupMenuItem _clearListMenu( - AppLocalizations appLocalizations, - DaoProductList daoProductList, - LocalDatabase localDatabase, - BuildContext context, - ProductList productList, - ) { - final ProductListPopupClear clearItem = ProductListPopupClear(); - return PopupMenuItem( - value: PopupMenuEntries.clearList, - child: ListTile( - leading: const Icon(Icons.delete_sweep), - title: Text(clearItem.getTitle(appLocalizations)), - contentPadding: EdgeInsets.zero, - onTap: () async { - Navigator.of(context).pop(); - - clearItem.doSomething( - productList: productList, - localDatabase: localDatabase, - context: context, - ); - }, - ), - ); - } - - PopupMenuItem _deleteListMenu( - AppLocalizations appLocalizations, - DaoProductList daoProductList, - BuildContext context, - ProductList productList, - ) { - return PopupMenuItem( - value: PopupMenuEntries.deleteList, - child: ListTile( - leading: const Icon(Icons.delete), - title: Text(appLocalizations.action_delete_list), - contentPadding: EdgeInsets.zero, - ), - onTap: () { - WidgetsBinding.instance.addPostFrameCallback((_) { - ProductListUserDialogHelper(daoProductList) - .showDeleteUserListDialog(context, productList); - }); - }); - } -} - -enum PopupMenuEntries { - shareList, - openListInBrowser, - renameList, - clearList, - deleteList, } diff --git a/packages/smooth_app/lib/pages/product/common/product_list_popup_items.dart b/packages/smooth_app/lib/pages/product/common/product_list_popup_items.dart index 651858440b4..637cd83b400 100644 --- a/packages/smooth_app/lib/pages/product/common/product_list_popup_items.dart +++ b/packages/smooth_app/lib/pages/product/common/product_list_popup_items.dart @@ -10,12 +10,25 @@ import 'package:smooth_app/helpers/temp_product_list_share_helper.dart'; import 'package:smooth_app/pages/product_list_user_dialog_helper.dart'; import 'package:url_launcher/url_launcher.dart'; +enum ProductListPopupMenuEntry { + share, + openInBrowser, + rename, + clear, + delete, +} + /// Popup menu items for the product list page. abstract class ProductListPopupItem { /// Title of the popup menu item. - @protected String getTitle(final AppLocalizations appLocalizations); + /// IconData of the popup menu item. + IconData getIconData(); + + /// Popup menu entry of the popup menu item. + ProductListPopupMenuEntry getEntry(); + /// Action of the popup menu item. /// /// Returns a different product list if there are changes, else null. @@ -39,7 +52,13 @@ abstract class ProductListPopupItem { class ProductListPopupClear extends ProductListPopupItem { @override String getTitle(final AppLocalizations appLocalizations) => - appLocalizations.clear; + appLocalizations.clear_long; + + @override + IconData getIconData() => Icons.delete_sweep; + + @override + ProductListPopupMenuEntry getEntry() => ProductListPopupMenuEntry.clear; @override Future doSomething({ @@ -83,6 +102,12 @@ class ProductListPopupRename extends ProductListPopupItem { String getTitle(final AppLocalizations appLocalizations) => appLocalizations.user_list_popup_rename; + @override + IconData getIconData() => Icons.edit; + + @override + ProductListPopupMenuEntry getEntry() => ProductListPopupMenuEntry.rename; + @override Future doSomething({ required final ProductList productList, @@ -99,6 +124,12 @@ class ProductListPopupShare extends ProductListPopupItem { String getTitle(final AppLocalizations appLocalizations) => appLocalizations.share; + @override + IconData getIconData() => Icons.share; + + @override + ProductListPopupMenuEntry getEntry() => ProductListPopupMenuEntry.share; + @override Future doSomething({ required final ProductList productList, @@ -125,6 +156,13 @@ class ProductListPopupOpenInWeb extends ProductListPopupItem { String getTitle(final AppLocalizations appLocalizations) => appLocalizations.label_web; + @override + IconData getIconData() => Icons.public; + + @override + ProductListPopupMenuEntry getEntry() => + ProductListPopupMenuEntry.openInBrowser; + @override Future doSomething({ required final ProductList productList, @@ -137,3 +175,28 @@ class ProductListPopupOpenInWeb extends ProductListPopupItem { return null; } } + +/// Popup menu item for the product list page: delete. +class ProductListPopupDelete extends ProductListPopupItem { + @override + String getTitle(final AppLocalizations appLocalizations) => + appLocalizations.action_delete_list; + + @override + IconData getIconData() => Icons.delete; + + @override + ProductListPopupMenuEntry getEntry() => ProductListPopupMenuEntry.delete; + + @override + Future doSomething({ + required final ProductList productList, + required final LocalDatabase localDatabase, + required final BuildContext context, + }) async { + final bool deleted = + await ProductListUserDialogHelper(DaoProductList(localDatabase)) + .showDeleteUserListDialog(context, productList); + return deleted ? null : productList; + } +}