mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Fix bullet points not having leading margin on timeline items (#4536)
* Fix bullet points not having leading margin on timeline items * Remove other usages of `SpannableString` constructor, use either `valueOf` to reuse the existing value or `SpannedString` instead if the spans don't have to change
This commit is contained in:
committed by
GitHub
parent
b1dd555baa
commit
977268b876
+2
-2
@@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
package io.element.android.features.messages.impl.timeline.components.event
|
package io.element.android.features.messages.impl.timeline.components.event
|
||||||
|
|
||||||
import android.text.SpannableString
|
import android.text.SpannedString
|
||||||
import androidx.annotation.VisibleForTesting
|
import androidx.annotation.VisibleForTesting
|
||||||
import androidx.compose.foundation.layout.Box
|
import androidx.compose.foundation.layout.Box
|
||||||
import androidx.compose.material3.LocalContentColor
|
import androidx.compose.material3.LocalContentColor
|
||||||
@@ -71,7 +71,7 @@ fun TimelineItemTextView(
|
|||||||
internal fun getTextWithResolvedMentions(content: TimelineItemTextBasedContent): CharSequence {
|
internal fun getTextWithResolvedMentions(content: TimelineItemTextBasedContent): CharSequence {
|
||||||
val mentionSpanUpdater = LocalMentionSpanUpdater.current
|
val mentionSpanUpdater = LocalMentionSpanUpdater.current
|
||||||
val bodyWithResolvedMentions = mentionSpanUpdater.rememberMentionSpans(content.formattedBody)
|
val bodyWithResolvedMentions = mentionSpanUpdater.rememberMentionSpans(content.formattedBody)
|
||||||
return SpannableString(bodyWithResolvedMentions)
|
return SpannedString.valueOf(bodyWithResolvedMentions)
|
||||||
}
|
}
|
||||||
|
|
||||||
@PreviewsDayNight
|
@PreviewsDayNight
|
||||||
|
|||||||
+1
-1
@@ -135,7 +135,7 @@ fun ClickableLinkText(
|
|||||||
|
|
||||||
fun AnnotatedString.linkify(linkStyle: SpanStyle): AnnotatedString {
|
fun AnnotatedString.linkify(linkStyle: SpanStyle): AnnotatedString {
|
||||||
val original = this
|
val original = this
|
||||||
val spannable = SpannableString(this.text)
|
val spannable = SpannableString.valueOf(this.text)
|
||||||
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.PHONE_NUMBERS or Linkify.EMAIL_ADDRESSES)
|
LinkifyCompat.addLinks(spannable, Linkify.WEB_URLS or Linkify.PHONE_NUMBERS or Linkify.EMAIL_ADDRESSES)
|
||||||
|
|
||||||
val spans = spannable.getSpans(0, spannable.length, URLSpan::class.java)
|
val spans = spannable.getSpans(0, spannable.length, URLSpan::class.java)
|
||||||
|
|||||||
+2
-2
@@ -8,7 +8,7 @@
|
|||||||
package io.element.android.libraries.designsystem.text
|
package io.element.android.libraries.designsystem.text
|
||||||
|
|
||||||
import android.graphics.Typeface
|
import android.graphics.Typeface
|
||||||
import android.text.SpannableString
|
import android.text.SpannedString
|
||||||
import android.text.style.ForegroundColorSpan
|
import android.text.style.ForegroundColorSpan
|
||||||
import android.text.style.StyleSpan
|
import android.text.style.StyleSpan
|
||||||
import android.text.style.UnderlineSpan
|
import android.text.style.UnderlineSpan
|
||||||
@@ -26,7 +26,7 @@ import io.element.android.compound.theme.LinkColor
|
|||||||
|
|
||||||
fun String.toAnnotatedString(): AnnotatedString = buildAnnotatedString {
|
fun String.toAnnotatedString(): AnnotatedString = buildAnnotatedString {
|
||||||
append(this@toAnnotatedString)
|
append(this@toAnnotatedString)
|
||||||
val spannable = SpannableString(this@toAnnotatedString)
|
val spannable = SpannedString.valueOf(this@toAnnotatedString)
|
||||||
spannable.getSpans(0, spannable.length, Any::class.java).forEach { span ->
|
spannable.getSpans(0, spannable.length, Any::class.java).forEach { span ->
|
||||||
val start = spannable.getSpanStart(span)
|
val start = spannable.getSpanStart(span)
|
||||||
val end = spannable.getSpanEnd(span)
|
val end = spannable.getSpanEnd(span)
|
||||||
|
|||||||
+2
-2
@@ -16,11 +16,11 @@ import io.element.android.libraries.core.extensions.orEmpty
|
|||||||
|
|
||||||
@Stable
|
@Stable
|
||||||
class StableCharSequence(initialText: CharSequence = "") {
|
class StableCharSequence(initialText: CharSequence = "") {
|
||||||
private var value by mutableStateOf<SpannableString>(SpannableString(initialText))
|
private var value by mutableStateOf<SpannableString>(SpannableString.valueOf(initialText))
|
||||||
private var needsDisplaying by mutableStateOf(false)
|
private var needsDisplaying by mutableStateOf(false)
|
||||||
|
|
||||||
fun update(newText: CharSequence?, needsDisplaying: Boolean) {
|
fun update(newText: CharSequence?, needsDisplaying: Boolean) {
|
||||||
value = SpannableString(newText.orEmpty())
|
value = SpannableString.valueOf(newText.orEmpty())
|
||||||
this.needsDisplaying = needsDisplaying
|
this.needsDisplaying = needsDisplaying
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-3
@@ -9,7 +9,6 @@ package io.element.android.libraries.textcomposer.model
|
|||||||
|
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.text.Spannable
|
import android.text.Spannable
|
||||||
import android.text.SpannableString
|
|
||||||
import android.text.SpannableStringBuilder
|
import android.text.SpannableStringBuilder
|
||||||
import android.text.Spanned
|
import android.text.Spanned
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
@@ -118,8 +117,7 @@ class MarkdownTextEditorState(
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun getMentions(): List<IntentionalMention> {
|
fun getMentions(): List<IntentionalMention> {
|
||||||
val text = SpannableString(text.value())
|
val mentionSpans = text.value().getMentionSpans()
|
||||||
val mentionSpans = text.getMentionSpans()
|
|
||||||
return mentionSpans.mapNotNull { mentionSpan ->
|
return mentionSpans.mapNotNull { mentionSpan ->
|
||||||
when (mentionSpan.type) {
|
when (mentionSpan.type) {
|
||||||
is MentionType.User -> IntentionalMention.User(mentionSpan.type.userId)
|
is MentionType.User -> IntentionalMention.User(mentionSpan.type.userId)
|
||||||
|
|||||||
Reference in New Issue
Block a user