Merge pull request #3432 from Isira-Seneviratne/Pip_support

Disable picture-in-picture on Android Go devices.
This commit is contained in:
Bnyro 2023-03-28 17:09:07 +02:00 committed by GitHub
commit 446c9478e0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 8 deletions

View File

@ -1,9 +1,16 @@
package com.github.libretube.compat
import android.app.Activity
import android.content.Context
import android.content.pm.PackageManager
import android.os.Build
object PictureInPictureCompat {
fun isPictureInPictureAvailable(context: Context): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O &&
context.packageManager.hasSystemFeature(PackageManager.FEATURE_PICTURE_IN_PICTURE)
}
fun isInPictureInPictureMode(activity: Activity): Boolean {
return Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && activity.isInPictureInPictureMode
}

View File

@ -344,13 +344,12 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
binding.playerMotionLayout.progress = 1.toFloat()
binding.playerMotionLayout.transitionToStart()
val activity = requireActivity()
if (PlayerHelper.pipEnabled) {
PictureInPictureCompat.setPictureInPictureParams(requireActivity(), pipParams)
}
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
binding.relPlayerPip.visibility = View.GONE
PictureInPictureCompat.setPictureInPictureParams(activity, pipParams)
}
binding.relPlayerPip.isVisible = PictureInPictureCompat
.isPictureInPictureAvailable(activity)
}
// actions that don't depend on video information

View File

@ -2,8 +2,6 @@ package com.github.libretube.ui.preferences
import android.content.ActivityNotFoundException
import android.content.Intent
import android.os.Build
import android.os.Build.VERSION.SDK_INT
import android.os.Bundle
import android.provider.Settings
import android.widget.Toast
@ -11,6 +9,7 @@ import androidx.preference.ListPreference
import androidx.preference.Preference
import androidx.preference.SwitchPreferenceCompat
import com.github.libretube.R
import com.github.libretube.compat.PictureInPictureCompat
import com.github.libretube.constants.PreferenceKeys
import com.github.libretube.helpers.LocaleHelper
import com.github.libretube.helpers.PreferenceHelper
@ -64,7 +63,8 @@ class PlayerSettings : BasePreferenceFragment() {
PreferenceKeys.PICTURE_IN_PICTURE
)!!
val pauseOnQuit = findPreference<SwitchPreferenceCompat>(PreferenceKeys.PAUSE_ON_QUIT)
pictureInPicture.isVisible = SDK_INT >= Build.VERSION_CODES.O
pictureInPicture.isVisible = PictureInPictureCompat
.isPictureInPictureAvailable(requireContext())
pauseOnQuit?.isVisible = !pictureInPicture.isVisible || !pictureInPicture.isChecked
pictureInPicture.setOnPreferenceChangeListener { _, newValue ->