More generic name
This commit is contained in:
parent
c31b64771b
commit
05a788453f
|
@ -98,7 +98,7 @@ interface RelationService {
|
||||||
/**
|
/**
|
||||||
* Reply to an event in the timeline (must be in same room)
|
* Reply to an event in the timeline (must be in same room)
|
||||||
* https://matrix.org/docs/spec/client_server/r0.4.0.html#id350
|
* https://matrix.org/docs/spec/client_server/r0.4.0.html#id350
|
||||||
* The replyText can be a Spannable and contains special spans (UserMentionSpan) that will be translated
|
* The replyText can be a Spannable and contains special spans (MatrixItemSpan) that will be translated
|
||||||
* by the sdk into pills.
|
* by the sdk into pills.
|
||||||
* @param eventReplied the event referenced by the reply
|
* @param eventReplied the event referenced by the reply
|
||||||
* @param replyText the reply text
|
* @param replyText the reply text
|
||||||
|
|
|
@ -19,9 +19,9 @@ package im.vector.matrix.android.api.session.room.send
|
||||||
import im.vector.matrix.android.api.util.MatrixItem
|
import im.vector.matrix.android.api.util.MatrixItem
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tag class for spans that should mention a user.
|
* Tag class for spans that should mention a matrix item.
|
||||||
* These Spans will be transformed into pills when detected in message to send
|
* These Spans will be transformed into pills when detected in message to send
|
||||||
*/
|
*/
|
||||||
interface UserMentionSpan {
|
interface MatrixItemSpan {
|
||||||
val matrixItem: MatrixItem
|
val matrixItem: MatrixItem
|
||||||
}
|
}
|
|
@ -29,7 +29,7 @@ interface SendService {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Method to send a text message asynchronously.
|
* Method to send a text message asynchronously.
|
||||||
* The text to send can be a Spannable and contains special spans (UserMentionSpan) that will be translated
|
* The text to send can be a Spannable and contains special spans (MatrixItemSpan) that will be translated
|
||||||
* by the sdk into pills.
|
* by the sdk into pills.
|
||||||
* @param text the text message to send
|
* @param text the text message to send
|
||||||
* @param msgType the message type: MessageType.MSGTYPE_TEXT (default) or MessageType.MSGTYPE_EMOTE
|
* @param msgType the message type: MessageType.MSGTYPE_TEXT (default) or MessageType.MSGTYPE_EMOTE
|
||||||
|
|
|
@ -16,10 +16,10 @@
|
||||||
|
|
||||||
package im.vector.matrix.android.internal.session.room.send.pills
|
package im.vector.matrix.android.internal.session.room.send.pills
|
||||||
|
|
||||||
import im.vector.matrix.android.api.session.room.send.UserMentionSpan
|
import im.vector.matrix.android.api.session.room.send.MatrixItemSpan
|
||||||
|
|
||||||
internal data class MentionLinkSpec(
|
internal data class MentionLinkSpec(
|
||||||
val span: UserMentionSpan,
|
val span: MatrixItemSpan,
|
||||||
val start: Int,
|
val start: Int,
|
||||||
val end: Int
|
val end: Int
|
||||||
)
|
)
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
package im.vector.matrix.android.internal.session.room.send.pills
|
package im.vector.matrix.android.internal.session.room.send.pills
|
||||||
|
|
||||||
import android.text.SpannableString
|
import android.text.SpannableString
|
||||||
import im.vector.matrix.android.api.session.room.send.UserMentionSpan
|
import im.vector.matrix.android.api.session.room.send.MatrixItemSpan
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@ -49,7 +49,7 @@ internal class TextPillsUtils @Inject constructor(
|
||||||
private fun transformPills(text: CharSequence, template: String): String? {
|
private fun transformPills(text: CharSequence, template: String): String? {
|
||||||
val spannableString = SpannableString.valueOf(text)
|
val spannableString = SpannableString.valueOf(text)
|
||||||
val pills = spannableString
|
val pills = spannableString
|
||||||
?.getSpans(0, text.length, UserMentionSpan::class.java)
|
?.getSpans(0, text.length, MatrixItemSpan::class.java)
|
||||||
?.map { MentionLinkSpec(it, spannableString.getSpanStart(it), spannableString.getSpanEnd(it)) }
|
?.map { MentionLinkSpec(it, spannableString.getSpanStart(it), spannableString.getSpanEnd(it)) }
|
||||||
?.toMutableList()
|
?.toMutableList()
|
||||||
?.takeIf { it.isNotEmpty() }
|
?.takeIf { it.isNotEmpty() }
|
||||||
|
@ -65,7 +65,7 @@ internal class TextPillsUtils @Inject constructor(
|
||||||
// append text before pill
|
// append text before pill
|
||||||
append(text, currIndex, start)
|
append(text, currIndex, start)
|
||||||
// append the pill
|
// append the pill
|
||||||
append(String.format(template, urlSpan.matrixItem.id, urlSpan.matrixItem.displayName))
|
append(String.format(template, urlSpan.matrixItem.id, urlSpan.matrixItem.getBestName()))
|
||||||
currIndex = end
|
currIndex = end
|
||||||
}
|
}
|
||||||
// append text after the last pill
|
// append text after the last pill
|
||||||
|
|
|
@ -28,7 +28,7 @@ import androidx.annotation.UiThread
|
||||||
import com.bumptech.glide.request.target.SimpleTarget
|
import com.bumptech.glide.request.target.SimpleTarget
|
||||||
import com.bumptech.glide.request.transition.Transition
|
import com.bumptech.glide.request.transition.Transition
|
||||||
import com.google.android.material.chip.ChipDrawable
|
import com.google.android.material.chip.ChipDrawable
|
||||||
import im.vector.matrix.android.api.session.room.send.UserMentionSpan
|
import im.vector.matrix.android.api.session.room.send.MatrixItemSpan
|
||||||
import im.vector.matrix.android.api.util.MatrixItem
|
import im.vector.matrix.android.api.util.MatrixItem
|
||||||
import im.vector.riotx.R
|
import im.vector.riotx.R
|
||||||
import im.vector.riotx.core.glide.GlideRequests
|
import im.vector.riotx.core.glide.GlideRequests
|
||||||
|
@ -38,13 +38,13 @@ import java.lang.ref.WeakReference
|
||||||
/**
|
/**
|
||||||
* This span is able to replace a text by a [ChipDrawable]
|
* This span is able to replace a text by a [ChipDrawable]
|
||||||
* It's needed to call [bind] method to start requesting avatar, otherwise only the placeholder icon will be displayed if not already cached.
|
* It's needed to call [bind] method to start requesting avatar, otherwise only the placeholder icon will be displayed if not already cached.
|
||||||
* Implements UserMentionSpan so that it could be automatically transformed in matrix links and displayed as pills.
|
* Implements MatrixItemSpan so that it could be automatically transformed in matrix links and displayed as pills.
|
||||||
*/
|
*/
|
||||||
class PillImageSpan(private val glideRequests: GlideRequests,
|
class PillImageSpan(private val glideRequests: GlideRequests,
|
||||||
private val avatarRenderer: AvatarRenderer,
|
private val avatarRenderer: AvatarRenderer,
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
override val matrixItem: MatrixItem
|
override val matrixItem: MatrixItem
|
||||||
) : ReplacementSpan(), UserMentionSpan {
|
) : ReplacementSpan(), MatrixItemSpan {
|
||||||
|
|
||||||
private val pillDrawable = createChipDrawable()
|
private val pillDrawable = createChipDrawable()
|
||||||
private val target = PillImageSpanTarget(this)
|
private val target = PillImageSpanTarget(this)
|
||||||
|
|
Loading…
Reference in New Issue