[Android] Streams: copy mrl to clipboard ctx option

Geoffrey Métais git at videolan.org
Tue Sep 24 17:07:55 CEST 2019


vlc-android | branch: 3.2.x | Geoffrey Métais <geoffrey.metais at gmail.com> | Sat Feb  2 15:04:18 2019 +0000| [47a059389e9c3fe8208701f8e5ca9ad30dee15ae] | committer: Geoffrey Métais

Streams: copy mrl to clipboard ctx option

(cherry picked from commit 3ee34559ed109bb76df23c478e3c01bfb027ecb5)

> https://code.videolan.org/videolan/vlc-android/commit/47a059389e9c3fe8208701f8e5ca9ad30dee15ae
---

 .../main/java/org/videolan/tools/KotlinExtensions.kt    |  7 +++++++
 .../src/org/videolan/vlc/gui/dialogs/ContextSheet.kt    |  1 +
 .../org/videolan/vlc/gui/network/MRLPanelFragment.kt    | 17 ++++++++---------
 vlc-android/src/org/videolan/vlc/util/Constants.kt      |  1 +
 4 files changed, 17 insertions(+), 9 deletions(-)

diff --git a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
index 45129aa5c..92a44f2c8 100644
--- a/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
+++ b/tools/src/main/java/org/videolan/tools/KotlinExtensions.kt
@@ -1,5 +1,7 @@
 package org.videolan.tools
 
+import android.content.ClipData
+import android.content.ClipboardManager
 import android.content.Context
 import android.content.res.Resources
 import android.util.TypedValue
@@ -71,3 +73,8 @@ fun Context.getColorFromAttr(
     theme.resolveAttribute(attrColor, typedValue, resolveRefs)
     return typedValue.data
 }
+
+fun Context.copy(label: String, text: String) {
+    val clipboard = applicationContext.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager
+    clipboard.primaryClip = ClipData.newPlainText(label, text)
+}
diff --git a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
index b75ad9d49..d173a4bfe 100644
--- a/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/dialogs/ContextSheet.kt
@@ -107,6 +107,7 @@ class ContextSheet : VLCBottomSheetDialogFragment() {
         if (flags and CTX_REMOVE_FROM_PLAYLIST != 0) add(Simple(CTX_REMOVE_FROM_PLAYLIST, getString(R.string.remove), R.drawable.ic_ctx_remove_from_playlist_normal))
         if (flags and CTX_STOP_AFTER_THIS != 0) add(Simple(CTX_STOP_AFTER_THIS, getString(R.string.stop_after_this), R.drawable.ic_ctx_stop_after_this))
         if (flags and CTX_RENAME != 0) add(Simple(CTX_RENAME, getString(R.string.rename), R.drawable.ic_ctx_edit_normal))
+        if (flags and CTX_COPY != 0) add(Simple(CTX_COPY, getString(R.string.copy_to_clipboard), R.drawable.ic_ctx_edit_normal))
         if (flags and CTX_DELETE != 0) add(Simple(CTX_DELETE, getString(R.string.delete), R.drawable.ic_ctx_delete_normal))
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
index 9ef67a500..e1bec1b1e 100644
--- a/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
+++ b/vlc-android/src/org/videolan/vlc/gui/network/MRLPanelFragment.kt
@@ -45,6 +45,7 @@ import kotlinx.coroutines.ObsoleteCoroutinesApi
 import kotlinx.coroutines.channels.actor
 import org.videolan.medialibrary.MLServiceLocator
 import org.videolan.medialibrary.interfaces.media.AbstractMediaWrapper
+import org.videolan.tools.copy
 import org.videolan.tools.coroutineScope
 import org.videolan.vlc.R
 import org.videolan.vlc.databinding.MrlPanelBinding
@@ -55,10 +56,7 @@ import org.videolan.vlc.gui.dialogs.showContext
 import org.videolan.vlc.gui.helpers.UiTools
 import org.videolan.vlc.gui.tv.browser.interfaces.BrowserFragmentInterface
 import org.videolan.vlc.media.MediaUtils
-import org.videolan.vlc.util.CTX_ADD_TO_PLAYLIST
-import org.videolan.vlc.util.CTX_APPEND
-import org.videolan.vlc.util.CTX_RENAME
-import org.videolan.vlc.util.Settings
+import org.videolan.vlc.util.*
 import org.videolan.vlc.viewmodels.StreamsModel
 
 const val TAG = "VLC/MrlPanelFragment"
@@ -165,12 +163,9 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
     }
 
     private fun showContext(position: Int) {
-        val flags = CTX_RENAME or CTX_APPEND or CTX_ADD_TO_PLAYLIST
+        val flags = CTX_RENAME or CTX_APPEND or CTX_ADD_TO_PLAYLIST or CTX_COPY
         val media = viewModel.dataset.value.get(position)
-        if (media == null)
-            return
-        else
-            showContext(requireActivity(), this, position, media.title, flags)
+        showContext(requireActivity(), this, position, media.title, flags)
     }
 
     override fun onCtxAction(position: Int, option: Int) {
@@ -184,6 +179,10 @@ class MRLPanelFragment : Fragment(), View.OnKeyListener, TextView.OnEditorAction
                 val media = viewModel.dataset.value[position]
                 UiTools.addToPlaylist(requireActivity(), media.tracks, SavePlaylistDialog.KEY_NEW_TRACKS)
             }
+            CTX_COPY -> {
+                val media = viewModel.dataset.value[position]
+                requireContext().copy(media.title, media.location)
+            }
         }
     }
 
diff --git a/vlc-android/src/org/videolan/vlc/util/Constants.kt b/vlc-android/src/org/videolan/vlc/util/Constants.kt
index 68a91dc31..b67cd068d 100644
--- a/vlc-android/src/org/videolan/vlc/util/Constants.kt
+++ b/vlc-android/src/org/videolan/vlc/util/Constants.kt
@@ -164,6 +164,7 @@ const val CTX_SUBS_TRACK = 1 shl 21
 const val CTX_PICK_SUBS = 1 shl 22
 const val CTX_VIDEO_TRACK = 1 shl 23
 const val CTX_DOWNLOAD_SUBTITLES_PLAYER = 1 shl 24
+const val CTX_COPY = 1 shl 25
 
 const val CTX_VIDEO_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_DOWNLOAD_SUBTITLES or CTX_INFORMATION or CTX_PLAY_ALL or CTX_PLAY_AS_AUDIO or CTX_ADD_TO_PLAYLIST
 const val CTX_TRACK_FLAGS = CTX_APPEND or CTX_PLAY_NEXT or CTX_DELETE or CTX_INFORMATION or CTX_PLAY_ALL or CTX_ADD_TO_PLAYLIST or CTX_SET_RINGTONE



More information about the Android mailing list