diff --git a/app/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt b/app/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt new file mode 100644 index 000000000..b04ac61c2 --- /dev/null +++ b/app/src/main/java/com/vitorpamplona/amethyst/model/HashtagIcon.kt @@ -0,0 +1,17 @@ +package com.vitorpamplona.amethyst.model + +import androidx.compose.ui.graphics.Color +import com.vitorpamplona.amethyst.R +fun checkForHashtagWithIcon(tag: String): HashtagIcon? { + if (tag.lowercase() == "bitcoin" || tag.lowercase() == "btc") { + return HashtagIcon(R.drawable.ht_btc, "Bitcoin", Color(0xFFF2A900)) + } else if (tag.lowercase() == "nostr") { + return HashtagIcon(R.drawable.ht_nostr, "Nostr", Color(0xFF9C59FF)) + } + return null +} +class HashtagIcon( + val icon: Int, + val description: String, + val color: Color +) diff --git a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt index 6c390d583..229f90612 100644 --- a/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt +++ b/app/src/main/java/com/vitorpamplona/amethyst/ui/components/RichTextViewer.kt @@ -4,11 +4,10 @@ import android.util.Patterns import androidx.compose.animation.animateContentSize import androidx.compose.foundation.background import androidx.compose.foundation.border -import androidx.compose.foundation.layout.Column -import androidx.compose.foundation.layout.fillMaxWidth -import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.* import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.text.ClickableText +import androidx.compose.material.Icon import androidx.compose.material.LocalTextStyle import androidx.compose.material.MaterialTheme import androidx.compose.material.Text @@ -18,6 +17,7 @@ import androidx.compose.ui.Modifier import androidx.compose.ui.draw.clip import androidx.compose.ui.graphics.Color import androidx.compose.ui.graphics.compositeOver +import androidx.compose.ui.res.painterResource import androidx.compose.ui.text.AnnotatedString import androidx.compose.ui.text.SpanStyle import androidx.compose.ui.text.TextStyle @@ -34,6 +34,7 @@ import com.halilibo.richtext.ui.RichTextStyle import com.halilibo.richtext.ui.material.MaterialRichText import com.halilibo.richtext.ui.resolveDefaults import com.vitorpamplona.amethyst.model.LocalCache +import com.vitorpamplona.amethyst.model.checkForHashtagWithIcon import com.vitorpamplona.amethyst.service.lnurl.LnInvoiceUtil import com.vitorpamplona.amethyst.service.nip19.Nip19 import com.vitorpamplona.amethyst.ui.note.NoteCompose @@ -49,7 +50,7 @@ val noProtocolUrlValidator = Pattern.compile("^[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\. val tagIndex = Pattern.compile(".*\\#\\[([0-9]+)\\].*") val mentionsPattern: Pattern = Pattern.compile("@([A-Za-z0-9_\\-]+)") -val hashTagsPattern: Pattern = Pattern.compile("#([A-Za-z0-9_\\-]+)") +val hashTagsPattern: Pattern = Pattern.compile("#([A-Za-z0-9_\\-]+\\.?+\\,?+\\??+\\!?+\\;?+\\-?)") val urlPattern: Pattern = Patterns.WEB_URL fun isValidURL(url: String?): Boolean { @@ -147,7 +148,21 @@ fun RichTextViewer( } else if (tagIndex.matcher(word).matches() && tags != null) { TagLink(word, tags, canPreview, backgroundColor, accountViewModel, navController) } else if (hashTagsPattern.matcher(word).matches()) { - HashTag(word, accountViewModel, navController) + if (word.endsWith(".") || word.endsWith(",") || word.endsWith("?") || word.endsWith("!") || word.endsWith(";") || word.endsWith("-")) { + var wordwithoutsuffix = word.removeRange(word.length - 1, word.length) + var suffix = word.last() + HashTag(wordwithoutsuffix, accountViewModel, navController) + Text( + text = "$suffix ", + style = LocalTextStyle.current.copy(textDirection = TextDirection.Content) + ) + } else { + HashTag(word, accountViewModel, navController) + Text( + text = " ", + style = LocalTextStyle.current.copy(textDirection = TextDirection.Content) + ) + } } else if (isBechLink(word)) { BechLink(word, navController) } else { @@ -219,11 +234,22 @@ fun HashTag(word: String, accountViewModel: AccountViewModel, navController: Nav } if (tag != null) { + val hashtagIcon = checkForHashtagWithIcon(tag) ClickableText( - text = AnnotatedString("#$tag "), + text = AnnotatedString("#$tag"), onClick = { navController.navigate("Hashtag/$tag") }, style = LocalTextStyle.current.copy(color = MaterialTheme.colors.primary) ) + + if (hashtagIcon != null) { + Icon( + painter = painterResource(hashtagIcon.icon), + contentDescription = hashtagIcon.description, + tint = hashtagIcon.color, + modifier = Modifier.size(20.dp).padding(0.dp, 5.dp, 0.dp, 0.dp) + + ) + } } else { Text(text = "$word ") } diff --git a/app/src/main/res/drawable-hdpi/ht_btc.png b/app/src/main/res/drawable-hdpi/ht_btc.png new file mode 100644 index 000000000..3c9b974d8 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ht_btc.png differ diff --git a/app/src/main/res/drawable-hdpi/ht_nostr.png b/app/src/main/res/drawable-hdpi/ht_nostr.png new file mode 100644 index 000000000..eb6c1f90b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ht_nostr.png differ diff --git a/app/src/main/res/drawable-mdpi/ht_btc.png b/app/src/main/res/drawable-mdpi/ht_btc.png new file mode 100644 index 000000000..3c9b974d8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ht_btc.png differ diff --git a/app/src/main/res/drawable-mdpi/ht_nostr.png b/app/src/main/res/drawable-mdpi/ht_nostr.png new file mode 100644 index 000000000..eb6c1f90b Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ht_nostr.png differ diff --git a/app/src/main/res/drawable-xhdpi/ht_btc.png b/app/src/main/res/drawable-xhdpi/ht_btc.png new file mode 100644 index 000000000..3c9b974d8 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ht_btc.png differ diff --git a/app/src/main/res/drawable-xhdpi/ht_nostr.png b/app/src/main/res/drawable-xhdpi/ht_nostr.png new file mode 100644 index 000000000..eb6c1f90b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ht_nostr.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ht_btc.png b/app/src/main/res/drawable-xxhdpi/ht_btc.png new file mode 100644 index 000000000..3c9b974d8 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ht_btc.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ht_nostr.png b/app/src/main/res/drawable-xxhdpi/ht_nostr.png new file mode 100644 index 000000000..eb6c1f90b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ht_nostr.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ht_btc.png b/app/src/main/res/drawable-xxxhdpi/ht_btc.png new file mode 100644 index 000000000..3c9b974d8 Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ht_btc.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ht_nostr.png b/app/src/main/res/drawable-xxxhdpi/ht_nostr.png new file mode 100644 index 000000000..eb6c1f90b Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ht_nostr.png differ