-
Notifications
You must be signed in to change notification settings - Fork 174
Add home-screen quick actions #205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
7d01e88
Add home-screen quick actions
phanan 839e075
Add icons to the quick actions
phanan a32d76d
Use Lucide glyphs for the quick action icons
phanan bc3fecc
Inset the quick action glyphs
phanan 47b3fd9
Tidy quick-action cleanup and error handling
phanan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| import 'dart:async'; | ||
|
|
||
| import 'package:quick_actions/quick_actions.dart'; | ||
|
|
||
| /// Wraps the home-screen quick actions (long-press the app icon) and relays | ||
| /// them to the app. Actions received before a listener is ready (e.g. a cold | ||
| /// launch opened via a shortcut) are buffered and consumed once the app is up. | ||
| class KoelQuickActions { | ||
| static const search = 'koel_action_search'; | ||
| static const playFavorites = 'koel_action_play_favorites'; | ||
| static const playDownloaded = 'koel_action_play_downloaded'; | ||
| static const playRecent = 'koel_action_play_recent'; | ||
|
|
||
| final QuickActions _quickActions; | ||
| final _actions = StreamController<String>.broadcast(); | ||
| final _searchFocusRequests = StreamController<void>.broadcast(); | ||
|
|
||
| String? _pendingAction; | ||
| var _searchFocusPending = false; | ||
|
|
||
| KoelQuickActions({QuickActions quickActions = const QuickActions()}) | ||
| : _quickActions = quickActions; | ||
|
|
||
| /// Emits a shortcut type each time the user triggers a quick action while the | ||
| /// app is running. | ||
| Stream<String> get actions => _actions.stream; | ||
|
|
||
| /// Emits whenever the Search field should grab focus. | ||
| Stream<void> get searchFocusRequests => _searchFocusRequests.stream; | ||
|
|
||
| void initialize() { | ||
| _quickActions.initialize((type) { | ||
| _pendingAction = type; | ||
| _actions.add(type); | ||
| }); | ||
| } | ||
|
|
||
| /// Returns and clears an action received before a listener attached (a cold | ||
| /// launch via a shortcut), or null if there was none. | ||
| String? consumePendingAction() { | ||
| final action = _pendingAction; | ||
| _pendingAction = null; | ||
| return action; | ||
| } | ||
|
|
||
| void requestSearchFocus() { | ||
| _searchFocusPending = true; | ||
| _searchFocusRequests.add(null); | ||
| } | ||
|
|
||
| /// True once if a focus request arrived before the Search screen was built. | ||
| bool consumePendingSearchFocus() { | ||
| final pending = _searchFocusPending; | ||
| _searchFocusPending = false; | ||
| return pending; | ||
| } | ||
|
|
||
| Future<void> setShortcuts({String? recentSubtitle}) { | ||
| return _quickActions | ||
| .setShortcutItems(shortcutItems(recentSubtitle: recentSubtitle)); | ||
| } | ||
|
|
||
| /// The shortcut items to expose. "Play Most Recent" is only offered when | ||
| /// there is a recent track to describe. | ||
| static List<ShortcutItem> shortcutItems({String? recentSubtitle}) { | ||
| return [ | ||
| const ShortcutItem(type: search, localizedTitle: 'Search'), | ||
| const ShortcutItem( | ||
| type: playFavorites, | ||
| localizedTitle: 'Play Favorite Songs', | ||
| ), | ||
| const ShortcutItem( | ||
| type: playDownloaded, | ||
| localizedTitle: 'Play Downloaded', | ||
| ), | ||
| if (recentSubtitle != null && recentSubtitle.isNotEmpty) | ||
| ShortcutItem( | ||
| type: playRecent, | ||
| localizedTitle: 'Play Most Recent', | ||
| localizedSubtitle: recentSubtitle, | ||
| ), | ||
| ]; | ||
| } | ||
|
|
||
| /// Formats a "Artist - Title" label for the most-recent track, or just the | ||
| /// title when there's no artist. | ||
| static String? recentSubtitle({String? artist, String? title}) { | ||
| if (title == null || title.isEmpty) return null; | ||
| return (artist == null || artist.isEmpty) ? title : '$artist - $title'; | ||
| } | ||
|
|
||
| void dispose() { | ||
| _actions.close(); | ||
| _searchFocusRequests.close(); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.