From 3e7b7e07d926e62f73bef089b7769d99331b094a Mon Sep 17 00:00:00 2001 From: Jamie McDowell Date: Sun, 16 Jul 2023 21:39:33 +0100 Subject: [PATCH] Audio ducking now reads legacy setting --- CHANGELOG.md | 6 ++++-- .../settings/NotificationsSettingsFragment.kt | 4 ++-- .../src/main/res/xml/preferences_notifications.xml | 2 +- .../localization/src/main/res/values/strings.xml | 2 +- .../shiftyjelly/pocketcasts/preferences/Settings.kt | 4 ++-- .../pocketcasts/preferences/SettingsImpl.kt | 13 +++++++++---- .../repositories/playback/FocusManager.kt | 1 + 7 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2ca1732e692..3cbaceee789 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,10 @@ * Added share option to episode swipe and multiselect menus ([#1190](https://github.com/Automattic/pocket-casts-android/pull/1190)), ([#1191](https://github.com/Automattic/pocket-casts-android/pull/1191)) +* Bug Fixes: + * Added audio ducking as an option when playing over notifications + ([#1009](https://github.com/Automattic/pocket-casts-android/pull/1009)). +>>>>>>> a8995106b (Audio ducking now reads legacy setting) 7.43 ----- @@ -64,8 +68,6 @@ ([#973](https://github.com/Automattic/pocket-casts-android/pull/973)). * Improved the Automotive user profile view ([#975](https://github.com/Automattic/pocket-casts-android/pull/975)). - * Added audio ducking as an option when playing over external notifications - ([#1009](https://github.com/Automattic/pocket-casts-android/pull/1009)). 7.39 ----- diff --git a/modules/features/settings/src/main/java/au/com/shiftyjelly/pocketcasts/settings/NotificationsSettingsFragment.kt b/modules/features/settings/src/main/java/au/com/shiftyjelly/pocketcasts/settings/NotificationsSettingsFragment.kt index 67197f4fb66..cedda73a6a4 100644 --- a/modules/features/settings/src/main/java/au/com/shiftyjelly/pocketcasts/settings/NotificationsSettingsFragment.kt +++ b/modules/features/settings/src/main/java/au/com/shiftyjelly/pocketcasts/settings/NotificationsSettingsFragment.kt @@ -97,7 +97,7 @@ class NotificationsSettingsFragment : vibratePreference = manager.findPreference("notificationVibrate") notificationActions = manager.findPreference("notificationActions") systemSettingsPreference = manager.findPreference("openSystemSettings") - playOverNotificationPreference = manager.findPreference("notificationAudio") + playOverNotificationPreference = manager.findPreference("overrideNotificationAudio") // turn preferences off by default, because they are enable async, we don't want this view to remove them from the screen after it loads as it looks jarring enabledPreferences(false) @@ -410,7 +410,7 @@ class NotificationsSettingsFragment : override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String) { if (Settings.PREFERENCE_NOTIFICATION_VIBRATE == key) { changeVibrateSummary() - } else if (Settings.PREFERENCE_NOTIFICATION_AUDIO == key) { + } else if (Settings.PREFERENCE_OVERRIDE_NOTIFICATION_AUDIO == key) { changePlayOverNotificationSummary() } } diff --git a/modules/features/settings/src/main/res/xml/preferences_notifications.xml b/modules/features/settings/src/main/res/xml/preferences_notifications.xml index 90b51bfd249..8355e0c24d6 100644 --- a/modules/features/settings/src/main/res/xml/preferences_notifications.xml +++ b/modules/features/settings/src/main/res/xml/preferences_notifications.xml @@ -43,7 +43,7 @@ diff --git a/modules/services/localization/src/main/res/values/strings.xml b/modules/services/localization/src/main/res/values/strings.xml index 35fd92b9c36..5e162689ea0 100644 --- a/modules/services/localization/src/main/res/values/strings.xml +++ b/modules/services/localization/src/main/res/values/strings.xml @@ -1135,7 +1135,7 @@ Choose podcasts Hide playback notification on pause Notify me - Play over external notifications + Play over notifications Never Duck volume Always diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt index 898132e172c..197cff2875e 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/Settings.kt @@ -83,8 +83,8 @@ interface Settings { const val PREFERENCE_SELECT_PODCAST_LIBRARY_SORT = "selectPodcastLibrarySort" const val PREFERENCE_WARN_WHEN_NOT_ON_WIFI = "warnWhenNotOnWifi" const val PREFERENCE_SYNC_ON_METERED = "SyncWhenOnMetered" - const val PREFERENCE_NOTIFICATION_AUDIO = "notificationAudio" - const val PREFERENCE_NOTIFICATION_AUDIO_DEFAULT = "2" + const val PREFERENCE_OVERRIDE_AUDIO_LEGACY = "overrideAudioInterruption" + const val PREFERENCE_OVERRIDE_NOTIFICATION_AUDIO = "overrideNotificationAudio" const val PREFERENCE_USE_EMBEDDED_ARTWORK = "useEmbeddedArtwork" const val PREFERENCE_LAST_MODIFIED = "lastModified" const val PREFERENCE_FIRST_SYNC_RUN = "firstSyncRun" diff --git a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt index f6c2f73534d..25f7bb5bd6c 100644 --- a/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt +++ b/modules/services/preferences/src/main/java/au/com/shiftyjelly/pocketcasts/preferences/SettingsImpl.kt @@ -505,13 +505,18 @@ class SettingsImpl @Inject constructor( } override fun getPlayOverNotification(): PlayOverNotificationSetting { - val value = sharedPreferences.getString( - Settings.PREFERENCE_NOTIFICATION_AUDIO, - Settings.PREFERENCE_NOTIFICATION_AUDIO_DEFAULT - ) ?: Settings.PREFERENCE_NOTIFICATION_AUDIO_DEFAULT + 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() + } + override fun hasBlockAlreadyRun(label: String): Boolean { return sharedPreferences.getBoolean("blockAlreadyRun$label", false) } diff --git a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/FocusManager.kt b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/FocusManager.kt index 7d032c645a9..d48688452e8 100644 --- a/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/FocusManager.kt +++ b/modules/services/repositories/src/main/java/au/com/shiftyjelly/pocketcasts/repositories/playback/FocusManager.kt @@ -155,6 +155,7 @@ open class FocusManager(private val settings: Settings, context: Context?) : Aud if (audioFocus != AUDIO_NO_FOCUS_CAN_DUCK_TRANSIENT) return PlayOverNotificationSetting.NEVER return settings.getPlayOverNotification() } + interface FocusChangeListener { fun onFocusGain(shouldResume: Boolean) fun onFocusLoss(playOverNotification: PlayOverNotificationSetting, transientLoss: Boolean)