From a5e56fa92ffa3ddb6bc2c7405945beae628d91b8 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 31 Jul 2022 08:55:14 +0200 Subject: [PATCH 1/2] settings: Add reset method --- packages/settings/lib/src/options/option.dart | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/settings/lib/src/options/option.dart b/packages/settings/lib/src/options/option.dart index 3172acc8..2127dd00 100644 --- a/packages/settings/lib/src/options/option.dart +++ b/packages/settings/lib/src/options/option.dart @@ -34,6 +34,10 @@ abstract class Option { return stream.value ?? defaultValue.value; } + Future reset() async { + await set(defaultValue.value); + } + void dispose() { stream.close(); enabled.close(); From 755d6aedd0694bb99bcb4fa2ea28d390dc1135b0 Mon Sep 17 00:00:00 2001 From: jld3103 Date: Sun, 31 Jul 2022 08:55:38 +0200 Subject: [PATCH 2/2] neon: Add reset settings buttons --- packages/neon/lib/l10n/en.arb | 24 ++++++------------- packages/neon/lib/l10n/localizations.dart | 24 +++++++++---------- packages/neon/lib/l10n/localizations_en.dart | 18 +++++++------- packages/neon/lib/src/models/account.dart | 6 +++++ .../settings/account_specific_settings.dart | 19 +++++++++++---- .../nextcloud_app_specific_settings.dart | 15 +++++++++++- .../neon/lib/src/pages/settings/settings.dart | 18 ++++++++++++++ .../neon/lib/src/utils/global_options.dart | 6 +++++ .../utils/nextcloud_app_specific_options.dart | 6 +++++ 9 files changed, 91 insertions(+), 45 deletions(-) diff --git a/packages/neon/lib/l10n/en.arb b/packages/neon/lib/l10n/en.arb index 0cd3eb6d..a696c27c 100644 --- a/packages/neon/lib/l10n/en.arb +++ b/packages/neon/lib/l10n/en.arb @@ -52,29 +52,19 @@ "exit": "Exit", "disabled": "Disabled", "settings": "Settings", - "settingsForApp": "Settings - {name}", - "@settingsForApp": { + "settingsApps": "Apps", + "settingsExport": "Export settings", + "settingsImport": "Import settings", + "settingsImportWrongFileExtension": "Settings import has wrong file extension (has to be .json.base64)", + "settingsResetAllConfirmation": "Do you want to reset all settings?", + "settingsResetForConfirmation": "Do you want to reset all settings for {name}?", + "@settingsResetForConfirmation": { "placeholders": { "name": { "type": "String" } } }, - "settingsForAccount": "Settings - {username}@{host}", - "@settingsForAccount": { - "placeholders": { - "username": { - "type": "String" - }, - "host": { - "type": "String" - } - } - }, - "settingsApps": "Apps", - "settingsExport": "Export settings", - "settingsImport": "Import settings", - "settingsImportWrongFileExtension": "Settings import has wrong file extension (has to be .json.base64)", "optionsCategoryGeneral": "General", "optionsCategoryTheme": "Theme", "optionsCategoryPushNotifications": "Push notifications", diff --git a/packages/neon/lib/l10n/localizations.dart b/packages/neon/lib/l10n/localizations.dart index 6d0e6e6d..ee0d8279 100644 --- a/packages/neon/lib/l10n/localizations.dart +++ b/packages/neon/lib/l10n/localizations.dart @@ -275,18 +275,6 @@ abstract class AppLocalizations { /// **'Settings'** String get settings; - /// No description provided for @settingsForApp. - /// - /// In en, this message translates to: - /// **'Settings - {name}'** - String settingsForApp(String name); - - /// No description provided for @settingsForAccount. - /// - /// In en, this message translates to: - /// **'Settings - {username}@{host}'** - String settingsForAccount(String username, String host); - /// No description provided for @settingsApps. /// /// In en, this message translates to: @@ -311,6 +299,18 @@ abstract class AppLocalizations { /// **'Settings import has wrong file extension (has to be .json.base64)'** String get settingsImportWrongFileExtension; + /// No description provided for @settingsResetAllConfirmation. + /// + /// In en, this message translates to: + /// **'Do you want to reset all settings?'** + String get settingsResetAllConfirmation; + + /// No description provided for @settingsResetForConfirmation. + /// + /// In en, this message translates to: + /// **'Do you want to reset all settings for {name}?'** + String settingsResetForConfirmation(String name); + /// No description provided for @optionsCategoryGeneral. /// /// In en, this message translates to: diff --git a/packages/neon/lib/l10n/localizations_en.dart b/packages/neon/lib/l10n/localizations_en.dart index be09b25f..5ae52801 100644 --- a/packages/neon/lib/l10n/localizations_en.dart +++ b/packages/neon/lib/l10n/localizations_en.dart @@ -106,16 +106,6 @@ class AppLocalizationsEn extends AppLocalizations { @override String get settings => 'Settings'; - @override - String settingsForApp(String name) { - return 'Settings - $name'; - } - - @override - String settingsForAccount(String username, String host) { - return 'Settings - $username@$host'; - } - @override String get settingsApps => 'Apps'; @@ -128,6 +118,14 @@ class AppLocalizationsEn extends AppLocalizations { @override String get settingsImportWrongFileExtension => 'Settings import has wrong file extension (has to be .json.base64)'; + @override + String get settingsResetAllConfirmation => 'Do you want to reset all settings?'; + + @override + String settingsResetForConfirmation(String name) { + return 'Do you want to reset all settings for $name?'; + } + @override String get optionsCategoryGeneral => 'General'; diff --git a/packages/neon/lib/src/models/account.dart b/packages/neon/lib/src/models/account.dart index a5981028..54ca1090 100644 --- a/packages/neon/lib/src/models/account.dart +++ b/packages/neon/lib/src/models/account.dart @@ -102,6 +102,12 @@ class AccountSpecificOptions { }); } + Future reset() async { + for (final option in options) { + await option.reset(); + } + } + void dispose() { _appIDsSubject.close(); for (final option in options) { diff --git a/packages/neon/lib/src/pages/settings/account_specific_settings.dart b/packages/neon/lib/src/pages/settings/account_specific_settings.dart index d87036a3..a91ff1a6 100644 --- a/packages/neon/lib/src/pages/settings/account_specific_settings.dart +++ b/packages/neon/lib/src/pages/settings/account_specific_settings.dart @@ -11,17 +11,26 @@ class AccountSpecificSettingsPage extends StatelessWidget { final Account account; late final _options = bloc.getOptions(account)!; + late final _name = '${account.username}@${Uri.parse(account.serverURL).host}'; @override Widget build(final BuildContext context) => Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( - title: Text( - AppLocalizations.of(context).settingsForAccount( - account.username, - Uri.parse(account.serverURL).host, + title: Text(_name), + actions: [ + IconButton( + onPressed: () async { + if (await showConfirmationDialog( + context, + AppLocalizations.of(context).settingsResetForConfirmation(_name), + )) { + await _options.reset(); + } + }, + icon: const Icon(MdiIcons.cogRefresh), ), - ), + ], ), body: SettingsList( categories: [ diff --git a/packages/neon/lib/src/pages/settings/nextcloud_app_specific_settings.dart b/packages/neon/lib/src/pages/settings/nextcloud_app_specific_settings.dart index 04c085e3..1e5c9b70 100644 --- a/packages/neon/lib/src/pages/settings/nextcloud_app_specific_settings.dart +++ b/packages/neon/lib/src/pages/settings/nextcloud_app_specific_settings.dart @@ -12,7 +12,20 @@ class NextcloudAppSpecificSettingsPage extends StatelessWidget { Widget build(final BuildContext context) => Scaffold( resizeToAvoidBottomInset: false, appBar: AppBar( - title: Text(AppLocalizations.of(context).settingsForApp(appImplementation.name(context))), + title: Text(appImplementation.name(context)), + actions: [ + IconButton( + onPressed: () async { + if (await showConfirmationDialog( + context, + AppLocalizations.of(context).settingsResetForConfirmation(appImplementation.name(context)), + )) { + await appImplementation.options.reset(); + } + }, + icon: const Icon(MdiIcons.cogRefresh), + ), + ], ), body: SettingsList( categories: [ diff --git a/packages/neon/lib/src/pages/settings/settings.dart b/packages/neon/lib/src/pages/settings/settings.dart index fcb40bd2..9b59c1b7 100644 --- a/packages/neon/lib/src/pages/settings/settings.dart +++ b/packages/neon/lib/src/pages/settings/settings.dart @@ -19,6 +19,24 @@ class _SettingsPageState extends State { resizeToAvoidBottomInset: false, appBar: AppBar( title: Text(AppLocalizations.of(context).settings), + actions: [ + IconButton( + onPressed: () async { + if (await showConfirmationDialog(context, AppLocalizations.of(context).settingsResetAllConfirmation)) { + await globalOptions.reset(); + + for (final appImplementation in appImplementations) { + await appImplementation.options.reset(); + } + + for (final account in accountsBloc.accounts.value) { + await accountsBloc.getOptions(account)!.reset(); + } + } + }, + icon: const Icon(MdiIcons.cogRefresh), + ), + ], ), body: RxBlocBuilder>( bloc: accountsBloc, diff --git a/packages/neon/lib/src/utils/global_options.dart b/packages/neon/lib/src/utils/global_options.dart index 75a9f221..9bf6724b 100644 --- a/packages/neon/lib/src/utils/global_options.dart +++ b/packages/neon/lib/src/utils/global_options.dart @@ -64,6 +64,12 @@ class GlobalOptions { lastAccount, ]; + Future reset() async { + for (final option in options) { + await option.reset(); + } + } + void dispose() { _accountsIDsSubject.close(); _themeOLEDAsDarkEnabledSubject.close(); diff --git a/packages/neon/lib/src/utils/nextcloud_app_specific_options.dart b/packages/neon/lib/src/utils/nextcloud_app_specific_options.dart index 5953f3d6..cb55a9f7 100644 --- a/packages/neon/lib/src/utils/nextcloud_app_specific_options.dart +++ b/packages/neon/lib/src/utils/nextcloud_app_specific_options.dart @@ -7,6 +7,12 @@ abstract class NextcloudAppSpecificOptions { late final List categories; late final List