[Android] Add custom action constants

Robert Stone git at videolan.org
Thu Feb 3 09:01:34 UTC 2022


vlc-android | branch: master | Robert Stone <rhstone at gmail.com> | Fri Jan 14 22:47:55 2022 -0800| [487cbdb3c60b6c165288a76098607a11c8e44243] | committer: Nicolas Pomepuy

Add custom action constants

> https://code.videolan.org/videolan/vlc-android/commit/487cbdb3c60b6c165288a76098607a11c8e44243
---

 .../src/main/java/org/videolan/resources/Constants.kt        |  9 +++++++++
 .../vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt | 12 ++++++------
 .../vlc-android/src/org/videolan/vlc/PlaybackService.kt      | 12 ++++++------
 3 files changed, 21 insertions(+), 12 deletions(-)

diff --git a/application/resources/src/main/java/org/videolan/resources/Constants.kt b/application/resources/src/main/java/org/videolan/resources/Constants.kt
index c26bee1df..33ea0affb 100644
--- a/application/resources/src/main/java/org/videolan/resources/Constants.kt
+++ b/application/resources/src/main/java/org/videolan/resources/Constants.kt
@@ -56,6 +56,14 @@ val ACTION_REMOTE_GENERIC = "remote.".buildPkgString()
 @JvmField val ACTION_REMOTE_PLAYPAUSE = "${ACTION_REMOTE_GENERIC}PlayPause"
 @JvmField val ACTION_REMOTE_PLAY = "${ACTION_REMOTE_GENERIC}Play"
 @JvmField val ACTION_REMOTE_BACKWARD = "${ACTION_REMOTE_GENERIC}Backward"
+ at JvmField val CUSTOM_ACTION = "CustomAction".buildPkgString()
+ at JvmField val CUSTOM_ACTION_BOOKMARK = "bookmark".buildPkgString()
+ at JvmField val CUSTOM_ACTION_FAST_FORWARD = "fast_forward".buildPkgString()
+ at JvmField val CUSTOM_ACTION_SHUFFLE = "shuffle".buildPkgString()
+ at JvmField val CUSTOM_ACTION_SPEED = "speed".buildPkgString()
+ at JvmField val CUSTOM_ACTION_REPEAT = "repeat".buildPkgString()
+ at JvmField val CUSTOM_ACTION_REWIND = "rewind".buildPkgString()
+ at JvmField val EXTRA_CUSTOM_ACTION_ID = "EXTRA_CUSTOM_ACTION_ID".buildPkgString()
 const val ACTION_CAR_MODE_EXIT = "android.app.action.EXIT_CAR_MODE"
 const val PLAYLIST_TYPE_AUDIO = 0
 const val PLAYLIST_TYPE_VIDEO = 1
@@ -150,6 +158,7 @@ const val CATEGORY_VIDEOS = 25L
 const val CATEGORY_NOW_PLAYING_PIP = 26L
 
 const val CATEGORY = "category"
+const val DRAWABLE = "drawable"
 const val ITEM = "item"
 const val KEY_GROUP = "key_group"
 const val KEY_FOLDER = "key_folder"
diff --git a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
index 516f96073..3e213f73c 100644
--- a/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
+++ b/application/vlc-android/src/org/videolan/vlc/MediaSessionCallback.kt
@@ -110,12 +110,12 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
 
     override fun onCustomAction(actionId: String?, extras: Bundle?) {
         when (actionId) {
-            "${BuildConfig.APP_ID}.speed" -> {
+            CUSTOM_ACTION_SPEED -> {
                 val steps = listOf(0.50f, 0.80f, 1.00f, 1.10f, 1.20f, 1.50f, 2.00f)
                 val index = 1 + steps.indexOf(steps.minByOrNull { abs(playbackService.rate - it) })
                 playbackService.setRate(steps[index % steps.size], false)
             }
-            "${BuildConfig.APP_ID}.bookmark" -> {
+            CUSTOM_ACTION_BOOKMARK -> {
                 playbackService.lifecycleScope.launch {
                     val context = playbackService.applicationContext
                     playbackService.currentMediaWrapper?.let {
@@ -126,10 +126,10 @@ internal class MediaSessionCallback(private val playbackService: PlaybackService
                     }
                 }
             }
-            "${BuildConfig.APP_ID}.rewind" -> onRewind()
-            "${BuildConfig.APP_ID}.fast_forward" -> onFastForward()
-            "${BuildConfig.APP_ID}.shuffle" -> if (playbackService.canShuffle()) playbackService.shuffle()
-            "${BuildConfig.APP_ID}.repeat" -> playbackService.repeatType = when (playbackService.repeatType) {
+            CUSTOM_ACTION_REWIND -> onRewind()
+            CUSTOM_ACTION_FAST_FORWARD -> onFastForward()
+            CUSTOM_ACTION_SHUFFLE -> if (playbackService.canShuffle()) playbackService.shuffle()
+            CUSTOM_ACTION_REPEAT -> playbackService.repeatType = when (playbackService.repeatType) {
                 PlaybackStateCompat.REPEAT_MODE_NONE -> PlaybackStateCompat.REPEAT_MODE_ALL
                 PlaybackStateCompat.REPEAT_MODE_ALL -> PlaybackStateCompat.REPEAT_MODE_ONE
                 PlaybackStateCompat.REPEAT_MODE_ONE -> PlaybackStateCompat.REPEAT_MODE_NONE
diff --git a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
index 54df829cc..653288358 100644
--- a/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
+++ b/application/vlc-android/src/org/videolan/vlc/PlaybackService.kt
@@ -1055,7 +1055,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
         if (podcastMode) {
             addCustomSeekActions(pscb)
             addCustomSpeedActions(pscb)
-            pscb.addCustomAction("${BuildConfig.APP_ID}.bookmark", getString(R.string.add_bookmark), R.drawable.ic_bookmark_add)
+            pscb.addCustomAction(CUSTOM_ACTION_BOOKMARK, getString(R.string.add_bookmark), R.drawable.ic_bookmark_add)
         } else {
             if (playlistManager.canRepeat())
                 actions = actions or PlaybackStateCompat.ACTION_SET_REPEAT_MODE
@@ -1066,13 +1066,13 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 isShuffling -> R.drawable.ic_auto_shuffle_enabled
                 else -> R.drawable.ic_auto_shuffle_disabled
             }
-            pscb.addCustomAction("${BuildConfig.APP_ID}.shuffle", getString(R.string.shuffle_title), shuffleResId)
+            pscb.addCustomAction(CUSTOM_ACTION_SHUFFLE, getString(R.string.shuffle_title), shuffleResId)
             val repeatResId = when (repeatType) {
                 PlaybackStateCompat.REPEAT_MODE_ALL -> R.drawable.ic_auto_repeat_pressed
                 PlaybackStateCompat.REPEAT_MODE_ONE -> R.drawable.ic_auto_repeat_one_pressed
                 else -> R.drawable.ic_auto_repeat_normal
             }
-            pscb.addCustomAction("${BuildConfig.APP_ID}.repeat", getString(R.string.repeat_title), repeatResId)
+            pscb.addCustomAction(CUSTOM_ACTION_REPEAT, getString(R.string.repeat_title), repeatResId)
             addCustomSpeedActions(pscb, settings.getBoolean("enable_android_auto_speed_buttons", false))
             addCustomSeekActions(pscb, settings.getBoolean("enable_android_auto_seek_buttons", false))
         }
@@ -1101,11 +1101,11 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
 
     private fun addCustomSeekActions(pscb: PlaybackStateCompat.Builder, showSeekActions: Boolean = true) {
         if (!showSeekActions) return
-        pscb.addCustomAction(PlaybackStateCompat.CustomAction.Builder("${BuildConfig.APP_ID}.rewind",
+        pscb.addCustomAction(PlaybackStateCompat.CustomAction.Builder(CUSTOM_ACTION_REWIND,
                 getString(R.string.playback_rewind), R.drawable.ic_auto_rewind_10)
                 .setExtras(Bundle().apply { putBoolean(WEARABLE_SHOW_CUSTOM_ACTION, true) })
                 .build())
-        pscb.addCustomAction(PlaybackStateCompat.CustomAction.Builder("${BuildConfig.APP_ID}.fast_forward",
+        pscb.addCustomAction(PlaybackStateCompat.CustomAction.Builder(CUSTOM_ACTION_FAST_FORWARD,
                 getString(R.string.playback_forward), R.drawable.ic_auto_forward_10)
                 .setExtras(Bundle().apply { putBoolean(WEARABLE_SHOW_CUSTOM_ACTION, true) })
                 .build())
@@ -1123,7 +1123,7 @@ class PlaybackService : MediaBrowserServiceCompat(), LifecycleOwner {
                 2.00f to R.drawable.ic_auto_speed_2_00
             )
             val speedResId = speedIcons[speedIcons.keys.minByOrNull { abs(speed - it) }] ?: R.drawable.ic_auto_speed
-            pscb.addCustomAction("${BuildConfig.APP_ID}.speed", getString(R.string.playback_speed), speedResId)
+            pscb.addCustomAction(CUSTOM_ACTION_SPEED, getString(R.string.playback_speed), speedResId)
         }
     }
 



More information about the Android mailing list