mirror of
https://github.com/JGeek00/adguard-home-manager.git
synced 2025-04-24 07:46:06 +00:00
Added add filter lists
This commit is contained in:
parent
d12a1134f0
commit
6a285bf213
10 changed files with 522 additions and 83 deletions
|
@ -216,5 +216,17 @@
|
||||||
"ruleRemovedSuccessfully": "Rule removed successfully",
|
"ruleRemovedSuccessfully": "Rule removed successfully",
|
||||||
"ruleNotRemoved": "Couldn't remove the rule",
|
"ruleNotRemoved": "Couldn't remove the rule",
|
||||||
"ruleAddedSuccessfully": "Rule added successfully",
|
"ruleAddedSuccessfully": "Rule added successfully",
|
||||||
"ruleNotAdded": "Couldn't add the rule,"
|
"ruleNotAdded": "Couldn't add the rule",
|
||||||
|
"noCustomFilters": "No custom filters",
|
||||||
|
"noBlackLists": "No blacklists",
|
||||||
|
"noWhiteLists": "No whitelists",
|
||||||
|
"addWhitelist": "Add whitelist",
|
||||||
|
"addBlacklist": "Add blacklist",
|
||||||
|
"urlNotValid": "URL is not valid",
|
||||||
|
"urlAbsolutePath": "URL or absolute path",
|
||||||
|
"addingList": "Adding list...",
|
||||||
|
"listAdded": "List added successfully. Items added:",
|
||||||
|
"listAlreadyAdded": "List already added",
|
||||||
|
"listUrlInvalid": "List URL invalid",
|
||||||
|
"listNotAdded": "List couldn't be added"
|
||||||
}
|
}
|
|
@ -216,5 +216,17 @@
|
||||||
"ruleRemovedSuccessfully": "Regla eliminada correctamente",
|
"ruleRemovedSuccessfully": "Regla eliminada correctamente",
|
||||||
"ruleNotRemoved": "No se ha podido eliminar la regla",
|
"ruleNotRemoved": "No se ha podido eliminar la regla",
|
||||||
"ruleAddedSuccessfully": "Regla añadida correctamente",
|
"ruleAddedSuccessfully": "Regla añadida correctamente",
|
||||||
"ruleNotAdded": "No se ha podido añadir la regla"
|
"ruleNotAdded": "No se ha podido añadir la regla",
|
||||||
|
"noCustomFilters": "No custom filters",
|
||||||
|
"noBlackLists": "No hay listas negras",
|
||||||
|
"noWhiteLists": "No hay listas blancas",
|
||||||
|
"addWhitelist": "Añadir lista blanca",
|
||||||
|
"addBlacklist": "Añadir lista negra",
|
||||||
|
"urlNotValid": "La URL no es válida",
|
||||||
|
"urlAbsolutePath": "URL o ruta absoluta",
|
||||||
|
"addingList": "Añadiendo lista...",
|
||||||
|
"listAdded": "Lista añadida correctamente. Items añadidos:",
|
||||||
|
"listAlreadyAdded": "La lista ya estaba añadida",
|
||||||
|
"listUrlInvalid": "URL de la lista no válida",
|
||||||
|
"listNotAdded": "La lista no se pudo añadir"
|
||||||
}
|
}
|
|
@ -30,9 +30,9 @@ class FilteringData {
|
||||||
});
|
});
|
||||||
|
|
||||||
factory FilteringData.fromJson(Map<String, dynamic> json) => FilteringData(
|
factory FilteringData.fromJson(Map<String, dynamic> json) => FilteringData(
|
||||||
filters: List<Filter>.from(json["filters"].map((x) => Filter.fromJson(x))),
|
filters: json["filters"] != null ? List<Filter>.from(json["filters"].map((x) => Filter.fromJson(x))) : [],
|
||||||
whitelistFilters: List<Filter>.from(json["whitelist_filters"].map((x) => Filter.fromJson(x))),
|
whitelistFilters: json["whitelist_filters"] != null ? List<Filter>.from(json["whitelist_filters"].map((x) => Filter.fromJson(x))) : [],
|
||||||
userRules: List<String>.from(json["user_rules"].map((x) => x)),
|
userRules: json["user_rules"] != null ? List<String>.from(json["user_rules"].map((x) => x)) : [],
|
||||||
interval: json["interval"],
|
interval: json["interval"],
|
||||||
enabled: json["enabled"],
|
enabled: json["enabled"],
|
||||||
);
|
);
|
||||||
|
|
|
@ -73,9 +73,7 @@ class BlockedList extends StatelessWidget {
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
if (data.isNotEmpty) RefreshIndicator(
|
if (data.isNotEmpty) ListView.builder(
|
||||||
onRefresh: () async {},
|
|
||||||
child: ListView.builder(
|
|
||||||
padding: const EdgeInsets.only(top: 0),
|
padding: const EdgeInsets.only(top: 0),
|
||||||
itemCount: data.length,
|
itemCount: data.length,
|
||||||
itemBuilder: (context, index) => ListTile(
|
itemBuilder: (context, index) => ListTile(
|
||||||
|
@ -93,14 +91,13 @@ class BlockedList extends StatelessWidget {
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
),
|
|
||||||
if (data.isEmpty) SizedBox(
|
if (data.isEmpty) SizedBox(
|
||||||
width: double.maxFinite,
|
width: double.maxFinite,
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
AppLocalizations.of(context)!.noClientsList,
|
AppLocalizations.of(context)!.noCustomFilters,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 24,
|
fontSize: 24,
|
||||||
|
|
143
lib/screens/filters/add_list_modal.dart
Normal file
143
lib/screens/filters/add_list_modal.dart
Normal file
|
@ -0,0 +1,143 @@
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
class AddListModal extends StatefulWidget {
|
||||||
|
final String type;
|
||||||
|
final void Function({required String name, required String url}) onConfirm;
|
||||||
|
|
||||||
|
const AddListModal({
|
||||||
|
Key? key,
|
||||||
|
required this.type,
|
||||||
|
required this.onConfirm,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<AddListModal> createState() => _AddListModalState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _AddListModalState extends State<AddListModal> {
|
||||||
|
final TextEditingController nameController = TextEditingController();
|
||||||
|
final TextEditingController urlController = TextEditingController();
|
||||||
|
String? urlError;
|
||||||
|
|
||||||
|
bool validData = false;
|
||||||
|
|
||||||
|
void checkValidValues() {
|
||||||
|
if (nameController.text != '' && urlController.text != '') {
|
||||||
|
setState(() => validData = true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setState(() => validData = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void validateUrl(String value) {
|
||||||
|
final urlRegex = RegExp(r'^(https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|www\.[a-zA-Z0-9][a-zA-Z0-9-]+[a-zA-Z0-9]\.[^\s]{2,}|https?:\/\/(?:www\.|(?!www))[a-zA-Z0-9]+\.[^\s]{2,}|www\.[a-zA-Z0-9]+\.[^\s]{2,})$');
|
||||||
|
if (urlRegex.hasMatch(value)) {
|
||||||
|
setState(() => urlError = null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final pathRegex = RegExp(r'^(((\\|\/)[a-z0-9^&@{}\[\],$=!\-#\(\)%\.\+~_]+)*(\\|\/))([^\\\/:\*\<>\|]+\.[a-z0-9]+)$');
|
||||||
|
if (pathRegex.hasMatch(value)) {
|
||||||
|
setState(() => urlError = null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
setState(() => urlError = AppLocalizations.of(context)!.urlNotValid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
return Padding(
|
||||||
|
padding: MediaQuery.of(context).viewInsets,
|
||||||
|
child: Container(
|
||||||
|
height: 408,
|
||||||
|
padding: const EdgeInsets.all(24),
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
borderRadius: const BorderRadius.only(
|
||||||
|
topLeft: Radius.circular(28),
|
||||||
|
topRight: Radius.circular(28)
|
||||||
|
),
|
||||||
|
color: Theme.of(context).dialogBackgroundColor
|
||||||
|
),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
Icon(
|
||||||
|
widget.type == 'whitelist'
|
||||||
|
? Icons.verified_user_rounded
|
||||||
|
: Icons.gpp_bad_rounded,
|
||||||
|
size: 26,
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Text(
|
||||||
|
widget.type == 'whitelist'
|
||||||
|
? AppLocalizations.of(context)!.addWhitelist
|
||||||
|
: AppLocalizations.of(context)!.addBlacklist,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
TextFormField(
|
||||||
|
controller: nameController,
|
||||||
|
onChanged: (_) => checkValidValues(),
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.badge_rounded),
|
||||||
|
border: const OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(10)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
labelText: AppLocalizations.of(context)!.name,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
TextFormField(
|
||||||
|
controller: urlController,
|
||||||
|
onChanged: validateUrl,
|
||||||
|
decoration: InputDecoration(
|
||||||
|
prefixIcon: const Icon(Icons.link_rounded),
|
||||||
|
border: const OutlineInputBorder(
|
||||||
|
borderRadius: BorderRadius.all(
|
||||||
|
Radius.circular(10)
|
||||||
|
)
|
||||||
|
),
|
||||||
|
errorText: urlError,
|
||||||
|
labelText: AppLocalizations.of(context)!.urlAbsolutePath,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 20),
|
||||||
|
Expanded(
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text(AppLocalizations.of(context)!.cancel)
|
||||||
|
),
|
||||||
|
const SizedBox(width: 20),
|
||||||
|
TextButton(
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.pop(context);
|
||||||
|
widget.onConfirm(
|
||||||
|
name: nameController.text,
|
||||||
|
url: urlController.text
|
||||||
|
);
|
||||||
|
},
|
||||||
|
child: Text(AppLocalizations.of(context)!.confirm)
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,6 +1,7 @@
|
||||||
// ignore_for_file: use_build_context_synchronously
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
@ -13,14 +14,46 @@ import 'package:adguard_home_manager/services/http_requests.dart';
|
||||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||||
import 'package:adguard_home_manager/classes/process_modal.dart';
|
import 'package:adguard_home_manager/classes/process_modal.dart';
|
||||||
|
|
||||||
class CustomRulesList extends StatelessWidget {
|
class CustomRulesList extends StatefulWidget {
|
||||||
|
final ScrollController scrollController;
|
||||||
final List<String> data;
|
final List<String> data;
|
||||||
|
final void Function() fetchData;
|
||||||
|
|
||||||
const CustomRulesList({
|
const CustomRulesList({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.data
|
required this.scrollController,
|
||||||
|
required this.data,
|
||||||
|
required this.fetchData
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<CustomRulesList> createState() => _CustomRulesListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _CustomRulesListState extends State<CustomRulesList> {
|
||||||
|
late bool isVisible;
|
||||||
|
|
||||||
|
@override
|
||||||
|
initState(){
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
isVisible = true;
|
||||||
|
widget.scrollController.addListener(() {
|
||||||
|
if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) {
|
||||||
|
if (mounted && isVisible == true) {
|
||||||
|
setState(() => isVisible = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) {
|
||||||
|
if (mounted && isVisible == false) {
|
||||||
|
setState(() => isVisible = true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final serversProvider = Provider.of<ServersProvider>(context);
|
final serversProvider = Provider.of<ServersProvider>(context);
|
||||||
|
@ -69,21 +102,47 @@ class CustomRulesList extends StatelessWidget {
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
ListView.builder(
|
if (widget.data.isNotEmpty) ListView.builder(
|
||||||
padding: const EdgeInsets.only(top: 0),
|
padding: const EdgeInsets.only(top: 0),
|
||||||
itemCount: data.length,
|
itemCount: widget.data.length,
|
||||||
itemBuilder: (context, index) => ListTile(
|
itemBuilder: (context, index) => ListTile(
|
||||||
title: Text(data[index]),
|
title: Text(widget.data[index]),
|
||||||
trailing: IconButton(
|
trailing: IconButton(
|
||||||
onPressed: () => openRemoveCustomRuleModal(data[index]),
|
onPressed: () => openRemoveCustomRuleModal(widget.data[index]),
|
||||||
icon: const Icon(Icons.delete)
|
icon: const Icon(Icons.delete)
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
const Positioned(
|
if (widget.data.isEmpty) SizedBox(
|
||||||
bottom: 20,
|
width: double.maxFinite,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
AppLocalizations.of(context)!.noBlackLists,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
color: Colors.grey
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
TextButton.icon(
|
||||||
|
onPressed: widget.fetchData,
|
||||||
|
icon: const Icon(Icons.refresh_rounded),
|
||||||
|
label: Text(AppLocalizations.of(context)!.refresh),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
AnimatedPositioned(
|
||||||
|
duration: const Duration(milliseconds: 100),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
bottom: isVisible ? 20 : -70,
|
||||||
right: 20,
|
right: 20,
|
||||||
child: FiltersFab()
|
child: const FiltersFab(
|
||||||
|
type: 'custom_rule',
|
||||||
|
)
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
// ignore_for_file: use_build_context_synchronously
|
// ignore_for_file: use_build_context_synchronously
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/screens/filters/add_list_modal.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
@ -13,7 +14,12 @@ import 'package:adguard_home_manager/models/filtering.dart';
|
||||||
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
import 'package:adguard_home_manager/providers/servers_provider.dart';
|
||||||
|
|
||||||
class FiltersFab extends StatelessWidget {
|
class FiltersFab extends StatelessWidget {
|
||||||
const FiltersFab({Key? key}) : super(key: key);
|
final String type;
|
||||||
|
|
||||||
|
const FiltersFab({
|
||||||
|
Key? key,
|
||||||
|
required this.type,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
@ -53,7 +59,7 @@ class FiltersFab extends StatelessWidget {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void openAddClient() {
|
void openAddCustomRule() {
|
||||||
showModalBottomSheet(
|
showModalBottomSheet(
|
||||||
context: context,
|
context: context,
|
||||||
builder: (ctx) => AddCustomRule(
|
builder: (ctx) => AddCustomRule(
|
||||||
|
@ -64,8 +70,97 @@ class FiltersFab extends StatelessWidget {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void confirmAddList({required String name, required String url}) async {
|
||||||
|
ProcessModal processModal = ProcessModal(context: context);
|
||||||
|
processModal.open(AppLocalizations.of(context)!.addingList);
|
||||||
|
|
||||||
|
final result1 = await addFilteringList(server: serversProvider.selectedServer!, data: {
|
||||||
|
'name': name,
|
||||||
|
'url': url,
|
||||||
|
'whitelist': type == 'whitelist' ? true : false
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result1['result'] == 'success') {
|
||||||
|
if (result1['data'].toString().contains("OK")) {
|
||||||
|
final result2 = await getFiltering(server: serversProvider.selectedServer!);
|
||||||
|
final items = result1['data'].toString().split(' ')[1];
|
||||||
|
|
||||||
|
if (result2['result'] == 'success') {
|
||||||
|
serversProvider.setFilteringData(result2['data']);
|
||||||
|
serversProvider.setFilteringLoadStatus(1, true);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
appConfigProvider.addLog(result2['log']);
|
||||||
|
serversProvider.setFilteringLoadStatus(2, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
processModal.close();
|
||||||
|
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text("${AppLocalizations.of(context)!.listAdded} $items."),
|
||||||
|
backgroundColor: Colors.green,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processModal.close();
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listNotAdded),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (result1['result'] == 'error' && result1['log'].statusCode == '400' && result1['log'].resBody.toString().contains("Couldn't fetch filter from url")) {
|
||||||
|
processModal.close();
|
||||||
|
appConfigProvider.addLog(result1['log']);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listUrlInvalid),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else if (result1['result'] == 'error' && result1['log'].statusCode == '400' && result1['log'].resBody.toString().contains('Filter URL already added')) {
|
||||||
|
processModal.close();
|
||||||
|
appConfigProvider.addLog(result1['log']);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listAlreadyAdded),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
processModal.close();
|
||||||
|
appConfigProvider.addLog(result1['log']);
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(
|
||||||
|
content: Text(AppLocalizations.of(context)!.listNotAdded),
|
||||||
|
backgroundColor: Colors.red,
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void openAddWhitelistBlacklist() {
|
||||||
|
showModalBottomSheet(
|
||||||
|
context: context,
|
||||||
|
builder: (ctx) => AddListModal(
|
||||||
|
type: type,
|
||||||
|
onConfirm: confirmAddList
|
||||||
|
),
|
||||||
|
isScrollControlled: true,
|
||||||
|
backgroundColor: Colors.transparent
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return FloatingActionButton(
|
return FloatingActionButton(
|
||||||
onPressed: openAddClient,
|
onPressed: type == 'blacklist' || type == 'whitelist'
|
||||||
|
? () => openAddWhitelistBlacklist()
|
||||||
|
: () => openAddCustomRule(),
|
||||||
child: const Icon(Icons.add),
|
child: const Icon(Icons.add),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -41,6 +41,7 @@ class FiltersWidget extends StatefulWidget {
|
||||||
|
|
||||||
class _FiltersWidgetState extends State<FiltersWidget> with TickerProviderStateMixin {
|
class _FiltersWidgetState extends State<FiltersWidget> with TickerProviderStateMixin {
|
||||||
late TabController tabController;
|
late TabController tabController;
|
||||||
|
final ScrollController scrollController = ScrollController();
|
||||||
|
|
||||||
Future fetchFilters() async {
|
Future fetchFilters() async {
|
||||||
widget.serversProvider.setFilteringLoadStatus(0, false);
|
widget.serversProvider.setFilteringLoadStatus(0, false);
|
||||||
|
@ -114,6 +115,7 @@ class _FiltersWidgetState extends State<FiltersWidget> with TickerProviderStateM
|
||||||
return DefaultTabController(
|
return DefaultTabController(
|
||||||
length: 3,
|
length: 3,
|
||||||
child: NestedScrollView(
|
child: NestedScrollView(
|
||||||
|
controller: scrollController,
|
||||||
headerSliverBuilder: ((context, innerBoxIsScrolled) {
|
headerSliverBuilder: ((context, innerBoxIsScrolled) {
|
||||||
return [
|
return [
|
||||||
SliverAppBar(
|
SliverAppBar(
|
||||||
|
@ -158,19 +160,27 @@ class _FiltersWidgetState extends State<FiltersWidget> with TickerProviderStateM
|
||||||
RefreshIndicator(
|
RefreshIndicator(
|
||||||
onRefresh: fetchFilters,
|
onRefresh: fetchFilters,
|
||||||
child: FiltersList(
|
child: FiltersList(
|
||||||
data: serversProvider.filtering.data!.whitelistFilters
|
scrollController: scrollController,
|
||||||
|
type: 'whitelist',
|
||||||
|
data: serversProvider.filtering.data!.whitelistFilters,
|
||||||
|
fetchData: fetchFilters,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
RefreshIndicator(
|
RefreshIndicator(
|
||||||
onRefresh: fetchFilters,
|
onRefresh: fetchFilters,
|
||||||
child: FiltersList(
|
child: FiltersList(
|
||||||
data: serversProvider.filtering.data!.filters
|
scrollController: scrollController,
|
||||||
|
type: 'blacklist',
|
||||||
|
data: serversProvider.filtering.data!.filters,
|
||||||
|
fetchData: fetchFilters,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
RefreshIndicator(
|
RefreshIndicator(
|
||||||
onRefresh: fetchFilters,
|
onRefresh: fetchFilters,
|
||||||
child: CustomRulesList(
|
child: CustomRulesList(
|
||||||
data: serversProvider.filtering.data!.userRules
|
scrollController: scrollController,
|
||||||
|
data: serversProvider.filtering.data!.userRules,
|
||||||
|
fetchData: fetchFilters,
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
|
|
@ -1,24 +1,63 @@
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
import 'package:flutter_gen/gen_l10n/app_localizations.dart';
|
||||||
|
|
||||||
|
import 'package:adguard_home_manager/screens/filters/fab.dart';
|
||||||
|
|
||||||
import 'package:adguard_home_manager/functions/number_format.dart';
|
import 'package:adguard_home_manager/functions/number_format.dart';
|
||||||
import 'package:adguard_home_manager/models/filtering.dart';
|
import 'package:adguard_home_manager/models/filtering.dart';
|
||||||
|
|
||||||
class FiltersList extends StatelessWidget {
|
class FiltersList extends StatefulWidget {
|
||||||
|
final ScrollController scrollController;
|
||||||
final List<Filter> data;
|
final List<Filter> data;
|
||||||
|
final void Function() fetchData;
|
||||||
|
final String type;
|
||||||
|
|
||||||
const FiltersList({
|
const FiltersList({
|
||||||
Key? key,
|
Key? key,
|
||||||
required this.data
|
required this.scrollController,
|
||||||
|
required this.data,
|
||||||
|
required this.fetchData,
|
||||||
|
required this.type,
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<FiltersList> createState() => _FiltersListState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _FiltersListState extends State<FiltersList> {
|
||||||
|
late bool isVisible;
|
||||||
|
|
||||||
|
@override
|
||||||
|
initState(){
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
isVisible = true;
|
||||||
|
widget.scrollController.addListener(() {
|
||||||
|
if (widget.scrollController.position.userScrollDirection == ScrollDirection.reverse) {
|
||||||
|
if (mounted && isVisible == true) {
|
||||||
|
setState(() => isVisible = false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
if (widget.scrollController.position.userScrollDirection == ScrollDirection.forward) {
|
||||||
|
if (mounted && isVisible == false) {
|
||||||
|
setState(() => isVisible = true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return ListView.builder(
|
return Stack(
|
||||||
|
children: [
|
||||||
|
if (widget.data.isNotEmpty) ListView.builder(
|
||||||
padding: const EdgeInsets.only(top: 0),
|
padding: const EdgeInsets.only(top: 0),
|
||||||
itemCount: data.length,
|
itemCount: widget.data.length,
|
||||||
itemBuilder: (context, index) => Material(
|
itemBuilder: (context, index) => Material(
|
||||||
color: Colors.transparent,
|
color: Colors.transparent,
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
|
@ -34,7 +73,7 @@ class FiltersList extends StatelessWidget {
|
||||||
SizedBox(
|
SizedBox(
|
||||||
width: MediaQuery.of(context).size.width-130,
|
width: MediaQuery.of(context).size.width-130,
|
||||||
child: Text(
|
child: Text(
|
||||||
data[index].name,
|
widget.data[index].name,
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontWeight: FontWeight.w500,
|
fontWeight: FontWeight.w500,
|
||||||
fontSize: 16
|
fontSize: 16
|
||||||
|
@ -43,7 +82,7 @@ class FiltersList extends StatelessWidget {
|
||||||
),
|
),
|
||||||
const SizedBox(height: 5),
|
const SizedBox(height: 5),
|
||||||
Text(
|
Text(
|
||||||
"${intFormat(data[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}",
|
"${intFormat(widget.data[index].rulesCount, Platform.localeName)} ${AppLocalizations.of(context)!.enabledRules}",
|
||||||
style: const TextStyle(
|
style: const TextStyle(
|
||||||
fontSize: 14,
|
fontSize: 14,
|
||||||
color: Colors.grey
|
color: Colors.grey
|
||||||
|
@ -52,11 +91,11 @@ class FiltersList extends StatelessWidget {
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
Text(
|
Text(
|
||||||
data[index].enabled == true
|
widget.data[index].enabled == true
|
||||||
? AppLocalizations.of(context)!.enabled
|
? AppLocalizations.of(context)!.enabled
|
||||||
: AppLocalizations.of(context)!.disabled,
|
: AppLocalizations.of(context)!.disabled,
|
||||||
style: TextStyle(
|
style: TextStyle(
|
||||||
color: data[index].enabled == true
|
color: widget.data[index].enabled == true
|
||||||
? Colors.green
|
? Colors.green
|
||||||
: Colors.red,
|
: Colors.red,
|
||||||
fontWeight: FontWeight.w500
|
fontWeight: FontWeight.w500
|
||||||
|
@ -67,6 +106,41 @@ class FiltersList extends StatelessWidget {
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
if (widget.data.isEmpty) if (widget.data.isEmpty) SizedBox(
|
||||||
|
width: double.maxFinite,
|
||||||
|
child: Column(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
|
children: [
|
||||||
|
Text(
|
||||||
|
widget.type == 'blacklist'
|
||||||
|
? AppLocalizations.of(context)!.noBlackLists
|
||||||
|
: AppLocalizations.of(context)!.noWhiteLists,
|
||||||
|
textAlign: TextAlign.center,
|
||||||
|
style: const TextStyle(
|
||||||
|
fontSize: 24,
|
||||||
|
color: Colors.grey
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(height: 30),
|
||||||
|
TextButton.icon(
|
||||||
|
onPressed: widget.fetchData,
|
||||||
|
icon: const Icon(Icons.refresh_rounded),
|
||||||
|
label: Text(AppLocalizations.of(context)!.refresh),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
AnimatedPositioned(
|
||||||
|
duration: const Duration(milliseconds: 100),
|
||||||
|
curve: Curves.easeInOut,
|
||||||
|
bottom: isVisible ? 20 : -70,
|
||||||
|
right: 20,
|
||||||
|
child: FiltersFab(
|
||||||
|
type: widget.type
|
||||||
|
)
|
||||||
|
)
|
||||||
|
],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -773,4 +773,41 @@ Future setCustomRules({
|
||||||
else {
|
else {
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
Future addFilteringList({
|
||||||
|
required Server server,
|
||||||
|
required Map<String, dynamic> data,
|
||||||
|
}) async {
|
||||||
|
final result = await apiRequest(
|
||||||
|
urlPath: '/filtering/add_url',
|
||||||
|
method: 'post',
|
||||||
|
server: server,
|
||||||
|
body: data,
|
||||||
|
type: 'add_filtering_url'
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result['hasResponse'] == true) {
|
||||||
|
if (result['statusCode'] == 200) {
|
||||||
|
return {
|
||||||
|
'result': 'success',
|
||||||
|
'data': result['body']
|
||||||
|
};
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return {
|
||||||
|
'result': 'error',
|
||||||
|
'log': AppLog(
|
||||||
|
type: 'add_filtering_url',
|
||||||
|
dateTime: DateTime.now(),
|
||||||
|
message: 'error_code_not_expected',
|
||||||
|
statusCode: result['statusCode'].toString(),
|
||||||
|
resBody: result['body']
|
||||||
|
)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Add table
Reference in a new issue