Even more player bug fixes (#561)

* fix status and nav bar showing up in dialogs

* update PiP when paused by external app
This commit is contained in:
Quickdesh 2022-05-02 00:40:20 +09:00 committed by GitHub
parent 50eaf8087f
commit 856847f06e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 40 additions and 15 deletions

View file

@ -35,6 +35,7 @@ import android.view.WindowManager
import android.view.animation.AnimationUtils
import android.widget.LinearLayout
import androidx.annotation.RequiresApi
import androidx.appcompat.app.AlertDialog
import androidx.core.content.ContextCompat
import androidx.core.view.GestureDetectorCompat
import androidx.core.view.WindowInsetsCompat
@ -325,6 +326,30 @@ class PlayerActivity :
playerIsDestroyed = false
}
/**
* Class to override [MaterialAlertDialogBuilder] to hide the navigation and status bars
*/
internal inner class HideBarsMaterialAlertDialogBuilder(context: Context) : MaterialAlertDialogBuilder(context) {
override fun create(): AlertDialog {
return super.create().apply {
val window = this.window ?: return@apply
val alertWindowInsetsController = WindowInsetsControllerCompat(window, window.decorView)
alertWindowInsetsController.hide(WindowInsetsCompat.Type.systemBars())
alertWindowInsetsController.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.setFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE, WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
}
}
override fun show(): AlertDialog {
return super.show().apply {
val window = this.window ?: return@apply
window.clearFlags(WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE)
}
}
}
/**
* Function to handle UI during orientation changes
*/
@ -582,12 +607,13 @@ class PlayerActivity :
verticalScrollRight(-1 / maxVolume.toFloat())
return true
}
// Not entirely sure how to handle these KeyCodes yet, need to learn some more
/**
KeyEvent.KEYCODE_MEDIA_NEXT -> {
switchEpisode(false)
return true
}
// Not entirely sure how to handle these KeyCodes yet, need to learn some more
/**
KeyEvent.KEYCODE_MEDIA_PREVIOUS -> {
switchEpisode(true)
return true
@ -664,7 +690,7 @@ class PlayerActivity :
@Suppress("UNUSED_PARAMETER")
fun openQuality(view: View) {
if (currentVideoList?.isNotEmpty() != true) return
val qualityAlert = MaterialAlertDialogBuilder(this)
val qualityAlert = HideBarsMaterialAlertDialogBuilder(this)
qualityAlert.setTitle(R.string.playback_quality_dialog_title)
@ -764,6 +790,7 @@ class PlayerActivity :
}
private fun updatePlaybackStatus(paused: Boolean) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) updatePictureInPictureActions(!paused)
val r = if (paused) R.drawable.ic_play_arrow_80dp else R.drawable.ic_pause_80dp
binding.playerControls.binding.playBtn.setImageResource(r)
@ -822,11 +849,9 @@ class PlayerActivity :
when (intent.getIntExtra(EXTRA_CONTROL_TYPE, 0)) {
CONTROL_TYPE_PLAY -> {
player.paused = false
updatePictureInPictureActions(true)
}
CONTROL_TYPE_PAUSE -> {
player.paused = true
updatePictureInPictureActions(false)
}
CONTROL_TYPE_PREVIOUS -> {
switchEpisode(true)

View file

@ -14,7 +14,6 @@ import android.widget.LinearLayout
import android.widget.SeekBar
import androidx.annotation.StringRes
import androidx.core.view.isVisible
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.databinding.PlayerControlsBinding
@ -222,7 +221,7 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
if (activity.audioTracks.isEmpty()) return
val restore = pauseForDialog()
with(MaterialAlertDialogBuilder(context)) {
with(activity.HideBarsMaterialAlertDialogBuilder(context)) {
setSingleChoiceItems(
activity.audioTracks.map { it.lang }.toTypedArray(),
activity.selectedAudio,
@ -237,7 +236,8 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
dialog.dismiss()
}
setOnDismissListener { restore() }
create().show()
create()
show()
}
}
@ -245,7 +245,7 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
if (activity.subTracks.isEmpty()) return
val restore = pauseForDialog()
with(MaterialAlertDialogBuilder(context)) {
with(activity.HideBarsMaterialAlertDialogBuilder(context)) {
setSingleChoiceItems(
activity.subTracks.map { it.lang }.toTypedArray(),
activity.selectedSub,
@ -259,7 +259,8 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
dialog.dismiss()
}
setOnDismissListener { restore() }
create().show()
create()
show()
}
}
@ -279,7 +280,7 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
@StringRes titleRes: Int,
restoreState: StateRestoreCallback,
) {
val dialog = with(MaterialAlertDialogBuilder(context)) {
with(activity.HideBarsMaterialAlertDialogBuilder(context)) {
setTitle(titleRes)
setView(picker.buildView(LayoutInflater.from(context)))
setPositiveButton(R.string.dialog_ok) { _, _ ->
@ -295,10 +296,9 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
setNegativeButton(R.string.dialog_cancel) { dialog, _ -> dialog.cancel() }
setOnDismissListener { restoreState() }
create()
show()
}
picker.number = MPVLib.getPropertyDouble("speed")
dialog.show()
}
private fun showSettings() {