Merge pull request #1746 from davotoula/cleaner-code

Cleaner code
This commit is contained in:
Vitor Pamplona
2026-03-03 06:46:34 -05:00
committed by GitHub
16 changed files with 102 additions and 64 deletions
@@ -229,7 +229,9 @@ interface ILocalCache {
fun markAsSeen(
eventId: String,
relay: NormalizedRelayUrl,
) {}
) {
// Default no-op; implementations may override to track seen events per relay
}
}
object LocalCache : ILocalCache, ICacheProvider {
@@ -91,6 +91,7 @@ class MeltProcessor {
onError: (String, String) -> Unit,
context: Context,
) {
// TODO: Implement Cashu token melting via Lightning invoice
}
suspend fun feeCalculator(
@@ -110,5 +110,7 @@ class ByteArrayMediaDataSource(
}
@Throws(IOException::class)
override fun close() {}
override fun close() {
// No resources to release; data is an in-memory byte array
}
}
@@ -199,12 +199,16 @@ object VideoCompressionHelper {
),
listener =
object : CompressionListener {
override fun onStart(index: Int) {}
override fun onStart(index: Int) {
// No action needed on compression start
}
override fun onProgress(
index: Int,
percent: Float,
) {}
) {
// Progress tracking not needed for this use case
}
override fun onSuccess(
index: Int,
@@ -117,6 +117,8 @@ fun RenderContentAsMarkdown(
}
}
private const val PREVIEW_CALLBACK_URI = "nostr:something"
@Preview
@Composable
fun RenderContentAsMarkdownPreview() {
@@ -162,7 +164,7 @@ fun RenderContentAsMarkdownPreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -212,7 +214,7 @@ fun RenderContentAsMarkdownListsPreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -266,7 +268,7 @@ fun RenderContentAsMarkdownCodePreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -306,7 +308,7 @@ fun RenderContentAsMarkdownTablesPreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -344,7 +346,7 @@ fun RenderContentAsMarkdownFootNotesPreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -405,7 +407,7 @@ fun RenderContentAsMarkdownUserPreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -455,7 +457,7 @@ fun RenderContentAsMarkdownNotePreview() {
remember {
mutableStateOf(background)
},
callbackUri = "nostr:something",
callbackUri = PREVIEW_CALLBACK_URI,
accountViewModel = accountViewModel,
nav = nav,
)
@@ -106,7 +106,9 @@ class ChannelFeedContentState(
}
}
fun deleteFromFeed(deletedNotes: Set<Note>) {}
fun deleteFromFeed(deletedNotes: Set<Note>) {
// TODO: Implement deletion of notes from the channel feed
}
fun refreshFromOldState(newItems: Set<Note>) {
val oldNotesState = _feedContent.value
@@ -51,6 +51,9 @@ import com.vitorpamplona.amethyst.ui.theme.Size55Modifier
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
import com.vitorpamplona.quartz.utils.TimeUtils
private const val PREVIEW_AUTHOR = "This is my author"
private const val PREVIEW_MESSAGE = "This is a message from this person"
@Composable
@Preview
fun ChannelNamePreview() {
@@ -65,11 +68,11 @@ fun ChannelNamePreview() {
)
},
firstRow = {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
},
secondRow = {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
Spacer(modifier = Height4dpModifier)
NewItemsBubble()
},
@@ -81,13 +84,13 @@ fun ChannelNamePreview() {
ListItem(
headlineContent = {
Row(verticalAlignment = Alignment.CenterVertically) {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
}
},
supportingContent = {
Row {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
NewItemsBubble()
}
},
@@ -106,13 +109,13 @@ fun ChannelNamePreview() {
SlimListItem(
headlineContent = {
Row(verticalAlignment = Alignment.CenterVertically) {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
}
},
supportingContent = {
Row(verticalAlignment = Alignment.CenterVertically) {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
NewItemsBubble()
}
},
@@ -80,6 +80,9 @@ import kotlin.math.max
* This is a copy of Material3's ListItemLayout.kt file, with the only change being the padding change from 16.dp to 10.dp
*/
private const val PREVIEW_AUTHOR = "This is my author"
private const val PREVIEW_MESSAGE = "This is a message from this person"
@Composable
@Preview
fun ChannelNamePreview() {
@@ -94,11 +97,11 @@ fun ChannelNamePreview() {
)
},
firstRow = {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
},
secondRow = {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
NewItemsBubble()
},
onClick = {},
@@ -109,13 +112,13 @@ fun ChannelNamePreview() {
SlimListItem(
headlineContent = {
Row(verticalAlignment = CenterVertically) {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
}
},
supportingContent = {
Row(verticalAlignment = CenterVertically) {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
Spacer(modifier = Height4dpModifier)
NewItemsBubble()
}
@@ -135,13 +138,13 @@ fun ChannelNamePreview() {
ListItem(
headlineContent = {
Row(verticalAlignment = CenterVertically) {
Text("This is my author", Modifier.weight(1f))
Text(PREVIEW_AUTHOR, Modifier.weight(1f))
TimeAgo(TimeUtils.now())
}
},
supportingContent = {
Row(verticalAlignment = CenterVertically) {
Text("This is a message from this person", Modifier.weight(1f))
Text(PREVIEW_MESSAGE, Modifier.weight(1f))
Spacer(modifier = Height4dpModifier)
NewItemsBubble()
}
@@ -37,6 +37,7 @@ class EmptyNav : INav {
override fun openDrawer() = runBlocking { drawerState.open() }
// All navigation methods are intentionally no-op; this is a stub for previews and tests
override fun nav(route: Route) {}
override fun nav(computeRoute: suspend () -> Route?) {}
@@ -1542,33 +1542,38 @@ fun ReactionChoicePopupContent(
}
}
private const val EMOJI_ROCKET = "\uD83D\uDE80"
private const val EMOJI_THINKING = "\uD83E\uDD14"
private const val EMOJI_SCREAM = "\uD83D\uDE31"
private const val EMOJI_PARTY = "\uD83C\uDF89"
@Preview()
@Composable
fun ReactionChoicePopupPeeview() {
ThemeComparisonColumn {
ReactionChoicePopupContent(
persistentListOf(
"\uD83D\uDE80",
EMOJI_ROCKET,
"\uD83E\uDEC2",
"\uD83D\uDC40",
"\uD83D\uDE02",
"\uD83C\uDF89",
"\uD83E\uDD14",
"\uD83D\uDE31",
"\uD83E\uDD14",
"\uD83D\uDE31",
EMOJI_PARTY,
EMOJI_THINKING,
EMOJI_SCREAM,
EMOJI_THINKING,
EMOJI_SCREAM,
"+",
"-",
"\uD83C\uDF89",
"\uD83E\uDD14",
"\uD83D\uDE31",
"\uD83E\uDD14",
"\uD83D\uDE31",
EMOJI_PARTY,
EMOJI_THINKING,
EMOJI_SCREAM,
EMOJI_THINKING,
EMOJI_SCREAM,
"\uD83D\uDE80\uDB40\uDD58\uDB40\uDD64\uDB40\uDD64\uDB40\uDD60\uDB40\uDD63\uDB40\uDD2A\uDB40\uDD1F\uDB40\uDD1F\uDB40\uDD53\uDB40\uDD54\uDB40\uDD5E\uDB40\uDD1E\uDB40\uDD63\uDB40\uDD51\uDB40\uDD64\uDB40\uDD55\uDB40\uDD5C\uDB40\uDD5C\uDB40\uDD59\uDB40\uDD64\uDB40\uDD55\uDB40\uDD1E\uDB40\uDD55\uDB40\uDD51\uDB40\uDD62\uDB40\uDD64\uDB40\uDD58\uDB40\uDD1F\uDB40\uDD29\uDB40\uDD24\uDB40\uDD27\uDB40\uDD55\uDB40\uDD24\uDB40\uDD51\uDB40\uDD52\uDB40\uDD22\uDB40\uDD54\uDB40\uDD23\uDB40\uDD21\uDB40\uDD21\uDB40\uDD25\uDB40\uDD52\uDB40\uDD55\uDB40\uDD25\uDB40\uDD26\uDB40\uDD25\uDB40\uDD51\uDB40\uDD24\uDB40\uDD29\uDB40\uDD53\uDB40\uDD56\uDB40\uDD25\uDB40\uDD54\uDB40\uDD52\uDB40\uDD20\uDB40\uDD22\uDB40\uDD25\uDB40\uDD25\uDB40\uDD29\uDB40\uDD56\uDB40\uDD23\uDB40\uDD21\uDB40\uDD20\uDB40\uDD53\uDB40\uDD51\uDB40\uDD20\uDB40\uDD51\uDB40\uDD26\uDB40\uDD54\uDB40\uDD54\uDB40\uDD56\uDB40\uDD54\uDB40\uDD54\uDB40\uDD52\uDB40\uDD54\uDB40\uDD24\uDB40\uDD52\uDB40\uDD54\uDB40\uDD28\uDB40\uDD53\uDB40\uDD52\uDB40\uDD55\uDB40\uDD53\uDB40\uDD24\uDB40\uDD24\uDB40\uDD29\uDB40\uDD29\uDB40\uDD25\uDB40\uDD53\uDB40\uDD22\uDB40\uDD55\uDB40\uDD27\uDB40\uDD1E\uDB40\uDD67\uDB40\uDD55\uDB40\uDD52\uDB40\uDD60",
),
onClick = {},
onChangeAmount = {},
toRemove = persistentSetOf("\uD83D\uDE80", "\uD83E\uDD14", "\uD83D\uDE31"),
toRemove = persistentSetOf(EMOJI_ROCKET, EMOJI_THINKING, EMOJI_SCREAM),
)
}
}
@@ -433,6 +433,10 @@ fun ObserveAndDrawInnerUserPicture(
)
}
private const val PREVIEW_USER_HEX = "989c3734c46abac7ce3ce229971581a5a6ee39cdd6aa7261a55823fa7f8c4799"
private const val PREVIEW_PICTURE_URL = "http://null"
private const val PREVIEW_USER_NAME = "vitor"
@Preview
@Composable
fun ScoreTag55Preview() {
@@ -442,9 +446,9 @@ fun ScoreTag55Preview() {
var size = 75.dp
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
InnerUserPicture(
userHex = "989c3734c46abac7ce3ce229971581a5a6ee39cdd6aa7261a55823fa7f8c4799",
userPicture = "http://null",
userName = "vitor",
userHex = PREVIEW_USER_HEX,
userPicture = PREVIEW_PICTURE_URL,
userName = PREVIEW_USER_NAME,
size = size,
modifier = Modifier,
accountViewModel = accountViewModel,
@@ -455,9 +459,9 @@ fun ScoreTag55Preview() {
size = 55.dp
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
InnerUserPicture(
userHex = "989c3734c46abac7ce3ce229971581a5a6ee39cdd6aa7261a55823fa7f8c4799",
userPicture = "http://null",
userName = "vitor",
userHex = PREVIEW_USER_HEX,
userPicture = PREVIEW_PICTURE_URL,
userName = PREVIEW_USER_NAME,
size = size,
modifier = Modifier,
accountViewModel = accountViewModel,
@@ -468,9 +472,9 @@ fun ScoreTag55Preview() {
size = 35.dp
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
InnerUserPicture(
userHex = "989c3734c46abac7ce3ce229971581a5a6ee39cdd6aa7261a55823fa7f8c4799",
userPicture = "http://null",
userName = "vitor",
userHex = PREVIEW_USER_HEX,
userPicture = PREVIEW_PICTURE_URL,
userName = PREVIEW_USER_NAME,
size = size,
modifier = Modifier,
accountViewModel = accountViewModel,
@@ -481,9 +485,9 @@ fun ScoreTag55Preview() {
size = 25.dp
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
InnerUserPicture(
userHex = "989c3734c46abac7ce3ce229971581a5a6ee39cdd6aa7261a55823fa7f8c4799",
userPicture = "http://null",
userName = "vitor",
userHex = PREVIEW_USER_HEX,
userPicture = PREVIEW_PICTURE_URL,
userName = PREVIEW_USER_NAME,
size = size,
modifier = Modifier,
accountViewModel = accountViewModel,
@@ -495,8 +499,8 @@ fun ScoreTag55Preview() {
Box(Modifier.size(size), contentAlignment = Alignment.TopEnd) {
InnerUserPicture(
userHex = "AABBCC",
userPicture = "http://null",
userName = "vitor",
userPicture = PREVIEW_PICTURE_URL,
userName = PREVIEW_USER_NAME,
size = size,
modifier = Modifier,
accountViewModel = accountViewModel,
@@ -102,7 +102,9 @@ class ZapOptionViewModel : ViewModel() {
fun value(): Long? = customAmount.text.trim().toLongOrNull()
fun cancel() {}
fun cancel() {
// No cleanup needed; dialog state is reset on close
}
}
@Composable
@@ -141,6 +141,7 @@ class EventProcessor(
}
interface EventHandler<T : IEvent> {
// Default no-ops; implementations override only the operations they handle
suspend fun add(
event: T,
eventNote: Note,
@@ -71,6 +71,10 @@ import com.vitorpamplona.amethyst.ui.theme.SpacedBy2dp
import com.vitorpamplona.amethyst.ui.theme.SpacedBy5dp
import com.vitorpamplona.amethyst.ui.theme.ThemeComparisonColumn
private const val PREVIEW_LIST_TITLE = "Sample List Title"
private const val PREVIEW_LIST_DESCRIPTION = "Sample List Description"
private const val PREVIEW_LIST_IMAGE = "http://some.com/image.png"
@Preview()
@Composable
private fun PeopleListItemPreview() {
@@ -82,8 +86,8 @@ private fun PeopleListItemPreview() {
PeopleList(
identifierTag = "00001-2222",
title = "Sample List Title, Very long title, very very very long",
description = "Sample List Description",
image = "http://some.com/image.png",
description = PREVIEW_LIST_DESCRIPTION,
image = PREVIEW_LIST_IMAGE,
emptySet(),
emptySet(),
)
@@ -91,9 +95,9 @@ private fun PeopleListItemPreview() {
val samplePeopleList2 =
PeopleList(
identifierTag = "00001-2223",
title = "Sample List Title",
description = "Sample List Description",
image = "http://some.com/image.png",
title = PREVIEW_LIST_TITLE,
description = PREVIEW_LIST_DESCRIPTION,
image = PREVIEW_LIST_IMAGE,
setOf(user1, user3),
emptySet(),
)
@@ -101,9 +105,9 @@ private fun PeopleListItemPreview() {
val samplePeopleList3 =
PeopleList(
identifierTag = "00001-2224",
title = "Sample List Title",
description = "Sample List Description",
image = "http://some.com/image.png",
title = PREVIEW_LIST_TITLE,
description = PREVIEW_LIST_DESCRIPTION,
image = PREVIEW_LIST_IMAGE,
emptySet(),
setOf(user1, user3),
)
@@ -111,9 +115,9 @@ private fun PeopleListItemPreview() {
val samplePeopleList4 =
PeopleList(
identifierTag = "00001-2225",
title = "Sample List Title",
description = "Sample List Description",
image = "http://some.com/image.png",
title = PREVIEW_LIST_TITLE,
description = PREVIEW_LIST_DESCRIPTION,
image = PREVIEW_LIST_IMAGE,
setOf(user3),
setOf(user1, user2, user3),
)
@@ -92,7 +92,7 @@ class CardFeedContentState(
viewModelScope.launch(Dispatchers.IO) { _scrollToTop.emit(_scrollToTop.value + 1) }
}
suspend fun sentToTop() {
fun sentToTop() {
scrolltoTopPending = false
}
@@ -212,7 +212,7 @@ class CardFeedContentState(
val zapRequest = event.zapRequest
if (zapRequest != null) {
val zapRequestNote = LocalCache.getNoteIfExists(zapRequest.id)
val zapRequestNote = getNoteIfExists(zapRequest.id)
if (zapRequestNote != null) {
zapsPerUser
.getOrPut(author, { mutableListOf() })
@@ -352,6 +352,7 @@ class CardFeedContentState(
}
fun deleteFromFeed(deletedNotes: Set<Note>) {
// TODO: Implement deletion of notes from the notification feed
}
private fun refreshFromOldState(newItems: Set<Note>) {
@@ -57,5 +57,6 @@ class ConnectedRelayListViewModel : BasicRelaySetupInfoModel() {
.sorted()
override suspend fun saveRelayList(urlList: List<NormalizedRelayUrl>) {
// Connected relays are read-only; saving is not applicable
}
}