Bug fixes

This commit is contained in:
Juan Gilsanz Polo 2022-10-10 01:42:09 +02:00
parent ce9367b29f
commit 50c3ca720e
5 changed files with 41 additions and 24 deletions

View file

@ -302,5 +302,7 @@
"example2": "Unblocks access to example.org and all its subdomains.",
"example3": "Adds a comment.",
"example4": "Block access to domains matching the specified regular expression.",
"moreInformation": "More information"
"moreInformation": "More information",
"addingRule": "Adding rule...",
"deletingRule": "Deleting rule..."
}

View file

@ -302,5 +302,7 @@
"example2": "Desbloquea el acceso al dominio ejemplo.org y a todos sus subdominios.",
"example3": "Añade un comentario.",
"example4": "Bloquea el acceso a los dominios que coincidan con la expresión regular especificada.",
"moreInformation": "Más información"
"moreInformation": "Más información",
"addingRule": "Añadiendo regla...",
"deletingRule": "Eliminando regla..."
}

View file

@ -24,18 +24,24 @@ class _AddCustomRuleState extends State<AddCustomRule> {
final TextEditingController domainController = TextEditingController();
String? domainError;
bool validValues = false;
String preset = "block";
bool addImportant = false;
void checkValidValues() {
if (domainController.text != '') {
setState(() => validValues = true);
bool checkValidValues() {
if (
domainController.text != '' &&
domainError == null &&
(
preset == 'block' ||
preset == 'unblock' ||
preset == 'custom'
)
) {
return true;
}
else {
setState(() => validValues = false);
return false;
}
}
@ -47,19 +53,22 @@ class _AddCustomRuleState extends State<AddCustomRule> {
else {
setState(() => domainError = AppLocalizations.of(context)!.domainNotValid);
}
checkValidValues();
}
String buildRule() {
String buildRule({String?value}) {
String rule = "";
String fieldValue = value ?? domainController.text;
if (preset == 'block') {
rule = "||${domainController.text.trim()}^";
rule = "||${fieldValue.trim()}^";
}
else if (preset == 'unblock') {
rule = "@@||${domainController.text.trim()}^";
rule = "@@||${fieldValue.trim()}^";
}
else {
rule = domainController.text.trim();
rule = fieldValue.trim();
}
if (addImportant == true) {
@ -151,7 +160,7 @@ class _AddCustomRuleState extends State<AddCustomRule> {
padding: const EdgeInsets.symmetric(horizontal: 28),
child: TextFormField(
controller: domainController,
onChanged: validateDomain,
onChanged: (value) => setState(() => {}),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.link_rounded),
border: const OutlineInputBorder(
@ -378,16 +387,16 @@ class _AddCustomRuleState extends State<AddCustomRule> {
),
const SizedBox(width: 20),
TextButton(
onPressed: validValues == true
onPressed: checkValidValues() == true
? () {
Navigator.pop(context);
widget.onConfirm(domainController.text);
widget.onConfirm(buildRule());
}
: null,
child: Text(
AppLocalizations.of(context)!.confirm,
style: TextStyle(
color: validValues == true
color: checkValidValues() == true
? Theme.of(context).primaryColor
: Colors.grey
),

View file

@ -64,7 +64,7 @@ class _CustomRulesListState extends State<CustomRulesList> {
void removeCustomRule(String rule) async {
ProcessModal processModal = ProcessModal(context: context);
processModal.open(AppLocalizations.of(context)!.updatingRules);
processModal.open(AppLocalizations.of(context)!.deletingRule);
final List<String> newRules = serversProvider.filtering.data!.userRules.where((r) => r != rule).toList();
@ -146,12 +146,16 @@ class _CustomRulesListState extends State<CustomRulesList> {
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
AppLocalizations.of(context)!.noBlackLists,
textAlign: TextAlign.center,
style: const TextStyle(
fontSize: 24,
color: Colors.grey
SizedBox(
width: MediaQuery.of(context).size.width-100,
child: Text(
AppLocalizations.of(context)!.noBlackLists,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
style: const TextStyle(
fontSize: 24,
color: Colors.grey
),
),
),
const SizedBox(height: 30),

View file

@ -30,7 +30,7 @@ class FiltersFab extends StatelessWidget {
void confirmAddRule(String rule) async {
ProcessModal processModal = ProcessModal(context: context);
processModal.open(AppLocalizations.of(context)!.updatingRules);
processModal.open(AppLocalizations.of(context)!.addingRule);
final List<String> newRules = serversProvider.filtering.data!.userRules;
newRules.add(rule);