From 333cb7a49bde2aafe9c23645ee2245d5cdb42dec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Chiotti?= <44336112+maelchiotti@users.noreply.github.com> Date: Fri, 10 Jan 2025 12:22:15 +0100 Subject: [PATCH] [344] feat: move tiles settings to new page --- lib/l10n/translations/app_en.arb | 58 ++++--- .../pages/settings_appearance_page.dart | 93 ----------- .../pages/settings_notes_tiles_page.dart | 144 ++++++++++++++++++ lib/pages/settings/settings_main_page.dart | 7 + 4 files changed, 192 insertions(+), 110 deletions(-) create mode 100644 lib/pages/settings/pages/settings_notes_tiles_page.dart diff --git a/lib/l10n/translations/app_en.arb b/lib/l10n/translations/app_en.arb index 59e4c69a..323e6ff6 100644 --- a/lib/l10n/translations/app_en.arb +++ b/lib/l10n/translations/app_en.arb @@ -77,6 +77,10 @@ "@navigation_settings_appearance": { "description": "Title of the settings page regarding the application's appearance." }, + "navigation_settings_notes_tiles": "Notes tiles", + "@navigation_settings_notes_tiles": { + "description": "Title of the settings page regarding the notes tiles appearance." + }, "navigation_settings_behavior": "Behavior", "@navigation_settings_behavior": { "description": "Title of the settings page regarding the application's behavior." @@ -113,7 +117,7 @@ "@settings_page_appearance": { "description": "Title of the settings page regarding the application's appearance." }, - "settings_page_appearance_description": "Language, theming, fonts, notes tiles", + "settings_page_appearance_description": "Language, theming, fonts", "@settings_page_appearance_description": { "description": "Description of the appearance settings page." }, @@ -181,25 +185,21 @@ "@settings_editor_font_description": { "description": "Description of the setting tile to choose the font of the app." }, - "settings_appearance_section_notes_tiles": "Notes tiles", - "@settings_appearance_section_notes_tiles": { - "description": "Title of the section regarding the notes tiles under the appearance settings." - }, - "settings_show_titles_only": "Titles only", - "@settings_show_titles_only": { - "description": "Title of the setting tile to only show the titles of the notes in the notes tiles." + "settings_page_notes_tiles": "Notes tiles", + "@settings_page_notes_tiles": { + "description": "Title of the settings page regarding the notes tiles." }, - "settings_show_titles_only_description": "Only show the titles of the notes", - "@settings_show_titles_only_description": { - "description": "Description of the setting tile to only show the titles of the notes in the notes tiles." + "settings_page_notes_tiles_description": "Appearance, content", + "@settings_page_notes_tiles_description": { + "description": "Description of the notes tiles settings page." }, - "settings_show_titles_only_disable_in_search_view": "Disable titles only in search view", - "@settings_show_titles_only_disable_in_search_view": { - "description": "Title of the setting tile to disable only showing the titles of the notes in the search view." + "settings_page_notes_tiles_appearance_section": "Appearance", + "@settings_page_notes_tiles_appearance_section": { + "description": "Title of the section regarding the appearance under the notes tiles settings." }, - "settings_show_titles_only_disable_in_search_view_description": "Disable the option to only show the titles when in the search view", - "@settings_show_titles_only_disable_in_search_view_description": { - "description": "Description of the setting tile to disable only showing the titles of the notes in the search view." + "settings_page_notes_tiles_content_section": "Content", + "@settings_page_notes_tiles_content_section": { + "description": "Title of the section regarding the content under the notes tiles settings." }, "settings_show_tiles_background": "Background", "@settings_show_tiles_background": { @@ -217,6 +217,30 @@ "@settings_show_separators_description": { "description": "Description of the setting tile to show the separators between the notes tiles." }, + "settings_show_titles_only": "Titles only", + "@settings_show_titles_only": { + "description": "Title of the setting tile to only show the titles of the notes in the notes tiles." + }, + "settings_show_titles_only_description": "Only show the titles of the notes", + "@settings_show_titles_only_description": { + "description": "Description of the setting tile to only show the titles of the notes in the notes tiles." + }, + "settings_show_titles_only_disable_in_search_view": "Disable titles only in search view", + "@settings_show_titles_only_disable_in_search_view": { + "description": "Title of the setting tile to disable only showing the titles of the notes in the search view." + }, + "settings_show_titles_only_disable_in_search_view_description": "Disable the option to only show the titles when in the search view", + "@settings_show_titles_only_disable_in_search_view_description": { + "description": "Description of the setting tile to disable only showing the titles of the notes in the search view." + }, + "settings_content_preview_max_lines": "Maximum preview lines", + "@settings_content_preview_max_lines": { + "description": "Title of the setting tile to choose the maximum number of content preview lines to show." + }, + "settings_content_preview_max_lines_description": "Maximum number of lines of the content preview to show", + "@settings_content_preview_max_lines_description": { + "description": "Description of the setting tile to choose the maximum number of content preview lines to show." + }, "settings_behavior": "Behavior", "@settings_behavior": { "description": "Title of the settings page regarding the application's behavior." diff --git a/lib/pages/settings/pages/settings_appearance_page.dart b/lib/pages/settings/pages/settings_appearance_page.dart index 08a4556f..5377b969 100644 --- a/lib/pages/settings/pages/settings_appearance_page.dart +++ b/lib/pages/settings/pages/settings_appearance_page.dart @@ -3,7 +3,6 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:locale_names/locale_names.dart'; -import 'package:material_symbols_icons/material_symbols_icons.dart'; import 'package:restart_app/restart_app.dart'; import 'package:settings_tiles/settings_tiles.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -88,43 +87,6 @@ class _SettingsAppearancePageState extends ConsumerState }); } - /// Toggles the setting to show background of the notes tiles. - void _toggleShowTilesBackground(bool toggled) { - PreferenceKey.showTilesBackground.set(toggled); - - ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTilesBackground: toggled)); - } - - /// Toggles the setting to show the separators between the notes tiles. - void _toggleShowSeparators(bool toggled) { - PreferenceKey.showSeparators.set(toggled); - - ref.read(preferencesProvider.notifier).update(WatchedPreferences(showSeparators: toggled)); - } - - /// Toggles the setting to show background of the notes tiles. - void _toggleShowTitlesOnly(bool toggled) { - PreferenceKey.showTitlesOnly.set(toggled); - - ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTitlesOnly: toggled)); - } - - /// Toggles the setting to show background of the notes tiles. - void _toggleShowTitlesOnlyDisableInSearchView(bool toggled) { - setState(() { - PreferenceKey.showTitlesOnlyDisableInSearchView.set(toggled); - }); - } - - /// Sets the note content preview maximum lines count to the new [noteContentPreviewMaxLines]. - void _submittedNoteContentPreviewMaxLines(double noteContentPreviewMaxLines) { - PreferenceKey.noteContentPreviewMaxLines.set(noteContentPreviewMaxLines.toInt()); - - ref.read(preferencesProvider.notifier).update( - WatchedPreferences(noteContentPreviewMaxLines: noteContentPreviewMaxLines.toInt()), - ); - } - @override Widget build(BuildContext context) { final locale = LocaleUtils().appLocale; @@ -136,13 +98,6 @@ class _SettingsAppearancePageState extends ConsumerState final appFont = ref.watch(preferencesProvider.select((preferences) => preferences.appFont)); final editorFont = Font.editorFromPreference(); - final showTilesBackground = ref.watch(preferencesProvider.select((preferences) => preferences.showTilesBackground)); - final showSeparators = ref.watch(preferencesProvider.select((preferences) => preferences.showSeparators)); - final showTitlesOnly = ref.watch(preferencesProvider.select((preferences) => preferences.showTitlesOnly)); - final showTitlesOnlyDisableInSearchView = PreferenceKey.showTitlesOnlyDisableInSearchView.getPreferenceOrDefault(); - final noteContentPreviewMaxLines = - ref.watch(preferencesProvider.select((preferences) => preferences.noteContentPreviewMaxLines)); - final isDarkMode = Theme.of(context).brightness == Brightness.dark; return Scaffold( @@ -256,54 +211,6 @@ class _SettingsAppearancePageState extends ConsumerState ), ], ), - SettingSection( - divider: null, - title: l.settings_appearance_section_notes_tiles, - tiles: [ - SettingSwitchTile( - icon: Icons.gradient, - title: l.settings_show_tiles_background, - description: l.settings_show_tiles_background_description, - toggled: showTilesBackground, - onChanged: _toggleShowTilesBackground, - ), - SettingSwitchTile( - icon: Icons.safety_divider, - title: l.settings_show_separators, - description: l.settings_show_separators_description, - toggled: showSeparators, - onChanged: _toggleShowSeparators, - ), - SettingSwitchTile( - icon: Icons.title, - title: l.settings_show_titles_only, - description: l.settings_show_titles_only_description, - toggled: showTitlesOnly, - onChanged: _toggleShowTitlesOnly, - ), - SettingSwitchTile( - enabled: showTitlesOnly, - icon: Symbols.feature_search, - title: l.settings_show_titles_only_disable_in_search_view, - description: l.settings_show_titles_only_disable_in_search_view_description, - toggled: showTitlesOnlyDisableInSearchView, - onChanged: _toggleShowTitlesOnlyDisableInSearchView, - ), - SettingSliderTile( - icon: Icons.format_size, - title: 'Preview max lines', - description: 'Maximum number of lines shown for the preview of the content', - value: '$noteContentPreviewMaxLines', - dialogTitle: 'Preview max lines', - label: (noteContentPreviewMaxLines) => '${noteContentPreviewMaxLines.toInt()}', - min: 1.0, - max: 10.0, - divisions: 9, - initialValue: noteContentPreviewMaxLines.toDouble(), - onSubmitted: _submittedNoteContentPreviewMaxLines, - ), - ], - ), ], ), ), diff --git a/lib/pages/settings/pages/settings_notes_tiles_page.dart b/lib/pages/settings/pages/settings_notes_tiles_page.dart new file mode 100644 index 00000000..2081f9f4 --- /dev/null +++ b/lib/pages/settings/pages/settings_notes_tiles_page.dart @@ -0,0 +1,144 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:material_symbols_icons/material_symbols_icons.dart'; +import 'package:settings_tiles/settings_tiles.dart'; + +import '../../../common/constants/constants.dart'; +import '../../../common/constants/paddings.dart'; +import '../../../common/navigation/app_bars/basic_app_bar.dart'; +import '../../../common/navigation/top_navigation.dart'; +import '../../../common/preferences/preference_key.dart'; +import '../../../common/preferences/watched_preferences.dart'; +import '../../../providers/preferences/preferences_provider.dart'; +import '../../../utils/keys.dart'; + +/// Settings related to the appearance of the application. +class SettingsNotesTilesPage extends ConsumerStatefulWidget { + /// Default constructor. + const SettingsNotesTilesPage({super.key}); + + @override + ConsumerState createState() => _SettingsNotesTilesPageState(); +} + +class _SettingsNotesTilesPageState extends ConsumerState { + /// Toggles the setting to show background of the notes tiles. + void _toggleShowTilesBackground(bool toggled) { + PreferenceKey.showTilesBackground.set(toggled); + + ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTilesBackground: toggled)); + } + + /// Toggles the setting to show the separators between the notes tiles. + void _toggleShowSeparators(bool toggled) { + PreferenceKey.showSeparators.set(toggled); + + ref.read(preferencesProvider.notifier).update(WatchedPreferences(showSeparators: toggled)); + } + + /// Toggles the setting to show background of the notes tiles. + void _toggleShowTitlesOnly(bool toggled) { + PreferenceKey.showTitlesOnly.set(toggled); + + ref.read(preferencesProvider.notifier).update(WatchedPreferences(showTitlesOnly: toggled)); + } + + /// Toggles the setting to show background of the notes tiles. + void _toggleShowTitlesOnlyDisableInSearchView(bool toggled) { + setState(() { + PreferenceKey.showTitlesOnlyDisableInSearchView.set(toggled); + }); + } + + /// Sets the note content preview maximum lines count to the new [noteContentPreviewMaxLines]. + void _submittedNoteContentPreviewMaxLines(double noteContentPreviewMaxLines) { + PreferenceKey.noteContentPreviewMaxLines.set(noteContentPreviewMaxLines.toInt()); + + ref.read(preferencesProvider.notifier).update( + WatchedPreferences(noteContentPreviewMaxLines: noteContentPreviewMaxLines.toInt()), + ); + } + + @override + Widget build(BuildContext context) { + final showTilesBackground = ref.watch(preferencesProvider.select((preferences) => preferences.showTilesBackground)); + final showSeparators = ref.watch(preferencesProvider.select((preferences) => preferences.showSeparators)); + final showTitlesOnly = ref.watch(preferencesProvider.select((preferences) => preferences.showTitlesOnly)); + final showTitlesOnlyDisableInSearchView = PreferenceKey.showTitlesOnlyDisableInSearchView.getPreferenceOrDefault(); + final noteContentPreviewMaxLines = + ref.watch(preferencesProvider.select((preferences) => preferences.noteContentPreviewMaxLines)); + + return Scaffold( + appBar: TopNavigation( + key: Keys.appBarSettingsMainSubpage, + appbar: BasicAppBar( + title: l.navigation_settings_notes_tiles, + //back: true, + ), + ), + body: SingleChildScrollView( + child: Padding( + padding: Paddings.bottomSystemUi, + child: Column( + children: [ + SettingSection( + divider: null, + title: l.settings_page_notes_tiles_appearance_section, + tiles: [ + SettingSwitchTile( + icon: Icons.gradient, + title: l.settings_show_tiles_background, + description: l.settings_show_tiles_background_description, + toggled: showTilesBackground, + onChanged: _toggleShowTilesBackground, + ), + SettingSwitchTile( + icon: Icons.safety_divider, + title: l.settings_show_separators, + description: l.settings_show_separators_description, + toggled: showSeparators, + onChanged: _toggleShowSeparators, + ), + ], + ), + SettingSection( + divider: null, + title: l.settings_page_notes_tiles_content_section, + tiles: [ + SettingSwitchTile( + icon: Icons.title, + title: l.settings_show_titles_only, + description: l.settings_show_titles_only_description, + toggled: showTitlesOnly, + onChanged: _toggleShowTitlesOnly, + ), + SettingSwitchTile( + enabled: showTitlesOnly, + icon: Symbols.feature_search, + title: l.settings_show_titles_only_disable_in_search_view, + description: l.settings_show_titles_only_disable_in_search_view_description, + toggled: showTitlesOnlyDisableInSearchView, + onChanged: _toggleShowTitlesOnlyDisableInSearchView, + ), + SettingSliderTile( + icon: Icons.short_text, + title: l.settings_content_preview_max_lines, + description: l.settings_content_preview_max_lines_description, + value: '$noteContentPreviewMaxLines', + dialogTitle: l.settings_content_preview_max_lines, + label: (noteContentPreviewMaxLines) => '${noteContentPreviewMaxLines.toInt()}', + min: 1.0, + max: 10.0, + divisions: 9, + initialValue: noteContentPreviewMaxLines.toDouble(), + onSubmitted: _submittedNoteContentPreviewMaxLines, + ), + ], + ), + ], + ), + ), + ), + ); + } +} diff --git a/lib/pages/settings/settings_main_page.dart b/lib/pages/settings/settings_main_page.dart index f83be159..ddf9dbc9 100644 --- a/lib/pages/settings/settings_main_page.dart +++ b/lib/pages/settings/settings_main_page.dart @@ -14,6 +14,7 @@ import 'pages/settings_backup_page.dart'; import 'pages/settings_behavior_page.dart'; import 'pages/settings_editor_page.dart'; import 'pages/settings_labels_page.dart'; +import 'pages/settings_notes_tiles_page.dart'; /// Page for the settings of the application. class SettingsMainPage extends StatelessWidget { @@ -43,6 +44,12 @@ class SettingsMainPage extends StatelessWidget { description: l.settings_page_appearance_description, onTap: () => NavigationRoute.settingsAppearance.push(context, SettingsAppearancePage()), ), + SettingActionTile( + icon: Icons.dashboard, + title: l.settings_page_notes_tiles, + description: l.settings_page_notes_tiles_description, + onTap: () => NavigationRoute.settingsAppearance.push(context, SettingsNotesTilesPage()), + ), SettingActionTile( icon: Icons.swipe, title: l.settings_behavior,