mirror of
https://github.com/libre-tube/LibreTube.git
synced 2025-04-29 00:10:32 +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 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
|
||||||
@ -71,23 +72,19 @@ class NowPlayingNotification(
|
|||||||
// starts a new MainActivity Intent when the player notification is clicked
|
// starts a new MainActivity Intent when the player notification is clicked
|
||||||
// it doesn't start a completely new MainActivity because the MainActivity's launchMode
|
// it doesn't start a completely new MainActivity because the MainActivity's launchMode
|
||||||
// is set to "singleTop" in the AndroidManifest (important!!!)
|
// 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 {
|
val intent = Intent(context, MainActivity::class.java).apply {
|
||||||
if (isBackgroundPlayerNotification) {
|
if (isBackgroundPlayerNotification) {
|
||||||
putExtra(IntentData.openAudioPlayer, true)
|
putExtra(IntentData.openAudioPlayer, true)
|
||||||
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,
|
PendingIntentCompat.updateCurrentFlags
|
||||||
PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT
|
)
|
||||||
)
|
|
||||||
} 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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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(
|
activity,
|
||||||
if (!isOfflinePlayer && alternativePiPControls) {
|
R.drawable.ic_headphones,
|
||||||
getRemoteAction(
|
R.string.background_mode,
|
||||||
activity,
|
PlayerEvent.Background
|
||||||
R.drawable.ic_headphones,
|
|
||||||
R.string.background_mode,
|
|
||||||
PlayerEvent.Background
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
getRemoteAction(
|
|
||||||
activity,
|
|
||||||
R.drawable.ic_rewind,
|
|
||||||
R.string.rewind,
|
|
||||||
PlayerEvent.Rewind
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
|
|
||||||
actions.add(
|
val rewindAction = getRemoteAction(
|
||||||
getRemoteAction(
|
activity,
|
||||||
activity,
|
R.drawable.ic_rewind,
|
||||||
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
R.string.rewind,
|
||||||
R.string.pause,
|
PlayerEvent.Rewind
|
||||||
if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
|
|
||||||
actions.add(
|
val playPauseAction = getRemoteAction(
|
||||||
if (!isOfflinePlayer && alternativePiPControls) {
|
activity,
|
||||||
getRemoteAction(
|
if (isPlaying) R.drawable.ic_pause else R.drawable.ic_play,
|
||||||
activity,
|
R.string.pause,
|
||||||
R.drawable.ic_next,
|
if (isPlaying) PlayerEvent.Pause else PlayerEvent.Play
|
||||||
R.string.play_next,
|
|
||||||
PlayerEvent.Next
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
getRemoteAction(
|
|
||||||
activity,
|
|
||||||
R.drawable.ic_forward,
|
|
||||||
R.string.forward,
|
|
||||||
PlayerEvent.Forward
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
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…
x
Reference in New Issue
Block a user