diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 9bb2e0154..13a0ec59f 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -33,7 +33,8 @@ diff --git a/app/src/main/java/com/github/libretube/MainActivity.kt b/app/src/main/java/com/github/libretube/MainActivity.kt index 7cd322ee4..455b411c6 100644 --- a/app/src/main/java/com/github/libretube/MainActivity.kt +++ b/app/src/main/java/com/github/libretube/MainActivity.kt @@ -317,6 +317,13 @@ class MainActivity : AppCompatActivity() { } } + override fun onUserLeaveHint() { + super.onUserLeaveHint() + supportFragmentManager.fragments.forEach { fragment -> + (fragment as? PlayerFragment)?.onUserLeaveHint() + } + } + } fun Fragment.hideKeyboard() { view?.let { activity?.hideKeyboard(it) } diff --git a/app/src/main/java/com/github/libretube/PlayerFragment.kt b/app/src/main/java/com/github/libretube/PlayerFragment.kt index fa6c60caf..f4af043fd 100644 --- a/app/src/main/java/com/github/libretube/PlayerFragment.kt +++ b/app/src/main/java/com/github/libretube/PlayerFragment.kt @@ -2,12 +2,12 @@ package com.github.libretube import android.Manifest import android.annotation.SuppressLint -import android.app.Activity import android.content.Context import android.content.DialogInterface import android.content.Intent import android.content.pm.ActivityInfo import android.content.pm.PackageManager +import android.graphics.Rect import android.net.Uri import android.os.Build import android.os.Build.VERSION.SDK_INT @@ -15,7 +15,6 @@ import android.os.Bundle import android.os.Environment import android.text.Html import android.util.Log -import android.util.TypedValue import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -804,4 +803,39 @@ class PlayerFragment : Fragment() { } } } + + override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean) { + super.onPictureInPictureModeChanged(isInPictureInPictureMode) + if (isInPictureInPictureMode) { + exoPlayerView.hideController() + with(motionLayout) { + getConstraintSet(R.id.start).constrainHeight(R.id.player, -1) + enableTransition(R.id.yt_transition, false) + } + view?.findViewById(R.id.main_container)?.isClickable = true + view?.findViewById(R.id.linLayout)?.visibility = View.GONE + view?.findViewById(R.id.top_bar)?.visibility = View.GONE + val mainActivity = activity as MainActivity + mainActivity.requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT + isFullScreen = false; + } else { + with(motionLayout) { + getConstraintSet(R.id.start).constrainHeight(R.id.player, 0) + enableTransition(R.id.yt_transition, true) + } + view?.findViewById(R.id.main_container)?.isClickable = false + view?.findViewById(R.id.linLayout)?.visibility = View.VISIBLE + view?.findViewById(R.id.top_bar)?.visibility = View.VISIBLE + } + } + + fun onUserLeaveHint() { + val bounds = Rect() + val scrollView = view?.findViewById(R.id.player_scrollView) + scrollView?.getHitRect(bounds) + + if (SDK_INT >= Build.VERSION_CODES.N && exoPlayer.isPlaying && (scrollView?.getLocalVisibleRect(bounds) == true || isFullScreen)) { + requireActivity().enterPictureInPictureMode() + }; + } }