Browse Source

Merge pull request #389 from Leptopoda/refactor/option

Refactor/option
pull/394/head
Nikolas Rimikis 1 year ago committed by GitHub
parent
commit
bba5c2b575
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/neon/neon/lib/src/utils/account_options.dart
  2. 26
      packages/neon/neon/lib/src/utils/global_options.dart
  3. 14
      packages/neon/neon_files/lib/options.dart
  4. 22
      packages/neon/neon_news/lib/options.dart
  5. 12
      packages/neon/neon_notes/lib/options.dart
  6. 16
      packages/settings/lib/src/options/option.dart
  7. 2
      packages/settings/lib/src/options/select_option.dart
  8. 2
      packages/settings/lib/src/options/toggle_option.dart
  9. 12
      packages/settings/lib/src/widgets/option_builder.dart

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

@ -42,7 +42,7 @@ class AccountSpecificOptions {
storage: _storage, storage: _storage,
key: 'initial-app', key: 'initial-app',
label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp, label: (final context) => AppLocalizations.of(context).accountOptionsInitialApp,
defaultValue: BehaviorSubject.seeded(null), defaultValue: null,
values: _appIDsSubject, values: _appIDsSubject,
); );
} }

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

@ -124,7 +124,7 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'theme-mode', key: 'theme-mode',
label: (final context) => AppLocalizations.of(context).globalOptionsThemeMode, label: (final context) => AppLocalizations.of(context).globalOptionsThemeMode,
defaultValue: BehaviorSubject.seeded(ThemeMode.system), defaultValue: ThemeMode.system,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
ThemeMode.light: (final context) => AppLocalizations.of(context).globalOptionsThemeModeLight, ThemeMode.light: (final context) => AppLocalizations.of(context).globalOptionsThemeModeLight,
ThemeMode.dark: (final context) => AppLocalizations.of(context).globalOptionsThemeModeDark, ThemeMode.dark: (final context) => AppLocalizations.of(context).globalOptionsThemeModeDark,
@ -136,7 +136,7 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'theme-oled-as-dark', key: 'theme-oled-as-dark',
label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark, label: (final context) => AppLocalizations.of(context).globalOptionsThemeOLEDAsDark,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
enabled: _themeOLEDAsDarkEnabledSubject, enabled: _themeOLEDAsDarkEnabledSubject,
); );
@ -144,14 +144,14 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'theme-keep-original-accent-color', key: 'theme-keep-original-accent-color',
label: (final context) => AppLocalizations.of(context).globalOptionsThemeKeepOriginalAccentColor, label: (final context) => AppLocalizations.of(context).globalOptionsThemeKeepOriginalAccentColor,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
); );
late final pushNotificationsEnabled = ToggleOption( late final pushNotificationsEnabled = ToggleOption(
storage: _storage, storage: _storage,
key: 'push-notifications-enabled', key: 'push-notifications-enabled',
label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsEnabled, label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsEnabled,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
enabled: _pushNotificationsEnabledEnabledSubject, enabled: _pushNotificationsEnabledEnabledSubject,
); );
@ -159,7 +159,7 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'push-notifications-distributor', key: 'push-notifications-distributor',
label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsDistributor, label: (final context) => AppLocalizations.of(context).globalOptionsPushNotificationsDistributor,
defaultValue: BehaviorSubject.seeded(null), defaultValue: null,
values: _pushNotificationsDistributorsSubject, values: _pushNotificationsDistributorsSubject,
enabled: pushNotificationsEnabled.stream, enabled: pushNotificationsEnabled.stream,
); );
@ -168,14 +168,14 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'startup-minimized', key: 'startup-minimized',
label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimized, label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimized,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
); );
late final startupMinimizeInsteadOfExit = ToggleOption( late final startupMinimizeInsteadOfExit = ToggleOption(
storage: _storage, storage: _storage,
key: 'startup-minimize-instead-of-exit', key: 'startup-minimize-instead-of-exit',
label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimizeInsteadOfExit, label: (final context) => AppLocalizations.of(context).globalOptionsStartupMinimizeInsteadOfExit,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
); );
// TODO: Autostart option // TODO: Autostart option
@ -184,14 +184,14 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'systemtray-enabled', key: 'systemtray-enabled',
label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayEnabled, label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayEnabled,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
); );
late final systemTrayHideToTrayWhenMinimized = ToggleOption( late final systemTrayHideToTrayWhenMinimized = ToggleOption(
storage: _storage, storage: _storage,
key: 'systemtray-hide-to-tray-when-minimized', key: 'systemtray-hide-to-tray-when-minimized',
label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayHideToTrayWhenMinimized, label: (final context) => AppLocalizations.of(context).globalOptionsSystemTrayHideToTrayWhenMinimized,
defaultValue: BehaviorSubject.seeded(true), defaultValue: true,
enabled: systemTrayEnabled.stream, enabled: systemTrayEnabled.stream,
); );
@ -199,14 +199,14 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'remember-last-used-account', key: 'remember-last-used-account',
label: (final context) => AppLocalizations.of(context).globalOptionsAccountsRememberLastUsedAccount, label: (final context) => AppLocalizations.of(context).globalOptionsAccountsRememberLastUsedAccount,
defaultValue: BehaviorSubject.seeded(true), defaultValue: true,
); );
late final initialAccount = SelectOption<String?>( late final initialAccount = SelectOption<String?>(
storage: _storage, storage: _storage,
key: 'initial-account', key: 'initial-account',
label: (final context) => AppLocalizations.of(context).globalOptionsAccountsInitialAccount, label: (final context) => AppLocalizations.of(context).globalOptionsAccountsInitialAccount,
defaultValue: BehaviorSubject.seeded(null), defaultValue: null,
values: _accountsIDsSubject, values: _accountsIDsSubject,
enabled: _initialAccountEnabledSubject, enabled: _initialAccountEnabledSubject,
); );
@ -215,9 +215,7 @@ class GlobalOptions {
storage: _storage, storage: _storage,
key: 'navigation-mode', key: 'navigation-mode',
label: (final context) => AppLocalizations.of(context).globalOptionsNavigationMode, label: (final context) => AppLocalizations.of(context).globalOptionsNavigationMode,
defaultValue: BehaviorSubject.seeded( defaultValue: Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible,
Platform.isAndroid || Platform.isIOS ? NavigationMode.drawer : NavigationMode.drawerAlwaysVisible,
),
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
NavigationMode.drawer: (final context) => AppLocalizations.of(context).globalOptionsNavigationModeDrawer, NavigationMode.drawer: (final context) => AppLocalizations.of(context).globalOptionsNavigationModeDrawer,
if (!Platform.isAndroid && !Platform.isIOS) ...{ if (!Platform.isAndroid && !Platform.isIOS) ...{

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

@ -25,7 +25,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'files-sort-property', key: 'files-sort-property',
label: (final context) => AppLocalizations.of(context).optionsFilesSortProperty, label: (final context) => AppLocalizations.of(context).optionsFilesSortProperty,
defaultValue: BehaviorSubject.seeded(FilesSortProperty.name), defaultValue: FilesSortProperty.name,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
FilesSortProperty.name: (final context) => AppLocalizations.of(context).optionsFilesSortPropertyName, FilesSortProperty.name: (final context) => AppLocalizations.of(context).optionsFilesSortPropertyName,
FilesSortProperty.modifiedDate: (final context) => FilesSortProperty.modifiedDate: (final context) =>
@ -39,7 +39,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'files-sort-box-order', key: 'files-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsFilesSortOrder, label: (final context) => AppLocalizations.of(context).optionsFilesSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.ascending), defaultValue: SortBoxOrder.ascending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
@ -48,7 +48,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'show-previews', key: 'show-previews',
label: (final context) => AppLocalizations.of(context).optionsShowPreviews, label: (final context) => AppLocalizations.of(context).optionsShowPreviews,
defaultValue: BehaviorSubject.seeded(true), defaultValue: true,
); );
late final uploadQueueParallelism = SelectOption<int>( late final uploadQueueParallelism = SelectOption<int>(
@ -56,7 +56,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'upload-queue-parallelism', key: 'upload-queue-parallelism',
label: (final context) => AppLocalizations.of(context).optionsUploadQueueParallelism, label: (final context) => AppLocalizations.of(context).optionsUploadQueueParallelism,
defaultValue: BehaviorSubject.seeded(4), defaultValue: 4,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
for (var i = 1; i <= 16; i = i * 2) ...{ for (var i = 1; i <= 16; i = i * 2) ...{
i: (final _) => i.toString(), i: (final _) => i.toString(),
@ -69,7 +69,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'download-queue-parallelism', key: 'download-queue-parallelism',
label: (final context) => AppLocalizations.of(context).optionsDownloadQueueParallelism, label: (final context) => AppLocalizations.of(context).optionsDownloadQueueParallelism,
defaultValue: BehaviorSubject.seeded(4), defaultValue: 4,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
for (var i = 1; i <= 16; i = i * 2) ...{ for (var i = 1; i <= 16; i = i * 2) ...{
i: (final _) => i.toString(), i: (final _) => i.toString(),
@ -99,7 +99,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'upload-size-warning', key: 'upload-size-warning',
label: (final context) => AppLocalizations.of(context).optionsUploadSizeWarning, label: (final context) => AppLocalizations.of(context).optionsUploadSizeWarning,
defaultValue: BehaviorSubject.seeded(_mb(10)), defaultValue: _mb(10),
values: BehaviorSubject.seeded(_sizeWarningValues), values: BehaviorSubject.seeded(_sizeWarningValues),
); );
@ -108,7 +108,7 @@ class FilesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'download-size-warning', key: 'download-size-warning',
label: (final context) => AppLocalizations.of(context).optionsDownloadSizeWarning, label: (final context) => AppLocalizations.of(context).optionsDownloadSizeWarning,
defaultValue: BehaviorSubject.seeded(_mb(10)), defaultValue: _mb(10),
values: BehaviorSubject.seeded(_sizeWarningValues), values: BehaviorSubject.seeded(_sizeWarningValues),
); );
} }

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

@ -56,7 +56,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'default-category', key: 'default-category',
label: (final context) => AppLocalizations.of(context).optionsDefaultCategory, label: (final context) => AppLocalizations.of(context).optionsDefaultCategory,
defaultValue: BehaviorSubject.seeded(DefaultCategory.articles), defaultValue: DefaultCategory.articles,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
DefaultCategory.articles: (final context) => AppLocalizations.of(context).articles, DefaultCategory.articles: (final context) => AppLocalizations.of(context).articles,
DefaultCategory.folders: (final context) => AppLocalizations.of(context).folders, DefaultCategory.folders: (final context) => AppLocalizations.of(context).folders,
@ -69,7 +69,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: articlesCategory, category: articlesCategory,
key: 'article-view-type', key: 'article-view-type',
label: (final context) => AppLocalizations.of(context).optionsArticleViewType, label: (final context) => AppLocalizations.of(context).optionsArticleViewType,
defaultValue: BehaviorSubject.seeded(ArticleViewType.direct), defaultValue: ArticleViewType.direct,
values: _articleViewTypeValuesSubject, values: _articleViewTypeValuesSubject,
); );
@ -78,7 +78,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: articlesCategory, category: articlesCategory,
key: 'article-disable-mark-as-read-timeout', key: 'article-disable-mark-as-read-timeout',
label: (final context) => AppLocalizations.of(context).optionsArticleDisableMarkAsReadTimeout, label: (final context) => AppLocalizations.of(context).optionsArticleDisableMarkAsReadTimeout,
defaultValue: BehaviorSubject.seeded(false), defaultValue: false,
); );
late final defaultArticlesFilterOption = SelectOption<FilterType>( late final defaultArticlesFilterOption = SelectOption<FilterType>(
@ -86,7 +86,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: articlesCategory, category: articlesCategory,
key: 'default-articles-filter', key: 'default-articles-filter',
label: (final context) => AppLocalizations.of(context).optionsDefaultArticlesFilter, label: (final context) => AppLocalizations.of(context).optionsDefaultArticlesFilter,
defaultValue: BehaviorSubject.seeded(FilterType.unread), defaultValue: FilterType.unread,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
FilterType.all: (final context) => AppLocalizations.of(context).articlesFilterAll, FilterType.all: (final context) => AppLocalizations.of(context).articlesFilterAll,
FilterType.unread: (final context) => AppLocalizations.of(context).articlesFilterUnread, FilterType.unread: (final context) => AppLocalizations.of(context).articlesFilterUnread,
@ -99,7 +99,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: articlesCategory, category: articlesCategory,
key: 'articles-sort-property', key: 'articles-sort-property',
label: (final context) => AppLocalizations.of(context).optionsArticlesSortProperty, label: (final context) => AppLocalizations.of(context).optionsArticlesSortProperty,
defaultValue: BehaviorSubject.seeded(ArticlesSortProperty.publishDate), defaultValue: ArticlesSortProperty.publishDate,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
ArticlesSortProperty.publishDate: (final context) => ArticlesSortProperty.publishDate: (final context) =>
AppLocalizations.of(context).optionsArticlesSortPropertyPublishDate, AppLocalizations.of(context).optionsArticlesSortPropertyPublishDate,
@ -114,7 +114,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: articlesCategory, category: articlesCategory,
key: 'articles-sort-box-order', key: 'articles-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsArticlesSortOrder, label: (final context) => AppLocalizations.of(context).optionsArticlesSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.descending), defaultValue: SortBoxOrder.descending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
@ -123,7 +123,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: foldersCategory, category: foldersCategory,
key: 'folders-sort-property', key: 'folders-sort-property',
label: (final context) => AppLocalizations.of(context).optionsFoldersSortProperty, label: (final context) => AppLocalizations.of(context).optionsFoldersSortProperty,
defaultValue: BehaviorSubject.seeded(FoldersSortProperty.alphabetical), defaultValue: FoldersSortProperty.alphabetical,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
FoldersSortProperty.alphabetical: (final context) => FoldersSortProperty.alphabetical: (final context) =>
AppLocalizations.of(context).optionsFoldersSortPropertyAlphabetical, AppLocalizations.of(context).optionsFoldersSortPropertyAlphabetical,
@ -137,7 +137,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: foldersCategory, category: foldersCategory,
key: 'folders-sort-box-order', key: 'folders-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsFoldersSortOrder, label: (final context) => AppLocalizations.of(context).optionsFoldersSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.ascending), defaultValue: SortBoxOrder.ascending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
@ -146,7 +146,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: foldersCategory, category: foldersCategory,
key: 'default-folder-view-type', key: 'default-folder-view-type',
label: (final context) => AppLocalizations.of(context).optionsDefaultFolderViewType, label: (final context) => AppLocalizations.of(context).optionsDefaultFolderViewType,
defaultValue: BehaviorSubject.seeded(DefaultFolderViewType.articles), defaultValue: DefaultFolderViewType.articles,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
DefaultFolderViewType.articles: (final context) => AppLocalizations.of(context).articles, DefaultFolderViewType.articles: (final context) => AppLocalizations.of(context).articles,
DefaultFolderViewType.feeds: (final context) => AppLocalizations.of(context).feeds, DefaultFolderViewType.feeds: (final context) => AppLocalizations.of(context).feeds,
@ -158,7 +158,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: feedsCategory, category: feedsCategory,
key: 'feeds-sort-property', key: 'feeds-sort-property',
label: (final context) => AppLocalizations.of(context).optionsFeedsSortProperty, label: (final context) => AppLocalizations.of(context).optionsFeedsSortProperty,
defaultValue: BehaviorSubject.seeded(FeedsSortProperty.alphabetical), defaultValue: FeedsSortProperty.alphabetical,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
FeedsSortProperty.alphabetical: (final context) => FeedsSortProperty.alphabetical: (final context) =>
AppLocalizations.of(context).optionsFeedsSortPropertyAlphabetical, AppLocalizations.of(context).optionsFeedsSortPropertyAlphabetical,
@ -172,7 +172,7 @@ class NewsAppSpecificOptions extends NextcloudAppSpecificOptions {
category: feedsCategory, category: feedsCategory,
key: 'feeds-sort-box-order', key: 'feeds-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsFeedsSortOrder, label: (final context) => AppLocalizations.of(context).optionsFeedsSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.ascending), defaultValue: SortBoxOrder.ascending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
} }

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

@ -34,7 +34,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'default-category', key: 'default-category',
label: (final context) => AppLocalizations.of(context).optionsDefaultCategory, label: (final context) => AppLocalizations.of(context).optionsDefaultCategory,
defaultValue: BehaviorSubject.seeded(DefaultCategory.notes), defaultValue: DefaultCategory.notes,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
DefaultCategory.notes: (final context) => AppLocalizations.of(context).notes, DefaultCategory.notes: (final context) => AppLocalizations.of(context).notes,
DefaultCategory.categories: (final context) => AppLocalizations.of(context).categories, DefaultCategory.categories: (final context) => AppLocalizations.of(context).categories,
@ -46,7 +46,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: generalCategory, category: generalCategory,
key: 'default-note-view-type', key: 'default-note-view-type',
label: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewType, label: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewType,
defaultValue: BehaviorSubject.seeded(DefaultNoteViewType.preview), defaultValue: DefaultNoteViewType.preview,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
DefaultNoteViewType.preview: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewTypePreview, DefaultNoteViewType.preview: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewTypePreview,
DefaultNoteViewType.edit: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewTypeEdit, DefaultNoteViewType.edit: (final context) => AppLocalizations.of(context).optionsDefaultNoteViewTypeEdit,
@ -58,7 +58,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: notesCategory, category: notesCategory,
key: 'notes-sort-property', key: 'notes-sort-property',
label: (final context) => AppLocalizations.of(context).optionsNotesSortProperty, label: (final context) => AppLocalizations.of(context).optionsNotesSortProperty,
defaultValue: BehaviorSubject.seeded(NotesSortProperty.lastModified), defaultValue: NotesSortProperty.lastModified,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
NotesSortProperty.lastModified: (final context) => NotesSortProperty.lastModified: (final context) =>
AppLocalizations.of(context).optionsNotesSortPropertyLastModified, AppLocalizations.of(context).optionsNotesSortPropertyLastModified,
@ -72,7 +72,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: notesCategory, category: notesCategory,
key: 'notes-sort-box-order', key: 'notes-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsNotesSortOrder, label: (final context) => AppLocalizations.of(context).optionsNotesSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.descending), defaultValue: SortBoxOrder.descending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
@ -81,7 +81,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: categoriesCategory, category: categoriesCategory,
key: 'categories-sort-property', key: 'categories-sort-property',
label: (final context) => AppLocalizations.of(context).optionsCategoriesSortProperty, label: (final context) => AppLocalizations.of(context).optionsCategoriesSortProperty,
defaultValue: BehaviorSubject.seeded(CategoriesSortProperty.alphabetical), defaultValue: CategoriesSortProperty.alphabetical,
values: BehaviorSubject.seeded({ values: BehaviorSubject.seeded({
CategoriesSortProperty.alphabetical: (final context) => CategoriesSortProperty.alphabetical: (final context) =>
AppLocalizations.of(context).optionsCategoriesSortPropertyAlphabetical, AppLocalizations.of(context).optionsCategoriesSortPropertyAlphabetical,
@ -95,7 +95,7 @@ class NotesAppSpecificOptions extends NextcloudAppSpecificOptions {
category: categoriesCategory, category: categoriesCategory,
key: 'categories-sort-box-order', key: 'categories-sort-box-order',
label: (final context) => AppLocalizations.of(context).optionsCategoriesSortOrder, label: (final context) => AppLocalizations.of(context).optionsCategoriesSortOrder,
defaultValue: BehaviorSubject.seeded(SortBoxOrder.ascending), defaultValue: SortBoxOrder.ascending,
values: BehaviorSubject.seeded(sortBoxOrderOptionValues), values: BehaviorSubject.seeded(sortBoxOrderOptionValues),
); );
} }

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

@ -10,20 +10,14 @@ abstract class Option<T> {
required this.defaultValue, required this.defaultValue,
this.category, this.category,
final BehaviorSubject<bool>? enabled, final BehaviorSubject<bool>? enabled,
}) : assert(defaultValue.hasValue, 'When using defaultValue the stream has to be seeded') { }) : enabled = enabled ?? BehaviorSubject<bool>.seeded(true);
if (enabled != null) {
this.enabled = enabled;
} else {
this.enabled = BehaviorSubject<bool>.seeded(true);
}
}
final SettingsStorage storage; final SettingsStorage storage;
final String key; final String key;
final LabelBuilder label; final LabelBuilder label;
final BehaviorSubject<T> defaultValue; final T defaultValue;
final OptionsCategory? category; final OptionsCategory? category;
late final BehaviorSubject<bool> enabled; final BehaviorSubject<bool> enabled;
late BehaviorSubject<T> stream; late BehaviorSubject<T> stream;
T get value { T get value {
@ -31,7 +25,7 @@ abstract class Option<T> {
return stream.value; return stream.value;
} }
return defaultValue.value; return defaultValue;
} }
bool get hasValue { bool get hasValue {
@ -43,7 +37,7 @@ abstract class Option<T> {
} }
Future reset() async { Future reset() async {
await set(defaultValue.value); await set(defaultValue);
} }
void dispose() { void dispose() {

2
packages/settings/lib/src/options/select_option.dart

@ -19,7 +19,7 @@ class SelectOption<T> extends Option<T> {
if (valueStr != null) { if (valueStr != null) {
initialValue = _fromString(vs, valueStr); initialValue = _fromString(vs, valueStr);
} }
stream.add(initialValue ?? await defaultValue.first); stream.add(initialValue ?? defaultValue);
}), }),
); );
} }

2
packages/settings/lib/src/options/toggle_option.dart

@ -9,7 +9,7 @@ class ToggleOption extends Option<bool> {
super.category, super.category,
super.enabled, super.enabled,
}) { }) {
stream = BehaviorSubject.seeded(storage.getBool(key) ?? defaultValue.value); stream = BehaviorSubject.seeded(storage.getBool(key) ?? defaultValue);
} }
@override @override

12
packages/settings/lib/src/widgets/option_builder.dart

@ -12,13 +12,11 @@ class OptionBuilder<T> extends StatelessWidget {
@override @override
Widget build(final BuildContext context) => StreamBuilder<T?>( Widget build(final BuildContext context) => StreamBuilder<T?>(
stream: option.defaultValue, stream: option.stream,
builder: (final context, final defaultValueSnapshot) => StreamBuilder<T?>( initialData: option.defaultValue,
stream: option.stream, builder: (final context, final valueSnapshot) => builder(
builder: (final context, final valueSnapshot) => builder( context,
context, valueSnapshot.data,
valueSnapshot.data ?? defaultValueSnapshot.data,
),
), ),
); );
} }

Loading…
Cancel
Save