Skip to content

Commit

Permalink
fix: links in sms are not following the theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Bnyro committed Feb 15, 2024
1 parent d6fafff commit 855680f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
6 changes: 1 addition & 5 deletions app/src/main/java/com/bnyro/contacts/db/obj/SmsData.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package com.bnyro.contacts.db.obj

import androidx.compose.ui.text.AnnotatedString
import androidx.room.ColumnInfo
import androidx.room.Entity
import androidx.room.Ignore
import androidx.room.PrimaryKey
import com.bnyro.contacts.util.generateAnnotations

@Entity(tableName = "localSms")
data class SmsData(
Expand All @@ -15,6 +12,5 @@ data class SmsData(
@ColumnInfo var timestamp: Long = 0,
@ColumnInfo var threadId: Long = 0,
@ColumnInfo var type: Int = 0,
@ColumnInfo(defaultValue = "NULL") var simNumber: Int? = null,
@Ignore val formatted: AnnotatedString = generateAnnotations(body)
@ColumnInfo(defaultValue = "NULL") var simNumber: Int? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import com.bnyro.contacts.R
import com.bnyro.contacts.db.obj.SmsData
import com.bnyro.contacts.ui.components.dialogs.ConfirmationDialog
import com.bnyro.contacts.ui.models.SmsModel
import com.bnyro.contacts.util.generateAnnotations

@OptIn(ExperimentalMaterial3Api::class)
@Composable
Expand Down Expand Up @@ -225,15 +226,18 @@ fun ClickableMessage(
) {
SelectionContainer {
val uriHandler = LocalUriHandler.current
val primary = MaterialTheme.colorScheme.primary

val formatted = remember {
generateAnnotations(smsData.body, primary)
}

ClickableText(
text = smsData.formatted,
text = formatted,
style = MaterialTheme.typography.bodyLarge.copy(color = LocalContentColor.current),
onClick = { offset ->
val annotation =
smsData.formatted.getStringAnnotations(
offset,
offset
).firstOrNull()
formatted.getStringAnnotations(offset, offset).firstOrNull()
annotation?.let {
uriHandler.openUri(it.item)
}
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/bnyro/contacts/util/TextFormatUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ fun MutableList<Pair<Format, String>>.addKeywords(
}
}

fun generateAnnotations(text: String): AnnotatedString {
fun generateAnnotations(text: String, color: Color): AnnotatedString {
val keywords = mutableListOf<Pair<Format, String>>().apply {
addKeywords(
text,
Expand All @@ -48,7 +48,7 @@ fun generateAnnotations(text: String): AnnotatedString {
val indexOf = text.indexOf(keyword)
addStyle(
style = SpanStyle(
color = Color.Blue,
color = color,
textDecoration = when (format) {
Format.LINK -> TextDecoration.Underline
else -> TextDecoration.None
Expand Down

0 comments on commit 855680f

Please sign in to comment.