Browse Source

Merge pull request #48 from jld3103/feature/settings-reset

Implement resetting settings
pull/50/head
jld3103 2 years ago committed by GitHub
parent
commit
9812d250ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 24
      packages/neon/lib/l10n/en.arb
  2. 24
      packages/neon/lib/l10n/localizations.dart
  3. 18
      packages/neon/lib/l10n/localizations_en.dart
  4. 6
      packages/neon/lib/src/models/account.dart
  5. 19
      packages/neon/lib/src/pages/settings/account_specific_settings.dart
  6. 15
      packages/neon/lib/src/pages/settings/nextcloud_app_specific_settings.dart
  7. 18
      packages/neon/lib/src/pages/settings/settings.dart
  8. 6
      packages/neon/lib/src/utils/global_options.dart
  9. 6
      packages/neon/lib/src/utils/nextcloud_app_specific_options.dart
  10. 4
      packages/settings/lib/src/options/option.dart

24
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",

24
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:

18
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';

6
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) {

19
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: [

15
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: [

18
packages/neon/lib/src/pages/settings/settings.dart

@ -19,6 +19,24 @@ class _SettingsPageState extends State<SettingsPage> {
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<AccountsBloc, List<Account>>(
bloc: accountsBloc,

6
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();

6
packages/neon/lib/src/utils/nextcloud_app_specific_options.dart

@ -7,6 +7,12 @@ abstract class NextcloudAppSpecificOptions {
late final List<OptionsCategory> categories;
late final List<Option> options;
Future reset() async {
for (final option in options) {
await option.reset();
}
}
void dispose() {
for (final option in options) {
option.dispose();

4
packages/settings/lib/src/options/option.dart

@ -34,6 +34,10 @@ abstract class Option<T> {
return stream.value ?? defaultValue.value;
}
Future reset() async {
await set(defaultValue.value);
}
void dispose() {
stream.close();
enabled.close();

Loading…
Cancel
Save