Replicated multiselect logic into products
This commit is contained in:
parent
f3a3779fcb
commit
8c5f7f706d
|
|
@ -193,7 +193,7 @@ abstract class ProductEntity extends Object
|
||||||
bool multiselect = false}) {
|
bool multiselect = false}) {
|
||||||
final actions = <EntityAction>[];
|
final actions = <EntityAction>[];
|
||||||
|
|
||||||
if (!isDeleted) {
|
if (!isDeleted && !multiselect) {
|
||||||
if (includeEdit && userCompany.canEditEntity(this)) {
|
if (includeEdit && userCompany.canEditEntity(this)) {
|
||||||
actions.add(EntityAction.edit);
|
actions.add(EntityAction.edit);
|
||||||
}
|
}
|
||||||
|
|
@ -203,7 +203,7 @@ abstract class ProductEntity extends Object
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userCompany.canCreate(EntityType.product)) {
|
if (userCompany.canCreate(EntityType.product) && !multiselect) {
|
||||||
actions.add(EntityAction.clone);
|
actions.add(EntityAction.clone);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,15 +17,11 @@ import 'package:invoiceninja_flutter/ui/settings/products_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/settings/tax_rates_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/tax_rates_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/settings/templates_and_reminders_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/templates_and_reminders_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/settings/user_details_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/user_details_vm.dart';
|
||||||
import 'package:sentry/sentry.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
import 'package:font_awesome_flutter/font_awesome_flutter.dart';
|
|
||||||
import 'package:intl/intl.dart';
|
|
||||||
import 'package:redux/redux.dart';
|
|
||||||
import 'package:local_auth/local_auth.dart';
|
import 'package:local_auth/local_auth.dart';
|
||||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
|
||||||
import 'package:redux_logging/redux_logging.dart';
|
import 'package:redux_logging/redux_logging.dart';
|
||||||
|
import 'package:sentry/sentry.dart';
|
||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
import 'package:invoiceninja_flutter/.env.dart';
|
import 'package:invoiceninja_flutter/.env.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/settings/settings_middleware.dart';
|
import 'package:invoiceninja_flutter/redux/settings/settings_middleware.dart';
|
||||||
|
|
@ -280,7 +276,7 @@ class InvoiceNinjaAppState extends State<InvoiceNinjaApp> {
|
||||||
LoginScreen.route: (context) => LoginScreen(),
|
LoginScreen.route: (context) => LoginScreen(),
|
||||||
MainScreen.route: (context) => MainScreen(),
|
MainScreen.route: (context) => MainScreen(),
|
||||||
DashboardScreen.route: (context) => DashboardScreen(),
|
DashboardScreen.route: (context) => DashboardScreen(),
|
||||||
ProductScreen.route: (context) => ProductScreen(),
|
ProductScreen.route: (context) => ProductScreenBuilder(),
|
||||||
ProductViewScreen.route: (context) => ProductViewScreen(),
|
ProductViewScreen.route: (context) => ProductViewScreen(),
|
||||||
ProductEditScreen.route: (context) => ProductEditScreen(),
|
ProductEditScreen.route: (context) => ProductEditScreen(),
|
||||||
ClientScreen.route: (context) => ClientScreenBuilder(),
|
ClientScreen.route: (context) => ClientScreenBuilder(),
|
||||||
|
|
|
||||||
|
|
@ -175,7 +175,6 @@ ListUIState _removeFromListMultiselect(
|
||||||
|
|
||||||
ListUIState _clearListMultiselect(
|
ListUIState _clearListMultiselect(
|
||||||
ListUIState clientListState, ClearMultiselect action) {
|
ListUIState clientListState, ClearMultiselect action) {
|
||||||
// TODO: Notify UI which IDs were selected
|
|
||||||
return clientListState.rebuild((b) => b..selectedEntities = null);
|
return clientListState.rebuild((b) => b..selectedEntities = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -196,7 +196,7 @@ class FilterProductDropdown {
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleProductAction(
|
void handleProductAction(
|
||||||
BuildContext context, List<ProductEntity> products, EntityAction action) {
|
BuildContext context, List<BaseEntity> products, EntityAction action) {
|
||||||
final store = StoreProvider.of<AppState>(context);
|
final store = StoreProvider.of<AppState>(context);
|
||||||
final state = store.state;
|
final state = store.state;
|
||||||
final localization = AppLocalization.of(context);
|
final localization = AppLocalization.of(context);
|
||||||
|
|
@ -214,7 +214,8 @@ void handleProductAction(
|
||||||
store.dispatch(EditProduct(context: context, product: products[0]));
|
store.dispatch(EditProduct(context: context, product: products[0]));
|
||||||
break;
|
break;
|
||||||
case EntityAction.clone:
|
case EntityAction.clone:
|
||||||
store.dispatch(EditProduct(context: context, product: products[0].clone));
|
store.dispatch(EditProduct(
|
||||||
|
context: context, product: (products[0] as ProductEntity).clone));
|
||||||
break;
|
break;
|
||||||
case EntityAction.restore:
|
case EntityAction.restore:
|
||||||
store.dispatch(RestoreProductRequest(
|
store.dispatch(RestoreProductRequest(
|
||||||
|
|
@ -231,5 +232,50 @@ void handleProductAction(
|
||||||
snackBarCompleter(context, localization.deletedProduct),
|
snackBarCompleter(context, localization.deletedProduct),
|
||||||
products[0].id));
|
products[0].id));
|
||||||
break;
|
break;
|
||||||
|
case EntityAction.toggleMultiselect:
|
||||||
|
if (!store.state.productListState.isInMultiselect()) {
|
||||||
|
store.dispatch(StartMultiselect(context: context));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (products.isEmpty) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
final select = !store.state.productListState.isSelected(products[0]);
|
||||||
|
for (final product in products) {
|
||||||
|
if (select) {
|
||||||
|
store.dispatch(AddToMultiselect(context: context, entity: product));
|
||||||
|
} else {
|
||||||
|
store.dispatch(
|
||||||
|
RemoveFromMultiselect(context: context, entity: product));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class StartMultiselect {
|
||||||
|
StartMultiselect({@required this.context});
|
||||||
|
|
||||||
|
final BuildContext context;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddToMultiselect {
|
||||||
|
AddToMultiselect({@required this.context, @required this.entity});
|
||||||
|
|
||||||
|
final BuildContext context;
|
||||||
|
final BaseEntity entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
class RemoveFromMultiselect {
|
||||||
|
RemoveFromMultiselect({@required this.context, @required this.entity});
|
||||||
|
|
||||||
|
final BuildContext context;
|
||||||
|
final BaseEntity entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ClearMultiselect {
|
||||||
|
ClearMultiselect({@required this.context});
|
||||||
|
|
||||||
|
final BuildContext context;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,11 @@
|
||||||
|
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/product_model.dart';
|
import 'package:invoiceninja_flutter/data/models/product_model.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/company/company_actions.dart';
|
import 'package:invoiceninja_flutter/redux/company/company_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/product/product_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart';
|
import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
|
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/product/product_state.dart';
|
|
||||||
|
|
||||||
EntityUIState productUIReducer(ProductUIState state, dynamic action) {
|
EntityUIState productUIReducer(ProductUIState state, dynamic action) {
|
||||||
return state.rebuild((b) => b
|
return state.rebuild((b) => b
|
||||||
|
|
@ -55,6 +56,10 @@ final productListReducer = combineReducers<ListUIState>([
|
||||||
TypedReducer<ListUIState, FilterProductsByState>(_filterProductsByState),
|
TypedReducer<ListUIState, FilterProductsByState>(_filterProductsByState),
|
||||||
TypedReducer<ListUIState, FilterProductsByCustom1>(_filterProductsByCustom1),
|
TypedReducer<ListUIState, FilterProductsByCustom1>(_filterProductsByCustom1),
|
||||||
TypedReducer<ListUIState, FilterProductsByCustom2>(_filterProductsByCustom2),
|
TypedReducer<ListUIState, FilterProductsByCustom2>(_filterProductsByCustom2),
|
||||||
|
TypedReducer<ListUIState, StartMultiselect>(_startListMultiselect),
|
||||||
|
TypedReducer<ListUIState, AddToMultiselect>(_addToListMultiselect),
|
||||||
|
TypedReducer<ListUIState, RemoveFromMultiselect>(_removeFromListMultiselect),
|
||||||
|
TypedReducer<ListUIState, ClearMultiselect>(_clearListMultiselect),
|
||||||
]);
|
]);
|
||||||
|
|
||||||
ListUIState _filterProductsByState(
|
ListUIState _filterProductsByState(
|
||||||
|
|
@ -102,6 +107,28 @@ ListUIState _sortProducts(ListUIState productListState, SortProducts action) {
|
||||||
..sortField = action.field);
|
..sortField = action.field);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ListUIState _startListMultiselect(
|
||||||
|
ListUIState productListState, StartMultiselect action) {
|
||||||
|
return productListState.rebuild((b) => b..selectedEntities = <BaseEntity>[]);
|
||||||
|
}
|
||||||
|
|
||||||
|
ListUIState _addToListMultiselect(
|
||||||
|
ListUIState productListState, AddToMultiselect action) {
|
||||||
|
return productListState
|
||||||
|
.rebuild((b) => b..selectedEntities.add(action.entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
ListUIState _removeFromListMultiselect(
|
||||||
|
ListUIState productListState, RemoveFromMultiselect action) {
|
||||||
|
return productListState
|
||||||
|
.rebuild((b) => b..selectedEntities.remove(action.entity));
|
||||||
|
}
|
||||||
|
|
||||||
|
ListUIState _clearListMultiselect(
|
||||||
|
ListUIState productListState, ClearMultiselect action) {
|
||||||
|
return productListState.rebuild((b) => b..selectedEntities = null);
|
||||||
|
}
|
||||||
|
|
||||||
final productsReducer = combineReducers<ProductState>([
|
final productsReducer = combineReducers<ProductState>([
|
||||||
TypedReducer<ProductState, SaveProductSuccess>(_updateProduct),
|
TypedReducer<ProductState, SaveProductSuccess>(_updateProduct),
|
||||||
TypedReducer<ProductState, AddProductSuccess>(_addProduct),
|
TypedReducer<ProductState, AddProductSuccess>(_addProduct),
|
||||||
|
|
|
||||||
|
|
@ -4,14 +4,17 @@ import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/icons.dart';
|
import 'package:invoiceninja_flutter/utils/icons.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
|
||||||
Future<void> showEntityActionsDialog({
|
Future<void> showEntityActionsDialog(
|
||||||
@required BuildContext context,
|
{@required
|
||||||
@required List<BaseEntity> entities,
|
BuildContext context,
|
||||||
@required UserCompanyEntity userCompany,
|
@required
|
||||||
@required
|
List<BaseEntity> entities,
|
||||||
Function(BuildContext, List<BaseEntity>, EntityAction) onEntityAction,
|
@required
|
||||||
ClientEntity client,
|
UserCompanyEntity userCompany,
|
||||||
}) async {
|
@required
|
||||||
|
Function(BuildContext, List<BaseEntity>, EntityAction) onEntityAction,
|
||||||
|
ClientEntity client,
|
||||||
|
bool multiselect = false}) async {
|
||||||
if (entities == null) {
|
if (entities == null) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -22,7 +25,10 @@ Future<void> showEntityActionsDialog({
|
||||||
final actions = <Widget>[];
|
final actions = <Widget>[];
|
||||||
actions.addAll(entities[0]
|
actions.addAll(entities[0]
|
||||||
.getActions(
|
.getActions(
|
||||||
userCompany: userCompany, includeEdit: true, client: client)
|
userCompany: userCompany,
|
||||||
|
includeEdit: true,
|
||||||
|
client: client,
|
||||||
|
multiselect: multiselect)
|
||||||
.map((entityAction) {
|
.map((entityAction) {
|
||||||
if (entityAction == null) {
|
if (entityAction == null) {
|
||||||
return Divider();
|
return Divider();
|
||||||
|
|
|
||||||
|
|
@ -64,13 +64,16 @@ class ClientList extends StatelessWidget {
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.start,
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Checkbox(
|
Padding(
|
||||||
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
padding: const EdgeInsets.only(left: 20.0),
|
||||||
onChanged: (value) =>
|
child: Checkbox(
|
||||||
_toggleSelectionForAll(store, context),
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
value:
|
onChanged: (value) =>
|
||||||
store.state.clientListState.selectedEntities.length ==
|
_toggleSelectionForAll(store, context),
|
||||||
viewModel.clientList.length)
|
activeColor: Theme.of(context).accentColor,
|
||||||
|
value: listUIState.selectedEntities.length ==
|
||||||
|
viewModel.clientList.length),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/client/client_actions.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/app/entity_state_label.dart';
|
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dismissible_entity.dart';
|
import 'package:invoiceninja_flutter/ui/app/dismissible_entity.dart';
|
||||||
import 'package:redux/src/store.dart';
|
import 'package:invoiceninja_flutter/ui/app/entity_state_label.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
|
|
||||||
class ClientListItem extends StatelessWidget {
|
class ClientListItem extends StatelessWidget {
|
||||||
const ClientListItem({
|
const ClientListItem({
|
||||||
|
|
|
||||||
|
|
@ -113,7 +113,8 @@ class ClientScreen extends StatelessWidget {
|
||||||
entities: store.state.clientListState.selectedEntities,
|
entities: store.state.clientListState.selectedEntities,
|
||||||
userCompany: viewModel.userCompany,
|
userCompany: viewModel.userCompany,
|
||||||
context: context,
|
context: context,
|
||||||
onEntityAction: viewModel.onEntityAction);
|
onEntityAction: viewModel.onEntityAction,
|
||||||
|
multiselect: true);
|
||||||
}
|
}
|
||||||
store.dispatch(ClearMultiselect(context: context));
|
store.dispatch(ClearMultiselect(context: context));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/help_text.dart';
|
import 'package:invoiceninja_flutter/ui/app/help_text.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/lists/list_divider.dart';
|
import 'package:invoiceninja_flutter/ui/app/lists/list_divider.dart';
|
||||||
|
|
@ -8,6 +10,7 @@ import 'package:invoiceninja_flutter/ui/app/loading_indicator.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/product/product_list_item.dart';
|
import 'package:invoiceninja_flutter/ui/product/product_list_item.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/product/product_list_vm.dart';
|
import 'package:invoiceninja_flutter/ui/product/product_list_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
import 'package:redux/src/store.dart';
|
||||||
|
|
||||||
class ProductList extends StatelessWidget {
|
class ProductList extends StatelessWidget {
|
||||||
const ProductList({
|
const ProductList({
|
||||||
|
|
@ -29,12 +32,41 @@ class ProductList extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildListView(BuildContext context) {
|
Widget _buildListView(BuildContext context) {
|
||||||
|
final store = StoreProvider.of<AppState>(context);
|
||||||
|
final listUIState = store.state.uiState.productUIState.listUIState;
|
||||||
|
final isInMultiselect = listUIState.isInMultiselect();
|
||||||
|
|
||||||
return RefreshIndicator(
|
return RefreshIndicator(
|
||||||
onRefresh: () => viewModel.onRefreshed(context),
|
onRefresh: () => viewModel.onRefreshed(context),
|
||||||
child: ListView.separated(
|
child: ListView.separated(
|
||||||
separatorBuilder: (context, index) => ListDivider(),
|
separatorBuilder: (context, index) => ListDivider(),
|
||||||
itemCount: viewModel.productList.length,
|
itemCount: isInMultiselect
|
||||||
|
? viewModel.productList.length + 1
|
||||||
|
: viewModel.productList.length,
|
||||||
itemBuilder: (BuildContext context, index) {
|
itemBuilder: (BuildContext context, index) {
|
||||||
|
// Add header
|
||||||
|
if (index == 0 && isInMultiselect) {
|
||||||
|
return Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.start,
|
||||||
|
children: <Widget>[
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(left: 20.0),
|
||||||
|
child: Checkbox(
|
||||||
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
|
onChanged: (value) =>
|
||||||
|
_toggleSelectionForAll(store, context),
|
||||||
|
activeColor: Theme.of(context).accentColor,
|
||||||
|
value: listUIState.selectedEntities.length ==
|
||||||
|
viewModel.productList.length),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isInMultiselect) {
|
||||||
|
index--;
|
||||||
|
}
|
||||||
|
|
||||||
final productId = viewModel.productList[index];
|
final productId = viewModel.productList[index];
|
||||||
final product = viewModel.productMap[productId];
|
final product = viewModel.productMap[productId];
|
||||||
|
|
||||||
|
|
@ -56,9 +88,27 @@ class ProductList extends StatelessWidget {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onTap: () => viewModel.onProductTap(context, product),
|
onTap: () => viewModel.onProductTap(context, product),
|
||||||
onLongPress: () => showDialog(),
|
onLongPress: () async {
|
||||||
|
final longPressIsSelection =
|
||||||
|
store.state.uiState.longPressSelectionIsDefault ?? true;
|
||||||
|
if (longPressIsSelection) {
|
||||||
|
viewModel.onEntityAction(
|
||||||
|
context, [product], EntityAction.toggleMultiselect);
|
||||||
|
} else {
|
||||||
|
showDialog();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
isChecked: isInMultiselect && listUIState.isSelected(product),
|
||||||
);
|
);
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _toggleSelectionForAll(Store<AppState> store, BuildContext context) {
|
||||||
|
final products = viewModel.productList
|
||||||
|
.map<ProductEntity>((productId) => viewModel.productMap[productId])
|
||||||
|
.toList();
|
||||||
|
|
||||||
|
viewModel.onEntityAction(context, products, EntityAction.toggleMultiselect);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,11 @@
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/app/entity_state_label.dart';
|
|
||||||
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dismissible_entity.dart';
|
import 'package:invoiceninja_flutter/ui/app/dismissible_entity.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/entity_state_label.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/formatting.dart';
|
||||||
|
|
||||||
class ProductListItem extends StatelessWidget {
|
class ProductListItem extends StatelessWidget {
|
||||||
const ProductListItem({
|
const ProductListItem({
|
||||||
|
|
@ -28,6 +28,8 @@ class ProductListItem extends StatelessWidget {
|
||||||
? product.matchesFilterValue(filter)
|
? product.matchesFilterValue(filter)
|
||||||
: null;
|
: null;
|
||||||
final subtitle = filterMatch ?? product.notes;
|
final subtitle = filterMatch ?? product.notes;
|
||||||
|
final listUIState = productUIState.listUIState;
|
||||||
|
final isInMultiselect = listUIState.isInMultiselect();
|
||||||
|
|
||||||
return DismissibleEntity(
|
return DismissibleEntity(
|
||||||
isSelected: product.id ==
|
isSelected: product.id ==
|
||||||
|
|
@ -38,16 +40,22 @@ class ProductListItem extends StatelessWidget {
|
||||||
entity: product,
|
entity: product,
|
||||||
onEntityAction: onEntityAction,
|
onEntityAction: onEntityAction,
|
||||||
child: ListTile(
|
child: ListTile(
|
||||||
onTap: onTap,
|
onTap: isInMultiselect
|
||||||
|
? () => onEntityAction(EntityAction.toggleMultiselect)
|
||||||
|
: onTap,
|
||||||
onLongPress: onLongPress,
|
onLongPress: onLongPress,
|
||||||
leading: onCheckboxChanged != null
|
leading: IgnorePointer(
|
||||||
? Checkbox(
|
ignoring: listUIState.isInMultiselect(),
|
||||||
//key: NinjaKeys.productItemCheckbox(task.id),
|
child: (onCheckboxChanged != null || isInMultiselect)
|
||||||
value: isChecked,
|
? Checkbox(
|
||||||
onChanged: (value) => onCheckboxChanged(value),
|
//key: NinjaKeys.productItemCheckbox(task.id),
|
||||||
activeColor: Theme.of(context).accentColor,
|
value: isChecked,
|
||||||
)
|
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
|
||||||
: null,
|
onChanged: (value) => onCheckboxChanged(value),
|
||||||
|
activeColor: Theme.of(context).accentColor,
|
||||||
|
)
|
||||||
|
: null,
|
||||||
|
),
|
||||||
title: Container(
|
title: Container(
|
||||||
width: MediaQuery.of(context).size.width,
|
width: MediaQuery.of(context).size.width,
|
||||||
child: Row(
|
child: Row(
|
||||||
|
|
|
||||||
|
|
@ -67,7 +67,7 @@ class ProductListVM {
|
||||||
onProductTap: (context, product) {
|
onProductTap: (context, product) {
|
||||||
store.dispatch(ViewProduct(productId: product.id, context: context));
|
store.dispatch(ViewProduct(productId: product.id, context: context));
|
||||||
},
|
},
|
||||||
onEntityAction: (BuildContext context, List<BaseEntity> products,
|
onEntityAction: (BuildContext context, List<ProductEntity> products,
|
||||||
EntityAction action) =>
|
EntityAction action) =>
|
||||||
handleProductAction(context, products, action),
|
handleProductAction(context, products, action),
|
||||||
onRefreshed: (context) => _handleRefresh(context),
|
onRefreshed: (context) => _handleRefresh(context),
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,28 @@
|
||||||
import 'package:invoiceninja_flutter/ui/app/app_scaffold.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
|
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/product/product_list_vm.dart';
|
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
|
import 'package:invoiceninja_flutter/ui/app/app_bottom_bar.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/app_scaffold.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/entities/entity_actions_dialog.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/list_filter.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/app/list_filter_button.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/product/product_list_vm.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/product/product_screen_vm.dart';
|
||||||
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
import 'package:redux/src/store.dart';
|
||||||
|
|
||||||
class ProductScreen extends StatelessWidget {
|
class ProductScreen extends StatelessWidget {
|
||||||
|
const ProductScreen({
|
||||||
|
Key key,
|
||||||
|
@required this.viewModel,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
static const String route = '/product';
|
static const String route = '/product';
|
||||||
|
|
||||||
|
final ProductScreenVM viewModel;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final store = StoreProvider.of<AppState>(context);
|
final store = StoreProvider.of<AppState>(context);
|
||||||
|
|
@ -29,12 +39,31 @@ class ProductScreen extends StatelessWidget {
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
appBarActions: [
|
appBarActions: [
|
||||||
ListFilterButton(
|
if (!viewModel.isInMultiselect)
|
||||||
entityType: EntityType.product,
|
ListFilterButton(
|
||||||
onFilterPressed: (String value) {
|
entityType: EntityType.product,
|
||||||
store.dispatch(FilterProducts(value));
|
onFilterPressed: (String value) {
|
||||||
},
|
store.dispatch(FilterProducts(value));
|
||||||
),
|
},
|
||||||
|
),
|
||||||
|
if (viewModel.isInMultiselect)
|
||||||
|
FlatButton(
|
||||||
|
key: key,
|
||||||
|
child: Text(
|
||||||
|
localization.done,
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () => _finishMultiselect(context, 'done', store),
|
||||||
|
),
|
||||||
|
if (viewModel.isInMultiselect)
|
||||||
|
FlatButton(
|
||||||
|
key: key,
|
||||||
|
child: Text(
|
||||||
|
localization.cancel,
|
||||||
|
style: TextStyle(color: Colors.white),
|
||||||
|
),
|
||||||
|
onPressed: () => _finishMultiselect(context, 'cancel', store),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
body: ProductListBuilder(),
|
body: ProductListBuilder(),
|
||||||
bottomNavigationBar: AppBottomBar(
|
bottomNavigationBar: AppBottomBar(
|
||||||
|
|
@ -74,4 +103,17 @@ class ProductScreen extends StatelessWidget {
|
||||||
: null,
|
: null,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _finishMultiselect(
|
||||||
|
BuildContext context, String mode, Store<AppState> store) async {
|
||||||
|
if (mode == 'done') {
|
||||||
|
await showEntityActionsDialog(
|
||||||
|
entities: store.state.productListState.selectedEntities,
|
||||||
|
userCompany: viewModel.userCompany,
|
||||||
|
context: context,
|
||||||
|
onEntityAction: viewModel.onEntityAction,
|
||||||
|
multiselect: true);
|
||||||
|
}
|
||||||
|
store.dispatch(ClearMultiselect(context: context));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,51 @@
|
||||||
|
import 'package:flutter/foundation.dart';
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/widgets.dart';
|
||||||
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/product/product_actions.dart';
|
||||||
|
import 'package:redux/redux.dart';
|
||||||
|
|
||||||
|
import 'product_screen.dart';
|
||||||
|
|
||||||
|
class ProductScreenBuilder extends StatelessWidget {
|
||||||
|
const ProductScreenBuilder({Key key}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return StoreConnector<AppState, ProductScreenVM>(
|
||||||
|
//rebuildOnChange: true,
|
||||||
|
converter: ProductScreenVM.fromStore,
|
||||||
|
builder: (context, vm) {
|
||||||
|
return ProductScreen(
|
||||||
|
viewModel: vm,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class ProductScreenVM {
|
||||||
|
ProductScreenVM({
|
||||||
|
@required this.isInMultiselect,
|
||||||
|
@required this.userCompany,
|
||||||
|
@required this.onEntityAction,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool isInMultiselect;
|
||||||
|
final UserCompanyEntity userCompany;
|
||||||
|
final Function(BuildContext, List<BaseEntity>, EntityAction) onEntityAction;
|
||||||
|
|
||||||
|
static ProductScreenVM fromStore(Store<AppState> store) {
|
||||||
|
final state = store.state;
|
||||||
|
|
||||||
|
return ProductScreenVM(
|
||||||
|
userCompany: state.userCompany,
|
||||||
|
isInMultiselect: state.productListState.isInMultiselect(),
|
||||||
|
onEntityAction: (BuildContext context, List<BaseEntity> products,
|
||||||
|
EntityAction action) =>
|
||||||
|
handleProductAction(context, products, action),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -5,7 +5,6 @@ import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/lists/list_filter.dart';
|
import 'package:invoiceninja_flutter/ui/app/lists/list_filter.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/lists/selected_indicator.dart';
|
import 'package:invoiceninja_flutter/ui/app/lists/selected_indicator.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/entities.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/settings/settings_list_vm.dart';
|
import 'package:invoiceninja_flutter/ui/settings/settings_list_vm.dart';
|
||||||
import 'package:invoiceninja_flutter/utils/localization.dart';
|
import 'package:invoiceninja_flutter/utils/localization.dart';
|
||||||
|
|
||||||
|
|
@ -62,6 +61,11 @@ class SettingsList extends StatelessWidget {
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
icon: FontAwesomeIcons.user,
|
icon: FontAwesomeIcons.user,
|
||||||
),
|
),
|
||||||
|
SettingsListTile(
|
||||||
|
section: kSettingsUserDetails,
|
||||||
|
viewModel: viewModel,
|
||||||
|
icon: FontAwesomeIcons.user,
|
||||||
|
),
|
||||||
SettingsListTile(
|
SettingsListTile(
|
||||||
section: kSettingsLocalization,
|
section: kSettingsLocalization,
|
||||||
viewModel: viewModel,
|
viewModel: viewModel,
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,5 @@
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
import 'package:invoiceninja_flutter/ui/app/dialogs/error_dialog.dart';
|
||||||
import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart';
|
import 'package:invoiceninja_flutter/ui/app/snackbar_row.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue