2025-03-09 19:45:48 +01:00
|
|
|
import 'package:adguard_home_manager/constants/regexps.dart';
|
2024-01-24 13:55:15 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2024-01-24 15:14:19 +01:00
|
|
|
import 'package:uuid/uuid.dart';
|
2024-01-24 13:55:15 +01:00
|
|
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
|
|
|
|
2024-01-24 15:14:19 +01:00
|
|
|
import 'package:adguard_home_manager/screens/settings/logs_settings/logs_settings.dart';
|
|
|
|
import 'package:adguard_home_manager/widgets/section_label.dart';
|
2024-01-28 20:39:42 +01:00
|
|
|
import 'package:adguard_home_manager/widgets/master_switch.dart';
|
2024-01-24 13:55:15 +01:00
|
|
|
import 'package:adguard_home_manager/widgets/custom_checkbox_list_tile.dart';
|
|
|
|
|
|
|
|
class LogsConfigOptions extends StatelessWidget {
|
|
|
|
final bool generalSwitch;
|
|
|
|
final void Function(bool) updateGeneralSwitch;
|
|
|
|
final bool anonymizeClientIp;
|
|
|
|
final void Function(bool) updateAnonymizeClientIp;
|
2025-01-21 20:47:24 +01:00
|
|
|
final List<String> retentionItems;
|
|
|
|
final String? retentionTime;
|
|
|
|
final void Function(String?) updateRetentionTime;
|
2024-01-24 13:55:15 +01:00
|
|
|
final void Function() onClear;
|
|
|
|
final void Function() onConfirm;
|
2024-01-24 15:14:19 +01:00
|
|
|
final List<DomainListItemController> ignoredDomainsControllers;
|
|
|
|
final void Function(List<DomainListItemController>) updateIgnoredDomainsControllers;
|
2025-01-21 20:47:24 +01:00
|
|
|
final TextEditingController customTimeController;
|
|
|
|
final String? customTimeError;
|
|
|
|
final void Function(String) validateCustomTime;
|
2024-01-24 13:55:15 +01:00
|
|
|
|
|
|
|
const LogsConfigOptions({
|
|
|
|
super.key,
|
|
|
|
required this.generalSwitch,
|
|
|
|
required this.updateGeneralSwitch,
|
|
|
|
required this.anonymizeClientIp,
|
|
|
|
required this.updateAnonymizeClientIp,
|
|
|
|
required this.retentionItems,
|
|
|
|
required this.retentionTime,
|
|
|
|
required this.updateRetentionTime,
|
|
|
|
required this.onClear,
|
2024-01-24 15:14:19 +01:00
|
|
|
required this.onConfirm,
|
|
|
|
required this.ignoredDomainsControllers,
|
2025-01-21 20:47:24 +01:00
|
|
|
required this.updateIgnoredDomainsControllers,
|
|
|
|
required this.customTimeController,
|
|
|
|
required this.customTimeError,
|
|
|
|
required this.validateCustomTime,
|
2024-01-24 13:55:15 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2024-01-24 15:14:19 +01:00
|
|
|
const Uuid uuid = Uuid();
|
|
|
|
|
2024-01-24 13:55:15 +01:00
|
|
|
final List<String> dropdownItemTranslation = [
|
2025-01-21 20:47:24 +01:00
|
|
|
AppLocalizations.of(context)!.custom,
|
2024-01-24 13:55:15 +01:00
|
|
|
AppLocalizations.of(context)!.hours6,
|
|
|
|
AppLocalizations.of(context)!.hours24,
|
|
|
|
AppLocalizations.of(context)!.days7,
|
|
|
|
AppLocalizations.of(context)!.days30,
|
|
|
|
AppLocalizations.of(context)!.days90,
|
|
|
|
];
|
|
|
|
|
2024-01-24 15:14:19 +01:00
|
|
|
void validateDomain(String value, String id) {
|
|
|
|
bool error = false;
|
2025-03-09 19:45:48 +01:00
|
|
|
if (Regexps.domain.hasMatch(value)) {
|
2024-01-24 15:14:19 +01:00
|
|
|
error = false;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
error = true;
|
|
|
|
}
|
|
|
|
updateIgnoredDomainsControllers(
|
|
|
|
ignoredDomainsControllers.map((entry) {
|
|
|
|
if (entry.id != id) return entry;
|
|
|
|
return DomainListItemController(
|
|
|
|
id: id,
|
|
|
|
controller: entry.controller,
|
|
|
|
error: error
|
|
|
|
);
|
|
|
|
}).toList()
|
|
|
|
);
|
|
|
|
}
|
2025-01-21 20:47:24 +01:00
|
|
|
print(retentionTime);
|
2024-01-24 15:14:19 +01:00
|
|
|
return ListView(
|
2024-01-24 13:55:15 +01:00
|
|
|
children: [
|
|
|
|
const SizedBox(height: 16),
|
2024-01-28 20:39:42 +01:00
|
|
|
MasterSwitch(
|
|
|
|
label: AppLocalizations.of(context)!.enableLog,
|
|
|
|
value: generalSwitch,
|
|
|
|
onChange: updateGeneralSwitch
|
2024-01-24 13:55:15 +01:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
CustomCheckboxListTile(
|
|
|
|
value: anonymizeClientIp,
|
|
|
|
onChanged: (_) => updateAnonymizeClientIp(!anonymizeClientIp),
|
|
|
|
title: AppLocalizations.of(context)!.anonymizeClientIp,
|
2024-01-28 20:39:42 +01:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
|
2024-01-24 13:55:15 +01:00
|
|
|
),
|
|
|
|
const SizedBox(height: 16),
|
|
|
|
Padding(
|
2024-01-28 20:39:42 +01:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16),
|
2024-01-24 13:55:15 +01:00
|
|
|
child: DropdownButtonFormField(
|
|
|
|
items: retentionItems.asMap().entries.map((item) => DropdownMenuItem(
|
|
|
|
value: item.value,
|
|
|
|
child: Text(dropdownItemTranslation[item.key]),
|
|
|
|
)).toList(),
|
|
|
|
value: retentionTime,
|
2025-01-21 20:47:24 +01:00
|
|
|
onChanged: (value) => updateRetentionTime(value.toString()),
|
2024-01-24 13:55:15 +01:00
|
|
|
decoration: InputDecoration(
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
label: Text(AppLocalizations.of(context)!.retentionTime)
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(20),
|
|
|
|
),
|
2025-01-21 20:47:24 +01:00
|
|
|
),
|
|
|
|
if (retentionTime == "custom") Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24, left: 16, right: 16),
|
|
|
|
child: TextFormField(
|
|
|
|
controller: customTimeController,
|
|
|
|
onChanged: validateCustomTime,
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.schedule_rounded),
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
labelText: AppLocalizations.of(context)!.customTimeInHours,
|
|
|
|
errorText: customTimeError
|
|
|
|
),
|
|
|
|
keyboardType: TextInputType.number,
|
|
|
|
),
|
2024-01-24 13:55:15 +01:00
|
|
|
),
|
2024-01-24 15:14:19 +01:00
|
|
|
Padding(
|
|
|
|
padding: const EdgeInsets.only(top: 24, bottom: 8),
|
|
|
|
child: Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
children: [
|
|
|
|
SectionLabel(
|
|
|
|
label: AppLocalizations.of(context)!.ignoredDomains,
|
2024-01-28 20:39:42 +01:00
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 0),
|
2024-01-24 15:14:19 +01:00
|
|
|
),
|
|
|
|
Padding(
|
2024-01-28 20:39:42 +01:00
|
|
|
padding: const EdgeInsets.only(right: 6),
|
2024-01-24 15:14:19 +01:00
|
|
|
child: IconButton(
|
|
|
|
onPressed: () => updateIgnoredDomainsControllers([
|
|
|
|
...ignoredDomainsControllers,
|
|
|
|
DomainListItemController(
|
|
|
|
id: uuid.v4(),
|
|
|
|
controller: TextEditingController(),
|
|
|
|
error: false
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
icon: const Icon(Icons.add)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
if (ignoredDomainsControllers.isNotEmpty) ...ignoredDomainsControllers.map((controller) => Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
2024-01-28 20:39:42 +01:00
|
|
|
top: 12, bottom: 12, left: 16, right: 6
|
2024-01-24 15:14:19 +01:00
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
Expanded(
|
|
|
|
child: TextFormField(
|
|
|
|
controller: controller.controller,
|
|
|
|
onChanged: (v) => validateDomain(v, controller.id),
|
|
|
|
decoration: InputDecoration(
|
|
|
|
prefixIcon: const Icon(Icons.link_rounded),
|
|
|
|
border: const OutlineInputBorder(
|
|
|
|
borderRadius: BorderRadius.all(
|
|
|
|
Radius.circular(10)
|
|
|
|
)
|
|
|
|
),
|
|
|
|
labelText: AppLocalizations.of(context)!.domain,
|
|
|
|
errorText: controller.error
|
|
|
|
? AppLocalizations.of(context)!.invalidDomain
|
|
|
|
: null
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
const SizedBox(width: 12),
|
|
|
|
Padding(
|
|
|
|
padding: controller.error
|
|
|
|
? const EdgeInsets.only(bottom: 24)
|
|
|
|
: const EdgeInsets.all(0),
|
|
|
|
child: IconButton(
|
|
|
|
onPressed: () => updateIgnoredDomainsControllers(
|
|
|
|
ignoredDomainsControllers.where((e) => e.id != controller.id).toList()
|
|
|
|
),
|
|
|
|
icon: const Icon(Icons.remove_circle_outline_outlined)
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
if (ignoredDomainsControllers.isEmpty) Container(
|
|
|
|
padding: const EdgeInsets.symmetric(vertical: 16),
|
|
|
|
child: Text(
|
|
|
|
AppLocalizations.of(context)!.noIgnoredDomainsAdded,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
style: TextStyle(
|
|
|
|
fontSize: 18,
|
|
|
|
color: Theme.of(context).colorScheme.onSurfaceVariant,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
2024-01-24 13:55:15 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|