[Android] Add a share line to the audio advanced options

Nicolas Pomepuy git at videolan.org
Tue Sep 10 11:10:57 UTC 2024


vlc-android | branch: master | Nicolas Pomepuy <nicolas at videolabs.io> | Tue Sep 10 11:03:49 2024 +0200| [2bc098d2f95ba30ea116410d784de64514f3c3e9] | committer: Duncan McNamara

Add a share line to the audio advanced options

Fixes #3082

> https://code.videolan.org/videolan/vlc-android/commit/2bc098d2f95ba30ea116410d784de64514f3c3e9
---

 .../resources/src/main/res/values/strings.xml      |  2 ++
 .../vlc/gui/helpers/PlayerOptionsDelegate.kt       | 27 ++++++++++++++++++++++
 .../src/org/videolan/vlc/util/Kextensions.kt       |  2 +-
 3 files changed, 30 insertions(+), 1 deletion(-)

diff --git a/application/resources/src/main/res/values/strings.xml b/application/resources/src/main/res/values/strings.xml
index 650a8ab06f..20c1fcc957 100644
--- a/application/resources/src/main/res/values/strings.xml
+++ b/application/resources/src/main/res/values/strings.xml
@@ -889,6 +889,8 @@
     <string name="invalid_file">Invalid file. Cannot be shared.</string>
     <string name="share_file">Share %s</string>
     <string name="share_message">Here is %s</string>
+    <string name="share_track_info">Share the track info</string>
+    <string name="share_track">Currently listening to %s</string>
     <string name="find_metadata">Find metadata</string>
     <string name="moviepedia_hint">Search metadata</string>
     <string name="moviepedia_result">Video results</string>
diff --git a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
index 1e0db46701..448febd54e 100644
--- a/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
+++ b/application/vlc-android/src/org/videolan/vlc/gui/helpers/PlayerOptionsDelegate.kt
@@ -42,8 +42,10 @@ import org.videolan.vlc.gui.helpers.hf.PinCodeDelegate
 import org.videolan.vlc.gui.helpers.hf.checkPIN
 import org.videolan.vlc.gui.video.VideoPlayerActivity
 import org.videolan.vlc.media.PlayerController
+import org.videolan.vlc.util.TextUtils
 import org.videolan.vlc.util.getScreenHeight
 import org.videolan.vlc.util.isTalkbackIsEnabled
+import org.videolan.vlc.util.share
 
 private const val ACTION_AUDIO_DELAY = 2
 private const val ACTION_SPU_DELAY = 3
@@ -71,6 +73,7 @@ private const val ID_VIDEO_CONTROL_SETTING = 19L
 private const val ID_AUDIO_CONTROL_SETTING = 20L
 private const val ID_SAFE_MODE_LOCK = 21L
 private const val ID_SAFE_MODE_UNLOCK = 22L
+private const val ID_SHARE = 23L
 @SuppressLint("ShowToast")
 class PlayerOptionsDelegate(val activity: FragmentActivity, val service: PlaybackService, private val showABReapeat:Boolean = true)  {
 
@@ -123,6 +126,8 @@ class PlayerOptionsDelegate(val activity: FragmentActivity, val service: Playbac
             if (PinCodeDelegate.pinUnlocked.value == true) options.add(PlayerOption(ID_SAFE_MODE_LOCK, R.drawable.ic_pin_lock, res.getString(R.string.lock_with_pin)))
             if (Settings.safeMode && PinCodeDelegate.pinUnlocked.value == false) options.add(PlayerOption(ID_SAFE_MODE_UNLOCK, R.drawable.ic_pin_unlock, res.getString(R.string.unlock_with_pin)))
             options.add(PlayerOption(ID_VIDEO_CONTROL_SETTING, R.drawable.ic_video_controls, res.getString(R.string.control_setting)))
+        } else {
+            options.add(PlayerOption(ID_SHARE, R.drawable.ic_share, res.getString(R.string.share_track_info)))
         }
 
         if (!Settings.showTvUi) {
@@ -252,6 +257,28 @@ class PlayerOptionsDelegate(val activity: FragmentActivity, val service: Playbac
                 val videoControlsSettingsDialog = VideoControlsSettingsDialog()
                 videoControlsSettingsDialog.show(activity.supportFragmentManager, "fragment_video_controls_settings")
             }
+            ID_SHARE -> {
+                hide()
+                service.playlistManager.getCurrentMedia()?.let { media ->
+                    val trackInfo = buildString {
+                        var started = false
+                        if (media.title.isNotBlank()) {
+                            append(media.title)
+                            started = true
+                        }
+                        if (media.album.isNotBlank()) {
+                            if (started) append(" ${TextUtils.separator} ")
+                            started = true
+                            append(media.album)
+                        }
+                        if (media.artist.isNotBlank()) {
+                            if (started) append(" ${TextUtils.separator} ")
+                            append(media.artist)
+                        }
+                    }
+                    activity.share("", activity.getString(R.string.share_track, trackInfo))
+                }
+            }
             ID_AUDIO_CONTROL_SETTING -> {
                 hide()
                 val audioControlsSettingsDialog = AudioControlsSettingsDialog()
diff --git a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
index 601dfa9255..7dd6824396 100644
--- a/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
+++ b/application/vlc-android/src/org/videolan/vlc/util/Kextensions.kt
@@ -107,7 +107,7 @@ fun FragmentActivity.share(file: File) {
 fun FragmentActivity.share(title:String, content: String) {
     val intentShareFile = Intent(Intent.ACTION_SEND)
     if (isStarted()) {
-        intentShareFile.type = "*/*"
+        intentShareFile.type = "text/plain"
         intentShareFile.putExtra(Intent.EXTRA_SUBJECT, title)
         intentShareFile.putExtra(Intent.EXTRA_TEXT, content)
         startActivity(Intent.createChooser(intentShareFile, getString(R.string.share_file,title)))



More information about the Android mailing list