Cleanup the PiP window controls

This commit is contained in:
Bnyro 2023-01-15 13:26:16 +01:00
parent a52bd6247c
commit 12d4ee9e8e
2 changed files with 49 additions and 53 deletions

View File

@ -17,6 +17,7 @@ import android.support.v4.media.session.MediaSessionCompat
import coil.request.ImageRequest import coil.request.ImageRequest
import com.github.libretube.R import com.github.libretube.R
import com.github.libretube.api.obj.Streams import com.github.libretube.api.obj.Streams
import com.github.libretube.compat.PendingIntentCompat
import com.github.libretube.constants.BACKGROUND_CHANNEL_ID import com.github.libretube.constants.BACKGROUND_CHANNEL_ID
import com.github.libretube.constants.IntentData import com.github.libretube.constants.IntentData
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
@ -78,16 +79,12 @@ class NowPlayingNotification(
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP) addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
} }
} }
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { return PendingIntent.getActivity(
PendingIntent.getActivity(
context, context,
0, 0,
intent, intent,
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT PendingIntentCompat.updateCurrentFlags
) )
} else {
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
}
} }
/** /**
@ -120,7 +117,11 @@ class NowPlayingNotification(
// returns the bitmap on Android 13+, for everything below scaled down to a square // returns the bitmap on Android 13+, for everything below scaled down to a square
return if ( return if (
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
) ImageHelper.getSquareBitmap(bitmap) else bitmap ) {
ImageHelper.getSquareBitmap(bitmap)
} else {
bitmap
}
} }
} }

View File

@ -397,52 +397,47 @@ object PlayerHelper {
*/ */
@RequiresApi(Build.VERSION_CODES.O) @RequiresApi(Build.VERSION_CODES.O)
fun getPiPModeActions(activity: Activity, isPlaying: Boolean, isOfflinePlayer: Boolean = false): ArrayList<RemoteAction> { fun getPiPModeActions(activity: Activity, isPlaying: Boolean, isOfflinePlayer: Boolean = false): ArrayList<RemoteAction> {
val actions: ArrayList<RemoteAction> = ArrayList() val audioModeAction = getRemoteAction(
actions.add(
if (!isOfflinePlayer && alternativePiPControls) {
getRemoteAction(
activity, activity,
R.drawable.ic_headphones, R.drawable.ic_headphones,
R.string.background_mode, R.string.background_mode,
PlayerEvent.Background PlayerEvent.Background
) )
} else {
getRemoteAction( val rewindAction = getRemoteAction(
activity, activity,
R.drawable.ic_rewind, R.drawable.ic_rewind,
R.string.rewind, R.string.rewind,
PlayerEvent.Rewind PlayerEvent.Rewind
) )
}
)
actions.add( val playPauseAction = getRemoteAction(
getRemoteAction(
activity, activity,
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play, if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
R.string.pause, R.string.pause,
if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play
) )
)
actions.add( val skipNextAction = getRemoteAction(
if (!isOfflinePlayer && alternativePiPControls) {
getRemoteAction(
activity, activity,
R.drawable.ic_next, R.drawable.ic_next,
R.string.play_next, R.string.play_next,
PlayerEvent.Next PlayerEvent.Next
) )
} else {
getRemoteAction( val forwardAction = getRemoteAction(
activity, activity,
R.drawable.ic_forward, R.drawable.ic_forward,
R.string.forward, R.string.forward,
PlayerEvent.Forward PlayerEvent.Forward
) )
return if (
!isOfflinePlayer && alternativePiPControls
) {
arrayListOf(audioModeAction, playPauseAction, skipNextAction)
} else {
arrayListOf(rewindAction, playPauseAction, forwardAction)
} }
)
return actions
} }
/** /**