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 (#5842)

* feat: 1392 - added "select all" and "select none" actions for product 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

* different icon for none, more refined title with count

Impacted files:
* `app_en.arb`: added 1 label for multiselect title
* `product_list_item_popup_items.dart`: changed the icon for none
* `product_list_page.dart`: more refined multiselect title
  • Loading branch information
monsieurtanuki authored Nov 11, 2024
1 parent d6446ba commit 2784043
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
21 changes: 20 additions & 1 deletion packages/smooth_app/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -998,10 +998,29 @@
"count": {}
}
},
"compare_products_mode": "Compare products",
"multiselect_title": "{count,plural, =0{No selected product} =1{One selected product} other{{count} selected products}}",
"@multiselect_title": {
"description": "Page title with the number of selected items",
"placeholders": {
"count": {}
}
},
"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.check_box_outline_blank;

@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 @@ -182,7 +186,9 @@ class _ProductListPageState extends State<ProductListPage>
onLeaveActionMode: () {
setState(() => _selectionMode = false);
},
actionModeTitle: Text('${_selectedBarcodes.length}'),
actionModeTitle: Text(
appLocalizations.multiselect_title(_selectedBarcodes.length),
),
actionModeActions: <Widget>[
SmoothPopupMenuButton<ProductListItemPopupItem>(
onSelected: (final ProductListItemPopupItem action) async {
Expand Down Expand Up @@ -216,6 +222,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 2784043

Please sign in to comment.