From 97290cea48e4c5a5fd3c4a97d652a558bda13eb2 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Thu, 24 Apr 2025 22:28:11 +0200 Subject: [PATCH] Replace String.capitalize with replaceFirstChar --- .../amethyst/ui/note/types/CommunityHeader.kt | 5 ++++- .../amethyst/ui/note/types/LiveActivity.kt | 5 ++++- .../amethyst/ui/note/types/MedicalData.kt | 14 +++++++++++--- .../LongLiveActivityChannelHeader.kt | 5 ++++- .../datasource/DiscoveryFilterAssembler.kt | 16 ++++++++++++---- .../hashtag/datasource/HashtagFilterAssembler.kt | 4 +++- .../home/datasource/HomeFilterAssembler.kt | 4 +++- .../video/datasource/VideoFilterAssembler.kt | 12 ++++++++++-- 8 files changed, 51 insertions(+), 14 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt index 0a302904a..0291e11cb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt @@ -226,7 +226,10 @@ fun LongCommunityHeader( ) { it.first.role?.let { it1 -> Text( - text = it1.capitalize(Locale.ROOT), + text = + it1.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.width(75.dp), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt index 988906078..26bd51bc7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt @@ -262,7 +262,10 @@ fun RenderLiveActivityEventInner( Spacer(StdHorzSpacer) it.first.role?.let { Text( - text = it.capitalize(Locale.ROOT), + text = + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, color = MaterialTheme.colorScheme.placeholderText, maxLines = 1, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt index 64d7913fd..154ffbf5e 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/types/MedicalData.kt @@ -258,7 +258,9 @@ fun RenderEyeGlassesPrescription( } visionPrescription.status?.let { Text( - text = "Status: ${it.capitalize(Locale.getDefault())}", + text = "Status: ${it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }}", modifier = Modifier.padding(4.dp).fillMaxWidth(), ) } @@ -359,7 +361,10 @@ fun RenderEyeGlassesPrescriptionRow(data: LensSpecification) { verticalAlignment = Alignment.CenterVertically, ) { Text( - text = data.eye?.capitalize(Locale.getDefault()) ?: "Unknown", + text = + data.eye?.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + } ?: "Unknown", modifier = Modifier.padding(4.dp).weight(1f), ) VerticalDivider(thickness = DividerThickness) @@ -515,7 +520,10 @@ fun RenderEyeContactsPrescriptionRow(data: LensSpecification) { verticalAlignment = Alignment.CenterVertically, ) { Text( - text = data.eye?.capitalize(Locale.getDefault()) ?: "Unknown", + text = + data.eye?.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + } ?: "Unknown", modifier = Modifier.padding(4.dp).weight(1f), ) VerticalDivider(thickness = DividerThickness) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LongLiveActivityChannelHeader.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LongLiveActivityChannelHeader.kt index ae33ff953..1f58c639d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LongLiveActivityChannelHeader.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/publicChannels/nip53LiveActivities/LongLiveActivityChannelHeader.kt @@ -181,7 +181,10 @@ fun LongLiveActivityChannelHeader( ) { it.first.role?.let { it1 -> Text( - text = it1.capitalize(Locale.ROOT), + text = + it1.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, maxLines = 1, overflow = TextOverflow.Ellipsis, modifier = Modifier.width(55.dp), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFilterAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFilterAssembler.kt index 6715be963..57a76f642 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFilterAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/discover/datasource/DiscoveryFilterAssembler.kt @@ -114,7 +114,9 @@ class DiscoveryFilterAssembler( it, it.lowercase(), it.uppercase(), - it.capitalize(Locale.getDefault()), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten(), ), @@ -277,7 +279,9 @@ class DiscoveryFilterAssembler( it, it.lowercase(), it.uppercase(), - it.capitalize(Locale.getDefault()), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten(), ), @@ -338,7 +342,9 @@ class DiscoveryFilterAssembler( it, it.lowercase(), it.uppercase(), - it.capitalize(Locale.getDefault()), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten(), ), @@ -400,7 +406,9 @@ class DiscoveryFilterAssembler( it, it.lowercase(), it.uppercase(), - it.capitalize(Locale.getDefault()), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten(), ), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/hashtag/datasource/HashtagFilterAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/hashtag/datasource/HashtagFilterAssembler.kt index 7c1a65c4a..2d0381acb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/hashtag/datasource/HashtagFilterAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/hashtag/datasource/HashtagFilterAssembler.kt @@ -80,7 +80,9 @@ class HashtagFilterAssembler( it.hashtag, it.hashtag.lowercase(), it.hashtag.uppercase(), - it.hashtag.capitalize(Locale.getDefault()), + it.hashtag.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/HomeFilterAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/HomeFilterAssembler.kt index f188f4eb6..54780b1d2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/HomeFilterAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/home/datasource/HomeFilterAssembler.kt @@ -177,7 +177,9 @@ class HomeFilterAssembler( it, it.lowercase(), it.uppercase(), - it.capitalize(Locale.getDefault()), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, ) }.flatten(), ), diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/VideoFilterAssembler.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/VideoFilterAssembler.kt index 77841c74c..9a6c7519d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/VideoFilterAssembler.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/video/datasource/VideoFilterAssembler.kt @@ -103,8 +103,16 @@ class VideoFilterAssembler( val hashtags = hashToLoad - .map { listOf(it, it.lowercase(), it.uppercase(), it.capitalize(Locale.getDefault())) } - .flatten() + .map { + listOf( + it, + it.lowercase(), + it.uppercase(), + it.replaceFirstChar { + if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + }, + ) + }.flatten() return listOf( TypedFilter(