|
|
|
@ -3,8 +3,12 @@ package org.thoughtcrime.securesms.conversation.v2.messages
|
|
|
|
|
import android.content.Context
|
|
|
|
|
import android.graphics.Rect
|
|
|
|
|
import android.graphics.drawable.Drawable
|
|
|
|
|
import android.text.method.LinkMovementMethod
|
|
|
|
|
import android.text.style.ReplacementSpan
|
|
|
|
|
import android.text.style.URLSpan
|
|
|
|
|
import android.text.util.Linkify
|
|
|
|
|
import android.util.AttributeSet
|
|
|
|
|
import android.util.Log
|
|
|
|
|
import android.util.TypedValue
|
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
|
import android.widget.LinearLayout
|
|
|
|
@ -12,10 +16,13 @@ import android.widget.TextView
|
|
|
|
|
import android.widget.Toast
|
|
|
|
|
import androidx.annotation.ColorInt
|
|
|
|
|
import androidx.annotation.DrawableRes
|
|
|
|
|
import androidx.appcompat.app.AppCompatActivity
|
|
|
|
|
import androidx.core.content.res.ResourcesCompat
|
|
|
|
|
import androidx.core.graphics.BlendModeColorFilterCompat
|
|
|
|
|
import androidx.core.graphics.BlendModeCompat
|
|
|
|
|
import androidx.core.text.getSpans
|
|
|
|
|
import androidx.core.text.toSpannable
|
|
|
|
|
import androidx.core.text.util.LinkifyCompat
|
|
|
|
|
import kotlinx.android.synthetic.main.view_visible_message_content.view.*
|
|
|
|
|
import network.loki.messenger.R
|
|
|
|
|
import org.session.libsession.utilities.ThemeUtil
|
|
|
|
@ -23,6 +30,8 @@ import org.session.libsession.utilities.ViewUtil
|
|
|
|
|
import org.session.libsession.utilities.recipients.Recipient
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.components.AlbumThumbnailView
|
|
|
|
|
import org.thoughtcrime.securesms.components.emoji.EmojiTextView
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.dialogs.OpenURLDialog
|
|
|
|
|
import org.thoughtcrime.securesms.conversation.v2.utilities.ModalURLSpan
|
|
|
|
|
import org.thoughtcrime.securesms.database.model.MessageRecord
|
|
|
|
|
import org.thoughtcrime.securesms.database.model.MmsMessageRecord
|
|
|
|
|
import org.thoughtcrime.securesms.loki.utilities.*
|
|
|
|
@ -61,7 +70,9 @@ class VisibleMessageContentView : LinearLayout {
|
|
|
|
|
val linkPreviewView = LinkPreviewView(context)
|
|
|
|
|
linkPreviewView.bind(message, glide, isStartOfMessageCluster, isEndOfMessageCluster)
|
|
|
|
|
mainContainer.addView(linkPreviewView)
|
|
|
|
|
onContentClick = { linkPreviewView.openURL() }
|
|
|
|
|
onContentClick = { rect ->
|
|
|
|
|
linkPreviewView.calculateHit(rect)
|
|
|
|
|
}
|
|
|
|
|
// Body text view is inside the link preview for layout convenience
|
|
|
|
|
} else if (message is MmsMessageRecord && message.quote != null) {
|
|
|
|
|
val quote = message.quote!!
|
|
|
|
@ -106,9 +117,8 @@ class VisibleMessageContentView : LinearLayout {
|
|
|
|
|
mainContainer.addView(openGroupInvitationView)
|
|
|
|
|
onContentClick = { openGroupInvitationView.joinOpenGroup() }
|
|
|
|
|
} else {
|
|
|
|
|
val bodyTextView = VisibleMessageContentView.getBodyTextView(context, message)
|
|
|
|
|
val bodyTextView = getBodyTextView(context, message)
|
|
|
|
|
mainContainer.addView(bodyTextView)
|
|
|
|
|
onContentClick = { openURLIfNeeded(message) }
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -132,12 +142,6 @@ class VisibleMessageContentView : LinearLayout {
|
|
|
|
|
}
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
// region Interaction
|
|
|
|
|
private fun openURLIfNeeded(message: MessageRecord) {
|
|
|
|
|
Toast.makeText(context, "Not yet implemented", Toast.LENGTH_LONG).show()
|
|
|
|
|
}
|
|
|
|
|
// endregion
|
|
|
|
|
|
|
|
|
|
// region Convenience
|
|
|
|
|
companion object {
|
|
|
|
|
|
|
|
|
@ -152,8 +156,23 @@ class VisibleMessageContentView : LinearLayout {
|
|
|
|
|
result.setLinkTextColor(color)
|
|
|
|
|
var body = message.body.toSpannable()
|
|
|
|
|
Linkify.addLinks(body, Linkify.WEB_URLS)
|
|
|
|
|
|
|
|
|
|
// replace URLSpans with ModalURLSpans
|
|
|
|
|
body.getSpans<URLSpan>(0, body.length).toList().forEach { urlSpan ->
|
|
|
|
|
val replacementSpan = ModalURLSpan(urlSpan.url) { url ->
|
|
|
|
|
val activity = context as AppCompatActivity
|
|
|
|
|
OpenURLDialog(url).show(activity.supportFragmentManager, "Open URL Dialog")
|
|
|
|
|
}
|
|
|
|
|
val start = body.getSpanStart(urlSpan)
|
|
|
|
|
val end = body.getSpanEnd(urlSpan)
|
|
|
|
|
val flags = body.getSpanFlags(urlSpan)
|
|
|
|
|
body.removeSpan(urlSpan)
|
|
|
|
|
body.setSpan(replacementSpan, start, end, flags)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
body = MentionUtilities.highlightMentions(body, message.isOutgoing, message.threadId, context);
|
|
|
|
|
result.text = body
|
|
|
|
|
result.movementMethod = LinkMovementMethod.getInstance()
|
|
|
|
|
return result
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|