chore: bump target sdk to 34 and fix pip issues

This commit is contained in:
Bnyro 2024-02-26 12:33:30 +01:00
parent f0a779b4d1
commit bf0d6bde2c
5 changed files with 36 additions and 23 deletions

View File

@ -14,7 +14,7 @@ android {
defaultConfig { defaultConfig {
applicationId = "com.github.libretube" applicationId = "com.github.libretube"
minSdk = 21 minSdk = 21
targetSdk = 33 targetSdk = 34
versionCode = 47 versionCode = 47
versionName = "0.21.1" versionName = "0.21.1"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

View File

@ -221,10 +221,11 @@ object PlayerHelper {
false false
) )
private val behaviorWhenMinimized = PreferenceHelper.getString( private val behaviorWhenMinimized
PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED, get() = PreferenceHelper.getString(
"pip" PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED,
) "pip"
)
val pipEnabled: Boolean val pipEnabled: Boolean
get() = behaviorWhenMinimized == "pip" get() = behaviorWhenMinimized == "pip"
@ -386,7 +387,9 @@ object PlayerHelper {
} }
private fun getPendingIntent(activity: Activity, event: PlayerEvent): PendingIntent { private fun getPendingIntent(activity: Activity, event: PlayerEvent): PendingIntent {
val intent = Intent(getIntentAction(activity)).putExtra(CONTROL_TYPE, event) val intent = Intent(getIntentAction(activity))
.setPackage(activity.packageName)
.putExtra(CONTROL_TYPE, event)
return PendingIntentCompat.getBroadcast(activity, event.ordinal, intent, 0, false)!! return PendingIntentCompat.getBroadcast(activity, event.ordinal, intent, 0, false)!!
} }

View File

@ -10,6 +10,7 @@ import android.os.IBinder
import android.view.LayoutInflater import android.view.LayoutInflater
import android.view.View import android.view.View
import android.view.ViewGroup import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.core.view.isGone import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.isVisible import androidx.core.view.isVisible
@ -193,10 +194,12 @@ class DownloadsFragment : DynamicLayoutManagerFragment() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
val filter = IntentFilter()
filter.addAction(DownloadService.ACTION_SERVICE_STARTED) val filter = IntentFilter().apply {
filter.addAction(DownloadService.ACTION_SERVICE_STOPPED) addAction(DownloadService.ACTION_SERVICE_STARTED)
context?.registerReceiver(downloadReceiver, filter) addAction(DownloadService.ACTION_SERVICE_STOPPED)
}
ContextCompat.registerReceiver(requireContext(), downloadReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)
} }
fun bindDownloadService(ids: IntArray? = null) { fun bindDownloadService(ids: IntArray? = null) {

View File

@ -23,6 +23,7 @@ import android.view.ViewGroup.LayoutParams
import android.widget.Toast import android.widget.Toast
import androidx.constraintlayout.motion.widget.MotionLayout import androidx.constraintlayout.motion.widget.MotionLayout
import androidx.constraintlayout.motion.widget.TransitionAdapter import androidx.constraintlayout.motion.widget.TransitionAdapter
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toDrawable import androidx.core.graphics.drawable.toDrawable
import androidx.core.net.toUri import androidx.core.net.toUri
@ -371,9 +372,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playerLayoutOrientation = resources.configuration.orientation playerLayoutOrientation = resources.configuration.orientation
// broadcast receiver for PiP actions // broadcast receiver for PiP actions
context?.registerReceiver( ContextCompat.registerReceiver(
requireContext(),
broadcastReceiver, broadcastReceiver,
IntentFilter(PlayerHelper.getIntentAction(requireContext())) IntentFilter(PlayerHelper.getIntentAction(requireContext())),
ContextCompat.RECEIVER_NOT_EXPORTED
) )
fullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), true) fullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), true)
@ -595,6 +598,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
playOnBackground() playOnBackground()
} }
binding.relPlayerPip.isVisible = PictureInPictureCompat.isPictureInPictureAvailable(requireContext())
binding.relPlayerPip.setOnClickListener { binding.relPlayerPip.setOnClickListener {
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams) PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
} }
@ -1586,11 +1591,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
} }
fun onUserLeaveHint() { fun onUserLeaveHint() {
if (PlayerHelper.pipEnabled && shouldStartPiP()) { if (shouldStartPiP()) {
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams) PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
return } else if (PlayerHelper.pauseOnQuit) {
}
if (PlayerHelper.pauseOnQuit) {
exoPlayer.pause() exoPlayer.pause()
} }
} }
@ -1625,14 +1628,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
/** /**
* Detect whether PiP is supported and enabled * Detect whether PiP is supported and enabled
*/ */
private fun usePiP(): Boolean { private fun shouldUsePip(): Boolean {
return PictureInPictureCompat.isPictureInPictureAvailable(requireContext()) && PlayerHelper.pipEnabled return PictureInPictureCompat.isPictureInPictureAvailable(requireContext()) && PlayerHelper.pipEnabled
} }
private fun shouldStartPiP(): Boolean { private fun shouldStartPiP(): Boolean {
return usePiP() && exoPlayer.isPlaying && !BackgroundHelper.isBackgroundServiceRunning( return shouldUsePip() && exoPlayer.isPlaying &&
requireContext() !BackgroundHelper.isBackgroundServiceRunning(requireContext())
)
} }
private fun killPlayerFragment() { private fun killPlayerFragment() {

View File

@ -14,6 +14,7 @@ import android.support.v4.media.session.PlaybackStateCompat
import androidx.annotation.DrawableRes import androidx.annotation.DrawableRes
import androidx.core.app.NotificationCompat import androidx.core.app.NotificationCompat
import androidx.core.app.PendingIntentCompat import androidx.core.app.PendingIntentCompat
import androidx.core.content.ContextCompat
import androidx.core.content.getSystemService import androidx.core.content.getSystemService
import androidx.core.graphics.drawable.toBitmap import androidx.core.graphics.drawable.toBitmap
import androidx.media.app.NotificationCompat.MediaStyle import androidx.media.app.NotificationCompat.MediaStyle
@ -92,7 +93,8 @@ class NowPlayingNotification(
} }
private fun createIntent(action: String): PendingIntent? { private fun createIntent(action: String): PendingIntent? {
val intent = Intent(action).setPackage(context.packageName) val intent = Intent(action)
.setPackage(context.packageName)
return PendingIntentCompat return PendingIntentCompat
.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT, false) .getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT, false)
@ -374,9 +376,12 @@ class NowPlayingNotification(
} }
private fun createActionReceiver() { private fun createActionReceiver() {
listOf(PREV, NEXT, REWIND, FORWARD, PLAY_PAUSE, STOP).forEach { val filter = IntentFilter().apply {
context.registerReceiver(notificationActionReceiver, IntentFilter(it)) listOf(PREV, NEXT, REWIND, FORWARD, PLAY_PAUSE, STOP).forEach {
addAction(it)
}
} }
ContextCompat.registerReceiver(context, notificationActionReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)
} }
/** /**