Skip to content

Commit

Permalink
feat: Clickable home feed avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
wingio committed Jan 3, 2025
1 parent 6ba1253 commit 76e0761
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.materiiapps.gloom.Res
import com.materiiapps.gloom.gql.fragment.CreatedRepoItemFragment
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.util.annotatingStringResource
import com.materiiapps.gloom.ui.util.navigate
import dev.icerock.moko.resources.compose.stringResource

@Composable
Expand All @@ -23,6 +27,7 @@ fun CreatedRepoItem(
onStarPressed: (String) -> Unit = {},
onUnstarPressed: (String) -> Unit = {},
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.actor.actorFragment
val repo = item.repository.feedRepository

Expand All @@ -37,6 +42,7 @@ fun CreatedRepoItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Filled.Book,
badgeIconDescription = stringResource(Res.strings.noun_repo),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = annotatingStringResource(res = Res.strings.created_repo, actor.login) {
when (it) {
"name" -> SpanStyle(color = MaterialTheme.colorScheme.onSurface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.materiiapps.gloom.ui.screen.home.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
Expand All @@ -19,6 +20,7 @@ import androidx.compose.ui.graphics.vector.ImageVector
import androidx.compose.ui.text.AnnotatedString
import androidx.compose.ui.unit.dp
import com.materiiapps.gloom.ui.component.BadgedItem
import com.materiiapps.gloom.ui.util.thenIf
import com.seiko.imageloader.rememberImagePainter

@Composable
Expand All @@ -28,7 +30,8 @@ fun FeedActor(
badgeIconDescription: String? = null,
iconVector: ImageVector? = null,
iconDescription: String? = null,
text: AnnotatedString
text: AnnotatedString,
onIconClick: (() -> Unit)? = null
) {
Row(
horizontalArrangement = Arrangement.spacedBy(10.dp),
Expand All @@ -50,6 +53,7 @@ fun FeedActor(
painter = rememberImagePainter(iconUrl),
contentDescription = iconDescription,
modifier = Modifier
.thenIf(onIconClick != null) { clickable(onClick = onIconClick!!) }
.size(33.dp)
.clip(CircleShape)
)
Expand All @@ -60,6 +64,7 @@ fun FeedActor(
contentDescription = iconDescription,
tint = MaterialTheme.colorScheme.onPrimary,
modifier = Modifier
.thenIf(onIconClick != null) { clickable(onClick = onIconClick!!) }
.clip(CircleShape)
.background(MaterialTheme.colorScheme.primary)
.size(33.dp)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.materiiapps.gloom.Res
import com.materiiapps.gloom.gql.fragment.FollowedUserFeedItemFragment
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.util.annotatingStringResource
import com.materiiapps.gloom.ui.util.navigate
import dev.icerock.moko.resources.compose.stringResource

@Composable
Expand All @@ -23,6 +27,7 @@ fun FollowedUserItem(
onFollowPressed: (String) -> Unit = {},
onUnfollowPressed: (String) -> Unit = {},
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.follower
val user = item.followee
val userLogin = user.feedUser?.login ?: user.feedOrg?.login
Expand All @@ -47,6 +52,7 @@ fun FollowedUserItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Filled.PersonAddAlt1,
badgeIconDescription = stringResource(Res.strings.cd_followed),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = actorText
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.materiiapps.gloom.Res
import com.materiiapps.gloom.gql.fragment.ForkedRepositoryFeedItemFragment
import com.materiiapps.gloom.ui.icon.Custom
import com.materiiapps.gloom.ui.icon.custom.Fork
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.util.annotatingStringResource
import com.materiiapps.gloom.ui.util.navigate
import dev.icerock.moko.resources.compose.stringResource

@Composable
Expand All @@ -24,6 +28,7 @@ fun ForkedRepoItem(
onStarPressed: (String) -> Unit = {},
onUnstarPressed: (String) -> Unit = {},
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.actor.actorFragment
val repo = item.repository.feedRepository

Expand All @@ -38,6 +43,7 @@ fun ForkedRepoItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Custom.Fork,
badgeIconDescription = stringResource(Res.strings.cd_forked_repo),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = annotatingStringResource(res = Res.strings.forked_repo, actor.login) {
when (it) {
"name" -> SpanStyle(color = MaterialTheme.colorScheme.onSurface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import com.materiiapps.gloom.ui.component.Label
import com.materiiapps.gloom.ui.component.ThinDivider
import com.materiiapps.gloom.ui.icon.Custom
import com.materiiapps.gloom.ui.icon.custom.MergedPullRequest
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.screen.repo.RepoScreen
import com.materiiapps.gloom.ui.theme.gloomColorScheme
import com.materiiapps.gloom.ui.util.annotatingStringResource
Expand All @@ -46,6 +47,7 @@ fun MergedPullRequestItem(
item: MergedPullRequestFeedItemFragment,
onReactionClick: (ReactionContent, Boolean) -> Unit
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.actor.actorFragment
val pullRequest = item.pullRequest
val baseRepo = pullRequest.baseRepository
Expand All @@ -61,6 +63,7 @@ fun MergedPullRequestItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Custom.MergedPullRequest,
badgeIconDescription = stringResource(Res.strings.cd_forked_repo),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = annotatingStringResource(res = Res.strings.contributed_repo, actor.login, "${baseRepo?.owner?.login}/${baseRepo?.name}") {
when (it) {
"repo",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.materiiapps.gloom.ui.component.Avatar
import com.materiiapps.gloom.ui.component.ThinDivider
import com.materiiapps.gloom.ui.icon.Custom
import com.materiiapps.gloom.ui.icon.custom.Commit
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.screen.release.ReleaseScreen
import com.materiiapps.gloom.ui.screen.repo.RepoScreen
import com.materiiapps.gloom.ui.theme.DarkGreen
Expand All @@ -70,6 +71,7 @@ fun NewReleaseItem(
starData: Pair<Boolean, Int>? = null,
onVisitPressed: (String) -> Unit = {},
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.actor.actorFragment
val release = item.release

Expand All @@ -84,6 +86,7 @@ fun NewReleaseItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Filled.LocalOffer,
badgeIconDescription = stringResource(Res.strings.noun_release),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = annotatingStringResource(res = Res.strings.published_release, actor.login) {
when (it) {
"name" -> SpanStyle(color = MaterialTheme.colorScheme.onSurface)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.SpanStyle
import androidx.compose.ui.unit.dp
import cafe.adriel.voyager.navigator.LocalNavigator
import cafe.adriel.voyager.navigator.currentOrThrow
import com.materiiapps.gloom.Res
import com.materiiapps.gloom.gql.fragment.StarredFeedItemFragment
import com.materiiapps.gloom.ui.screen.profile.ProfileScreen
import com.materiiapps.gloom.ui.util.annotatingStringResource
import com.materiiapps.gloom.ui.util.navigate
import dev.icerock.moko.resources.compose.stringResource

@Composable
Expand All @@ -23,6 +27,7 @@ fun StarredRepoItem(
onStarPressed: (String) -> Unit = {},
onUnstarPressed: (String) -> Unit = {},
) {
val navigator = LocalNavigator.currentOrThrow
val actor = item.actor.actorFragment
val repo = item.repository.feedRepository

Expand All @@ -37,6 +42,7 @@ fun StarredRepoItem(
iconDescription = stringResource(Res.strings.noun_users_avatar, actor.login),
badgeIcon = Icons.Filled.Star,
badgeIconDescription = stringResource(Res.strings.title_starred),
onIconClick = { navigator.navigate(ProfileScreen(actor.login)) },
text = annotatingStringResource(res = Res.strings.starred_repo, actor.login) {
when (it) {
"name" -> SpanStyle(color = MaterialTheme.colorScheme.onSurface)
Expand Down

0 comments on commit 76e0761

Please sign in to comment.