Skip to content

Commit

Permalink
[303] New notes types (#393)
Browse files Browse the repository at this point in the history
* [303] fix: snack bar with expandable fab

* [303] feat: add back hint in the editors

* [303] feat: add an item by default in a new checklist note and focus it

* [303] style: note type icon

* [303] feat: move per note type settings into the notes types settings page
  • Loading branch information
maelchiotti authored Feb 12, 2025
1 parent 3fd7ee8 commit 5b4ef9a
Show file tree
Hide file tree
Showing 18 changed files with 60 additions and 119 deletions.
2 changes: 1 addition & 1 deletion lib/common/preferences/preference_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ enum PreferenceKey<T extends Object> {
// Notes tiles
showTilesBackground<bool>(false),
showSeparators<bool>(false),
showNoteTypeIcon<bool>(true),
showTitlesOnly<bool>(false),
showTitlesOnlyDisableInSearchView<bool>(true),
maximumContentPreviewLines<int>(3),
showNoteTypeIcon<bool>(true),

// Behavior
flagSecure<bool>(false),
Expand Down
6 changes: 3 additions & 3 deletions lib/common/preferences/watched_preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ class WatchedPreferences {
// Notes tiles
late bool showTilesBackground;
late bool showSeparators;
late bool showNoteTypeIcon;
late bool showTitlesOnly;
late int maximumContentPreviewLines;
late bool showNoteTypeIcon;

// Behavior
late ({SwipeAction right, SwipeAction left}) swipeActions;
Expand All @@ -51,9 +51,9 @@ class WatchedPreferences {
List<NoteType>? availableNotesTypes,
bool? showTitlesOnly,
bool? showTilesBackground,
bool? showNoteTypeIcon,
bool? showSeparators,
int? maximumContentPreviewLines,
bool? showNoteTypeIcon,
SwipeAction? rightSwipeAction,
SwipeAction? leftSwipeAction,
BinSwipeAction? binRightSwipeAction,
Expand All @@ -73,10 +73,10 @@ class WatchedPreferences {

this.showTitlesOnly = showTitlesOnly ?? PreferenceKey.showTitlesOnly.getPreferenceOrDefault();
this.showTilesBackground = showTilesBackground ?? PreferenceKey.showTilesBackground.getPreferenceOrDefault();
this.showNoteTypeIcon = showNoteTypeIcon ?? PreferenceKey.showNoteTypeIcon.getPreferenceOrDefault();
this.showSeparators = showSeparators ?? PreferenceKey.showSeparators.getPreferenceOrDefault();
this.maximumContentPreviewLines =
maximumContentPreviewLines ?? PreferenceKey.maximumContentPreviewLines.getPreferenceOrDefault();
this.showNoteTypeIcon = showNoteTypeIcon ?? PreferenceKey.showNoteTypeIcon.getPreferenceOrDefault();

swipeActions = (
right: rightSwipeAction ?? SwipeAction.rightFromPreference(),
Expand Down
1 change: 0 additions & 1 deletion lib/common/ui/snack_bar_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class SnackBarUtils {
void show({BuildContext? context}) {
ScaffoldMessenger.of(context ?? rootNavigatorKey.currentContext!).showSnackBar(
SnackBar(
behavior: SnackBarBehavior.floating,
duration: duration,
content: Text(text),
),
Expand Down
18 changes: 5 additions & 13 deletions lib/l10n/translations/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -329,18 +329,14 @@
"@settings_page_notes_types": {
"description": "Title of the settings page regarding the notes types."
},
"settings_page_notes_types_description": "Types to use, per-type settings",
"settings_page_notes_types_description": "Types to use, rich text",
"@settings_page_notes_types_description": {
"description": "Description of the settings page regarding the notes types."
},
"settings_section_types_to_use": "Types to use",
"@settings_section_types_to_use": {
"description": "Title of the settings section regarding the notes types to use."
},
"settings_section_per_type_settings": "Per-type settings",
"@settings_section_per_type_settings": {
"description": "Title of the settings section regarding the per-type settings."
},
"settings_available_notes_types": "Available notes types",
"@settings_available_notes_types": {
"description": "Title of the setting tile to choose the available notes types."
Expand All @@ -357,14 +353,6 @@
"@settings_available_default_shortcut_type_description": {
"description": "Description of the setting tile to choose the default note type to use when creating a note from a shortcut."
},
"settings_page_rich_text_notes_description": "Appearance",
"@settings_page_rich_text_notes_description": {
"description": "Description of the settings page regarding the rich text notes."
},
"settings_section_rich_text_notes_appearance": "Appearance",
"@settings_section_rich_text_notes_appearance": {
"description": "Description of the settings page regarding the rich text notes."
},
"settings_editor": "Editor",
"@settings_editor": {
"description": "Title of the settings page regarding the notes content editor."
Expand Down Expand Up @@ -683,6 +671,10 @@
"@hint_title": {
"description": "Hint for the text field of the title of the notes."
},
"hint_content": "Note",
"@hint_content": {
"description": "Hint for the text field of the content of the notes."
},
"hint_link": "Link",
"@hint_link": {
"description": "Hint for the link text field in the dialog to add a link in the editor."
Expand Down
6 changes: 3 additions & 3 deletions lib/models/note/types/checklist_note.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class ChecklistNote extends Note {
'The lists of checkboxes and texts of a checklist note are different: ${checkboxes.length} and ${texts.length}',
);

/// Checklist note with empty title and content.
/// Checklist note with empty title and 1 empty checklist item.
factory ChecklistNote.empty() => ChecklistNote(
deleted: false,
pinned: false,
createdTime: DateTime.now(),
editedTime: DateTime.now(),
title: '',
checkboxes: [],
texts: [],
checkboxes: [false],
texts: [''],
);

/// Checklist note with the provided [content].
Expand Down
1 change: 0 additions & 1 deletion lib/navigation/navigation_routes.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ enum NavigationRoute {
settingsNotesTiles,
settingsBehavior,
settingsNotesTypes,
settingsNotesTypesRichText,
settingsEditor,
settingsLabels,
settingsBackup,
Expand Down
1 change: 1 addition & 0 deletions lib/pages/editor/editor_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ class _EditorState extends ConsumerState<NotesEditorPage> {
case ChecklistNote note:
contentEditor = ChecklistEditor(
note: note,
isNewNote: widget.isNewNote,
readOnly: readOnly,
);
}
Expand Down
5 changes: 5 additions & 0 deletions lib/pages/editor/widgets/checklist/checklist_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,16 @@ class ChecklistEditor extends ConsumerWidget {
const ChecklistEditor({
super.key,
required this.note,
required this.isNewNote,
required this.readOnly,
});

/// The note to display.
final ChecklistNote note;

/// Whether the note was just created.
final bool isNewNote;

/// Whether the text fields are read only.
final bool readOnly;

Expand All @@ -38,6 +42,7 @@ class ChecklistEditor extends ConsumerWidget {
child: Checklist(
lines: note.checklistLines,
enabled: !readOnly,
autofocusFirstLine: isNewNote,
onChanged: (checklistLines) => onChecklistChanged(ref, checklistLines),
),
),
Expand Down
6 changes: 3 additions & 3 deletions lib/pages/editor/widgets/markdown/markdown_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {

return Padding(
padding: Paddings.pageHorizontal,
child: widget.readOnly
child: widget.readOnly && !widget.note.isContentEmpty
? Markdown(
data: widget.note.content,
padding: EdgeInsets.zero,
Expand All @@ -85,11 +85,11 @@ class _MarkdownEditorState extends ConsumerState<MarkdownEditor> {
child: TextField(
controller: contentTextController,
focusNode: editorFocusNode,
readOnly: widget.readOnly,
readOnly: widget.readOnly && widget.note.isContentEmpty,
autofocus: widget.autofocus,
maxLines: null,
expands: true,
decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration.collapsed(hintText: l.hint_content),
spellCheckConfiguration: SpellCheckConfiguration(
spellCheckService: DefaultSpellCheckService(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/editor/widgets/plain_text/plain_text_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class _PlainTextEditorState extends ConsumerState<PlainTextEditor> {
autofocus: widget.autofocus,
maxLines: null,
expands: true,
decoration: InputDecoration.collapsed(hintText: ''),
decoration: InputDecoration.collapsed(hintText: l.hint_content),
spellCheckConfiguration: SpellCheckConfiguration(
spellCheckService: DefaultSpellCheckService(),
),
Expand Down
3 changes: 2 additions & 1 deletion lib/pages/editor/widgets/rich_text/rich_text_editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,13 +106,14 @@ class _RichTextEditorState extends ConsumerState<RichTextEditor> {

return FleatherTheme(
data: fleatherTheme,
child: FleatherEditor(
child: FleatherField(
controller: widget.fleatherController,
focusNode: editorFocusNode,
autofocus: widget.autofocus,
readOnly: widget.readOnly,
expands: true,
onLaunchUrl: onLaunchUrl,
decoration: InputDecoration.collapsed(hintText: l.hint_content),
spellCheckConfiguration: SpellCheckConfiguration(
spellCheckService: DefaultSpellCheckService(),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/notes/widgets/add_note_fab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class _AddNoteFabState extends ConsumerState<AddNoteFab> {
key: fabKey,
type: ExpandableFabType.up,
childrenAnimation: ExpandableFabAnimation.none,
distance: 75,
distance: 64,
openButtonBuilder: RotateFloatingActionButtonBuilder(
heroTag: '<open add note FAB hero tag>',
child: const Icon(Icons.add),
Expand Down
27 changes: 16 additions & 11 deletions lib/pages/settings/pages/notes_types/settings_notes_types_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ import '../../../../common/preferences/preference_key.dart';
import '../../../../common/preferences/watched_preferences.dart';
import '../../../../common/widgets/keys.dart';
import '../../../../models/note/types/note_type.dart';
import '../../../../navigation/navigation_routes.dart';
import '../../../../providers/preferences/preferences_provider.dart';
import 'settings_notes_types_rich_text_page.dart';

/// Notes types settings.
class SettingsNotesTypesPage extends ConsumerStatefulWidget {
Expand All @@ -38,6 +36,13 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
});
}

/// Toggles the setting to use spacing between the paragraphs.
void _toggleUseParagraphSpacing(bool toggled) {
setState(() {
PreferenceKey.useParagraphsSpacing.set(toggled);
});
}

@override
Widget build(BuildContext context) {
final notesTypes = NoteType.values.map((type) {
Expand All @@ -53,6 +58,8 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
}).toList();
final defaultShortcutNoteType = NoteType.defaultShortcutType;

final useParagraphsSpacing = PreferenceKey.useParagraphsSpacing.getPreferenceOrDefault();

return Scaffold(
appBar: TopNavigation(
key: Keys.appBarSettingsMainSubpage,
Expand Down Expand Up @@ -91,16 +98,14 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
],
),
SettingSection(
title: l.settings_section_per_type_settings,
title: NoteType.richText.title,
tiles: [
SettingActionTile(
icon: NoteType.richText.icon,
title: NoteType.richText.title,
description: l.settings_page_rich_text_notes_description,
onTap: () => NavigationRoute.settingsNotesTypesRichText.push(
context,
SettingsNotesTypesRichTextPage(),
),
SettingSwitchTile(
icon: Icons.format_line_spacing,
title: l.settings_use_paragraph_spacing,
description: l.settings_use_paragraph_spacing_description,
toggled: useParagraphsSpacing,
onChanged: _toggleUseParagraphSpacing,
),
],
),
Expand Down

This file was deleted.

Loading

0 comments on commit 5b4ef9a

Please sign in to comment.