2023-05-01 21:34:00 +02:00
|
|
|
import 'package:flutter/material.dart';
|
2023-05-04 22:38:37 +02:00
|
|
|
import 'package:contextmenu/contextmenu.dart';
|
2023-05-01 21:34:00 +02:00
|
|
|
import 'package:provider/provider.dart';
|
2023-05-04 22:38:37 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
2023-05-01 21:34:00 +02:00
|
|
|
|
|
|
|
import 'package:adguard_home_manager/widgets/custom_list_tile.dart';
|
|
|
|
|
2023-11-02 18:26:58 +01:00
|
|
|
import 'package:adguard_home_manager/providers/status_provider.dart';
|
2023-05-01 21:34:00 +02:00
|
|
|
import 'package:adguard_home_manager/functions/compare_versions.dart';
|
2023-05-04 22:38:37 +02:00
|
|
|
import 'package:adguard_home_manager/functions/copy_clipboard.dart';
|
2023-05-01 21:34:00 +02:00
|
|
|
import 'package:adguard_home_manager/models/clients.dart';
|
|
|
|
import 'package:adguard_home_manager/providers/app_config_provider.dart';
|
|
|
|
|
2023-05-04 22:38:37 +02:00
|
|
|
class AddedClientTile extends StatelessWidget {
|
2023-05-01 21:34:00 +02:00
|
|
|
final Client client;
|
|
|
|
final void Function(Client) onTap;
|
|
|
|
final void Function(Client) onLongPress;
|
2023-10-08 00:05:38 +02:00
|
|
|
final void Function(Client)? onEdit;
|
2023-10-07 23:03:30 +02:00
|
|
|
final void Function(Client) onDelete;
|
2023-05-01 21:34:00 +02:00
|
|
|
final Client? selectedClient;
|
|
|
|
final bool? splitView;
|
|
|
|
|
|
|
|
const AddedClientTile({
|
|
|
|
Key? key,
|
|
|
|
required this.client,
|
|
|
|
required this.onTap,
|
|
|
|
required this.onLongPress,
|
2023-10-08 00:05:38 +02:00
|
|
|
this.onEdit,
|
2023-10-07 23:03:30 +02:00
|
|
|
required this.onDelete,
|
2023-05-01 21:34:00 +02:00
|
|
|
this.selectedClient,
|
2023-05-12 23:11:38 +02:00
|
|
|
required this.splitView,
|
2023-05-01 21:34:00 +02:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-11-02 18:26:58 +01:00
|
|
|
final statusProvider = Provider.of<StatusProvider>(context);
|
2023-05-01 21:34:00 +02:00
|
|
|
final appConfigProvider = Provider.of<AppConfigProvider>(context);
|
|
|
|
|
2023-05-04 22:38:37 +02:00
|
|
|
if (splitView == true) {
|
2023-05-01 21:34:00 +02:00
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12),
|
|
|
|
child: Material(
|
|
|
|
color: Colors.transparent,
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
2023-05-04 22:38:37 +02:00
|
|
|
child: ContextMenuArea(
|
|
|
|
builder: (context) => [
|
2023-10-08 00:05:38 +02:00
|
|
|
if (onEdit != null) CustomListTile(
|
2023-10-07 23:03:30 +02:00
|
|
|
title: AppLocalizations.of(context)!.edit,
|
|
|
|
icon: Icons.edit_rounded,
|
2023-05-04 22:38:37 +02:00
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
2023-10-08 00:05:38 +02:00
|
|
|
onEdit!(client);
|
2023-05-04 22:38:37 +02:00
|
|
|
}
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
2023-10-07 23:03:30 +02:00
|
|
|
CustomListTile(
|
|
|
|
title: AppLocalizations.of(context)!.delete,
|
|
|
|
icon: Icons.delete_rounded,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
|
|
|
onDelete(client);
|
|
|
|
}
|
|
|
|
),
|
2023-05-04 22:38:37 +02:00
|
|
|
CustomListTile(
|
|
|
|
title: AppLocalizations.of(context)!.copyClipboard,
|
|
|
|
icon: Icons.copy_rounded,
|
|
|
|
onTap: () {
|
|
|
|
copyToClipboard(
|
|
|
|
value: client.ids.toString().replaceAll(RegExp(r'^\[|\]$'), ''),
|
|
|
|
successMessage: AppLocalizations.of(context)!.copiedClipboard,
|
|
|
|
);
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: InkWell(
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
onTap: () => onTap(client),
|
|
|
|
onLongPress: () => onLongPress(client),
|
|
|
|
child: Container(
|
|
|
|
width: double.maxFinite,
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 12),
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(28),
|
|
|
|
color: client == selectedClient
|
|
|
|
? Theme.of(context).colorScheme.primaryContainer
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: Row(
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
children: [
|
|
|
|
Flexible(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
client.ids.toString().replaceAll(RegExp(r'^\[|\]$'), ''),
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 16,
|
|
|
|
fontWeight: FontWeight.w400,
|
|
|
|
color: Theme.of(context).colorScheme.onSurface,
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
2023-05-04 22:38:37 +02:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.filter_list_rounded,
|
|
|
|
size: 19,
|
|
|
|
color: client.filteringEnabled == true
|
2023-05-01 21:34:00 +02:00
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
2023-05-04 22:38:37 +02:00
|
|
|
: Colors.red,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Icon(
|
|
|
|
Icons.vpn_lock_rounded,
|
|
|
|
size: 18,
|
|
|
|
color: client.safebrowsingEnabled == true
|
2023-05-01 21:34:00 +02:00
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
2023-05-04 22:38:37 +02:00
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Icon(
|
|
|
|
Icons.block,
|
|
|
|
size: 18,
|
|
|
|
color: client.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: serverVersionIsAhead(
|
2023-11-02 18:26:58 +01:00
|
|
|
currentVersion: statusProvider.serverStatus!.serverVersion,
|
2023-05-04 22:38:37 +02:00
|
|
|
referenceVersion: 'v0.107.28',
|
|
|
|
referenceVersionBeta: 'v0.108.0-b.33'
|
|
|
|
) == true
|
|
|
|
? client.safeSearch != null && client.safeSearch!.enabled == true
|
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red
|
|
|
|
: client.safesearchEnabled == true
|
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
2023-05-04 22:38:37 +02:00
|
|
|
],
|
|
|
|
)
|
|
|
|
),
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
else {
|
2023-05-04 22:38:37 +02:00
|
|
|
return ContextMenuArea(
|
|
|
|
builder: (context) => [
|
2023-10-08 00:05:38 +02:00
|
|
|
if (onEdit != null) CustomListTile(
|
2023-05-04 22:38:37 +02:00
|
|
|
title: AppLocalizations.of(context)!.seeDetails,
|
|
|
|
icon: Icons.file_open_rounded,
|
|
|
|
onTap: () {
|
|
|
|
Navigator.pop(context);
|
2023-10-08 00:05:38 +02:00
|
|
|
onEdit!(client);
|
2023-05-04 22:38:37 +02:00
|
|
|
}
|
|
|
|
),
|
|
|
|
CustomListTile(
|
|
|
|
title: AppLocalizations.of(context)!.copyClipboard,
|
|
|
|
icon: Icons.copy_rounded,
|
|
|
|
onTap: () {
|
|
|
|
copyToClipboard(
|
|
|
|
value: client.ids.toString().replaceAll(RegExp(r'^\[|\]$'), ''),
|
|
|
|
successMessage: AppLocalizations.of(context)!.copiedClipboard,
|
|
|
|
);
|
|
|
|
Navigator.pop(context);
|
|
|
|
}
|
|
|
|
),
|
|
|
|
],
|
|
|
|
child: CustomListTile(
|
|
|
|
onLongPress: () => onLongPress(client),
|
|
|
|
onTap: () => onTap(client),
|
|
|
|
title: client.name,
|
|
|
|
subtitleWidget: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: [
|
|
|
|
Text(
|
|
|
|
client.ids.toString().replaceAll(RegExp(r'^\[|\]$'), ''),
|
|
|
|
style: TextStyle(
|
|
|
|
color: Theme.of(context).listTileTheme.textColor
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
2023-05-04 22:38:37 +02:00
|
|
|
),
|
|
|
|
const SizedBox(height: 8),
|
|
|
|
Row(
|
|
|
|
children: [
|
|
|
|
Icon(
|
|
|
|
Icons.filter_list_rounded,
|
|
|
|
size: 19,
|
|
|
|
color: client.filteringEnabled == true
|
2023-05-01 21:34:00 +02:00
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
2023-05-04 22:38:37 +02:00
|
|
|
: Colors.red,
|
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Icon(
|
|
|
|
Icons.vpn_lock_rounded,
|
|
|
|
size: 18,
|
|
|
|
color: client.safebrowsingEnabled == true
|
2023-05-01 21:34:00 +02:00
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
2023-05-04 22:38:37 +02:00
|
|
|
),
|
|
|
|
const SizedBox(width: 10),
|
|
|
|
Icon(
|
|
|
|
Icons.block,
|
|
|
|
size: 18,
|
|
|
|
color: client.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: serverVersionIsAhead(
|
2023-11-02 18:26:58 +01:00
|
|
|
currentVersion: statusProvider.serverStatus!.serverVersion,
|
2023-05-04 22:38:37 +02:00
|
|
|
referenceVersion: 'v0.107.28',
|
|
|
|
referenceVersionBeta: 'v0.108.0-b.33'
|
|
|
|
) == true
|
|
|
|
? client.safeSearch != null && client.safeSearch!.enabled == true
|
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red
|
|
|
|
: client.safesearchEnabled == true
|
|
|
|
? appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Theme.of(context).colorScheme.primary
|
|
|
|
: Colors.green
|
|
|
|
: appConfigProvider.useThemeColorForStatus == true
|
|
|
|
? Colors.grey
|
|
|
|
: Colors.red,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2023-05-01 21:34:00 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|