Skip to content

Commit

Permalink
[303] feat: update quick actions (#395)
Browse files Browse the repository at this point in the history
  • Loading branch information
maelchiotti authored Feb 13, 2025
1 parent 0d1f9ab commit 51791c9
Show file tree
Hide file tree
Showing 16 changed files with 105 additions and 53 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 0 additions & 3 deletions lib/common/localization/localizations_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class LocalizationsUtils {
_appLocalizations = await AppLocalizations.delegate.load(LocaleUtils().appLocale);
}

/// Title of the quick action to add a note.
String get actionAddNoteTitle => _appLocalizations.action_add_note_title;

/// Title of the welcome note.
String get welcomeNoteTitle => _appLocalizations.welcome_note_title;

Expand Down
2 changes: 1 addition & 1 deletion lib/common/preferences/preference_key.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum PreferenceKey<T extends Object> {

// Notes types
availableNotesTypes<List<String>>(['plainText', 'richText', 'markdown', 'checklist']),
defaultShortcutNoteType<String>('plainText'),
defaultShareNoteType<String>('plainText'),

// Rich text notes
useParagraphsSpacing<bool>(true),
Expand Down
60 changes: 50 additions & 10 deletions lib/common/system/quick_actions_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,31 +4,71 @@ import 'package:quick_actions/quick_actions.dart';

import '../../models/note/types/note_type.dart';
import '../actions/notes/add.dart';
import '../localization/localizations_utils.dart';
import '../constants/constants.dart';

/// Utilities for the quick actions.
///
/// This class is a singleton.
class QuickActionsUtils {
static final QuickActionsUtils _singleton = QuickActionsUtils._internal();

/// Default constructor.
factory QuickActionsUtils() => _singleton;

QuickActionsUtils._internal();

/// Application's quick actions.
late final QuickActions quickActions;

/// Ensures the utility is initialized.
void ensureInitialized(BuildContext context, WidgetRef ref) {
quickActions = const QuickActions();

quickActions.initialize((action) {
if (action == 'add_note') {
final defaultShortcutNoteType = NoteType.defaultShortcutType;
setQuickActions(context, ref);
}

/// Sets the quick actions.
void setQuickActions(BuildContext context, WidgetRef ref) {
final availableNotesTypes = NoteType.availableTypes;

addNote(context, ref, noteType: defaultShortcutNoteType);
final addPlainTextNoteAction = ShortcutItem(
type: 'add_plain_text_note',
localizedTitle: l.quick_action_add_plain_text_note_title,
icon: 'ic_text_fields',
);
final addMarkdownNoteAction = ShortcutItem(
type: 'add_markdown_note',
localizedTitle: l.quick_action_add_markdown_note_title,
icon: 'ic_markdown',
);
final addRichTextNoteAction = ShortcutItem(
type: 'add_rich_text_note',
localizedTitle: l.quick_action_add_rich_text_note_title,
icon: 'ic_format_paint',
);
final addChecklistNoteAction = ShortcutItem(
type: 'add_checklist_note',
localizedTitle: l.quick_action_add_checklist_note_title,
icon: 'ic_checklist',
);

quickActions.initialize((action) {
if (action == addPlainTextNoteAction.type) {
addNote(context, ref, noteType: NoteType.plainText);
} else if (action == addMarkdownNoteAction.type) {
addNote(context, ref, noteType: NoteType.markdown);
} else if (action == addRichTextNoteAction.type) {
addNote(context, ref, noteType: NoteType.richText);
} else if (action == addChecklistNoteAction.type) {
addNote(context, ref, noteType: NoteType.checklist);
}
});

quickActions.setShortcutItems([
ShortcutItem(
type: 'add_note',
localizedTitle: LocalizationsUtils().actionAddNoteTitle,
icon: 'ic_launcher',
),
if (availableNotesTypes.contains(NoteType.plainText)) addPlainTextNoteAction,
if (availableNotesTypes.contains(NoteType.markdown)) addMarkdownNoteAction,
if (availableNotesTypes.contains(NoteType.richText)) addRichTextNoteAction,
if (availableNotesTypes.contains(NoteType.checklist)) addChecklistNoteAction,
]);
}
}
2 changes: 1 addition & 1 deletion lib/common/system/share_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ void _processSharedData(WidgetRef ref, List<SharedMediaFile> data) {
delta.insert('$line\n');
}

final defaultShortcutNoteType = NoteType.defaultShortcutType;
final defaultShortcutNoteType = NoteType.defaultShareType;
final context = rootNavigatorKey.currentContext!;
final content = jsonEncode(delta);

Expand Down
30 changes: 21 additions & 9 deletions lib/l10n/translations/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -345,13 +345,13 @@
"@settings_available_notes_types_description": {
"description": "Description of the setting tile to choose the available notes types."
},
"settings_available_default_shortcut_type": "Default shortcut type",
"@settings_available_default_shortcut_type": {
"description": "Title of the setting tile to choose the default note type to use when creating a note from a shortcut."
"settings_available_default_share_type": "Default share type",
"@settings_available_default_share_type": {
"description": "Title of the setting tile to choose the default note type to use when creating a note from a share action."
},
"settings_available_default_shortcut_type_description": "The default note type to use when creating a note from a shortcut. It can be a type that is not available from the \"Add\" button",
"@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_available_default_share_type_description": "The default note type to use when creating a note from a share action. It can be a type that is not available from the \"Add\" button",
"@settings_available_default_share_type_description": {
"description": "Description of the setting tile to choose the default note type to use when creating a note from a share action."
},
"settings_editor": "Editor",
"@settings_editor": {
Expand Down Expand Up @@ -1045,9 +1045,21 @@
"@snack_bar_no_labels": {
"description": "Snack bar message shown when the user tries to select the labels for a note, but there are no labels available."
},
"action_add_note_title": "Add a note",
"@action_add_note_title": {
"description": "Title of the home screen action to add a new note."
"quick_action_add_plain_text_note_title": "Add a plain text note",
"@quick_action_add_plain_text_note_title": {
"description": "Title of the home screen action to add a new plain text note."
},
"quick_action_add_markdown_note_title": "Add a markdown note",
"@quick_action_add_markdown_note_title": {
"description": "Title of the home screen action to add a new markdown note."
},
"quick_action_add_rich_text_note_title": "Add a rich text note",
"@quick_action_add_rich_text_note_title": {
"description": "Title of the home screen action to add a new rich text note."
},
"quick_action_add_checklist_note_title": "Add a checklist note",
"@quick_action_add_checklist_note_title": {
"description": "Title of the home screen action to add a new checklist note."
},
"welcome_note_title": "Welcome to Material Notes!",
"@welcome_note_title": {
Expand Down
12 changes: 6 additions & 6 deletions lib/models/note/types/note_type.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_helper_utils/flutter_helper_utils.dart';
import 'package:simple_icons/simple_icons.dart';
import 'package:material_symbols_icons/material_symbols_icons.dart';

import '../../../common/constants/constants.dart';
import '../../../common/preferences/preference_key.dart';
Expand All @@ -11,7 +11,7 @@ enum NoteType {
plainText(Icons.text_fields),

/// Markdown.
markdown(SimpleIcons.markdown),
markdown(Symbols.markdown),

/// Rich text note.
richText(Icons.format_paint),
Expand All @@ -36,7 +36,7 @@ enum NoteType {
}

/// The types that can be used when creating a new note from a shortcut.
static List<NoteType> get shortcutTypes => [plainText, markdown, richText];
static List<NoteType> get shareTypes => [plainText, markdown, richText];

/// The list of types available when creating a new note from the notes list.
static List<NoteType> get availableTypes {
Expand All @@ -52,9 +52,9 @@ enum NoteType {
return availableTypes.map((type) => type.title).join(', ').capitalizeFirstLowerRest;
}

/// The default note type to used when creating a new note from a shortcut.
static NoteType get defaultShortcutType {
final defaultShortcutType = PreferenceKey.defaultShortcutNoteType.getPreferenceOrDefault();
/// The default note type to used when creating a new note via a share action.
static NoteType get defaultShareType {
final defaultShortcutType = PreferenceKey.defaultShareNoteType.getPreferenceOrDefault();

return values.byName(defaultShortcutType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.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 '../../../../common/widgets/keys.dart';
import '../../../../models/note/types/note_type.dart';
import '../../../../providers/preferences/preferences_provider.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 '../../../common/system/quick_actions_utils.dart';
import '../../../common/widgets/keys.dart';
import '../../../models/note/types/note_type.dart';
import '../../../providers/preferences/preferences_provider.dart';

/// Notes types settings.
class SettingsNotesTypesPage extends ConsumerStatefulWidget {
Expand All @@ -27,12 +28,14 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
PreferenceKey.availableNotesTypes.set(NoteType.toPreference(availableNotesTypes));

ref.read(preferencesProvider.notifier).update(WatchedPreferences(availableNotesTypes: availableNotesTypes));

QuickActionsUtils().setQuickActions(context, ref);
}

/// Sets the setting for the default shortcut note type to [defaultShortcutNoteType].
void onSubmittedDefaultShortcutNoteType(NoteType defaultShortcutNoteType) {
/// Sets the setting for the default share note type to [defaultShareNoteType].
void onSubmittedDefaultShareNoteType(NoteType defaultShareNoteType) {
setState(() {
PreferenceKey.defaultShortcutNoteType.set(defaultShortcutNoteType.name);
PreferenceKey.defaultShareNoteType.set(defaultShareNoteType.name);
});
}

Expand All @@ -53,10 +56,10 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
);
final availableNotesTypesString = NoteType.availableTypesAsString;

final shortcutNotesTypes = NoteType.shortcutTypes.map((type) {
final shareNotesTypes = NoteType.shareTypes.map((type) {
return (value: type, title: type.title, subtitle: null);
}).toList();
final defaultShortcutNoteType = NoteType.defaultShortcutType;
final defaultShareNoteType = NoteType.defaultShareType;

final useParagraphsSpacing = PreferenceKey.useParagraphsSpacing.getPreferenceOrDefault();

Expand Down Expand Up @@ -86,14 +89,14 @@ class _SettingsNotesTypesPageState extends ConsumerState<SettingsNotesTypesPage>
onSubmitted: onSubmittedAvailableNotesTypes,
),
SettingSingleOptionTile.detailed(
icon: Icons.app_shortcut,
title: l.settings_available_default_shortcut_type,
value: defaultShortcutNoteType.title,
description: l.settings_available_default_shortcut_type_description,
dialogTitle: l.settings_available_default_shortcut_type,
options: shortcutNotesTypes,
initialOption: defaultShortcutNoteType,
onSubmitted: onSubmittedDefaultShortcutNoteType,
icon: Icons.share,
title: l.settings_available_default_share_type,
value: defaultShareNoteType.title,
description: l.settings_available_default_share_type_description,
dialogTitle: l.settings_available_default_share_type,
options: shareNotesTypes,
initialOption: defaultShareNoteType,
onSubmitted: onSubmittedDefaultShareNoteType,
),
],
),
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/settings/settings_main_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import '../../common/navigation/side_navigation.dart';
import '../../common/navigation/top_navigation.dart';
import '../../common/widgets/keys.dart';
import '../../navigation/navigation_routes.dart';
import 'pages/notes_types/settings_notes_types_page.dart';
import 'pages/settings_about_page.dart';
import 'pages/settings_accessibility_page.dart';
import 'pages/settings_appearance_page.dart';
Expand All @@ -16,6 +15,7 @@ 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';
import 'pages/settings_notes_types_page.dart';

/// Page for the settings of the application.
class SettingsMainPage extends StatelessWidget {
Expand Down

0 comments on commit 51791c9

Please sign in to comment.