mirror of
https://github.com/LiveFastEatTrashRaccoon/RaccoonForLemmy.git
synced 2025-02-09 11:48:43 +01:00
feat: show community stats in sidebar
This commit is contained in:
parent
56327c559f
commit
660a38180d
@ -24,9 +24,7 @@ import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.CornerSize
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ScaledContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.prettifyDate
|
||||
|
||||
@Composable
|
||||
internal fun MessageCard(
|
||||
@ -111,54 +109,7 @@ internal fun MessageCard(
|
||||
tint = textColor,
|
||||
)
|
||||
Text(
|
||||
text = date.let {
|
||||
when {
|
||||
it.isEmpty() -> it
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(
|
||||
MR.strings.profile_year_short
|
||||
),
|
||||
monthLabel = stringResource(
|
||||
MR.strings.profile_month_short
|
||||
),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(
|
||||
MR.strings.post_hour_short
|
||||
),
|
||||
minuteLabel = stringResource(
|
||||
MR.strings.post_minute_short
|
||||
),
|
||||
secondLabel = stringResource(
|
||||
MR.strings.post_second_short
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(
|
||||
MR.strings.profile_year_short
|
||||
),
|
||||
monthLabel = stringResource(
|
||||
MR.strings.profile_month_short
|
||||
),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(
|
||||
MR.strings.post_hour_short
|
||||
),
|
||||
minuteLabel = stringResource(
|
||||
MR.strings.post_minute_short
|
||||
),
|
||||
secondLabel = stringResource(
|
||||
MR.strings.post_second_short
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
text = date.prettifyDate(),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = textColor,
|
||||
)
|
||||
|
@ -9,9 +9,18 @@ import androidx.compose.foundation.layout.fillMaxHeight
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.rememberScrollState
|
||||
import androidx.compose.foundation.verticalScroll
|
||||
import androidx.compose.foundation.lazy.LazyColumn
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cake
|
||||
import androidx.compose.material.icons.filled.CalendarViewDay
|
||||
import androidx.compose.material.icons.filled.CalendarViewMonth
|
||||
import androidx.compose.material.icons.filled.CalendarViewWeek
|
||||
import androidx.compose.material.icons.filled.Group
|
||||
import androidx.compose.material.icons.filled.Padding
|
||||
import androidx.compose.material.icons.filled.Reply
|
||||
import androidx.compose.material3.Divider
|
||||
import androidx.compose.material3.ExperimentalMaterial3Api
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Scaffold
|
||||
import androidx.compose.material3.Text
|
||||
@ -21,6 +30,11 @@ import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.graphics.vector.ImageVector
|
||||
import androidx.compose.ui.text.SpanStyle
|
||||
import androidx.compose.ui.text.buildAnnotatedString
|
||||
import androidx.compose.ui.text.font.FontWeight
|
||||
import androidx.compose.ui.text.withStyle
|
||||
import cafe.adriel.voyager.core.model.rememberScreenModel
|
||||
import cafe.adriel.voyager.core.screen.Screen
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
@ -28,8 +42,11 @@ import com.github.diegoberaldin.raccoonforlemmy.core.architecture.bindToLifecycl
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.BottomSheetHandle
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.PostCardBody
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ScaledContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.prettifyDate
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.di.getCommunityInfoViewModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
class CommunityInfoScreen(
|
||||
private val community: CommunityModel,
|
||||
@ -77,23 +94,104 @@ class CommunityInfoScreen(
|
||||
})
|
||||
},
|
||||
) { paddingValues ->
|
||||
Column(
|
||||
LazyColumn(
|
||||
modifier = Modifier
|
||||
.verticalScroll(rememberScrollState())
|
||||
.fillMaxSize()
|
||||
.padding(paddingValues)
|
||||
.padding(top = Spacing.m),
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.s),
|
||||
horizontalAlignment = Alignment.CenterHorizontally,
|
||||
) {
|
||||
ScaledContent {
|
||||
PostCardBody(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = uiState.community.description,
|
||||
)
|
||||
item {
|
||||
Column(
|
||||
verticalArrangement = Arrangement.spacedBy(Spacing.xs),
|
||||
) {
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.Cake,
|
||||
title = community.creationDate?.prettifyDate().orEmpty(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.Padding,
|
||||
title = stringResource(MR.strings.community_info_posts),
|
||||
value = uiState.community.posts.toString(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.Reply,
|
||||
title = stringResource(MR.strings.community_info_comments),
|
||||
value = uiState.community.comments.toString(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.Group,
|
||||
title = stringResource(MR.strings.community_info_subscribers),
|
||||
value = uiState.community.subscribers.toString(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.CalendarViewMonth,
|
||||
title = stringResource(MR.strings.community_info_monthly_active_users),
|
||||
value = uiState.community.monthlyActiveUsers.toString(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.CalendarViewWeek,
|
||||
title = stringResource(MR.strings.community_info_weekly_active_users),
|
||||
value = uiState.community.weeklyActiveUsers.toString(),
|
||||
)
|
||||
CommunityInfoItem(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
icon = Icons.Default.CalendarViewDay,
|
||||
title = stringResource(MR.strings.community_info_daily_active_users),
|
||||
value = uiState.community.dailyActiveUsers.toString(),
|
||||
)
|
||||
|
||||
Divider()
|
||||
}
|
||||
}
|
||||
item {
|
||||
ScaledContent {
|
||||
PostCardBody(
|
||||
modifier = Modifier.fillMaxWidth(),
|
||||
text = uiState.community.description,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
private fun CommunityInfoItem(
|
||||
modifier: Modifier = Modifier,
|
||||
icon: ImageVector? = null,
|
||||
title: String = "",
|
||||
value: String = "",
|
||||
) {
|
||||
Row(
|
||||
modifier = modifier,
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.xs),
|
||||
) {
|
||||
if (icon != null) {
|
||||
Icon(imageVector = icon, contentDescription = null)
|
||||
}
|
||||
Text(
|
||||
text = buildAnnotatedString {
|
||||
withStyle(
|
||||
SpanStyle(
|
||||
fontWeight = FontWeight.Bold,
|
||||
color = MaterialTheme.colorScheme.primary,
|
||||
)
|
||||
) {
|
||||
append(value)
|
||||
}
|
||||
append(" ")
|
||||
append(title)
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +1,19 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.CalendarViewMonth
|
||||
import androidx.compose.material.icons.filled.Group
|
||||
import androidx.compose.material.icons.outlined.Info
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@ -23,6 +27,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.FilterQuality
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
@ -45,21 +51,38 @@ fun CommunityHeader(
|
||||
onOpenImage: ((String) -> Unit)? = null,
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier.fillMaxWidth().padding(Spacing.s),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
) {
|
||||
// banner
|
||||
val banner = community.banner.orEmpty()
|
||||
if (banner.isNotEmpty() && autoLoadImages) {
|
||||
CustomImage(
|
||||
modifier = Modifier.fillMaxWidth().aspectRatio(4.5f),
|
||||
url = banner,
|
||||
contentScale = ContentScale.FillWidth,
|
||||
contentDescription = null,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth().aspectRatio(4f),
|
||||
) {
|
||||
CustomImage(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
url = banner,
|
||||
contentScale = ContentScale.FillBounds,
|
||||
contentDescription = null,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier
|
||||
.fillMaxSize()
|
||||
.background(
|
||||
brush = Brush.horizontalGradient(
|
||||
colors = listOf(
|
||||
MaterialTheme.colorScheme.background.copy(alpha = 0.95f),
|
||||
Color.Transparent,
|
||||
MaterialTheme.colorScheme.background.copy(alpha = 0.75f),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.TopEnd)
|
||||
modifier = Modifier.padding(top = Spacing.xs, end = Spacing.s).align(Alignment.TopEnd)
|
||||
) {
|
||||
if (options.isNotEmpty()) {
|
||||
var optionsExpanded by remember { mutableStateOf(false) }
|
||||
@ -101,7 +124,7 @@ fun CommunityHeader(
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().align(Alignment.Center),
|
||||
modifier = Modifier.fillMaxWidth().padding(Spacing.s).align(Alignment.Center),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.m)
|
||||
) {
|
||||
@ -152,6 +175,38 @@ fun CommunityHeader(
|
||||
style = MaterialTheme.typography.titleSmall,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
|
||||
// stats and age
|
||||
val iconSize = 22.dp
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.s),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
) {
|
||||
if (community.subscribers >= 0) {
|
||||
Icon(
|
||||
modifier = Modifier.size(iconSize),
|
||||
imageVector = Icons.Default.Group,
|
||||
contentDescription = null
|
||||
)
|
||||
Text(
|
||||
text = community.subscribers.toString(),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
}
|
||||
if (community.monthlyActiveUsers >= 0) {
|
||||
Icon(
|
||||
modifier = Modifier.size(iconSize),
|
||||
imageVector = Icons.Default.CalendarViewMonth,
|
||||
contentDescription = null
|
||||
)
|
||||
Text(
|
||||
text = community.monthlyActiveUsers.toString(),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,56 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.components
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun String.prettifyDate(): String = let {
|
||||
when {
|
||||
it.isEmpty() -> it
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(
|
||||
MR.strings.profile_year_short
|
||||
),
|
||||
monthLabel = stringResource(
|
||||
MR.strings.profile_month_short
|
||||
),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(
|
||||
MR.strings.post_hour_short
|
||||
),
|
||||
minuteLabel = stringResource(
|
||||
MR.strings.post_minute_short
|
||||
),
|
||||
secondLabel = stringResource(
|
||||
MR.strings.post_second_short
|
||||
),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(
|
||||
MR.strings.profile_year_short
|
||||
),
|
||||
monthLabel = stringResource(
|
||||
MR.strings.profile_month_short
|
||||
),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(
|
||||
MR.strings.post_hour_short
|
||||
),
|
||||
minuteLabel = stringResource(
|
||||
MR.strings.post_minute_short
|
||||
),
|
||||
secondLabel = stringResource(
|
||||
MR.strings.post_second_short
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
@ -31,12 +31,9 @@ import androidx.compose.ui.unit.Dp
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.CommunityModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun InboxReplySubtitle(
|
||||
@ -166,34 +163,7 @@ fun InboxReplySubtitle(
|
||||
tint = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
Text(
|
||||
text = date?.let {
|
||||
when {
|
||||
it.isEmpty() -> it
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
}
|
||||
} ?: "",
|
||||
text = date?.prettifyDate() ?: "",
|
||||
)
|
||||
Spacer(modifier = Modifier.weight(1f))
|
||||
Image(
|
||||
|
@ -36,11 +36,8 @@ import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.di.getThemeRepository
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun PostCardFooter(
|
||||
@ -100,34 +97,7 @@ fun PostCardFooter(
|
||||
tint = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
Text(
|
||||
text = date.let {
|
||||
when {
|
||||
it.isEmpty() -> it
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
text = date.prettifyDate(),
|
||||
style = MaterialTheme.typography.labelLarge,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
|
@ -1,20 +1,22 @@
|
||||
package com.github.diegoberaldin.raccoonforlemmy.core.commonui.components
|
||||
|
||||
import androidx.compose.foundation.background
|
||||
import androidx.compose.foundation.layout.Arrangement
|
||||
import androidx.compose.foundation.layout.Box
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.Row
|
||||
import androidx.compose.foundation.layout.Spacer
|
||||
import androidx.compose.foundation.layout.aspectRatio
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.foundation.layout.fillMaxWidth
|
||||
import androidx.compose.foundation.layout.padding
|
||||
import androidx.compose.foundation.layout.size
|
||||
import androidx.compose.foundation.layout.width
|
||||
import androidx.compose.foundation.shape.RoundedCornerShape
|
||||
import androidx.compose.material.icons.Icons
|
||||
import androidx.compose.material.icons.filled.Cake
|
||||
import androidx.compose.material.icons.filled.Padding
|
||||
import androidx.compose.material.icons.filled.Reply
|
||||
import androidx.compose.material.icons.filled.Schedule
|
||||
import androidx.compose.material.icons.outlined.MoreVert
|
||||
import androidx.compose.material3.Icon
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
@ -28,6 +30,8 @@ import androidx.compose.ui.Alignment
|
||||
import androidx.compose.ui.Modifier
|
||||
import androidx.compose.ui.draw.clip
|
||||
import androidx.compose.ui.geometry.Offset
|
||||
import androidx.compose.ui.graphics.Brush
|
||||
import androidx.compose.ui.graphics.Color
|
||||
import androidx.compose.ui.graphics.FilterQuality
|
||||
import androidx.compose.ui.layout.ContentScale
|
||||
import androidx.compose.ui.layout.onGloballyPositioned
|
||||
@ -36,12 +40,9 @@ import androidx.compose.ui.text.style.TextOverflow
|
||||
import androidx.compose.ui.unit.DpOffset
|
||||
import androidx.compose.ui.unit.dp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.toLocalDp
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
fun UserHeader(
|
||||
@ -53,22 +54,37 @@ fun UserHeader(
|
||||
onOpenImage: ((String) -> Unit)? = null,
|
||||
) {
|
||||
Box(
|
||||
modifier = modifier.fillMaxWidth().padding(Spacing.s),
|
||||
modifier = modifier.fillMaxWidth(),
|
||||
) {
|
||||
// banner
|
||||
val banner = user.banner.orEmpty()
|
||||
if (banner.isNotEmpty() && autoLoadImages) {
|
||||
CustomImage(
|
||||
modifier = Modifier.fillMaxWidth().aspectRatio(4.5f),
|
||||
url = banner,
|
||||
quality = FilterQuality.Low,
|
||||
contentScale = ContentScale.FillWidth,
|
||||
contentDescription = null,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.fillMaxWidth().aspectRatio(4f),
|
||||
) {
|
||||
CustomImage(
|
||||
modifier = Modifier.fillMaxSize(),
|
||||
url = banner,
|
||||
quality = FilterQuality.Low,
|
||||
contentScale = ContentScale.FillBounds,
|
||||
contentDescription = null,
|
||||
)
|
||||
Box(
|
||||
modifier = Modifier.fillMaxSize().background(
|
||||
brush = Brush.horizontalGradient(
|
||||
colors = listOf(
|
||||
MaterialTheme.colorScheme.background.copy(alpha = 0.95f),
|
||||
Color.Transparent,
|
||||
MaterialTheme.colorScheme.background.copy(alpha = 0.75f),
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.align(Alignment.TopEnd)
|
||||
modifier = Modifier.padding(top = Spacing.xs, end = Spacing.s).align(Alignment.TopEnd)
|
||||
) {
|
||||
// options menu
|
||||
if (options.isNotEmpty()) {
|
||||
@ -110,7 +126,7 @@ fun UserHeader(
|
||||
}
|
||||
|
||||
Row(
|
||||
modifier = Modifier.fillMaxWidth().align(Alignment.Center),
|
||||
modifier = Modifier.fillMaxWidth().padding(Spacing.s).align(Alignment.Center),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
horizontalArrangement = Arrangement.spacedBy(Spacing.m)
|
||||
) {
|
||||
@ -119,11 +135,8 @@ fun UserHeader(
|
||||
val avatarSize = 60.dp
|
||||
if (userAvatar.isNotEmpty() && autoLoadImages) {
|
||||
CustomImage(
|
||||
modifier = Modifier
|
||||
.padding(Spacing.xxxs)
|
||||
.size(avatarSize)
|
||||
.clip(RoundedCornerShape(avatarSize / 2))
|
||||
.onClick {
|
||||
modifier = Modifier.padding(Spacing.xxxs).size(avatarSize)
|
||||
.clip(RoundedCornerShape(avatarSize / 2)).onClick {
|
||||
onOpenImage?.invoke(userAvatar)
|
||||
},
|
||||
url = userAvatar,
|
||||
@ -207,37 +220,11 @@ fun UserHeader(
|
||||
}
|
||||
Icon(
|
||||
modifier = Modifier.size(iconSize),
|
||||
imageVector = Icons.Default.Schedule,
|
||||
imageVector = Icons.Default.Cake,
|
||||
contentDescription = null
|
||||
)
|
||||
Text(
|
||||
text = user.accountAge.let {
|
||||
when {
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
text = user.accountAge.prettifyDate(),
|
||||
style = MaterialTheme.typography.titleMedium,
|
||||
color = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
|
@ -14,4 +14,11 @@ data class CommunityModel(
|
||||
val subscribed: Boolean? = null,
|
||||
val instanceUrl: String = "",
|
||||
val nsfw: Boolean = false,
|
||||
val monthlyActiveUsers: Int = 0,
|
||||
val weeklyActiveUsers: Int = 0,
|
||||
val dailyActiveUsers: Int = 0,
|
||||
val subscribers: Int = 0,
|
||||
val posts: Int = 0,
|
||||
val comments: Int = 0,
|
||||
val creationDate: String? = null,
|
||||
) : JavaSerializable
|
||||
|
@ -4,6 +4,7 @@ import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentReplyView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentSortType
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommentView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.Community
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.CommunityView
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType.All
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType.Local
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.api.dto.ListingType.Subscribed
|
||||
@ -142,6 +143,16 @@ internal fun Community.toModel() = CommunityModel(
|
||||
instanceUrl = actorId.communityToInstanceUrl(),
|
||||
host = actorId.toHost(),
|
||||
nsfw = nsfw,
|
||||
creationDate = published,
|
||||
)
|
||||
|
||||
internal fun CommunityView.toModel() = community.toModel().copy(
|
||||
monthlyActiveUsers = counts.usersActiveMonth,
|
||||
weeklyActiveUsers = counts.usersActiveWeek,
|
||||
dailyActiveUsers = counts.usersActiveDay,
|
||||
subscribers = counts.subscribers,
|
||||
posts = counts.posts,
|
||||
comments = counts.comments,
|
||||
)
|
||||
|
||||
internal fun PersonMentionView.toModel() = PersonMentionModel(
|
||||
|
@ -23,11 +23,9 @@ import com.github.diegoberaldin.raccoonforlemmy.core.appearance.theme.Spacing
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.CustomImage
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.PlaceholderImage
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.ScaledContent
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.DateTime
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.commonui.components.prettifyDate
|
||||
import com.github.diegoberaldin.raccoonforlemmy.core.utils.onClick
|
||||
import com.github.diegoberaldin.raccoonforlemmy.domain.lemmy.data.UserModel
|
||||
import com.github.diegoberaldin.raccoonforlemmy.resources.MR
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
|
||||
@Composable
|
||||
internal fun ChatCard(
|
||||
@ -121,34 +119,7 @@ internal fun ChatCard(
|
||||
tint = MaterialTheme.colorScheme.onBackground,
|
||||
)
|
||||
Text(
|
||||
text = lastMessageDate.let {
|
||||
when {
|
||||
it.isEmpty() -> it
|
||||
!it.endsWith("Z") -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it + "Z",
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
|
||||
else -> {
|
||||
DateTime.getPrettyDate(
|
||||
iso8601Timestamp = it,
|
||||
yearLabel = stringResource(MR.strings.profile_year_short),
|
||||
monthLabel = stringResource(MR.strings.profile_month_short),
|
||||
dayLabel = stringResource(MR.strings.profile_day_short),
|
||||
hourLabel = stringResource(MR.strings.post_hour_short),
|
||||
minuteLabel = stringResource(MR.strings.post_minute_short),
|
||||
secondLabel = stringResource(MR.strings.post_second_short),
|
||||
)
|
||||
}
|
||||
}
|
||||
},
|
||||
text = lastMessageDate.prettifyDate(),
|
||||
style = MaterialTheme.typography.labelMedium,
|
||||
color = MaterialTheme.colorScheme.onSurface,
|
||||
)
|
||||
|
@ -154,6 +154,12 @@
|
||||
|
||||
<string name="community_detail_info">Community info</string>
|
||||
<string name="community_detail_instance_info">Instance details</string>
|
||||
<string name="community_info_posts">posts</string>
|
||||
<string name="community_info_comments">comments</string>
|
||||
<string name="community_info_subscribers">subscribers</string>
|
||||
<string name="community_info_monthly_active_users">active users (month)</string>
|
||||
<string name="community_info_weekly_active_users">active users (week)</string>
|
||||
<string name="community_info_daily_active_users">active users (day)</string>
|
||||
<string name="community_detail_block">Block</string>
|
||||
<string name="community_detail_block_instance">Block instance</string>
|
||||
<string name="instance_detail_title">Instance: %1$s</string>
|
||||
|
@ -152,6 +152,12 @@
|
||||
|
||||
<string name="community_detail_info">Info comunidad</string>
|
||||
<string name="community_detail_instance_info">Detalles instancia</string>
|
||||
<string name="community_info_posts">publicaciones</string>
|
||||
<string name="community_info_comments">comentarios</string>
|
||||
<string name="community_info_subscribers">suscriptores</string>
|
||||
<string name="community_info_monthly_active_users">usuarios activos (mes)</string>
|
||||
<string name="community_info_weekly_active_users">usuarios activos (semana)</string>
|
||||
<string name="community_info_daily_active_users">usuarios activos (día)</string>
|
||||
<string name="community_detail_block">Bloquear</string>
|
||||
<string name="community_detail_block_instance">Bloquear instancia</string>
|
||||
<string name="instance_detail_title">Instancia: %1$s</string>
|
||||
|
@ -153,6 +153,12 @@
|
||||
|
||||
<string name="community_detail_info">Info comunità</string>
|
||||
<string name="community_detail_instance_info">Dettagli istanza</string>
|
||||
<string name="community_info_posts">post</string>
|
||||
<string name="community_info_comments">commenti</string>
|
||||
<string name="community_info_subscribers">iscritti</string>
|
||||
<string name="community_info_monthly_active_users">utenti attivi (mese)</string>
|
||||
<string name="community_info_weekly_active_users">utenti attivi (settimana)</string>
|
||||
<string name="community_info_daily_active_users">utenti attivi (giorno)</string>
|
||||
<string name="instance_detail_title">Istanza: %1$s</string>
|
||||
<string name="instance_detail_communities">Comunità</string>
|
||||
<string name="action_back_to_top">Torna su</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user