mirror of
https://github.com/libre-tube/LibreTube.git
synced 2024-12-14 14:20:30 +05:30
Cleanup the PiP window controls
This commit is contained in:
parent
a52bd6247c
commit
12d4ee9e8e
@ -17,6 +17,7 @@ import android.support.v4.media.session.MediaSessionCompat
|
||||
import coil.request.ImageRequest
|
||||
import com.github.libretube.R
|
||||
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.IntentData
|
||||
import com.github.libretube.constants.PLAYER_NOTIFICATION_ID
|
||||
@ -71,23 +72,19 @@ class NowPlayingNotification(
|
||||
// starts a new MainActivity Intent when the player notification is clicked
|
||||
// it doesn't start a completely new MainActivity because the MainActivity's launchMode
|
||||
// is set to "singleTop" in the AndroidManifest (important!!!)
|
||||
// that's the only way to launch back into the previous activity (e.g. the player view
|
||||
// that's the only way to launch back into the previous activity (e.g. the player view
|
||||
val intent = Intent(context, MainActivity::class.java).apply {
|
||||
if (isBackgroundPlayerNotification) {
|
||||
putExtra(IntentData.openAudioPlayer, true)
|
||||
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
|
||||
}
|
||||
}
|
||||
return if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
||||
PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
intent,
|
||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
||||
)
|
||||
} else {
|
||||
PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT)
|
||||
}
|
||||
return PendingIntent.getActivity(
|
||||
context,
|
||||
0,
|
||||
intent,
|
||||
PendingIntentCompat.updateCurrentFlags
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -120,7 +117,11 @@ class NowPlayingNotification(
|
||||
// returns the bitmap on Android 13+, for everything below scaled down to a square
|
||||
return if (
|
||||
Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU
|
||||
) ImageHelper.getSquareBitmap(bitmap) else bitmap
|
||||
) {
|
||||
ImageHelper.getSquareBitmap(bitmap)
|
||||
} else {
|
||||
bitmap
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -397,52 +397,47 @@ object PlayerHelper {
|
||||
*/
|
||||
@RequiresApi(Build.VERSION_CODES.O)
|
||||
fun getPiPModeActions(activity: Activity, isPlaying: Boolean, isOfflinePlayer: Boolean = false): ArrayList<RemoteAction> {
|
||||
val actions: ArrayList<RemoteAction> = ArrayList()
|
||||
actions.add(
|
||||
if (!isOfflinePlayer && alternativePiPControls) {
|
||||
getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_headphones,
|
||||
R.string.background_mode,
|
||||
PlayerEvent.Background
|
||||
)
|
||||
} else {
|
||||
getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_rewind,
|
||||
R.string.rewind,
|
||||
PlayerEvent.Rewind
|
||||
)
|
||||
}
|
||||
val audioModeAction = getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_headphones,
|
||||
R.string.background_mode,
|
||||
PlayerEvent.Background
|
||||
)
|
||||
|
||||
actions.add(
|
||||
getRemoteAction(
|
||||
activity,
|
||||
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
||||
R.string.pause,
|
||||
if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play
|
||||
)
|
||||
val rewindAction = getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_rewind,
|
||||
R.string.rewind,
|
||||
PlayerEvent.Rewind
|
||||
)
|
||||
|
||||
actions.add(
|
||||
if (!isOfflinePlayer && alternativePiPControls) {
|
||||
getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_next,
|
||||
R.string.play_next,
|
||||
PlayerEvent.Next
|
||||
)
|
||||
} else {
|
||||
getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_forward,
|
||||
R.string.forward,
|
||||
PlayerEvent.Forward
|
||||
)
|
||||
}
|
||||
val playPauseAction = getRemoteAction(
|
||||
activity,
|
||||
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
||||
R.string.pause,
|
||||
if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play
|
||||
)
|
||||
return actions
|
||||
|
||||
val skipNextAction = getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_next,
|
||||
R.string.play_next,
|
||||
PlayerEvent.Next
|
||||
)
|
||||
|
||||
val forwardAction = getRemoteAction(
|
||||
activity,
|
||||
R.drawable.ic_forward,
|
||||
R.string.forward,
|
||||
PlayerEvent.Forward
|
||||
)
|
||||
return if (
|
||||
!isOfflinePlayer && alternativePiPControls
|
||||
) {
|
||||
arrayListOf(audioModeAction, playPauseAction, skipNextAction)
|
||||
} else {
|
||||
arrayListOf(rewindAction, playPauseAction, forwardAction)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user