mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-13 22:00:30 +05:30
chore: bump target sdk to 34 and fix pip issues
This commit is contained in:
parent
f0a779b4d1
commit
bf0d6bde2c
@ -14,7 +14,7 @@ android {
|
||||
defaultConfig {
|
||||
applicationId = "com.github.libretube"
|
||||
minSdk = 21
|
||||
targetSdk = 33
|
||||
targetSdk = 34
|
||||
versionCode = 47
|
||||
versionName = "0.21.1"
|
||||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
|
||||
|
@ -221,10 +221,11 @@ object PlayerHelper {
|
||||
false
|
||||
)
|
||||
|
||||
private val behaviorWhenMinimized = PreferenceHelper.getString(
|
||||
PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED,
|
||||
"pip"
|
||||
)
|
||||
private val behaviorWhenMinimized
|
||||
get() = PreferenceHelper.getString(
|
||||
PreferenceKeys.BEHAVIOR_WHEN_MINIMIZED,
|
||||
"pip"
|
||||
)
|
||||
|
||||
val pipEnabled: Boolean
|
||||
get() = behaviorWhenMinimized == "pip"
|
||||
@ -386,7 +387,9 @@ object PlayerHelper {
|
||||
}
|
||||
|
||||
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)!!
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,7 @@ import android.os.IBinder
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.isVisible
|
||||
@ -193,10 +194,12 @@ class DownloadsFragment : DynamicLayoutManagerFragment() {
|
||||
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
val filter = IntentFilter()
|
||||
filter.addAction(DownloadService.ACTION_SERVICE_STARTED)
|
||||
filter.addAction(DownloadService.ACTION_SERVICE_STOPPED)
|
||||
context?.registerReceiver(downloadReceiver, filter)
|
||||
|
||||
val filter = IntentFilter().apply {
|
||||
addAction(DownloadService.ACTION_SERVICE_STARTED)
|
||||
addAction(DownloadService.ACTION_SERVICE_STOPPED)
|
||||
}
|
||||
ContextCompat.registerReceiver(requireContext(), downloadReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)
|
||||
}
|
||||
|
||||
fun bindDownloadService(ids: IntArray? = null) {
|
||||
|
@ -23,6 +23,7 @@ import android.view.ViewGroup.LayoutParams
|
||||
import android.widget.Toast
|
||||
import androidx.constraintlayout.motion.widget.MotionLayout
|
||||
import androidx.constraintlayout.motion.widget.TransitionAdapter
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.toDrawable
|
||||
import androidx.core.net.toUri
|
||||
@ -371,9 +372,11 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
playerLayoutOrientation = resources.configuration.orientation
|
||||
|
||||
// broadcast receiver for PiP actions
|
||||
context?.registerReceiver(
|
||||
ContextCompat.registerReceiver(
|
||||
requireContext(),
|
||||
broadcastReceiver,
|
||||
IntentFilter(PlayerHelper.getIntentAction(requireContext()))
|
||||
IntentFilter(PlayerHelper.getIntentAction(requireContext())),
|
||||
ContextCompat.RECEIVER_NOT_EXPORTED
|
||||
)
|
||||
|
||||
fullscreenResolution = PlayerHelper.getDefaultResolution(requireContext(), true)
|
||||
@ -595,6 +598,8 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
playOnBackground()
|
||||
}
|
||||
|
||||
binding.relPlayerPip.isVisible = PictureInPictureCompat.isPictureInPictureAvailable(requireContext())
|
||||
|
||||
binding.relPlayerPip.setOnClickListener {
|
||||
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
|
||||
}
|
||||
@ -1586,11 +1591,9 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
}
|
||||
|
||||
fun onUserLeaveHint() {
|
||||
if (PlayerHelper.pipEnabled && shouldStartPiP()) {
|
||||
if (shouldStartPiP()) {
|
||||
PictureInPictureCompat.enterPictureInPictureMode(requireActivity(), pipParams)
|
||||
return
|
||||
}
|
||||
if (PlayerHelper.pauseOnQuit) {
|
||||
} else if (PlayerHelper.pauseOnQuit) {
|
||||
exoPlayer.pause()
|
||||
}
|
||||
}
|
||||
@ -1625,14 +1628,13 @@ class PlayerFragment : Fragment(), OnlinePlayerOptions {
|
||||
/**
|
||||
* Detect whether PiP is supported and enabled
|
||||
*/
|
||||
private fun usePiP(): Boolean {
|
||||
private fun shouldUsePip(): Boolean {
|
||||
return PictureInPictureCompat.isPictureInPictureAvailable(requireContext()) && PlayerHelper.pipEnabled
|
||||
}
|
||||
|
||||
private fun shouldStartPiP(): Boolean {
|
||||
return usePiP() && exoPlayer.isPlaying && !BackgroundHelper.isBackgroundServiceRunning(
|
||||
requireContext()
|
||||
)
|
||||
return shouldUsePip() && exoPlayer.isPlaying &&
|
||||
!BackgroundHelper.isBackgroundServiceRunning(requireContext())
|
||||
}
|
||||
|
||||
private fun killPlayerFragment() {
|
||||
|
@ -14,6 +14,7 @@ import android.support.v4.media.session.PlaybackStateCompat
|
||||
import androidx.annotation.DrawableRes
|
||||
import androidx.core.app.NotificationCompat
|
||||
import androidx.core.app.PendingIntentCompat
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.content.getSystemService
|
||||
import androidx.core.graphics.drawable.toBitmap
|
||||
import androidx.media.app.NotificationCompat.MediaStyle
|
||||
@ -92,7 +93,8 @@ class NowPlayingNotification(
|
||||
}
|
||||
|
||||
private fun createIntent(action: String): PendingIntent? {
|
||||
val intent = Intent(action).setPackage(context.packageName)
|
||||
val intent = Intent(action)
|
||||
.setPackage(context.packageName)
|
||||
|
||||
return PendingIntentCompat
|
||||
.getBroadcast(context, 1, intent, PendingIntent.FLAG_CANCEL_CURRENT, false)
|
||||
@ -374,9 +376,12 @@ class NowPlayingNotification(
|
||||
}
|
||||
|
||||
private fun createActionReceiver() {
|
||||
listOf(PREV, NEXT, REWIND, FORWARD, PLAY_PAUSE, STOP).forEach {
|
||||
context.registerReceiver(notificationActionReceiver, IntentFilter(it))
|
||||
val filter = IntentFilter().apply {
|
||||
listOf(PREV, NEXT, REWIND, FORWARD, PLAY_PAUSE, STOP).forEach {
|
||||
addAction(it)
|
||||
}
|
||||
}
|
||||
ContextCompat.registerReceiver(context, notificationActionReceiver, filter, ContextCompat.RECEIVER_NOT_EXPORTED)
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user