From f53a498c03a5b8e774f653eb88b6f17c903ec7f9 Mon Sep 17 00:00:00 2001 From: Juan Gilsanz Polo Date: Sun, 26 Nov 2023 22:42:05 +0100 Subject: [PATCH] Changed options menus --- lib/screens/clients/added_list.dart | 12 -- .../clients/client/added_client_tile.dart | 2 - lib/screens/clients/clients_list.dart | 4 +- lib/screens/clients/options_modal.dart | 72 ------- lib/screens/clients/search_clients.dart | 183 ++++++++++-------- .../filters/filters_triple_column.dart | 45 ++--- lib/screens/filters/list_options_menu.dart | 72 +++---- lib/widgets/custom_list_tile_dialog.dart | 4 +- lib/widgets/options_menu.dart | 67 ++++++- lib/widgets/options_modal.dart | 67 ------- 10 files changed, 225 insertions(+), 303 deletions(-) delete mode 100644 lib/screens/clients/options_modal.dart delete mode 100644 lib/widgets/options_modal.dart diff --git a/lib/screens/clients/added_list.dart b/lib/screens/clients/added_list.dart index 124f32c..a272940 100644 --- a/lib/screens/clients/added_list.dart +++ b/lib/screens/clients/added_list.dart @@ -11,7 +11,6 @@ import 'package:adguard_home_manager/screens/clients/client/client_screen_functi import 'package:adguard_home_manager/screens/clients/client/added_client_tile.dart'; import 'package:adguard_home_manager/screens/clients/client/remove_client_modal.dart'; import 'package:adguard_home_manager/screens/clients/fab.dart'; -import 'package:adguard_home_manager/screens/clients/options_modal.dart'; import 'package:adguard_home_manager/widgets/tab_content_list.dart'; import 'package:adguard_home_manager/functions/snackbar.dart'; @@ -144,16 +143,6 @@ class _AddedListState extends State { ); } - void openOptionsModal(Client client) { - showModal( - context: context, - builder: (ctx) => OptionsModal( - onDelete: () => openDeleteModal(client), - onEdit: () => openClientModal(client), - ) - ); - } - return CustomTabContentList( listPadding: widget.splitView == true ? const EdgeInsets.only(top: 8) @@ -182,7 +171,6 @@ class _AddedListState extends State { selectedClient: widget.selectedClient, client: widget.data[index], onTap: widget.onClientSelected, - onLongPress: openOptionsModal, onEdit: statusProvider.serverStatus != null ? (c) => openClientModal(c) : null, diff --git a/lib/screens/clients/client/added_client_tile.dart b/lib/screens/clients/client/added_client_tile.dart index a33578f..4f4037e 100644 --- a/lib/screens/clients/client/added_client_tile.dart +++ b/lib/screens/clients/client/added_client_tile.dart @@ -13,7 +13,6 @@ import 'package:adguard_home_manager/providers/app_config_provider.dart'; class AddedClientTile extends StatefulWidget { final Client client; final void Function(Client) onTap; - final void Function(Client) onLongPress; final void Function(Client)? onEdit; final void Function(Client) onDelete; final Client? selectedClient; @@ -23,7 +22,6 @@ class AddedClientTile extends StatefulWidget { super.key, required this.client, required this.onTap, - required this.onLongPress, this.onEdit, required this.onDelete, this.selectedClient, diff --git a/lib/screens/clients/clients_list.dart b/lib/screens/clients/clients_list.dart index 2e52738..bdff4ee 100644 --- a/lib/screens/clients/clients_list.dart +++ b/lib/screens/clients/clients_list.dart @@ -16,12 +16,12 @@ class ClientsList extends StatelessWidget { final bool splitView; const ClientsList({ - Key? key, + super.key, required this.data, required this.onClientSelected, this.selectedClient, required this.splitView, - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/lib/screens/clients/options_modal.dart b/lib/screens/clients/options_modal.dart deleted file mode 100644 index d779aae..0000000 --- a/lib/screens/clients/options_modal.dart +++ /dev/null @@ -1,72 +0,0 @@ -import 'package:flutter/material.dart'; -import 'package:provider/provider.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; - -import 'package:adguard_home_manager/providers/status_provider.dart'; -import 'package:adguard_home_manager/widgets/custom_list_tile_dialog.dart'; - -class OptionsModal extends StatelessWidget { - final void Function() onEdit; - final void Function() onDelete; - - const OptionsModal({ - Key? key, - required this.onDelete, - required this.onEdit, - }) : super(key: key); - - @override - Widget build(BuildContext context) { - final statusProvider = Provider.of(context); - - return AlertDialog( - contentPadding: const EdgeInsets.symmetric( - horizontal: 0, - vertical: 16 - ), - title: Column( - children: [ - Icon( - Icons.more_horiz, - color: Theme.of(context).listTileTheme.iconColor - ), - const SizedBox(height: 16), - Text( - AppLocalizations.of(context)!.options, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface - ), - ) - ], - ), - content: Column( - mainAxisSize: MainAxisSize.min, - children: [ - const SizedBox(height: 24), - if (statusProvider.serverStatus != null) CustomListTileDialog( - onTap: () { - Navigator.pop(context); - onEdit(); - }, - title: AppLocalizations.of(context)!.edit, - icon: Icons.edit, - ), - CustomListTileDialog( - onTap: () { - Navigator.pop(context); - onDelete(); - }, - title: AppLocalizations.of(context)!.delete, - icon: Icons.delete, - ), - ], - ), - actions: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: Text(AppLocalizations.of(context)!.close) - ) - ], - ); - } -} \ No newline at end of file diff --git a/lib/screens/clients/search_clients.dart b/lib/screens/clients/search_clients.dart index 895f458..d8e1104 100644 --- a/lib/screens/clients/search_clients.dart +++ b/lib/screens/clients/search_clients.dart @@ -7,11 +7,12 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:adguard_home_manager/screens/clients/client/remove_client_modal.dart'; import 'package:adguard_home_manager/screens/clients/client/client_screen_functions.dart'; -import 'package:adguard_home_manager/screens/clients/options_modal.dart'; +import 'package:adguard_home_manager/widgets/options_menu.dart'; import 'package:adguard_home_manager/widgets/section_label.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; +import 'package:adguard_home_manager/models/menu_option.dart'; import 'package:adguard_home_manager/classes/process_modal.dart'; import 'package:adguard_home_manager/functions/snackbar.dart'; import 'package:adguard_home_manager/providers/app_config_provider.dart'; @@ -151,15 +152,15 @@ class _SearchClientsState extends State { ); } - void openOptionsModal(Client client) { - showModal( - context: context, - builder: (ctx) => OptionsModal( - onDelete: () => openDeleteModal(client), - onEdit: () => openClientModal(client), - ) - ); - } + // void openOptionsModal(Client client) { + // showModal( + // context: context, + // builder: (ctx) => OptionsModal( + // onDelete: () => openDeleteModal(client), + // onEdit: () => openClientModal(client), + // ) + // ); + // } return Scaffold( appBar: AppBar( @@ -224,82 +225,96 @@ class _SearchClientsState extends State { primary: false, itemCount: clientsScreen.length, padding: const EdgeInsets.only(bottom: 0), - itemBuilder: (context, index) => ListTile( - contentPadding: index == 0 - ? const EdgeInsets.only(left: 20, right: 20, bottom: 15) - : const EdgeInsets.symmetric(horizontal: 20, vertical: 15), - isThreeLine: true, - onLongPress: () => openOptionsModal(clientsScreen[index]), - onTap: statusProvider.serverStatus != null - ? () => openClientModal(clientsScreen[index]) - : null, - title: Padding( - padding: const EdgeInsets.only(bottom: 5), - child: Text( - clientsScreen[index].name, - style: const TextStyle( - fontSize: 18, - fontWeight: FontWeight.normal + itemBuilder: (context, index) => OptionsMenu( + options: [ + MenuOption( + icon: Icons.edit_rounded, + title: AppLocalizations.of(context)!.edit, + action: (v) => openClientModal(v) + ), + MenuOption( + icon: Icons.delete_rounded, + title: AppLocalizations.of(context)!.delete, + action: (v) => openDeleteModal(v) + ), + ], + value: clientsScreen[index], + child: ListTile( + contentPadding: index == 0 + ? const EdgeInsets.only(left: 20, right: 20, bottom: 15) + : const EdgeInsets.symmetric(horizontal: 20, vertical: 15), + isThreeLine: true, + onTap: statusProvider.serverStatus != null + ? () => openClientModal(clientsScreen[index]) + : null, + title: Padding( + padding: const EdgeInsets.only(bottom: 5), + child: Text( + clientsScreen[index].name, + style: const TextStyle( + fontSize: 18, + fontWeight: FontWeight.normal + ), ), ), - ), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text(clientsScreen[index].ids.toString().replaceAll(RegExp(r'^\[|\]$'), '')), - const SizedBox(height: 7), - Row( - children: [ - Icon( - Icons.filter_list_rounded, - size: 19, - color: clientsScreen[index].filteringEnabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red, - ), - const SizedBox(width: 10), - Icon( - Icons.vpn_lock_rounded, - size: 18, - color: clientsScreen[index].safebrowsingEnabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red, - ), - const SizedBox(width: 10), - Icon( - Icons.block, - size: 18, - color: clientsScreen[index].parentalEnabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red, - ), - const SizedBox(width: 10), - Icon( - Icons.search_rounded, - size: 19, - color: clientsScreen[index].safeSearch != null && clientsScreen[index].safeSearch!.enabled == true - ? appConfigProvider.useThemeColorForStatus == true - ? Theme.of(context).colorScheme.primary - : Colors.green - : appConfigProvider.useThemeColorForStatus == true - ? Colors.grey - : Colors.red - ) - ], - ) - ], + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(clientsScreen[index].ids.toString().replaceAll(RegExp(r'^\[|\]$'), '')), + const SizedBox(height: 7), + Row( + children: [ + Icon( + Icons.filter_list_rounded, + size: 19, + color: clientsScreen[index].filteringEnabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red, + ), + const SizedBox(width: 10), + Icon( + Icons.vpn_lock_rounded, + size: 18, + color: clientsScreen[index].safebrowsingEnabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red, + ), + const SizedBox(width: 10), + Icon( + Icons.block, + size: 18, + color: clientsScreen[index].parentalEnabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red, + ), + const SizedBox(width: 10), + Icon( + Icons.search_rounded, + size: 19, + color: clientsScreen[index].safeSearch != null && clientsScreen[index].safeSearch!.enabled == true + ? appConfigProvider.useThemeColorForStatus == true + ? Theme.of(context).colorScheme.primary + : Colors.green + : appConfigProvider.useThemeColorForStatus == true + ? Colors.grey + : Colors.red + ) + ], + ) + ], + ), ), ) ) diff --git a/lib/screens/filters/filters_triple_column.dart b/lib/screens/filters/filters_triple_column.dart index 2042068..3401bac 100644 --- a/lib/screens/filters/filters_triple_column.dart +++ b/lib/screens/filters/filters_triple_column.dart @@ -7,10 +7,10 @@ import 'package:contextmenu/contextmenu.dart'; import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:adguard_home_manager/widgets/options_menu.dart'; import 'package:adguard_home_manager/screens/filters/add_button.dart'; import 'package:adguard_home_manager/screens/filters/list_options_menu.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; -import 'package:adguard_home_manager/widgets/options_modal.dart'; import 'package:adguard_home_manager/constants/enums.dart'; import 'package:adguard_home_manager/functions/desktop_mode.dart'; @@ -28,11 +28,11 @@ class FiltersTripleColumn extends StatelessWidget { final List actions; const FiltersTripleColumn({ - Key? key, + super.key, required this.onRemoveCustomRule, required this.onOpenDetailsModal, required this.actions, - }) : super(key: key); + }); @override Widget build(BuildContext context) { @@ -282,28 +282,25 @@ class FiltersTripleColumn extends StatelessWidget { } ), ], - child: CustomListTile( - onLongPress: () => showDialog( - context: context, - builder: (context) => OptionsModal( - options: [ - MenuOption( - title: AppLocalizations.of(context)!.copyClipboard, - icon: Icons.copy_rounded, - action: (_) => copyToClipboard( - value: filteringProvider.filtering!.userRules[index], - successMessage: AppLocalizations.of(context)!.copiedClipboard, - ) - ) - ] + child: OptionsMenu( + options: [ + MenuOption( + title: AppLocalizations.of(context)!.copyClipboard, + icon: Icons.copy_rounded, + action: (_) => copyToClipboard( + value: filteringProvider.filtering!.userRules[index], + successMessage: AppLocalizations.of(context)!.copiedClipboard, + ) ) - ), - title: filteringProvider.filtering!.userRules[index], - subtitleWidget: generateSubtitle(filteringProvider.filtering!.userRules[index]), - trailing: IconButton( - onPressed: () => onRemoveCustomRule(filteringProvider.filtering!.userRules[index]), - icon: const Icon(Icons.delete), - tooltip: AppLocalizations.of(context)!.delete, + ], + child: CustomListTile( + title: filteringProvider.filtering!.userRules[index], + subtitleWidget: generateSubtitle(filteringProvider.filtering!.userRules[index]), + trailing: IconButton( + onPressed: () => onRemoveCustomRule(filteringProvider.filtering!.userRules[index]), + icon: const Icon(Icons.delete), + tooltip: AppLocalizations.of(context)!.delete, + ), ), ), ), diff --git a/lib/screens/filters/list_options_menu.dart b/lib/screens/filters/list_options_menu.dart index f4337a1..4cb6865 100644 --- a/lib/screens/filters/list_options_menu.dart +++ b/lib/screens/filters/list_options_menu.dart @@ -8,7 +8,7 @@ import 'package:provider/provider.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; -import 'package:adguard_home_manager/widgets/options_modal.dart'; +import 'package:adguard_home_manager/widgets/options_menu.dart'; import 'package:adguard_home_manager/screens/filters/selection/selection_screen.dart'; import 'package:adguard_home_manager/functions/open_url.dart'; @@ -144,41 +144,41 @@ class ListOptionsMenu extends StatelessWidget { child: Material( color: Colors.transparent, child: InkWell( - onLongPress: Platform.isAndroid || Platform.isIOS ? () => showDialog( - context: context, - builder: (context) => OptionsModal( - options: [ - MenuOption( - title: list.enabled == true - ? AppLocalizations.of(context)!.disable - : AppLocalizations.of(context)!.enable, - icon: list.enabled == true - ? Icons.gpp_bad_rounded - : Icons.verified_user_rounded, - action: (_) => enableDisable() - ), - MenuOption( - title: AppLocalizations.of(context)!.copyListUrl, - icon: Icons.copy_rounded, - action: (_) => copyToClipboard( - value: list.url, - successMessage: AppLocalizations.of(context)!.listUrlCopied - ) - ), - MenuOption( - title: AppLocalizations.of(context)!.openListUrl, - icon: Icons.open_in_browser_rounded, - action: (_) => openUrl(list.url) - ), - MenuOption( - title: AppLocalizations.of(context)!.selectionMode, - icon: Icons.check_rounded, - action: (_) => openSelectionMode() - ), - ] - ) - ) : null, - child: child + child: OptionsMenu( + options: [ + MenuOption( + title: list.enabled == true + ? AppLocalizations.of(context)!.disable + : AppLocalizations.of(context)!.enable, + icon: list.enabled == true + ? Icons.gpp_bad_rounded + : Icons.verified_user_rounded, + action: (_) => enableDisable() + ), + MenuOption( + title: AppLocalizations.of(context)!.copyListUrl, + icon: Icons.copy_rounded, + action: (_) => copyToClipboard( + value: list.url, + successMessage: AppLocalizations.of(context)!.listUrlCopied + ) + ), + MenuOption( + title: AppLocalizations.of(context)!.openListUrl, + icon: Icons.open_in_browser_rounded, + action: (_) => openUrl(list.url) + ), + MenuOption( + title: AppLocalizations.of(context)!.selectionMode, + icon: Icons.check_rounded, + action: (_) => Future.delayed( + const Duration(milliseconds: 0), + () => openSelectionMode() + ) + ), + ], + child: child + ) ), ), ); diff --git a/lib/widgets/custom_list_tile_dialog.dart b/lib/widgets/custom_list_tile_dialog.dart index 1d09760..2e3cff4 100644 --- a/lib/widgets/custom_list_tile_dialog.dart +++ b/lib/widgets/custom_list_tile_dialog.dart @@ -6,11 +6,11 @@ class CustomListTileDialog extends StatelessWidget { final void Function()? onTap; const CustomListTileDialog({ - Key? key, + super.key, required this.title, this.icon, this.onTap - }) : super(key: key); + }); @override Widget build(BuildContext context) { diff --git a/lib/widgets/options_menu.dart b/lib/widgets/options_menu.dart index 34b755b..b6f6ec7 100644 --- a/lib/widgets/options_menu.dart +++ b/lib/widgets/options_menu.dart @@ -2,8 +2,9 @@ import 'dart:io'; import 'package:contextmenu/contextmenu.dart'; import 'package:flutter/material.dart'; +import 'package:flutter_gen/gen_l10n/app_localizations.dart'; -import 'package:adguard_home_manager/widgets/options_modal.dart'; +import 'package:adguard_home_manager/widgets/custom_list_tile_dialog.dart'; import 'package:adguard_home_manager/widgets/custom_list_tile.dart'; import 'package:adguard_home_manager/models/menu_option.dart'; @@ -29,7 +30,7 @@ class OptionsMenu extends StatelessWidget { void openOptionsModal() { showDialog( context: context, - builder: (context) => OptionsModal( + builder: (context) => _OptionsModal( options: options, value: value ) @@ -60,4 +61,66 @@ class OptionsMenu extends StatelessWidget { ), ); } +} + +class _OptionsModal extends StatelessWidget { + final List options; + final dynamic value; + + const _OptionsModal({ + super.key, + required this.options, + this.value, + }); + + @override + Widget build(BuildContext context) { + return AlertDialog( + contentPadding: const EdgeInsets.symmetric(vertical: 16), + title: Column( + children: [ + Icon( + Icons.more_horiz, + size: 24, + color: Theme.of(context).listTileTheme.iconColor + ), + const SizedBox(height: 16), + Text( + AppLocalizations.of(context)!.options, + style: TextStyle( + color: Theme.of(context).colorScheme.onSurface + ), + ) + ], + ), + content: ConstrainedBox( + constraints: const BoxConstraints( + maxWidth: 400 + ), + child: SingleChildScrollView( + child: Wrap( + children: options.map((opt) => CustomListTileDialog( + title: opt.title, + icon: opt.icon, + onTap: () { + Navigator.pop(context); + opt.action(value); + }, + )).toList() + ), + ), + ), + actions: [ + Row( + mainAxisAlignment: MainAxisAlignment.end, + children: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: Text(AppLocalizations.of(context)!.cancel) + ) + ], + ) + ], + ); + } } \ No newline at end of file diff --git a/lib/widgets/options_modal.dart b/lib/widgets/options_modal.dart deleted file mode 100644 index 102f7ca..0000000 --- a/lib/widgets/options_modal.dart +++ /dev/null @@ -1,67 +0,0 @@ -import 'package:adguard_home_manager/models/menu_option.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_gen/gen_l10n/app_localizations.dart'; - -import 'package:adguard_home_manager/widgets/custom_list_tile_dialog.dart'; - -class OptionsModal extends StatelessWidget { - final List options; - final dynamic value; - - const OptionsModal({ - super.key, - required this.options, - this.value, - }); - - @override - Widget build(BuildContext context) { - return AlertDialog( - contentPadding: const EdgeInsets.symmetric(vertical: 16), - title: Column( - children: [ - Icon( - Icons.more_horiz, - size: 24, - color: Theme.of(context).listTileTheme.iconColor - ), - const SizedBox(height: 16), - Text( - AppLocalizations.of(context)!.options, - style: TextStyle( - color: Theme.of(context).colorScheme.onSurface - ), - ) - ], - ), - content: ConstrainedBox( - constraints: const BoxConstraints( - maxWidth: 400 - ), - child: SingleChildScrollView( - child: Wrap( - children: options.map((opt) => CustomListTileDialog( - title: opt.title, - icon: opt.icon, - onTap: () { - Navigator.pop(context); - opt.action(value); - }, - )).toList() - ), - ), - ), - actions: [ - Row( - mainAxisAlignment: MainAxisAlignment.end, - children: [ - TextButton( - onPressed: () => Navigator.pop(context), - child: Text(AppLocalizations.of(context)!.cancel) - ) - ], - ) - ], - ); - } -} \ No newline at end of file