mirror of
https://github.com/signalapp/Signal-Android.git
synced 2026-02-21 10:17:56 +00:00
Fix hit detection for story link previews.
This commit is contained in:
committed by
Cody Henthorne
parent
4ad466390f
commit
ce244f2e8f
@@ -6,6 +6,7 @@ import android.animation.ObjectAnimator
|
||||
import android.annotation.SuppressLint
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Rect
|
||||
import android.graphics.drawable.Drawable
|
||||
import android.media.AudioManager
|
||||
import android.os.Bundle
|
||||
@@ -28,7 +29,6 @@ import androidx.core.content.ContextCompat
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.GestureDetectorCompat
|
||||
import androidx.core.view.animation.PathInterpolatorCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.fragment.app.viewModels
|
||||
@@ -72,7 +72,6 @@ import org.thoughtcrime.securesms.recipients.RecipientId
|
||||
import org.thoughtcrime.securesms.recipients.ui.bottomsheet.RecipientBottomSheetDialogFragment
|
||||
import org.thoughtcrime.securesms.safety.SafetyNumberBottomSheet
|
||||
import org.thoughtcrime.securesms.stories.StorySlateView
|
||||
import org.thoughtcrime.securesms.stories.StoryTextPostView
|
||||
import org.thoughtcrime.securesms.stories.StoryVolumeOverlayView
|
||||
import org.thoughtcrime.securesms.stories.dialogs.StoryContextMenu
|
||||
import org.thoughtcrime.securesms.stories.dialogs.StoryDialogs
|
||||
@@ -136,6 +135,9 @@ class StoryViewerPageFragment :
|
||||
|
||||
private val storyViewStateViewModel: StoryViewStateViewModel by viewModels()
|
||||
|
||||
private var textStoryIntersectProcessingEvents: Boolean = false
|
||||
private val textStoryIntersectHitRect: Rect = Rect()
|
||||
|
||||
private val viewModel: StoryViewerPageViewModel by viewModels(
|
||||
factoryProducer = {
|
||||
StoryViewerPageViewModel.Factory(
|
||||
@@ -545,16 +547,30 @@ class StoryViewerPageFragment :
|
||||
|
||||
private fun checkEventIntersectsClickableSpan(cardWrapper: ViewGroup, event: MotionEvent): Boolean {
|
||||
if (viewModel.getPost()?.content?.isText() != true) {
|
||||
textStoryIntersectProcessingEvents = false
|
||||
return false
|
||||
}
|
||||
|
||||
val action = event.action
|
||||
if (action != MotionEvent.ACTION_DOWN && action != MotionEvent.ACTION_UP) {
|
||||
return false
|
||||
return textStoryIntersectProcessingEvents
|
||||
}
|
||||
|
||||
val storyTextPostView = cardWrapper.findViewById<StoryTextPostView>(R.id.text)
|
||||
val textView = storyTextPostView.findViewById<TextView>(R.id.text_story_post_text)
|
||||
if (checkTextSpanIntersect(cardWrapper, event)) {
|
||||
textStoryIntersectProcessingEvents = true
|
||||
return true
|
||||
}
|
||||
|
||||
if (checkLinkPreviewIntersect(cardWrapper, event)) {
|
||||
textStoryIntersectProcessingEvents = true
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
private fun checkTextSpanIntersect(cardWrapper: ViewGroup, event: MotionEvent): Boolean {
|
||||
val textView = cardWrapper.findViewById<TextView>(R.id.text_story_post_text)
|
||||
val spanned = textView.text as? Spanned ?: return false
|
||||
|
||||
val textViewProjection = Projection.relativeToParent(cardWrapper, textView, null)
|
||||
@@ -579,12 +595,28 @@ class StoryViewerPageFragment :
|
||||
}
|
||||
|
||||
val clickables = spanned.getSpans(off, off, ClickableSpan::class.java)
|
||||
if (clickables.isNotEmpty()) {
|
||||
return true
|
||||
}
|
||||
return clickables.isNotEmpty()
|
||||
}
|
||||
|
||||
val linkPreview = storyTextPostView.findViewById<View>(R.id.text_story_post_link_preview)
|
||||
return linkPreview.isVisible
|
||||
private fun checkLinkPreviewIntersect(cardWrapper: ViewGroup, event: MotionEvent): Boolean {
|
||||
Log.d(TAG, "Checking motion event for link preview intersect: ${event.x} ${event.y}")
|
||||
|
||||
val linkPreviewView = cardWrapper.findViewById<View>(R.id.text_story_post_link_preview)
|
||||
val viewProjection = Projection.relativeToParent(cardWrapper, linkPreviewView, null)
|
||||
.translateY(linkPreviewView.translationY)
|
||||
|
||||
textStoryIntersectHitRect.set(
|
||||
viewProjection.x.toInt(),
|
||||
viewProjection.y.toInt(),
|
||||
viewProjection.x.toInt() + viewProjection.width,
|
||||
viewProjection.y.toInt() + viewProjection.height
|
||||
)
|
||||
|
||||
viewProjection.release()
|
||||
|
||||
Log.d(TAG, "${event.x}, ${event.y} within $textStoryIntersectHitRect? ${textStoryIntersectHitRect.contains(event.x.toInt(), event.y.toInt())}")
|
||||
|
||||
return textStoryIntersectHitRect.contains(event.x.toInt(), event.y.toInt())
|
||||
}
|
||||
|
||||
private fun calculateDurationForText(textContent: StoryPost.Content.TextContent): Long {
|
||||
|
||||
Reference in New Issue
Block a user