-
Notifications
You must be signed in to change notification settings - Fork 226
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
Audio ducking now supported during external notifications #1009
Conversation
e768508
to
b54b425
Compare
playOverNotificationPreference?.setOnPreferenceChangeListener { _, newValue -> | ||
analyticsTracker.track( | ||
AnalyticsEvent.SETTINGS_NOTIFICATIONS_PLAY_OVER_NOTIFICATIONS_TOGGLED, | ||
mapOf("enabled" to (newValue != "2")) |
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.
One thing to note around this, in the old form the tracking is a boolean since the setting is a switch and is either on or off:
AnalyticsEvent.SETTINGS_NOTIFICATIONS_PLAY_OVER_NOTIFICATIONS_TOGGLED,
mapOf("enabled" to newValue as Boolean)
I assume you're using this behind the scenes to do analytics and so I can't just create a new event, so to keep it useful, I kept the event the same, so true is when the setting is duck or always and false is when the setting is never.
If you want me to improve this in some way please let me know!
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.
Thanks for calling this out. What you've done here makes sense. Let's leave that to keep the legacy tracking of the "enabled" prop since that will keep us consistent with iOS, but we can also add a new property with the form of "value" to "never"/"duck"/"always". wdyt?
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.
we can also add a new property with the form of "value" to "never"/"duck"/"always". wdyt?
Yea that sounds good! Would you like me to add that now in this PR and you guys can add it behind the scenes when you get some time or would you rather me leave it out of this PR and you can add it in on both sides at the same time?
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.
Let's include it in this PR.
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.
This is looking really good @jamie23 ! Thanks so much for the contribution! 🙇
I left a few comments, but there are no major issues. This works very well.
One thing I did notice as I was looking through the code is that it seemed like the logic around handling the different settings values was getting spread around to a lot of places (there are a lot of classes that need to know what 0
, 1
, and 2
mean. I really liked how you created a PlayOverNotificationSetting
enum and thought we could maybe expand on that to consolidate the logic around those settings a bit and generally make the code a bit more readable.
I put together a quick POC here to show what I had in mind. Don't feel like you have to use that though, feel free to do it in your own style or decline this suggestion if you'd rather leave it as-is.
playOverNotificationPreference?.setOnPreferenceChangeListener { _, newValue -> | ||
analyticsTracker.track( | ||
AnalyticsEvent.SETTINGS_NOTIFICATIONS_PLAY_OVER_NOTIFICATIONS_TOGGLED, | ||
mapOf("enabled" to (newValue != "2")) |
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.
Thanks for calling this out. What you've done here makes sense. Let's leave that to keep the legacy tracking of the "enabled" prop since that will keep us consistent with iOS, but we can also add a new property with the form of "value" to "never"/"duck"/"always". wdyt?
val value = sharedPreferences.getString( | ||
Settings.PREFERENCE_NOTIFICATION_AUDIO, | ||
Settings.PREFERENCE_NOTIFICATION_AUDIO_DEFAULT | ||
) ?: Settings.PREFERENCE_NOTIFICATION_AUDIO_DEFAULT | ||
return Integer.parseInt(value) |
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.
What would you think about checking the value of Settings.PREFERENCE_OVERRIDE_AUDIO
if there is nothing saved for Settings.PREFERENCE_NOTIFICATION_AUDIO
? In particular, I'm thinking that for users who have previously applied the setting to play over notification audio it would be good if we retain that setting for them when they upgrade to a version of the app with your changes.
In particular, I'm looking at these test steps:
- Install previous version of the app
- Update notification preference to play over audio
- Install updated version of the app with the changes from this PR
- ❗ The app should still have the setting for playing over audio applied
wdyt?
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.
Yea great pickup and much more user friendly than a user losing their previous preference, I made an adjustment like so:
override fun getPlayOverNotification(): PlayOverNotificationSetting {
val value = sharedPreferences.getString(Settings.PREFERENCE_OVERRIDE_NOTIFICATION_AUDIO, null) ?: legacyPlayOverNotification()
return PlayOverNotificationSetting.fromPreferenceString(value)
}
private fun legacyPlayOverNotification(): String {
if (sharedPreferences.getBoolean(Settings.PREFERENCE_OVERRIDE_AUDIO_LEGACY, false)) {
return PlayOverNotificationSetting.ALWAYS.preferenceInt.toString()
}
return PlayOverNotificationSetting.NEVER.preferenceInt.toString()
}
So basically, check if they have a preference set, if not check then check if the legacy preference is set to true then return Always
otherwise return Never
.
I gave it a quick test on my device and it worked well for your test. Happy to modify if though if it can be improved further.
const val PREFERENCE_NOTIFICATION_AUDIO = "notificationAudio" | ||
const val PREFERENCE_NOTIFICATION_AUDIO_DEFAULT = "2" |
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.
"NOTIFICATION_AUDIO" makes me think that this is selecting the sound file to play with notifications. I would probably keep something like "override" or "play over" in the names here. That is just my personal preference though. This certainly isn't a blocker, so feel free to leave it as-is if you prefer.
return playOverNotification() | ||
} | ||
|
||
protected open fun playOverNotification() = when (settings.getPlayOverNotification()) { |
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.
I don't think this needs to be protected or open.
@@ -1090,8 +1090,10 @@ | |||
<string name="settings_notification_choose_podcasts">Choose podcasts</string> | |||
<string name="settings_notification_hide_on_pause">Hide playback notification on pause</string> | |||
<string name="settings_notification_notify_me">Notify me</string> | |||
<string name="settings_notification_play_over">Play over notifications</string> | |||
<string name="settings_notification_play_over_summary">Keep playing even when other apps, like notifications or navigation, play sounds.</string> | |||
<string name="settings_notification_play_over">Play over external notifications</string> |
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.
I noticed that you added "external" to this string. Do you find "notifications" on it's own to be unclear? Just asking because I'm curious.
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.
I think when I worked on it pre vacation I must have thought so, after some time away and re-reading it though I'm happy to leave "external" out of it.
CHANGELOG.md
Outdated
* Added audio ducking as an option when playing over external notifications | ||
([#1009](https://github.com/Automattic/pocket-casts-android/pull/1009)). |
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.
We'll need to merge in main
and move this entry to the next release before we merge this.
@jamie23 are you still working on this? It'd be great to have this 😊 |
b54b425
to
297c1da
Compare
Thanks for the review! I've been on vacation for the last couple of weeks so just getting back round to looking at your comments (sorry if you've been waiting on this @larena1 !). Yea I really like what you've done with |
297c1da
to
d72d56a
Compare
d72d56a
to
a899510
Compare
a899510
to
3e7b7e0
Compare
3e7b7e0
to
bf20eaa
Compare
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.
This looks good! Thanks!
Description
Added functionality for audio ducking when external notifications come in. There was already some logic there around it hence I've labeled this a fix.
Fixes #529
Testing Instructions
Screenshots or Screencast
Updated the logs file to show the setting chosen:
Checklist
modules/services/localization/src/main/res/values/strings.xml
I have tested any UI changes...