mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-26 09:47:43 +00:00
Re-introduce long press
This commit is contained in:
parent
834ac1106b
commit
61588332a6
@ -2,6 +2,8 @@ package org.thoughtcrime.securesms.conversation.v2.messages
|
|||||||
|
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
|
import android.os.Handler
|
||||||
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.*
|
import android.view.*
|
||||||
@ -23,9 +25,13 @@ import kotlin.math.sqrt
|
|||||||
class VisibleMessageView : LinearLayout {
|
class VisibleMessageView : LinearLayout {
|
||||||
private var dx = 0.0f
|
private var dx = 0.0f
|
||||||
private var previousTranslationX = 0.0f
|
private var previousTranslationX = 0.0f
|
||||||
|
private val gestureHandler = Handler(Looper.getMainLooper())
|
||||||
|
private var longPressCallback: Runnable? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val swipeToReplyThreshold = 100.0f // dp
|
const val swipeToReplyThreshold = 90.0f // dp
|
||||||
|
const val longPressMovementTreshold = 10.0f // dp
|
||||||
|
const val longPressDurationThreshold = 250.0f // ms
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
@ -144,10 +150,25 @@ class VisibleMessageView : LinearLayout {
|
|||||||
|
|
||||||
private fun onDown(event: MotionEvent) {
|
private fun onDown(event: MotionEvent) {
|
||||||
dx = x - event.rawX
|
dx = x - event.rawX
|
||||||
|
val oldLongPressCallback = longPressCallback
|
||||||
|
if (oldLongPressCallback != null) {
|
||||||
|
gestureHandler.removeCallbacks(oldLongPressCallback)
|
||||||
|
}
|
||||||
|
val longPressCallback = Runnable { onLongPress() }
|
||||||
|
this.longPressCallback = longPressCallback
|
||||||
|
gestureHandler.postDelayed(longPressCallback, VisibleMessageView.longPressDurationThreshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMove(event: MotionEvent) {
|
private fun onMove(event: MotionEvent) {
|
||||||
val translationX = toDp(event.rawX + dx, context.resources)
|
val translationX = toDp(event.rawX + dx, context.resources)
|
||||||
|
if (abs(translationX) < VisibleMessageView.longPressMovementTreshold) {
|
||||||
|
return
|
||||||
|
} else {
|
||||||
|
val longPressCallback = longPressCallback
|
||||||
|
if (longPressCallback != null) {
|
||||||
|
gestureHandler.removeCallbacks(longPressCallback)
|
||||||
|
}
|
||||||
|
}
|
||||||
// The idea here is to asymptotically approach a maximum drag distance
|
// The idea here is to asymptotically approach a maximum drag distance
|
||||||
val damping = 50.0f
|
val damping = 50.0f
|
||||||
val sign = -1.0f
|
val sign = -1.0f
|
||||||
@ -172,5 +193,10 @@ class VisibleMessageView : LinearLayout {
|
|||||||
.setDuration(150)
|
.setDuration(150)
|
||||||
.start()
|
.start()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun onLongPress() {
|
||||||
|
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||||
|
Log.d("Test", "Long press")
|
||||||
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user