Skip to content

Commit

Permalink
[344] feat: move tiles settings to new page
Browse files Browse the repository at this point in the history
  • Loading branch information
maelchiotti committed Jan 10, 2025
1 parent 081b7bd commit 333cb7a
Show file tree
Hide file tree
Showing 4 changed files with 192 additions and 110 deletions.
58 changes: 41 additions & 17 deletions lib/l10n/translations/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down Expand Up @@ -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."
},
Expand Down Expand Up @@ -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": {
Expand All @@ -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."
Expand Down
93 changes: 0 additions & 93 deletions lib/pages/settings/pages/settings_appearance_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -88,43 +87,6 @@ class _SettingsAppearancePageState extends ConsumerState<SettingsAppearancePage>
});
}

/// 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;
Expand All @@ -136,13 +98,6 @@ class _SettingsAppearancePageState extends ConsumerState<SettingsAppearancePage>
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(
Expand Down Expand Up @@ -256,54 +211,6 @@ class _SettingsAppearancePageState extends ConsumerState<SettingsAppearancePage>
),
],
),
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,
),
],
),
],
),
),
Expand Down
144 changes: 144 additions & 0 deletions lib/pages/settings/pages/settings_notes_tiles_page.dart
Original file line number Diff line number Diff line change
@@ -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<SettingsNotesTilesPage> createState() => _SettingsNotesTilesPageState();
}

class _SettingsNotesTilesPageState extends ConsumerState<SettingsNotesTilesPage> {
/// 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,
),
],
),
],
),
),
),
);
}
}
7 changes: 7 additions & 0 deletions lib/pages/settings/settings_main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 333cb7a

Please sign in to comment.