Skip to content
Snippets Groups Projects
Commit ee17b6b8 authored by AlexSviridov's avatar AlexSviridov Committed by Nicolas Pomepuy
Browse files

Copy track title to clipboard by long click

videolan/vlc-android#1211
parent 0c79b8cb
No related branches found
No related tags found
1 merge request!525Copy track title to clipboard by long click
Pipeline #15510 passed with stage
in 5 minutes and 10 seconds
......@@ -74,6 +74,7 @@
<item quantity="one">1 song</item>
<item quantity="other">%d songs</item>
</plurals>
<string name="track_info_copied_to_clipboard">Track info copied to clipboard</string>
<string name="artists">Artists</string>
<string name="albums">Albums</string>
......
......@@ -21,9 +21,7 @@
package org.videolan.vlc.gui.audio
import android.Manifest
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.*
import android.os.Bundle
import android.os.Handler
import android.support.v4.media.session.PlaybackStateCompat
......@@ -582,6 +580,21 @@ class AudioPlayer : Fragment(), PlaylistAdapter.IPlayer, TextWatcher, IAudioPlay
activity.slideUpOrDownAudioPlayer()
}
override fun onTouchLongClick() {
val trackInfo = playlistModel.title ?: return
val ctx = context ?: return
val data = ClipData.newPlainText(ctx.getString(R.string.app_name), trackInfo)
(ctx.getSystemService(Context.CLIPBOARD_SERVICE) as ClipboardManager)
.setPrimaryClip(data)
Snackbar.make(
binding.root,
R.string.track_info_copied_to_clipboard,
Snackbar.LENGTH_LONG
).show()
}
override fun onTouchDown() {}
override fun onTouchUp() {}
......
......@@ -68,6 +68,10 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
audioMediaSwitcherListener.onTouchClick()
}
override fun onTouchLongClick() {
audioMediaSwitcherListener.onTouchLongClick()
}
override fun onBackSwitched() {}
}
......@@ -121,6 +125,8 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
fun onTouchClick()
fun onTouchLongClick()
companion object {
const val PREVIOUS_MEDIA = 1
const val CURRENT_MEDIA = 2
......@@ -134,5 +140,6 @@ abstract class AudioMediaSwitcher(context: Context, attrs: AttributeSet) : Fling
override fun onTouchDown() {}
override fun onTouchUp() {}
override fun onTouchClick() {}
override fun onTouchLongClick() = Unit
}
}
......@@ -45,6 +45,8 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
abstract val viewSwitchListener: ViewSwitchListener
private var lastActionDownMillis = 0L
init {
layoutParams = LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.MATCH_PARENT)
......@@ -139,6 +141,7 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
MotionEvent.ACTION_DOWN -> {
if (!scroller.isFinished) scroller.abortAnimation()
lastX = x
lastActionDownMillis = event.eventTime
viewSwitchListener.onTouchDown()
}
MotionEvent.ACTION_MOVE -> {
......@@ -174,7 +177,16 @@ abstract class FlingViewGroup(context: Context, attrs: AttributeSet) : ViewGroup
this.velocityTracker = null
viewSwitchListener.onTouchUp()
if (dx * dx + dy * dy < touchSlop * touchSlop) viewSwitchListener.onTouchClick()
if (dx * dx + dy * dy < touchSlop * touchSlop) {
val isLongClick = lastActionDownMillis.let {
lastActionDownMillis = 0L
it > 0L && event.eventTime - it > ViewConfiguration.getLongPressTimeout()
}
if (isLongClick)
viewSwitchListener.onTouchLongClick()
else
viewSwitchListener.onTouchClick()
}
}
}
return true
......@@ -234,6 +246,8 @@ interface ViewSwitchListener {
fun onTouchClick()
fun onTouchLongClick()
fun onBackSwitched()
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment