From 75544f1f51b18ccc342e43077cae1ae384ca0679 Mon Sep 17 00:00:00 2001 From: Alberto Ponces Date: Wed, 7 Sep 2022 11:14:54 +0100 Subject: [PATCH] feat: Add a reset button to Custom Sources Dialog --- assets/i18n/en.json | 4 +- lib/services/manager_api.dart | 6 +-- lib/ui/views/settings/settings_viewmodel.dart | 43 +++++++++++++++++-- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/assets/i18n/en.json b/assets/i18n/en.json index c48cf627..02de88c8 100644 --- a/assets/i18n/en.json +++ b/assets/i18n/en.json @@ -96,11 +96,13 @@ "englishOption": "English", "frenchOption": "French", "sourcesLabel": "Sources", - "sourcesLabelHint": "Add your custom sources", + "sourcesLabelHint": "Configure your custom sources", "orgPatchesLabel" : "Patches Org", "sourcesPatchesLabel" : "Patches Source", "orgIntegrationsLabel": "Integrations Org", "sourcesIntegrationsLabel": "Integrations Source", + "sourcesResetDialogTitle": "Reset", + "sourcesResetDialogText": "Are you sure you want to reset custom sources to their default values?", "contributorsLabel": "Contributors", "contributorsHint": "A list of contributors of ReVanced", "aboutLabel": "About", diff --git a/lib/services/manager_api.dart b/lib/services/manager_api.dart index 1fde1cd5..ae7ede71 100644 --- a/lib/services/manager_api.dart +++ b/lib/services/manager_api.dart @@ -35,7 +35,7 @@ class ManagerAPI { } Future setPatchesRepo(String value) async { - if (value.isEmpty) { + if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) { value = defaultPatchesRepo; } await _prefs.setString('patchesRepo', value); @@ -46,7 +46,7 @@ class ManagerAPI { } Future setIntegrationsRepo(String value) async { - if (value.isEmpty) { + if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) { value = defaultIntegrationsRepo; } await _prefs.setString('integrationsRepo', value); @@ -61,7 +61,7 @@ class ManagerAPI { } Future setManagerRepo(String value) async { - if (value.isEmpty) { + if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) { value = defaultManagerRepo; } await _prefs.setString('managerRepo', value); diff --git a/lib/ui/views/settings/settings_viewmodel.dart b/lib/ui/views/settings/settings_viewmodel.dart index 2d3c3bb9..464611af 100644 --- a/lib/ui/views/settings/settings_viewmodel.dart +++ b/lib/ui/views/settings/settings_viewmodel.dart @@ -96,14 +96,25 @@ class SettingsViewModel extends BaseViewModel { return showDialog( context: context, builder: (context) => AlertDialog( - title: I18nText('settingsView.sourcesLabel'), + title: Row( + children: [ + I18nText('settingsView.sourcesLabel'), + const Spacer(), + IconButton( + icon: const Icon(Icons.manage_history_outlined), + onPressed: () => showResetConfirmationDialog(context), + color: Theme.of(context).colorScheme.secondary, + ) + ], + ), + backgroundColor: Theme.of(context).colorScheme.secondaryContainer, content: SingleChildScrollView( child: Column( children: [ CustomTextField( leadingIcon: Icon( Icons.extension_outlined, - color: Theme.of(context).colorScheme.primary, + color: Theme.of(context).colorScheme.secondary, ), inputController: _orgPatSourceController, label: I18nText('settingsView.orgPatchesLabel'), @@ -125,7 +136,7 @@ class SettingsViewModel extends BaseViewModel { CustomTextField( leadingIcon: Icon( Icons.merge_outlined, - color: Theme.of(context).colorScheme.primary, + color: Theme.of(context).colorScheme.secondary, ), inputController: _orgIntSourceController, label: I18nText('settingsView.orgIntegrationsLabel'), @@ -171,7 +182,33 @@ class SettingsViewModel extends BaseViewModel { }, ) ], + ), + ); + } + + Future showResetConfirmationDialog(BuildContext context) async { + return showDialog( + context: context, + builder: (context) => AlertDialog( + title: I18nText('settingsView.sourcesResetDialogTitle'), backgroundColor: Theme.of(context).colorScheme.secondaryContainer, + content: I18nText('settingsView.sourcesResetDialogText'), + actions: [ + CustomMaterialButton( + isFilled: false, + label: I18nText('cancelButton'), + onPressed: () => Navigator.of(context).pop(), + ), + CustomMaterialButton( + label: I18nText('okButton'), + onPressed: () { + _managerAPI.setPatchesRepo(''); + _managerAPI.setIntegrationsRepo(''); + Navigator.of(context).pop(); + Navigator.of(context).pop(); + }, + ) + ], ), ); }