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)
}
pictureInPictureParamsBuilder = PictureInPictureParams.Builder()
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 = PictureInPictureParams.Builder().setActions(mutableListOf(muteRemoteAction))
pictureInPictureParamsBuilder.setActions(mutableListOf(muteRemoteAction))
}
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
pictureInPictureParamsBuilder.setAutoEnterEnabled(true)
@ -368,6 +371,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
if (isInPictureInPictureMode) {
if (!emulationSettings.isAudioOutputDisabled) {
muteReceiver = object : BroadcastReceiver() {
override fun onReceive(context : Context?, intent : Intent) {
if (intent.action == muteIntentAction)
@ -378,17 +382,13 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
IntentFilter(muteIntentAction).also {
registerReceiver(muteReceiver, it)
}
}
binding.onScreenControllerView.isGone = true
binding.onScreenControllerToggle.isGone = true
} else {
binding.onScreenControllerView.apply {
controllerType = inputHandler.getFirstControllerType()
isGone = controllerType == ControllerType.None || !appSettings.onScreenControl
}
binding.onScreenControllerToggle.apply {
isGone = binding.onScreenControllerView.isGone
}
if (!emulationSettings.isAudioOutputDisabled) {
changeAudioStatus(true)
try {
if (this::muteReceiver.isInitialized)
@ -397,6 +397,15 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
// Perfectly acceptable and should be ignored
}
}
binding.onScreenControllerView.apply {
controllerType = inputHandler.getFirstControllerType()
isGone = controllerType == ControllerType.None || !appSettings.onScreenControl
}
binding.onScreenControllerToggle.apply {
isGone = binding.onScreenControllerView.isGone
}
}
}
/**