-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
236 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/xyz/wingio/dimett/ui/widgets/posts/PostPronouns.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package xyz.wingio.dimett.ui.widgets.posts | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.filled.Person | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.text.style.TextAlign | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import xyz.wingio.dimett.R | ||
import xyz.wingio.dimett.ast.EmojiSyntakts | ||
import xyz.wingio.dimett.ast.render | ||
import xyz.wingio.dimett.rest.dto.CustomEmoji | ||
import xyz.wingio.dimett.ui.components.Text | ||
import xyz.wingio.dimett.utils.toEmojiMap | ||
|
||
/** | ||
* Displays the users pronouns | ||
* | ||
* @param pronouns The users pronouns | ||
* @param emoji Emoji used in the users profile, possibly used for their pronouns | ||
* @param modifier The [Modifier] used for this component | ||
* @param color Content color for the icon and text | ||
*/ | ||
@Composable | ||
fun PostPronouns( | ||
pronouns: String?, | ||
emoji: List<CustomEmoji>, | ||
modifier: Modifier = Modifier, | ||
color: Color = LocalContentColor.current.copy(alpha = 0.5f) | ||
) { | ||
pronouns?.let { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(5.5.dp, Alignment.End), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
) { | ||
Text( | ||
text = EmojiSyntakts.render(pronouns, emojiMap = emoji.toEmojiMap()), | ||
style = MaterialTheme.typography.labelSmall, | ||
color = color, | ||
maxLines = 1, | ||
overflow = TextOverflow.Ellipsis, | ||
textAlign = TextAlign.End, | ||
modifier = Modifier.weight(1f) | ||
) | ||
|
||
Icon( | ||
imageVector = Icons.Filled.Person, | ||
contentDescription = stringResource(R.string.cd_pronouns), | ||
tint = color, | ||
modifier = Modifier.size(13.dp) | ||
) | ||
} | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
app/src/main/java/xyz/wingio/dimett/ui/widgets/posts/PostTimestamp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package xyz.wingio.dimett.ui.widgets.posts | ||
|
||
import android.text.format.DateUtils | ||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Row | ||
import androidx.compose.foundation.layout.size | ||
import androidx.compose.material.icons.Icons | ||
import androidx.compose.material.icons.outlined.Lock | ||
import androidx.compose.material.icons.outlined.Mail | ||
import androidx.compose.material.icons.outlined.Public | ||
import androidx.compose.material.icons.outlined.VpnLock | ||
import androidx.compose.material3.Icon | ||
import androidx.compose.material3.LocalContentColor | ||
import androidx.compose.material3.MaterialTheme | ||
import androidx.compose.material3.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.graphics.Color | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.compose.ui.unit.dp | ||
import kotlinx.datetime.Instant | ||
import xyz.wingio.dimett.R | ||
import xyz.wingio.dimett.rest.dto.post.Post | ||
|
||
/** | ||
* Displays a relative timestamp along with the posts visibility | ||
* | ||
* @param createdAt Timestamp for the posts creation | ||
* @param visibility The visibility level of the post | ||
* @param modifier The [Modifier] for this component | ||
* @param color Content color for the icon and text | ||
* @param showVisibility Whether or not to show an icon for the posts [visibility] | ||
*/ | ||
@Composable | ||
fun PostTimestamp( | ||
createdAt: Instant, | ||
visibility: Post.Visibility, | ||
modifier: Modifier = Modifier, | ||
color: Color = LocalContentColor.current.copy(alpha = 0.5f), | ||
showVisibility: Boolean = true, | ||
) { | ||
Row( | ||
horizontalArrangement = Arrangement.spacedBy(5.5.dp), | ||
verticalAlignment = Alignment.CenterVertically, | ||
modifier = modifier | ||
) { | ||
val (privacyIcon, privacyIconLabelRes) = remember(visibility) { | ||
when (visibility) { | ||
Post.Visibility.PUBLIC, | ||
Post.Visibility.LOCAL -> Icons.Outlined.Public to R.string.cd_privacy_public | ||
Post.Visibility.PRIVATE -> Icons.Outlined.Lock to R.string.cd_privacy_private | ||
Post.Visibility.DIRECT -> Icons.Outlined.Mail to R.string.cd_privacy_direct | ||
Post.Visibility.UNLISTED -> Icons.Outlined.VpnLock to R.string.cd_privacy_unlisted | ||
} | ||
} | ||
|
||
val timeString = remember(createdAt) { | ||
DateUtils.getRelativeTimeSpanString( | ||
/* time = */ createdAt.toEpochMilliseconds(), | ||
/* now = */ System.currentTimeMillis(), | ||
/* minResolution = */ 0L, | ||
/* flags = */ DateUtils.FORMAT_ABBREV_ALL | ||
).toString() | ||
} | ||
|
||
Text( | ||
text = timeString, | ||
style = MaterialTheme.typography.labelSmall, | ||
color = color | ||
) | ||
|
||
if (showVisibility) { | ||
Icon( | ||
imageVector = privacyIcon, | ||
contentDescription = stringResource(privacyIconLabelRes), | ||
tint = color, | ||
modifier = Modifier.size(13.dp) | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters