feat: Add a reset button to Custom Sources Dialog

This commit is contained in:
Alberto Ponces 2022-09-07 11:14:54 +01:00
parent 4775e2c07f
commit 75544f1f51
3 changed files with 46 additions and 7 deletions

View File

@ -96,11 +96,13 @@
"englishOption": "English", "englishOption": "English",
"frenchOption": "French", "frenchOption": "French",
"sourcesLabel": "Sources", "sourcesLabel": "Sources",
"sourcesLabelHint": "Add your custom sources", "sourcesLabelHint": "Configure your custom sources",
"orgPatchesLabel" : "Patches Org", "orgPatchesLabel" : "Patches Org",
"sourcesPatchesLabel" : "Patches Source", "sourcesPatchesLabel" : "Patches Source",
"orgIntegrationsLabel": "Integrations Org", "orgIntegrationsLabel": "Integrations Org",
"sourcesIntegrationsLabel": "Integrations Source", "sourcesIntegrationsLabel": "Integrations Source",
"sourcesResetDialogTitle": "Reset",
"sourcesResetDialogText": "Are you sure you want to reset custom sources to their default values?",
"contributorsLabel": "Contributors", "contributorsLabel": "Contributors",
"contributorsHint": "A list of contributors of ReVanced", "contributorsHint": "A list of contributors of ReVanced",
"aboutLabel": "About", "aboutLabel": "About",

View File

@ -35,7 +35,7 @@ class ManagerAPI {
} }
Future<void> setPatchesRepo(String value) async { Future<void> setPatchesRepo(String value) async {
if (value.isEmpty) { if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) {
value = defaultPatchesRepo; value = defaultPatchesRepo;
} }
await _prefs.setString('patchesRepo', value); await _prefs.setString('patchesRepo', value);
@ -46,7 +46,7 @@ class ManagerAPI {
} }
Future<void> setIntegrationsRepo(String value) async { Future<void> setIntegrationsRepo(String value) async {
if (value.isEmpty) { if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) {
value = defaultIntegrationsRepo; value = defaultIntegrationsRepo;
} }
await _prefs.setString('integrationsRepo', value); await _prefs.setString('integrationsRepo', value);
@ -61,7 +61,7 @@ class ManagerAPI {
} }
Future<void> setManagerRepo(String value) async { Future<void> setManagerRepo(String value) async {
if (value.isEmpty) { if (value.isEmpty || value.startsWith('/') || value.endsWith('/')) {
value = defaultManagerRepo; value = defaultManagerRepo;
} }
await _prefs.setString('managerRepo', value); await _prefs.setString('managerRepo', value);

View File

@ -96,14 +96,25 @@ class SettingsViewModel extends BaseViewModel {
return showDialog( return showDialog(
context: context, context: context,
builder: (context) => AlertDialog( 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( content: SingleChildScrollView(
child: Column( child: Column(
children: <Widget>[ children: <Widget>[
CustomTextField( CustomTextField(
leadingIcon: Icon( leadingIcon: Icon(
Icons.extension_outlined, Icons.extension_outlined,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.secondary,
), ),
inputController: _orgPatSourceController, inputController: _orgPatSourceController,
label: I18nText('settingsView.orgPatchesLabel'), label: I18nText('settingsView.orgPatchesLabel'),
@ -125,7 +136,7 @@ class SettingsViewModel extends BaseViewModel {
CustomTextField( CustomTextField(
leadingIcon: Icon( leadingIcon: Icon(
Icons.merge_outlined, Icons.merge_outlined,
color: Theme.of(context).colorScheme.primary, color: Theme.of(context).colorScheme.secondary,
), ),
inputController: _orgIntSourceController, inputController: _orgIntSourceController,
label: I18nText('settingsView.orgIntegrationsLabel'), label: I18nText('settingsView.orgIntegrationsLabel'),
@ -171,7 +182,33 @@ class SettingsViewModel extends BaseViewModel {
}, },
) )
], ],
),
);
}
Future<void> showResetConfirmationDialog(BuildContext context) async {
return showDialog(
context: context,
builder: (context) => AlertDialog(
title: I18nText('settingsView.sourcesResetDialogTitle'),
backgroundColor: Theme.of(context).colorScheme.secondaryContainer, 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();
},
)
],
), ),
); );
} }