mirror of
https://github.com/oxen-io/session-android.git
synced 2025-06-24 12:18:28 +00:00
Re-introduce regular press
This commit is contained in:
parent
61588332a6
commit
2988ac8b7a
@ -36,6 +36,9 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
|||||||
onItemPress = { message, position ->
|
onItemPress = { message, position ->
|
||||||
handlePress(message, position)
|
handlePress(message, position)
|
||||||
},
|
},
|
||||||
|
onItemSwipeToReply = { message, position ->
|
||||||
|
handleSwipeToReply(message, position)
|
||||||
|
},
|
||||||
onItemLongPress = { message, position ->
|
onItemLongPress = { message, position ->
|
||||||
handleLongPress(message, position)
|
handleLongPress(message, position)
|
||||||
}
|
}
|
||||||
@ -109,10 +112,7 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
|||||||
return super.onOptionsItemSelected(item)
|
return super.onOptionsItemSelected(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun reply(messagePosition: Int) {
|
// `position` is the adapter position; not the visual position
|
||||||
Log.d("Loki", "Reply to message at position: $messagePosition.")
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun handlePress(message: MessageRecord, position: Int) {
|
private fun handlePress(message: MessageRecord, position: Int) {
|
||||||
val actionMode = this.actionMode
|
val actionMode = this.actionMode
|
||||||
if (actionMode != null) {
|
if (actionMode != null) {
|
||||||
@ -126,6 +126,12 @@ class ConversationActivityV2 : PassphraseRequiredActionBarActivity() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// `position` is the adapter position; not the visual position
|
||||||
|
private fun handleSwipeToReply(message: MessageRecord, position: Int) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// `position` is the adapter position; not the visual position
|
||||||
private fun handleLongPress(message: MessageRecord, position: Int) {
|
private fun handleLongPress(message: MessageRecord, position: Int) {
|
||||||
val actionMode = this.actionMode
|
val actionMode = this.actionMode
|
||||||
val actionModeCallback = ConversationActionModeCallback(adapter, threadID, this)
|
val actionModeCallback = ConversationActionModeCallback(adapter, threadID, this)
|
||||||
|
@ -17,7 +17,8 @@ import org.thoughtcrime.securesms.loki.utilities.getColorWithID
|
|||||||
import java.lang.IllegalStateException
|
import java.lang.IllegalStateException
|
||||||
|
|
||||||
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPress: (MessageRecord, Int) -> Unit,
|
class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPress: (MessageRecord, Int) -> Unit,
|
||||||
private val onItemLongPress: (MessageRecord, Int) -> Unit) : CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
|
private val onItemSwipeToReply: (MessageRecord, Int) -> Unit, private val onItemLongPress: (MessageRecord, Int) -> Unit)
|
||||||
|
: CursorRecyclerViewAdapter<ViewHolder>(context, cursor) {
|
||||||
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
|
private val messageDB = DatabaseFactory.getMmsSmsDatabase(context)
|
||||||
var selectedItems = mutableSetOf<MessageRecord>()
|
var selectedItems = mutableSetOf<MessageRecord>()
|
||||||
|
|
||||||
@ -73,6 +74,9 @@ class ConversationAdapter(context: Context, cursor: Cursor, private val onItemPr
|
|||||||
view.messageTimestampTextView.isVisible = isSelected
|
view.messageTimestampTextView.isVisible = isSelected
|
||||||
val position = viewHolder.adapterPosition
|
val position = viewHolder.adapterPosition
|
||||||
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor))
|
view.bind(message, getMessageBefore(position, cursor), getMessageAfter(position, cursor))
|
||||||
|
view.onPress = { onItemPress(message, viewHolder.adapterPosition) }
|
||||||
|
view.onSwipeToReply = { onItemSwipeToReply(message, viewHolder.adapterPosition) }
|
||||||
|
view.onLongPress = { onItemLongPress(message, viewHolder.adapterPosition) }
|
||||||
}
|
}
|
||||||
is ControlMessageViewHolder -> viewHolder.view.bind(message)
|
is ControlMessageViewHolder -> viewHolder.view.bind(message)
|
||||||
}
|
}
|
||||||
|
@ -5,7 +5,6 @@ import android.os.Build
|
|||||||
import android.os.Handler
|
import android.os.Handler
|
||||||
import android.os.Looper
|
import android.os.Looper
|
||||||
import android.util.AttributeSet
|
import android.util.AttributeSet
|
||||||
import android.util.Log
|
|
||||||
import android.view.*
|
import android.view.*
|
||||||
import android.widget.LinearLayout
|
import android.widget.LinearLayout
|
||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
@ -27,11 +26,15 @@ class VisibleMessageView : LinearLayout {
|
|||||||
private var previousTranslationX = 0.0f
|
private var previousTranslationX = 0.0f
|
||||||
private val gestureHandler = Handler(Looper.getMainLooper())
|
private val gestureHandler = Handler(Looper.getMainLooper())
|
||||||
private var longPressCallback: Runnable? = null
|
private var longPressCallback: Runnable? = null
|
||||||
|
private var onDownTimestamp = 0L
|
||||||
|
var onPress: (() -> Unit)? = null
|
||||||
|
var onSwipeToReply: (() -> Unit)? = null
|
||||||
|
var onLongPress: (() -> Unit)? = null
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
const val swipeToReplyThreshold = 90.0f // dp
|
const val swipeToReplyThreshold = 90.0f // dp
|
||||||
const val longPressMovementTreshold = 10.0f // dp
|
const val longPressMovementTreshold = 10.0f // dp
|
||||||
const val longPressDurationThreshold = 250.0f // ms
|
const val longPressDurationThreshold = 250L // ms
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
@ -150,13 +153,11 @@ class VisibleMessageView : LinearLayout {
|
|||||||
|
|
||||||
private fun onDown(event: MotionEvent) {
|
private fun onDown(event: MotionEvent) {
|
||||||
dx = x - event.rawX
|
dx = x - event.rawX
|
||||||
val oldLongPressCallback = longPressCallback
|
longPressCallback?.let { gestureHandler.removeCallbacks(it) }
|
||||||
if (oldLongPressCallback != null) {
|
val newLongPressCallback = Runnable { onLongPress() }
|
||||||
gestureHandler.removeCallbacks(oldLongPressCallback)
|
this.longPressCallback = newLongPressCallback
|
||||||
}
|
gestureHandler.postDelayed(newLongPressCallback, VisibleMessageView.longPressDurationThreshold)
|
||||||
val longPressCallback = Runnable { onLongPress() }
|
onDownTimestamp = Date().time
|
||||||
this.longPressCallback = longPressCallback
|
|
||||||
gestureHandler.postDelayed(longPressCallback, VisibleMessageView.longPressDurationThreshold)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun onMove(event: MotionEvent) {
|
private fun onMove(event: MotionEvent) {
|
||||||
@ -164,10 +165,7 @@ class VisibleMessageView : LinearLayout {
|
|||||||
if (abs(translationX) < VisibleMessageView.longPressMovementTreshold) {
|
if (abs(translationX) < VisibleMessageView.longPressMovementTreshold) {
|
||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
val longPressCallback = longPressCallback
|
longPressCallback?.let { gestureHandler.removeCallbacks(it) }
|
||||||
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
|
||||||
@ -186,7 +184,10 @@ class VisibleMessageView : LinearLayout {
|
|||||||
|
|
||||||
private fun onFinish(event: MotionEvent) {
|
private fun onFinish(event: MotionEvent) {
|
||||||
if (abs(translationX) > VisibleMessageView.swipeToReplyThreshold) {
|
if (abs(translationX) > VisibleMessageView.swipeToReplyThreshold) {
|
||||||
Log.d("Test", "Reply")
|
onSwipeToReply?.invoke()
|
||||||
|
} else if ((Date().time - onDownTimestamp) < VisibleMessageView.longPressDurationThreshold) {
|
||||||
|
longPressCallback?.let { gestureHandler.removeCallbacks(it) }
|
||||||
|
onPress?.invoke()
|
||||||
}
|
}
|
||||||
animate()
|
animate()
|
||||||
.translationX(0.0f)
|
.translationX(0.0f)
|
||||||
@ -196,7 +197,7 @@ class VisibleMessageView : LinearLayout {
|
|||||||
|
|
||||||
private fun onLongPress() {
|
private fun onLongPress() {
|
||||||
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
performHapticFeedback(HapticFeedbackConstants.LONG_PRESS)
|
||||||
Log.d("Test", "Long press")
|
onLongPress?.invoke()
|
||||||
}
|
}
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user