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.", "example2": "Unblocks access to example.org and all its subdomains.",
"example3": "Adds a comment.", "example3": "Adds a comment.",
"example4": "Block access to domains matching the specified regular expression.", "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.", "example2": "Desbloquea el acceso al dominio ejemplo.org y a todos sus subdominios.",
"example3": "Añade un comentario.", "example3": "Añade un comentario.",
"example4": "Bloquea el acceso a los dominios que coincidan con la expresión regular especificada.", "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(); final TextEditingController domainController = TextEditingController();
String? domainError; String? domainError;
bool validValues = false;
String preset = "block"; String preset = "block";
bool addImportant = false; bool addImportant = false;
void checkValidValues() { bool checkValidValues() {
if (domainController.text != '') { if (
setState(() => validValues = true); domainController.text != '' &&
domainError == null &&
(
preset == 'block' ||
preset == 'unblock' ||
preset == 'custom'
)
) {
return true;
} }
else { else {
setState(() => validValues = false); return false;
} }
} }
@ -47,19 +53,22 @@ class _AddCustomRuleState extends State<AddCustomRule> {
else { else {
setState(() => domainError = AppLocalizations.of(context)!.domainNotValid); setState(() => domainError = AppLocalizations.of(context)!.domainNotValid);
} }
checkValidValues();
} }
String buildRule() { String buildRule({String?value}) {
String rule = ""; String rule = "";
String fieldValue = value ?? domainController.text;
if (preset == 'block') { if (preset == 'block') {
rule = "||${domainController.text.trim()}^"; rule = "||${fieldValue.trim()}^";
} }
else if (preset == 'unblock') { else if (preset == 'unblock') {
rule = "@@||${domainController.text.trim()}^"; rule = "@@||${fieldValue.trim()}^";
} }
else { else {
rule = domainController.text.trim(); rule = fieldValue.trim();
} }
if (addImportant == true) { if (addImportant == true) {
@ -151,7 +160,7 @@ class _AddCustomRuleState extends State<AddCustomRule> {
padding: const EdgeInsets.symmetric(horizontal: 28), padding: const EdgeInsets.symmetric(horizontal: 28),
child: TextFormField( child: TextFormField(
controller: domainController, controller: domainController,
onChanged: validateDomain, onChanged: (value) => setState(() => {}),
decoration: InputDecoration( decoration: InputDecoration(
prefixIcon: const Icon(Icons.link_rounded), prefixIcon: const Icon(Icons.link_rounded),
border: const OutlineInputBorder( border: const OutlineInputBorder(
@ -378,16 +387,16 @@ class _AddCustomRuleState extends State<AddCustomRule> {
), ),
const SizedBox(width: 20), const SizedBox(width: 20),
TextButton( TextButton(
onPressed: validValues == true onPressed: checkValidValues() == true
? () { ? () {
Navigator.pop(context); Navigator.pop(context);
widget.onConfirm(domainController.text); widget.onConfirm(buildRule());
} }
: null, : null,
child: Text( child: Text(
AppLocalizations.of(context)!.confirm, AppLocalizations.of(context)!.confirm,
style: TextStyle( style: TextStyle(
color: validValues == true color: checkValidValues() == true
? Theme.of(context).primaryColor ? Theme.of(context).primaryColor
: Colors.grey : Colors.grey
), ),

View file

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

View file

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