Browse Source

refactor(neon,neon_files,neon_news,neon_notes): make Option.key unique

Signed-off-by: Nikolas Rimikis <rimikis.nikolas@gmail.com>
pull/674/head
Nikolas Rimikis 1 year ago
parent
commit
0e563cec18
No known key found for this signature in database
GPG Key ID: 85ED1DE9786A4FF2
  1. 1
      packages/neon/neon/lib/settings.dart
  2. 2
      packages/neon/neon/lib/src/settings/models/option.dart
  3. 8
      packages/neon/neon/lib/src/settings/models/select_option.dart
  4. 7
      packages/neon/neon/lib/src/settings/models/storage.dart
  5. 8
      packages/neon/neon/lib/src/settings/models/toggle_option.dart
  6. 11
      packages/neon/neon/lib/src/utils/account_options.dart
  7. 44
      packages/neon/neon/lib/src/utils/global_options.dart
  8. 2
      packages/neon/neon/lib/src/utils/settings_export_helper.dart
  9. 31
      packages/neon/neon/test/option_test.dart
  10. 29
      packages/neon/neon_files/lib/options.dart
  11. 41
      packages/neon/neon_news/lib/options.dart
  12. 26
      packages/neon/neon_notes/lib/options.dart

1
packages/neon/neon/lib/settings.dart

@ -2,5 +2,6 @@ export 'package:neon/src/models/label_builder.dart';
export 'package:neon/src/settings/models/nextcloud_app_options.dart'; export 'package:neon/src/settings/models/nextcloud_app_options.dart';
export 'package:neon/src/settings/models/options_category.dart'; export 'package:neon/src/settings/models/options_category.dart';
export 'package:neon/src/settings/models/select_option.dart'; export 'package:neon/src/settings/models/select_option.dart';
export 'package:neon/src/settings/models/storage.dart' show Storable;
export 'package:neon/src/settings/models/toggle_option.dart'; export 'package:neon/src/settings/models/toggle_option.dart';
export 'package:neon/src/settings/widgets/settings_list.dart'; export 'package:neon/src/settings/widgets/settings_list.dart';

2
packages/neon/neon/lib/src/settings/models/option.dart

@ -38,7 +38,7 @@ abstract class Option<T> extends ChangeNotifier implements ValueListenable<T> {
} }
final SettingsStorage storage; final SettingsStorage storage;
final String key; final Storable key;
final LabelBuilder label; final LabelBuilder label;
final T defaultValue; final T defaultValue;
final OptionsCategory? category; final OptionsCategory? category;

8
packages/neon/neon/lib/src/settings/models/select_option.dart

@ -21,7 +21,7 @@ class SelectOption<T> extends Option<T> {
super.category, super.category,
super.enabled, super.enabled,
}) : _values = values, }) : _values = values,
super(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); super(initialValue: loadValue(values, storage.getString(key.value), forceLoad: forceLoadValue));
/// Creates a SelectOption depending on the State of another [Option]. /// Creates a SelectOption depending on the State of another [Option].
SelectOption.depend({ SelectOption.depend({
@ -39,7 +39,7 @@ class SelectOption<T> extends Option<T> {
final bool forceLoadValue = true, final bool forceLoadValue = true,
super.category, super.category,
}) : _values = values, }) : _values = values,
super.depend(initialValue: loadValue(values, storage.getString(key), forceLoad: forceLoadValue)); super.depend(initialValue: loadValue(values, storage.getString(key.value), forceLoad: forceLoadValue));
static T? loadValue<T>(final Map<T, LabelBuilder> vs, final String? stored, {final bool forceLoad = true}) { static T? loadValue<T>(final Map<T, LabelBuilder> vs, final String? stored, {final bool forceLoad = true}) {
if (forceLoad && vs.isEmpty && stored is T) { if (forceLoad && vs.isEmpty && stored is T) {
@ -51,7 +51,7 @@ class SelectOption<T> extends Option<T> {
@override @override
void reset() { void reset() {
unawaited(storage.remove(key)); unawaited(storage.remove(key.value));
super.reset(); super.reset();
} }
@ -63,7 +63,7 @@ class SelectOption<T> extends Option<T> {
super.value = value; super.value = value;
if (value != null) { if (value != null) {
unawaited(storage.setString(key, serialize()!)); unawaited(storage.setString(key.value, serialize()!));
} }
} }

7
packages/neon/neon/lib/src/settings/models/storage.dart

@ -16,8 +16,12 @@ abstract interface class SettingsStorage {
Future<bool> remove(final String key); Future<bool> remove(final String key);
} }
abstract interface class Storable {
String get value;
}
@internal @internal
enum StorageKeys { enum StorageKeys implements Storable {
apps._('app'), apps._('app'),
accounts._('accounts'), accounts._('accounts'),
global._('global'), global._('global'),
@ -28,6 +32,7 @@ enum StorageKeys {
const StorageKeys._(this.value); const StorageKeys._(this.value);
@override
final String value; final String value;
} }

8
packages/neon/neon/lib/src/settings/models/toggle_option.dart

@ -11,7 +11,7 @@ class ToggleOption extends Option<bool> {
required final bool defaultValue, required final bool defaultValue,
super.category, super.category,
super.enabled, super.enabled,
}) : super(defaultValue: storage.getBool(key) ?? defaultValue); }) : super(defaultValue: storage.getBool(key.value) ?? defaultValue);
/// Creates a ToggleOption depending on the State of another [Option]. /// Creates a ToggleOption depending on the State of another [Option].
ToggleOption.depend({ ToggleOption.depend({
@ -22,12 +22,12 @@ class ToggleOption extends Option<bool> {
required super.enabled, required super.enabled,
super.category, super.category,
}) : super.depend( }) : super.depend(
defaultValue: storage.getBool(key) ?? defaultValue, defaultValue: storage.getBool(key.value) ?? defaultValue,
); );
@override @override
void reset() { void reset() {
unawaited(storage.remove(key)); unawaited(storage.remove(key.value));
super.reset(); super.reset();
} }
@ -36,7 +36,7 @@ class ToggleOption extends Option<bool> {
set value(final bool value) { set value(final bool value) {
super.value = value; super.value = value;
unawaited(storage.setBool(key, serialize())); unawaited(storage.setBool(key.value, serialize()));
} }
@override @override

11
packages/neon/neon/lib/src/utils/account_options.dart

@ -47,9 +47,18 @@ class AccountSpecificOptions {
late final initialApp = SelectOption<String?>( late final initialApp = SelectOption<String?>(
storage: _storage, storage: _storage,
key: 'initial-app', key: AccountOptionKeys.initialApp,
label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp, label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp,
defaultValue: null, defaultValue: null,
values: {}, values: {},
); );
} }
enum AccountOptionKeys implements Storable {
initialApp._('initial-app');
const AccountOptionKeys._(this.value);
@override
final String value;
}

44
packages/neon/neon/lib/src/utils/global_options.dart

@ -125,7 +125,7 @@ class GlobalOptions {
late final themeMode = SelectOption<ThemeMode>( late final themeMode = SelectOption<ThemeMode>(
storage: _storage, storage: _storage,
key: 'theme-mode', key: GlobalOptionKeys.themeMode,
label: (final context) => AppLocalizations.of(context).globalOptionsThemeMode, label: (final context) => AppLocalizations.of(context).globalOptionsThemeMode,
defaultValue: ThemeMode.system, defaultValue: ThemeMode.system,
values: { values: {
@ -137,28 +137,28 @@ class GlobalOptions {
late final themeOLEDAsDark = ToggleOption( late final themeOLEDAsDark = ToggleOption(
storage: _storage, storage: _storage,
key: 'theme-oled-as-dark', key: GlobalOptionKeys.themeOledAsDark,
label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark, label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark,
defaultValue: false, defaultValue: false,
); );
late final themeKeepOriginalAccentColor = ToggleOption( late final themeKeepOriginalAccentColor = ToggleOption(
storage: _storage, storage: _storage,
key: 'theme-keep-original-accent-color', key: GlobalOptionKeys.themeKeepOriginalAccentColor,
label: (final context) => AppLocalizations.of(context).globalOptionsThemeKeepOriginalAccentColor, label: (final context) => AppLocalizations.of(context).globalOptionsThemeKeepOriginalAccentColor,
defaultValue: false, defaultValue: false,
); );
late final pushNotificationsEnabled = ToggleOption( late final pushNotificationsEnabled = ToggleOption(
storage: _storage, storage: _storage,
key: 'push-notifications-enabled', key: GlobalOptionKeys.pushNotificationsEnabled,
label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsEnabled, label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsEnabled,
defaultValue: false, defaultValue: false,
); );
late final pushNotificationsDistributor = SelectOption<String?>.depend( late final pushNotificationsDistributor = SelectOption<String?>.depend(
storage: _storage, storage: _storage,
key: 'push-notifications-distributor', key: GlobalOptionKeys.pushNotificationsDistributor,
label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsDistributor, label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsDistributor,
defaultValue: null, defaultValue: null,
values: {}, values: {},
@ -167,14 +167,14 @@ class GlobalOptions {
late final startupMinimized = ToggleOption( late final startupMinimized = ToggleOption(
storage: _storage, storage: _storage,
key: 'startup-minimized', key: GlobalOptionKeys.startupMinimized,
label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimized, label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimized,
defaultValue: false, defaultValue: false,
); );
late final startupMinimizeInsteadOfExit = ToggleOption( late final startupMinimizeInsteadOfExit = ToggleOption(
storage: _storage, storage: _storage,
key: 'startup-minimize-instead-of-exit', key: GlobalOptionKeys.startupMinimizeInsteadOfExit,
label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimizeInsteadOfExit, label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimizeInsteadOfExit,
defaultValue: false, defaultValue: false,
); );
@ -183,14 +183,14 @@ class GlobalOptions {
late final systemTrayEnabled = ToggleOption( late final systemTrayEnabled = ToggleOption(
storage: _storage, storage: _storage,
key: 'systemtray-enabled', key: GlobalOptionKeys.systemtrayEnabled,
label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayEnabled, label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayEnabled,
defaultValue: false, defaultValue: false,
); );
late final systemTrayHideToTrayWhenMinimized = ToggleOption.depend( late final systemTrayHideToTrayWhenMinimized = ToggleOption.depend(
storage: _storage, storage: _storage,
key: 'systemtray-hide-to-tray-when-minimized', key: GlobalOptionKeys.systemtrayHideToTrayWhenMinimized,
label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayHideToTrayWhenMinimized, label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayHideToTrayWhenMinimized,
defaultValue: true, defaultValue: true,
enabled: systemTrayEnabled, enabled: systemTrayEnabled,
@ -198,14 +198,14 @@ class GlobalOptions {
late final rememberLastUsedAccount = ToggleOption( late final rememberLastUsedAccount = ToggleOption(
storage: _storage, storage: _storage,
key: 'remember-last-used-account', key: GlobalOptionKeys.rememberLastUsedAccount,
label: (final context) => AppLocalizations.of(context).globalOptionsAccountsRememberLastUsedAccount, label: (final context) => AppLocalizations.of(context).globalOptionsAccountsRememberLastUsedAccount,
defaultValue: true, defaultValue: true,
); );
late final initialAccount = SelectOption<String?>( late final initialAccount = SelectOption<String?>(
storage: _storage, storage: _storage,
key: 'initial-account', key: GlobalOptionKeys.initialAccount,
label: (final context) => AppLocalizations.of(context).globalOptionsAccountsInitialAccount, label: (final context) => AppLocalizations.of(context).globalOptionsAccountsInitialAccount,
defaultValue: null, defaultValue: null,
values: {}, values: {},
@ -213,7 +213,7 @@ class GlobalOptions {
late final navigationMode = SelectOption<NavigationMode>( late final navigationMode = SelectOption<NavigationMode>(
storage: _storage, storage: _storage,
key: 'navigation-mode', key: GlobalOptionKeys.navigationMode,
label: (final context) => AppLocalizations.of(context).globalOptionsNavigationMode, label: (final context) => AppLocalizations.of(context).globalOptionsNavigationMode,
defaultValue: Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible, defaultValue: Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible,
values: { values: {
@ -228,6 +228,26 @@ class GlobalOptions {
); );
} }
enum GlobalOptionKeys implements Storable {
themeMode._('theme-mode'),
themeOledAsDark._('theme-oled-as-dark'),
themeKeepOriginalAccentColor._('theme-keep-original-accent-color'),
pushNotificationsEnabled._('push-notifications-enabled'),
pushNotificationsDistributor._('push-notifications-distributor'),
startupMinimized._('startup-minimized'),
startupMinimizeInsteadOfExit._('startup-minimize-instead-of-exit'),
systemtrayEnabled._('systemtray-enabled'),
systemtrayHideToTrayWhenMinimized._('systemtray-hide-to-tray-when-minimized'),
rememberLastUsedAccount._('remember-last-used-account'),
initialAccount._('initial-account'),
navigationMode._('navigation-mode');
const GlobalOptionKeys._(this.value);
@override
final String value;
}
enum NavigationMode { enum NavigationMode {
drawer, drawer,
drawerAlwaysVisible, drawerAlwaysVisible,

2
packages/neon/neon/lib/src/utils/settings_export_helper.dart

@ -53,7 +53,7 @@ class SettingsExportHelper {
Future _applyOptionsMapToOptions(final List<Option> options, final Map<String, dynamic> data) async { Future _applyOptionsMapToOptions(final List<Option> options, final Map<String, dynamic> data) async {
for (final optionKey in data.keys) { for (final optionKey in data.keys) {
for (final option in options) { for (final option in options) {
if (option.key == optionKey) { if (option.key.value == optionKey) {
final Object? value = data[optionKey]; final Object? value = data[optionKey];
if (value != null) { if (value != null) {

31
packages/neon/neon/test/option_test.dart

@ -15,6 +15,15 @@ class MockCallbackFunction extends Mock {
FutureOr<void> call(); FutureOr<void> call();
} }
enum StorageKey implements Storable {
key._('storage-key');
const StorageKey._(this.value);
@override
final String value;
}
enum SelectValues { enum SelectValues {
first, first,
second, second,
@ -23,7 +32,7 @@ enum SelectValues {
void main() { void main() {
final storage = MockStorage(); final storage = MockStorage();
const key = 'storage-key'; const key = StorageKey.key;
String labelBuilder(final _) => 'label'; String labelBuilder(final _) => 'label';
group('SelectOption', () { group('SelectOption', () {
@ -36,8 +45,8 @@ void main() {
late SelectOption<SelectValues> option; late SelectOption<SelectValues> option;
setUp(() { setUp(() {
when(() => storage.setString(key, any())).thenAnswer((final _) async {}); when(() => storage.setString(key.value, any())).thenAnswer((final _) async {});
when(() => storage.remove(key)).thenAnswer((final _) async => true); when(() => storage.remove(key.value)).thenAnswer((final _) async => true);
option = SelectOption<SelectValues>( option = SelectOption<SelectValues>(
storage: storage, storage: storage,
@ -56,7 +65,7 @@ void main() {
test('Create', () { test('Create', () {
expect(option.value, option.defaultValue, reason: 'Should default to defaultValue.'); expect(option.value, option.defaultValue, reason: 'Should default to defaultValue.');
when(() => storage.getString(key)).thenReturn('SelectValues.second'); when(() => storage.getString(key.value)).thenReturn('SelectValues.second');
option = SelectOption<SelectValues>( option = SelectOption<SelectValues>(
storage: storage, storage: storage,
@ -96,7 +105,7 @@ void main() {
..value = SelectValues.third; ..value = SelectValues.third;
verify(callback.call).called(1); verify(callback.call).called(1);
verify(() => storage.setString(key, 'SelectValues.third')).called(1); verify(() => storage.setString(key.value, 'SelectValues.third')).called(1);
expect(option.value, SelectValues.third, reason: 'Should update the value.'); expect(option.value, SelectValues.third, reason: 'Should update the value.');
option.value = SelectValues.third; option.value = SelectValues.third;
@ -150,7 +159,7 @@ void main() {
option.reset(); option.reset();
verify(callback.call).called(1); verify(callback.call).called(1);
verify(() => storage.remove(key)).called(1); verify(() => storage.remove(key.value)).called(1);
expect(option.value, option.defaultValue, reason: 'Should reset the value.'); expect(option.value, option.defaultValue, reason: 'Should reset the value.');
}); });
@ -171,8 +180,8 @@ void main() {
late ToggleOption option; late ToggleOption option;
setUp(() { setUp(() {
when(() => storage.setBool(key, any())).thenAnswer((final _) async {}); when(() => storage.setBool(key.value, any())).thenAnswer((final _) async {});
when(() => storage.remove(key)).thenAnswer((final _) async => true); when(() => storage.remove(key.value)).thenAnswer((final _) async => true);
option = ToggleOption( option = ToggleOption(
storage: storage, storage: storage,
@ -190,7 +199,7 @@ void main() {
test('Create', () { test('Create', () {
expect(option.value, option.defaultValue, reason: 'Should default to defaultValue.'); expect(option.value, option.defaultValue, reason: 'Should default to defaultValue.');
when(() => storage.getBool(key)).thenReturn(true); when(() => storage.getBool(key.value)).thenReturn(true);
option = ToggleOption( option = ToggleOption(
storage: storage, storage: storage,
@ -228,7 +237,7 @@ void main() {
..value = false; ..value = false;
verify(callback.call).called(1); verify(callback.call).called(1);
verify(() => storage.setBool(key, false)).called(1); verify(() => storage.setBool(key.value, false)).called(1);
expect(option.value, false, reason: 'Should update the value.'); expect(option.value, false, reason: 'Should update the value.');
option.value = false; option.value = false;
@ -262,7 +271,7 @@ void main() {
option.reset(); option.reset();
verify(callback.call).called(1); verify(callback.call).called(1);
verify(() => storage.remove(key)).called(1); verify(() => storage.remove(key.value)).called(1);
expect(option.value, option.defaultValue, reason: 'Should reset the value.'); expect(option.value, option.defaultValue, reason: 'Should reset the value.');
}); });
}); });

29
packages/neon/neon_files/lib/options.dart

@ -23,7 +23,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final filesSortPropertyOption = SelectOption<FilesSortProperty>( late final filesSortPropertyOption = SelectOption<FilesSortProperty>(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'files-sort-property', key: FilesOptionKeys.sortProperty,
label: (final context) => AppLocalizations.of(context).optionsFilesSortProperty, label: (final context) => AppLocalizations.of(context).optionsFilesSortProperty,
defaultValue: FilesSortProperty.name, defaultValue: FilesSortProperty.name,
values: { values: {
@ -37,7 +37,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final filesSortBoxOrderOption = SelectOption<SortBoxOrder>( late final filesSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'files-sort-box-order', key: FilesOptionKeys.sortOrder,
label: (final context) => AppLocalizations.of(context).optionsFilesSortOrder, label: (final context) => AppLocalizations.of(context).optionsFilesSortOrder,
defaultValue: SortBoxOrder.ascending, defaultValue: SortBoxOrder.ascending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
@ -46,7 +46,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final showPreviewsOption = ToggleOption( late final showPreviewsOption = ToggleOption(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'show-previews', key: FilesOptionKeys.showPreviews,
label: (final context) => AppLocalizations.of(context).optionsShowPreviews, label: (final context) => AppLocalizations.of(context).optionsShowPreviews,
defaultValue: true, defaultValue: true,
); );
@ -54,7 +54,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final uploadQueueParallelism = SelectOption<int>( late final uploadQueueParallelism = SelectOption<int>(
storage: storage, storage: storage,
category: generalCategory, category: generalCategory,
key: 'upload-queue-parallelism', key: FilesOptionKeys.uploadQueueParallelism,
label: (final context) => AppLocalizations.of(context).optionsUploadQueueParallelism, label: (final context) => AppLocalizations.of(context).optionsUploadQueueParallelism,
defaultValue: 4, defaultValue: 4,
values: { values: {
@ -67,7 +67,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final downloadQueueParallelism = SelectOption<int>( late final downloadQueueParallelism = SelectOption<int>(
storage: storage, storage: storage,
category: generalCategory, category: generalCategory,
key: 'download-queue-parallelism', key: FilesOptionKeys.downloadQueueParallelism,
label: (final context) => AppLocalizations.of(context).optionsDownloadQueueParallelism, label: (final context) => AppLocalizations.of(context).optionsDownloadQueueParallelism,
defaultValue: 4, defaultValue: 4,
values: { values: {
@ -97,7 +97,7 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final uploadSizeWarning = SelectOption<int?>( late final uploadSizeWarning = SelectOption<int?>(
storage: storage, storage: storage,
category: generalCategory, category: generalCategory,
key: 'upload-size-warning', key: FilesOptionKeys.uploadQueueParallelism,
label: (final context) => AppLocalizations.of(context).optionsUploadSizeWarning, label: (final context) => AppLocalizations.of(context).optionsUploadSizeWarning,
defaultValue: _mb(10), defaultValue: _mb(10),
values: _sizeWarningValues, values: _sizeWarningValues,
@ -106,13 +106,28 @@ class FilesAppSpecificOptions extends NextcloudAppOptions {
late final downloadSizeWarning = SelectOption<int?>( late final downloadSizeWarning = SelectOption<int?>(
storage: storage, storage: storage,
category: generalCategory, category: generalCategory,
key: 'download-size-warning', key: FilesOptionKeys.downloadSizeWarning,
label: (final context) => AppLocalizations.of(context).optionsDownloadSizeWarning, label: (final context) => AppLocalizations.of(context).optionsDownloadSizeWarning,
defaultValue: _mb(10), defaultValue: _mb(10),
values: _sizeWarningValues, values: _sizeWarningValues,
); );
} }
enum FilesOptionKeys implements Storable {
sortProperty._('files-sort-property'),
sortOrder._('files-sort-box-order'),
showPreviews._('show-previews'),
uploadQueueParallelism._('upload-queue-parallelism'),
downloadQueueParallelism._('download-queue-parallelism'),
uploadSizeWarning._('upload-size-warning'),
downloadSizeWarning._('download-size-warning');
const FilesOptionKeys._(this.value);
@override
final String value;
}
enum FilesSortProperty { enum FilesSortProperty {
name, name,
modifiedDate, modifiedDate,

41
packages/neon/neon_news/lib/options.dart

@ -42,7 +42,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final defaultCategoryOption = SelectOption<DefaultCategory>( late final defaultCategoryOption = SelectOption<DefaultCategory>(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'default-category', key: NewsOptionKeys.defaultCategory,
label: (final context) => AppLocalizations.of(context).optionsDefaultCategory, label: (final context) => AppLocalizations.of(context).optionsDefaultCategory,
defaultValue: DefaultCategory.articles, defaultValue: DefaultCategory.articles,
values: { values: {
@ -55,7 +55,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final articleViewTypeOption = SelectOption<ArticleViewType>( late final articleViewTypeOption = SelectOption<ArticleViewType>(
storage: super.storage, storage: super.storage,
category: articlesCategory, category: articlesCategory,
key: 'article-view-type', key: NewsOptionKeys.articleViewType,
label: (final context) => AppLocalizations.of(context).optionsArticleViewType, label: (final context) => AppLocalizations.of(context).optionsArticleViewType,
defaultValue: ArticleViewType.direct, defaultValue: ArticleViewType.direct,
values: { values: {
@ -71,7 +71,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final articleDisableMarkAsReadTimeoutOption = ToggleOption( late final articleDisableMarkAsReadTimeoutOption = ToggleOption(
storage: super.storage, storage: super.storage,
category: articlesCategory, category: articlesCategory,
key: 'article-disable-mark-as-read-timeout', key: NewsOptionKeys.articleDisableMarkAsReadTimeout,
label: (final context) => AppLocalizations.of(context).optionsArticleDisableMarkAsReadTimeout, label: (final context) => AppLocalizations.of(context).optionsArticleDisableMarkAsReadTimeout,
defaultValue: false, defaultValue: false,
); );
@ -79,7 +79,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final defaultArticlesFilterOption = SelectOption<FilterType>( late final defaultArticlesFilterOption = SelectOption<FilterType>(
storage: super.storage, storage: super.storage,
category: articlesCategory, category: articlesCategory,
key: 'default-articles-filter', key: NewsOptionKeys.defaultArticlesFilter,
label: (final context) => AppLocalizations.of(context).optionsDefaultArticlesFilter, label: (final context) => AppLocalizations.of(context).optionsDefaultArticlesFilter,
defaultValue: FilterType.unread, defaultValue: FilterType.unread,
values: { values: {
@ -92,7 +92,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final articlesSortPropertyOption = SelectOption<ArticlesSortProperty>( late final articlesSortPropertyOption = SelectOption<ArticlesSortProperty>(
storage: super.storage, storage: super.storage,
category: articlesCategory, category: articlesCategory,
key: 'articles-sort-property', key: NewsOptionKeys.articlesSortProperty,
label: (final context) => AppLocalizations.of(context).optionsArticlesSortProperty, label: (final context) => AppLocalizations.of(context).optionsArticlesSortProperty,
defaultValue: ArticlesSortProperty.publishDate, defaultValue: ArticlesSortProperty.publishDate,
values: { values: {
@ -107,7 +107,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final articlesSortBoxOrderOption = SelectOption<SortBoxOrder>( late final articlesSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: articlesCategory, category: articlesCategory,
key: 'articles-sort-box-order', key: NewsOptionKeys.articlesSortBoxOrder,
label: (final context) => AppLocalizations.of(context).optionsArticlesSortOrder, label: (final context) => AppLocalizations.of(context).optionsArticlesSortOrder,
defaultValue: SortBoxOrder.descending, defaultValue: SortBoxOrder.descending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
@ -116,7 +116,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final foldersSortPropertyOption = SelectOption<FoldersSortProperty>( late final foldersSortPropertyOption = SelectOption<FoldersSortProperty>(
storage: super.storage, storage: super.storage,
category: foldersCategory, category: foldersCategory,
key: 'folders-sort-property', key: NewsOptionKeys.foldersSortProperty,
label: (final context) => AppLocalizations.of(context).optionsFoldersSortProperty, label: (final context) => AppLocalizations.of(context).optionsFoldersSortProperty,
defaultValue: FoldersSortProperty.alphabetical, defaultValue: FoldersSortProperty.alphabetical,
values: { values: {
@ -130,7 +130,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final foldersSortBoxOrderOption = SelectOption<SortBoxOrder>( late final foldersSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: foldersCategory, category: foldersCategory,
key: 'folders-sort-box-order', key: NewsOptionKeys.foldersSortBoxOrder,
label: (final context) => AppLocalizations.of(context).optionsFoldersSortOrder, label: (final context) => AppLocalizations.of(context).optionsFoldersSortOrder,
defaultValue: SortBoxOrder.ascending, defaultValue: SortBoxOrder.ascending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
@ -139,7 +139,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final defaultFolderViewTypeOption = SelectOption<DefaultFolderViewType>( late final defaultFolderViewTypeOption = SelectOption<DefaultFolderViewType>(
storage: super.storage, storage: super.storage,
category: foldersCategory, category: foldersCategory,
key: 'default-folder-view-type', key: NewsOptionKeys.defaultFolderViewType,
label: (final context) => AppLocalizations.of(context).optionsDefaultFolderViewType, label: (final context) => AppLocalizations.of(context).optionsDefaultFolderViewType,
defaultValue: DefaultFolderViewType.articles, defaultValue: DefaultFolderViewType.articles,
values: { values: {
@ -151,7 +151,7 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final feedsSortPropertyOption = SelectOption<FeedsSortProperty>( late final feedsSortPropertyOption = SelectOption<FeedsSortProperty>(
storage: super.storage, storage: super.storage,
category: feedsCategory, category: feedsCategory,
key: 'feeds-sort-property', key: NewsOptionKeys.feedsSortProperty,
label: (final context) => AppLocalizations.of(context).optionsFeedsSortProperty, label: (final context) => AppLocalizations.of(context).optionsFeedsSortProperty,
defaultValue: FeedsSortProperty.alphabetical, defaultValue: FeedsSortProperty.alphabetical,
values: { values: {
@ -165,13 +165,32 @@ class NewsAppSpecificOptions extends NextcloudAppOptions {
late final feedsSortBoxOrderOption = SelectOption<SortBoxOrder>( late final feedsSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: feedsCategory, category: feedsCategory,
key: 'feeds-sort-box-order', key: NewsOptionKeys.feedsSortBoxOrder,
label: (final context) => AppLocalizations.of(context).optionsFeedsSortOrder, label: (final context) => AppLocalizations.of(context).optionsFeedsSortOrder,
defaultValue: SortBoxOrder.ascending, defaultValue: SortBoxOrder.ascending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
); );
} }
enum NewsOptionKeys implements Storable {
defaultCategory._('default-category'),
articleViewType._('article-view-type'),
articleDisableMarkAsReadTimeout._('article-disable-mark-as-read-timeout'),
defaultArticlesFilter._('default-articles-filter'),
articlesSortProperty._('articles-sort-property'),
articlesSortBoxOrder._('articles-sort-box-order'),
foldersSortProperty._('folders-sort-property'),
foldersSortBoxOrder._('folders-sort-box-order'),
defaultFolderViewType._('default-folder-view-type'),
feedsSortProperty._('feeds-sort-property'),
feedsSortBoxOrder._('feeds-sort-box-order');
const NewsOptionKeys._(this.value);
@override
final String value;
}
enum DefaultCategory { enum DefaultCategory {
articles, articles,
folders, folders,

26
packages/neon/neon_notes/lib/options.dart

@ -32,7 +32,7 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final defaultCategoryOption = SelectOption<DefaultCategory>( late final defaultCategoryOption = SelectOption<DefaultCategory>(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'default-category', key: NotesOptionKeys.defaultCategory,
label: (final context) => AppLocalizations.of(context).optionsDefaultCategory, label: (final context) => AppLocalizations.of(context).optionsDefaultCategory,
defaultValue: DefaultCategory.notes, defaultValue: DefaultCategory.notes,
values: { values: {
@ -44,7 +44,7 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final defaultNoteViewTypeOption = SelectOption<DefaultNoteViewType>( late final defaultNoteViewTypeOption = SelectOption<DefaultNoteViewType>(
storage: super.storage, storage: super.storage,
category: generalCategory, category: generalCategory,
key: 'default-note-view-type', key: NotesOptionKeys.defaultNoteViewType,
label: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewType, label: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewType,
defaultValue: DefaultNoteViewType.preview, defaultValue: DefaultNoteViewType.preview,
values: { values: {
@ -56,7 +56,7 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final notesSortPropertyOption = SelectOption<NotesSortProperty>( late final notesSortPropertyOption = SelectOption<NotesSortProperty>(
storage: super.storage, storage: super.storage,
category: notesCategory, category: notesCategory,
key: 'notes-sort-property', key: NotesOptionKeys.notesSortProperty,
label: (final context) => AppLocalizations.of(context).optionsNotesSortProperty, label: (final context) => AppLocalizations.of(context).optionsNotesSortProperty,
defaultValue: NotesSortProperty.lastModified, defaultValue: NotesSortProperty.lastModified,
values: { values: {
@ -70,7 +70,7 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final notesSortBoxOrderOption = SelectOption<SortBoxOrder>( late final notesSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: notesCategory, category: notesCategory,
key: 'notes-sort-box-order', key: NotesOptionKeys.notesSortBoxOrder,
label: (final context) => AppLocalizations.of(context).optionsNotesSortOrder, label: (final context) => AppLocalizations.of(context).optionsNotesSortOrder,
defaultValue: SortBoxOrder.descending, defaultValue: SortBoxOrder.descending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
@ -79,7 +79,7 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final categoriesSortPropertyOption = SelectOption<CategoriesSortProperty>( late final categoriesSortPropertyOption = SelectOption<CategoriesSortProperty>(
storage: super.storage, storage: super.storage,
category: categoriesCategory, category: categoriesCategory,
key: 'categories-sort-property', key: NotesOptionKeys.categoriesSortProperty,
label: (final context) => AppLocalizations.of(context).optionsCategoriesSortProperty, label: (final context) => AppLocalizations.of(context).optionsCategoriesSortProperty,
defaultValue: CategoriesSortProperty.alphabetical, defaultValue: CategoriesSortProperty.alphabetical,
values: { values: {
@ -93,13 +93,27 @@ class NotesAppSpecificOptions extends NextcloudAppOptions {
late final categoriesSortBoxOrderOption = SelectOption<SortBoxOrder>( late final categoriesSortBoxOrderOption = SelectOption<SortBoxOrder>(
storage: super.storage, storage: super.storage,
category: categoriesCategory, category: categoriesCategory,
key: 'categories-sort-box-order', key: NotesOptionKeys.categoriesSortBoxOrder,
label: (final context) => AppLocalizations.of(context).optionsCategoriesSortOrder, label: (final context) => AppLocalizations.of(context).optionsCategoriesSortOrder,
defaultValue: SortBoxOrder.ascending, defaultValue: SortBoxOrder.ascending,
values: sortBoxOrderOptionValues, values: sortBoxOrderOptionValues,
); );
} }
enum NotesOptionKeys implements Storable {
defaultCategory._('default-category'),
defaultNoteViewType._('default-note-view-type'),
notesSortProperty._('notes-sort-property'),
notesSortBoxOrder._('notes-sort-box-order'),
categoriesSortProperty._('categories-sort-property'),
categoriesSortBoxOrder._('categories-sort-box-order');
const NotesOptionKeys._(this.value);
@override
final String value;
}
enum DefaultNoteViewType { enum DefaultNoteViewType {
preview, preview,
edit, edit,

Loading…
Cancel
Save