diff --git a/CHANGELOG.md b/CHANGELOG.md index acfc4487..26462627 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## 1.8.1 - 2024-11-13 + +### Fixed + +- Crash at startup because of the sorting setting + ## 1.8.0 - 2024-11-23 ### Added diff --git a/RELEASING.md b/RELEASING.md index a9ef3d75..c9f9b961 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -11,7 +11,6 @@ - [ ] Upgrade Flutter and Dart versions - [ ] Bump application version - [ ] Bump dependencies versions -- [ ] Re-generate generated files ### Changelogs diff --git a/fastlane/metadata/android/en-US/changelogs/180.txt b/fastlane/metadata/android/en-US/changelogs/180.txt new file mode 100644 index 00000000..75c1b775 --- /dev/null +++ b/fastlane/metadata/android/en-US/changelogs/180.txt @@ -0,0 +1,2 @@ +FIXED +- Crash at startup because of the sorting setting \ No newline at end of file diff --git a/fastlane/metadata/android/fr-FR/changelogs/170.txt b/fastlane/metadata/android/fr-FR/changelogs/170.txt index eaf5a0a7..85d18fa4 100644 --- a/fastlane/metadata/android/fr-FR/changelogs/170.txt +++ b/fastlane/metadata/android/fr-FR/changelogs/170.txt @@ -1,4 +1,4 @@ -AJOUT +AJOUTÉ - Possibilité de catégoriser les notes avec des étiquettes - Possibilité de trier les notes en fonction de leur date de création - Possibilité d'utiliser un texte blanc avec le thème sombre diff --git a/fastlane/metadata/android/fr-FR/changelogs/180.txt b/fastlane/metadata/android/fr-FR/changelogs/180.txt new file mode 100644 index 00000000..44c1c72b --- /dev/null +++ b/fastlane/metadata/android/fr-FR/changelogs/180.txt @@ -0,0 +1,2 @@ +CORRIGÉ +- Crash au démarrage à cause du paramètre de tri \ No newline at end of file diff --git a/lib/common/extensions/iterable_extension.dart b/lib/common/extensions/iterable_extension.dart new file mode 100644 index 00000000..0eade1ad --- /dev/null +++ b/lib/common/extensions/iterable_extension.dart @@ -0,0 +1,17 @@ +/// Extends the [Iterable] class with some utilities functions. +extension IterableExtension on Iterable { + /// Returns the enum value for the [name] or `null` if it doesn't exist. + T? byNameOrNull(String? name) { + if (name == null) { + return null; + } + + for (var value in this) { + if (value.name == name) { + return value; + } + } + + return null; + } +} diff --git a/lib/common/logs/app_logger.dart b/lib/common/logs/app_logger.dart index 329535f4..6c315007 100644 --- a/lib/common/logs/app_logger.dart +++ b/lib/common/logs/app_logger.dart @@ -80,13 +80,13 @@ class AppLogger { } /// Logs an information message. - void i(String message, {Object? exception, StackTrace? stackTrace}) { + void i(String message, [Object? exception, StackTrace? stackTrace]) { _consoleLogger.i(message, error: exception, stackTrace: stackTrace); _fileLogger.i(message.firstLine, error: exception, stackTrace: stackTrace); } /// Logs a warning message. - void w(String message, {Object? exception, StackTrace? stackTrace}) { + void w(String message, [Object? exception, StackTrace? stackTrace]) { _consoleLogger.w(message, error: exception, stackTrace: stackTrace); _fileLogger.w(message.firstLine, error: exception, stackTrace: stackTrace); } @@ -98,7 +98,7 @@ class AppLogger { } /// Logs a fatal message. - void f(String message, {Object? exception, StackTrace? stackTrace}) { + void f(String message, [Object? exception, StackTrace? stackTrace]) { _consoleLogger.f(message, error: exception, stackTrace: stackTrace); _fileLogger.f(message.firstLine, error: exception, stackTrace: stackTrace); } diff --git a/lib/common/navigation/app_bars/notes_app_bar.dart b/lib/common/navigation/app_bars/notes_app_bar.dart index bfd04c5e..f699144a 100644 --- a/lib/common/navigation/app_bars/notes_app_bar.dart +++ b/lib/common/navigation/app_bars/notes_app_bar.dart @@ -7,7 +7,6 @@ import 'package:localmaterialnotes/common/extensions/build_context_extension.dar import 'package:localmaterialnotes/common/preferences/enums/layout.dart'; import 'package:localmaterialnotes/common/preferences/enums/sort_method.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/common/widgets/notes/note_tile.dart'; import 'package:localmaterialnotes/common/widgets/placeholders/empty_placeholder.dart'; import 'package:localmaterialnotes/models/note/note.dart'; @@ -68,7 +67,7 @@ class NotesAppBar extends ConsumerWidget { void _toggleLayout() { final newLayout = layoutNotifier.value == Layout.list ? Layout.grid : Layout.list; - PreferencesUtils().set(PreferenceKey.layout, newLayout.name); + PreferenceKey.layout.set(newLayout.name); layoutNotifier.value = newLayout; } @@ -79,20 +78,20 @@ class NotesAppBar extends ConsumerWidget { if (sortMethod == SortMethod.ascending) { final oldAscendingPreference = PreferenceKey.sortAscending.getPreferenceOrDefault(); - PreferencesUtils().set(PreferenceKey.sortAscending, !oldAscendingPreference); + PreferenceKey.sortAscending.set(!oldAscendingPreference); } // The 'Date' or 'Title' menu items were taped else if (sortMethod != null) { final forceAscending = sortMethod == SortMethod.title; - PreferencesUtils().set(PreferenceKey.sortMethod, sortMethod.name); - PreferencesUtils().set(PreferenceKey.sortAscending, forceAscending); + PreferenceKey.sortMethod.set(sortMethod.name); + PreferenceKey.sortAscending.set(forceAscending); } // The checkbox of the 'Ascending' menu item was toggled else if (ascending != null) { - PreferencesUtils().set(PreferenceKey.sortAscending, ascending); + PreferenceKey.sortAscending.set(ascending); Navigator.pop(context); } diff --git a/lib/common/preferences/enums/confirmations.dart b/lib/common/preferences/enums/confirmations.dart index eb904176..7a87dcb6 100644 --- a/lib/common/preferences/enums/confirmations.dart +++ b/lib/common/preferences/enums/confirmations.dart @@ -1,6 +1,6 @@ import 'package:localmaterialnotes/common/constants/constants.dart'; +import 'package:localmaterialnotes/common/extensions/iterable_extension.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; /// Lists the options for the confirmations asked for user actions such as pining and deleting notes. enum Confirmations { @@ -16,11 +16,18 @@ enum Confirmations { /// The value of the preference if set, or its default value otherwise. factory Confirmations.fromPreference() { - final preference = PreferencesUtils().get(PreferenceKey.confirmations); + final confirmations = Confirmations.values.byNameOrNull( + PreferenceKey.confirmations.getPreference(), + ); - return preference != null - ? Confirmations.values.byName(preference) - : PreferenceKey.confirmations.defaultValue as Confirmations; + // Reset the malformed preference to its default value + if (confirmations == null) { + PreferenceKey.confirmations.setToDefault(); + + return PreferenceKey.confirmations.defaultValue as Confirmations; + } + + return confirmations; } /// Returns the title of the preference for the settings page. diff --git a/lib/common/preferences/enums/layout.dart b/lib/common/preferences/enums/layout.dart index e968bbf4..ecc8249a 100644 --- a/lib/common/preferences/enums/layout.dart +++ b/lib/common/preferences/enums/layout.dart @@ -1,5 +1,5 @@ +import 'package:localmaterialnotes/common/extensions/iterable_extension.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; /// Lists the layouts of the notes list. enum Layout { @@ -12,8 +12,17 @@ enum Layout { /// Returns the value of the preference if set, or its default value otherwise. factory Layout.fromPreference() { - final preference = PreferencesUtils().get(PreferenceKey.layout); + final layout = Layout.values.byNameOrNull( + PreferenceKey.layout.getPreference(), + ); - return preference != null ? Layout.values.byName(preference) : PreferenceKey.layout.defaultValue as Layout; + // Reset the malformed preference to its default value + if (layout == null) { + PreferenceKey.layout.setToDefault(); + + return PreferenceKey.layout.defaultValue as Layout; + } + + return layout; } } diff --git a/lib/common/preferences/enums/sort_method.dart b/lib/common/preferences/enums/sort_method.dart index 649e3171..577a50e2 100644 --- a/lib/common/preferences/enums/sort_method.dart +++ b/lib/common/preferences/enums/sort_method.dart @@ -1,5 +1,5 @@ +import 'package:localmaterialnotes/common/extensions/iterable_extension.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; /// Lists the methods to sort the notes in the notes list. enum SortMethod { @@ -20,10 +20,17 @@ enum SortMethod { /// Returns the value of the preference if set, or its default value otherwise. factory SortMethod.fromPreference() { - final preference = PreferencesUtils().get(PreferenceKey.sortMethod); + final sortMethod = SortMethod.values.byNameOrNull( + PreferenceKey.sortMethod.getPreference(), + ); - return preference != null - ? SortMethod.values.byName(preference) - : PreferenceKey.sortMethod.defaultValue as SortMethod; + // Reset the malformed preference to its default value + if (sortMethod == null) { + PreferenceKey.sortMethod.setToDefault(); + + return PreferenceKey.sortMethod.defaultValue as SortMethod; + } + + return sortMethod; } } diff --git a/lib/common/preferences/enums/swipe_action.dart b/lib/common/preferences/enums/swipe_action.dart index 24e27ea8..3f2b2ac5 100644 --- a/lib/common/preferences/enums/swipe_action.dart +++ b/lib/common/preferences/enums/swipe_action.dart @@ -1,7 +1,7 @@ import 'package:flutter/material.dart'; import 'package:localmaterialnotes/common/constants/constants.dart'; +import 'package:localmaterialnotes/common/extensions/iterable_extension.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; /// Lists the actions to trigger when swiping on a note tile. enum SwipeAction { @@ -43,20 +43,34 @@ enum SwipeAction { /// Returns the value of the right swipe action preference if set, or its default value otherwise. factory SwipeAction.rightFromPreference() { - final preference = PreferencesUtils().get(PreferenceKey.swipeRightAction); + final swipeRightAction = SwipeAction.values.byNameOrNull( + PreferenceKey.swipeRightAction.getPreference(), + ); - return preference != null - ? SwipeAction.values.byName(preference) - : PreferenceKey.swipeRightAction.defaultValue as SwipeAction; + // Reset the malformed preference to its default value + if (swipeRightAction == null) { + PreferenceKey.swipeRightAction.setToDefault(); + + return PreferenceKey.swipeRightAction.defaultValue as SwipeAction; + } + + return swipeRightAction; } /// Returns the value of the left swipe action preference if set, or its default value otherwise. factory SwipeAction.leftFromPreference() { - final preference = PreferencesUtils().get(PreferenceKey.swipeLeftAction); + final swipeRightAction = SwipeAction.values.byNameOrNull( + PreferenceKey.swipeLeftAction.getPreference(), + ); + + // Reset the malformed preference to its default value + if (swipeRightAction == null) { + PreferenceKey.swipeLeftAction.setToDefault(); + + return PreferenceKey.swipeLeftAction.defaultValue as SwipeAction; + } - return preference != null - ? SwipeAction.values.byName(preference) - : PreferenceKey.swipeLeftAction.defaultValue as SwipeAction; + return swipeRightAction; } /// Returns whether the swipe action is enabled. diff --git a/lib/common/preferences/preference_key.dart b/lib/common/preferences/preference_key.dart index 3629e6df..009de304 100644 --- a/lib/common/preferences/preference_key.dart +++ b/lib/common/preferences/preference_key.dart @@ -1,4 +1,3 @@ -import 'package:localmaterialnotes/common/constants/constants.dart'; import 'package:localmaterialnotes/common/preferences/enums/confirmations.dart'; import 'package:localmaterialnotes/common/preferences/enums/layout.dart'; import 'package:localmaterialnotes/common/preferences/enums/sort_method.dart'; @@ -54,7 +53,7 @@ enum PreferenceKey { // Notes sortMethod(SortMethod.editedDate), - sortAscending(false), + sortAscending(bool), layout(Layout.list), ; @@ -71,29 +70,32 @@ enum PreferenceKey { /// if the preference should be securely stored, it can be marked as [secure]. const PreferenceKey(this.defaultValue, {this.secure = false}); - /// Returns the value of the preference if set, or its default value otherwise. - /// - /// The type [T] of the value should be a basic type: `bool`, `int`, `double`, `String` or `List`. - T getPreferenceOrDefault() { - if (T == dynamic) { - throw ArgumentError('The type T is required.'); - } + /// Sets the preference to the [value] with the type [T]. + Future set(T value) async { + await PreferencesUtils().set(this, value); + } - if (T != bool && T != int && T != double && T != String && T != List) { - throw ArgumentError('The type T should be a native type (bool, int, double, String or List), not $T.'); - } + /// Resets the preference to its [defaultValue]. + Future setToDefault() async { + await PreferencesUtils().set(this, defaultValue); + } - try { - return PreferencesUtils().get(this) ?? defaultValue as T; - } catch (exception, stackTrace) { - logger.e(exception.toString(), exception, stackTrace); + /// Returns the value of the preference if set, or its default value otherwise. + T? getPreference() { + return PreferencesUtils().get(this); + } - return defaultValue as T; - } + /// Returns the value of the preference if set, or its default value otherwise. + T getPreferenceOrDefault() { + return PreferencesUtils().get(this) ?? defaultValue as T; } /// Returns the value of the securely stored preference if set, or its default value otherwise. Future getPreferenceOrDefaultSecure() async { return await PreferencesUtils().getSecure(this) ?? defaultValue as String; } + + Future remove() async { + await PreferencesUtils().remove(this); + } } diff --git a/lib/common/preferences/preferences_utils.dart b/lib/common/preferences/preferences_utils.dart index 97ce97fe..1e3e28ec 100644 --- a/lib/common/preferences/preferences_utils.dart +++ b/lib/common/preferences/preferences_utils.dart @@ -58,14 +58,18 @@ class PreferencesUtils { /// /// The type [T] of the value should be a basic type: `bool`, `int`, `double`, `String` or `List`. T? get(PreferenceKey preferenceKey) { - if (preferenceKey.secure) { - throw ArgumentError('The preference is securely stored, use getSecure() instead'); - } - if (T == dynamic) { throw ArgumentError('The type T is required.'); } + if (T != bool && T != int && T != double && T != String && T != List) { + throw ArgumentError('The type T should be a native type (bool, int, double, String or List), not $T.'); + } + + if (preferenceKey.secure) { + throw ArgumentError('The preference is securely stored, use getSecure() instead'); + } + return _preferences.get(preferenceKey.name) as T?; } diff --git a/lib/pages/settings/pages/settings_accessibility_page.dart b/lib/pages/settings/pages/settings_accessibility_page.dart index 44bbf7b7..5a189975 100644 --- a/lib/pages/settings/pages/settings_accessibility_page.dart +++ b/lib/pages/settings/pages/settings_accessibility_page.dart @@ -5,7 +5,6 @@ import 'package:localmaterialnotes/common/constants/paddings.dart'; import 'package:localmaterialnotes/common/navigation/app_bars/basic_app_bar.dart'; import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/providers/notifiers.dart'; import 'package:localmaterialnotes/utils/keys.dart'; import 'package:localmaterialnotes/utils/locale_utils.dart'; @@ -29,7 +28,7 @@ class _SettingsAppearancePageState extends State { /// Sets the text scaling to the new [textScaling]. void _submittedTextScaling(double textScaling) { setState(() { - PreferencesUtils().set(PreferenceKey.textScaling, textScaling); + PreferenceKey.textScaling.set(textScaling); }); textScalingNotifier.value = textScaling; @@ -46,7 +45,7 @@ class _SettingsAppearancePageState extends State { /// Toggles whether to use white text in dark mode. void _toggleUseWhiteTextDarkMode(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.useWhiteTextDarkMode, toggled); + PreferenceKey.useWhiteTextDarkMode.set(toggled); }); useWhiteTextDarkModeNotifier.value = toggled; diff --git a/lib/pages/settings/pages/settings_appearance_page.dart b/lib/pages/settings/pages/settings_appearance_page.dart index 55f99540..ba88a623 100644 --- a/lib/pages/settings/pages/settings_appearance_page.dart +++ b/lib/pages/settings/pages/settings_appearance_page.dart @@ -8,7 +8,6 @@ import 'package:localmaterialnotes/common/enums/localization_completion.dart'; import 'package:localmaterialnotes/common/navigation/app_bars/basic_app_bar.dart'; import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/l10n/app_localizations/app_localizations.g.dart'; import 'package:localmaterialnotes/providers/notifiers.dart'; import 'package:localmaterialnotes/utils/keys.dart'; @@ -58,7 +57,7 @@ class _SettingsAppearancePageState extends State { /// Toggles the dynamic theming. void _toggleDynamicTheming(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.dynamicTheming, toggled); + PreferenceKey.dynamicTheming.set(toggled); }); dynamicThemingNotifier.value = toggled; @@ -67,7 +66,7 @@ class _SettingsAppearancePageState extends State { /// Toggles the black theming. void _toggleBlackTheming(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.blackTheming, toggled); + PreferenceKey.blackTheming.set(toggled); }); blackThemingNotifier.value = toggled; @@ -76,7 +75,7 @@ class _SettingsAppearancePageState extends State { /// Toggles the setting to show background of the notes tiles. void _toggleShowTitlesOnly(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showTitlesOnly, toggled); + PreferenceKey.showTitlesOnly.set(toggled); }); showTitlesOnlyNotifier.value = toggled; @@ -85,21 +84,21 @@ class _SettingsAppearancePageState extends State { /// Toggles the setting to show background of the notes tiles. void _toggleShowTitlesOnlyDisableInSearchView(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showTitlesOnlyDisableInSearchView, toggled); + PreferenceKey.showTitlesOnlyDisableInSearchView.set(toggled); }); } /// Toggles the setting to show background of the notes tiles. void _toggleDisableSubduedNoteContentPreview(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.disableSubduedNoteContentPreview, toggled); + PreferenceKey.disableSubduedNoteContentPreview.set(toggled); }); } /// Toggles the setting to show background of the notes tiles. void _toggleShowTilesBackground(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showTilesBackground, toggled); + PreferenceKey.showTilesBackground.set(toggled); }); showTilesBackgroundNotifier.value = toggled; @@ -108,7 +107,7 @@ class _SettingsAppearancePageState extends State { /// Toggles the setting to show the separators between the notes tiles. void _toggleShowSeparators(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showSeparators, toggled); + PreferenceKey.showSeparators.set(toggled); }); showSeparatorsNotifier.value = toggled; diff --git a/lib/pages/settings/pages/settings_backup_page.dart b/lib/pages/settings/pages/settings_backup_page.dart index 0c8762dd..3b775430 100644 --- a/lib/pages/settings/pages/settings_backup_page.dart +++ b/lib/pages/settings/pages/settings_backup_page.dart @@ -6,7 +6,6 @@ import 'package:localmaterialnotes/common/extensions/string_extension.dart'; import 'package:localmaterialnotes/common/navigation/app_bars/basic_app_bar.dart'; import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/pages/settings/dialogs/auto_export_frequency_dialog.dart'; import 'package:localmaterialnotes/pages/settings/dialogs/auto_export_password_dialog.dart'; import 'package:localmaterialnotes/pages/settings/dialogs/manual_export_dialog.dart'; @@ -97,14 +96,14 @@ class _SettingsBackupPageState extends ConsumerState { /// Toggles the setting to enable the automatic export. Future _toggleEnableAutoExport(bool toggled) async { - await PreferencesUtils().set(PreferenceKey.enableAutoExport, toggled); + await PreferenceKey.enableAutoExport.set(toggled); setState(() {}); if (!toggled) { - PreferencesUtils().remove(PreferenceKey.lastAutoExportDate); - PreferencesUtils().set(PreferenceKey.autoExportEncryption, false); - PreferencesUtils().remove(PreferenceKey.autoExportPassword); + PreferenceKey.lastAutoExportDate.remove(); + PreferenceKey.autoExportEncryption.set(false); + PreferenceKey.autoExportPassword.remove(); return; } @@ -118,10 +117,10 @@ class _SettingsBackupPageState extends ConsumerState { /// If enabled, asks the user for the password used for the encryption. Future _toggleAutoExportEncryption(bool toggled) async { if (!toggled) { - PreferencesUtils().remove(PreferenceKey.autoExportPassword); + PreferenceKey.autoExportPassword.remove(); setState(() { - PreferencesUtils().set(PreferenceKey.autoExportEncryption, false); + PreferenceKey.autoExportEncryption.set(false); }); return; @@ -140,10 +139,10 @@ class _SettingsBackupPageState extends ConsumerState { return; } - PreferencesUtils().set(PreferenceKey.autoExportPassword, autoExportPassword); + PreferenceKey.autoExportPassword.set(autoExportPassword); setState(() { - PreferencesUtils().set(PreferenceKey.autoExportEncryption, true); + PreferenceKey.autoExportEncryption.set(true); }); }); } @@ -160,7 +159,7 @@ class _SettingsBackupPageState extends ConsumerState { } setState(() { - PreferencesUtils().set(PreferenceKey.autoExportFrequency, autoExportFrequency); + PreferenceKey.autoExportFrequency.set(autoExportFrequency); }); }); } @@ -173,7 +172,8 @@ class _SettingsBackupPageState extends ConsumerState { return; } - PreferencesUtils().set(PreferenceKey.autoExportDirectory, autoExportDirectory); + PreferenceKey.autoExportDirectory.set(autoExportDirectory); + await AutoExportUtils().setAutoExportDirectory(); setState(() {}); @@ -181,7 +181,7 @@ class _SettingsBackupPageState extends ConsumerState { /// Resets the directory of the automatic export to its default value. Future _resetAutoExportDirectory() async { - await PreferencesUtils().remove(PreferenceKey.autoExportDirectory); + await PreferenceKey.autoExportDirectory.remove(); await AutoExportUtils().setAutoExportDirectory(); diff --git a/lib/pages/settings/pages/settings_behavior_page.dart b/lib/pages/settings/pages/settings_behavior_page.dart index 9eaa9955..daba586e 100644 --- a/lib/pages/settings/pages/settings_behavior_page.dart +++ b/lib/pages/settings/pages/settings_behavior_page.dart @@ -7,7 +7,6 @@ import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/enums/confirmations.dart'; import 'package:localmaterialnotes/common/preferences/enums/swipe_action.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/providers/notifiers.dart'; import 'package:localmaterialnotes/utils/keys.dart'; import 'package:settings_tiles/settings_tiles.dart'; @@ -25,14 +24,14 @@ class _SettingsBehaviorPageState extends State { /// Asks the user to choose which confirmations should be shown. void _submittedConfirmations(Confirmations confirmations) { setState(() { - PreferencesUtils().set(PreferenceKey.confirmations, confirmations.name); + PreferenceKey.confirmations.set(confirmations.name); }); } /// Sets the new right [swipeAction]. void _submittedSwipeRightAction(SwipeAction swipeAction) { setState(() { - PreferencesUtils().set(PreferenceKey.swipeRightAction, swipeAction.name); + PreferenceKey.swipeRightAction.set(swipeAction.name); swipeActionsNotifier.value = (right: swipeAction, left: swipeActionsNotifier.value.left); }); } @@ -40,7 +39,7 @@ class _SettingsBehaviorPageState extends State { /// Sets the new left [swipeAction]. void _submittedSwipeLeftAction(SwipeAction swipeAction) { setState(() { - PreferencesUtils().set(PreferenceKey.swipeLeftAction, swipeAction.name); + PreferenceKey.swipeLeftAction.set(swipeAction.name); swipeActionsNotifier.value = (right: swipeActionsNotifier.value.right, left: swipeAction); }); } @@ -48,7 +47,7 @@ class _SettingsBehaviorPageState extends State { /// Toggles Android's `FLAG_SECURE` to hide the app from the recent apps and prevent screenshots. Future _setFlagSecure(bool toggled) async { setState(() { - PreferencesUtils().set(PreferenceKey.flagSecure, toggled); + PreferenceKey.flagSecure.set(toggled); }); toggled ? await FlagSecure.set() : await FlagSecure.unset(); diff --git a/lib/pages/settings/pages/settings_editor_page.dart b/lib/pages/settings/pages/settings_editor_page.dart index e14c7328..0ce7793d 100644 --- a/lib/pages/settings/pages/settings_editor_page.dart +++ b/lib/pages/settings/pages/settings_editor_page.dart @@ -4,7 +4,6 @@ import 'package:localmaterialnotes/common/constants/paddings.dart'; import 'package:localmaterialnotes/common/navigation/app_bars/basic_app_bar.dart'; import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/utils/keys.dart'; import 'package:settings_tiles/settings_tiles.dart'; @@ -21,7 +20,7 @@ class _SettingsEditorPageState extends State { /// Toggles the setting to show the undo/redo buttons in the editor's app bar. void _toggleShowUndoRedoButtons(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showUndoRedoButtons, toggled); + PreferenceKey.showUndoRedoButtons.set(toggled); }); } @@ -31,42 +30,42 @@ class _SettingsEditorPageState extends State { /// Otherwise, it's shown in the editor's app bar. void _toggleShowChecklistButton(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showChecklistButton, toggled); + PreferenceKey.showChecklistButton.set(toggled); }); } /// Toggles the setting to show the editor's toolbar. void _toggleShowToolbar(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.showToolbar, toggled); + PreferenceKey.showToolbar.set(toggled); }); } /// Toggles the setting to use the editor mode button. void _toggleShowEditorModeButton(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.editorModeButton, toggled); + PreferenceKey.editorModeButton.set(toggled); }); } /// Toggles the setting to open the editor in reading mode by default. void _toggleOpenEditorInReadMode(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.openEditorReadingMode, toggled); + PreferenceKey.openEditorReadingMode.set(toggled); }); } /// Toggles the setting to use spacing between the paragraphs. void _toggleFocusTitleOnNewNote(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.focusTitleOnNewNote, toggled); + PreferenceKey.focusTitleOnNewNote.set(toggled); }); } /// Toggles the setting to use spacing between the paragraphs. void _toggleUseParagraphSpacing(bool toggled) { setState(() { - PreferencesUtils().set(PreferenceKey.useParagraphsSpacing, toggled); + PreferenceKey.useParagraphsSpacing.set(toggled); }); } diff --git a/lib/pages/settings/pages/settings_labels_page.dart b/lib/pages/settings/pages/settings_labels_page.dart index f44b943a..233bdcfe 100644 --- a/lib/pages/settings/pages/settings_labels_page.dart +++ b/lib/pages/settings/pages/settings_labels_page.dart @@ -5,7 +5,6 @@ import 'package:localmaterialnotes/common/constants/paddings.dart'; import 'package:localmaterialnotes/common/navigation/app_bars/basic_app_bar.dart'; import 'package:localmaterialnotes/common/navigation/top_navigation.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/utils/keys.dart'; import 'package:material_symbols_icons/material_symbols_icons.dart'; import 'package:restart_app/restart_app.dart'; @@ -24,7 +23,7 @@ class _SettingsLabelsPageState extends State { /// Toggles whether to enable the labels. Future _toggleEnableLabels(bool toggled) async { setState(() { - PreferencesUtils().set(PreferenceKey.enableLabels, toggled); + PreferenceKey.enableLabels.set(toggled); }); // The Restart package crashes the app if used in debug mode @@ -36,14 +35,14 @@ class _SettingsLabelsPageState extends State { /// Toggles whether to show the labels list in the editor. Future _toggleShowLabelsListOnNoteTile(bool toggled) async { setState(() { - PreferencesUtils().set(PreferenceKey.showLabelsListOnNoteTile, toggled); + PreferenceKey.showLabelsListOnNoteTile.set(toggled); }); } /// Toggles whether to show the labels list in the editor. Future _toggleShowLabelsListInEditor(bool toggled) async { setState(() { - PreferencesUtils().set(PreferenceKey.showLabelsListInEditorPage, toggled); + PreferenceKey.showLabelsListInEditorPage.set(toggled); }); } diff --git a/lib/utils/auto_export_utils.dart b/lib/utils/auto_export_utils.dart index 7da8b534..f1e5aaf4 100644 --- a/lib/utils/auto_export_utils.dart +++ b/lib/utils/auto_export_utils.dart @@ -2,7 +2,6 @@ import 'dart:developer'; import 'package:localmaterialnotes/common/constants/constants.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/utils/database_utils.dart'; import 'package:localmaterialnotes/utils/files_utils.dart'; import 'package:path/path.dart'; @@ -55,7 +54,7 @@ class AutoExportUtils { // URIs for SAF used before v1.7.1 are not compatible and need to be discarded log("[Auto export] Discarding an URI in the old format for the SAF auto export directory."); - await PreferencesUtils().remove(PreferenceKey.autoExportDirectory); + await PreferenceKey.autoExportDirectory.remove(); return setAutoExportDirectoryToDefault(); } @@ -120,9 +119,6 @@ class AutoExportUtils { DatabaseUtils().autoExportAsJson(encrypt, password); - PreferencesUtils().set( - PreferenceKey.lastAutoExportDate, - DateTime.now().toIso8601String(), - ); + PreferenceKey.lastAutoExportDate.set(DateTime.now().toIso8601String()); } } diff --git a/lib/utils/locale_utils.dart b/lib/utils/locale_utils.dart index 59c35cb6..8d1859fc 100644 --- a/lib/utils/locale_utils.dart +++ b/lib/utils/locale_utils.dart @@ -2,7 +2,6 @@ import 'dart:io'; import 'package:flutter/material.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/utils/localizations_utils.dart'; /// Utilities for the application's locale. @@ -26,7 +25,7 @@ class LocaleUtils { /// Sets the application's locale to [locale]. Future setLocale(Locale locale) async { - await PreferencesUtils().set(PreferenceKey.locale, locale.languageCode); + await PreferenceKey.locale.set(locale.languageCode); // Reset the hardcoded localizations. await LocalizationsUtils().ensureInitialized(); diff --git a/lib/utils/theme_utils.dart b/lib/utils/theme_utils.dart index 5c0b4d5d..e6223986 100644 --- a/lib/utils/theme_utils.dart +++ b/lib/utils/theme_utils.dart @@ -2,7 +2,6 @@ import 'package:dynamic_color/dynamic_color.dart'; import 'package:flutter/material.dart'; import 'package:localmaterialnotes/common/constants/constants.dart'; import 'package:localmaterialnotes/common/preferences/preference_key.dart'; -import 'package:localmaterialnotes/common/preferences/preferences_utils.dart'; import 'package:localmaterialnotes/providers/notifiers.dart'; /// Utilities for the application's theme. @@ -179,7 +178,7 @@ class ThemeUtils { value = 2; } - PreferencesUtils().set(PreferenceKey.theme, value); + PreferenceKey.theme.set(value); themeModeNotifier.value = themeMode; } diff --git a/pubspec.yaml b/pubspec.yaml index 9e682526..f0cef2aa 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -2,7 +2,7 @@ name: localmaterialnotes description: Simple, local, material design notes repository: https://github.com/maelchiotti/LocalMaterialNotes -version: 1.8.0+17 +version: 1.8.1+18 publish_to: none environment: