mirror of
https://github.com/aniyomiorg/aniyomi.git
synced 2024-11-29 09:39:03 +03:00
Few PiP fixes (#552)
This commit is contained in:
parent
a9ff9e792d
commit
d2c25d6caa
7 changed files with 73 additions and 33 deletions
|
@ -11,6 +11,8 @@ object PreferenceKeys {
|
|||
|
||||
const val defaultReadingMode = "pref_default_reading_mode_key"
|
||||
|
||||
const val pipEpisodeToasts = "pref_pip_episode_toasts"
|
||||
|
||||
const val defaultOrientationType = "pref_default_orientation_type_key"
|
||||
|
||||
const val defaultPlayerOrientationType = "pref_default_player_orientation_type_key"
|
||||
|
|
|
@ -118,6 +118,8 @@ class PreferencesHelper(val context: Context) {
|
|||
|
||||
fun defaultReadingMode() = prefs.getInt(Keys.defaultReadingMode, ReadingModeType.RIGHT_TO_LEFT.flagValue)
|
||||
|
||||
fun pipEpisodeToasts() = prefs.getBoolean(Keys.pipEpisodeToasts, true)
|
||||
|
||||
fun defaultOrientationType() = prefs.getInt(Keys.defaultOrientationType, OrientationType.FREE.flagValue)
|
||||
|
||||
fun defaultPlayerOrientationType() = prefs.getInt(Keys.defaultPlayerOrientationType, OrientationType.FREE.flagValue)
|
||||
|
|
|
@ -92,6 +92,7 @@ class PlayerActivity :
|
|||
}
|
||||
|
||||
private var isInPipMode: Boolean = false
|
||||
private var isPipStarted: Boolean = false
|
||||
|
||||
private var mReceiver: BroadcastReceiver? = null
|
||||
|
||||
|
@ -311,10 +312,46 @@ class PlayerActivity :
|
|||
}
|
||||
presenter.init(anime, episode)
|
||||
}
|
||||
val dm = DisplayMetrics()
|
||||
windowManager.defaultDisplay.getRealMetrics(dm)
|
||||
width = dm.widthPixels
|
||||
height = dm.heightPixels
|
||||
if (width <= height) {
|
||||
switchOrientation(false)
|
||||
} else {
|
||||
switchOrientation(true)
|
||||
}
|
||||
|
||||
playerIsDestroyed = false
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to handle UI during orientation changes
|
||||
*/
|
||||
|
||||
private fun switchOrientation(isLandscape: Boolean) {
|
||||
launchUI {
|
||||
if (isLandscape) {
|
||||
if (width <= height) {
|
||||
width = height.also { height = width }
|
||||
}
|
||||
binding.playerControls.binding.controlsTopLandscape.visibility = View.VISIBLE
|
||||
binding.playerControls.binding.controlsTopPortrait.visibility = View.GONE
|
||||
setupGestures()
|
||||
setViewMode()
|
||||
} else {
|
||||
if (width >= height) {
|
||||
width = height.also { height = width }
|
||||
}
|
||||
binding.playerControls.binding.controlsTopPortrait.visibility = View.VISIBLE
|
||||
binding.playerControls.binding.controlsTopLandscape.visibility = View.GONE
|
||||
setupGestures()
|
||||
setViewMode()
|
||||
}
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) player.paused?.let { updatePictureInPictureActions(!it) }
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets up the gestures to be used
|
||||
*/
|
||||
|
@ -322,11 +359,6 @@ class PlayerActivity :
|
|||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
private fun setupGestures() {
|
||||
val dm = DisplayMetrics()
|
||||
windowManager.defaultDisplay.getRealMetrics(dm)
|
||||
width = dm.widthPixels
|
||||
height = dm.heightPixels
|
||||
|
||||
val gestures = Gestures(this, width.toFloat(), height.toFloat())
|
||||
mDetector = GestureDetectorCompat(this, gestures)
|
||||
player.setOnTouchListener { v, event ->
|
||||
|
@ -337,7 +369,13 @@ class PlayerActivity :
|
|||
|
||||
override fun onConfigurationChanged(newConfig: Configuration) {
|
||||
super.onConfigurationChanged(newConfig)
|
||||
if (newConfig.orientation == ORIENTATION_PORTRAIT || newConfig.orientation == ORIENTATION_LANDSCAPE) launchUI { setupGestures(); setViewMode() }
|
||||
if (!isPipStarted) {
|
||||
if (newConfig.orientation == ORIENTATION_LANDSCAPE) {
|
||||
switchOrientation(true)
|
||||
} else if (newConfig.orientation == ORIENTATION_PORTRAIT) {
|
||||
switchOrientation(false)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,7 +401,7 @@ class PlayerActivity :
|
|||
when {
|
||||
epTxt == "Invalid" -> return
|
||||
epTxt == null -> { launchUI { toast(errorRes) }; showLoadingIndicator(false) }
|
||||
isInPipMode -> launchUI { toast(epTxt) }
|
||||
isInPipMode -> if (preferences.pipEpisodeToasts()) launchUI { toast(epTxt) }
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -445,12 +483,8 @@ class PlayerActivity :
|
|||
fun rotatePlayer(view: View) {
|
||||
if (this.requestedOrientation == ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT) {
|
||||
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||
binding.playerControls.binding.controlsTopLandscape.isVisible = true
|
||||
binding.playerControls.binding.controlsTopPortrait.isVisible = false
|
||||
} else {
|
||||
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||
binding.playerControls.binding.controlsTopLandscape.isVisible = false
|
||||
binding.playerControls.binding.controlsTopPortrait.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -773,7 +807,7 @@ class PlayerActivity :
|
|||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration?) {
|
||||
isInPipMode = isInPictureInPictureMode
|
||||
|
||||
isPipStarted = isInPipMode
|
||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
||||
|
||||
if (isInPictureInPictureMode) {
|
||||
|
@ -796,11 +830,9 @@ class PlayerActivity :
|
|||
}
|
||||
CONTROL_TYPE_PREVIOUS -> {
|
||||
switchEpisode(true)
|
||||
player.paused?.let { updatePictureInPictureActions(!it) }
|
||||
}
|
||||
CONTROL_TYPE_NEXT -> {
|
||||
switchEpisode(false)
|
||||
player.paused?.let { updatePictureInPictureActions(!it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -816,9 +848,10 @@ class PlayerActivity :
|
|||
}
|
||||
}
|
||||
|
||||
@Suppress("DEPRECATION")
|
||||
internal fun startPiP() {
|
||||
@Suppress("DEPRECATION", "UNUSED_PARAMETER")
|
||||
fun startPiP(view: View) {
|
||||
if (packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
isPipStarted = true
|
||||
player.paused?.let { updatePictureInPictureActions(!it) }
|
||||
?.let { this.enterPictureInPictureMode(it) }
|
||||
}
|
||||
|
@ -886,7 +919,7 @@ class PlayerActivity :
|
|||
|
||||
),
|
||||
)
|
||||
.setAspectRatio(player.videoAspect?.times(10000)?.let { Rational(it.toInt(), 10000) })
|
||||
.setAspectRatio(MPVLib.getPropertyInt("video-params/dw")?.let { width -> MPVLib.getPropertyInt("video-params/dh")?.let { height -> Rational(width, height) } })
|
||||
.build()
|
||||
setPictureInPictureParams(mPictureInPictureParams)
|
||||
return mPictureInPictureParams
|
||||
|
@ -1046,22 +1079,16 @@ class PlayerActivity :
|
|||
.coerceAtLeast(0)
|
||||
}
|
||||
}
|
||||
launchUI { showLoadingIndicator(false) }
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) player.paused?.let { updatePictureInPictureActions(!it) }
|
||||
if (player.videoW!! / player.videoH!! >= 1) {
|
||||
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||
launchUI {
|
||||
binding.playerControls.binding.controlsTopLandscape.visibility = View.VISIBLE
|
||||
binding.playerControls.binding.controlsTopPortrait.visibility = View.GONE
|
||||
}
|
||||
} else {
|
||||
this.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||
launchUI {
|
||||
binding.playerControls.binding.controlsTopPortrait.visibility = View.VISIBLE
|
||||
binding.playerControls.binding.controlsTopLandscape.visibility = View.GONE
|
||||
launchUI {
|
||||
showLoadingIndicator(false)
|
||||
if (player.videoW!! / player.videoH!! >= 1) {
|
||||
this@PlayerActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
|
||||
switchOrientation(true)
|
||||
} else {
|
||||
this@PlayerActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
|
||||
switchOrientation(false)
|
||||
}
|
||||
}
|
||||
launchUI { setupGestures(); setViewMode() }
|
||||
}
|
||||
|
||||
// mpv events
|
||||
|
|
|
@ -71,8 +71,6 @@ class PlayerControlsView @JvmOverloads constructor(context: Context, attrs: Attr
|
|||
binding.backArrowBtnLandscape.setOnClickListener { activity.finishAndRemoveTask() }
|
||||
binding.backArrowBtnPortrait.setOnClickListener { activity.finishAndRemoveTask() }
|
||||
|
||||
binding.pipBtn.setOnClickListener { activity.startPiP() }
|
||||
|
||||
// Lock and Unlock controls
|
||||
binding.lockBtn.setOnClickListener { lockControls(true) }
|
||||
binding.unlockBtn.setOnClickListener { lockControls(false) }
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package eu.kanade.tachiyomi.ui.setting
|
||||
|
||||
import android.content.pm.PackageManager
|
||||
import android.os.Build
|
||||
import androidx.preference.PreferenceScreen
|
||||
import eu.kanade.tachiyomi.R
|
||||
|
@ -71,6 +72,14 @@ class SettingsPlayerController : SettingsController() {
|
|||
}
|
||||
}
|
||||
|
||||
if (context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE) && Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
switchPreference {
|
||||
key = Keys.pipEpisodeToasts
|
||||
titleRes = R.string.pref_pip_episode_toasts
|
||||
defaultValue = true
|
||||
}
|
||||
}
|
||||
|
||||
switchPreference {
|
||||
key = Keys.alwaysUseExternalPlayer
|
||||
titleRes = R.string.pref_always_use_external_player
|
||||
|
|
|
@ -392,6 +392,7 @@
|
|||
android:layout_height="match_parent"
|
||||
android:background="?android:attr/selectableItemBackground"
|
||||
android:contentDescription="@string/action_player_pip"
|
||||
android:onClick="startPiP"
|
||||
android:src="@drawable/ic_picture_in_picture_24dp"
|
||||
android:visibility="visible" />
|
||||
|
||||
|
|
|
@ -444,6 +444,7 @@
|
|||
<string name="pref_skip_5">5s</string>
|
||||
<string name="pref_always_use_external_player">Always use external player</string>
|
||||
<string name="pref_player_fullscreen">Show content in display cutout</string>
|
||||
<string name="pref_pip_episode_toasts">Show episode toasts when switching episodes in PiP mode</string>
|
||||
<string name="pref_external_player_preference">External player preference</string>
|
||||
<string name="pref_progress_70">70%</string>
|
||||
<string name="pref_progress_75">75%</string>
|
||||
|
|
Loading…
Reference in a new issue