Commit 3ee34559 authored by Geoffrey Métais's avatar Geoffrey Métais
Browse files

Streams: copy mrl to clipboard ctx option

parent be9e2e5c
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)
}
......@@ -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))
}
......
......@@ -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)
}
}
}
......
......@@ -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
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment