Skip to content

Commit

Permalink
feat: 1392 - added "select all" and "select none" actions for product…
Browse files Browse the repository at this point in the history
… lists

Impacted files:
* `app_en.arb`: added 3 labels (2 new actions, 1 previously not localized)
* `product_list_item_popup_items.dart`: added 2 actions; minor refactoring
* `product_list_page.dart`: added 2 actions
  • Loading branch information
monsieurtanuki committed Nov 11, 2024
1 parent 45b7e7b commit 575e479
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 6 deletions.
14 changes: 13 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -999,10 +999,22 @@
"count": {}
}
},
"compare_products_mode": "Compare products",
"compare_products_mode": "Compare selected products",
"@compare_products_mode": {
"description": "Button to switch to 'compare products mode'"
},
"delete_products_mode": "Delete selected products",
"@delete_products_mode": {
"description": "Button to switch to 'delete products'"
},
"select_all_products_mode": "Select all products",
"@select_all_products_mode": {
"description": "Button to switch to 'select all products'"
},
"select_none_products_mode": "Select none",
"@select_none_products_mode": {
"description": "Button to switch to 'select no products'"
},
"compare_products_appbar_title": "Compare products",
"@compare_products_appbar_title": {
"description": "AppBar title when in comparison mode "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ abstract class ProductListItemPopupItem {
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Iterable<String> selectedBarcodes,
required final Set<String> selectedBarcodes,
});

/// Returns the popup menu item.
Expand Down Expand Up @@ -68,7 +68,7 @@ class ProductListItemPopupSideBySide extends ProductListItemPopupItem {
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Iterable<String> selectedBarcodes,
required final Set<String> selectedBarcodes,
}) async {
final OrderedNutrientsCache? cache =
await OrderedNutrientsCache.getCache(context);
Expand Down Expand Up @@ -118,7 +118,7 @@ class ProductListItemPopupRank extends ProductListItemPopupItem {
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Iterable<String> selectedBarcodes,
required final Set<String> selectedBarcodes,
}) async {
await Navigator.push<void>(
context,
Expand All @@ -137,7 +137,7 @@ class ProductListItemPopupRank extends ProductListItemPopupItem {
class ProductListItemPopupDelete extends ProductListItemPopupItem {
@override
String getTitle(final AppLocalizations appLocalizations) =>
'Delete selected items'; //appLocalizations.action_delete_list;
appLocalizations.delete_products_mode;

@override
IconData getIconData() => Icons.delete;
Expand All @@ -150,7 +150,7 @@ class ProductListItemPopupDelete extends ProductListItemPopupItem {
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Iterable<String> selectedBarcodes,
required final Set<String> selectedBarcodes,
}) async {
final AppLocalizations appLocalizations = AppLocalizations.of(context);
final DaoProductList daoProductList = DaoProductList(localDatabase);
Expand Down Expand Up @@ -190,3 +190,45 @@ class ProductListItemPopupDelete extends ProductListItemPopupItem {
return true;
}
}

/// Popup menu item for the product list page: select all items.
class ProductListItemPopupSelectAll extends ProductListItemPopupItem {
@override
String getTitle(final AppLocalizations appLocalizations) =>
appLocalizations.select_all_products_mode;

@override
IconData getIconData() => Icons.check_box;

@override
Future<bool> doSomething({
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Set<String> selectedBarcodes,
}) async {
selectedBarcodes.addAll(productList.barcodes);
return true;
}
}

/// Popup menu item for the product list page: unselect all items.
class ProductListItemPopupUnselectAll extends ProductListItemPopupItem {
@override
String getTitle(final AppLocalizations appLocalizations) =>
appLocalizations.select_none_products_mode;

@override
IconData getIconData() => Icons.clear;

@override
Future<bool> doSomething({
required final ProductList productList,
required final LocalDatabase localDatabase,
required final BuildContext context,
required final Set<String> selectedBarcodes,
}) async {
selectedBarcodes.clear();
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ class _ProductListPageState extends State<ProductListPage>
final ProductListItemPopupItem _rankItems = ProductListItemPopupRank();
final ProductListItemPopupItem _sideBySideItems =
ProductListItemPopupSideBySide();
final ProductListItemPopupItem _selectAllItems =
ProductListItemPopupSelectAll();
final ProductListItemPopupItem _selectNoneItems =
ProductListItemPopupUnselectAll();

//returns bool to handle WillPopScope
Future<bool> _handleUserBacktap() async {
Expand Down Expand Up @@ -216,6 +220,14 @@ class _ProductListPageState extends State<ProductListPage>
appLocalizations,
_selectedBarcodes.isNotEmpty,
),
_selectAllItems.getMenuItem(
appLocalizations,
_selectedBarcodes.length < productList.barcodes.length,
),
_selectNoneItems.getMenuItem(
appLocalizations,
_selectedBarcodes.isNotEmpty,
),
],
),
],
Expand Down

0 comments on commit 575e479

Please sign in to comment.