Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor user badge component #259

Merged
merged 5 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/detekt-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<ID>CyclomaticComplexMethod:FeedNoteCard.kt$@Composable private fun FeedNote( data: FeedPostUi, fullWidthContent: Boolean, avatarSizeDp: Dp, avatarPaddingValues: PaddingValues, notePaddingValues: PaddingValues, enableTweetsMode: Boolean, headerSingleLine: Boolean, showReplyTo: Boolean, forceContentIndent: Boolean, expanded: Boolean, textSelectable: Boolean, showNoteStatCounts: Boolean, noteCallbacks: NoteCallbacks, onPostAction: ((FeedPostAction) -&gt; Unit)? = null, onPostLongClickAction: ((FeedPostAction) -&gt; Unit)? = null, contentFooter: @Composable () -&gt; Unit = {}, )</ID>
<ID>CyclomaticComplexMethod:FeedNoteCard.kt$@ExperimentalMaterial3Api @Composable private fun FeedNoteCard( data: FeedPostUi, state: NoteContract.UiState, eventPublisher: (UiEvent) -&gt; Unit, modifier: Modifier = Modifier, shape: Shape = CardDefaults.shape, colors: CardColors = noteCardColors(), cardPadding: PaddingValues = PaddingValues(all = 0.dp), enableTweetsMode: Boolean = false, headerSingleLine: Boolean = true, fullWidthContent: Boolean = false, forceContentIndent: Boolean = false, drawLineAboveAvatar: Boolean = false, drawLineBelowAvatar: Boolean = false, expanded: Boolean = false, textSelectable: Boolean = false, showReplyTo: Boolean = true, noteOptionsMenuEnabled: Boolean = true, showNoteStatCounts: Boolean = true, noteCallbacks: NoteCallbacks = NoteCallbacks(), onGoToWallet: (() -&gt; Unit)? = null, contentFooter: @Composable () -&gt; Unit = {}, )</ID>
<ID>CyclomaticComplexMethod:MessagesRemoteMediator.kt$MessagesRemoteMediator$override suspend fun load(loadType: LoadType, state: PagingState&lt;Int, DirectMessage&gt;): MediatorResult</ID>
<ID>CyclomaticComplexMethod:NostrUserText.kt$@Composable fun NostrUserText( displayName: String, internetIdentifier: String?, modifier: Modifier = Modifier, displayNameColor: Color = AppTheme.colorScheme.onSurface, fontSize: TextUnit = TextUnit.Unspecified, style: TextStyle = LocalTextStyle.current, overflow: TextOverflow = TextOverflow.Ellipsis, maxLines: Int = 1, internetIdentifierBadgeSize: Dp = 14.dp, internetIdentifierBadgeAlign: PlaceholderVerticalAlign = PlaceholderVerticalAlign.Center, customBadgeStyle: LegendaryStyle? = null, annotatedStringPrefixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, annotatedStringSuffixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, )</ID>
<ID>CyclomaticComplexMethod:NostrUserText.kt$@Composable fun NostrUserText( displayName: String, internetIdentifier: String?, modifier: Modifier = Modifier, displayNameColor: Color = AppTheme.colorScheme.onSurface, fontSize: TextUnit = TextUnit.Unspecified, style: TextStyle = LocalTextStyle.current, overflow: TextOverflow = TextOverflow.Ellipsis, maxLines: Int = 1, internetIdentifierBadgeSize: Dp = 14.dp, internetIdentifierBadgeAlign: PlaceholderVerticalAlign = PlaceholderVerticalAlign.Center, authorLegendaryCustomization: LegendaryCustomization? = null, annotatedStringPrefixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, annotatedStringSuffixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, )</ID>
<ID>CyclomaticComplexMethod:NoteActionsRow.kt$@Composable fun FeedNoteActionsRow( modifier: Modifier, eventStats: EventStatsUi, isBookmarked: Boolean, highlightedNote: Boolean = false, showBookmark: Boolean = false, showCounts: Boolean = true, onPostAction: ((FeedPostAction) -&gt; Unit)? = null, onPostLongPressAction: ((FeedPostAction) -&gt; Unit)? = null, )</ID>
<ID>CyclomaticComplexMethod:NoteContent.kt$@OptIn(ExperimentalFoundationApi::class) @Composable fun NoteContent( modifier: Modifier = Modifier, data: NoteContentUi, expanded: Boolean, noteCallbacks: NoteCallbacks, maxLines: Int = Int.MAX_VALUE, overflow: TextOverflow = TextOverflow.Clip, enableTweetsMode: Boolean = false, textSelectable: Boolean = false, referencedEventsHaveBorder: Boolean = false, highlightColor: Color = AppTheme.colorScheme.secondary, contentColor: Color = AppTheme.colorScheme.onSurface, referencedEventsContainerColor: Color = AppTheme.extraColorScheme.surfaceVariantAlt1, onClick: ((offset: Offset) -&gt; Unit)? = null, onUrlClick: ((url: String) -&gt; Unit)? = null, )</ID>
<ID>CyclomaticComplexMethod:NoteFeedLazyColumn.kt$@ExperimentalMaterial3Api @ExperimentalFoundationApi @Composable fun NoteFeedLazyColumn( modifier: Modifier = Modifier, pagingItems: LazyPagingItems&lt;FeedPostUi&gt;, listState: LazyListState, showPaywall: Boolean, noteCallbacks: NoteCallbacks, onGoToWallet: () -&gt; Unit, showTopZaps: Boolean = false, shouldShowLoadingState: Boolean = true, shouldShowNoContentState: Boolean = true, showReplyTo: Boolean = true, noContentVerticalArrangement: Arrangement.Vertical = Arrangement.Center, noContentPaddingValues: PaddingValues = PaddingValues(all = 0.dp), noContentText: String = stringResource(id = R.string.feed_no_content), contentPadding: PaddingValues = PaddingValues(all = 0.dp), header: @Composable (LazyItemScope.() -&gt; Unit)? = null, stickyHeader: @Composable (LazyItemScope.() -&gt; Unit)? = null, onUiError: ((UiError) -&gt; Unit)? = null, )</ID>
Expand Down Expand Up @@ -54,7 +54,7 @@
<ID>LongMethod:MessageConversationListScreen.kt$@Composable private fun ConversationListItem( conversation: MessageConversationUi, onConversationClick: (String) -&gt; Unit, onProfileClick: (profileId: String) -&gt; Unit, )</ID>
<ID>LongMethod:MessageConversationListScreen.kt$@Composable private fun MessagesTabs( relation: ConversationRelation, onFollowsTabClick: () -&gt; Unit, onOtherTabClick: () -&gt; Unit, onMarkAllRead: () -&gt; Unit, )</ID>
<ID>LongMethod:MultipleUserPicker.kt$@OptIn(ExperimentalMaterial3Api::class) @Composable fun MultipleUserPicker( modifier: Modifier = Modifier, sheetTitle: String, placeholderText: String, onDismissRequest: () -&gt; Unit, onUsersSelected: (Set&lt;UserProfileItemUi&gt;) -&gt; Unit, sheetState: SheetState = rememberModalBottomSheetState(skipPartiallyExpanded = true), startingSelectedUsers: Set&lt;UserProfileItemUi&gt;, )</ID>
<ID>LongMethod:NostrUserText.kt$@Composable fun NostrUserText( displayName: String, internetIdentifier: String?, modifier: Modifier = Modifier, displayNameColor: Color = AppTheme.colorScheme.onSurface, fontSize: TextUnit = TextUnit.Unspecified, style: TextStyle = LocalTextStyle.current, overflow: TextOverflow = TextOverflow.Ellipsis, maxLines: Int = 1, internetIdentifierBadgeSize: Dp = 14.dp, internetIdentifierBadgeAlign: PlaceholderVerticalAlign = PlaceholderVerticalAlign.Center, customBadgeStyle: LegendaryStyle? = null, annotatedStringPrefixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, annotatedStringSuffixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, )</ID>
<ID>LongMethod:NostrUserText.kt$@Composable fun NostrUserText( displayName: String, internetIdentifier: String?, modifier: Modifier = Modifier, displayNameColor: Color = AppTheme.colorScheme.onSurface, fontSize: TextUnit = TextUnit.Unspecified, style: TextStyle = LocalTextStyle.current, overflow: TextOverflow = TextOverflow.Ellipsis, maxLines: Int = 1, internetIdentifierBadgeSize: Dp = 14.dp, internetIdentifierBadgeAlign: PlaceholderVerticalAlign = PlaceholderVerticalAlign.Center, authorLegendaryCustomization: LegendaryCustomization? = null, annotatedStringPrefixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, annotatedStringSuffixBuilder: (AnnotatedString.Builder.() -&gt; Unit)? = null, )</ID>
<ID>LongMethod:NoteActionsRow.kt$@Composable fun FeedNoteActionsRow( modifier: Modifier, eventStats: EventStatsUi, isBookmarked: Boolean, highlightedNote: Boolean = false, showBookmark: Boolean = false, showCounts: Boolean = true, onPostAction: ((FeedPostAction) -&gt; Unit)? = null, onPostLongPressAction: ((FeedPostAction) -&gt; Unit)? = null, )</ID>
<ID>LongMethod:NoteContent.kt$@OptIn(ExperimentalFoundationApi::class) @Composable fun NoteContent( modifier: Modifier = Modifier, data: NoteContentUi, expanded: Boolean, noteCallbacks: NoteCallbacks, maxLines: Int = Int.MAX_VALUE, overflow: TextOverflow = TextOverflow.Clip, enableTweetsMode: Boolean = false, textSelectable: Boolean = false, referencedEventsHaveBorder: Boolean = false, highlightColor: Color = AppTheme.colorScheme.secondary, contentColor: Color = AppTheme.colorScheme.onSurface, referencedEventsContainerColor: Color = AppTheme.extraColorScheme.surfaceVariantAlt1, onClick: ((offset: Offset) -&gt; Unit)? = null, onUrlClick: ((url: String) -&gt; Unit)? = null, )</ID>
<ID>LongMethod:NoteDropdownMenu.kt$@Composable fun NoteDropdownMenuIcon( modifier: Modifier, noteId: String, noteContent: String, noteRawData: String, authorId: String, isBookmarked: Boolean, enabled: Boolean = true, onBookmarkClick: (() -&gt; Unit)? = null, onMuteUserClick: (() -&gt; Unit)? = null, onReportContentClick: (() -&gt; Unit)? = null, )</ID>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import net.primal.android.core.compose.icons.primaliconpack.PrimalBadgeTeal
import net.primal.android.core.compose.icons.primaliconpack.Verified
import net.primal.android.core.compose.preview.PrimalPreview
import net.primal.android.core.utils.isPrimalIdentifier
import net.primal.android.premium.legend.LegendaryCustomization
import net.primal.android.premium.legend.LegendaryStyle
import net.primal.android.theme.AppTheme
import net.primal.android.theme.domain.PrimalTheme
Expand All @@ -57,12 +58,18 @@ fun NostrUserText(
maxLines: Int = 1,
internetIdentifierBadgeSize: Dp = 14.dp,
internetIdentifierBadgeAlign: PlaceholderVerticalAlign = PlaceholderVerticalAlign.Center,
customBadgeStyle: LegendaryStyle? = null,
authorLegendaryCustomization: LegendaryCustomization? = null,
mehmedalijaK marked this conversation as resolved.
Show resolved Hide resolved
annotatedStringPrefixBuilder: (AnnotatedString.Builder.() -> Unit)? = null,
annotatedStringSuffixBuilder: (AnnotatedString.Builder.() -> Unit)? = null,
) {
val verifiedBadge = !internetIdentifier.isNullOrEmpty()

val customBadgeStyle = if (authorLegendaryCustomization?.customBadge == true) {
authorLegendaryCustomization.legendaryStyle
} else {
null
}

val titleText = buildAnnotatedString {
annotatedStringPrefixBuilder?.invoke(this)
append(
Expand Down Expand Up @@ -156,6 +163,7 @@ fun PreviewNostrUserTextWithPrimalBadge() {
annotatedStringSuffixBuilder = {
append("• 42 y. ago")
},
authorLegendaryCustomization = null,
)
}
}
Expand All @@ -172,6 +180,7 @@ fun PreviewNostrUserTextWithRandomBadge() {
annotatedStringSuffixBuilder = {
append("• 42 y. ago")
},
authorLegendaryCustomization = null,
)
}
}
Expand All @@ -188,6 +197,7 @@ fun PreviewNostrUserTextWithoutBadge() {
annotatedStringSuffixBuilder = {
append(" • 42 y. ago")
},
authorLegendaryCustomization = null,
)
}
}
Expand All @@ -200,11 +210,15 @@ fun PreviewNostrUserTextWithCustomBadge() {
Surface {
NostrUserText(
displayName = "Nostr Adamus",
customBadgeStyle = LegendaryStyle.GOLD,
internetIdentifier = "[email protected]",
annotatedStringSuffixBuilder = {
append(" • 42 y. ago")
},
authorLegendaryCustomization = LegendaryCustomization(
customBadge = true,
avatarGlow = true,
legendaryStyle = LegendaryStyle.GOLD,
),
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,7 @@ private fun DrawerHeader(
top.linkTo(avatarRef.bottom, margin = 16.dp)
width = Dimension.preferredValue(220.dp)
},
customBadgeStyle = if (legendaryCustomization?.customBadge == true) {
legendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = legendaryCustomization,
)

IconButton(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,7 @@ private fun ExplorePersonListItem(
NostrUserText(
displayName = person.profile.userDisplayName,
internetIdentifier = person.profile.internetIdentifier,
customBadgeStyle = if (person.profile.premiumDetails?.legendaryCustomization?.customBadge == true) {
person.profile.premiumDetails.legendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = person.profile.premiumDetails?.legendaryCustomization,
)
person.profile.internetIdentifier?.let {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private fun ConversationListItem(
displayName = conversation.participantUsername,
internetIdentifier = conversation.participantInternetIdentifier,
annotatedStringSuffixBuilder = { append(suffixText) },
customBadgeStyle = conversation.participantLegendaryCustomization?.legendaryStyle,
authorLegendaryCustomization = conversation.participantLegendaryCustomization,
style = AppTheme.typography.bodyMedium,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,11 +141,7 @@ private fun NoteAuthorBadgeAndTimestampSection(
style = topRowTextStyle,
internetIdentifierBadgeSize = topRowTextStyle.fontSize.value.dp,
overflow = TextOverflow.Ellipsis,
customBadgeStyle = if (authorLegendaryCustomization?.customBadge == true) {
authorLegendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = authorLegendaryCustomization,
)
},
suffixFixedContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,11 +147,7 @@ private fun PremiumHomeScreen(
internetIdentifier = "[email protected]",
internetIdentifierBadgeSize = 24.dp,
fontSize = 20.sp,
customBadgeStyle = if (state.avatarLegendaryCustomization?.customBadge == true) {
state.avatarLegendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = state.avatarLegendaryCustomization,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ fun BecomeLegendAmountStage(
internetIdentifier = "${state.primalName}@primal.net",
internetIdentifierBadgeSize = 24.dp,
fontSize = 20.sp,
customBadgeStyle = LegendaryStyle.GOLD,
authorLegendaryCustomization = LegendaryCustomization(
customBadge = true,
legendaryStyle = LegendaryStyle.GOLD,
),
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,12 @@ fun LegendaryProfileCustomizationScreen(
displayName = primalName,
internetIdentifier = "[email protected]",
internetIdentifierBadgeSize = 24.dp,
customBadgeStyle = if (customBadge == true) selectedStyle else null,
authorLegendaryCustomization =
if (customBadge == true) {
mehmedalijaK marked this conversation as resolved.
Show resolved Hide resolved
LegendaryCustomization(customBadge = true, legendaryStyle = selectedStyle)
} else {
null
},
fontSize = 20.sp,
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,7 @@ fun ConfirmNameChangeStage(
internetIdentifier = "[email protected]",
internetIdentifierBadgeSize = 24.dp,
fontSize = 20.sp,
customBadgeStyle = if (profileLegendaryCustomization?.customBadge == true) {
profileLegendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = profileLegendaryCustomization,
)
Text(
modifier = Modifier.padding(horizontal = 12.dp),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ private fun UserDisplayName(
activeUserPremiumTier: String?,
onPremiumBadgeClick: (tier: String) -> Unit,
) {
val hasCustomBadge = profilePremiumDetails?.legendaryCustomization?.customBadge == true

Row(
modifier = modifier.padding(top = 12.dp, bottom = 3.dp),
verticalAlignment = Alignment.CenterVertically,
Expand All @@ -357,11 +355,7 @@ private fun UserDisplayName(
lineHeight = 20.sp,
fontWeight = FontWeight.Bold,
),
customBadgeStyle = if (hasCustomBadge) {
profilePremiumDetails?.legendaryCustomization?.legendaryStyle
} else {
null
},
authorLegendaryCustomization = profilePremiumDetails?.legendaryCustomization,
)

val isPremiumBadgeClickable = activeUserPremiumTier == null ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,19 +177,14 @@ private fun ProfileTopAppBar(
enter = fadeIn(),
exit = fadeOut(),
) {
val hasCustomBadge = state.profileDetails?.premiumDetails?.legendaryCustomization?.customBadge
NostrUserText(
modifier = Modifier.padding(top = 4.dp),
displayName = state.profileDetails?.authorDisplayName
?: state.profileId.asEllipsizedNpub(),
internetIdentifier = state.profileDetails?.internetIdentifier,
internetIdentifierBadgeSize = 20.dp,
internetIdentifierBadgeAlign = PlaceholderVerticalAlign.Center,
customBadgeStyle = if (hasCustomBadge == true) {
state.profileDetails.premiumDetails.legendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = state.profileDetails?.premiumDetails?.legendaryCustomization,
)
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ private fun GenericReactionListItem(
NostrUserText(
displayName = item.profile.authorDisplayName,
internetIdentifier = item.profile.internetIdentifier,
customBadgeStyle = if (item.profile.premiumDetails?.legendaryCustomization?.customBadge == true) {
item.profile.premiumDetails.legendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = item.profile.premiumDetails?.legendaryCustomization,
)
},
trailingContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,7 @@ private fun NoteZapListItem(data: EventZapUiModel, onProfileClick: (profileId: S
NostrUserText(
displayName = data.zapperName,
internetIdentifier = data.zapperInternetIdentifier,
customBadgeStyle = if (data.zapperLegendaryCustomization?.customBadge == true) {
data.zapperLegendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = data.zapperLegendaryCustomization,
)
},
supportingContent = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,7 @@ fun ArticleAuthorRow(
fontSize = 16.sp,
lineHeight = 16.sp,
),
customBadgeStyle = if (authorLegendaryCustomization?.customBadge == true) {
authorLegendaryCustomization.legendaryStyle
} else {
null
},
authorLegendaryCustomization = authorLegendaryCustomization,
)

if (!authorInternetIdentifier.isNullOrBlank()) {
Expand Down
Loading