Respect the existing "mute" user preference

This commit is contained in:
Abandoned Cart 2023-02-15 02:54:17 -05:00 committed by Billy Laws
parent bdc368e039
commit a1143ee5de

View File

@ -272,11 +272,14 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler) binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
} }
val muteIcon = Icon.createWithResource(this, R.drawable.ic_volume_mute) pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
val mutePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_volume_mute, Intent(muteIntentAction), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val muteRemoteAction = RemoteAction(muteIcon, getString(R.string.mute), getString(R.string.disable_audio_output), mutePendingIntent)
pictureInPictureParamsBuilder = PictureInPictureParams.Builder().setActions(mutableListOf(muteRemoteAction)) if (!emulationSettings.isAudioOutputDisabled) {
val muteIcon = Icon.createWithResource(this, R.drawable.ic_volume_mute)
val mutePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_volume_mute, Intent(muteIntentAction), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val muteRemoteAction = RemoteAction(muteIcon, getString(R.string.mute), getString(R.string.disable_audio_output), mutePendingIntent)
pictureInPictureParamsBuilder.setActions(mutableListOf(muteRemoteAction))
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
pictureInPictureParamsBuilder.setAutoEnterEnabled(true) pictureInPictureParamsBuilder.setAutoEnterEnabled(true)
@ -368,20 +371,33 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) { override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig) super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
muteReceiver = object : BroadcastReceiver() { if (!emulationSettings.isAudioOutputDisabled) {
override fun onReceive(context: Context?, intent: Intent) { muteReceiver = object : BroadcastReceiver() {
if (intent.action == muteIntentAction) override fun onReceive(context : Context?, intent : Intent) {
changeAudioStatus(false) if (intent.action == muteIntentAction)
changeAudioStatus(false)
}
} }
}
IntentFilter(muteIntentAction).also { IntentFilter(muteIntentAction).also {
registerReceiver(muteReceiver, it) registerReceiver(muteReceiver, it)
}
} }
binding.onScreenControllerView.isGone = true binding.onScreenControllerView.isGone = true
binding.onScreenControllerToggle.isGone = true binding.onScreenControllerToggle.isGone = true
} else { } else {
if (!emulationSettings.isAudioOutputDisabled) {
changeAudioStatus(true)
try {
if (this::muteReceiver.isInitialized)
unregisterReceiver(muteReceiver)
} catch (ignored : Exception) {
// Perfectly acceptable and should be ignored
}
}
binding.onScreenControllerView.apply { binding.onScreenControllerView.apply {
controllerType = inputHandler.getFirstControllerType() controllerType = inputHandler.getFirstControllerType()
isGone = controllerType == ControllerType.None || !appSettings.onScreenControl isGone = controllerType == ControllerType.None || !appSettings.onScreenControl
@ -389,13 +405,6 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
binding.onScreenControllerToggle.apply { binding.onScreenControllerToggle.apply {
isGone = binding.onScreenControllerView.isGone isGone = binding.onScreenControllerView.isGone
} }
try {
if (this::muteReceiver.isInitialized)
unregisterReceiver(muteReceiver)
} catch (ignored: Exception) {
// Perfectly acceptable and should be ignored
}
} }
} }