-
-
Notifications
You must be signed in to change notification settings - Fork 686
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
feat: notification config builder #914
base: minor
Are you sure you want to change the base?
Conversation
adds `NotificationConfig` that contains config adds `NotificationConfigBuilder` that is used to accure config adds `PlayerStateSnapshot` that provides access to state to builder
@ryanheise here's discussed prototype. |
|
||
/// Snapshot of current player state. | ||
/// Used to provide data to [NotificationConfigBuilder]. | ||
abstract class PlayerStateSnapshot { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unfortunate to replicate existing state classes that are in just_audio, but just_audio_background should not depend on just_audio so this is understandable for now.
Eventually, I think these state classes should be defined in just_audio_platform_interface where they can be reused.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, is this in scope of this PR, if so, tell me where I should move it, please?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That comment was just to recognise the need for something now even though it should be moved elsewhere in the future.
But as it is, is this really a "snapshot"? It looks like you're using this as a mixin (although you defined it as an abstract class instead of a mixin). That means that this package is now returning a reference to an internal class which it probably shouldn't. If the so-called snapshot is actually an object where the values may change behind the scenes, then it is not really a snapshot. I think it would be far less surprising to create an immutable state object, and to build a new instance of it each time a new state needs to be broadcast.
As for naming, and considering where these state objects will likely move in the future, I would say we do not know at this stage what that future state object will look like, and anything we might come up with now would be rather narrow in its vision. So to avoid any future problems, it might be best to choose a class name for this state that is obviously specific to this particular package rather than some name that we might want to reserve for the future ideal API.
since this class is internal, but exposed to provider access to the interface
Just as an update on where I'm at with this PR, I am not yet 100% sure on which way we want to go on the API design. If we look at the default implementation of the notification builder: _defaultNotificationConfigBuilder(PlayerStateSnapshot state) {
final controls = [
if (state.hasPrevious) MediaControl.skipToPrevious,
if (state.playing) MediaControl.pause else MediaControl.play,
MediaControl.stop,
if (state.hasNext) MediaControl.skipToNext,
];
return NotificationConfig(
controls: controls,
systemActions: const {
MediaAction.seek,
MediaAction.seekForward,
MediaAction.seekBackward,
},
androidCompactActionIndices: List.generate(controls.length, (i) => i)
..removeAt(controls.indexOf(MediaControl.stop)));
} I still find this In terms of API naming, an app may display other kinds of notifications, and so it may perhaps be a good idea to prefix these class names with |
resolves #912
adds
NotificationConfig
that contains configadds
NotificationConfigBuilder
that is used to accure configadds
PlayerStateSnapshot
that provides access to state to builder