feat(posts): add host to community view in card

This commit is contained in:
Diego Beraldin 2023-07-27 09:11:02 +02:00
parent 4b80c78e30
commit 74cda9afcd
7 changed files with 22 additions and 5 deletions

View File

@ -3,6 +3,6 @@ package com.github.diegoberaldin.raccoonforlemmy.data
data class CommunityModel(
val id: Int = 0,
val name: String = "",
val instance: String = "",
val host: String = "",
val icon: String? = null,
)

View File

@ -8,4 +8,5 @@ data class PostModel(
val comments: Int = 0,
val thumbnailUrl: String? = null,
val community: CommunityModel? = null,
val author: UserModel? = null,
)

View File

@ -2,4 +2,5 @@ package com.github.diegoberaldin.raccoonforlemmy.data
data class UserModel(
val name: String = "",
val instance: String = "",
)

View File

@ -17,4 +17,5 @@ class CommunityRepository(
private fun CommunityView.toModel() = CommunityModel(
name = community.name,
icon = community.icon,
)
host = extractHost(community.actorId),
)

View File

@ -0,0 +1,6 @@
package com.github.diegoberaldin.raccoonforlemmy.domain_post.repository
internal fun extractHost(value: String) = value.replace("https://", "").let {
val i = it.indexOf("/")
it.substring(0, i)
}

View File

@ -66,6 +66,7 @@ class HomeScreenModel(
community = it.community?.copy(
name = remoteCommunity?.name.orEmpty(),
icon = remoteCommunity?.icon,
host = remoteCommunity?.host.orEmpty(),
)
)
} else {

View File

@ -55,7 +55,8 @@ fun PostCard(
val communityName = post.community?.name.orEmpty()
val communityIcon = post.community?.icon.orEmpty()
val iconSize = 21.dp
val communityHost = post.community?.host.orEmpty()
val iconSize = 20.dp
if (communityName.isNotEmpty()) {
Row(
verticalAlignment = Alignment.CenterVertically,
@ -68,11 +69,16 @@ fun PostCard(
.clip(RoundedCornerShape(iconSize / 2)),
painter = painter,
contentDescription = null,
contentScale = ContentScale.FillWidth,
contentScale = ContentScale.FillBounds,
)
}
Text(
text = communityName,
text = buildString {
append(communityName)
if (communityHost.isNotEmpty()) {
append("@$communityHost")
}
},
style = MaterialTheme.typography.titleSmall,
)
}
@ -120,6 +126,7 @@ fun PostCard(
colorFilter = ColorFilter.tint(color = MaterialTheme.colorScheme.onSurface)
)
Text(
modifier = Modifier.padding(end = Spacing.s),
text = "${post.comments}"
)
}