From ad2387f8e9db6279aeb18d0f7f031c57490fc4a4 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Thu, 24 Apr 2025 22:15:04 +0200 Subject: [PATCH 1/5] Add @OptIns Change to auto mirrored icons Remove unnecessary inline --- .../main/java/com/vitorpamplona/amethyst/DebugUtils.kt | 2 +- .../java/com/vitorpamplona/amethyst/model/Account.kt | 2 ++ .../amethyst/service/images/ImageLoaderSetup.kt | 2 ++ .../relayClient/reqCommand/event/EventObservers.kt | 10 +++++----- .../relayClient/reqCommand/user/UserObservers.kt | 2 +- .../amethyst/ui/navigation/AccountSwitchBottomSheet.kt | 4 ++-- .../amethyst/ui/note/NIP05VerificationDisplay.kt | 1 - .../amethyst/ui/note/creators/previews/PreviewState.kt | 2 ++ .../creators/userSuggestions/UserSuggestionState.kt | 1 + .../ui/screen/loggedIn/chats/utils/ThinSendButton.kt | 4 ++-- .../loggedIn/profile/relays/RelayFeedViewModel.kt | 2 ++ 11 files changed, 20 insertions(+), 12 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/DebugUtils.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/DebugUtils.kt index 2b04f99f2..a5f949e5a 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/DebugUtils.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/DebugUtils.kt @@ -164,7 +164,7 @@ inline fun logTime( block() } -inline fun debug( +fun debug( tag: String, debugMessage: String, ) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt index 7fcb11a90..5c203f20d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Account.kt @@ -181,6 +181,7 @@ import kotlinx.coroutines.CoroutineScope import kotlinx.coroutines.DelicateCoroutinesApi import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.ExperimentalCoroutinesApi +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.GlobalScope import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.MutableStateFlow @@ -1086,6 +1087,7 @@ class Account( ) } + @OptIn(FlowPreview::class) val decryptBookmarks: Flow by lazy { userProfile() .flow() diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt index 31097217c..72806c7aa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/images/ImageLoaderSetup.kt @@ -24,6 +24,7 @@ import android.app.Application import android.os.Build import coil3.ImageLoader import coil3.SingletonImageLoader +import coil3.annotation.DelicateCoilApi import coil3.disk.DiskCache import coil3.gif.AnimatedImageDecoder import coil3.gif.GifDecoder @@ -37,6 +38,7 @@ import okhttp3.Call class ImageLoaderSetup { companion object { + @OptIn(DelicateCoilApi::class) fun setup( app: Application, diskCache: DiskCache, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt index e43f6129d..6f382acf8 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/event/EventObservers.kt @@ -50,7 +50,7 @@ fun observeNote(note: Note): State { } @Suppress("UNCHECKED_CAST") -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeNoteEvent(note: Note): State { // Subscribe in the relay for changes in this note. @@ -68,7 +68,7 @@ fun observeNoteEvent(note: Note): State { return flow.collectAsStateWithLifecycle(note.event as? T?) } -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeNoteAndMap( note: Note, @@ -91,8 +91,8 @@ fun observeNoteAndMap( return flow.collectAsStateWithLifecycle(map(note)) } +@OptIn(ExperimentalCoroutinesApi::class) @Suppress("UNCHECKED_CAST") -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) @Composable fun observeNoteEventAndMap( note: Note, @@ -116,7 +116,7 @@ fun observeNoteEventAndMap( return flow.collectAsStateWithLifecycle((note.event as? T)?.let { map(it) }) } -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeNoteHasEvent(note: Note): State { // Subscribe in the relay for changes in this note. @@ -225,7 +225,7 @@ fun observeNoteReposts(note: Note): State { .collectAsStateWithLifecycle() } -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) +@OptIn(ExperimentalCoroutinesApi::class) @Composable fun observeNoteRepostsBy( note: Note, diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt index 8904190fa..db3302ab0 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/service/relayClient/reqCommand/user/UserObservers.kt @@ -565,7 +565,7 @@ data class RelayUsage( val userRelayList: List = emptyList(), ) -@OptIn(ExperimentalCoroutinesApi::class, FlowPreview::class) +@OptIn(FlowPreview::class) @Composable fun observeUserRelaysUsing(user: User): State { // Subscribe in the relay for changes in the metadata of this user. diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AccountSwitchBottomSheet.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AccountSwitchBottomSheet.kt index 06e8d16f8..15be32fce 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AccountSwitchBottomSheet.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/AccountSwitchBottomSheet.kt @@ -32,7 +32,7 @@ import androidx.compose.foundation.layout.width import androidx.compose.foundation.rememberScrollState import androidx.compose.foundation.verticalScroll import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Logout +import androidx.compose.material.icons.automirrored.filled.Logout import androidx.compose.material.icons.filled.RadioButtonChecked import androidx.compose.material3.AlertDialog import androidx.compose.material3.ExperimentalMaterial3Api @@ -285,7 +285,7 @@ private fun LogoutButton( onClick = { logoutDialog = true }, ) { Icon( - imageVector = Icons.Default.Logout, + imageVector = Icons.AutoMirrored.Filled.Logout, contentDescription = stringRes(R.string.log_out), tint = MaterialTheme.colorScheme.onSurface, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt index 429878b0f..b7bb586fb 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/NIP05VerificationDisplay.kt @@ -26,7 +26,6 @@ import androidx.compose.foundation.layout.Spacer import androidx.compose.foundation.layout.padding import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.OpenInNew -import androidx.compose.material.icons.filled.OpenInNew import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.material3.LocalTextStyle diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt index 95ba45749..53e2ce17d 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/previews/PreviewState.kt @@ -23,6 +23,7 @@ package com.vitorpamplona.amethyst.ui.note.creators.previews import androidx.compose.ui.text.input.TextFieldValue import com.vitorpamplona.amethyst.commons.richtext.RichTextParser import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.debounce import kotlinx.coroutines.flow.distinctUntilChanged @@ -32,6 +33,7 @@ import kotlinx.coroutines.flow.map class PreviewState { var source = MutableStateFlow(TextFieldValue("")) + @OptIn(FlowPreview::class) val results = source .debounce(200) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt index ebad5f11a..bef45fbb7 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/creators/userSuggestions/UserSuggestionState.kt @@ -52,6 +52,7 @@ class UserSuggestionState( .map(::userSearchTermOrNull) .onEach(::updateDataSource) + @OptIn(FlowPreview::class) val results = combine(searchTerm, invalidations.debounce(100)) { prefix, version -> if (prefix != null) { diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/utils/ThinSendButton.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/utils/ThinSendButton.kt index f3a0d42ce..cef4d1da4 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/utils/ThinSendButton.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/chats/utils/ThinSendButton.kt @@ -21,7 +21,7 @@ package com.vitorpamplona.amethyst.ui.screen.loggedIn.chats.utils import androidx.compose.material.icons.Icons -import androidx.compose.material.icons.filled.Send +import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material3.Icon import androidx.compose.material3.IconButton import androidx.compose.runtime.Composable @@ -42,7 +42,7 @@ fun ThinSendButton( onClick = onClick, ) { Icon( - imageVector = Icons.Default.Send, + imageVector = Icons.AutoMirrored.Filled.Send, contentDescription = stringRes(id = R.string.accessibility_send), modifier = Size20Modifier, ) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt index 84422fd34..7f75b0b10 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/profile/relays/RelayFeedViewModel.kt @@ -33,6 +33,7 @@ import com.vitorpamplona.ammolite.relays.BundledUpdate import com.vitorpamplona.quartz.nip02FollowList.ReadWrite import com.vitorpamplona.quartz.nip65RelayList.RelayUrlFormatter import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.FlowPreview import kotlinx.coroutines.Job import kotlinx.coroutines.flow.MutableStateFlow import kotlinx.coroutines.flow.asStateFlow @@ -96,6 +97,7 @@ class RelayFeedViewModel : return (userRelaysBeingUsed + currentUserRelays).sortedWith(order) } + @OptIn(FlowPreview::class) fun subscribeTo(user: User) { if (currentUser != user) { currentUser = user From 97290cea48e4c5a5fd3c4a97d652a558bda13eb2 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Thu, 24 Apr 2025 22:28:11 +0200 Subject: [PATCH 2/5] 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( From 96436912bb8eecd10fbe732430f2e4dffa361230 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Fri, 25 Apr 2025 15:52:30 +0200 Subject: [PATCH 3/5] Safe checked casting --- .../main/java/com/vitorpamplona/amethyst/model/Note.kt | 9 ++++++++- .../loggedIn/settings/dal/HiddenAccountsFeedViewModel.kt | 9 +++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt index e511cd844..a79d677f2 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/model/Note.kt @@ -926,7 +926,14 @@ open class Note( } } - fun toEventHint() = (event as? T)?.let { EventHintBundle(it, relayHintUrl(), author?.bestRelayHint()) } + inline fun toEventHint(): EventHintBundle? { + val safeEvent = event + return if (safeEvent is T) { + EventHintBundle(safeEvent, relayHintUrl(), author?.bestRelayHint()) + } else { + null + } + } fun toMarkedETag(marker: MarkedETag.MARKER): MarkedETag { val noteEvent = event diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedViewModel.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedViewModel.kt index 8b25172b3..0de1d2933 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedViewModel.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/settings/dal/HiddenAccountsFeedViewModel.kt @@ -31,7 +31,12 @@ class HiddenAccountsFeedViewModel( class Factory( val account: Account, ) : ViewModelProvider.Factory { - @Suppress("UNCHECKED_CAST") - override fun create(modelClass: Class): T = HiddenAccountsFeedViewModel(account) as T + override fun create(modelClass: Class): T { + if (modelClass.isAssignableFrom(HiddenAccountsFeedViewModel::class.java)) { + @Suppress("UNCHECKED_CAST") + return HiddenAccountsFeedViewModel(account) as T + } + throw IllegalArgumentException("Unknown ViewModel class: ${modelClass.name}") + } } } From e40ca09f7cad09d1743991ad4b69412dece42607 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Fri, 25 Apr 2025 17:00:16 +0200 Subject: [PATCH 4/5] Use default locale for capitalisation in UI strings (use ROOT for IDs/Hashes for consistency) --- .../com/vitorpamplona/amethyst/ui/note/types/CommunityHeader.kt | 2 +- .../com/vitorpamplona/amethyst/ui/note/types/LiveActivity.kt | 2 +- .../nip53LiveActivities/LongLiveActivityChannelHeader.kt | 2 +- 3 files changed, 3 insertions(+), 3 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 0291e11cb..81e03f9d4 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 @@ -228,7 +228,7 @@ fun LongCommunityHeader( Text( text = it1.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }, maxLines = 1, overflow = TextOverflow.Ellipsis, 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 26bd51bc7..4445c493e 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 @@ -264,7 +264,7 @@ fun RenderLiveActivityEventInner( Text( text = it.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }, color = MaterialTheme.colorScheme.placeholderText, maxLines = 1, 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 1f58c639d..a8ac04453 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 @@ -183,7 +183,7 @@ fun LongLiveActivityChannelHeader( Text( text = it1.replaceFirstChar { - if (it.isLowerCase()) it.titlecase(Locale.ROOT) else it.toString() + if (it.isLowerCase()) it.titlecase(Locale.getDefault()) else it.toString() }, maxLines = 1, overflow = TextOverflow.Ellipsis, From d874e798c60ac8dee8096a9ae3833cf8865c28c0 Mon Sep 17 00:00:00 2001 From: David Kaspar Date: Fri, 25 Apr 2025 17:01:41 +0200 Subject: [PATCH 5/5] remove unused imports --- .../com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt | 4 +--- .../src/main/java/com/vitorpamplona/amethyst/ui/note/Icons.kt | 1 - .../amethyst/ui/screen/loggedIn/relays/AllRelayListScreen.kt | 1 - 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt index ce4d6fa93..5bda4cd30 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/navigation/DrawerContent.kt @@ -46,9 +46,7 @@ import androidx.compose.material.icons.Icons import androidx.compose.material.icons.automirrored.filled.Send import androidx.compose.material.icons.filled.AccountCircle import androidx.compose.material.icons.filled.Delete -import androidx.compose.material.icons.outlined.AccountCircle import androidx.compose.material.icons.outlined.BookmarkBorder -import androidx.compose.material.icons.outlined.Bookmarks import androidx.compose.material.icons.outlined.CloudUpload import androidx.compose.material.icons.outlined.Drafts import androidx.compose.material.icons.outlined.GroupAdd @@ -283,7 +281,7 @@ private fun EditStatusBoxes( statuses.forEach { val noteStatus by observeNote(it) - StatusEditBar(noteStatus?.note?.event?.content, it.address, accountViewModel, nav) + StatusEditBar(noteStatus.note.event?.content, it.address, accountViewModel, nav) } } } diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Icons.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Icons.kt index e503de742..36b8889fa 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Icons.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/note/Icons.kt @@ -52,7 +52,6 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.res.painterResource import androidx.compose.ui.tooling.preview.Preview import androidx.compose.ui.unit.Dp -import coil3.compose.AsyncImagePainter.State.Empty.painter import com.vitorpamplona.amethyst.R import com.vitorpamplona.amethyst.commons.hashtags.Amethyst import com.vitorpamplona.amethyst.commons.hashtags.Cashu diff --git a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/AllRelayListScreen.kt b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/AllRelayListScreen.kt index f0bec9d55..60c2ff153 100644 --- a/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/AllRelayListScreen.kt +++ b/amethyst/src/main/java/com/vitorpamplona/amethyst/ui/screen/loggedIn/relays/AllRelayListScreen.kt @@ -20,7 +20,6 @@ */ package com.vitorpamplona.amethyst.ui.screen.loggedIn.relays -import android.R.attr.action import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Column import androidx.compose.foundation.layout.Row